<%
  const settingsLocaleCandidate = typeof lang === 'string'
    ? lang
    : (user && typeof user.lang === 'string' ? user.lang : 'ar');
  const settingsLocale = String(settingsLocaleCandidate).toLowerCase().startsWith('en') ? 'en' : 'ar';
  const settingsIsEnglish = settingsLocale === 'en';
  const settingsCopy = settingsIsEnglish
    ? {
      eyebrow: 'Platform settings',
      title: 'Settings',
      subtitle: 'Manage the platform’s core settings from an organized and secure workspace.',
      scopeLabel: 'Settings scope',
      scopeValue: '7 active sections',
      navigationEyebrow: 'Control paths',
      navigationTitle: 'Settings sections',
      navigationDescription: 'Choose a section to review its current configuration.',
      navigationLabel: 'Settings section navigation',
      activeLabel: 'Current',
      contentEyebrow: 'Current section',
      assuranceTitle: 'Independent update',
      assuranceDescription: 'Each section keeps its current save contract.',
    }
    : {
      eyebrow: 'إعدادات المنصة',
      title: 'الإعدادات',
      subtitle: 'إدارة إعدادات المنصة الأساسية من مساحة منظمة وآمنة.',
      scopeLabel: 'نطاق الإعدادات',
      scopeValue: '7 أقسام فعالة',
      navigationEyebrow: 'مسارات التحكم',
      navigationTitle: 'أقسام الإعدادات',
      navigationDescription: 'اختر القسم لمراجعة إعداداته الحالية.',
      navigationLabel: 'التنقل بين أقسام الإعدادات',
      activeLabel: 'الحالي',
      contentEyebrow: 'القسم الحالي',
      assuranceTitle: 'تحديث مستقل',
      assuranceDescription: 'يحتفظ كل قسم بعقد الحفظ الحالي.',
    };
  const settingsSections = settingsIsEnglish
    ? [
      {
        key: 'site',
        title: 'Site settings',
        helper: 'Identity, links, and core operation',
        icon: 'ti-adjustments-horizontal',
      },
      {
        key: 'about',
        title: 'About us',
        helper: 'Platform identity and introduction',
        icon: 'ti-info-circle',
      },
      {
        key: 'terms',
        title: 'Terms & conditions',
        helper: 'Policies and legal content',
        icon: 'ti-file-certificate',
      },
      {
        key: 'activation',
        title: 'Activation code',
        helper: 'Code generation policy',
        icon: 'ti-key',
      },
      {
        key: 'smtp',
        title: 'Email SMTP',
        helper: 'Operational email channel',
        icon: 'ti-mail-cog',
      },
      {
        key: 'orders',
        title: 'Order control',
        helper: 'Timings and cancellation policy',
        icon: 'ti-clock-cog',
      },
      {
        key: 'auctions',
        title: 'Auction settings',
        helper: 'Fees, bids, and payment windows',
        icon: 'ti-gavel',
      },
    ]
    : [
      {
        key: 'site',
        title: 'إعدادات الموقع',
        helper: 'الهوية والروابط والتشغيل الأساسي',
        icon: 'ti-adjustments-horizontal',
      },
      {
        key: 'about',
        title: 'من نحن',
        helper: 'هوية المنصة والمحتوى التعريفي',
        icon: 'ti-info-circle',
      },
      {
        key: 'terms',
        title: 'الشروط والأحكام',
        helper: 'السياسات والمحتوى القانوني',
        icon: 'ti-file-certificate',
      },
      {
        key: 'activation',
        title: 'كود التفعيل',
        helper: 'سياسة إنشاء أكواد التفعيل',
        icon: 'ti-key',
      },
      {
        key: 'smtp',
        title: 'البريد الإلكتروني SMTP',
        helper: 'قناة الإرسال والبريد التشغيلي',
        icon: 'ti-mail-cog',
      },
      {
        key: 'orders',
        title: 'التحكم في الطلبات',
        helper: 'المواعيد وسياسات الإلغاء',
        icon: 'ti-clock-cog',
      },
      {
        key: 'auctions',
        title: 'إعدادات المزادات',
        helper: 'الرسوم والمزايدات ومهل السداد',
        icon: 'ti-gavel',
      },
    ];
  const defaultSettingsSection = settingsSections[0];
  const safeSettingsSmtp = (
    typeof smtp !== 'undefined'
    && smtp
    && typeof smtp === 'object'
  )
    ? smtp
    : {
      _id: '',
      userName: '',
      password: '',
      emailSend: '',
      nameSend: '',
      host: '',
      encryption: '',
      port: '',
    };
