/* Mockup overlay + 11 Sample Casino screens (5 deposit + 6 withdraw) */

const {
  ArrowRight, ArrowLeft, ArrowUp, ArrowDown, ArrowUpRight,
  ChevronRight, ChevronLeft,
  ShieldCheck, Landmark, Lock, Scale,
  Building, Plug, SwapinGlyph,
  Coins, Wallet, Send, Activity, CheckCircle, Bank, Users,
  Plus, Copy, Gift, Scan, X, Alert,
  ScissorMark,
} = window;

// ─────────────────────────────────────────────────────────
// Sample Casino fictional wordmark
// ─────────────────────────────────────────────────────────
const SampleCasinoMark = ({ size = 18, color = "#fff", subtle }) => (
  <div className="sc-wordmark" style={{ display: "inline-flex", alignItems: "baseline", gap: 6, color, fontSize: size, lineHeight: 1, letterSpacing: subtle ? "0.04em" : 0 }}>
    <span style={{ fontFamily: "Poppins, sans-serif", fontWeight: 700, letterSpacing: "0.18em", fontSize: subtle ? size * 0.85 : size }}>SAMPLE</span>
    <span style={{ fontFamily: "'Fraunces', 'Times New Roman', serif", fontStyle: "italic", fontWeight: 600, fontSize: size, color: "var(--sc-gold)" }}>Casino</span>
  </div>
);

// ─────────────────────────────────────────────────────────
// Sample Casino mock device chrome (status bar)
// ─────────────────────────────────────────────────────────
const ScStatusBar = () => (
  <div className="sc-statusbar">
    <span>9:41</span>
    <span className="icons">
      <svg width="16" height="10" viewBox="0 0 16 10" fill="currentColor"><rect x="0" y="6" width="3" height="4" rx="0.5"/><rect x="4" y="4" width="3" height="6" rx="0.5"/><rect x="8" y="2" width="3" height="8" rx="0.5"/><rect x="12" y="0" width="3" height="10" rx="0.5"/></svg>
      <svg width="22" height="11" viewBox="0 0 22 11" fill="none"><rect x="0.5" y="0.5" width="18" height="10" rx="2.5" stroke="currentColor"/><rect x="2.5" y="2.5" width="14" height="6" rx="1" fill="currentColor"/><rect x="19.5" y="3.5" width="1.5" height="4" rx="0.5" fill="currentColor"/></svg>
    </span>
  </div>
);

// ─────────────────────────────────────────────────────────
// Hero card (top of every dashboard screen)
// ─────────────────────────────────────────────────────────
const ScHero = ({ cash, dimmed = false, onDeposit, onWithdraw, highlightAction }) => {
  const fmt = (n) => {
    const [w, d] = n.toFixed(2).split(".");
    return { whole: w, dec: d };
  };
  const c = fmt(cash);
  return (
    <div className="sc-hero">
      <div className="top">
        <div className="sc-avatar">JD</div>
        <div className="top-actions">
          <div className="sc-icon-btn"><Gift size={18} /></div>
        </div>
      </div>

      <div className="sc-balance-area">
        <div className="sc-balance-label" style={{ opacity: dimmed ? 0.35 : 0.8 }}>Cash Balance</div>
        <div className="sc-balance-amount" style={{ opacity: dimmed ? 0.45 : 1 }}>
          <span className="sym">€</span>
          <span className="whole">{c.whole}</span>
          <span className="dec">.{c.dec}</span>
        </div>
      </div>

      <div className="sc-actions">
        <button className={`sc-action-btn ${highlightAction === "deposit" ? "highlighted tap-pulse" : ""}`} onClick={onDeposit}>
          <Plus size={16} /> Deposit
        </button>
        <button className={`sc-action-btn ${highlightAction === "withdraw" ? "highlighted tap-pulse" : ""}`} onClick={onWithdraw}>
          <ArrowUpRight size={16} /> Withdraw
        </button>
      </div>
    </div>
  );
};

// ─────────────────────────────────────────────────────────
// Tx row (used on dashboard)
// ─────────────────────────────────────────────────────────
const ScTxRow = ({ icon, title, date, amount, status = "Confirmed" }) => (
  <div className="sc-tx-row">
    <div className="ic">{icon}</div>
    <div className="body">
      <div className="t">{title}</div>
      <div className="d">{date}</div>
    </div>
    <div className="right">
      <div className="amt">{amount}</div>
      <div className="st"><span className="d"></span>{status}</div>
    </div>
  </div>
);

