<%- include('_head') %>
  <h1 style="font-size:24px; margin-bottom:18px;">Store settings</h1>

  <% if (query.saved) { %><div class="panel" style="background:var(--gold-soft); border-color:rgba(212,175,55,.35); margin-bottom:14px;">Settings saved.</div><% } %>

  <form method="post" action="/admin/settings">
    <div class="panel">
      <h3>Store</h3>
      <div class="form-grid">
        <div class="form-field"><label for="store_name">Store name</label><input id="store_name" name="store_name" value="<%= s.store_name %>"></div>
        <div class="form-field"><label for="slogan">Slogan</label><input id="slogan" name="slogan" value="<%= s.slogan %>"></div>
        <div class="form-field" style="grid-column: 1 / -1;"><label for="tagline">Tagline / description</label><input id="tagline" name="tagline" value="<%= s.tagline %>"></div>
      </div>
      <div class="form-field"><label for="address">Address</label><input id="address" name="address" value="<%= s.address %>"></div>
      <div class="form-grid">
        <div class="form-field"><label for="phone">Phone</label><input id="phone" name="phone" value="<%= s.phone %>"></div>
        <div class="form-field"><label for="whatsapp">WhatsApp number (no + or spaces)</label><input id="whatsapp" name="whatsapp" value="<%= s.whatsapp %>"></div>
        <div class="form-field"><label for="email">Email</label><input id="email" name="email" value="<%= s.email %>"></div>
        <div class="form-field"><label for="business_hours">Business hours</label><input id="business_hours" name="business_hours" value="<%= s.business_hours %>"></div>
        <div class="form-field"><label for="facebook">Facebook link</label><input id="facebook" name="facebook" value="<%= s.facebook %>"></div>
        <div class="form-field"><label for="instagram">Instagram link</label><input id="instagram" name="instagram" value="<%= s.instagram %>"></div>
      </div>
      <div class="form-field"><label for="maps_url">Google Maps directions URL</label><input id="maps_url" name="maps_url" value="<%= s.maps_url %>"></div>
    </div>

    <div class="panel">
      <h3>Shipping & money</h3>
      <div class="form-grid">
        <div class="form-field"><label for="currency">Currency</label><input id="currency" name="currency" value="<%= s.currency %>"></div>
        <div class="form-field"><label for="shipping_fee">Base shipping fee</label><input id="shipping_fee" name="shipping_fee" value="<%= s.shipping_fee %>"></div>
        <div class="form-field"><label for="free_shipping_threshold">Free shipping over (subtotal)</label><input id="free_shipping_threshold" name="free_shipping_threshold" value="<%= s.free_shipping_threshold %>"></div>
      </div>
    </div>

    <div class="panel">
      <h3>PayFast (online payments)</h3>
      <p class="admin-hint" style="margin-bottom:14px;">Leave empty to disable card payments (only Cash on Delivery will show). Get keys from your PayFast dashboard. Sandbox mode uses test payments.</p>
      <div class="form-grid">
        <div class="form-field"><label for="payfast_merchant_id">Merchant ID</label><input id="payfast_merchant_id" name="payfast_merchant_id" value="<%= s.payfast_merchant_id %>"></div>
        <div class="form-field"><label for="payfast_merchant_key">Merchant Key</label><input id="payfast_merchant_key" name="payfast_merchant_key" value="<%= s.payfast_merchant_key %>"></div>
        <div class="form-field"><label for="payfast_passphrase">Passphrase</label><input id="payfast_passphrase" name="payfast_passphrase" value="<%= s.payfast_passphrase %>"></div>
        <div class="form-field"><label for="payfast_sandbox">Mode</label>
          <select id="payfast_sandbox" name="payfast_sandbox">
            <option value="1" <%= s.payfast_sandbox === '1' ? 'selected' : '' %>>Sandbox (test)</option>
            <option value="0" <%= s.payfast_sandbox === '0' ? 'selected' : '' %>>Live</option>
          </select>
        </div>
      </div>
    </div>

    <div class="panel">
      <h3>Email notifications (SMTP)</h3>
      <p class="admin-hint" style="margin-bottom:14px;">Used to send order confirmations to customers and new-order alerts to you. Leave empty to skip emails (orders still work).</p>
      <div class="form-grid">
        <div class="form-field"><label for="smtp_host">SMTP host</label><input id="smtp_host" name="smtp_host" value="<%= s.smtp_host %>" placeholder="smtp.gmail.com"></div>
        <div class="form-field"><label for="smtp_port">Port</label><input id="smtp_port" name="smtp_port" value="<%= s.smtp_port %>"></div>
        <div class="form-field"><label for="smtp_user">Username</label><input id="smtp_user" name="smtp_user" value="<%= s.smtp_user %>"></div>
        <div class="form-field"><label for="smtp_pass">Password / app password</label><input id="smtp_pass" name="smtp_pass" type="password" value="<%= s.smtp_pass %>"></div>
        <div class="form-field"><label for="smtp_from">From email</label><input id="smtp_from" name="smtp_from" value="<%= s.smtp_from %>"></div>
        <div class="form-field"><label for="smtp_secure">Use SSL/TLS</label>
          <select id="smtp_secure" name="smtp_secure"><option value="1" <%= s.smtp_secure === '1' ? 'selected' : '' %>>Yes</option><option value="0" <%= s.smtp_secure === '0' ? 'selected' : '' %>>No</option></select>
        </div>
      </div>
    </div>

    <button class="btn btn-gold" type="submit"><i class="ic" data-ic="check"></i> Save all settings</button>
  </form>
<%- include('_foot') %>
