<?php
/**
 * YAWIK
 *
 * @filesource
 * @license MIT
 * @copyright https://yawik.org/COPYRIGHT.php
 */

$job = $this->element->getObject(); /* @var \Jobs\Entity\JobInterface $job */

if ($job instanceOf \Jobs\Entity\JobSnapshot) {
    $query = ['snapshot' => $job->getSnapshotId()];
} else {
    $query = ['id' => $job->getId()];
}

$viewLink = $this->jobUrl($job, ['linkOnly' => true, 'preview' => true ]);

$query['page'] = 0;
$multipostLink = $this->url(
    'lang/jobs/manage',
    array(),
    array(
        'query' => $query,
    )
);



$options = $this->services('Core/Options');
$defaultCurrencyCode = $options->defaultCurrencyCode;
$defaultTaxRate = $options->defaultTaxRate;

?>
<h3><?=$this->translate("Preview of your job posting"); ?></h3>
<div class="row">
    <div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-body">
                <iframe id="previewJob" style="width:100%; height:800px;" src="<?= $viewLink ?>"></iframe>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="alert alert-info">
            <script type="text/javascript">
                function printIframe(id)
                {
                    var iframe = document.frames ? document.frames[id] : document.getElementById(id);
                    var ifWin = iframe.contentWindow || iframe;
                    iframe.focus();
                    ifWin.yawikPrintJob();
                    return false;
                }
            </script>
            <?php echo sprintf($this->translate('Please check the preview of your job position. Click %s to open the preview in a new window'),
                               '<a target="_blank" href="'.$viewLink.'">'.$this->translate("here").'</a>'); ?><br/>
            <a target="_blank" href="<?=$viewLink?>" class="btn btn-info" role="button"><i class="fa fa-external-link"></i>
                <?=$this->translate('Open new Window')?>
            </a>
            <a href="#" onclick="javascript:printIframe('previewJob');return false;" class="btn btn-info" role="button"><i class="fa fa-print"></i>
                <?=$this->translate('Print')?>
            </a>
        </div>
    </div>
</div>

    <div id="product-list-wrapper">
        <?php if ($job->getPortals()): ?>
            <?= $this->partial('jobs/partials/channel-list', [
                                                                          'portals'             => $job->getPortals(),
                                                                          'channels'            => $this->services('Jobs/Options/Provider'),
                                                                          'defaultCurrencyCode' => $defaultCurrencyCode,
                                                                          'defaultTaxRate'      => $defaultTaxRate,
                                                                          'jobId'               => $job->getId(),
                                                                      ]);
            ?>

        <?php endif; // $this->job->portals ?>
    </div>

<?= $this->formCollection($this->element); ?>