// ─────────────────────────────────────────────────────────
// Dashboard (shared between deposit + withdraw flows)
// ─────────────────────────────────────────────────────────
const ScDashboard = ({ flow, balance = 30.00, transactions = [], onAction }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero
      cash={balance}
      onDeposit={() => flow === "deposit" && onAction()}
      onWithdraw={() => flow === "withdraw" && onAction()}
      highlightAction={flow}
    />
    <div className="sc-tx-list">
      {transactions.map((t, i) => (
        <ScTxRow key={i} {...t} />
      ))}
    </div>
  </div>
);

// ─────────────────────────────────────────────────────────
// DEPOSIT FLOW — 5 screens
// ─────────────────────────────────────────────────────────

// 1. Dashboard
const DepStep1 = ({ onNext }) => (
  <ScDashboard
    flow="deposit"
    balance={30.00}
    onAction={onNext}
    transactions={[
      { icon: <Plus size={14} />, title: "Cash out", date: "22/11/2025", amount: "− €50" },
      { icon: <Plus size={14} />, title: "Deposit",  date: "21/11/2025", amount: "+ €80" },
    ]}
  />
);

// 2. Choose method
const DepStep2 = ({ onNext, onClose }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero cash={30.00} dimmed />
    <div className="sc-sheet">
      <div className="sh-top">
        <button className="sh-close" onClick={onClose}><X size={20} /></button>
      </div>
      <h3>Choose method</h3>
      <div style={{ marginTop: 6 }}>
        <div className="sc-method-row">
          <div className="ic"><Bank size={20} /></div>
          <div><div className="name">Banking & Transfers</div></div>
          <ChevronRight size={20} className="chev" />
        </div>
        <div className="sc-method-row">
          <div className="ic"><Wallet size={20} /></div>
          <div><div className="name">Cards</div></div>
          <ChevronRight size={20} className="chev" />
        </div>
        <div className="sc-method-row highlighted tap-pulse" onClick={onNext} style={{ cursor: "pointer" }}>
          <div className="ic" style={{ background: "rgba(42,246,255,0.12)", color: "var(--swapin-cyan-600)" }}><Coins size={20} /></div>
          <div><div className="name">Crypto</div></div>
          <ChevronRight size={20} className="chev" />
        </div>
      </div>
    </div>
  </div>
);

// 3. Choose provider
const DepStep3 = ({ onNext, onBack }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero cash={30.00} dimmed />
    <div className="sc-sheet">
      <div className="sh-top">
        <button className="sh-back" onClick={onBack}><ChevronLeft size={22} /></button>
      </div>
      <h3>Choose crypto to deposit</h3>
      <div style={{ marginTop: 6 }}>
        {[
          { code: "USDT", color: "usdt", label: "T", desc: "Send USDT and receive EUR to your casino balance.", min: true, highlighted: true },
          { code: "ETH",  color: "eth",  label: "◆", desc: "Send ETH and receive EUR to your casino balance.", min: true },
          { code: "BTC",  color: "btc",  label: "₿", desc: "Send BTC and receive EUR to your casino balance.", min: true },
          { code: "TON",  color: "ton",  label: "T", desc: "Send TON and receive EUR to your casino balance.", min: true },
          { code: "TRX",  color: "trx",  label: "T", desc: "Send TRX and receive EUR to your casino balance.", min: true },
          { code: "USDC", color: "usdc", label: "$", desc: "Send USDC and receive EUR to your casino balance.", min: true },
        ].map((p, i) => (
          <div
            key={i}
            className={`sc-provider-row ${p.highlighted ? "highlighted tap-pulse" : ""}`}
            onClick={p.highlighted ? onNext : undefined}
            style={{ cursor: p.highlighted ? "pointer" : "default" }}
          >
            <div className={`ic ${p.color}`}>{p.label}</div>
            <div>
              <div className="name">{p.code}</div>
              <div className="sub">{p.desc}{p.min ? " Min 5 EUR. Max 1 000 000 EUR." : ""}</div>
            </div>
            <ChevronRight size={20} className="chev" />
          </div>
        ))}
      </div>
    </div>
  </div>
);

