// shared.jsx — content and utilities shared across the three directions.
// Exports to window: LEMONAID, useOpenStatus, usePriceCalc, formatMoney.

const LEMONAID = {
  name: "Lemon-AID",
  tagline: "Refreshment. Recovery. Results.",
  founded: 2026,
  founder: {
    name: "Ari",
    title: "Founder & Chief Executive Officer",
    bio_short:
      "Ari founded Lemon-AID in the spring of 2026 to address what she identified as a chronic underservicing of refreshment and minor-injury care in the immediate neighborhood corridor.",
    letter: [
      "I am ten years old. I founded Lemon-AID this spring.",
      "The corner I operate from sees consistent foot traffic on weekends - joggers, dog walkers, families pushing strollers, kids on scooters. They are warm. They are sometimes lightly scraped. Until April of this year, no one was serving them.",
      "Lemon-AID is a vertically integrated refreshment and recovery operation. We squeeze our own lemons. We staff our own table. We assemble our own first aid bundles. We do this on Saturday and Sunday, and after school when conditions permit.",
      "We don't deliver. We don't have a loyalty program. We have lemonade, we have water, we have bandages, and we have a card table on the corner. We think that's enough.",
      "Thank you for stopping.",
    ],
    sig: "Ari",
  },
  products: [
    {
      id: "lemonade",
      sku: "LA-001",
      name: "Fresh Lemonade",
      price: 2.0,
      unit: "12 fl oz",
      tag: "Flagship",
      short: "Small-batch. Real lemons. Cane sugar. Cold water. Stirred. Compostable cup, lid, and straw.",
      details: [
        "Small-batch. Hand-stirred. Not from concentrate.",
        "Approximately four lemons per pitcher.",
        "Served over ice in a compostable cup with a compostable lid and straw. No single-use plastic in the supply chain.",
      ],
    },
    {
      id: "water",
      sku: "LA-002",
      name: "Cold Water",
      price: 1.0,
      unit: "12 fl oz",
      tag: "Hydration",
      short: "Municipal tap. Filtered through the building. Kept cold.",
      details: [
        "Stored in a labeled jug inside a sealed cooler.",
        "Poured to order over ice.",
        "Tastes like water.",
      ],
    },
    {
      id: "firstaid",
      sku: "LA-003",
      name: "First Aid Bundle",
      price: 2.0,
      unit: "1 kit",
      tag: "Recovery",
      short: "Two bandages. One antiseptic wipe. Sealed.",
      details: [
        "Two (2) adhesive bandages, standard size.",
        "One (1) individually-wrapped antiseptic wipe.",
        "Hand-assembled in small runs, stored away from sunlight.",
      ],
    },
  ],
  // Synced from the Lemon-AID Printful store via scripts/printful_pull.py.
  // `price` is the base ("from") retail price; sizes scale up from there.
  // `url` is the Square Online product page; empty = Specification pending.
  merch: [
    {
      id: "hyphen-white",
      sku: "LA-101",
      name: "The hyphen is load-bearing.",
      price: 22.0,
      color: "White",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-hyphen-white.webp",
      url: "https://lemon-aid-103662.square.site/product/the-hyphen-is-load-bearing-/UPDLY53E5F52RGI6H7LZYXLL",
    },
    {
      id: "hyphen-black",
      sku: "LA-102",
      name: "The hyphen is load-bearing.",
      price: 22.0,
      color: "Black Heather",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-hyphen-black.webp",
      url: "https://lemon-aid-103662.square.site/product/the-hyphen-is-load-bearing-/DUYQFPAR3OPRI2N33E67M4MS",
    },
    {
      id: "gethurt-white",
      sku: "LA-103",
      name: "The Bundle Specified. Specifically White.",
      price: 22.0,
      color: "White",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-gethurt-white.webp",
      url: "https://lemon-aid-103662.square.site/product/the-bundle-specified-specifically-white-/CD7NCRBROO7VS5T4I332DUHX",
    },
    {
      id: "gethurt-black",
      sku: "LA-104",
      name: "The Bundle Specified. Specifically Black.",
      price: 22.0,
      color: "Black",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-gethurt-black.webp",
      url: "https://lemon-aid-103662.square.site/product/the-bundle-specified-specifically-black-/IIE6U4QJEGVJHGUNZ7PJMWYK",
    },
    {
      id: "operation-black",
      sku: "LA-105",
      name: "It's an operation.",
      price: 22.0,
      color: "Black Heather",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-operation-black.webp",
      url: "https://lemon-aid-103662.square.site/product/it-s-an-operation-/ER2C7QQN2WDTF4RS6JXJAPOH",
    },
    {
      id: "keepitsimple-black",
      sku: "LA-106",
      name: "Keep It Simple",
      price: 22.0,
      color: "Black",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-keepitsimple-black.webp",
      url: "https://lemon-aid-103662.square.site/product/keep-it-simple/BKCZJSJXEMIZJHV7L4Z56H5O",
    },
    {
      id: "deliver-white",
      sku: "LA-107",
      name: "We don't deliver.",
      price: 22.0,
      color: "White",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-deliver-white.webp",
      url: "https://lemon-aid-103662.square.site/product/we-don-t-deliver-/HGYFWDDIIZZKAAAD2VGTFQRF",
    },
    {
      id: "deliver-black",
      sku: "LA-108",
      name: "We don't deliver. Like at all.",
      price: 22.0,
      color: "Black",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-deliver-black.webp",
      url: "https://lemon-aid-103662.square.site/product/we-don-t-deliver-like-at-all-/AVTLMX4VBIXXK4YXDHPOUIW3",
    },
    {
      id: "fulfillment-white",
      sku: "LA-109",
      name: "Fulfillment Policy",
      price: 22.0,
      color: "White",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-fulfillment-white.webp",
      url: "https://lemon-aid-103662.square.site/product/fulfillment-policy/SNJAF5QTEK77Z2ALE6JHWMDU",
    },
    {
      id: "fulfillment-black",
      sku: "LA-110",
      name: "Our Fulfillment Policy is your Feet",
      price: 22.0,
      color: "Black",
      fabric: "Bella + Canvas 3001",
      image: "assets/db-merch-fulfillment-black.webp",
      url: "https://lemon-aid-103662.square.site/product/our-fulfillment-policy-is-your-feet/6FYD7E5HIYALBACTCECH3OK6",
    },
  ],
  hours: [
    { day: "Monday", note: "After school, when possible", start: 15, end: 17, soft: true },
    { day: "Tuesday", note: "After school, when possible", start: 15, end: 17, soft: true },
    { day: "Wednesday", note: "After school, when possible", start: 15, end: 17, soft: true },
    { day: "Thursday", note: "After school, when possible", start: 15, end: 17, soft: true },
    { day: "Friday", note: "Closed", start: null, end: null, soft: false },
    { day: "Saturday", note: "Open", start: 10, end: 16, soft: false },
    { day: "Sunday", note: "Open", start: 12, end: 16, soft: false },
  ],
  location: {
    primary: "The corner. You'll see the table.",
    city: "Winston-Salem, North Carolina",
    landmarks: "Look for the white card table. There is a sign.",
  },
  press: [
    {
      quote: "I had not planned to buy lemonade. I bought lemonade.",
      source: "A neighbor, walking a beagle",
    },
    {
      quote: "My son fell off his scooter. The bandage held.",
      source: "Parent, verified purchase",
    },
    {
      quote: "It's lemonade. It's good.",
      source: "Mailman, declined to provide last name",
    },
    {
      quote: "She asked for exact change in a way I respected.",
      source: "Regular customer",
    },
  ],
  careers: {
    headline: "Lemon-AID is not currently hiring.",
    body: "The company is fully staffed. Future openings will be posted here in the event that the founder needs assistance, which she does not anticipate.",
  },
  ir: {
    headline: "Investor Relations",
    body: "Lemon-AID is privately held. The company is not raising. Outside capital is not under consideration at this time. Inquiries may be directed to the founder, in person, at the table.",
    metrics: [
      { label: "Years in operation", value: "1" },
      { label: "Product lines", value: "3" },
      { label: "Locations", value: "1" },
      { label: "Outstanding debt", value: "$0" },
    ],
    allocation: [
      { pct: "25%", label: "College fund" },
      { pct: "50%", label: "Hi-jinx, shenanigans & mayhem" },
      { pct: "25%", label: "Charitable causes" },
    ],
  },
  contact: {
    inPerson: "The corner, Saturday & Sunday",
    note: "We do not have a phone. We are usually at the table.",
  },
  payment: {
    methods: "Cash & cards accepted",
    change: "Exact change appreciated",
  },
  legal: {
    builder: "Bespoke Software Design",
    builderUrl: "https://bespokesoftwaredesign.com",
    copyright: "© 2026 Lemon-AID. A sole proprietorship operating from a card table.",
  },
};

