// ──────────────────────────────────────────────────────────────────
// Empty-state designs.
// Each has a tactical metaphor — not generic "no items" illustrations.
//   · Gallery / SavedDesigns — "blank canvas waiting"
//   · OrderHistory — "step on the mat" diagram
//   · Notifications — "quiet on the line" status grid
//   · MatchHistory — "no record yet" timeline
// ──────────────────────────────────────────────────────────────────

const EmptyShell = ({ title, overline, body, action, children }) => (
  <div style={{ position: "absolute", inset: 0, background: "var(--bg-primary)", display: "flex", flexDirection: "column" }}>
    <TopBar title={title.split(" ").slice(0, 2).join(" ")} />
    <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: "20px 28px", textAlign: "center" }}>
      <div style={{ marginBottom: 32 }}>{children}</div>
      <Overline style={{ color: "var(--accent)", marginBottom: 10 }}>{overline}</Overline>
      <div className="t-h3" style={{ textWrap: "balance" }}>{title}</div>
      <p className="t-body-lg" style={{ color: "var(--text-secondary)", marginTop: 12, maxWidth: 280, textWrap: "pretty" }}>{body}</p>
      {action && <div style={{ marginTop: 24 }}>{action}</div>}
    </div>
  </div>
);

// Saved designs empty — wireframe singlet with dashed cuts
const EmptySavedDesigns = ({ onAction }) => (
  <EmptyShell
    overline="SGL · NO DRAFTS"
    title="Blank pattern."
    body="Start a build to save it here. Drafts auto-sync across devices."
    action={<Button label="OPEN DESIGNER" tone="mono" rightIcon={<I.ArrowRight />} onClick={onAction} />}
  >
    <svg viewBox="0 0 200 240" style={{ width: 140, height: 168 }}>
      <path
        d="M50 30 L80 20 L120 20 L150 30 L160 60 L140 90 L150 220 L130 240 L70 240 L50 220 L60 90 L40 60 Z"
        fill="none"
        stroke="var(--border-default)"
        strokeWidth="1"
        strokeDasharray="4 4"
      />
      <text x="100" y="135" textAnchor="middle" fontSize="9" fill="var(--text-tertiary)" fontFamily="Figtree" fontWeight="700" letterSpacing="0.2em">DRAFT · 000</text>
      <CornerMarkSVG x={36} y={16} />
      <CornerMarkSVG x={164} y={16} flipX />
      <CornerMarkSVG x={36} y={244} flipY />
      <CornerMarkSVG x={164} y={244} flipX flipY />
    </svg>
  </EmptyShell>
);

const CornerMarkSVG = ({ x, y, flipX, flipY }) => {
  const sx = flipX ? -1 : 1;
  const sy = flipY ? -1 : 1;
  return (
    <g transform={`translate(${x},${y}) scale(${sx},${sy})`}>
      <line x1="0" y1="0" x2="10" y2="0" stroke="var(--accent)" strokeWidth="1.5" />
      <line x1="0" y1="0" x2="0" y2="10" stroke="var(--accent)" strokeWidth="1.5" />
    </g>
  );
};

// Order history empty — ruler with no marks
const EmptyOrderHistory = ({ onAction }) => (
  <EmptyShell
    overline="ORDERS · NONE YET"
    title="Nothing shipped."
    body="Your production pipeline is empty. Submit a build to start tracking."
    action={<Button label="START A BUILD" tone="mono" rightIcon={<I.ArrowRight />} onClick={onAction} />}
  >
    <div style={{ width: 200, padding: "20px 0" }}>
      <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
        <Overline style={{ color: "var(--text-tertiary)" }}>QUEUE</Overline>
        <Overline style={{ color: "var(--text-tertiary)" }}>SHIPPED</Overline>
      </div>
      {/* Pipeline ruler */}
      <div style={{ position: "relative", height: 36 }}>
        <div style={{ position: "absolute", top: 18, left: 0, right: 0, height: 1, background: "var(--border-default)" }} />
        {[0, 25, 50, 75, 100].map((pct) => (
          <div key={pct} style={{ position: "absolute", left: `${pct}%`, top: 12, transform: "translateX(-50%)" }}>
            <div style={{ width: 1, height: 12, background: "var(--border-default)" }} />
          </div>
        ))}
      </div>
      <div className="t-caption-lg" style={{ color: "var(--text-tertiary)", textAlign: "center", marginTop: 8 }}>
        No orders on the line · 0 / 0
      </div>
    </div>
  </EmptyShell>
);

// Notifications empty — "all clear" status grid
const EmptyNotifications = ({ onAction }) => (
  <EmptyShell
    overline="NOTIFICATIONS · CLEAR"
    title="Quiet on the line."
    body="No new pings. We'll surface build status, scout DMs, and gym alerts here."
    action={
      <Button
        label="OPEN SETTINGS"
        variant="secondary"
        tone="mono"
        size="medium"
        onClick={onAction}
        leftIcon={<I.Settings />}
      />
    }
  >
    <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 64px)", gap: 8 }}>
      {Array.from({ length: 9 }).map((_, i) => (
        <div
          key={i}
          style={{
            aspectRatio: 1,
            border: "1px solid var(--border-subtle)",
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            color: "var(--text-tertiary)",
          }}
        >
          <span style={{
            width: 5, height: 5, background: "var(--text-tertiary)",
            opacity: 0.4,
            borderRadius: 1,
          }} />
        </div>
      ))}
    </div>
  </EmptyShell>
);

// Match history empty — empty record card
const EmptyMatchHistory = ({ onAction }) => (
  <EmptyShell
    overline="MAT RECORD · 0-0"
    title="No record yet."
    body="Log your first bout to start building a record. Wins, subs, scout flags - all here."
    action={<Button label="LOG A BOUT" tone="mono" rightIcon={<I.Plus />} onClick={onAction} />}
  >
    <div style={{
      width: 220, padding: 16, border: "1px solid var(--border-default)",
      borderRadius: "var(--r-sm)", textAlign: "left",
    }}>
      <div style={{ display: "flex", justifyContent: "space-between" }}>
        <Overline>RECORD · CARD</Overline>
        <Overline style={{ color: "var(--text-tertiary)" }}>-.-.--</Overline>
      </div>
      <Hairline style={{ margin: "10px 0" }} />
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8, textAlign: "center" }}>
        {["W", "L", "D"].map((k) => (
          <div key={k}>
            <div className="t-h3" style={{ color: "var(--text-tertiary)" }}>0</div>
            <Overline style={{ color: "var(--text-tertiary)", marginTop: 4 }}>{k}</Overline>
          </div>
        ))}
      </div>
    </div>
  </EmptyShell>
);

Object.assign(window, {
  EmptyShell,
  EmptySavedDesigns,
  EmptyOrderHistory,
  EmptyNotifications,
  EmptyMatchHistory,
});
