// ChairShare — owner cluster (15-19)

const OwnerShell = ({ active, children, title, subtitle, action }) => {
  const items = [
    ["home", "Today", 15], ["pin", "Properties", 16], ["scissors", "Practitioners", 17],
    ["plus", "Onboard", 18], ["card", "Revenue", 19],
  ];
  return (
    <div className="cs" style={{ width: 1440, minHeight: 900, background: "var(--cs-cream)", display: "grid", gridTemplateColumns: "240px 1fr" }}>
      <aside style={{ borderRight: "1px solid var(--cs-line)", background: "var(--cs-ink)", color: "var(--cs-cream)", padding: "22px 16px", display: "flex", flexDirection: "column", gap: 4 }}>
        <div style={{ padding: "6px 10px 18px" }}><Wordmark size={16} color="var(--cs-cream)" /></div>
        <div className="eyebrow" style={{ padding: "4px 10px", marginBottom: 4, color: "var(--cs-gold-soft)" }}>Owner workspace</div>
        {items.map(([icon, label, n]) => {
          const a = active === n;
          return (
            <button key={n} style={{
              display: "flex", alignItems: "center", gap: 10, padding: "10px 12px", borderRadius: 12,
              border: "none", background: a ? "rgba(255,253,249,0.08)" : "transparent",
              color: a ? "var(--cs-cream)" : "rgba(244,237,224,0.65)", fontWeight: a ? 500 : 400,
              fontSize: 13, cursor: "pointer", textAlign: "left",
            }}>
              <Icon name={icon} size={15} /> {label}
            </button>
          );
        })}
        <div style={{ marginTop: "auto", padding: "16px 6px 4px", borderTop: "1px solid rgba(244,237,224,0.15)", display: "flex", alignItems: "center", gap: 10 }}>
          <Avatar name="Tom W" size={32} tone="gold" />
          <div style={{ fontSize: 12, fontWeight: 500 }}>Tom W. <span style={{ color: "var(--cs-gold-soft)", fontWeight: 400, display: "block", fontSize: 10 }}>owner</span></div>
        </div>
      </aside>
      <main>
        <header style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", padding: "26px 36px 18px", borderBottom: "1px solid var(--cs-line)" }}>
          <div>
            <div className="eyebrow" style={{ marginBottom: 6 }}>{subtitle}</div>
            <h1 className="serif" style={{ fontSize: 34, margin: 0, fontWeight: 400, lineHeight: 1 }}>{title}</h1>
          </div>
          <div style={{ display: "flex", gap: 10, alignItems: "center" }}>{action}</div>
        </header>
        {children}
      </main>
    </div>
  );
};