// --- Open / closed status -----------------------------------------------

function getStatusFor(date, hours, override) {
  if (override === "open") return { open: true, label: "Open now", detail: "Override: open" };
  if (override === "closed") return { open: false, label: "Closed", detail: "Override: closed" };
  const dayIdx = date.getDay(); // 0=Sun
  // Reorder our hours array (Mon-first) to Sun-first
  const order = [6, 0, 1, 2, 3, 4, 5]; // hours[] index for [Sun,Mon,...,Sat]
  const todayIdx = order[dayIdx];
  const today = hours[todayIdx];
  const h = date.getHours() + date.getMinutes() / 60;
  if (today.start != null && h >= today.start && h < today.end) {
    const closeH = Math.floor(today.end);
    return {
      open: true,
      label: "Open now",
      detail: `Closes ${formatHour(closeH)}`,
    };
  }
  // Find next open window
  for (let i = 1; i <= 7; i++) {
    const next = hours[order[(dayIdx + i) % 7]];
    if (next.start != null) {
      return {
        open: false,
        label: "Closed",
        detail: `${next.day} ${formatHour(next.start)}`,
      };
    }
  }
  return { open: false, label: "Closed", detail: "" };
}

function formatHour(h) {
  const am = h < 12;
  const hh = h === 0 ? 12 : h > 12 ? h - 12 : h;
  return `${hh} ${am ? "AM" : "PM"}`;
}

