// Shared products + helpers — 41st Archive 001 · 5 tees (Drop 001 giveaway)

const PRODUCTS = [
  { sku: 'TS-001', cat: 'TEE', series: 'NEVER',  name: 'SHITTY HANDWRITING',          tag: "AI WILL NEVER REPLACE MY",   price: 65, edN: 1, edTotal: 25, rear: 'assets/tee-04-furniture.png' },
  { sku: 'TS-002', cat: 'TEE', series: 'NEVER',  name: 'KARAOKE SKILLS',              tag: "AI WILL NEVER REPLACE MY",   price: 65, edN: 1, edTotal: 25, rear: 'assets/tee-02-karaoke.png' },
  { sku: 'TS-003', cat: 'TEE', series: 'NEVER',  name: 'TRAGIC PARALLEL PARKING',     tag: "AI WILL NEVER REPLACE MY",   price: 65, edN: 1, edTotal: 25, rear: 'assets/tee-03-parking.png' },
  { sku: 'TS-004', cat: 'TEE', series: 'NEVER',  name: 'POORLY ASSEMBLING FURNITURE', tag: "AI WILL NEVER BEAT ME AT",   price: 65, edN: 1, edTotal: 25, rear: 'assets/tee-01-handwriting.png' },
  { sku: 'TS-005', cat: 'TEE', series: 'CALL',   name: 'CALL MY AI AGENT',            tag: "+34 · LA · TI · TU · DE",    price: 75, edN: 1, edTotal: 25, rear: 'assets/tee-05-callmy.png' },
];

const FRONT = 'assets/tee-front.png';

const SERIES = {
  NEVER: { label: 'A · NEVER REPLACE ME', caption: "I'M NOT AFRAID OF AI." },
  CALL:  { label: 'B · CALL MY AGENT',     caption: "+34 · LA · TI · TU · DE" },
};

const DESCRIPTION = `From the AI-WILL-NEVER-REPLACE-ME archive. Heavyweight 240gsm cotton, garment-dyed, hand-screened back print. Small Latitude rainbow embroidered at the back neck and front hem. Each piece numbered against the edition cap.`;

const SPECS = [
  ['MATERIAL', '100% LONG-STAPLE COTTON · 240 GSM'],
  ['FIT',      'BOXED · DROP SHOULDER'],
  ['PRINT',    'WATER-BASED · HAND-PULLED'],
  ['SHIPS',    'FROM 03 JUN 2026'],
];

const DROP_DEADLINE = Date.now() + (4 * 24 * 60 + 12 * 60 + 38) * 60 * 1000;

function useCountdown() {
  const [now, setNow] = React.useState(Date.now());
  React.useEffect(() => {
    const t = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(t);
  }, []);
  const ms = Math.max(0, DROP_DEADLINE - now);
  const d = Math.floor(ms / 86400000);
  const h = Math.floor((ms % 86400000) / 3600000);
  const m = Math.floor((ms % 3600000) / 60000);
  const s = Math.floor((ms % 60000) / 1000);
  return { d, h, m, s, raw: ms };
}

// Live countdown to the next Friday at noon UTC. Auto-rolls each week —
// no hard-coded dates anywhere.
function useNextFriday() {
  const [now, setNow] = React.useState(Date.now());
  React.useEffect(() => {
    const t = setInterval(() => setNow(Date.now()), 1000);
    return () => clearInterval(t);
  }, []);
  const target = new Date(now);
  const day = target.getUTCDay(); // 0=Sun … 5=Fri … 6=Sat
  target.setUTCHours(9, 0, 0, 0);
  const daysUntilFriday = (5 - day + 7) % 7;
  target.setUTCDate(target.getUTCDate() + daysUntilFriday);
  if (target.getTime() <= now) target.setUTCDate(target.getUTCDate() + 7);
  const ms = Math.max(0, target.getTime() - now);
  const d = Math.floor(ms / 86400000);
  const h = Math.floor((ms % 86400000) / 3600000);
  const m = Math.floor((ms % 3600000) / 60000);
  const s = Math.floor((ms % 60000) / 1000);
  return { d, h, m, s, raw: ms };
}

const pad = (n, w=2) => String(n).padStart(w, '0');
const money = (n) => `$${n.toFixed(2)}`;

Object.assign(window, {
  PRODUCTS, FRONT, SERIES, DESCRIPTION, SPECS,
  useCountdown, useNextFriday, pad, money,
});
