/* Product-UI fragments used inside marketing cards. Cosmetic only. */
const { Tag, Toggle, Icon } = window.DuologueDesignSystem_a613c9;

const shell = {
  background: "var(--white)", borderRadius: "var(--radius-md)",
  border: "var(--border-hairline)", overflow: "hidden", width: "100%"
};
const rowLine = { display: "flex", alignItems: "center", gap: 12, padding: "12px 14px", borderBottom: "var(--border-hairline)" };
const mono = { fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: ".08em", textTransform: "uppercase", color: "var(--text-muted)" };

/* ============================================================
   Original marketing mocks, used by screen-product / screen-pricing.
   ============================================================ */

function SequenceMock() {
  const steps = [
    { d: "Day 0", t: "Cold email · opener from their launch post", s: "Sent" },
    { d: "Day 2", t: "Call · reference the pricing question", s: "Queued" },
    { d: "Day 5", t: "LinkedIn · one line, no pitch", s: "Draft" }
  ];
  return <div style={shell}>
    <div style={{ ...rowLine, justifyContent: "space-between", background: "var(--ink-050)" }}>
      <span style={mono}>Sequence · Series B ops leads</span><Tag tone="success" dot>Live</Tag>
    </div>
    {steps.map((s, i) => <div key={i} style={rowLine}>
      <span style={{ ...mono, width: 44 }}>{s.d}</span>
      <span style={{ flex: 1, fontSize: 13, color: "var(--text-strong)" }}>{s.t}</span>
      <Tag tone={s.s === "Sent" ? "neutral" : s.s === "Queued" ? "brand" : "outline"}>{s.s}</Tag>
    </div>)}
  </div>;
}

function MemoryMock() {
  const facts = [
    ["Asked about SOC 2 twice, send the report first.", "Objection"],
    ["Budget cycle closes 31 March.", "Timing"],
    ["Dana owns the tool decision, not Marcus.", "Champion"]
  ];
  return <div style={shell}>
    <div style={{ ...rowLine, gap: 18, background: "var(--ink-050)" }}>
      <span style={{ ...mono, color: "var(--text-strong)" }}>All (28)</span>
      <span style={mono}>Objections (9)</span><span style={mono}>People (12)</span>
    </div>
    {facts.map(([t, tag], i) => <div key={i} style={{ ...rowLine, alignItems: "flex-start", flexDirection: "column", gap: 8 }}>
      <span style={{ fontSize: 13, color: "var(--text-strong)" }}>{t}</span><Tag tone="brand">{tag}</Tag>
    </div>)}
  </div>;
}

function CallPrepMock() {
  return <div style={shell}>
    <div style={{ padding: "14px 14px 10px" }}>
      <div style={mono}>Call in 15 min · Northbeam</div>
      <div style={{ fontSize: 15, fontWeight: 700, color: "var(--text-strong)", marginTop: 6 }}>Open with the migration, not the demo</div>
    </div>
    {["They churned off Outreach in Jan.", "Last reply: “send pricing after the board meeting”.", "Two reps already trialling."].map((t, i) =>
      <div key={i} style={rowLine}><Icon name="dot" size={8} color="var(--blue-700)" /><span style={{ fontSize: 13 }}>{t}</span></div>)}
  </div>;
}

function AutomationsMock() {
  const rows = [["Draft the nudge when a thread goes quiet", "3 days after last reply"], ["Log the call summary to HubSpot", "On call end"]];
  return <div style={{ display: "grid", gap: 10, width: "100%" }}>
    {rows.map(([t, w], i) => <div key={i} style={{ background: "var(--ink-050)", borderRadius: "var(--radius-md)", padding: 14 }}>
      <div style={{ fontSize: 14, fontWeight: 700, color: "var(--text-strong)" }}>{t}</div>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginTop: 10 }}>
        <span style={mono}>{w}</span><Toggle checked size={22} />
      </div>
    </div>)}
  </div>;
}

