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

ob_start();
?>
  <div id="settings-tabs">
    <ul class="resp-tabs-list settings-tabs">
      <li><i class="fa fa-file"></i>TreĹ›Ä‡</li>
      <li><i class="fa fa-wrench"></i>Ustawienia</li>
      <li><i class="fa fa-globe"></i>SEO</li>
    </ul>
    <div class="resp-tabs-container settings-tabs">
      <div>
        <div id="languages-main">
          <ul class="resp-tabs-list languages-main htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="JÄ™zyk domyĹ›lny"></i> ';?><?= $lg['name'];?></a></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::input(
                              array(
                                'label'   => 'Nazwa kategorii',
                                'name'    => 'title[' . $lg['id'] . ']',
                                'id'      => 'title_' . $lg['id'],
                                'value'   => $this -> category[ 'languages' ][ $lg['id'] ]['title'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Opis kategorii',
                                'name'    => 'text[' . $lg['id'] . ']',
                                'id'      => 'text_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['text'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Opis kategorii (rozwiniÄ™cie)',
                                'name'    => 'text_hidden[' . $lg['id'] . ']',
                                'id'      => 'text_hidden_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['text_hidden'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea( [
                                'label' => 'Dodatkowy tekst (nad produktami)',
                                'name' => 'additional_text[' . $lg['id'] . ']',
                                'id' => 'additional_text_' . $lg['id'],
                                'value' => $this -> category['languages'][ $lg['id'] ]['additional_text'],
                                'inline' => true
                    ] );?>
                  <script type="text/javascript">
                    $( function() {
                      $( '#text_<?= $lg['id'];?>, #text_hidden_<?= $lg['id'];?>, #additional_text_<?= $lg['id'];?>' ).ckeditor( {
                        toolbar : 'MyToolbar',
                        height:'250'
                      });
                    });
                  </script>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div style="padding: 15px;">
        <?= \Html::input_switch(
            array(
              'label'   => 'Aktywna',
              'name'    => 'status',
              'checked' => $this -> category['status'] == 1 or !$this -> category['id'] ? true : false
            )
        );?>
        <?= \Html::select(
          [
            'label'   => 'Sortowanie produktĂłw',
            'name'    => 'sort_type',
            'id'      => 'sort_type',
            'values'  => is_array( $this -> sort_types ) ? $this -> sort_types : [],
            'value'   => $this -> category['sort_type']
          ]
        );?>
        <?= \Html::input_switch(
            array(
              'label'   => 'WyĹ›wietliÄ‡ podkategorie',
              'name'    => 'view_subcategories',
              'checked' => $this -> category['view_subcategories'] == 1 ? true : false
            )
        );?>
      </div>
      <div>
        <div id="languages-seo">
          <ul class="resp-tabs-list languages-seo htabs">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="JÄ™zyk domyĹ›lny"></i> ';?><?= $lg['name'];?></a></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-seo">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::input_icon(
                              array(
                                'label'         => 'Link SEO',
                                'name'          => 'seo_link[' . $lg['id'] . ']',
                                'id'            => 'seo_link_' . $lg['id'],
                                'value'         => $this -> category['languages' ][ $lg['id'] ]['seo_link'],
                                'icon_content'  => 'generuj',
                                'icon_js'       => 'generate_seo_links( "' . $lg['id'] . '", $( "#title_' . $lg['id'] . '" ).val(), ' . (int)$this -> category['id'] . ' );'
                              )
                          );?>
                  <?= \Html::input(
                              array(
                                'label' => 'TytuĹ‚ kategorii (h1)',
                                'name'  => 'category_title[' . $lg['id'] . ']',
                                'id'    => 'category_title_' . $lg['id'],
                                'value' => $this -> category['languages' ][ $lg['id'] ]['category_title']
                              )
                          );?>
                  <?= \Html::input(
                              array(
                                'label'   => 'Meta title',
                                'name'    => 'meta_title[' . $lg['id'] . ']',
                                'id'      => 'meta_title_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_title']
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Meta description',
                                'name'    => 'meta_description[' . $lg['id'] . ']',
                                'id'      => 'meta_description_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_description']
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Meta keywords',
                                'name'    => 'meta_keywords[' . $lg['id'] . ']',
                                'id'      => 'meta_keywords_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_keywords']
                              )
                          );?>
                  <?= \Html::select(
                              array(
                                'label'   => 'Blokuj indeksacjÄ™',
                                'name'    => 'noindex[' . $lg['id'] . ']',
                                'id'      => 'noindex_' . $lg['id'],
                                'values'  => array(
                                              0 => 'nie', 1 => 'tak'
                                            ),
                                'value' => $this -> category['languages'][ $lg['id'] ]['noindex'] == 1 ? 1 : 0
                              )
                          );?>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
  </div>
  <div class="clear"></div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id               = 'category-edit';
$grid -> gdb_opt          = $gdb;
$grid -> include_plugins  = true;
$grid -> title            = 'Edycja kategorii';
$grid -> fields           = [
                              [
                                'db' => 'id',
                                'type' => 'hidden',
                                'value' => $this -> category['id']
                              ],
                              [
                                'db' => 'parent_id',
                                'type' => 'hidden',
                                'value' => $this -> category['id'] ? $this -> category['parent_id'] : $this -> pid
                              ]
                            ];
$grid -> actions          = [
                              'save' => [ 'url' => '/admin/shop_category/save/', 'back_url' => '/admin/shop_category/view_list/' ],
                              'cancel' => [ 'url' => '/admin/shop_category/view_list/' ]
                            ];
$grid -> external_code    = $out;
$grid -> persist_edit     = true;
$grid -> id_param         = 'id';

echo $grid -> draw();
?>

<?= \Tpl::view( 'shop-category/category-edit-custom-script' ); ?>