const OwnerHome = () => {
  const stats = [
    { l: "Active practitioners", v: "9", sub: "of 12 chairs" },
    { l: "GMV this month", v: "$48.2k", sub: "+18% vs Apr" },
    { l: "Chair rent collected", v: "$11,240", sub: "of $11,540 due" },
    { l: "Occupancy", v: "75%", sub: "9 of 12 chairs" },
  ];
  const alerts = [
    { dot: "warn", t: "KYC stuck for Lara K.", sub: "Stripe pending 4 days · nudge", action: "Nudge" },
    { dot: "err", t: "Rent overdue · Iris T.", sub: "$285 · 2 days late", action: "Send reminder" },
    { dot: "warn", t: "Chair 03 maintenance overdue", sub: "Yarraville · last serviced 3 mo", action: "Schedule" },
  ];
  return (
    <OwnerShell active={15} title="Tuesday May 5" subtitle="Owner · all properties"
      action={<button className="btn btn-primary btn-sm">+ Onboard practitioner</button>}>
      <div style={{ padding: "26px 36px" }}>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16, marginBottom: 24 }}>
          {stats.map(s => (
            <div key={s.l} className="card" style={{ padding: 20 }}>
              <div className="eyebrow" style={{ marginBottom: 10 }}>{s.l}</div>
              <div className="serif" style={{ fontSize: 36, lineHeight: 1, marginBottom: 4 }}>{s.v}</div>
              <div style={{ fontSize: 11, color: "var(--cs-ink-3)" }}>{s.sub}</div>
            </div>
          ))}
        </div>

        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
          <div className="card" style={{ padding: 0 }}>
            <div style={{ padding: "16px 22px", borderBottom: "1px solid var(--cs-line)", display: "flex", justifyContent: "space-between" }}>
              <h3 className="serif" style={{ fontSize: 20, margin: 0, fontWeight: 400 }}>Needs attention</h3>
              <span className="pill pill-rose">{alerts.length} alerts</span>
            </div>
            {alerts.map((a, i) => (
              <div key={i} style={{ display: "flex", gap: 14, alignItems: "center", padding: "16px 22px", borderBottom: i < alerts.length - 1 ? "1px solid var(--cs-line)" : "none" }}>
                <span className={"dot dot-" + a.dot} />
                <div style={{ flex: 1 }}>
                  <div style={{ fontSize: 13, fontWeight: 500 }}>{a.t}</div>
                  <div style={{ fontSize: 11, color: "var(--cs-ink-3)", marginTop: 2 }}>{a.sub}</div>
                </div>
                <button className="btn btn-ghost btn-sm">{a.action}</button>
              </div>
            ))}
          </div>

          <div className="card" style={{ padding: 0 }}>
            <div style={{ padding: "16px 22px", borderBottom: "1px solid var(--cs-line)" }}>
              <h3 className="serif" style={{ fontSize: 20, margin: 0, fontWeight: 400 }}>Properties</h3>
            </div>
            {[
              { name: "Atelier · Yarraville", chairs: "4 of 4 leased", gmv: "$22.1k", occ: 100 },
              { name: "House of Lune · Brunswick", chairs: "3 of 5 leased", gmv: "$18.4k", occ: 60 },
              { name: "Studio West · Footscray", chairs: "2 of 3 leased", gmv: "$7.6k", occ: 67 },
            ].map((p, i) => (
              <div key={p.name} style={{ padding: "16px 22px", borderBottom: i < 2 ? "1px solid var(--cs-line)" : "none" }}>
                <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
                  <span style={{ fontSize: 13, fontWeight: 500 }}>{p.name}</span>
                  <span className="serif" style={{ fontSize: 16 }}>{p.gmv}</span>
                </div>
                <div style={{ display: "flex", justifyContent: "space-between", fontSize: 11, color: "var(--cs-ink-3)", marginBottom: 6 }}>
                  <span>{p.chairs}</span><span>{p.occ}% occupied</span>
                </div>
                <div style={{ height: 4, background: "var(--cs-cream-2)", borderRadius: 999, overflow: "hidden" }}>
                  <div style={{ height: "100%", width: p.occ + "%", background: "var(--cs-gold)" }} />
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </OwnerShell>
  );
};

const OwnerProperties = () => {
  const props = [
    { name: "The Atelier · Yarraville", chairs: [
      { n: "Chair 01", status: "leased", who: "Amelia M.", rate: "$285", tone: "rose" },
      { n: "Chair 02", status: "leased", who: "Hannah G.", rate: "$285", tone: "gold" },
      { n: "Chair 03", status: "leased", who: "Marco T.", rate: "$320", tone: "default" },
      { n: "Chair 04", status: "maintenance", who: null, rate: "$285", tone: null },
    ]},
    { name: "House of Lune · Brunswick", chairs: [
      { n: "Chair 01", status: "leased", who: "Iris T.", rate: "$245", tone: "rose" },
      { n: "Chair 02", status: "available", who: null, rate: "$245", tone: null },
      { n: "Chair 03", status: "leased", who: "Lara K.", rate: "$245", tone: "gold" },
      { n: "Chair 04", status: "available", who: null, rate: "$245", tone: null },
      { n: "Chair 05", status: "leased", who: "Priya N.", rate: "$245", tone: "default" },
    ]},
  ];
  const statusPill = s => {
    if (s === "leased") return <span className="pill" style={{ background: "rgba(107,126,90,0.15)", color: "var(--cs-ok)" }}><span className="dot dot-ok" /> leased</span>;
    if (s === "available") return <span className="pill pill-gold">available</span>;
    return <span className="pill" style={{ background: "rgba(181,82,63,0.1)", color: "var(--cs-err)" }}>maintenance</span>;
  };
  return (
    <OwnerShell active={16} title="Properties & chairs" subtitle="3 properties · 12 chairs"
      action={<button className="btn btn-primary btn-sm">+ Add chair</button>}>
      <div style={{ padding: "26px 36px", display: "flex", flexDirection: "column", gap: 24 }}>
        {props.map(p => (
          <div key={p.name}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
              <h3 className="serif" style={{ fontSize: 22, margin: 0, fontWeight: 400 }}>{p.name}</h3>
              <span style={{ fontSize: 12, color: "var(--cs-ink-3)" }}>{p.chairs.filter(c => c.status === "leased").length} of {p.chairs.length} leased</span>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14 }}>
              {p.chairs.map(c => (
                <div key={c.n} className="card" style={{ padding: 0, overflow: "hidden" }}>
                  <Placeholder label={c.n + " · photo"} tone={c.status === "available" ? "gold" : c.status === "maintenance" ? "default" : "rose"} style={{ height: 120, borderRadius: 0, border: "none" }} />
                  <div style={{ padding: 14 }}>
                    <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }}>
                      <span className="serif" style={{ fontSize: 16 }}>{c.n}</span>
                      {statusPill(c.status)}
                    </div>
                    {c.who ? (
                      <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 12, color: "var(--cs-ink-2)" }}>
                        <Avatar name={c.who} size={20} tone={c.tone} />
                        {c.who}
                      </div>
                    ) : (
                      <div style={{ fontSize: 12, color: "var(--cs-ink-3)" }}>{c.status === "maintenance" ? "Backwash repair · 2 days" : "Open for lease"}</div>
                    )}
                    <div style={{ fontSize: 11, color: "var(--cs-ink-3)", marginTop: 8 }}>{c.rate} / week</div>
                  </div>
                </div>
              ))}
            </div>
          </div>
        ))}
      </div>
    </OwnerShell>
  );
};