function InboxMock() {
  const rows = [["Dana Okafor", "Re: pricing after the board call", "Reply due", "brand"],
    ["Marcus Vance", "Intro to the ops team", "Waiting", "neutral"],
    ["Priya Raman", "Migration questions", "Draft ready", "success"]];
  return <div style={{ ...shell, boxShadow: "var(--shadow-raised)" }}>
    <div style={{ ...rowLine, justifyContent: "space-between", background: "var(--ink-050)" }}>
      <span style={mono}>Today · 6 threads need you</span><Tag tone="brand">Focus</Tag>
    </div>
    {rows.map(([n, s, st, tone], i) => <div key={i} style={rowLine}>
      <span style={{ width: 120, fontSize: 13, fontWeight: 700, color: "var(--text-strong)" }}>{n}</span>
      <span style={{ flex: 1, fontSize: 13, color: "var(--text-body)" }}>{s}</span>
      <Tag tone={tone}>{st}</Tag>
    </div>)}
    <div style={{ padding: 14, display: "flex", gap: 10, alignItems: "center" }}>
      <span style={{ ...mono, color: "var(--text-strong)" }}>Suggested</span>
      <span style={{ fontSize: 13, color: "var(--text-body)" }}>“You mentioned the board call, did pricing land?”</span>
    </div>
  </div>;
}

/* ============================================================
   Duologue product UI, ported from the "Duologue Design System -
   Components" library so the marketing visuals match the real app.
   Everything below renders inside a `.duo-cmp` token scope (defined
   in index.html) which supplies the Components palette + Figtree.
   ============================================================ */

const CMP_AVATAR_TINTS = [
  ["var(--violet-100)", "var(--violet-600)"],
  ["var(--blue-100)", "var(--blue-700)"],
  ["var(--green-100)", "var(--green-700)"],
  ["var(--teal-100)", "var(--teal-600)"],
  ["var(--amber-50)", "var(--amber-700)"]
];
function CAvatar({ name = "", size = 34, badge, style }) {
  const initials = name.split(/[\s-]+/).filter(Boolean).slice(0, 2).map(w => w[0]).join("").toUpperCase();
  const idx = Math.abs([...name].reduce((a, c) => a + c.charCodeAt(0), 0)) % CMP_AVATAR_TINTS.length;
  const [bg, fg] = CMP_AVATAR_TINTS[idx];
  return <span style={{ position: "relative", display: "inline-flex", flex: "0 0 auto", ...style }}>
    <span style={{ width: size, height: size, borderRadius: "var(--r-pill)", display: "inline-flex", alignItems: "center", justifyContent: "center", background: bg, color: fg, font: `600 ${Math.round(size * 0.36)}px/1 var(--font-sans)`, letterSpacing: ".02em" }}>{initials}</span>
    {badge ? <span style={{ position: "absolute", right: -3, bottom: -3, minWidth: 14, height: 14, padding: "0 3px", borderRadius: "var(--r-pill)", background: "var(--green-100)", color: "var(--green-700)", border: "2px solid var(--surface-card)", display: "inline-flex", alignItems: "center", justifyContent: "center", font: "700 9px/1 var(--font-sans)" }}>{badge}</span> : null}
  </span>;
}

const CMP_BADGE_TONES = {
  neutral: ["var(--surface-active)", "var(--text-secondary)"],
  success: ["var(--green-50)", "var(--green-700)"],
  accent: ["var(--blue-50)", "var(--blue-700)"],
  warning: ["var(--amber-50)", "var(--amber-700)"],
  danger: ["var(--red-50)", "var(--red-700)"]
};
function CBadge({ children, tone = "neutral", caps = true, dot = false, style }) {
  const [bg, fg] = CMP_BADGE_TONES[tone] || CMP_BADGE_TONES.neutral;
  return <span style={{ display: "inline-flex", alignItems: "center", gap: 5, padding: caps ? "2px 6px" : "3px 9px", borderRadius: "var(--r-chip)", font: "600 var(--fs-micro)/var(--lh-micro) var(--font-sans)", letterSpacing: caps ? "var(--ls-caps)" : 0, textTransform: caps ? "uppercase" : "none", background: bg, color: fg, ...style }}>
    {dot ? <span style={{ width: 5, height: 5, borderRadius: "var(--r-pill)", background: "currentColor" }} /> : null}{children}
  </span>;
}

