/* Minimal i18n dictionary — EN default, AR when toggled */
const DICT = {
  en: {
    nav: { collections: "Collections", makers: "Makers", journal: "Journal", atelier: "Atelier", contact: "Contact", search: "Search", bag: "Bag" },
    hero_eyebrow: "Curated from Egypt · Est. 2026",
    hero_title_1: "Objects made",
    hero_title_2: "slowly, by hand,",
    hero_title_3: "in the old way.",
    hero_body: "SANAA is a small, tended marketplace for Egyptian artisans working in macramé, wax, resin and fired earth. Every piece is approved, photographed, packed and shipped from our atelier in Cairo.",
    hero_cta_1: "Browse the Collection",
    hero_cta_2: "Meet the Makers",
    hero_pill_1: "Curated, not crowded",
    hero_pill_2: "Packed in Cairo",
    marquee: ["Handmade in Egypt", "Curated not crowded", "Packed with care", "Numbered editions", "Made by hand", "From the atelier"],
    story_eyebrow: "The word",
    story_title: "Sanaa,",
    story_title_it: "the craft itself.",
    story_body: "In Arabic, ṣanʿa (صَنعة) is the skill held in the hands — the knowing that passes from a grandmother's loom to a daughter's fingers, from a pot thrown in Fustat to the bowl on your table. We are a house for that knowing.",
    collections_eyebrow: "The four houses",
    collections_title: "A small, deliberate",
    collections_title_it: "catalogue.",
    col_1_name: "Macramé",
    col_1_ar: "مكرمية",
    col_1_desc: "Hand-knotted cotton, linen and palm fibre. Wall hangings, plant cradles, table runners.",
    col_2_name: "Candle & Scent",
    col_2_ar: "شموع",
    col_2_desc: "Soy-coconut blends poured in small batches. Notes of jasmine, oud, orange blossom, cedar.",
    col_3_name: "Resin & Stone",
    col_3_ar: "راتنج",
    col_3_desc: "Coasters, trays and small sculpture cast in resin with Egyptian sand, malachite, alabaster dust.",
    col_4_name: "Fired Earth",
    col_4_ar: "فخار",
    col_4_desc: "Wheel-thrown ceramics from Fustat. Food-safe glazes, tested for lead and cadmium. (Selective release.)",
    makers_eyebrow: "Hand of the maker",
    makers_title: "Twelve artisans.",
    makers_title_2: "Thirteen governorates.",
    pieces_eyebrow: "This season",
    pieces_title: "New, numbered,",
    pieces_title_it: "and few.",
    journal_eyebrow: "The journal",
    journal_title: "Notes from the atelier.",
    atelier_eyebrow: "The atelier",
    atelier_title: "How a piece",
    atelier_title_it: "leaves our door.",
    atelier_body: "Every object passes through the same six hands in Zamalek. Approved, photographed in daylight, quality-checked against a written standard, wrapped in recycled tissue and sealed with a numbered wax mark. What you unwrap at home is the same piece the maker released.",
    letter_eyebrow: "Quiet correspondence",
    letter_title: "A letter once a month.",
    letter_body: "New arrivals, atelier notes, and one long-form story about a maker. No promotions, no noise.",
    letter_placeholder: "your@address",
    letter_cta: "Subscribe",
    footer_tag: "A curated house for Egyptian handmade.",
  },
  ar: {
    nav: { collections: "المجموعات", makers: "الصنّاع", journal: "اليوميّات", atelier: "المحترف", contact: "تواصل", search: "بحث", bag: "الحقيبة" },
    hero_eyebrow: "منتقاة من مصر · تأسّست ٢٠٢٦",
    hero_title_1: "أشياءٌ صُنعت",
    hero_title_2: "بتؤدة، باليد،",
    hero_title_3: "على الطريقة العتيقة.",
    hero_body: "صَنعة هو سوقٌ صغيرٌ مُعتنى به للحرفيين المصريين، في المكرمية والشمع والراتنج والفخار. كل قطعة معتمدة ومصوّرة ومُغلّفة ومُرسلة من محترفنا في القاهرة.",
    hero_cta_1: "تصفّح المجموعة",
    hero_cta_2: "تعرّف على الصنّاع",
    hero_pill_1: "منتقاة، لا مزدحمة",
    hero_pill_2: "تُغلَّف في القاهرة",
    marquee: ["صُنع في مصر", "منتقاة لا مزدحمة", "تُغلَّف بعناية", "إصدارات مرقّمة", "صُنعت باليد", "من المحترف"],
    story_eyebrow: "الكلمة",
    story_title: "صَنعة،",
    story_title_it: "الحِرفة نفسها.",
    story_body: "صَنعة في العربية هي المهارة التي تسكن اليد — المعرفة التي تنتقل من نول الجدّة إلى أصابع الحفيدة، ومن إبريقٍ صُنع في الفسطاط إلى طاسةٍ على مائدتك. نحن بيتٌ لهذه المعرفة.",
    collections_eyebrow: "البيوت الأربعة",
    collections_title: "كتالوجٌ صغيرٌ",
    collections_title_it: "مدروس.",
    col_1_name: "مكرمية",
    col_1_ar: "Macramé",
    col_1_desc: "قطنٌ وكتّانٌ وليفُ نخيلٍ معقودٌ باليد. معلّقاتٌ جداريّة، مهاد نبات، ممرّات مائدة.",
    col_2_name: "شموع وعطور",
    col_2_ar: "Scent",
    col_2_desc: "خلطات صويا وجوز هند، صبٌّ يدويٌّ بدفعاتٍ صغيرة. فلٌّ، عود، زهر برتقال، أرز.",
    col_3_name: "راتنج وحجر",
    col_3_ar: "Resin",
    col_3_desc: "قواعد أكواب، صوانٍ، ونحتٌ صغير مع رملٍ مصريٍّ، مالاكيت، وغبار مرمر.",
    col_4_name: "فخار",
    col_4_ar: "Earth",
    col_4_desc: "سيراميك من الفسطاط. طلاءات آمنة غذائيًّا، مفحوصةٌ من الرصاص والكادميوم. (إصدار انتقائي).",
    makers_eyebrow: "يد الصانع",
    makers_title: "اثنا عشر حِرفيًّا.",
    makers_title_2: "ثلاث عشرة محافظة.",
    pieces_eyebrow: "هذا الموسم",
    pieces_title: "جديدة، مرقّمة،",
    pieces_title_it: "وقليلة.",
    journal_eyebrow: "اليوميّات",
    journal_title: "ملاحظات من المحترف.",
    atelier_eyebrow: "المحترف",
    atelier_title: "كيف تخرج القطعة",
    atelier_title_it: "من بابنا.",
    atelier_body: "كل قطعة تمرّ بالأيدي الستّ نفسها في الزمالك. تُعتمَد، تُصوَّر في ضوء النهار، تُفحَص وفق معيارٍ مكتوب، تُلَفّ بورقٍ مُعاد تدويره، وتُختَم بشمعٍ مرقّم. ما تفتحه في البيت هو القطعة ذاتها التي أطلقها الصانع.",
    letter_eyebrow: "مراسلاتٌ هادئة",
    letter_title: "رسالةٌ واحدةٌ في الشهر.",
    letter_body: "وارداتٌ جديدة، ملاحظاتٌ من المحترف، وقصّةٌ طويلةٌ عن صانعٍ واحد. بلا عروض، بلا ضجيج.",
    letter_placeholder: "بريدك@",
    letter_cta: "اشتراك",
    footer_tag: "بيتٌ منتقىً للصناعة المصريّة اليدويّة.",
  }
};