%>

<link rel="stylesheet" href="/admin/assets/css/pages/settings.css?v=2.6.3.b1">

<section
  class="kt-settings-console"
  dir="<%= settingsIsEnglish ? 'ltr' : 'rtl' %>"
  data-settings-console
  data-settings-default-section="site"
  data-settings-theme-aware="light-dark-system"
>
  <div class="kt-settings-console__container">
    <header class="kt-settings-console__hero" data-settings-hero>
      <div class="kt-settings-console__hero-identity">
        <span class="kt-settings-console__hero-mark" aria-hidden="true">
          <i class="ti ti-settings-cog"></i>
        </span>

        <div class="kt-settings-console__hero-copy">
          <span class="kt-settings-console__eyebrow"><%= settingsCopy.eyebrow %></span>
          <h1><%= settingsCopy.title %></h1>
          <p><%= settingsCopy.subtitle %></p>
        </div>
      </div>

      <aside class="kt-settings-console__scope" aria-label="<%= settingsCopy.scopeLabel %>">
        <span class="kt-settings-console__scope-icon" aria-hidden="true">
          <i class="ti ti-shield-check"></i>
        </span>
        <span class="kt-settings-console__scope-copy">
          <small><%= settingsCopy.scopeLabel %></small>
          <strong><%= settingsCopy.scopeValue %></strong>
        </span>
      </aside>
    </header>

    <section class="kt-settings-console__navigation" data-settings-navigation>
      <div class="kt-settings-console__navigation-heading">
        <span class="kt-settings-console__navigation-mark" aria-hidden="true">
          <i class="ti ti-category-2"></i>
        </span>
        <div>
          <span><%= settingsCopy.navigationEyebrow %></span>
          <h2><%= settingsCopy.navigationTitle %></h2>
          <p><%= settingsCopy.navigationDescription %></p>
        </div>
      </div>

      <%- include('./partials/sectionNav.ejs', {
        settingsSections,
        settingsCopy
      }) %>
    </section>

    <section
      class="kt-settings-console__content"
      data-settings-content
      aria-live="polite"
    >
      <header class="kt-settings-console__content-header">
        <div class="kt-settings-console__current">
          <span class="kt-settings-console__current-icon" aria-hidden="true">
            <i
              class="ti <%= defaultSettingsSection.icon %>"
              data-settings-current-icon
            ></i>
          </span>
          <div>
            <span><%= settingsCopy.contentEyebrow %></span>
            <h2 data-settings-current-title><%= defaultSettingsSection.title %></h2>
            <p data-settings-current-helper><%= defaultSettingsSection.helper %></p>
          </div>
        </div>

        <div class="kt-settings-console__assurance">
          <i class="ti ti-lock-check" aria-hidden="true"></i>
          <span>
            <strong><%= settingsCopy.assuranceTitle %></strong>
            <small><%= settingsCopy.assuranceDescription %></small>
          </span>
        </div>
      </header>

      <div class="kt-settings-console__panels">
        <section
          class="kt-settings-console__panel is-active"
          id="settings-panel-site"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-site"
          data-settings-panel="site"
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/siteSetting.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-about"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-about"
          data-settings-panel="about"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/about.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-terms"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-terms"
          data-settings-panel="terms"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/termsCondition.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-activation"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-activation"
          data-settings-panel="activation"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/codeGenerate.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-smtp"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-smtp"
          data-settings-panel="smtp"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/email.ejs', {smtp: safeSettingsSmtp, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-orders"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-orders"
          data-settings-panel="orders"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/control.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>

        <section
          class="kt-settings-console__panel"
          id="settings-panel-auctions"
          role="tabpanel"
          tabindex="0"
          aria-labelledby="settings-tab-auctions"
          data-settings-panel="auctions"
          hidden
        >
          <div class="kt-settings-console__legacy">
            <%- include('includes/auction.ejs', {setting: setting, csrfToken: csrfToken, i18n}) %>
          </div>
        </section>
      </div>
    </section>
  </div>
</section>

<script src="/admin/app-assets/js/core/libraries/jquery.min.js"></script>
<script src="https://cdn.ckeditor.com/4.14.0/full/ckeditor.js"></script>
<%- include('./includes/includes.ejs', {i18n}) %>
<script src="/admin/assets/js/pages/settings.js?v=2.6.3.b1" defer></script>