function CCaps({ children, color = "var(--text-muted)", style }) {
  return <span style={{ font: "var(--type-section-caps)", letterSpacing: "var(--ls-caps)", textTransform: "uppercase", color, ...style }}>{children}</span>;
}

function CCard({ children, tone = "default", padding = "var(--pad-card)", style }) {
  const tones = {
    default: { background: "var(--surface-card)", border: "1px solid var(--border-default)" },
    sunken: { background: "var(--surface-sunken)", border: "1px solid transparent" },
    accent: { background: "var(--accent-tint)", border: "1px solid var(--blue-100)" }
  };
  return <div style={{ borderRadius: "var(--r-card)", padding, ...tones[tone], ...style }}>{children}</div>;
}

function CTabs({ tabs, value }) {
  return <div style={{ display: "flex", alignItems: "center", gap: 24, flexWrap: "wrap" }}>
    {tabs.map(t => {
      const active = t.id === value;
      return <span key={t.id} style={{ display: "inline-flex", alignItems: "center", gap: 8, font: `${active ? 600 : 500} var(--fs-heading)/var(--lh-heading) var(--font-sans)`, color: active ? "var(--text-primary)" : "var(--text-muted)" }}>
        {t.label}{typeof t.count === "number" ? <span style={{ minWidth: 18, height: 18, padding: "0 5px", borderRadius: "var(--r-pill)", display: "inline-flex", alignItems: "center", justifyContent: "center", font: "600 var(--fs-caption)/1 var(--font-sans)", background: active ? "var(--surface-active)" : "var(--surface-hover)", color: active ? "var(--text-secondary)" : "var(--text-disabled)" }}>{t.count}</span> : null}
      </span>;
    })}
  </div>;
}

