/* global React, Head, Foot, Bubble, Proactive, Msg, Typing, Chips, Input, VoiceRecording, PreChat, Handoff, CSAT, Offline, Settings, DesignCanvas, DCSection, DCArtboard */
const { useState } = React;

/* ============================================================
   STATE COMPOSERS — full panel for each state
   ============================================================ */

function StateClosed({ variant, badgeCount=2 }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <Bubble unread={badgeCount} />
    </div>
  );
}

function StateProactive({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <Proactive />
    </div>
  );
}

function StateStarters({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Praatbox" status="online" />
        <Starters
          intro="Hey! Pick a question to get started, or type your own."
          items={[
            "Wat kost Praatbox?",
            "Hoe installeer ik de widget?",
            "Welke talen worden ondersteund?",
            "Wat zit er in de gratis proef?",
          ]}
        />
        <Input placeholder="Typ uw bericht…" />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StatePreChat({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Hi 👋" status="online" />
        <PreChat />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateConversation({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="AI Assistant" status="online" />
        <div className="w-body">
          <Msg role="bot" time="14:02">Hey Anouk! 👋 How can I help today?</Msg>
          <Msg role="user" time="14:02">I want to track my package — order #4291</Msg>
          <Msg role="bot" time="14:03">Found it. Your order shipped Tuesday and is currently <strong>out for delivery</strong> in Amsterdam. Estimated arrival: today before 18:00.</Msg>
          <Msg role="bot">Anything else I can dig into?</Msg>
          <Chips items={["See tracking","Change address","Talk to agent"]} />
        </div>
        <Input placeholder="Type your message…" />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateTyping({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="AI Assistant" status="online" />
        <div className="w-body">
          <Msg role="user" time="14:05">Can you cancel my subscription?</Msg>
          <Typing />
        </div>
        <Input />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateVoice({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="AI Assistant" status="online" />
        <VoiceRecording />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateHandoff({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Support" status="waiting" />
        <div className="w-body">
          <Msg role="user" time="14:08">I need to talk to a human about a refund</Msg>
          <Msg role="bot" time="14:08">No problem — let me get Sara from billing. She handles refunds personally and is online right now.</Msg>
          <Handoff />
          <Msg role="system">SARA JOINED THE CONVERSATION</Msg>
          <Msg role="bot" time="14:09">Hi Anouk, I'm Sara. I see you're asking about order #4291 — give me 30 seconds to pull it up.</Msg>
        </div>
        <Input />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateCSAT({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Sara · Resolved" status="offline" />
        <CSAT />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateOffline({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Currently away" status="offline" />
        <Offline />
        <Foot show={true} />
      </div>
    </div>
  );
}

function StateSettings({ variant }) {
  return (
    <div className={`widget-stage v-${variant}`}>
      <div className="w-panel">
        <Head variant={variant} agentName="Settings" status="online" />
        <Settings />
        <Foot show={true} />
      </div>
    </div>
  );
}

/* ============================================================
   LAYOUT — DesignCanvas: one section per variant, 10 artboards each
   ============================================================ */

const STATES = [
  { id: "closed",       label: "01 — Closed bubble",          w: 460, h: 220, Cmp: StateClosed },
  { id: "proactive",    label: "02 — Proactive popup",        w: 460, h: 280, Cmp: StateProactive },
  { id: "starters",     label: "03 — Starter questions",      w: 460, h: 700, Cmp: StateStarters },
  { id: "pre-chat",     label: "04 — Pre-chat form",          w: 460, h: 700, Cmp: StatePreChat },
  { id: "conversation", label: "05 — Open conversation",      w: 460, h: 700, Cmp: StateConversation },
  { id: "typing",       label: "06 — AI is typing",           w: 460, h: 700, Cmp: StateTyping },
  { id: "voice",        label: "07 — Voice recording",        w: 460, h: 700, Cmp: StateVoice },
  { id: "handoff",      label: "08 — Live agent handoff",     w: 460, h: 700, Cmp: StateHandoff },
  { id: "csat",         label: "09 — Conversation rated",     w: 460, h: 700, Cmp: StateCSAT },
  { id: "offline",      label: "10 — Offline / email capture", w: 460, h: 700, Cmp: StateOffline },
  { id: "settings",     label: "11 — Settings",               w: 460, h: 700, Cmp: StateSettings },
];

const VARIANTS = [
  { id: "default",   title: "Default — paper, rounded",    subtitle: "Closest to the existing widget. Soft cream surface, generous radii, friendly green primary.", bg: "linear-gradient(135deg, #f0e8d6 0%, #faf6ec 100%)" },
  { id: "minimal",   title: "Minimal — sharp, mono",       subtitle: "No rounded corners, ink-black header, mono accents. For confident, technical brands.",          bg: "linear-gradient(135deg, #ebe7df 0%, #f6f3ec 100%)" },
  { id: "dark",      title: "Dark mode",                   subtitle: "Warm dark — paper recessed to ink. Same shape language as Default, just inverted.",            bg: "linear-gradient(135deg, #1a1815 0%, #2a2622 100%)" },
  { id: "glass",     title: "Glass — frosted, layered",    subtitle: "Sits on a colorful host page. Backdrop blur + inset highlight, no hard background.",           bg: "radial-gradient(60% 60% at 30% 20%, #f9c5b0, transparent 60%), radial-gradient(50% 50% at 80% 80%, #b3d9c4, transparent 60%), linear-gradient(135deg, #faf6ec, #f0e8d6)" },
  { id: "editorial", title: "Editorial — serif heads",     subtitle: "Praatbox brand voice baked into the widget. Serif greetings, mono-cased chips, paper-cream.",  bg: "linear-gradient(135deg, #f3eee2 0%, #faf7f0 100%)" },
];

function App() {
  return (
    <DesignCanvas>
      {VARIANTS.map((v) => (
        <DCSection
          key={v.id}
          id={v.id}
          title={v.title}
          subtitle={v.subtitle}
        >
          {STATES.map((s) => {
            const C = s.Cmp;
            return (
              <DCArtboard
                key={`${v.id}-${s.id}`}
                id={`${v.id}-${s.id}`}
                label={s.label}
                width={s.w}
                height={s.h}
                style={{
                  background: v.bg,
                  padding: 0,
                }}
              >
                <C variant={v.id} />
              </DCArtboard>
            );
          })}
        </DCSection>
      ))}
    </DesignCanvas>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