const OwnerPractitioners = () => {
  const rows = [
    { name: "Amelia Marcheva", slug: "amelia.cuts", chair: "Atelier 01", rent: "ok", kyc: "ok", gmv: "$8.4k", tone: "rose" },
    { name: "Hannah Geist", slug: "hannah.hair", chair: "Atelier 02", rent: "ok", kyc: "ok", gmv: "$6.1k", tone: "gold" },
    { name: "Marco Trevi", slug: "marco.cuts", chair: "Atelier 03", rent: "ok", kyc: "ok", gmv: "$7.6k", tone: "default" },
    { name: "Iris Tan", slug: "iris.studio", chair: "Lune 01", rent: "late", kyc: "ok", gmv: "$3.2k", tone: "rose" },
    { name: "Lara Khoury", slug: "lara.k", chair: "Lune 03", rent: "ok", kyc: "pending", gmv: "$0.9k", tone: "gold" },
    { name: "Priya Nair", slug: "priya.colour", chair: "Lune 05", rent: "ok", kyc: "ok", gmv: "$5.8k", tone: "default" },
  ];
  const pill = (kind, val) => {
    if (kind === "rent" && val === "ok") return <span className="pill" style={{ background: "rgba(107,126,90,0.15)", color: "var(--cs-ok)" }}>paid</span>;
    if (kind === "rent" && val === "late") return <span className="pill" style={{ background: "rgba(181,82,63,0.1)", color: "var(--cs-err)" }}>late</span>;
    if (val === "ok") return <span className="pill" style={{ background: "rgba(107,126,90,0.15)", color: "var(--cs-ok)" }}>verified</span>;
    if (val === "pending") return <span className="pill" style={{ background: "rgba(182,134,66,0.15)", color: "var(--cs-warn)" }}>pending</span>;
  };
  return (
    <OwnerShell active={17} title="Practitioners" subtitle="9 active · 1 KYC pending"
      action={<>
        <button className="btn btn-ghost btn-sm">Export</button>
        <button className="btn btn-primary btn-sm">+ Onboard</button>
      </>}>
      <div style={{ padding: "26px 36px" }}>
        <div style={{ display: "flex", gap: 8, marginBottom: 18 }}>
          {["All", "Active", "KYC pending", "Ended"].map((c, i) => (
            <span key={c} className={"chip " + (i === 0 ? "chip-active" : "")}>{c}</span>
          ))}
        </div>

        <div className="card" style={{ padding: 0, overflow: "hidden" }}>
          <div style={{ display: "grid", gridTemplateColumns: "1.6fr 1.2fr 1fr 100px 100px 100px 30px", padding: "12px 22px", background: "var(--cs-bone)", borderBottom: "1px solid var(--cs-line)", fontSize: 11, color: "var(--cs-ink-3)", textTransform: "uppercase", letterSpacing: "0.06em" }}>
            <span>Practitioner</span><span>Subdomain</span><span>Chair</span><span>Rent</span><span>KYC</span><span style={{ textAlign: "right" }}>GMV (mo)</span><span></span>
          </div>
          {rows.map((r, i) => (
            <div key={r.name} style={{ display: "grid", gridTemplateColumns: "1.6fr 1.2fr 1fr 100px 100px 100px 30px", padding: "14px 22px", alignItems: "center", borderBottom: i < rows.length - 1 ? "1px solid var(--cs-line)" : "none", fontSize: 13 }}>
              <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
                <Avatar name={r.name} size={32} tone={r.tone} />
                <span style={{ fontWeight: 500 }}>{r.name}</span>
              </div>
              <span className="mono" style={{ fontSize: 12, color: "var(--cs-ink-2)" }}>{r.slug}.voxink</span>
              <span style={{ color: "var(--cs-ink-2)" }}>{r.chair}</span>
              {pill("rent", r.rent)}
              {pill("kyc", r.kyc)}
              <span className="serif" style={{ fontSize: 16, textAlign: "right" }}>{r.gmv}</span>
              <Icon name="chevron_right" size={14} color="var(--cs-ink-3)" />
            </div>
          ))}
        </div>
      </div>
    </OwnerShell>
  );
};

