{% extends "/layouts/main.twig" %}
{% set active_menu = 'settings' %}

{% set xdata = 'settings' %}
{% block title p__('title', 'Storage settings')|title %}

{% block template %}
<div>
  {% include "snippets/back.twig" with {link: 'admin/settings', label: 'Settings'} %}

  <h1 class="mt-4">{{ p__('heading', 'Storage settings') }}</h1>
</div>

<x-form>
  <form class="flex flex-col gap-8" @submit.prevent="submit" x-ref="form">
    <div class="flex flex-col gap-2">
      <section class="grid gap-6 box" data-density="comfortable">
        <h2>{{ p__('heading', 'Configuration') }}</h2>

        <div>
          <label for="cdn.adapter">
            {{ p__('label', 'Adapter') }}
          </label>

          <select id="cdn.adapter" name="cdn[adapter]" class="mt-2 input">
            {% for key, adapter in cdn_adapters %}
            <option value="{{ key }}"
              {{ option.cdn.adapter is defined and option.cdn.adapter == key ? 'selected' : '' }}>
              {{ adapter.name }}
            </option>
            {% endfor %}
          </select>

          <ul
            class="m-3 mb-0 text-xs list-disc list-inside text-content-dimmed">
            <li>
              {{ __('Switching CDN adapter won\'t synchronize current files.') }}
            </li>

            <li>
              {{ __('Selected adapter must be enabled') }}
            </li>
          </ul>
        </div>

        <div>
          <div class="flex gap-2 items-center p-3 rounded-lg bg-intermediate">
            {{ p__('label', 'Secure URLs') }}

            <i class="text-base cursor-auto ti ti-test-pipe text-content-dimmed hover:text-content"
              x-tooltip.raw="{{ __('Experimental') }}"></i>

            <label
              class="inline-flex gap-2 items-center ml-auto cursor-pointer">
              <input type="checkbox" name="cdn[sign_urls]" class="hidden peer"
                {{ option.cdn.sign_urls is defined and option.cdn.sign_urls ? 'checked' : '' }}>

              <span
                class="block relative w-10 h-6 rounded-3xl transition-all bg-line peer-checked:bg-success after:h-5 after:w-5 after:top-0.5 after:absolute after:left-0 after:ml-0.5 after:transition-all after:rounded-full after:bg-white peer-checked:after:left-4"></span>

              <span class="text-content-dimmed peer-checked:hidden">
                {{ __('Off') }}
              </span>

              <span class="hidden text-success peer-checked:inline">
                {{ __('On') }}
              </span>
            </label>
          </div>

          <ul
            class="flex flex-col gap-1 m-3 mb-0 text-xs list-disc list-inside text-content-dimmed">

            <li>
              {{ __('Secure URLs will generate temporary signed URLs for private files.') }}
              <a href="https://docs.aikeedo.com/advanced/secure-urls"
                class="inline-flex gap-1 items-center text-content hover:underline"
                target="_blank">
                {{ __('Learn more') }}
                <i class="text-xs ti ti-external-link"></i>
              </a>
            </li>
          </ul>
        </div>
      </section>
    </div>

    <div class="flex gap-4 justify-end">
      <a href="admin/settings" class="button button-outline">
        {{ p__('button', 'Cancel') }}
      </a>

      <button type="submit" class="button button-accent"
        :processing="isProcessing">
        {% include "/snippets/spinner.twig" %}

        {{ p__('button', 'Save changes') }}
      </button>
    </div>
  </form>
</x-form>
{% endblock %}