<?php
namespace zin;

global $lang, $app;
$createItem      = array('text' => $lang->repo->createAction, 'url' => createLink('repo', 'create'));
$createRepoItem  = array('text' => $lang->repo->createRepoAction, 'url' => createLink('repo', 'createRepo'));
$batchCreateItem = array('text' => $lang->repo->batchCreate, 'url' => createLink('repo', 'import'));
$serverPairs     = $app->control->loadModel('pipeline')->getPairs('gitfox,gitlab');

query('#actionBar')->replaceWith(toolBar
(
    set::id('actionBar'),
    hasPriv('repo', 'createRepo') && $serverPairs ? item(set($createRepoItem + array
    (
        'icon'  => 'plus',
        'class' => 'btn primary'
    ))) : null,
    !hasPriv('repo', 'create') && hasPriv('repo', 'import') && $serverPairs ? item(set($batchCreateItem + array
    (
        'icon'  => 'plus',
        'class' => 'btn primary'
    ))) : null,
    !hasPriv('repo', 'import') && hasPriv('repo', 'create') ? item(set($createItem + array
    (
        'icon'  => 'plus',
        'class' => 'btn primary'
    ))) : null,
    hasPriv('repo', 'import') && hasPriv('repo', 'create') ? btnGroup
    (
        btn(setClass('btn primary'), set::icon('plus'), set::url(createLink('repo', 'create')), $lang->repo->createAction),
        $serverPairs ? dropDown
        (
            btn(setClass('btn primary dropdown-toggle'),
            setStyle(array('padding' => '6px', 'border-radius' => '0 2px 2px 0'))),
            set::placement('bottom-end'),
            set::items(array($createItem, $batchCreateItem))
        ) : null
    ) : null,
));