function CRow({ subject, person, tag, badge, time, unread, selected }) {
  return <div style={{ display: "flex", alignItems: "center", gap: 16, padding: "13px 24px", borderBottom: selected ? "1px solid transparent" : "1px solid var(--border-subtle)", background: selected ? "var(--surface-selected)" : "transparent" }}>
    <CAvatar name={person} size={34} badge={badge} />
    <div style={{ flex: 1, minWidth: 0 }}>
      <div style={{ font: `${unread ? 600 : 500} var(--fs-heading)/var(--lh-heading) var(--font-sans)`, color: "var(--text-primary)", letterSpacing: "var(--ls-tight)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{subject}</div>
      <div style={{ display: "flex", alignItems: "center", gap: 10, marginTop: 2 }}>
        <span style={{ font: "var(--type-body)", color: "var(--text-secondary)" }}>{person}</span>
        {tag ? <CBadge tone="success">{tag}</CBadge> : null}
      </div>
    </div>
    <span style={{ font: "var(--type-body)", color: "var(--text-muted)", flex: "0 0 auto" }}>{time}</span>
  </div>;
}

function CIconBtn({ name }) {
  return <span style={{ width: 32, height: 32, borderRadius: "var(--r-md)", border: "1px solid var(--border-default)", background: "var(--surface-card)", display: "inline-flex", alignItems: "center", justifyContent: "center", flex: "0 0 auto" }}>
    <Icon name={name} size={16} color="var(--text-secondary)" />
  </span>;
}

// HERO CENTERPIECE, the account-native inbox: nav rail + conversation list +
// account detail rail. Framed like a real product screenshot.
function WorkspaceMock() {
  const rows = [
    { subject: "Renewal question on our seats", person: "Russ Hanneman · Trescomas", tag: "Long-term customer", badge: "$", time: "1h", unread: true },
    { subject: "New VP Sales just started", person: "Dana Okafor · Kestrel", tag: "New champion", time: "2h", unread: true, selected: true },
    { subject: "Can we sync HubSpot fields?", person: "Jian-Yang · Pied Piper", time: "3h", unread: true },
    { subject: "Security review before we renew", person: "Priya Raman · Northbeam", tag: "SOC 2 sent", time: "Yesterday" },
    { subject: "Budget frozen until Q3", person: "Marcus Vance · Ovion", time: "2d" }
  ];
  const changed = [["banknote", "Raised a $40M Series B", "2h"], ["user-plus", "Hired a VP of Revenue", "1d"], ["refresh-cw", "Moved off Outreach", "3d"]];
  return <div className="duo-cmp" style={{ width: "100%", display: "flex", justifyContent: "center", overflow: "hidden" }}>
    <div className="du-workspace" style={{ width: "100%", maxWidth: 1060, minWidth: 900, borderRadius: 16, overflow: "hidden", border: "1px solid var(--border-default)", background: "var(--surface-card)", boxShadow: "var(--shadow-lg)" }}>
      {/* window chrome */}
      <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "11px 16px", borderBottom: "1px solid var(--border-subtle)", background: "var(--surface-canvas)" }}>
        <span style={{ display: "flex", gap: 6 }}>{["#E5484D", "#E9A33A", "#2CBB6B"].map(c => <span key={c} style={{ width: 10, height: 10, borderRadius: "var(--r-pill)", background: c, opacity: .85 }} />)}</span>
        <span style={{ flex: 1 }} />
        <span style={{ font: "var(--type-label)", color: "var(--text-muted)" }}>duologue · Acme Sales workspace</span>
        <span style={{ flex: 1 }} />
      </div>
      <div style={{ display: "flex", height: 496, minHeight: 0 }}>
        {/* nav rail */}
        <div style={{ width: "var(--nav-rail-width)", flex: "0 0 auto", borderRight: "1px solid var(--border-subtle)", display: "flex", flexDirection: "column", alignItems: "center", padding: "16px 0" }}>
          <img src={(typeof window !== "undefined" && window.DUOLOGUE_ASSETS ? window.DUOLOGUE_ASSETS : "../../assets/") + "duologue-mark.svg"} alt="duologue" style={{ width: 20, height: 20, objectFit: "contain" }} />
          <div style={{ marginTop: 24, display: "flex", flexDirection: "column", gap: 20 }}>
            <Icon name="inbox" size={19} color="var(--accent-solid)" />
            <Icon name="send" size={19} color="var(--text-muted)" />
            <Icon name="users" size={19} color="var(--text-muted)" />
            <Icon name="settings" size={19} color="var(--text-muted)" />
          </div>
          <div style={{ flex: 1 }} />
          <CAvatar name="Amal Rahman" size={30} />
        </div>
        {/* list column */}
        <div style={{ flex: 1, minWidth: 0, display: "flex", flexDirection: "column" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 16, padding: "18px 24px 14px", borderBottom: "1px solid var(--border-subtle)" }}>
            <CTabs value="inbox" tabs={[{ id: "inbox", label: "Inbox", count: 5 }, { id: "replies", label: "Replies", count: 2 }, { id: "followups", label: "Follow-ups", count: 3 }, { id: "vip", label: "VIP", count: 1 }]} />
            <span style={{ flex: 1 }} />
            <CIconBtn name="search" /><CIconBtn name="sliders-horizontal" />
          </div>
          <div style={{ padding: "8px 0" }}>
            {rows.map((r, i) => <CRow key={i} {...r} />)}
          </div>
        </div>
        {/* account detail rail */}
        <div className="du-workspace-rail" style={{ width: 312, flex: "0 0 auto", borderLeft: "1px solid var(--border-subtle)", padding: "22px 22px 30px", display: "flex", flexDirection: "column", gap: 24, background: "var(--surface-card)" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
            <CAvatar name="Kestrel" size={40} />
            <div>
              <div style={{ font: "600 var(--fs-subheading)/var(--lh-subheading) var(--font-sans)", color: "var(--text-primary)" }}>Kestrel</div>
              <div style={{ font: "var(--type-body)", color: "var(--text-secondary)" }}>Series B · 120 employees</div>
            </div>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 11 }}>
            <CCaps>What changed</CCaps>
            {changed.map(([ic, t, w], i) => <div key={i} style={{ display: "flex", alignItems: "center", gap: 10 }}>
              <span style={{ width: 26, height: 26, borderRadius: "var(--r-md)", background: "var(--accent-tint)", display: "grid", placeItems: "center", flex: "0 0 auto" }}><Icon name={ic} size={14} color="var(--blue-600)" /></span>
              <span style={{ flex: 1, font: "500 var(--fs-body)/var(--lh-body) var(--font-sans)", color: "var(--text-body)" }}>{t}</span>
              <span style={{ font: "var(--type-body)", color: "var(--text-muted)" }}>{w}</span>
            </div>)}
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
            <CCaps>Objections in play</CCaps>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
              <CBadge tone="warning">Not ready to scale tooling</CBadge>
              <CBadge tone="accent">Timing · end of quarter</CBadge>
            </div>
          </div>
          <CCard tone="accent" style={{ padding: "13px 15px" }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 7 }}><Icon name="sparkles" size={14} color="var(--blue-600)" /><CCaps color="var(--blue-700)">Suggested reply</CCaps></div>
            <div style={{ font: "var(--type-body)", color: "var(--text-body)" }}>Lead with the raise, teams hiring 8 AEs feel the tooling gap by month two.</div>
          </CCard>
        </div>
      </div>
    </div>
  </div>;
}

