<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'] == $this->dlang ) 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>
                  <?= \Shared\Html\Html::input(
                              array(
                                'label'   => 'Nazwa kategorii',
                                'name'    => 'title[' . $lg['id'] . ']',
                                'id'      => 'title_' . $lg['id'],
                                'value'   => $this -> category[ 'languages' ][ $lg['id'] ]['title'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Shared\Html\Html::textarea(
                              array(
                                'label'   => 'Opis kategorii',
                                'name'    => 'text[' . $lg['id'] . ']',
                                'id'      => 'text_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['text'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Shared\Html\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
                              )
                          );?>
                  <?= \Shared\Html\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;">
        <?= \Shared\Html\Html::input_switch(
            array(
              'label'   => 'Aktywna',
              'name'    => 'status',
              'checked' => $this -> category['status'] == 1 or !$this -> category['id'] ? true : false
            )
        );?>
        <?= \Shared\Html\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']
          ]
        );?>
        <?= \Shared\Html\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'] == $this->dlang ) 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>
                  <?= \Shared\Html\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'] . ' );'
                              )
                          );?>
                  <?= \Shared\Html\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']
                              )
                          );?>
                  <?= \Shared\Html\Html::input(
                              array(
                                'label'   => 'Meta title',
                                'name'    => 'meta_title[' . $lg['id'] . ']',
                                'id'      => 'meta_title_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_title']
                              )
                          );?>
                  <?= \Shared\Html\Html::textarea(
                              array(
                                'label'   => 'Meta description',
                                'name'    => 'meta_description[' . $lg['id'] . ']',
                                'id'      => 'meta_description_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_description']
                              )
                          );?>
                  <?= \Shared\Html\Html::textarea(
                              array(
                                'label'   => 'Meta keywords',
                                'name'    => 'meta_keywords[' . $lg['id'] . ']',
                                'id'      => 'meta_keywords_' . $lg['id'],
                                'value'   => $this -> category['languages'][ $lg['id'] ]['meta_keywords']
                              )
                          );?>
                  <?= \Shared\Html\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();

$gridId = 'category-edit';
$gridTitle = 'Edycja kategorii';
$gridSaveUrl = '/admin/shop_category/save/';
$gridBackUrl = '/admin/shop_category/view_list/';
$gridHidden = [
  ['name' => 'id', 'value' => $this -> category['id']],
  ['name' => 'parent_id', 'value' => $this -> category['id'] ? $this -> category['parent_id'] : $this -> pid]
];
$gridContent = $out;
$gridPersist = true;
include __DIR__ . '/../components/grid-edit-replacement.php';
?>

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

