// ==========================================================================
// Components / Navigation 家族 — thumbnails + detail pages
// ==========================================================================
const { Demo: __Demo_nv, DocCard: __DocCard_nv, Bar: __Bar_nv, Spinner: __Spinner_nv } = window;
const Demo = __Demo_nv, DocCard = __DocCard_nv, Bar = __Bar_nv, Spinner = __Spinner_nv;

const T_MenuBar = () => (
  <div style={{ width: 170 }}>
    <div style={{ display: "flex", gap: 8, padding: 6, background: "var(--n-50)", borderRadius: 3 }}>
      {[1, 1, 1].map((_, i) => <Bar key={i} w={30} h={4} c={i === 0 ? "var(--blue-500)" : "var(--n-400)"} />)}
    </div>
    <div style={{ marginTop: 4, padding: 6, background: "#fff", border: "1px solid var(--blue-500)", borderRadius: 3 }}>
      <Bar w="80%" h={3} c="var(--blue-500)" />
    </div>
  </div>
);
const T_AppBar = () => (
  <div style={{ width: 170, padding: 8, background: "var(--blue-500)", borderRadius: 3, display: "flex", alignItems: "center", gap: 6 }}>
    <Icon name="menu" size={14} color="#fff" />
    <Bar w={70} h={5} c="rgba(255,255,255,.9)" />
    <div style={{ marginLeft: "auto" }}><Icon name="search" size={14} color="#fff" /></div>
  </div>
);
const T_BottomNav = () => (
  <div style={{ width: 170, padding: "8px 12px", background: "var(--blue-500)", borderRadius: 4, display: "flex", justifyContent: "space-around" }}>
    {["home", "search", "bell", "user"].map((n, i) => <Icon key={n} name={n} size={16} color={i === 0 ? "#fff" : "rgba(255,255,255,.6)"} />)}
  </div>
);
const T_Breadcrumb = () => (
  <div style={{ display: "flex", alignItems: "center", gap: 4 }}>
    <Bar w={20} h={3} c="var(--n-400)" /><span style={{ color: "var(--n-400)", fontSize: 10 }}>/</span>
    <Bar w={30} h={4} c="var(--blue-500)" /><span style={{ color: "var(--n-400)", fontSize: 10 }}>/</span>
    <Bar w={20} h={3} c="var(--n-400)" />
  </div>
);
const T_Drawer = () => (
  <div style={{ width: 160, height: 80, background: "var(--n-100)", borderRadius: 4, position: "relative", overflow: "hidden", border: "1px solid var(--n-300)" }}>
    <div style={{ position: "absolute", top: 0, right: 0, bottom: 0, width: 70, background: "#fff", borderLeft: "1px solid var(--blue-500)", padding: 6 }}>
      <Bar w="80%" h={4} c="var(--blue-500)" />
      <div style={{ marginTop: 4, display: "flex", flexDirection: "column", gap: 3 }}>
        <Bar w="60%" h={3} c="var(--n-300)" /><Bar w="80%" h={3} c="var(--n-300)" />
      </div>
    </div>
  </div>
);
const T_Links = () => (
  <span style={{ color: "var(--blue-500)", fontSize: 14, fontWeight: 500, textDecoration: "underline", textUnderlineOffset: 3 }}>Link to install</span>
);
const T_Pagination = () => (
  <div style={{ display: "flex", gap: 4 }}>
    {[1, 2, 3, "…", 10].map((n, i) =>
      <span key={i} style={{ width: 22, height: 22, borderRadius: "50%", background: i === 0 ? "var(--blue-500)" : "#fff", border: i === 0 ? "none" : "1px solid var(--n-300)", color: i === 0 ? "#fff" : "var(--n-700)", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 10, fontFamily: "var(--ff-en)", fontWeight: 600 }}>{n}</span>
    )}
  </div>
);
const T_SpeedDial = () => (
  <div style={{ display: "flex", alignItems: "center", gap: 6 }}>
    {[0, 1, 2].map(i => <div key={i} style={{ width: 20, height: 20, borderRadius: "50%", background: "var(--blue-500)", opacity: 0.4 + i * 0.2 }} />)}
    <div style={{ width: 36, height: 36, borderRadius: "50%", background: "var(--blue-500)", display: "flex", alignItems: "center", justifyContent: "center" }}>
      <Icon name="x" size={16} color="#fff" />
    </div>
  </div>
);
const T_Stepper = () => (
  <div style={{ display: "flex", alignItems: "center", gap: 6, width: 170 }}>
    {[1, 2, 3].map((n, i) =>
      <React.Fragment key={n}>
        <div style={{ width: 20, height: 20, borderRadius: "50%", background: i <= 1 ? "var(--blue-500)" : "var(--n-300)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", fontSize: 10, fontWeight: 700 }}>{n}</div>
        {i < 2 && <div style={{ flex: 1, height: 2, background: i < 1 ? "var(--blue-500)" : "var(--n-300)" }} />}
      </React.Fragment>
    )}
  </div>
);
const T_Tabs = () => (
  <div style={{ width: 170 }}>
    <div style={{ display: "flex", gap: 16, borderBottom: "1px solid var(--n-200)", paddingBottom: 4 }}>
      <Bar w={30} h={4} c="var(--blue-500)" /><Bar w={28} h={4} c="var(--n-400)" /><Bar w={32} h={4} c="var(--n-400)" />
    </div>
    <div style={{ marginTop: -1, width: 30, height: 2, background: "var(--blue-500)" }} />
    <div style={{ marginTop: 8, padding: 6, background: "var(--blue-50)", borderRadius: 3 }}>
      <Bar w="80%" h={3} c="var(--blue-400)" />
    </div>
  </div>
);
const T_Dropdown = () => (
  <div style={{ width: 130 }}>
    <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "5px 10px", background: "var(--blue-500)", borderRadius: 3, color: "#fff" }}>
      <Bar w={40} h={4} c="rgba(255,255,255,.9)" /><Icon name="chev" size={10} color="#fff" />
    </div>
    <div style={{ marginTop: 4, padding: 6, background: "#fff", border: "1px solid var(--blue-500)", borderRadius: 3, display: "flex", flexDirection: "column", gap: 3 }}>
      <Bar w="80%" h={3} c="var(--blue-400)" /><Bar w="60%" h={3} c="var(--n-400)" />
    </div>
  </div>
);
const T_Anchor = () => (
  <div style={{ display: "flex", flexDirection: "column", gap: 4, borderLeft: "2px solid var(--n-200)", paddingLeft: 10 }}>
    {[0, 1, 2, 3].map(i =>
      <div key={i} style={{ position: "relative" }}>
        {i === 1 && <div style={{ position: "absolute", left: -12, top: "50%", transform: "translateY(-50%)", width: 4, height: 12, background: "var(--blue-500)", borderRadius: 2 }} />}
        <Bar w={i === 1 ? 70 : 50 + i * 6} h={3} c={i === 1 ? "var(--blue-500)" : "var(--n-400)"} />
      </div>
    )}
  </div>
);