// VALUE 1, "Learns what's changing at each account, periodically."
function SignalsCardMock() {
  const signals = [["banknote", "Raised a $40M Series B", "Funding", "2h"], ["user-plus", "Hired a VP of Revenue", "People", "1d"], ["refresh-cw", "Moved off Outreach", "Tech", "3d"], ["building-2", "Opened a London office", "Expansion", "1w"]];
  return <div className="duo-cmp"><CCard padding="0" style={{ overflow: "hidden", boxShadow: "var(--shadow-md)" }}>
    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "14px 16px", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}><CAvatar name="Northbeam" size={28} /><span style={{ font: "600 var(--fs-heading)/1 var(--font-sans)", color: "var(--text-primary)" }}>Northbeam</span></div>
      <CBadge tone="success" dot>Refreshed 2h ago</CBadge>
    </div>
    {signals.map(([ic, t, kind, w], i) => <div key={i} style={{ display: "flex", alignItems: "center", gap: 12, padding: "12px 16px", borderBottom: "1px solid var(--border-subtle)" }}>
      <span style={{ width: 30, height: 30, borderRadius: "var(--r-md)", background: "var(--accent-tint)", display: "grid", placeItems: "center", flex: "0 0 auto" }}><Icon name={ic} size={15} color="var(--blue-600)" /></span>
      <span style={{ flex: 1, font: "500 var(--fs-body)/var(--lh-body) var(--font-sans)", color: "var(--text-body)" }}>{t}</span>
      <CBadge tone="neutral">{kind}</CBadge>
      <span style={{ font: "var(--type-body)", color: "var(--text-muted)", width: 26, textAlign: "right" }}>{w}</span>
    </div>)}
    <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "12px 16px", background: "var(--surface-sunken)" }}><Icon name="refresh-cw" size={13} color="var(--text-muted)" /><span style={{ font: "var(--type-label)", color: "var(--text-secondary)" }}>Checks every account, hourly</span></div>
  </CCard></div>;
}

