<? global $user, $settings;?>
<!DOCTYPE html>
<html>
  <head>
    <title>shopPro</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="www.project-pro.pl - internetowe rozwi&#261;zania dla biznesu">
    <link rel='stylesheet' type="text/css" href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700'>
    <link rel="stylesheet" type="text/css" href="/libraries/framework/skin/default_skin/css/theme.css">
    <link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/magnific/magnific-popup.css">
    <link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/datepicker/css/bootstrap-datetimepicker.css">
    <link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/jquery/jquery_ui/jquery-ui.structure.min.css">
    <link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/jquery/jquery_ui/jquery-ui.theme.min.css">
    <link rel="stylesheet" type="text/css" href="/libraries/framework/vendor/plugins/daterange/daterangepicker.css">
    <link rel="stylesheet" type="text/css" href="/libraries/jquery-confirm/jquery-confirm.min.css">
    <link rel="stylesheet" type="text/css" href="/libraries/easy-tabs/css/easy-responsive-tabs.css">
    <link rel="stylesheet" type="text/css" href="/libraries/bootstrap-4.5.2-dist/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/libraries/font-awesome-4.7.0/css/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="/libraries/grid/plugins/icheck/skins/square/blue.css">
    <script type="text/javascript" src="/libraries/framework/vendor/jquery/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/jquery/jquery_ui/jquery-ui.min.js"></script>
    <script type="text/javascript" src="/libraries/framework/js/utility/utility.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/plugins/magnific/jquery.magnific-popup.js"></script>
    <script type="text/javascript" src="/libraries/easy-tabs/js/easyResponsiveTabs.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/plugins/moment/moment.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/plugins/moment/pl.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/plugins/datepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="/libraries/framework/vendor/plugins/daterange/daterangepicker.js"></script>
    <script type="text/javascript" src="/libraries/jquery-confirm/jquery-confirm.min.js"></script>
    <script type="text/javascript" src="/libraries/bootstrap-4.5.2-dist/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/libraries/bootstrap-4.5.2-dist/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="/libraries/grid/plugins/icheck/icheck.js"></script>
    <script type="text/javascript" src="/libraries/functions.js"></script>
    <script type="text/javascript" src="/admin/js/functions.js"></script>
    <link rel="stylesheet" href="/admin/layout/style-css/style.css" />
  </head>
  <body>
    <div class="admin-page">
      <div class="menu">
        <div class="logo sticky-top">
          shop<b>Pro</b>
          <span>ver. <?= \Shared\Helpers\Helpers::get_version();?></span><br>
          <? if ( $settings[ 'update' ] and \Shared\Helpers\Helpers::get_new_version() > \Shared\Helpers\Helpers::get_version() ):?>
            <a href="/admin/update/main_view/" class="label label-danger">aktualizacja</a>
          <? endif;?>
        </div>
        <div class="menu-content">
          <ul>
            <li><a href="/admin/dashboard/main_view/"><img src="/admin/layout/icon/icon-menu/bxs-dashboard.svg">Pulpit</a></li>
          </ul>
          <div class="title">
            Sklep
          </div>
          <ul>
            <li> <a href="/admin/shop_order/list/"><img src="/admin/layout/icon/icon-menu/shopping-cart.svg">Zam&#243;wienia</a></li>
            <li> <a href="/admin/shop_clients/list/"><img src="/admin/layout/icon/icon-menu/people-fill.svg">Klienci</a></li>
            <li><a href="/admin/shop_category/list/"><img src="/admin/layout/icon/icon-menu/bxs-category-alt.svg">Kategorie</a></li>
            <li><a  href="/admin/shop_product/view_list/"><img src="/admin/layout/icon/icon-menu/shopping-basket.svg">Produkty</a></li>
            <li><a href="/admin/shop_product/mass_edit/"><i class="fa fa-bars"></i>Masowa edycja</a></li>
            <li>
              <a href="/admin/shop_producer/list/">
                <i class="fa fa-user"></i>Producenci
              </a>
            </li>
            <li>
              <a  href="/admin/shop_product_sets/list/">
                <i class="fa fa-bars"></i>Komplety Produkt&#243;w
              </a>
            </li>
            <li><a href="/admin/shop_attribute/list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produkt&#243;w</a></li>
            <li><a href="/admin/shop_transport/list/"><img src="/admin/layout/icon/icon-menu/bus.svg">Rodzaje transportu</a></li>
            <li><a href="/admin/shop_payment_method/list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody p&#322;atno&#347;ci</a></li>
            <li>
              <a href="/admin/shop_statuses/list/"><i class="fa fa-bars"></i>Statusy zam&#243;wie&#324;</a>
            </li>
            <li><a href="/admin/shop_coupon/list/"><img src="/admin/layout/icon/icon-menu/piggy-bank-coins.svg">Kody rabatowe</a></li>
            <li><a href="/admin/shop_promotion/list/"><img src="/admin/layout/icon/icon-menu/burst-sale.svg">Promocje</a></li>
          </ul>
          <div class="title">Zawarto&#347;&#263;</div>
          <ul>
            <li><a href="/admin/pages/list/"><img src="/admin/layout/icon/icon-menu/menu(1).svg">Konfiguracja menu</a></li>
            <li><a href="/admin/articles/list/"><img src="/admin/layout/icon/icon-menu/note.svg">Artyku&#322;y</a></li>
            <li><a href="/admin/articles_archive/list/"><img src="/admin/layout/icon/icon-menu/baseline-sticky-note-2.svg">Archiwum artyku&#322;&#243;w</a></li>
            <li><a href="/admin/scontainers/list/"><img src="/admin/layout/icon/icon-menu/view-cols.svg">Zawarto&#347;&#263; statyczna</a></li>
          </ul>
          <div class="title">
            Newsletter
          </div>
          <ul>
            <li><a href="/admin/newsletter/emails_list/"><img src="/admin/layout/icon/icon-menu/bx-at.svg">Baza emaili</a></li>
            <li><a href="/admin/newsletter/email_templates_admin/"><img src="/admin/layout/icon/icon-menu/template.svg">Szablony administracyjne</a></li>
            <li><a href="/admin/newsletter/settings/"><img src="/admin/layout/icon/icon-menu/baseline-settings.svg">Ustawienia</a></li>
          </ul>
          <div class="title">
            Pozosta&#322;e
          </div>
          <ul>
            <li><a href="/admin/filemanager/draw/"><img src="/admin/layout/icon/icon-menu/file-image-outlined.svg">Menad&#380;er plik&#243;w</a></li>
            <li><a  href="/admin/banners/list/"><img src="/admin/layout/icon/icon-menu/photo-video.svg">Banery</a></li>
          </ul>
          <div class="title">
            Konfiguracja
          </div>
          <ul>
            <li><a href="/admin/users/view_list/"><img src="/admin/layout/icon/icon-menu/people-fill.svg">U&#380;ytkownicy</a></li>
            <li><a href="/admin/languages/view_list/"><img src="/admin/layout/icon/icon-menu/letter-aa.svg">J&#281;zyki</a></li>
            <li><a href="/admin/languages/translation_list/"><img src="/admin/layout/icon/icon-menu/language.svg">T&#322;umaczenia</a></li>
            <li><a href="/admin/settings/view/"><img src="/admin/layout/icon/icon-menu/baseline-settings.svg">Ustawienia</a></li>
            <li><a href="/admin/layouts/list/"><img src="/admin/layout/icon/icon-menu/calendar-settings.svg">Szablony</a></li>
          </ul>
          <div class="title">
            S&#322;owniki
          </div>
          <ul>
            <li>
              <a href="/admin/dictionaries/list/">
                <i class="fa fa-puzzle-piece" aria-hidden="true"></i>Jednostki miary
              </a>
            </li>
          </ul>
          <div class="title">
            Archiwum
          </div>
          <ul>
            <li>
              <a href="/admin/product_archive/list/">
                <i class="fa fa-trash" aria-hidden="true"></i>Produkty
              </a>
            </li>
          </ul>
          <div class="title">
            Integracje
          </div>
          <ul>
            <li>
              <a href="/admin/integrations/apilo_settings/">
                <i class="fa fa-cogs" aria-hidden="true"></i>apilo.com
              </a>
            </li>
            <li>
              <a href="/admin/integrations/shoppro_settings/">
                <i class="fa fa-cogs" aria-hidden="true"></i>shopPRO
              </a>
            </li>
          </ul>
        </div>
        <div class="preview">
          <a href="/" target="_blank"><img src="/admin/layout/icon/icon-menu/chevrons-right.svg">Podgl&#261;d</a>
        </div>
      </div>
      <div class="mobile-menu-btn" id="mobile-menu-btn">
        <i class="fa fa-bars"></i>
      </div>
      <div class="site-content">
        <div class="container-fluid">
          <div class="row">
            <div class="col-12 col-md-3 col-lg-2">
              <button id="clear-cache-btn" class="btn btn-danger mt-3">Wyczy&#347;&#263; cache</button>
            </div>
            <div class="col-12 col-md-6 col-lg-7 mt-3">
              <div class="admin-global-search" id="admin-global-search-wrap">
                <input
                  type="text"
                  id="admin-global-search-input"
                  class="form-control"
                  placeholder="Szukaj produktu (EAN, Nazwa, SKU) lub zamówienia (email, imię, nazwisko, telefon, numer)"
                  autocomplete="off"
                >
                <div class="admin-global-search-results" id="admin-global-search-results"></div>
              </div>
            </div>
            <div class="col-12 col-md-3 col-lg-3 top-user">
              <div class="dropdown">
                <?
                if ( $user[ 'name' ] or $user[ 'surname' ] )
                  echo $user[ 'surname' ] . ' ' . $user[ 'name' ];
                else
                  echo $user[ 'login' ];
                ?>
                <img src="/admin/layout/icon/user-avatar-filled.svg" alt="avatar"  >
                <div class="dropdown-content">
                  <a href="/admin/?s-action=user-logout"><span class="fa fa-power-off"></span>Wyloguj si&#281;</a>
                </div>
              </div>
            </div>
          </div>
          <?
          if ( $alert = \Shared\Helpers\Helpers::get_session( 'alert' ) ):
            \Shared\Helpers\Helpers::alert( false );
            ?>
            <div class="row">
              <div class=" col-12">
                <div class="alert alert-danger alert-dismissable">
                  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                  <i class="fa fa-info pr10"></i>
                  <?= $alert;?>
                </div>
              </div>
            </div>
          <? endif;?>
          <div class="row">
            <div class="col-12 dashboard-page" id="content">
              <?= $this -> content;?>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script class="footer" type="text/javascript">
      (function() {
        function bindClearCacheButton() {
          $(document)
            .off('click.clearCacheBtn', '#clear-cache-btn')
            .on('click.clearCacheBtn', '#clear-cache-btn', function(e) {
              e.preventDefault();

              var $btn = $(this);
              var originalText = $btn.text();

              // Show pending state
              $btn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Czyszcz\u0119 cache...');

              // Send AJAX request
              $.ajax({
                url: '/admin/settings/clearCacheAjax/',
                type: 'POST',
                dataType: 'json',
                success: function(response) {
                  if (response.status === 'success') {
                    // Show success state
                    $btn.html('<i class="fa fa-check"></i> Cache wyczyszczony!').removeClass('btn-danger').addClass('btn-success');

                    // Restore original state after delay
                    setTimeout(function() {
                      $btn.prop('disabled', false).html(originalText).removeClass('btn-success').addClass('btn-danger');
                    }, 2000);
                  } else {
                    // Request failed on server
                    $btn.html('<i class="fa fa-exclamation-triangle"></i> B\u0142\u0105d!').removeClass('btn-danger').addClass('btn-warning');
                    setTimeout(function() {
                      $btn.prop('disabled', false).html(originalText).removeClass('btn-warning').addClass('btn-danger');
                    }, 2000);
                  }
                },
                error: function() {
                  // Network or transport error
                  $btn.html('<i class="fa fa-exclamation-triangle"></i> B\u0142\u0105d po\u0142\u0105czenia!').removeClass('btn-danger').addClass('btn-warning');
                  setTimeout(function() {
                    $btn.prop('disabled', false).html(originalText).removeClass('btn-warning').addClass('btn-danger');
                  }, 2000);
                }
              });
            });
        }

        bindClearCacheButton();
      })();

      (function() {
        var $input = $('#admin-global-search-input');
        var $results = $('#admin-global-search-results');
        var $wrap = $('#admin-global-search-wrap');
        var timer = null;

        function escapeHtml(value) {
          return $('<div>').text(value || '').html();
        }

        function hideResults() {
          $results.removeClass('open').empty();
        }

        function renderResults(items) {
          if (!Array.isArray(items) || items.length === 0) {
            $results
              .html('<div class="admin-global-search-empty">Brak wyników</div>')
              .addClass('open');
            return;
          }

          var html = '';
          items.forEach(function(item) {
            var title = escapeHtml(item.title || '');
            var subtitle = escapeHtml(item.subtitle || '');
            var type = item.type === 'order' ? 'Zamówienie' : 'Produkt';
            var url = escapeHtml(item.url || '#');

            html += ''
              + '<a class="admin-global-search-item" href="' + url + '">'
              + '  <div class="admin-global-search-item-title">' + title + '</div>'
              + '  <div class="admin-global-search-item-subtitle">' + escapeHtml(type) + (subtitle ? ' | ' + subtitle : '') + '</div>'
              + '</a>';
          });

          $results.html(html).addClass('open');
        }

        function searchNow() {
          var phrase = ($input.val() || '').trim();
          if (phrase.length < 2) {
            hideResults();
            return;
          }

          $results.html('<div class="admin-global-search-empty">Szukam...</div>').addClass('open');

          $.ajax({
            url: '/admin/settings/globalSearchAjax/',
            type: 'GET',
            dataType: 'json',
            data: { q: phrase },
            success: function(response) {
              if (!response || response.status !== 'ok') {
                $results.html('<div class="admin-global-search-empty">Wystąpił błąd wyszukiwania</div>').addClass('open');
                return;
              }

              renderResults(response.items || []);
            },
            error: function() {
              $results.html('<div class="admin-global-search-empty">Błąd połączenia</div>').addClass('open');
            }
          });
        }

        $(document)
          .off('input.adminGlobalSearch', '#admin-global-search-input')
          .on('input.adminGlobalSearch', '#admin-global-search-input', function() {
            clearTimeout(timer);
            timer = setTimeout(searchNow, 250);
          });

        $(document)
          .off('focus.adminGlobalSearch', '#admin-global-search-input')
          .on('focus.adminGlobalSearch', '#admin-global-search-input', function() {
            if (($input.val() || '').trim().length >= 2 && $results.children().length > 0) {
              $results.addClass('open');
            }
          });

        $(document)
          .off('click.adminGlobalSearch')
          .on('click.adminGlobalSearch', function(e) {
            if ($wrap.length === 0) {
              return;
            }

            if ($(e.target).closest('#admin-global-search-wrap').length === 0) {
              hideResults();
            }
          });
      })();

      $(document).ready(function () {
        var user_agent 	= navigator.userAgent.toLowerCase();
        var click_event = user_agent.match(/(iphone|ipod|ipad)/)  ? "touchend" : "click";
        $('body').on(click_event, '#mobile-menu-btn', function ()
        {
          if ($(this).hasClass('active'))
          {
            $(this).removeClass('active');
            $( '.menu' ).removeClass( 'visible' );
              $( '#mobile-menu-btn i' ).addClass( 'fa-bars' ).removeClass( 'fa-times' );
            $( '.site-content' ).removeClass( 'with-menu' );
          }
          else
          {
            $(this).addClass('active');
            $( '.menu' ).addClass( 'visible' );
            $( '.site-content' ).addClass( 'with-menu' );
              $( '#mobile-menu-btn i' ).addClass( 'fa-times' ).removeClass( 'fa-bars' );
          }
        });

      });
    </script>
    <style type="text/css">
      .admin-global-search {
        position: relative;
        max-width: 900px;
      }

      .admin-global-search-results {
        display: none;
        position: absolute;
        left: 0;
        right: 0;
        top: calc(100% + 4px);
        z-index: 9999;
        background: #fff;
        border: 1px solid #e5e5e5;
        border-radius: 4px;
        max-height: 420px;
        overflow: auto;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
      }

      .admin-global-search-results.open {
        display: block;
      }

      .admin-global-search-item {
        display: block;
        padding: 10px 12px;
        border-bottom: 1px solid #f1f1f1;
        color: #333;
        text-decoration: none;
      }

      .admin-global-search-item:hover,
      .admin-global-search-item:focus {
        background: #f7f9fc;
        color: #222;
        text-decoration: none;
      }

      .admin-global-search-item-title {
        font-weight: 600;
        margin-bottom: 2px;
      }

      .admin-global-search-item-subtitle {
        font-size: 12px;
        color: #6c757d;
        line-height: 1.3;
      }

      .admin-global-search-empty {
        padding: 10px 12px;
        color: #6c757d;
        font-size: 13px;
      }
    </style>
  </body>
</html>