// ---------- Detail Cards ----------
const DocNav = () => (
  <>
    <DocCard id="c-nav-menubar" en="Menu Bar & Menu" intro="桌面端常見的多層選單列，hover 或點擊主項目展開子選單。常用於工具列、複雜應用。">
      <Demo title="基本用法"><MenuBarDemo /></Demo>
    </DocCard>

    <DocCard id="c-nav-appbar" en="App Bar" intro="應用程式列，固定在畫面頂部，放置 Logo、導航、搜尋、使用者頭像等。">
      <Demo title="基本用法">
        <div style={{ width: "100%", padding: "12px 20px", background: "#fff", border: "1px solid var(--n-200)", borderRadius: 8, display: "flex", alignItems: "center", gap: 16, boxShadow: "var(--shadow-1)" }}>
          <Icon name="menu" size={20} color="var(--n-700)" />
          <div style={{ fontFamily: "var(--ff-en)", fontSize: 16, fontWeight: 700, color: "var(--blue-500)" }}>DesignSys</div>
          <div style={{ display: "flex", gap: 18, marginLeft: 24, fontSize: 14, color: "var(--n-700)" }}>
            <span style={{ color: "var(--blue-500)", fontWeight: 500 }}>儀表板</span>
            <span>專案</span><span>成員</span><span>設定</span>
          </div>
          <div style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 14 }}>
            <Icon name="search" size={18} color="var(--n-700)" />
            <Icon name="bell" size={18} color="var(--n-700)" />
            <div style={{ width: 32, height: 32, borderRadius: "50%", background: "var(--blue-500)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 600, fontSize: 13 }}>L</div>
          </div>
        </div>
      </Demo>
      <Demo title="深色變體">
        <div style={{ width: "100%", padding: "12px 20px", background: "var(--n-900)", borderRadius: 8, display: "flex", alignItems: "center", gap: 16 }}>
          <div style={{ fontFamily: "var(--ff-en)", fontSize: 16, fontWeight: 700, color: "#fff" }}>DesignSys</div>
          <div style={{ display: "flex", gap: 18, marginLeft: 24, fontSize: 14, color: "rgba(255,255,255,.7)" }}>
            <span style={{ color: "#fff", fontWeight: 500 }}>儀表板</span><span>專案</span><span>成員</span>
          </div>
          <div style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 14, color: "#fff" }}>
            <Icon name="search" size={18} color="rgba(255,255,255,.85)" />
            <Icon name="bell" size={18} color="rgba(255,255,255,.85)" />
          </div>
        </div>
      </Demo>
    </DocCard>

    <DocCard id="c-nav-bottom" en="Bottom Navigation" intro="行動裝置常見的底部導航，建議 3-5 個項目，每個必須是 APP 最頂層的入口。">
      <Demo title="基本用法">
        <div style={{ width: 320, background: "#fff", border: "1px solid var(--n-200)", borderRadius: 8, padding: "10px 0", display: "flex", justifyContent: "space-around", boxShadow: "var(--shadow-2)" }}>
          {[{ n: "home", l: "首頁" }, { n: "search", l: "搜尋" }, { n: "heart", l: "收藏" }, { n: "user", l: "我的" }].map((t, i) => (
            <div key={t.n} style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 4, color: i === 0 ? "var(--blue-500)" : "var(--n-500)", cursor: "pointer" }}>
              <Icon name={t.n} size={20} />
              <span style={{ fontSize: 11, fontWeight: i === 0 ? 600 : 400 }}>{t.l}</span>
            </div>
          ))}
        </div>
      </Demo>
    </DocCard>

    <DocCard id="c-nav-breadcrumb" en="Breadcrumbs" intro="麵包屑顯示目前頁面在資訊架構中的位置。每一階都應可點擊回上層。">
      <Demo title="基本用法">
        <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 14, color: "var(--n-700)" }}>
          <a href="#" style={{ color: "var(--blue-500)" }}>首頁</a>
          <Icon name="chevR" size={12} color="var(--n-400)" />
          <a href="#" style={{ color: "var(--blue-500)" }}>專案管理</a>
          <Icon name="chevR" size={12} color="var(--n-400)" />
          <a href="#" style={{ color: "var(--blue-500)" }}>2026 春季活動</a>
          <Icon name="chevR" size={12} color="var(--n-400)" />
          <span style={{ color: "var(--n-900)", fontWeight: 500 }}>編輯資產</span>
        </div>
      </Demo>
      <Demo title="含 icon">
        <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 14, color: "var(--n-700)" }}>
          <a href="#" style={{ color: "var(--blue-500)", display: "inline-flex", alignItems: "center", gap: 4 }}><Icon name="home" size={14} />首頁</a>
          <Icon name="chevR" size={12} color="var(--n-400)" />
          <a href="#" style={{ color: "var(--blue-500)" }}>專案</a>
          <Icon name="chevR" size={12} color="var(--n-400)" />
          <span style={{ color: "var(--n-900)", fontWeight: 500 }}>編輯</span>
        </div>
      </Demo>
    </DocCard>

    <DocCard id="c-nav-drawer" en="Drawer" intro="從畫面邊緣滑入的抽屜，用於檢視 / 編輯細節，不離開當前頁面。">
      <Demo title="右側抽屜"><DrawerDemo side="right" /></Demo>
      <Demo title="左側抽屜（選單型）"><DrawerDemo side="left" /></Demo>
    </DocCard>

    <DocCard id="c-nav-links" en="Links" intro="連結用於頁內 / 跨頁跳轉。建議使用主色藍 + hover 底線；不可用顏色單獨承載語意。">
      <Demo title="變體">
        <a href="#" style={{ color: "var(--blue-500)" }}>預設連結</a>
        <a href="#" style={{ color: "var(--blue-500)", textDecoration: "underline", textUnderlineOffset: 3 }}>已加底線</a>
        <a href="#" style={{ color: "var(--error)" }}>危險連結</a>
        <a href="#" style={{ color: "var(--n-400)", pointerEvents: "none" }}>禁用連結</a>
      </Demo>
      <Demo title="含圖示">
        <a href="#" style={{ display: "inline-flex", alignItems: "center", gap: 4, color: "var(--blue-500)" }}>
          下載文件<Icon name="download" size={14} />
        </a>
        <a href="#" style={{ display: "inline-flex", alignItems: "center", gap: 4, color: "var(--blue-500)" }}>
          外部連結<Icon name="link" size={14} />
        </a>
      </Demo>
    </DocCard>

    <DocCard id="c-nav-pagination" en="Pagination" intro="頁碼導航，搭配長列表使用。建議顯示「總頁數 / 跳轉欄位」當資料量大時。">
      <Demo title="基本用法"><Pagination total={12} defaultPage={2} /></Demo>
      <Demo title="少量頁數"><Pagination total={5} defaultPage={1} /></Demo>
      <Demo title="大量頁數"><Pagination total={42} defaultPage={15} /></Demo>
    </DocCard>

    <DocCard id="c-nav-speeddial" en="Speed Dial" intro="點擊 FAB 後展開的快速操作選單，常用於拍照、編輯、分享等附屬動作。">
      <Demo title="基本用法"><SpeedDialDemo /></Demo>
    </DocCard>

    <DocCard id="c-nav-stepper" en="Stepper" intro="步驟進度條，引導使用者完成多步驟流程（如註冊、結帳、設定精靈）。">
      <Demo title="水平 (Horizontal)"><StepperHorizontal /></Demo>
      <Demo title="垂直 (Vertical)"><StepperVertical /></Demo>
    </DocCard>

    <DocCard id="c-nav-tabs" en="Tabs" intro="分頁用於在同層級切換不同視圖。一個畫面建議只有一組主 Tabs。">
      <Demo title="基本用法"><Tabs items={["總覽", "成員", "權限", "計費"]} defaultIndex={0} /></Demo>
      <Demo title="含圖示"><TabsIconDemo /></Demo>
    </DocCard>

    <DocCard id="c-nav-dropdown" en="Dropdown" intro="動作選單，點擊按鈕後彈出選項列表。可放普通操作或危險操作。">
      <Demo title="基本用法"><DropdownDemo /></Demo>
    </DocCard>

    <DocCard id="c-nav-anchor" en="Anchor" intro="錨點導航，跳轉到頁面內的特定區塊。常用於長文件、設定頁、API 文件。">
      <Demo title="基本用法">
        <div style={{ display: "flex", flexDirection: "column", gap: 4, borderLeft: "2px solid var(--n-200)", paddingLeft: 16, position: "relative", minWidth: 220 }}>
          {["基本資料", "通知設定", "安全性", "計費資訊", "API Token"].map((t, i) => (
            <div key={t} style={{ position: "relative" }}>
              {i === 1 && <div style={{ position: "absolute", left: -18, top: 0, bottom: 0, width: 2, background: "var(--blue-500)" }} />}
              <div style={{ padding: "6px 0", fontSize: 13, color: i === 1 ? "var(--blue-600)" : "var(--n-700)", fontWeight: i === 1 ? 600 : 400, cursor: "pointer" }}>{t}</div>
            </div>
          ))}
        </div>
      </Demo>
    </DocCard>
  </>
);

