{%- comment -%}
  Delivery Box — estimated delivery window, computed from today.

  Dates are derived from real epoch maths (now + N days), not hardcoded,
  so the window never goes stale. Uses working-day padding rather than
  pretending weekends ship. Keep the day counts honest — this is a
  delivery promise customers will hold you to.
{%- endcomment -%}

{%- liquid
  assign s = section.settings
  assign uid = section.id
  assign day = 86400
  assign now = 'now' | date: '%s' | plus: 0

  assign from_days = s.min_days
  assign to_days = s.max_days
  if to_days < from_days
    assign to_days = from_days
  endif

  assign from_ts = from_days | times: day | plus: now
  assign to_ts = to_days | times: day | plus: now
-%}

{% style %}
  .db-{{ uid }} { padding: {{ s.padding_y }}px 0; }
  .db-{{ uid }}__box {
    max-width: {{ s.max_width }}px; margin: 0 auto;
    padding: {{ s.card_padding }}px;
    border-radius: {{ s.radius }}px;
    background: {{ s.bg_color }}; color: {{ s.text_color }};
    border: 1px solid {{ s.border_color }};
  }
  .db-{{ uid }}__row { display: flex; align-items: flex-start; gap: 12px; }
  .db-{{ uid }}__row + .db-{{ uid }}__row { margin-top: 12px; padding-top: 12px; border-top: 1px solid {{ s.border_color }}; }
  .db-{{ uid }}__icon { flex: 0 0 auto; width: 22px; height: 22px; color: {{ s.accent }}; }
  .db-{{ uid }}__icon svg { width: 100%; height: 100%; display: block; }
  .db-{{ uid }}__label { margin: 0; font-size: {{ s.text_size }}px; font-weight: 600; }
  .db-{{ uid }}__sub { margin: 2px 0 0; font-size: {{ s.text_size | minus: 1 }}px; opacity: .78; }
{% endstyle %}

<div class="db-{{ uid }}">
  <div class="page-width">
    <div class="db-{{ uid }}__box">

      <div class="db-{{ uid }}__row">
        <span class="db-{{ uid }}__icon" aria-hidden="true">
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
            <path d="M1 3h13v10H1z"/><path d="M14 8h4l3 3v2h-7z"/>
            <circle cx="5.5" cy="17.5" r="2.5"/><circle cx="17.5" cy="17.5" r="2.5"/>
          </svg>
        </span>
        <div>
          <p class="db-{{ uid }}__label">
            {{ s.delivery_label | escape }}
            <span>{{ from_ts | date: s.date_format }} – {{ to_ts | date: s.date_format }}</span>
          </p>
          {%- if s.delivery_note != blank -%}
            <p class="db-{{ uid }}__sub">{{ s.delivery_note | escape }}</p>
          {%- endif -%}
        </div>
      </div>

      {%- if s.show_cod -%}
        <div class="db-{{ uid }}__row">
          <span class="db-{{ uid }}__icon" aria-hidden="true">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
              <rect x="2" y="6" width="20" height="12" rx="2"/><circle cx="12" cy="12" r="2.5"/>
            </svg>
          </span>
          <div>
            <p class="db-{{ uid }}__label">{{ s.cod_label | escape }}</p>
            {%- if s.cod_note != blank -%}<p class="db-{{ uid }}__sub">{{ s.cod_note | escape }}</p>{%- endif -%}
          </div>
        </div>
      {%- endif -%}

      {%- if s.show_returns -%}
        <div class="db-{{ uid }}__row">
          <span class="db-{{ uid }}__icon" aria-hidden="true">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">
              <path d="M3 12a9 9 0 1 0 3-6.7"/><path d="M3 4v5h5"/>
            </svg>
          </span>
          <div>
            <p class="db-{{ uid }}__label">{{ s.returns_label | escape }}</p>
            {%- if s.returns_note != blank -%}<p class="db-{{ uid }}__sub">{{ s.returns_note | escape }}</p>{%- endif -%}
          </div>
        </div>
      {%- endif -%}

    </div>
  </div>
</div>

{% schema %}
{
  "name": "Delivery Box",
  "tag": "section",
  "class": "section",
  "settings": [
    { "type": "paragraph", "content": "Dates are calculated from today. Keep the day counts honest — customers hold you to this." },
    { "type": "text", "id": "delivery_label", "label": "Delivery label", "default": "Estimated delivery" },
    { "type": "range", "id": "min_days", "min": 0, "max": 30, "step": 1, "label": "Earliest (days from today)", "default": 1 },
    { "type": "range", "id": "max_days", "min": 0, "max": 60, "step": 1, "label": "Latest (days from today)", "default": 3 },
    { "type": "text", "id": "date_format", "label": "Date format", "default": "%d %b", "info": "Liquid strftime, e.g. %d %b gives 05 Aug." },
    { "type": "text", "id": "delivery_note", "label": "Delivery note", "default": "Working days, inside Dhaka" },
    { "type": "header", "content": "Cash on delivery" },
    { "type": "checkbox", "id": "show_cod", "label": "Show row", "default": true },
    { "type": "text", "id": "cod_label", "label": "Label", "default": "Cash on delivery" },
    { "type": "text", "id": "cod_note", "label": "Note", "default": "Inspect your order before you pay" },
    { "type": "header", "content": "Returns" },
    { "type": "checkbox", "id": "show_returns", "label": "Show row", "default": true },
    { "type": "text", "id": "returns_label", "label": "Label", "default": "Exchange window" },
    { "type": "text", "id": "returns_note", "label": "Note", "default": "2 days for preference, 15 days for defects" },
    { "type": "header", "content": "Style" },
    { "type": "range", "id": "max_width", "min": 280, "max": 900, "step": 20, "unit": "px", "label": "Max width", "default": 520 },
    { "type": "range", "id": "card_padding", "min": 8, "max": 40, "step": 2, "unit": "px", "label": "Padding", "default": 16 },
    { "type": "range", "id": "radius", "min": 0, "max": 28, "step": 2, "unit": "px", "label": "Corner radius", "default": 10 },
    { "type": "range", "id": "text_size", "min": 11, "max": 22, "step": 1, "unit": "px", "label": "Text size", "default": 14 },
    { "type": "color", "id": "bg_color", "label": "Background", "default": "#ffffff" },
    { "type": "color", "id": "text_color", "label": "Text", "default": "#111111" },
    { "type": "color", "id": "border_color", "label": "Border", "default": "#e6e6e6" },
    { "type": "color", "id": "accent", "label": "Icon colour", "default": "#111111" },
    { "type": "range", "id": "padding_y", "min": 0, "max": 60, "step": 2, "unit": "px", "label": "Vertical padding", "default": 12 }
  ],
  "presets": [ { "name": "Delivery Box" } ]
}
{% endschema %}