function useLang() {
  const [lang, setLang] = React.useState(() => localStorage.getItem("sanaa_lang") || "en");
  React.useEffect(() => {
    localStorage.setItem("sanaa_lang", lang);
    document.body.classList.toggle("rtl", lang === "ar");
    // Keep the document root in sync for a11y (screen readers) + SEO.
    document.documentElement.lang = lang;
    document.documentElement.dir = lang === "ar" ? "rtl" : "ltr";
  }, [lang]);
  const t = DICT[lang];
  return { lang, setLang, t };
}

// ─── Locale-aware date helpers
// Arabic uses ar-EG (Egyptian Arabic numerals + month names);
// English uses en-GB (day-month order, matches the rest of the UI).
function _locale(lang) { return lang === "ar" ? "ar-EG" : "en-GB"; }
function fmtDate(iso, lang, opts) {
  if (!iso) return "—";
  try {
    return new Date(iso).toLocaleDateString(_locale(lang), opts || { day: "numeric", month: "short" });
  } catch { return ""; }
}
function fmtDateTime(iso, lang, opts) {
  if (!iso) return "—";
  try {
    return new Date(iso).toLocaleString(_locale(lang), opts || { day: "numeric", month: "short", hour: "2-digit", minute: "2-digit" });
  } catch { return ""; }
}

// Bilingual relative "age" — formatted at RENDER time against the current lang
// (callers pass `lang`), so a mid-session language toggle re-localizes already
// loaded timestamps instead of leaving them baked in the load-time language.
function fmtAge(iso, lang) {
  if (!iso) return "—";
  const ar = lang === "ar";
  const m = Math.round((Date.now() - new Date(iso).getTime()) / 60000);
  if (m < 1) return ar ? "الآن" : "now";
  if (m < 60) return ar ? `منذ ${m} د` : `${m}m ago`;
  const h = Math.round(m / 60);
  if (h < 24) return ar ? `منذ ${h} س` : `${h}h ago`;
  return ar ? `منذ ${Math.round(h / 24)} ي` : `${Math.round(h / 24)}d ago`;
}

Object.assign(window, { DICT, useLang, fmtDate, fmtDateTime, fmtAge });