// ---------- demo helpers ----------
const MenuBarDemo = () => {
  const [open, setOpen] = React.useState(null);
  const items = [
    { l: "檔案", sub: ["新增", "開啟", "儲存", "匯出"] },
    { l: "編輯", sub: ["復原", "重做", "剪下", "貼上"] },
    { l: "檢視", sub: ["放大", "縮小", "全螢幕"] },
    { l: "說明", sub: ["關於", "使用指南"] },
  ];
  return (
    <div style={{ width: "100%", background: "#fff", border: "1px solid var(--n-200)", borderRadius: 6, padding: 4, display: "flex", gap: 2, position: "relative" }}
      onMouseLeave={() => setOpen(null)}>
      {items.map((it, i) => (
        <div key={it.l} style={{ position: "relative" }}>
          <div onMouseEnter={() => setOpen(i)} style={{ padding: "6px 14px", fontSize: 13, color: open === i ? "var(--blue-600)" : "var(--n-800)", background: open === i ? "var(--blue-50)" : "transparent", borderRadius: 4, cursor: "pointer" }}>{it.l}</div>
          {open === i && (
            <div className="ds-menu" style={{ position: "absolute", top: "calc(100% + 2px)", left: 0, zIndex: 5 }}>
              {it.sub.map(s => <div key={s} className="ds-menu__item">{s}</div>)}
            </div>
          )}
        </div>
      ))}
    </div>
  );
};

