<table class="window">
  <tr>
    <td>
      <check if="{{!file_exists(@ROOT.'/app/api_config.php')}}">
      <div align="center">
        <div class="logo">
          <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 400.82 128.7">
              <defs>
                <linearGradient id="linear-gradient" x1="57.86" y1="49.36" x2="102.8" y2="78.95" gradientUnits="userSpaceOnUse">
                    <stop offset="0" stop-color="#e4006e"/>
                    <stop offset="1" stop-color="#474a98"/>
                </linearGradient>
                <linearGradient id="linear-gradient-2" x1="43.8" y1="34.14" x2="88" y2="59.61" gradientTransform="translate(-13.11 54.71) rotate(-45)" xlink:href="#linear-gradient"/>
              </defs>
              <polygon class="cls-1" points="80.73 43.18 80.73 64.42 59.49 64.42 59.49 85.67 80.73 85.67 101.98 85.67 101.98 64.42 101.98 43.18 80.73 43.18"/>
              <rect class="cls-2" x="48.86" y="32.55" width="21.25" height="21.25" transform="translate(47.95 -29.42) rotate(45)"/>
              <path class="cls-3" d="M130.91,43.27,120,85.67h7l2.7-10.94h19.62l2.91,10.94h7.3l-11.26-42.4ZM131.56,68l4.55-18.15h6.73L147.59,68Z"/>
              <path class="cls-3" d="M273,45.63a17.3,17.3,0,0,0-9.17-2.36H246.37v42.4h6.92v-14H264a17.37,17.37,0,0,0,7.21-1.51c5.15-2.33,8.27-6.22,8.6-11.93C280.1,52.74,277.69,48.5,273,45.63ZM263.31,65h-10V49.86h10.43a9.91,9.91,0,0,1,5.47,1.33A6.82,6.82,0,0,1,272.54,57a7.31,7.31,0,0,1-3.16,6.57A10.76,10.76,0,0,1,263.31,65Z"/>
              <path class="cls-3" d="M169.23,85.67h7V49.87l16.82,0V43.27H169.23Z"/>
              <polygon class="cls-3" points="317.12 43.27 282.28 43.27 282.28 49.86 296.2 49.86 296.2 85.67 303.22 85.67 303.22 49.86 317.12 49.86 317.12 43.27"/>
              <path class="cls-3" d="M216,42.9a21.18,21.18,0,0,0-15.36,6.29,20.41,20.41,0,0,0-6.43,15,20.52,20.52,0,0,0,7.05,16.13,21.94,21.94,0,0,0,29.93-.71,20.48,20.48,0,0,0,6.39-15.18A21.68,21.68,0,0,0,216,42.9Zm14.64,21.52a14.75,14.75,0,0,1-4.3,10.68,14.77,14.77,0,0,1-25.18-10.78,14.41,14.41,0,0,1,4.28-10.57,14.84,14.84,0,0,1,20.95,0A14.65,14.65,0,0,1,230.63,64.42Z"/>
              <path class="cls-3" d="M329.16,43.27l-10.93,42.4h7L328,74.73h19.61l2.91,10.94h7.3l-11.25-42.4ZM329.81,68l4.55-18.15h6.74L345.85,68Z"/>
          </svg>
        </div>
      </div>
      </check>
      <div class="frame_center settings_form">
        <h1>{{@page_data.title}}</h1>
        <check if="{{file_exists(@ROOT.'/app/api_config.php')}}">
          <check if="{{!@base_settings.autonomous}}">
            <true>
              <check if="{{!@api_data.domen}}">
        <p>Настройте API для синхронизации с сервисом Агорта или включите <a href="/settings/autonomous">автономный режим работы</a>.</p>
              </check>
            </true>
            <false>
        <p>Для синхронизации с сервисом Агорта выключите <a href="/settings/autonomous">автономный режим работы</a>.</p>
            </false>
          </check>
        </check>
        <form name="form_db_config" action="{{@URI}}" method="POST">
          <input type="hidden" name="count" value="{{@api_data.count?@api_data.count:500}}">
          <table width="100%">
            <tr>
              <td>
                <b>Адрес запроса (без https://)</b>*
              </td>
              <td align="right">
                <input type="text" class="apiset" name="domen" placeholder="Адрес запроса (пример: test.agorta.ru)" value="{{@api_data.domen?@api_data.domen:@GET.domen}}" autocomplete="off" required="true">
              </td>
            </tr>
            <tr>
              <td>
                <b>Секретный ключ</b>*
              </td>
              <td align="right">
                <input type="text" class="apiset" name="pass" placeholder="Секретный ключ" value="{{@api_data.pass?@api_data.pass:@GET.key}}" autocomplete="off" required="true">
                <p class="false settings_api_error"></p>
              </td>
            </tr>
            <tr class="api_settings hide">
              <td>
                <b>Склад</b>*
              </td>
              <td align="right">
                <select name="store_id"></select>
              </td>
            </tr>
            <tr class="api_settings hide">
              <td>
                <b>Имя кассы</b>*
              </td>
              <td align="right">
                <input type="text" name="rm_name" placeholder="Имя кассы" value="{{@api_data.rm_name}}" autocomplete="off" required="true">
                <input type="hidden" name="rm_id" value="{{@api_data.rm_id??uniqid('rm_')}}" autocomplete="off" required="true">
              </td>
            </tr>
            <tr class="api_settings hide">
              <td colspan="2">
                <p><small>Имя кассы должно быть уникальным, оно не должно совпадать с именами касс, действующих сейчас и действовавших ранее.</small></p>
              </td>
            </tr>
            <tr>
              <td colspan="2" align="center">
                * обязательное поле
              </td>
            </tr>
            <tr>
              <td colspan="2" align="center">
                <input type="submit" value="Сохранить">
                <check if="{{isset(@authorization_user.module) && in_array('settings/reset', @authorization_user.module)}}">
                <input type="button" value="Сбросить настройки" class="show_window" href="/messages/continue?uri={{urlencode("/settings/reset")}}">
                </check>
                <check if="{{!file_exists(@ROOT.'/app/api_config.php')}}">
                <a href="/settings/start"><input type="button" value="Назад"></a>
                {~@reg_link=@agorta_url.'/registration'~}
                {~if(mb_strpos(mb_strtolower(@SERVER['SERVER_SOFTWARE']), 'lighttpd')!==false || mb_strpos(mb_strtolower(@SERVER['SERVER_SOFTWARE']), 'ksweb')!==false)@reg_link.='?partner_id=10000'~}
                <p>Если у вас еще нет учетной записи в сервисе Агорта, то вы можете зарегистрироваться пройдя по ссылке <a href="{{@reg_link}}" target="_blank">
                {{@agorta_url}}</a></p>
                </check>
              </td>
            </tr>
          </table>
        </form>
      </div>
    </td>
  </tr>
</table>
<link rel="stylesheet" href="/ui/css/jquery-ui.css">
<script type="text/javascript" src="/ui/scripts/jquery-ui.js"></script>
<script type="text/javascript">
$("input[name='domen']").autocomplete({
  source: "/api/searchsubdomain",
  minLength: 2,
  select: function( event, ui ) {
    $("input[name='domen']").val(ui.label);
  },
  focus: function( event, ui ) {
    $("input[name='domen']").val(ui.label);
  }
});
</script>