const OwnerOnboard = () => {
  return (
    <OwnerShell active={18} title="Onboard a practitioner" subtitle="Manual onboard · sends magic link + lease"
      action={<button className="btn btn-ghost btn-sm">Save draft</button>}>
      <div style={{ padding: "26px 36px", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 32 }}>
        <div>
          <div className="eyebrow" style={{ marginBottom: 14 }}>Practitioner details</div>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginBottom: 12 }}>
            <div className="field"><label>First name</label><input defaultValue="Cleo" /></div>
            <div className="field"><label>Last name</label><input defaultValue="Vance" /></div>
          </div>
          <div className="field" style={{ marginBottom: 12 }}><label>Email</label><input defaultValue="cleo@vancehair.co" /></div>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginBottom: 22 }}>
            <div className="field"><label>Phone</label><input defaultValue="0411 222 333" /></div>
            <div className="field"><label>ABN</label><input defaultValue="44 555 666 777" /></div>
          </div>
          <div className="field" style={{ marginBottom: 22 }}><label>Instagram</label><input defaultValue="@cleo.vance" /></div>

          <div className="eyebrow" style={{ marginBottom: 14 }}>Chair assignment</div>
          <div className="field" style={{ marginBottom: 12 }}>
            <label>Chair</label>
            <select defaultValue="Lune 02"><option>Atelier 04 · $285/wk</option><option>Lune 02 · $245/wk</option><option>Studio West 02 · $210/wk</option></select>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginBottom: 22 }}>
            <div className="field"><label>Days</label><select><option>Mon · Tue · Wed</option><option>Thu · Fri · Sat</option></select></div>
            <div className="field"><label>Weekly rent</label><input defaultValue="$245" /></div>
          </div>

          <div style={{ display: "flex", gap: 10, justifyContent: "flex-end", paddingTop: 18, borderTop: "1px solid var(--cs-line)" }}>
            <button className="btn btn-ghost">Save & invite later</button>
            <button className="btn btn-primary">Send magic link & lease <Icon name="arrow_right" size={14} /></button>
          </div>
        </div>

        <div>
          <div className="eyebrow" style={{ marginBottom: 14 }}>Lease preview · auto-generated</div>
          <div className="card" style={{ padding: 0, overflow: "hidden", height: 600 }}>
            <div style={{ padding: "12px 22px", background: "var(--cs-bone)", borderBottom: "1px solid var(--cs-line)", fontSize: 12, color: "var(--cs-ink-3)" }} className="mono">
              CLEO_VANCE_LEASE_DRAFT.pdf
            </div>
            <div style={{ padding: 28, fontFamily: "var(--cs-serif)", fontSize: 13, lineHeight: 1.7, color: "var(--cs-ink-2)", height: "calc(100% - 41px)", overflow: "auto" }}>
              <div style={{ textAlign: "center", marginBottom: 22 }}>
                <div className="eyebrow" style={{ marginBottom: 8 }}>Chair Rental Agreement</div>
                <div className="serif" style={{ fontSize: 22, color: "var(--cs-ink)" }}>House of Lune · Chair 02</div>
              </div>
              <p><strong>Between:</strong> ChairShare Pty Ltd and <em>Cleo Vance</em> (ABN 44 555 666 777).</p>
              <p><strong>1. Chair.</strong> Chair 02 at 14 Sydney Rd, Brunswick — Thursdays, Fridays, Saturdays.</p>
              <p><strong>2. Rent.</strong> $245 per week, direct debit weekly in advance.</p>
              <p><strong>3. Term.</strong> Three months minimum, rolling. 30 days notice after.</p>
              <p><strong>4. Included.</strong> Chair, station, mirror, backwash, towels, utilities, wifi, cleaning, booking platform.</p>
              <p style={{ marginTop: 28, padding: 14, background: "var(--cs-cream-2)", borderRadius: 8, fontSize: 11, color: "var(--cs-ink-3)" }}>This document will be emailed to cleo@vancehair.co alongside a magic-link signup. She types her name to sign.</p>
            </div>
          </div>
        </div>
      </div>
    </OwnerShell>
  );
};

