<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
  $( function()
  {
    $( '#settings-tabs' ).easyResponsiveTabs(
    {
      width: 'auto',
      fit: true,
      tabidentify: 'settings-tabs',
      type: 'vertical'
    });

    $('#languages-main').easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-main'
    });

    $( '#additional_info, #shop_bank_account_info' ).ckeditor(
    {
      toolbar: 'MyTool',
      height: '150'
    });
  });
</script>
<?
global $db;

ob_start();
?>
  <div id="settings-tabs">
    <ul class="resp-tabs-list settings-tabs">
      <li><i class="fa fa-paper-plane"></i>Dane kontaktowe</li>
      <li><i class="fa fa-dollar"></i>Sklep</li>
      <li><i class="fa fa-shopping-cart"></i>Produkty</li>
      <li><i class="fa fa-envelope"></i>Poczta</li>
      <li><i class="fa fa-bars"></i>Pozostałe</li>
      <li><i class="fa fa-cog"></i>System</li>
      <li><i class="fa fa-line-chart"></i>Konwersje</li>
    </ul>
    <div class="resp-tabs-container settings-tabs">
      <div>
        <?= \Html::input(
                    array(
                      'label'   => 'Nazwa firmy',
                      'name'    => 'firm_name',
                      'id'      => 'firm_name',
                      'value'   => $this -> settings['firm_name']
                    )
                );?>
        <?= \Html::textarea(
                    array(
                      'label'   => 'Dodatkowe informacje',
                      'name'    => 'additional_info',
                      'id'      => 'additional_info',
                      'value'   => $this -> settings['additional_info']
                    )
                );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Mapa',
                      'name'    => 'google_maps',
                      'checked' => $this -> settings['google_maps'] == 1 ? true : false
                    )
                );?>
        <?= \Html::textarea(
                    array(
                      'label'   => 'Mapa - adres',
                      'name'    => 'firm_adress',
                      'id'      => 'firm_adress',
                      'value'   => $this -> settings['firm_adress']
                    )
                );?>
      </div>
      <div>
        <?= \Html::textarea(
                    array(
                      'label'     => 'Dane do przelewu',
                      'name'      => 'shop_bank_account_info',
                      'id'        => 'shop_bank_account_info',
                      'value'     => $this -> settings['shop_bank_account_info'],
                      'rows'      => 10,
                      'ckeditor'  => true
                    )
                );?>
        <?= \Html::input( [
                      'label'   => 'Klucz API HotPay',
                      'name'    => 'hotpay_api',
                      'id'      => 'hotpay_api',
                      'value'   => $this -> settings['hotpay_api']
                    ] );?>
        <?= \Html::input_switch( [
                      'label'   => 'Tpay.com - tryb sandbox',
                      'name'    => 'tpay_sandbox',
                      'checked' => $this -> settings['tpay_sandbox'] == 1 ? true : false
                    ] );?>
        <?= \Html::input( [
                      'label'   => 'Tpay.com ID',
                      'name'    => 'tpay_id',
                      'id'      => 'tpay_id',
                      'value'   => $this -> settings['tpay_id']
                    ] );?>
        <?= \Html::input( [
                      'label'   => 'Tpay.com - kod bezpieczeństwa',
                      'name'    => 'tpay_security_code',
                      'id'      => 'tpay_security_code',
                      'value'   => $this -> settings['tpay_security_code']
                    ] );?>
        <?= \Html::input_switch( [
                      'label'   => 'Przelewy24.pl - tryb sandbox',
                      'name'    => 'przelewy24_sandbox',
                      'checked' => $this -> settings['przelewy24_sandbox'] == 1 ? true : false
                    ] );?>
        <?= \Html::input( [
                      'label'   => 'Przelewy24.pl - merchant ID',
                      'name'    => 'przelewy24_merchant_id',
                      'id'      => 'przelewy24_merchant_id',
                      'value'   => $this -> settings['przelewy24_merchant_id']
                    ] );?>
        <?= \Html::input( [
                      'label'   => 'Przelewy24.pl - klucz CRC',
                      'name'    => 'przelewy24_crc_key',
                      'id'      => 'przelewy24_crc_key',
                      'value'   => $this -> settings['przelewy24_crc_key']
                    ] );?>
        <?= \Html::input( [
              'label'   => 'Darmowa dostawa od',
              'class' => 'number-format',
              'name'    => 'free_delivery',
              'id'      => 'free_delivery',
              'value'   => $this -> settings['free_delivery']
            ] );?>
        <?= \Html::textarea( [
                      'label' => 'Ankieta Ekomi',
                      'name' => 'ekomi_survey',
                      'id' => 'ekomi_survey',
                      'value' => $this -> settings['ekomi_survey'],
                      'rows' => 10
                    ] );?>
      </div>
      <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 ):?>
              <?
                $languages = array();

                $languages[''] = '---- wersja językowa ----';
                if ( is_array( $this -> languages ) ) foreach ( $this -> languages as $lg_tmp )
                {
                  if ( $lg_tmp['id'] != $lg['id'] )
                    $languages[ $lg_tmp['id'] ] = $lg_tmp['name'];
                }
              ?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::input(
                              array(
                                'label'   => 'Komunikat gdy stan magazynowy równy 0',
                                'name'    => 'warehouse_message_zero[' . $lg['id'] . ']',
                                'id'      => 'warehouse_message_zero_' . $lg['id'],
                                'value'   => $this -> settings[ 'warehouse_message_zero_' . $lg['id'] ],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::input(
                              array(
                                'label'   => 'Komunikat gdy stan magazynowy większy niż 0',
                                'name'    => 'warehouse_message_nonzero[' . $lg['id'] . ']',
                                'id'      => 'warehouse_message_nonzero_' . $lg['id'],
                                'value'   => $this -> settings[ 'warehouse_message_nonzero_' . $lg['id'] ],
                                'inline'  => true
                              )
                          );?>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Formularz kontaktowy',
                      'name'    => 'contact_form',
                      'checked' => $this -> settings['contact_form'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input(
                    array(
                      'label'   => 'Email kontaktowy',
                      'name'    => 'contact_email',
                      'id'      => 'contact_email',
                      'value'   => $this -> settings['contact_email']
                    )
                );?>
        <?= \Html::input(
                    array(
                      'label'   => 'Email - host',
                      'name'    => 'email_host',
                      'id'      => 'email_host',
                      'value'   => $this -> settings['email_host']
                    )
                );?>
        <?= \Html::input(
                    array(
                      'label'   => 'Email - port',
                      'name'    => 'email_port',
                      'id'      => 'email_port',
                      'value'   => $this -> settings['email_port']
                    )
                );?>
        <?= \Html::input(
                    array(
                      'label'   => 'Email - login',
                      'name'    => 'email_login',
                      'id'      => 'email_login',
                      'value'   => $this -> settings['email_login']
                    )
                );?>
        <?= \Html::input(
                    array(
                      'label'   => 'Email - hasło',
                      'name'    => 'email_password',
                      'id'      => 'email_password',
                      'value'   => $this -> settings['email_password']
                    )
                );?>
      </div>
      <div>
        <?= \Html::input(
                    array(
                      'label'   => 'Facebook link',
                      'name'    => 'facebook_link',
                      'id'      => 'facebook_link',
                      'value'   => $this -> settings['facebook_link']
                    )
                );?>
        <?= Html::input( [
                          'label' => 'Piksel Facebook',
                          'name'  => 'piksel',
                          'id' => 'piksel',
                          'value' => $this -> settings['piksel']
                        ]
          );
        ?>
        <?= \Html::textarea(
                    array(
                      'label'   => 'Kod statystyk',
                      'name'    => 'statistic_code',
                      'id'      => 'statistic_code',
                      'value'   => $this -> settings['statistic_code'],
                      'rows'    => 10
                    )
                );?>
        <?= \Html::textarea(
                    array(
                      'label'   => 'Własne reguły htacess',
                      'name'    => 'htaccess',
                      'id'      => 'htaccess',
                      'value'   => $this -> settings['htaccess'],
                      'rows'    => 10
                    )
                );?>
        <?= \Html::textarea(
                    array(
                      'label'   => 'Własne reguły robots.txt',
                      'name'    => 'robots',
                      'id'      => 'robots',
                      'value'   => $this -> settings['robots'],
                      'rows'    => 10
                    )
                );?>
      </div>
      <div>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Aktualizacja',
                      'name'    => 'update',
                      'checked' => $this -> settings['update'] == 1 ? true : false
                    )
                );?>
        <?= Html::input( [
                          'label' => 'Numer licencji',
                          'name'  => 'update_key',
                          'id'    => 'update_key',
                          'value' => $this -> settings['update_key']
                        ]
          );
        ?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Strona konstrukcyjna',
                      'name'    => 'devel',
                      'checked' => $this -> settings['devel'] == 1 ? true : false
                    )
                );?>
        <?= \Html::input_switch( [
          'label' => 'Lazy loading obrazów',
          'name' => 'lazy_loading',
          'checked' => $this -> settings['lazy_loading'] == 1 ? true : false
        ] );?>

        <?= \Html::input_switch( [
          'label' => 'Generowanie obrazków WEBP',
          'name' => 'generate_webp',
          'checked' => $this -> settings['generate_webp'] == 1 ? true : false
        ] );?>

        <?= \Html::input_switch( [
          'label' => 'Infinitescroll',
          'name' => 'infinitescroll',
          'checked' => $this -> settings['infinitescroll'] == 1 ? true : false
        ] );?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Htaccess cache',
                      'name'    => 'htaccess_cache',
                      'checked' => $this -> settings['htaccess_cache'] == 1 ? true : false
                    )
                );?>
      </div>
      <div>
        <?= Html::input( [
          'label' => 'Google Tag Manager - ID',
          'name'  => 'google_tag_manager_id',
          'id' => 'google_tag_manager_id',
          'value' => $this -> settings['google_tag_manager_id']
        ] ); ?>
      <?= \Html::textarea( [
        'label' => 'Własny kod GTM JS (bez tagu script)',
        'name' => 'own_gtm_js',
        'id' => 'own_gtm_js',
        'value' => $this -> settings['own_gtm_js'],
        'rows' => 10
      ] );?>
      <?= \Html::textarea( [
        'label' => 'Własny kod GTM HTML',
        'name' => 'own_gtm_html',
        'id' => 'own_gtm_html',
        'value' => $this -> settings['own_gtm_html'],
        'rows' => 10
      ] );?>
      </div>
  </div>
  <div class="clear"></div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id               = 'settings-edit';
$grid -> gdb_opt          = $gdb;
$grid -> include_plugins  = true;
$grid -> title            = 'Edycja ustawień';
$grid -> actions          = [
                              'save' => [ 'url' => '/admin/settings/settings_save/', 'back_url' => '/admin/settings/view/' ],
                            ];
$grid -> external_code    = $out;
echo $grid -> draw();
?>
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
<style type="text/css">#g-edit-cancel { display: none; }</style>
<script type="text/javascript">
  $( document).ready( function ()
  {
    $( '.popover-btn' ).popover(
    {
      trigger: 'hover',
      html: true
    });
  });
</script>