// 4. Recurring deposit address (QR + address)
const DepStep4 = ({ onNext, onClose }) => {
  // generate fake QR pattern
  const [copied, setCopied] = React.useState(false);
  const handleCopy = () => { setCopied(true); setTimeout(() => setCopied(false), 1400); };

  return (
    <div className="sc-screen">
      <ScStatusBar />
      <ScHero cash={30.00} dimmed />
      <div className="sc-sheet">
        <div className="sh-top">
          <button className="sh-close" onClick={onClose}><X size={20} /></button>
        </div>
        <div>
          <h3 style={{ fontSize: 22, fontWeight: 700, marginBottom: 8 }}>Deposit details</h3>
          <p className="sh-desc" style={{ marginBottom: 0 }}>
            By depositing USDT you confirm that you are the sole beneficiary of the USDT wallet you are depositing from. Other cryptocurrencies will be returned.
          </p>
        </div>

        <div style={{ background: "#EEF6F2", borderRadius: 14, padding: "14px 16px" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 6 }}>
            <span style={{ fontSize: 12, color: "#5d5d5d" }}>To wallet address</span>
            <button className="copy" onClick={handleCopy} style={{ display: "inline-flex", alignItems: "center", gap: 6, background: "#fff", border: "1px solid #E0E3EA", borderRadius: 999, height: 28, padding: "0 12px", fontSize: 12, fontWeight: 600, cursor: "pointer" }}>
              <Copy size={12} /> {copied ? "Copied!" : "Copy"}
            </button>
          </div>
          <div style={{ fontFamily: "var(--font-mono)", fontWeight: 600, fontSize: 14, color: "#0a0a0a" }}>TUwhKsJAW…Sy84d</div>
        </div>

        <div className="sc-qr">
          <QrSample />
        </div>

        <div className="sc-kv-list">
          <div className="sc-kv"><span className="k">Wallet address</span><span className="v mono">TUwhKsJAW…Sy84d</span></div>
          <div className="sc-kv"><span className="k">Network</span>
            <span className="v"><span className="nb"><span style={{ width: 16, height: 16, borderRadius: "50%", background: "#EB0029", display: "inline-flex", alignItems: "center", justifyContent: "center", color: "#fff", fontSize: 9, fontWeight: 700 }}>T</span>TRON</span></span>
          </div>
          <div className="sc-kv"><span className="k">Exchange rate</span><span className="v">1 USDT = 0.86 EUR</span></div>
        </div>

        <button className="sc-prim-btn tap-pulse" onClick={onNext}>Done</button>
      </div>
    </div>
  );
};

// 5. Deposit completed
const DepStep5 = ({ onNext, onClose }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero cash={30.00} dimmed />
    <div className="sc-sheet">
      <div className="sh-top">
        <button className="sh-close" onClick={onClose}><X size={20} /></button>
      </div>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
        <h3 style={{ fontSize: 22, fontWeight: 700, margin: 0 }}>Transaction details</h3>
        <span style={{ background: "#0a0a0a", color: "#fff", borderRadius: 999, fontSize: 11, padding: "4px 10px", fontWeight: 600 }}>More details</span>
      </div>

      <div style={{ marginTop: 6 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#0a0a0a", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 12, fontWeight: 700, letterSpacing: "0.02em" }}>
            JD
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>From</div>
            <div style={{ fontSize: 14, fontWeight: 600 }}>JD</div>
          </div>
          <Copy size={14} style={{ color: "#b8b8b8" }} />
        </div>

        <div style={{ marginLeft: 18, color: "#b8b8b8", margin: "4px 0 4px 18px" }}>↓</div>

        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#E8F4EE", color: "var(--sc-success)", display: "flex", alignItems: "center", justifyContent: "center" }}>
            <CheckCircle size={18} />
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 700 }}>Deposit <span style={{ fontWeight: 500, color: "#8c8c8c" }}>(Swapin)</span></div>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>Today, 10:55</div>
          </div>
          <div style={{ fontSize: 11, color: "#8c8c8c", display: "inline-flex", alignItems: "center", gap: 4 }}>
            <span style={{ width: 4, height: 4, borderRadius: "50%", background: "var(--sc-success)" }} /> Confirmed
          </div>
        </div>

        <div style={{ marginLeft: 18, color: "#b8b8b8", margin: "4px 0 4px 18px" }}>↓</div>

        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#F4F5F8", color: "#555", display: "flex", alignItems: "center", justifyContent: "center" }}>
            <Wallet size={18} />
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>To</div>
            <div style={{ fontSize: 14, fontWeight: 600 }}>Sample Casino Wallet</div>
          </div>
          <div style={{ fontSize: 18, fontWeight: 700 }}>€42.90</div>
        </div>
      </div>

      <div style={{ height: 1, background: "#EEF0F4", margin: "4px 0" }}></div>
      <div className="sc-kv"><span className="k">Exchange rate</span><span className="v">1 USDT = 0.858 EUR</span></div>

      <div style={{ marginTop: "auto" }}>
        <button className="sc-prim-btn tap-pulse" onClick={onNext}>Close</button>
      </div>
    </div>
  </div>
);