// VALUE 2, "Turns account data into context automatically."
function ContextCardMock() {
  return <div className="duo-cmp"><CCard padding="0" style={{ overflow: "hidden", boxShadow: "var(--shadow-md)" }}>
    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "14px 16px", borderBottom: "1px solid var(--border-subtle)" }}>
      <CCaps>Auto-context · Kestrel</CCaps><CBadge tone="accent">Objection · timing</CBadge>
    </div>
    <div style={{ padding: 16 }}>
      <CCaps style={{ display: "block", marginBottom: 10 }}>What changed</CCaps>
      <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
        {["Series B · $40M", "New VP Sales", "Hiring 8 AEs"].map((s, i) => <CBadge key={i} tone="neutral" caps={false} style={{ fontSize: "var(--fs-label)", fontWeight: 500 }}>{s}</CBadge>)}
      </div>
      <div style={{ display: "flex", alignItems: "center", gap: 8, margin: "14px 0" }}><Icon name="arrow-down" size={15} color="var(--blue-500)" /><span style={{ font: "var(--type-label)", color: "var(--text-secondary)" }}>Duologue turns it into the line you send</span></div>
      <CCard tone="accent" style={{ padding: "14px 16px" }}>
        <div style={{ font: "400 15px/23px var(--font-sans)", color: "var(--text-body)" }}>“Congrats on the raise, teams hiring 8 AEs usually feel the tooling gap by month two. Worth 20 minutes before the new reps ramp?”</div>
        <div style={{ display: "flex", alignItems: "center", gap: 7, marginTop: 12 }}><Icon name="circle-check" size={15} color="var(--green-600)" /><CCaps color="var(--green-700)">Breaks “not ready to scale tooling”</CCaps></div>
      </CCard>
    </div>
  </CCard></div>;
}

// VALUE 3, "Keeps the thread coherent across multiple channels."
function ThreadCardMock() {
  const items = [["mail", "Email", "Asked for pricing after the board meeting", "Mon"], ["linkedin", "LinkedIn", "Liked the Series B launch post", "Wed"], ["phone", "Call", "Said Dana owns the decision, not Marcus", "Thu"]];
  return <div className="duo-cmp"><CCard padding="0" style={{ overflow: "hidden", boxShadow: "var(--shadow-md)" }}>
    <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "14px 16px", borderBottom: "1px solid var(--border-subtle)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}><CAvatar name="Ovion" size={28} /><span style={{ font: "600 var(--fs-heading)/1 var(--font-sans)", color: "var(--text-primary)" }}>Ovion</span></div>
      <CBadge tone="neutral">3 channels</CBadge>
    </div>
    {items.map(([ic, ch, t, when], i) => <div key={i} style={{ display: "flex", gap: 12, padding: "13px 16px", borderBottom: "1px solid var(--border-subtle)" }}>
      <span style={{ width: 30, height: 30, borderRadius: "var(--r-md)", background: "var(--accent-tint)", display: "grid", placeItems: "center", flex: "0 0 auto" }}><Icon name={ic} size={15} color="var(--blue-600)" /></span>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 8 }}><span style={{ font: "600 var(--fs-label)/1 var(--font-sans)", color: "var(--text-primary)" }}>{ch}</span><span style={{ font: "var(--type-body)", color: "var(--text-muted)" }}>{when}</span></div>
        <div style={{ font: "var(--type-body)", color: "var(--text-body)", marginTop: 3 }}>{t}</div>
      </div>
    </div>)}
    <div style={{ padding: "14px 16px", background: "var(--surface-sunken)" }}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 7 }}><CCaps color="var(--text-secondary)">Next touch · Email</CCaps><CBadge tone="success">Draft ready</CBadge></div>
      <div style={{ font: "var(--type-body)", color: "var(--text-body)" }}>“Dana, sending pricing ahead of the 31st, like you asked on our call.”</div>
    </div>
  </CCard></div>;
}

Object.assign(window, {
  SequenceMock, MemoryMock, CallPrepMock, AutomationsMock, InboxMock,
  WorkspaceMock, SignalsCardMock, ContextCardMock, ThreadCardMock
});
