<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/libraries/jquery/sortable/sortable.js"></script>
<?
global $db;

ob_start();
?>
<div id="settings-tabs">
  <ul class="resp-tabs-list settings-tabs">
    <li><i class="fa fa-wrench"></i>Ustawienia</li>
  </ul>
  <div class="resp-tabs-container settings-tabs">
    <div>
      <?= \Html::input([
        'label' => 'Nazwa',
        'name' => 'name',
        'id' => 'name',
        'value' => $this -> coupon['name']
      ]); ?>
      <?= \Html::input_switch([
        'label' => 'Wysłany',
        'name' => 'send',
        'checked' => $this -> coupon['send'] == 1 ? true : false
      ]); ?>
      <?= \Html::input_switch([
        'label' => 'Aktywny',
        'name' => 'status',
        'checked' => $this -> coupon['status'] == 1 ? true : false
      ]); ?>
      <?= \Html::input_switch( [
        'label'   => 'Użyty',
        'name'    => 'used',
        'checked' => $this -> coupon['used'] == 1 ? true : false,
      ]); ?>
      <?= \Html::select([
        'label' => 'Typ kuponu',
        'name' => 'type',
        'values' => [ 1 => 'Rabat procentowy na koszyk'],
        'value' => $this -> coupo['type'],
      ]); ?>
      <?= \Html::input([
        'label' => 'Wartość',
        'class' => 'number-format',
        'name' => 'amount',
        'id' => 'amount',
        'value' => $this -> coupon['amount']
      ]); ?>
      <?= \Html::input_switch([
        'label' => 'Kupon jednorazowy',
        'name' => 'one_time',
        'checked' => $this -> coupon['one_time'] == 1 ? true : false
      ]); ?>
      <?= \Html::input_switch([
        'label'   => 'Dotyczy również produktów przecenionych',
        'name'    => 'include_discounted_product',
        'checked' => $this -> coupon['include_discounted_product'] == 1 ? true : false,
      ]); ?>
      <div class="form-group row">
        <label class="col-lg-4 control-label">Ogranicz promocję do wybranych kategorii:</label>
        <div class="col-lg-8">
          <div class="menu_sortable">
            <ol class="sortable" id="sortable">
              <?
              if ( is_array( $this -> categories ) )
              {
                foreach ( $this -> categories as $category )
                {
                  ?>
                  <li id="list_<?= $category[ 'id' ];?>" class="category_<?= $category[ 'id' ];?>" category="<?= $category[ 'id' ];?>">
                    <div class="context_0 content content_menu">
                      <span class="disclose"><span></span></span>
                      <? if ( !$category[ 'status' ] ) echo '<i class="fa fa-ban fa-lg text-danger" title="Kategoria nieaktywna"></i>';?>
                      <input type="checkbox" class="g-checkbox" name="categories[]" value="<?= $category[ 'id' ];?>" <? if ( is_array( json_decode( $this -> coupon['categories'] ) ) and in_array( $category[ 'id' ], json_decode( $this -> coupon['categories'] ) ) ):?>checked="checked"<? endif;?> />
                      <b><?= $category[ 'languages' ][ $this -> dlang ][ 'title' ];?></b>
                    </div>
                    <?=
                    \Tpl::view( 'shop-product/subcategories-list', [
                        'categories' => \admin\factory\ShopCategory::subcategories( $category[ 'id' ] ),
                        'product_categories' => json_decode( $this -> coupon['categories'] ),
                        'dlang' => $this -> dlang
                    ] );
                    ?>
                  </li>
                  <?
                }
              }
              ?>
            </ol>
          </div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
  </div>
</div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid->id               = 'coupon-edit';
$grid->gdb_opt          = $gdb;
$grid->include_plugins  = true;
$grid->title            = $this -> coupon['id'] ? 'Edycja kuponu: <u>' . $this -> coupon['name'] . '</u>' : 'Nowy kupon';
$grid->fields           = [
  [
    'db' => 'id',
    'type' => 'hidden',
    'value' => $this -> coupon['id']
  ]
];
$grid->actions          = [
  'save' => ['url' => '/admin/shop_coupon/coupon_save/', 'back_url' => '/admin/shop_coupon/view_list/'],
  'cancel' => ['url' => '/admin/shop_coupon/view_list/']
];
$grid->external_code    = $out;
$grid->persist_edit     = true;
$grid->id_param         = 'id';

echo $grid->draw();
?>

<link type="text/css" rel="stylesheet" href="/libraries/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css">
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.css">
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.default.css">

<script type="text/javascript" src="/libraries/plupload/plupload.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html4.js"></script>
<script type="text/javascript" src="/libraries/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/libraries/plupload/i18n/pl.js"></script>
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>
<script type="text/javascript" src="/libraries/selectize/js/standalone/selectize.js"></script>

<script type="text/javascript">
  $(function() {
    const observer = lozad();
    observer.observe();

    disable_menu();

    $('#settings-tabs').easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'settings-tabs',
      type: 'vertical'
    });
  });
</script>