// ─────────────────────────────────────────────────────────
// WITHDRAW FLOW — 6 screens
// ─────────────────────────────────────────────────────────

// 1. Dashboard (carried-over balance + recent deposit)
const WdStep1 = ({ onNext }) => (
  <ScDashboard
    flow="withdraw"
    balance={72.90}
    onAction={onNext}
    transactions={[
      { icon: <Plus size={14} />, title: "Deposit", date: "Today, 10:55", amount: "+ €42.90" },
      { icon: <Plus size={14} />, title: "Cash out", date: "22/11/2025", amount: "− €50" },
    ]}
  />
);

// 2. Choose network
const WdStep2 = ({ onNext, onBack }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero cash={72.90} dimmed />
    <div className="sc-sheet">
      <div className="sh-top">
        <button className="sh-back" onClick={onBack}><ChevronLeft size={22} /></button>
      </div>
      <h3>Choose crypto network</h3>
      <div style={{ marginTop: 6 }}>
        <div className="sc-network-row">
          <div className="ic eth">◆</div>
          <div><div className="name">Ethereum</div></div>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ fontSize: 12, color: "#8c8c8c" }}>USDT</span>
            <ChevronRight size={20} className="chev" />
          </div>
        </div>
        <div className="sc-network-row highlighted tap-pulse" onClick={onNext} style={{ cursor: "pointer" }}>
          <div className="ic tron">T</div>
          <div><div className="name">TRON</div></div>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ fontSize: 12, color: "#8c8c8c" }}>USDT</span>
            <ChevronRight size={20} className="chev" />
          </div>
        </div>
      </div>
    </div>
  </div>
);

// 3. Wallet address entry
const WdStep3 = ({ onNext, onClose }) => {
  const [val, setVal] = React.useState("TAH5uMxiF…SWSAV");
  return (
    <div className="sc-screen">
      <ScStatusBar />
      <ScHero cash={72.90} dimmed />
      <div className="sc-sheet">
        <button className="sh-close" onClick={onClose} style={{ alignSelf: "flex-start" }}><X size={20} /></button>
        <h3 style={{ fontSize: 20, fontWeight: 700, margin: "4px 0 4px" }}>Enter recipient's wallet address</h3>
        <div style={{ fontSize: 12, color: "#8c8c8c", marginBottom: 6, display: "flex", alignItems: "center", gap: 8 }}>
          Your selected network is
          <span className="net-pill"><span className="dot">T</span>TRON</span>
        </div>
        <div className="sc-input" style={{ background: "#fff" }}>
          <input value={val} onChange={(e) => setVal(e.target.value)} placeholder="To" />
          <button className="scan-btn" style={{ background: "transparent", border: 0 }}><Scan size={20} /></button>
        </div>
        <div className="sc-prim-btn-row" style={{ marginTop: "auto" }}>
          <button className="sc-prim-btn" onClick={onClose}>Cancel</button>
          <button className="sc-prim-btn dark tap-pulse" onClick={onNext}>Confirm</button>
        </div>
      </div>
    </div>
  );
};

