// shared.jsx — icons, wave dividers, helper components shared across pages
const { useState, useEffect, useRef } = React;

/* ---- Inline stroke icons (Lucide-style, 1.75 stroke, currentColor) ---- */
const Icon = {
  check: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M20 6 9 17l-5-5"/></svg>
  ),
  bolt: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2 4.5 13.5H11l-1 8.5 8.5-11.5H12z"/></svg>
  ),
  refresh: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/><path d="M3 21v-5h5"/></svg>
  ),
  sun: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M2 12h3M19 12h3M4.9 19.1 7 17M17 7l2.1-2.1"/></svg>
  ),
  drop: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 2.5S5 10 5 14.5a7 7 0 0 0 14 0C19 10 12 2.5 12 2.5Z"/></svg>
  ),
  lock: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="4.5" y="10.5" width="15" height="10" rx="2.5"/><path d="M8 10.5V7a4 4 0 0 1 8 0v3.5"/></svg>
  ),
  unlock: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="4.5" y="10.5" width="15" height="10" rx="2.5"/><path d="M8 10.5V7a4 4 0 0 1 7.6-2.2"/></svg>
  ),
  flame: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M12 2c.5 3-2 4.2-2 6.5 0 1.3 1 2.3 1 2.3s.4-1.6 1.6-2.3c1.7 2 3.4 3.4 3.4 6.2A6 6 0 0 1 6 14.7C6 10 10.5 8 12 2Z"/></svg>
  ),
  play: (p) => (<svg viewBox="0 0 24 24" {...p}><path d="M7 5v14l12-7z"/></svg>),
  userplus: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M15 19a6 6 0 0 0-12 0"/><circle cx="9" cy="8" r="4"/><path d="M18 8v6M21 11h-6"/></svg>
  ),
  gift: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M20 12v8H4v-8"/><path d="M2 7.5h20V12H2z"/><path d="M12 7.5V20"/><path d="M12 7.5H7.5a2.5 2.5 0 0 1 0-5C11 2.5 12 7.5 12 7.5Z"/><path d="M12 7.5h4.5a2.5 2.5 0 0 0 0-5C13 2.5 12 7.5 12 7.5Z"/></svg>
  ),
  camera: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 8h3l1.5-2h7L17 8h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1Z"/><circle cx="12" cy="13" r="3.2"/></svg>
  ),
  instagram: (p) => (<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" {...p}><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="currentColor" stroke="none"/></svg>),
  tiktok: (p) => (<svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M16 3c.3 2 1.6 3.6 3.8 3.9v2.7c-1.4 0-2.7-.4-3.8-1.1v5.8a5.6 5.6 0 1 1-5.6-5.6c.3 0 .6 0 .9.1v2.8a2.9 2.9 0 1 0 2 2.7V3H16Z"/></svg>),
  facebook: (p) => (<svg viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M14 9V7.5c0-.7.3-1 1.1-1H17V3.2c-.4 0-1.5-.1-2.7-.1-2.7 0-4.3 1.6-4.3 4.5V9H7.2v3.2H10V21h3.3v-8.8h2.6l.5-3.2H13.3Z"/></svg>),
};

/* ---- Wave divider. fill = wave colour, sits at boundary of two surfaces ---- */
function Wave({ fill = "var(--hyro-red)", flip = false, height = 46 }) {
  return (
    <div style={{ lineHeight: 0, transform: flip ? "scaleY(-1)" : "none" }}>
      <svg className="wave" viewBox="0 0 1440 80" preserveAspectRatio="none" style={{ height }}>
        <path fill={fill} d="M0,40 C180,90 360,0 540,28 C720,56 900,92 1080,64 C1260,36 1380,40 1440,52 L1440,80 L0,80 Z"/>
      </svg>
    </div>
  );
}

/* ---- Circular milestone ring with day number + fill fraction ---- */
function MilestoneRing({ day, frac, size = 76 }) {
  const r = size / 2 - 6;
  const c = 2 * Math.PI * r;
  return (
    <div className="ms-ring" style={{ width: size, height: size }}>
      <svg viewBox={`0 0 ${size} ${size}`} style={{ transform: "rotate(-90deg)" }}>
        <circle cx={size/2} cy={size/2} r={r} fill="none" stroke="var(--hyro-line)" strokeWidth="5"/>
        <circle cx={size/2} cy={size/2} r={r} fill="none" stroke="var(--hyro-red)" strokeWidth="5"
          strokeLinecap="round" strokeDasharray={c} strokeDashoffset={c * (1 - frac)} />
      </svg>
      <div className="day"><b>{day}</b><i>DAY</i></div>
    </div>
  );
}

/* ---- Hyro 750ml bottle icon (uses the line-art asset). Empty by default;
   red liquid rises + tick appears when done. state: future|missable|today|done ---- */
function Bottle({ state }) {
  const done = state === "done";
  return (
    <div className="bottle">
      <div className="bottle-fill"><img src="assets/bottle-fill-v2.png" alt="" /></div>
      <img className="bottle-line" src="assets/bottle-line-v2.png" alt="" />
      {done && (
        <span className="bottle-tick">
          {Icon.check({ style: { width: "62%", height: "62%", stroke: "var(--hyro-red)", strokeWidth: 3.2, fill: "none" } })}
        </span>
      )}
    </div>
  );
}

Object.assign(window, { Icon, Wave, MilestoneRing, Bottle });
