// Shared primitives for the ITCONNECT profile redesign.
// All sized for ~390px mobile artboard width. Pure presentational; no state.

const { useState: useStatePrim } = React;

// ─────────────────────────────────────────────────────────────
// Icons — Lucide stroke 1.75 / 2
// ─────────────────────────────────────────────────────────────
const Icon = {
  Arrow: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>,
  ArrowUR: (p = {}) => <svg width={p.size ?? 14} height={p.size ?? 14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M7 7h10v10"/><path d="M7 17 17 7"/></svg>,
  Mail: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>,
  Check: (p = {}) => <svg width={p.size ?? 14} height={p.size ?? 14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round"><polyline points="20 6 9 17 4 12"/></svg>,
  Phone: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>,
  Building: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><rect x="4" y="2" width="16" height="20" rx="2"/><path d="M9 22v-4h6v4"/><path d="M8 6h.01"/><path d="M16 6h.01"/><path d="M12 6h.01"/><path d="M12 10h.01"/><path d="M12 14h.01"/><path d="M16 10h.01"/><path d="M16 14h.01"/><path d="M8 10h.01"/><path d="M8 14h.01"/></svg>,
  Book: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20"/></svg>,
  Box: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><path d="m21 16-9 5-9-5"/><path d="m21 12-9 5-9-5"/><path d="M3 7l9 5 9-5-9-5z"/></svg>,
  Play: (p = {}) => <svg width={p.size ?? 16} height={p.size ?? 16} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><polygon points="6 4 20 12 6 20 6 4"/></svg>,
  Spark: (p = {}) => <svg width={p.size ?? 14} height={p.size ?? 14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3v3M12 18v3M5.6 5.6l2.1 2.1M16.3 16.3l2.1 2.1M3 12h3M18 12h3M5.6 18.4l2.1-2.1M16.3 7.7l2.1-2.1"/></svg>,
  Kakao: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M12 3C6.48 3 2 6.58 2 10.97c0 2.82 1.84 5.3 4.65 6.71l-.96 3.5c-.09.34.26.62.55.43L10.5 19c.49.05.99.07 1.5.07 5.52 0 10-3.58 10-7.97S17.52 3 12 3z"/></svg>,
  YouTube: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M23 7.5a3 3 0 0 0-2.1-2.1C19.1 5 12 5 12 5s-7.1 0-8.9.4A3 3 0 0 0 1 7.5C.6 9.3.6 12 .6 12s0 2.7.4 4.5a3 3 0 0 0 2.1 2.1C5 19 12 19 12 19s7.1 0 8.9-.4a3 3 0 0 0 2.1-2.1c.4-1.8.4-4.5.4-4.5s0-2.7-.4-4.5zM10 15.5v-7l6 3.5-6 3.5z"/></svg>,
  Linkedin: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M20.5 2h-17A1.5 1.5 0 0 0 2 3.5v17A1.5 1.5 0 0 0 3.5 22h17a1.5 1.5 0 0 0 1.5-1.5v-17A1.5 1.5 0 0 0 20.5 2zM8 19H5V8h3v11zm-1.5-12.3A1.7 1.7 0 1 1 8.2 5a1.7 1.7 0 0 1-1.7 1.7zM19 19h-3v-5.7c0-1.4-.5-2.3-1.7-2.3a1.85 1.85 0 0 0-1.7 1.2A2.3 2.3 0 0 0 12.5 13V19h-3V8h3v1.3a3 3 0 0 1 2.7-1.5c2 0 3.4 1.3 3.4 4V19z"/></svg>,
  Insta: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5"/><path d="M16 11.4a4 4 0 1 1-7.9 1.2A4 4 0 0 1 16 11.4z"/><line x1="17.5" y1="6.5" x2="17.51" y2="6.5"/></svg>,
  Threads: () => <svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><path d="M13.5 11.4c-1.8-.1-3 .4-3.4 1.6-.4 1.2.5 2 1.7 2.1 1.7.1 2.6-1 2.9-3.5l-1.2-.2zm5.1-2.6c.2.9.3 1.9.3 3 0 4.5-2.8 7.2-7.4 7.2-3.9 0-7-2.2-7-7.4 0-5.1 3.1-7.4 7.1-7.4 2.2 0 4 .7 5.2 2 .8.9 1.4 2 1.6 3.3l-1.9.4c-.4-2.1-1.9-3.7-4.9-3.7-3.2 0-5.2 1.9-5.2 5.4 0 3.6 2 5.5 5.1 5.5 3.2 0 5-1.6 5.4-4.4-.6-.4-1.3-.7-2-.9-.4 2.2-1.8 3.6-3.9 3.5-2-.2-3.4-1.6-3-3.4.4-1.7 2.1-2.6 4.4-2.5l1.2.1c0-1.1-.5-1.7-1.6-1.7-.8 0-1.4.3-1.7.9l-1.6-.6c.5-1.3 1.7-1.9 3.3-1.9 2.1 0 3.4 1.1 3.6 3.1.6.2 1.2.5 1.6 1z"/></svg>,
  Send: () => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>,
  Dot: () => <svg width="6" height="6" viewBox="0 0 6 6"><circle cx="3" cy="3" r="3" fill="currentColor"/></svg>,
};

// ─────────────────────────────────────────────────────────────
// Eyebrow — small uppercase mono label
// ─────────────────────────────────────────────────────────────
function Eyebrow({ children, onDark = false, rule = false, color }) {
  const c = color || (onDark ? "var(--accent-highlight)" : "var(--brand-blue)");
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
      <span style={{
        fontFamily: "var(--font-mono)", fontSize: 10.5, letterSpacing: "0.18em",
        textTransform: "uppercase", color: c, fontWeight: 500,
      }}>{children}</span>
      {rule && <span style={{ height: 1, width: 40, background: onDark ? "rgba(255,255,255,0.12)" : "var(--line-light)" }} />}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Highlight mark — yellow underline behind keyword
// ─────────────────────────────────────────────────────────────
function Mark({ children, color = "var(--brand-ink)", bar = "rgba(255,224,102,0.55)" }) {
  return (
    <span style={{ position: "relative", display: "inline-block" }}>
      <span style={{ position: "relative", zIndex: 1, color }}>{children}</span>
      <span style={{ position: "absolute", left: -2, right: -2, bottom: 1, height: 9, background: bar, zIndex: 0 }} />
    </span>
  );
}

// ─────────────────────────────────────────────────────────────
// Pill — small rounded tag
// ─────────────────────────────────────────────────────────────
function Pill({ children, variant = "default", small = false }) {
  const styles = {
    default: { bg: "rgba(62,94,146,0.06)", fg: "var(--brand-blue)", bd: "rgba(62,94,146,0.18)" },
    teal:    { bg: "rgba(111,137,132,0.10)", fg: "#4d6863", bd: "rgba(111,137,132,0.22)" },
    yellow:  { bg: "rgba(255,224,102,0.35)", fg: "#7a5f12", bd: "rgba(200,158,30,0.32)" },
    ink:     { bg: "rgba(31,36,48,0.06)", fg: "var(--brand-ink)", bd: "rgba(31,36,48,0.12)" },
    onDark:  { bg: "rgba(255,255,255,0.07)", fg: "rgba(255,255,255,0.92)", bd: "rgba(255,255,255,0.12)" },
    highlight: { bg: "var(--accent-highlight)", fg: "#5a4506", bd: "transparent" },
  }[variant];
  return (
    <span style={{
      display: "inline-flex", alignItems: "center", gap: 6,
      padding: small ? "3px 8px" : "5px 10px",
      borderRadius: 999, fontSize: small ? 10.5 : 11.5, fontWeight: 600,
      letterSpacing: "-0.005em",
      background: styles.bg, color: styles.fg,
      border: `1px solid ${styles.bd}`,
      whiteSpace: "nowrap",
    }}>{children}</span>
  );
}

// ─────────────────────────────────────────────────────────────
// Btn — primary / secondary / yellow / ghost
// ─────────────────────────────────────────────────────────────
function Btn({ children, variant = "primary", size = "md", iconRight, iconLeft, full = true, href, target = "_self" }) {
  const sizes = {
    md: { p: "14px 20px", fs: 15, r: 10 },
    sm: { p: "10px 14px", fs: 13.5, r: 8 },
    lg: { p: "17px 22px", fs: 15.5, r: 12 },
  }[size];
  const variants = {
    primary: { bg: "var(--brand-blue)", c: "#fff", bd: "transparent", sh: "0 4px 14px rgba(62,94,146,0.28)" },
    yellow:  { bg: "var(--accent-highlight)", c: "var(--brand-ink)", bd: "transparent", sh: "0 4px 14px rgba(200,158,30,0.25)" },
    dark:    { bg: "var(--brand-ink)", c: "#fff", bd: "transparent", sh: "0 4px 14px rgba(31,36,48,0.25)" },
    ghost:   { bg: "transparent", c: "var(--brand-ink)", bd: "1px solid var(--line)", sh: "none" },
    ghostOnDark: { bg: "transparent", c: "#fff", bd: "1px solid rgba(255,255,255,0.18)", sh: "none" },
    light:   { bg: "#fff", c: "var(--brand-ink)", bd: "1px solid var(--line-light)", sh: "0 1px 2px rgba(31,36,48,0.04)" },
    kakao:   { bg: "#FEE500", c: "#191919", bd: "transparent", sh: "0 4px 14px rgba(254,229,0,0.35)" },
  }[variant];
  const Tag = href ? "a" : "span";
  const linkProps = href ? {
    href,
    target,
    rel: target === "_blank" ? "noopener noreferrer" : undefined,
  } : {};
  return (
    <Tag {...linkProps} style={{
      display: full ? "flex" : "inline-flex", alignItems: "center", justifyContent: "center",
      gap: 8, padding: sizes.p, fontSize: sizes.fs, fontWeight: 600,
      letterSpacing: "-0.012em",
      borderRadius: sizes.r, background: variants.bg, color: variants.c,
      border: variants.bd, boxShadow: variants.sh,
      cursor: "pointer",
      width: full ? "100%" : "auto",
      boxSizing: "border-box",
      whiteSpace: "nowrap",
      textDecoration: "none",
    }}>
      {iconLeft}
      <span>{children}</span>
      {iconRight}
    </Tag>
  );
}

// ─────────────────────────────────────────────────────────────
// Card — warm off-white panel
// ─────────────────────────────────────────────────────────────
function Card({ children, dark = false, padding = 20, style }) {
  return (
    <div style={{
      background: dark ? "var(--accent-navy)" : "var(--surface-elevated)",
      border: dark ? "1px solid rgba(255,255,255,0.06)" : "1px solid var(--line-light)",
      borderRadius: 14,
      padding,
      color: dark ? "rgba(255,255,255,0.92)" : "var(--brand-ink)",
      ...style,
    }}>{children}</div>
  );
}

// ─────────────────────────────────────────────────────────────
// Dot grid background pattern (very faint)
// ─────────────────────────────────────────────────────────────
function DotGrid({ opacity = 0.5, size = 22, dark = false }) {
  const c = dark ? "rgba(255,255,255,0.12)" : "rgba(31,36,48,0.13)";
  return (
    <div style={{
      position: "absolute", inset: 0,
      backgroundImage: `radial-gradient(${c} 1px, transparent 1px)`,
      backgroundSize: `${size}px ${size}px`,
      opacity, pointerEvents: "none",
    }} />
  );
}

// ─────────────────────────────────────────────────────────────
// Stat tile — large number + label
// ─────────────────────────────────────────────────────────────
function Stat({ num, suffix, label, onDark = false }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
      <div style={{
        fontFamily: "var(--font-serif)",
        fontSize: 30, fontWeight: 700, lineHeight: 1, letterSpacing: "-0.02em",
        color: onDark ? "#fff" : "var(--brand-ink)",
        display: "inline-flex", alignItems: "baseline", gap: 2,
      }}>
        {num}
        {suffix && <span style={{ fontSize: 14, fontWeight: 500, opacity: 0.8, letterSpacing: 0, fontFamily: "var(--font-sans)" }}>{suffix}</span>}
      </div>
      <div style={{
        fontSize: 11, fontWeight: 500, letterSpacing: "-0.005em",
        color: onDark ? "rgba(255,255,255,0.55)" : "var(--text-soft)",
        lineHeight: 1.35,
      }}>{label}</div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// MobileFrame — simulated phone (status bar + content area + home indicator)
// ─────────────────────────────────────────────────────────────
function MobileFrame({ children, width = 390, theme = "paper", showHome = true, showStatus = true }) {
  const bg = theme === "paper" ? "var(--paper)" : (theme === "navy" ? "var(--accent-navy)" : "#fff");
  return (
    <div style={{
      width: "100%", maxWidth: width, background: bg, position: "relative",
      fontFamily: "var(--font-sans)", color: "var(--brand-ink)",
      letterSpacing: "-0.011em",
      boxSizing: "border-box", margin: "0 auto",
    }}>
      {showStatus && (
        <div style={{
          height: 44, display: "flex", alignItems: "center", justifyContent: "space-between",
          padding: "0 22px", fontWeight: 600, fontSize: 15,
          color: theme === "navy" ? "#fff" : "var(--brand-ink)",
        }}>
          <span style={{ fontFeatureSettings: '"tnum"' }}>9:41</span>
          <span style={{ display: "flex", gap: 4, alignItems: "center" }}>
            <svg width="17" height="11" viewBox="0 0 17 11" fill="currentColor"><rect x="0" y="6" width="3" height="5" rx="0.5"/><rect x="4.5" y="4" width="3" height="7" rx="0.5"/><rect x="9" y="2" width="3" height="9" rx="0.5"/><rect x="13.5" y="0" width="3" height="11" rx="0.5"/></svg>
            <svg width="22" height="11" viewBox="0 0 22 11" fill="none" stroke="currentColor" strokeWidth="1"><rect x="0.5" y="0.5" width="18" height="10" rx="2.5"/><rect x="2" y="2" width="15" height="7" rx="1.2" fill="currentColor"/><path d="M20 4v3" strokeLinecap="round"/></svg>
          </span>
        </div>
      )}
      {children}
      {showHome && (
        <div style={{ height: 28, display: "flex", justifyContent: "center", alignItems: "center", paddingBottom: 8 }}>
          <span style={{ width: 134, height: 5, borderRadius: 99, background: theme === "navy" ? "rgba(255,255,255,0.4)" : "rgba(31,36,48,0.4)" }} />
        </div>
      )}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Brand wordmark — ITCONNECT in Pretendard 700
// ─────────────────────────────────────────────────────────────
function Wordmark({ size = 16, color = "var(--brand-ink)" }) {
  return (
    <span style={{
      fontFamily: "var(--font-sans)", fontWeight: 700,
      letterSpacing: "-0.02em", fontSize: size, color,
    }}>ITCONNECT</span>
  );
}

Object.assign(window, { Icon, Eyebrow, Mark, Pill, Btn, Card, DotGrid, Stat, MobileFrame, Wordmark });