// 4. Select euro amount
const WdStep4 = ({ onNext, onClose }) => {
  const [amount, setAmount] = React.useState("50");
  return (
    <div className="sc-screen">
      <ScStatusBar />
      <ScHero cash={72.90} dimmed />
      <div className="sc-sheet">
        <button className="sh-close" onClick={onClose} style={{ alignSelf: "flex-start" }}><X size={20} /></button>
        <h3 style={{ fontSize: 20, fontWeight: 700, margin: "4px 0 4px" }}>Withdraw EUR</h3>
        <div style={{ fontSize: 12, color: "#8c8c8c", display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
          Your selected network is
          <span className="net-pill"><span className="dot">T</span>TRON</span>
        </div>
        <div style={{ fontSize: 12, color: "#8c8c8c" }}>
          Choose amount to withdraw to <strong style={{ color: "#0a0a0a", fontFamily: "var(--font-mono)" }}>TAH5uMxiF…SWSAV</strong>
        </div>
        <div className="sc-amount-input" style={{ background: "#fff" }}>
          <input
            value={amount}
            onChange={(e) => setAmount(e.target.value)}
            style={{ border: 0, outline: 0, fontSize: 22, fontWeight: 500, width: "100%", background: "transparent" }}
          />
          <div className="eur-tag"><span className="b">€</span>EUR</div>
        </div>

        <div className="sc-warn">
          <Alert size={16} style={{ color: "#C99A1D" }} />
          <div>Please note, withdrawals above 50 000 EUR may be subject to a delay of up to 24h.</div>
        </div>
        <div className="sc-prim-btn-row" style={{ marginTop: "auto" }}>
          <button className="sc-prim-btn" onClick={onClose}>Cancel</button>
          <button className="sc-prim-btn dark tap-pulse" onClick={onNext}>Confirm</button>
        </div>
      </div>
    </div>
  );
};

// 5. Withdrawal processing
const WdStep5 = ({ onNext, onClose }) => {
  return (
    <div className="sc-screen">
      <ScStatusBar />
      <ScHero cash={72.90} dimmed />
      <div className="sc-sheet">
        <button className="sh-close" onClick={onClose} style={{ alignSelf: "flex-start" }}><X size={20} /></button>
        <h3 style={{ fontSize: 20, fontWeight: 700, margin: 0 }}>Withdrawal details</h3>
        <p style={{ fontSize: 12, color: "#5d5d5d", margin: 0 }}>Please wait until funds arrive to the specified wallet's address.</p>

        <div style={{ fontSize: 11, color: "#8c8c8c", fontWeight: 600, letterSpacing: "0.04em", marginTop: 6 }}>Transfer tracking</div>

        <div className="sc-trans-tracker">
          <div className="sc-trans-step active">
            <div className="ic-wrap"><Activity size={18} /></div>
            <div className="lab">
              <div className="t">Payment</div>
              <div className="s">Your withdrawal is in progress</div>
            </div>
            <div className="right">
              <div className="pending-badge"><span className="d" /> Pending</div>
            </div>
          </div>
          <div className="connector" />
          <div className="sc-trans-step future">
            <div className="ic-wrap" style={{ background: "#fff" }}><span style={{ width: 8, height: 8, borderRadius: "50%", background: "transparent", border: "1.5px solid #d0d0d0" }} /></div>
            <div className="lab">
              <div className="t">Funds received</div>
            </div>
            <div className="right">
              <div className="a small">58.14 USDT</div>
              <div style={{ fontSize: 11, color: "#b8b8b8" }}>50.00 EUR</div>
            </div>
          </div>
        </div>

        <div style={{ height: 1, background: "#EEF0F4", margin: "6px 0" }} />
        <div className="sc-kv-list">
          <div className="sc-kv"><span className="k">Wallet address</span><span className="v mono">TAH5uMxiF…SWSAV</span></div>
          <div className="sc-kv"><span className="k">Network</span>
            <span className="v"><span className="nb"><span style={{ width: 16, height: 16, borderRadius: "50%", background: "#EB0029", display: "inline-flex", alignItems: "center", justifyContent: "center", color: "#fff", fontSize: 9, fontWeight: 700 }}>T</span>TRON</span></span>
          </div>
          <div className="sc-kv"><span className="k">Provider fee</span><span className="v">€0.00</span></div>
          <div className="sc-kv"><span className="k">Exchange rate</span><span className="v">1 EUR = 1.1627 USDT</span></div>
        </div>

        <button className="sc-prim-btn dark tap-pulse" onClick={onNext}>Done</button>
      </div>
    </div>
  );
};

// 6. Withdrawal completed
const WdStep6 = ({ onNext, onClose }) => (
  <div className="sc-screen">
    <ScStatusBar />
    <ScHero cash={22.90} dimmed />
    <div className="sc-sheet">
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
        <button className="sh-close" onClick={onClose}><X size={20} /></button>
        <div style={{ fontSize: 14, fontWeight: 600 }}>Transactions</div>
        <div style={{ width: 36 }}></div>
      </div>

      <div style={{ display: "flex", alignItems: "center", gap: 10, marginTop: 6 }}>
        <h3 style={{ fontSize: 22, fontWeight: 700, margin: 0 }}>Transaction details</h3>
        <span style={{ background: "#0a0a0a", color: "#fff", borderRadius: 999, fontSize: 11, padding: "4px 10px", fontWeight: 600 }}>More details</span>
      </div>

      <div style={{ marginTop: 6 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#F4F5F8", color: "#555", display: "flex", alignItems: "center", justifyContent: "center" }}>
            <Wallet size={18} />
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>From</div>
            <div style={{ fontSize: 14, fontWeight: 600 }}>Sample Casino Wallet</div>
          </div>
          <div style={{ fontSize: 18, fontWeight: 700 }}>€50</div>
        </div>

        <div style={{ color: "#b8b8b8", margin: "4px 0 4px 18px" }}>↓</div>

        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#E8F4EE", color: "var(--sc-success)", display: "flex", alignItems: "center", justifyContent: "center" }}>
            <CheckCircle size={18} />
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: 700 }}>Withdrawal <span style={{ fontWeight: 500, color: "#8c8c8c" }}>(Swapin)</span></div>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>Today, 11:06</div>
          </div>
          <div style={{ fontSize: 11, color: "#8c8c8c", display: "inline-flex", alignItems: "center", gap: 4 }}>
            <span style={{ width: 4, height: 4, borderRadius: "50%", background: "var(--sc-success)" }} /> Confirmed
          </div>
        </div>

        <div style={{ color: "#b8b8b8", margin: "4px 0 4px 18px" }}>↓</div>

        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <div style={{ width: 36, height: 36, borderRadius: "50%", background: "#0a0a0a", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 12, fontWeight: 700, letterSpacing: "0.02em" }}>
            JD
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontSize: 11, color: "#8c8c8c" }}>To</div>
            <div style={{ fontSize: 14, fontWeight: 600 }}>JD</div>
          </div>
          <Copy size={14} style={{ color: "#b8b8b8" }} />
        </div>
      </div>

      <div style={{ height: 1, background: "#EEF0F4", margin: "4px 0" }}></div>
      <div className="sc-kv"><span className="k">Exchange rate</span><span className="v">1 EUR = 1.1627 USDT</span></div>

      <div style={{ marginTop: "auto" }}>
        <button className="sc-prim-btn tap-pulse" onClick={onNext}>Close</button>
      </div>
    </div>
  </div>
);