function useOpenStatus(override) {
  const [now, setNow] = React.useState(new Date());
  React.useEffect(() => {
    const t = setInterval(() => setNow(new Date()), 30000);
    return () => clearInterval(t);
  }, []);
  return getStatusFor(now, LEMONAID.hours, override);
}

// --- Price calculator ---------------------------------------------------

function usePriceCalc() {
  const [qty, setQty] = React.useState({ lemonade: 1, water: 0, firstaid: 0 });
  const inc = (id, d) =>
    setQty((q) => ({ ...q, [id]: Math.max(0, Math.min(9, (q[id] || 0) + d)) }));
  const set = (id, v) =>
    setQty((q) => ({ ...q, [id]: Math.max(0, Math.min(9, v | 0)) }));
  const total = LEMONAID.products.reduce(
    (s, p) => s + (qty[p.id] || 0) * p.price,
    0
  );
  const itemCount = Object.values(qty).reduce((s, n) => s + n, 0);
  return { qty, inc, set, total, itemCount };
}

function formatMoney(n) {
  return `$${n.toFixed(2)}`;
}

// --- Stripey image-slot fallback art (CSS background, no SVG handcraft) --

function makeStripes(c1, c2) {
  return `repeating-linear-gradient(135deg, ${c1} 0 14px, ${c2} 14px 28px)`;
}

Object.assign(window, {
  LEMONAID,
  useOpenStatus,
  usePriceCalc,
  formatMoney,
  makeStripes,
});