const DrawerDemo = ({ side }) => {
  const [open, setOpen] = React.useState(true);
  const w = 240;
  return (
    <div style={{ position: "relative", width: "100%", maxWidth: 480, height: 240, background: "var(--n-100)", borderRadius: 8, overflow: "hidden", border: "1px solid var(--n-200)" }}>
      <div onClick={() => setOpen(false)} style={{ position: "absolute", inset: 0, background: open ? "rgba(7,12,18,.4)" : "transparent", transition: "background var(--dur-base) var(--ease)" }} />
      <div style={{
        position: "absolute", top: 0, bottom: 0,
        [side]: 0, width: w, background: "#fff",
        boxShadow: side === "right" ? "-4px 0 16px rgba(0,0,0,.1)" : "4px 0 16px rgba(0,0,0,.1)",
        transform: open ? "translateX(0)" : `translateX(${side === "right" ? "100%" : "-100%"})`,
        transition: "transform var(--dur-base) var(--ease)",
        padding: 16,
      }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
          <div style={{ fontSize: 15, fontWeight: 600 }}>{side === "right" ? "細節" : "選單"}</div>
          <Icon name="x" size={16} color="var(--n-500)" style={{ cursor: "pointer" }} onClick={() => setOpen(false)} />
        </div>
        {side === "right"
          ? <p style={{ fontSize: 13, color: "var(--n-600)", lineHeight: 1.7, margin: 0 }}>顯示項目的詳細資訊與編輯選項。</p>
          : ["儀表板", "專案", "成員", "設定"].map((t, i) => (
            <div key={t} style={{ padding: "8px 10px", fontSize: 13, color: i === 0 ? "var(--blue-600)" : "var(--n-800)", background: i === 0 ? "var(--blue-50)" : "transparent", borderRadius: 4, marginBottom: 2 }}>{t}</div>
          ))}
      </div>
      <div style={{ position: "absolute", top: 12, [side === "right" ? "left" : "right"]: 12 }}>
        <B kind="outline" size="sm" onClick={() => setOpen(!open)}>{open ? "關閉" : "開啟"}抽屜</B>
      </div>
    </div>
  );
};

const SpeedDialDemo = () => {
  const [open, setOpen] = React.useState(false);
  const actions = [{ n: "mail", l: "寄信" }, { n: "edit", l: "編輯" }, { n: "user", l: "新增成員" }];
  return (
    <div style={{ position: "relative", height: 200, width: 200 }}>
      <div style={{ position: "absolute", bottom: 0, right: 0, display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 12 }}>
        {open && actions.map(a => (
          <div key={a.n} style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ fontSize: 12, padding: "4px 10px", background: "var(--n-900)", color: "#fff", borderRadius: 4 }}>{a.l}</span>
            <div style={{ width: 40, height: 40, borderRadius: "50%", background: "#fff", color: "var(--blue-500)", border: "1px solid var(--blue-500)", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", boxShadow: "var(--shadow-2)" }}>
              <Icon name={a.n} size={18} />
            </div>
          </div>
        ))}
        <div onClick={() => setOpen(!open)} style={{ width: 56, height: 56, borderRadius: "50%", background: "var(--blue-500)", color: "#fff", display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", boxShadow: "0 6px 16px rgba(36,146,255,.4)", transition: "transform var(--dur-base) var(--ease)", transform: open ? "rotate(45deg)" : "rotate(0)" }}>
          <Icon name="plus" size={22} />
        </div>
      </div>
    </div>
  );
};

const StepperHorizontal = () => {
  const [step, setStep] = React.useState(1);
  const labels = ["填寫資料", "驗證身分", "確認資料", "完成"];
  return (
    <div style={{ width: "100%" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 16 }}>
        {labels.map((s, i) => (
          <React.Fragment key={i}>
            <div onClick={() => setStep(i)} style={{ display: "flex", alignItems: "center", gap: 8, cursor: "pointer" }}>
              <div style={{ width: 28, height: 28, borderRadius: "50%", background: i < step ? "var(--success)" : i === step ? "var(--blue-500)" : "var(--n-200)", color: i <= step ? "#fff" : "var(--n-600)", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 600, fontSize: 13 }}>{i < step ? <Icon name="check" size={14} /> : i + 1}</div>
              <div style={{ fontSize: 13, fontWeight: i === step ? 600 : 400, color: i <= step ? "var(--n-900)" : "var(--n-500)" }}>{s}</div>
            </div>
            {i < labels.length - 1 && <div style={{ flex: 1, height: 2, background: i < step ? "var(--success)" : "var(--n-200)" }} />}
          </React.Fragment>
        ))}
      </div>
      <div style={{ display: "flex", gap: 8 }}>
        <B kind="outline" size="sm" onClick={() => setStep(Math.max(0, step - 1))} disabled={step === 0}>上一步</B>
        <B kind="filled" size="sm" onClick={() => setStep(Math.min(labels.length - 1, step + 1))} disabled={step === labels.length - 1}>下一步</B>
      </div>
    </div>
  );
};

const StepperVertical = () => {
  const [step, setStep] = React.useState(1);
  const items = [
    { t: "建立工作區", d: "輸入名稱與類型" },
    { t: "邀請成員", d: "新增團隊成員" },
    { t: "完成設定", d: "確認所有資訊" },
  ];
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 0, width: 300 }}>
      {items.map((it, i) => (
        <div key={i} style={{ display: "flex", gap: 12, position: "relative" }}>
          <div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
            <div onClick={() => setStep(i)} style={{ width: 28, height: 28, borderRadius: "50%", background: i < step ? "var(--success)" : i === step ? "var(--blue-500)" : "var(--n-200)", color: i <= step ? "#fff" : "var(--n-600)", display: "flex", alignItems: "center", justifyContent: "center", fontWeight: 600, fontSize: 13, cursor: "pointer", flexShrink: 0 }}>
              {i < step ? <Icon name="check" size={14} /> : i + 1}
            </div>
            {i < items.length - 1 && <div style={{ flex: 1, width: 2, background: i < step ? "var(--success)" : "var(--n-200)", minHeight: 24 }} />}
          </div>
          <div style={{ paddingBottom: 18, flex: 1 }}>
            <div style={{ fontSize: 14, fontWeight: i === step ? 600 : 500, color: i <= step ? "var(--n-900)" : "var(--n-500)" }}>{it.t}</div>
            <div className="ds-cap" style={{ marginTop: 2 }}>{it.d}</div>
          </div>
        </div>
      ))}
    </div>
  );
};