// ─────────────────────────────────────────────────────────
// Fake QR for deposit step 4
// ─────────────────────────────────────────────────────────
const QrSample = () => {
  const cells = [];
  const pattern = "10010110100110101010010110101001011001101010110100101100110110101010110010110100110100101101010";
  for (let y = 0; y < 25; y++) {
    for (let x = 0; x < 25; x++) {
      const idx = (y * 25 + x + y * 3) % pattern.length;
      const isCorner = (
        (x < 7 && y < 7) || (x > 17 && y < 7) || (x < 7 && y > 17)
      );
      let fill = pattern[idx] === "1";
      if (isCorner) {
        const sx = x > 17 ? x - 18 : x;
        const sy = y > 17 ? y - 18 : y;
        if (sx === 0 || sx === 6 || sy === 0 || sy === 6) fill = true;
        else if (sx >= 2 && sx <= 4 && sy >= 2 && sy <= 4) fill = true;
        else fill = false;
      }
      if (fill) cells.push(<rect key={`${x}-${y}`} x={x * 6} y={y * 6} width="6" height="6" fill="#000" />);
    }
  }
  return <svg viewBox="0 0 150 150" width="140" height="140">{cells}</svg>;
};

// ─────────────────────────────────────────────────────────
// Annotation panel content (one per step, per flow)
// ─────────────────────────────────────────────────────────
const ANNOTATIONS = {
  deposit: [
    {
      eyebrow: "Step 1 · Sample Casino dashboard",
      title: "Player chooses to deposit",
      desc: "This is the casino's own UI. Swapin is invisible to the player at this stage — they just see the existing deposit button.",
      bullets: [
        "Branded as Sample Casino (operator) — not Swapin",
        "Same UI surface as any other deposit method",
      ],
      tapHint: "Tap the highlighted Deposit button to continue",
    },
    {
      eyebrow: "Step 2 · Choose method",
      title: "Crypto is just another payment method",
      desc: "Cards, banking, crypto — the player picks whichever they prefer. No new flow, no surprises.",
      bullets: [
        "Crypto appears alongside existing methods",
        "Operator's existing payment treatment applies",
      ],
      tapHint: "Tap Crypto",
    },
    {
      eyebrow: "Step 3 · Choose crypto to deposit",
      title: "Picks their preferred coin",
      desc: "Supports all major stablecoins and cryptocurrencies. Min/max limits per coin are configurable by the operator.",
      bullets: [
        "USDT · USDC · BTC · ETH · TON · TRX · USDT.POL · EURC · and more",
        "Min 5 EUR · Max 1 000 000 EUR per transaction",
      ],
      tapHint: "Tap USDT",
    },
    {
      eyebrow: "Step 4 · Recurring deposit address",
      title: "Same address every time",
      desc: "Each player has a persistent address per coin. They send crypto from any wallet they own — exchange, hardware, app — and Swapin handles the rest.",
      bullets: [
        "Persistent address — no new wallet per transaction",
        "KYT screening runs on incoming funds",
        "Network shown so player doesn't miss-send",
      ],
      tapHint: "Tap Done to simulate the deposit arriving",
    },
    {
      eyebrow: "Step 5 · Deposit completed",
      title: "Balance credited in EUR",
      desc: "Swapin detected the deposit, ran KYT, converted to EUR at floating rate, called back the operator. The player's casino balance is credited — they never see a crypto amount.",
      bullets: [
        "0.86 EUR per USDT at moment of execution",
        "Operator receives EUR via SEPA or stablecoin",
        "Treasury, accounting, banking unchanged",
      ],
      tapHint: "Tap Close to wrap the flow",
    },
  ],
  withdraw: [
    {
      eyebrow: "Step 1 · Sample Casino dashboard",
      title: "Player initiates a withdrawal",
      desc: "Same casino UI, same withdraw button. The crypto handling is entirely behind the scenes.",
      bullets: [
        "Player balance reflects the previous deposit (€72.90)",
        "Branded as Sample Casino — not Swapin",
      ],
      tapHint: "Tap the highlighted Withdraw button",
    },
    {
      eyebrow: "Step 2 · Choose network",
      title: "Player chooses where to receive",
      desc: "Same crypto, multiple networks. The choice routes the payout through the right blockchain at the lowest fee for the player.",
      bullets: [
        "Ethereum · TRON · Polygon — operator-configurable",
        "Network shown alongside the asset",
      ],
      tapHint: "Tap TRON",
    },
    {
      eyebrow: "Step 3 · Wallet address",
      title: "Player provides their destination",
      desc: "Address is screened by KYT before Swapin sends anything. Sanctioned wallets are blocked before execution.",
      bullets: [
        "Address pre-filled for the demo",
        "Real product validates against the selected network",
      ],
      tapHint: "Tap Confirm",
    },
    {
      eyebrow: "Step 4 · Amount in EUR",
      title: "Player picks EUR — Swapin quotes crypto",
      desc: "Operator's balance is in EUR. The player chooses how much they want to cash out; Swapin handles the conversion at floating rate at execution.",
      bullets: [
        "Floating rate, locked at execution — no slippage windows",
        "Operator-set delays for large amounts (>50 000 EUR)",
      ],
      tapHint: "Tap Confirm",
    },
    {
      eyebrow: "Step 5 · Processing",
      title: "Three-phase authorization runs",
      desc: "Initiator → Authorizer → Executor. KYT screens the destination wallet. EUR is converted to crypto at the rate at execution.",
      bullets: [
        "Initiator → Authorizer → Executor chain",
        "KYT clears destination wallet",
        "EUR → crypto at floating rate",
      ],
      tapHint: "Auto-advances when the transfer completes",
    },
    {
      eyebrow: "Step 6 · Withdrawal completed",
      title: "Player receives crypto",
      desc: "Crypto arrives in the player's wallet. Operator's EUR balance was debited at execution. Callback confirms — operator can mark the cashier ticket as paid.",
      bullets: [
        "Player wallet credited with 58.14 USDT",
        "Casino EUR balance debited at 1.1627 USDT/EUR",
        "No locked quotes, no crypto custody by the operator",
      ],
      tapHint: "Tap Close to wrap the flow",
    },
  ],
};