const OwnerRevenue = () => {
  const props = [
    { p: "Atelier · Yarraville", gmv: 22100, rent: 4280, mkt: 410 },
    { p: "House of Lune · Brunswick", gmv: 18400, rent: 3860, mkt: 280 },
    { p: "Studio West · Footscray", gmv: 7600, rent: 2520, mkt: 0 },
  ];
  const max = 22100;
  return (
    <OwnerShell active={19} title="Revenue · May 2026" subtitle="Consolidated · all properties"
      action={<>
        <div className="card" style={{ padding: 3, display: "inline-flex", borderRadius: 999 }}>
          {["Month", "Quarter", "Year", "Custom"].map((v, i) => (
            <button key={v} className="btn btn-sm" style={{ padding: "6px 14px", background: i === 0 ? "var(--cs-ink)" : "transparent", color: i === 0 ? "var(--cs-cream)" : "var(--cs-ink-2)" }}>{v}</button>
          ))}
        </div>
        <button className="btn btn-ghost btn-sm">Export PDF</button>
      </>}>
      <div style={{ padding: "26px 36px" }}>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 0, marginBottom: 28, padding: "26px 0", borderTop: "1px solid var(--cs-line)", borderBottom: "1px solid var(--cs-line)" }}>
          {[
            { l: "Customer GMV", v: "$48,200", sub: "127 bookings", main: false },
            { l: "Marketing fees", v: "$690", sub: "1.4% of GMV" },
            { l: "Chair rent", v: "$10,660", sub: "9 of 12 chairs" },
            { l: "To ChairShare", v: "$11,350", sub: "+18% vs Apr", main: true },
          ].map((s, i) => (
            <div key={s.l} style={{ padding: "0 24px", borderRight: i < 3 ? "1px solid var(--cs-line)" : "none" }}>
              <div className="eyebrow" style={{ marginBottom: 10, color: s.main ? "var(--cs-gold-deep)" : undefined }}>{s.l}</div>
              <div className="serif" style={{ fontSize: s.main ? 44 : 32, lineHeight: 1, marginBottom: 6, fontWeight: 400 }}>{s.v}</div>
              <div style={{ fontSize: 11, color: "var(--cs-ink-3)" }}>{s.sub}</div>
            </div>
          ))}
        </div>

        <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 24 }}>
          <div className="card" style={{ padding: 28 }}>
            <div className="eyebrow" style={{ marginBottom: 14 }}>By property · GMV</div>
            <div style={{ display: "flex", flexDirection: "column", gap: 22, marginTop: 22 }}>
              {props.map(r => (
                <div key={r.p}>
                  <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
                    <span style={{ fontSize: 13, fontWeight: 500 }}>{r.p}</span>
                    <span className="serif" style={{ fontSize: 18 }}>${(r.gmv/1000).toFixed(1)}k</span>
                  </div>
                  <div style={{ height: 8, background: "var(--cs-cream-2)", borderRadius: 999, overflow: "hidden", display: "flex" }}>
                    <div style={{ width: (r.gmv / max) * 100 + "%", background: "var(--cs-gold)" }} />
                  </div>
                </div>
              ))}
            </div>
          </div>

          <div className="card" style={{ padding: 0 }}>
            <div style={{ padding: "16px 22px", borderBottom: "1px solid var(--cs-line)" }}>
              <h3 className="serif" style={{ fontSize: 18, margin: 0, fontWeight: 400 }}>Stripe payouts log</h3>
            </div>
            {[
              { d: "Mon May 4", a: "$3,820.40", to: "ChairShare ANZ ····7702" },
              { d: "Mon Apr 27", a: "$2,940.80", to: "ChairShare ANZ ····7702" },
              { d: "Mon Apr 20", a: "$3,108.20", to: "ChairShare ANZ ····7702" },
            ].map((p, i) => (
              <div key={i} style={{ padding: "14px 22px", borderBottom: i < 2 ? "1px solid var(--cs-line)" : "none", display: "flex", justifyContent: "space-between" }}>
                <div>
                  <div style={{ fontSize: 13, fontWeight: 500 }}>{p.a}</div>
                  <div style={{ fontSize: 11, color: "var(--cs-ink-3)" }}>{p.d} · {p.to}</div>
                </div>
                <span className="pill" style={{ background: "rgba(107,126,90,0.15)", color: "var(--cs-ok)" }}><span className="dot dot-ok" /> arrived</span>
              </div>
            ))}
          </div>
        </div>
      </div>
    </OwnerShell>
  );
};

window.OwnerHome = OwnerHome;
window.OwnerProperties = OwnerProperties;
window.OwnerPractitioners = OwnerPractitioners;
window.OwnerOnboard = OwnerOnboard;
window.OwnerRevenue = OwnerRevenue;
