<?php
/**
 * YAWIK
 *
 * @filesource
 * @license    MIT
 * @copyright  2013 - 2015 Cross Solution <http://cross-solution.de>
 */

$options             = $this->services('Core/Options');
$defaultCurrencyCode = $options->defaultCurrencyCode;
$defaultTaxRate      = $options->defaultTaxRate;
$router = $this->services('Router');
/* @var $provider \Jobs\Options\ProviderOptions */
$provider = $this->services('Jobs/Options/Provider');

if ($this->renderSummary): echo $this->render('jobs/form/multiposting-select');
else:
    $isDisabled = 'disabled' == $this->element->getAttribute('disabled')?>
    <div id="<?php echo $this->element->getAttribute('id') ?>" class="mcp-checkboxes">
        <?php $valueOptions = $this->element->getValueOptions();?>
        <?php foreach ($valueOptions as $category => $vOpts): ?>
            <div class="row">
                <div class="col-md-12"><h4><?php echo $vOpts['label'] ?></h4></div>
            </div>
            <div class="row">
                <?php foreach ($vOpts['options'] as $v => $opt):
                    $checked = in_Array($v, $this->element->getValue());
                    $class   = $checked ? 'btn-success active' : 'btn-default';
                    $spec = explode('|', $opt);
                    $channel = $provider->getChannel($v);
                    ?>
                    <div class="col-md-4">
                        <?php
                        $popup = $spec[6]
                            ? '<img src="' . $this->basePath($spec[6]) . '" alt="' . $spec[1] . '" class="img-responsive">'
                            : '' .
                              sprintf($spec[2], '<a href="' . $spec[4] . '">' . $spec[3] . '</a>');
                        ?>
                        <style>
                            .portal-buttons .btn {
                                width: 80%;
                            }

                            .portal-buttons .btn-secondary {
                                width: 20%;
                                margin-bottom: 3px;
                            }
                        </style>
                        <div class="portal-buttons btn-toolbar" role="toolbar" aria-label="select portals for multiposting">
                            <div class="btn-group btn-block" role="group" aria-label="publish on <?php echo $v?>">

                                <button type="button"
                                        class="mpc-button btn <?php echo $class ?>"
                                        aria-pressed="<?php echo $checked ? 'true' : 'false' ?>"
                                        data-toggle="button"
                                        data-placement="top" data-trigger="hover focus" data-html="true"
                                        title="<?php echo $spec[1] ?>"
                                        data-content="<?php echo $this->escapeHtmlAttr($popup);?>"
                                    <?php
                                    echo $isDisabled ? 'disabled' : ''?>>
                                    <?php echo $spec[0] ?>
                                    <input <?php echo $checked ? 'checked ' : '' ?>type="checkbox"
                                           name="<?php echo $this->element->getName()?>[]" class="hidden"
                                           value="<?php echo $v ?>">
                                </button>
                                <?php
                                $link = $router->assemble($channel->getParams(), array('name' => $channel->getRoute())); ?>
                                <button data-target="#modal-portals-<?php echo $v?>" href="<?php echo $link ?>" data-toggle="modal" type="button" class="btn btn-secondary">?</button>
                            </div>
                        </div>
                        <?php
                        /**
                         * @todo: move the modal container at the bottom of the page and refresh the modal content
                         */
                        ?>
                        <div id="modal-portals-<?php echo $v?>" class="modal fade modal-scrollable" aria-hidden="true" aria-labelledby="portal help" role="dialog" tabindex="-1">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content"> </div>
                            </div>
                        </div>
                    </div>
                <?php endforeach ?>
            </div>
        <?php endforeach;?>

        <div id="<?php echo $this->element->getAttribute('id') ?>-total" class="text-right" style="padding: 10px 5px">

            <strong><span></span> <?php echo $defaultCurrencyCode?></strong><br>
            <small><?php echo $this->translate('plus VAT')?></small>

        </div>

        <?php
        // Element Templates
        $resultTmpl = '
    <div class="clearfix">
        <div class="pull-left">
            <strong>%name - %headline</strong><br>
            <small>%desc</small>
        </div>
        <div class="pull-right">
            <strong>%nicePrice</strong>
        </div>
    </div>

    ';

        $selectTmpl = '
        %name (  %duration ) [ %nicePrice ]
    ';

        ?>
        <span id="<?php echo $this->element->getAttribute('id') ?>-result-tmpl"
              data-template="<?php echo $this->escapeHtmlAttr($resultTmpl) ?>"></span>
        <span id="<?php echo $this->element->getAttribute('id') ?>-select-tmpl"
              data-template="<?php echo $this->escapeHtmlAttr($selectTmpl) ?>"></span>
        <span id="<?php echo $this->element->getAttribute('id') ?>-currency-tmpl"
              data-template="<?php echo $this->numberFormat(1234.56) ?>"></span>
    </div>
<?php endif; // (else > $this->renderSummary) ?>