// ─────────────────────────────────────────────────────────
// MockupOverlay shell
// ─────────────────────────────────────────────────────────
const FLOW_SCREENS = {
  deposit: [DepStep1, DepStep2, DepStep3, DepStep4, DepStep5],
  withdraw: [WdStep1, WdStep2, WdStep3, WdStep4, WdStep5, WdStep6],
};

const MockupOverlay = ({ flow, onClose, onSwitchFlow }) => {
  const [step, setStep] = React.useState(0);
  const open = flow !== null;

  // Reset step when flow changes
  React.useEffect(() => {
    setStep(0);
  }, [flow]);

  // Esc to close
  React.useEffect(() => {
    if (!open) return;
    const onKey = (e) => {
      if (e.key === "Escape") onClose();
      else if (e.key === "ArrowRight") setStep((s) => Math.min(s + 1, (FLOW_SCREENS[flow]?.length || 1) - 1));
      else if (e.key === "ArrowLeft")  setStep((s) => Math.max(s - 1, 0));
    };
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, [open, flow, onClose]);

  if (!flow) {
    return <div className="mockup-overlay" aria-hidden="true" />;
  }

  const screens = FLOW_SCREENS[flow];
  const ScreenComp = screens[step];
  const annot = ANNOTATIONS[flow][step];
  const total = screens.length;

  const next = () => {
    if (step < total - 1) setStep(step + 1);
    else setStep(0); // restart on final tap
  };
  const back = () => step > 0 && setStep(step - 1);

  return (
    <div className={`mockup-overlay ${open ? "open" : ""}`}>
      <div className="mockup-shell" data-screen-label={`Mockup · ${flow}`}>
        <div className="mockup-topbar">
          <div className="left">
            <button className="back-btn" onClick={onClose}>
              <ArrowLeft size={14} /> Back to demo
            </button>
            <div className="flow-title">
              <SampleCasinoMark size={14} subtle />
              <b>{flow === "deposit" ? "Deposit flow" : "Withdrawal flow"}</b>
            </div>
            {onSwitchFlow && (
              <button
                className="flow-switch-btn"
                onClick={() => onSwitchFlow(flow === "deposit" ? "withdraw" : "deposit")}
                title={`Switch to the ${flow === "deposit" ? "withdrawal" : "deposit"} flow`}
              >
                {flow === "deposit"
                  ? <><ArrowUp size={12} /> Switch to withdrawal</>
                  : <><ArrowDown size={12} /> Switch to deposit</>}
              </button>
            )}
          </div>
          <div className="center">
            <span className="step-counter">Step {step + 1} of {total}</span>
            <div className="step-dots">
              {screens.map((_, i) => (
                <div
                  key={i}
                  className={`d ${i === step ? "curr" : i < step ? "done" : ""}`}
                  onClick={() => setStep(i)}
                />
              ))}
            </div>
          </div>
          <div className="right">
            <span className="demo-tag">Sample integration · illustrative only</span>
          </div>
        </div>

        <div className="mockup-body">
          <div className="mockup-frame-wrap">
            <div className="mockup-frame" key={`${flow}-${step}`}>
              <ScreenComp onNext={next} onBack={back} onClose={onClose} />
            </div>
          </div>

          <div className="mockup-annot">
            <div className="eyebrow"><span className="dot"></span>{annot.eyebrow}</div>
            <h2>{annot.title}</h2>
            <p className="annot-desc">{annot.desc}</p>
            <div className="annot-bullets">
              {annot.bullets.map((b, i) => (
                <div className="annot-bullet" key={i}>
                  <span className="b-icon"><CheckCircle size={12} /></span>
                  <span>{b}</span>
                </div>
              ))}
            </div>
            <div className="annot-foot">
              <span className="annot-pill"><span style={{ width: 6, height: 6, borderRadius: "50%", background: "var(--swapin-cyan-400)", boxShadow: "0 0 6px var(--swapin-cyan-400)" }}></span>{annot.tapHint}</span>
            </div>
            <div className="nav-btns">
              <button className="nav-btn" onClick={back} disabled={step === 0}>
                <ChevronLeft size={14} /> Previous
              </button>
              <button className="nav-btn primary" onClick={next}>
                {step === total - 1 ? "Restart" : "Next"} <ChevronRight size={14} />
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

Object.assign(window, { MockupOverlay, SampleCasinoMark });