const TabsIconDemo = () => {
  const [idx, setIdx] = React.useState(0);
  const items = [{ icon: "home", t: "首頁" }, { icon: "user", t: "成員" }, { icon: "set", t: "設定" }];
  return (
    <div style={{ display: "flex", gap: 24, borderBottom: "1px solid var(--n-200)" }}>
      {items.map((t, i) => (
        <div key={i} onClick={() => setIdx(i)} style={{ padding: "12px 4px", fontSize: 14, color: i === idx ? "var(--blue-500)" : "var(--n-700)", fontWeight: i === idx ? 500 : 400, borderBottom: i === idx ? "2px solid var(--blue-500)" : "2px solid transparent", cursor: "pointer", display: "inline-flex", alignItems: "center", gap: 6 }}>
          <Icon name={t.icon} size={16} />{t.t}
        </div>
      ))}
    </div>
  );
};

const DropdownDemo = () => {
  const [open, setOpen] = React.useState(false);
  const ref = React.useRef(null);
  React.useEffect(() => {
    const fn = (e) => { if (ref.current && !ref.current.contains(e.target)) setOpen(false); };
    document.addEventListener("mousedown", fn); return () => document.removeEventListener("mousedown", fn);
  }, []);
  return (
    <div ref={ref} style={{ position: "relative" }}>
      <B kind="outline" onClick={() => setOpen(!open)}>
        更多動作<Icon name="chev" size={14} style={{ marginLeft: 4, transform: open ? "rotate(180deg)" : "none", transition: "transform var(--dur-fast) var(--ease)" }} />
      </B>
      {open && (
        <div className="ds-menu" style={{ position: "absolute", top: "calc(100% + 6px)", left: 0, zIndex: 5 }}>
          <div className="ds-menu__item"><Icon name="edit" size={14} />編輯</div>
          <div className="ds-menu__item"><Icon name="copy" size={14} />複製</div>
          <div className="ds-menu__item"><Icon name="download" size={14} />下載</div>
          <div className="ds-menu__sep" />
          <div className="ds-menu__item" style={{ color: "var(--error)" }}>
            <Icon name="trash" size={14} color="var(--error)" />刪除
          </div>
        </div>
      )}
    </div>
  );
};

Object.assign(window, { T_MenuBar, T_AppBar, T_BottomNav, T_Breadcrumb, T_Drawer, T_Links, T_Pagination, T_SpeedDial, T_Stepper, T_Tabs, T_Dropdown, T_Anchor, DocNav });
