/* global React */
// ============================================================
// Trekko Admin — icon library (line icons)
// All 16x16 by default, currentColor stroke 1.5
// ============================================================

const Ic = ({ d, size = 16, fill, stroke = "currentColor", sw = 1.5, ...rest }) =>
<svg width={size} height={size} viewBox="0 0 16 16" fill={fill || "none"} {...rest}>
    {Array.isArray(d) ? d.map((dd, i) =>
  <path key={i} d={dd} stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round" />
  ) :
  <path d={d} stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round" />
  }
  </svg>;


const Icon = {
  Home: (p) => <Ic d="M2.5 7.5L8 3l5.5 4.5V13a.5.5 0 01-.5.5h-3v-4h-4v4H3a.5.5 0 01-.5-.5V7.5z" {...p} />,
  Dashboard: (p) => <Ic d={["M2.5 2.5h4v6h-4z", "M9.5 2.5h4v3h-4z", "M9.5 8h4v5.5h-4z", "M2.5 10.5h4v3h-4z"]} {...p} />,
  Bookings: (p) => <Ic d={["M3 3.5h10v10H3z", "M3 6h10", "M6 3v2", "M10 3v2"]} {...p} />,
  Users: (p) => <Ic d={["M11.5 5.5a2 2 0 11-4 0 2 2 0 014 0z", "M5.5 13c0-1.7 1.6-3 4-3s4 1.3 4 3", "M5 9.5a1.7 1.7 0 100-3.4", "M2 13c0-1.3 1.1-2.4 2.6-2.7"]} {...p} />,
  Building: (p) => <Ic d={["M3 13.5V3.5h7v10", "M10 7h3v6.5", "M5 6h3", "M5 8.5h3", "M5 11h3", "M11 9.5h1", "M11 11.5h1"]} {...p} />,
  Car: (p) => <Ic d={["M2 9.5h12", "M4 9.5L5 6h6l1 3.5", "M3 9.5v3h2v-1", "M11 12.5h2v-3", "M5.5 11.5a.5.5 0 100-1 .5.5 0 000 1z", "M10.5 11.5a.5.5 0 100-1 .5.5 0 000 1z"]} {...p} />,
  Vendor: (p) => <Ic d={["M2.5 5L4 3h8l1.5 2", "M2.5 5v8.5h11V5", "M2.5 5h11", "M6 8h4"]} {...p} />,
  Payment: (p) => <Ic d={["M2 4.5h12v7H2z", "M2 7h12", "M4.5 9.5h2"]} {...p} />,
  Wallet: (p) => <Ic d={["M2.5 4.5v8a1 1 0 001 1h10V6h-10a1 1 0 01-1-1v0a1 1 0 011-1h9", "M11 9.5h1.5"]} {...p} />,
  Settings: (p) => <Ic d={["M8 10a2 2 0 100-4 2 2 0 000 4z", "M12.5 8c0 .3 0 .6-.1.9l1.2 1-1 1.7-1.4-.5c-.4.3-.9.6-1.5.7l-.2 1.5h-2l-.2-1.5c-.6-.1-1-.4-1.5-.7l-1.4.5-1-1.7 1.2-1c0-.3-.1-.6-.1-.9s0-.6.1-.9l-1.2-1 1-1.7 1.4.5c.4-.3.9-.6 1.5-.7L7 2h2l.2 1.5c.6.1 1 .4 1.5.7l1.4-.5 1 1.7-1.2 1c.1.3.1.6.1.9z"]} {...p} />,
  Globe: (p) => <Ic d={["M8 13.5a5.5 5.5 0 100-11 5.5 5.5 0 000 11z", "M2.5 8h11", "M8 2.5c1.5 1.6 2.3 3.5 2.3 5.5S9.5 11.9 8 13.5", "M8 2.5C6.5 4.1 5.7 6 5.7 8s.8 3.9 2.3 5.5"]} {...p} />,
  Chart: (p) => <Ic d={["M2.5 13.5h11", "M4 11V8", "M7 11V5", "M10 11V7", "M13 11V4"]} {...p} />,
  Pie: (p) => <Ic d={["M8 2.5v5.5h5.5A5.5 5.5 0 008 2.5z", "M7 4a4.5 4.5 0 104.5 7.8"]} {...p} />,
  Trend: (p) => <Ic d={["M2.5 11l3.5-4 2.5 2 4.5-5", "M13 4h-2.5", "M13 4v2.5"]} {...p} />,
  Bell: (p) => <Ic d={["M3.5 11.5h9l-1-1.5V7a3.5 3.5 0 00-7 0v3l-1 1.5z", "M6.5 13a1.5 1.5 0 003 0"]} {...p} />,
  Search: (p) => <Ic d={["M7 12a5 5 0 100-10 5 5 0 000 10z", "M10.5 10.5l3 3"]} {...p} />,
  Plus: (p) => <Ic d={["M8 3v10", "M3 8h10"]} {...p} />,
  Filter: (p) => <Ic d="M2.5 3.5h11L9 9v4.5L7 12.5V9L2.5 3.5z" {...p} />,
  Download: (p) => <Ic d={["M8 2.5v8", "M5 7.5L8 10.5l3-3", "M3 13.5h10"]} {...p} />,
  Upload: (p) => <Ic d={["M8 13V5", "M5 8L8 5l3 3", "M3 2.5h10"]} {...p} />,
  Edit: (p) => <Ic d={["M11 2.5l2.5 2.5L5 13.5l-3 .5.5-3z", "M9.5 4l2.5 2.5"]} {...p} />,
  Trash: (p) => <Ic d={["M2.5 4.5h11", "M4 4.5V13a1 1 0 001 1h6a1 1 0 001-1V4.5", "M6 4.5V3a1 1 0 011-1h2a1 1 0 011 1v1.5", "M6.5 7v4", "M9.5 7v4"]} {...p} />,
  Eye: (p) => <Ic d={["M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z", "M8 10a2 2 0 100-4 2 2 0 000 4z"]} {...p} />,
  EyeOff: (p) => <Ic d={["M3 3l10 10", "M6.5 6.5A2 2 0 008 10c.4 0 .8-.1 1.1-.3", "M11 11c-1 .6-2 1-3 1-4 0-6.5-4-6.5-4S3 5 5.5 4", "M9 4.6c4.5.7 5.5 3.4 5.5 3.4s-1 1.7-2.5 2.7"]} {...p} />,
  More: (p) => <Ic d={["M4 8a.5.5 0 100-1 .5.5 0 000 1z", "M8 8a.5.5 0 100-1 .5.5 0 000 1z", "M12 8a.5.5 0 100-1 .5.5 0 000 1z"]} sw={2} {...p} />,
  ChevronDown: (p) => <Ic d="M4 6l4 4 4-4" {...p} />,
  ChevronRight: (p) => <Ic d="M6 4l4 4-4 4" {...p} />,
  ChevronLeft: (p) => <Ic d="M10 4L6 8l4 4" {...p} />,
  ChevronUp: (p) => <Ic d="M4 10l4-4 4 4" {...p} />,
  ArrowUp: (p) => <Ic d={["M8 3v10", "M4 7l4-4 4 4"]} {...p} />,
  ArrowDown: (p) => <Ic d={["M8 3v10", "M4 9l4 4 4-4"]} {...p} />,
  Check: (p) => <Ic d="M3 8l3.5 3.5L13 5" {...p} />,
  X: (p) => <Ic d={["M4 4l8 8", "M12 4l-8 8"]} {...p} />,
  Info: (p) => <Ic d={["M8 13.5a5.5 5.5 0 100-11 5.5 5.5 0 000 11z", "M8 8v3", "M8 5.5h.01"]} {...p} />,
  Warning: (p) => <Ic d={["M8 2L14 13H2L8 2z", "M8 6.5v3.5", "M8 11.5h.01"]} {...p} />,
  Cal: (p) => <Ic d={["M3 4h10v9.5H3z", "M3 7h10", "M5.5 2.5v3", "M10.5 2.5v3"]} {...p} />,
  Mail: (p) => <Ic d={["M2.5 4h11v8h-11z", "M2.5 4l5.5 4.5L13.5 4"]} {...p} />,
  Phone: (p) => <Ic d="M3.5 2.5h2L7 5.5 5.5 7a8 8 0 003.5 3.5L10.5 9l3 1.5v2c-5.5 0-10-4.5-10-10z" {...p} />,
  Pin: (p) => <Ic d={["M8 13.5S3 9.5 3 6.5a5 5 0 1110 0c0 3-5 7-5 7z", "M8 8.5a2 2 0 100-4 2 2 0 000 4z"]} {...p} />,
  Logout: (p) => <Ic d={["M9 2.5H4a1 1 0 00-1 1v9a1 1 0 001 1h5", "M7 8h6", "M11 5.5L13.5 8 11 10.5"]} {...p} />,
  Star: (p) => <Ic d="M8 2.5l1.6 3.2 3.6.5-2.6 2.5.6 3.5L8 10.5 4.8 12.2l.6-3.5L2.8 6.2l3.6-.5L8 2.5z" {...p} />,
  Clock: (p) => <Ic d={["M8 13.5a5.5 5.5 0 100-11 5.5 5.5 0 000 11z", "M8 5v3l2 1.5"]} {...p} />,
  Refresh: (p) => <Ic d={["M13 8a5 5 0 11-1.5-3.5", "M13 2.5V5h-2.5"]} {...p} />,
  Doc: (p) => <Ic d={["M3.5 2h6L13 5.5v8.5h-9.5z", "M9 2.5V6h3.5", "M5.5 9h5", "M5.5 11h5"]} {...p} />,
  Link: (p) => <Ic d={["M7 9a2.5 2.5 0 003.5 0L13 6.5A2.5 2.5 0 109.5 3L8.5 4", "M9 7a2.5 2.5 0 00-3.5 0L3 9.5A2.5 2.5 0 006.5 13l1-1"]} {...p} />,
  Bookmark: (p) => <Ic d="M4 2.5h8v11L8 11l-4 2.5v-11z" {...p} />,
  Tag: (p) => <Ic d={["M2.5 8.5L8.5 2.5h5v5L7.5 13.5l-5-5z", "M11 5.5a.5.5 0 100-1 .5.5 0 000 1z"]} {...p} />,
  Lock: (p) => <Ic d={["M3.5 7h9v6.5h-9z", "M5.5 7V5a2.5 2.5 0 015 0v2", "M8 9.5v2"]} {...p} />,
  Shield: (p) => <Ic d={["M8 2.5l5 1.5v4c0 3-2 5-5 5.5C5 13 3 11 3 8V4L8 2.5z", "M6 8l1.5 1.5L10 7"]} {...p} />,
  Bed: (p) => <Ic d={["M2.5 7v6", "M13.5 13V9a2 2 0 00-2-2H2.5", "M5.5 7V5h6v2", "M5.5 13v-2"]} {...p} />,
  Plane: (p) => <Ic d="M2.5 9l4 .5L9 12.5l1-1L8.5 8 13 5l-.5-1.5L8 6 4.5 4l-1 .5L6 7 2.5 8z" {...p} />,
  Ship: (p) => <Ic d={["M2 11.5l1 2.5h10l1-2.5", "M3 11.5l1-3h8l1 3", "M8 3v5", "M5 8.5h6"]} {...p} />,
  Sun: (p) => <Ic d={["M8 10.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5z", "M8 2v1.5", "M8 12.5V14", "M3 8H1.5", "M14.5 8H13", "M4 4l-1-1", "M13 13l-1-1", "M4 12l-1 1", "M13 3l-1 1"]} {...p} />,
  Moon: (p) => <Ic d="M12.5 9.5A4.5 4.5 0 016.5 3.5a5 5 0 106 6z" {...p} />,
  Help: (p) => <Ic d={["M8 13.5a5.5 5.5 0 100-11 5.5 5.5 0 000 11z", "M6.5 6.5a1.5 1.5 0 113 0c0 1-1.5 1-1.5 2.5", "M8 11.5h.01"]} {...p} />,
  Send: (p) => <Ic d={["M13.5 2.5L7 8.5", "M13.5 2.5L9 13.5 7 8.5 2.5 7l11-4.5z"]} {...p} />,
  Copy: (p) => <Ic d={["M5.5 2.5h7v8h-7z", "M3.5 5.5v8h7"]} {...p} />
};

// ============================================================
// Tiny presentational helpers
// ============================================================

function Badge({ tone = "neutral", plain, children }) {
  return <span className={`badge badge--${tone}${plain ? " badge--plain" : ""}`}>{children}</span>;
}

function Tag({ kind = "neutral", children }) {
  return <span className={`tag tag--${kind}`}>{children}</span>;
}

const AVATAR_BG = [
"linear-gradient(135deg,#635bff,#8d6eff)",
"linear-gradient(135deg,#00d4ff,#0e7c66)",
"linear-gradient(135deg,#ff9f43,#d4366a)",
"linear-gradient(135deg,#4b45c4,#a78bfa)",
"linear-gradient(135deg,#0e7c66,#00d4ff)",
"linear-gradient(135deg,#d4366a,#ff9f43)"];

function Avatar({ name = "", size = "md" }) {
  const initials = name.
  split(" ").
  filter(Boolean).
  slice(0, 2).
  map((s) => s[0]).
  join("").
  toUpperCase() || "?";
  const idx = (name.charCodeAt(0) + name.length) % AVATAR_BG.length;
  const cls = size === "sm" ? "avatar avatar--sm" : size === "lg" ? "avatar avatar--lg" : size === "xl" ? "avatar avatar--xl" : "avatar";
  return <span className={cls} style={{ background: AVATAR_BG[idx] }}>{initials}</span>;
}

function Button({ kind = "secondary", size, icon, iconOnly, block, loading, children, ...rest }) {
  // Some callers pass loading={false} as a UX hint. React complains if a
  // boolean-coerced non-standard attribute leaks to the DOM, so consume
  // it here and only attach a data-loading marker when truthy.
  const cls = [
    "btn",
    `btn--${kind}`,
    size ? `btn--${size}` : "",
    iconOnly ? "btn--icon" : "",
    block ? "btn--block" : "",
    loading ? "btn--loading" : "",
  ].filter(Boolean).join(" ");
  const dataLoading = loading ? "true" : undefined;
  return (
    <button className={cls} data-loading={dataLoading} disabled={loading ? true : rest.disabled} {...rest}>
      {icon}
      {!iconOnly && children}
    </button>
  );
}

function Field({ label, hint, error, children }) {
  return (
    <label className="field">
      {label && <span className="field__label">{label}</span>}
      {children}
      {hint && !error && <span className="field__hint">{hint}</span>}
      {error && <span className="field__error">{error}</span>}
    </label>);

}

function Toggle({ on, onChange }) {
  return (
    <button
      type="button"
      className={`toggle${on ? " toggle--on" : ""}`}
      onClick={() => onChange && onChange(!on)}
      aria-pressed={on} />);


}

function Tabs({ tabs, active, onChange }) {
  return (
    <div className="tabs">
      {tabs.map((t) =>
      <button
        key={t.id}
        className={`tabs__tab${active === t.id ? " tabs__tab--active" : ""}`}
        onClick={() => onChange(t.id)}>
        
          {t.label}
          {t.count != null && <span style={{ marginLeft: 6, color: "var(--ink-4)", fontWeight: 500 }}>{t.count}</span>}
        </button>
      )}
    </div>);

}

function Segmented({ options, value, onChange }) {
  return (
    <div className="segmented">
      {options.map((o) =>
      <button
        key={o.value ?? o}
        className={`segmented__opt${value === (o.value ?? o) ? " segmented__opt--active" : ""}`}
        onClick={() => onChange(o.value ?? o)}>
        
          {o.label ?? o}
        </button>
      )}
    </div>);

}

function PeriodPicker({ value, onChange }) {
  const { useState, useRef, useEffect } = React;
  const [open, setOpen] = useState(false);
  const [from, setFrom] = useState("");
  const [to, setTo] = useState("");
  const ref = useRef(null);
  useEffect(() => {
    const h = (e) => {if (ref.current && !ref.current.contains(e.target)) setOpen(false);};
    document.addEventListener("mousedown", h);
    return () => document.removeEventListener("mousedown", h);
  }, []);
  const opts = [
  { value: "today", label: "Today" }, { value: "week", label: "Week" },
  { value: "month", label: "Month" }, { value: "qtd", label: "QTD" },
  { value: "ytd", label: "YTD" }, { value: "custom", label: "Custom" }];

  return (
    <div ref={ref} style={{ position: "relative", display: "inline-block" }}>
      <div className="segmented">
        {opts.map((o) =>
        <button key={o.value}
        className={`segmented__opt${value === o.value ? " segmented__opt--active" : ""}`}
        onClick={() => {(onChange || (() => {}))(o.value);if (o.value === "custom") setOpen((v) => !v);else setOpen(false);}}>
          {o.label}
        </button>)}
      </div>
      {open &&
      <div style={{ position: "absolute", right: 0, top: 40, zIndex: 200, background: "#fff", border: "1px solid var(--border)", borderRadius: 10, boxShadow: "var(--shadow-lg)", padding: 16, minWidth: 320 }}>
        <div className="bold" style={{ marginBottom: 12 }}>Custom date range</div>
        <div className="grid grid--2" style={{ gap: 12 }}>
          <Field label="From"><input className="input" type="date" value={from} onChange={(e) => setFrom(e.target.value)} /></Field>
          <Field label="To"><input className="input" type="date" value={to} onChange={(e) => setTo(e.target.value)} /></Field>
        </div>
        <div className="row" style={{ marginTop: 14, justifyContent: "flex-end", gap: 8 }}>
          <Button kind="ghost" onClick={() => setOpen(false)}>Cancel</Button>
          <Button kind="primary" onClick={() => setOpen(false)}>Apply</Button>
        </div>
      </div>}
    </div>);
}

function Card({ title, sub, actions, foot, flush, children, style, className }) {
  return (
    <div className={`card${className ? " " + className : ""}`} style={style} data-comment-anchor="53b58a805c-div-224-5">
      {(title || actions) &&
      <div className="card__head" data-comment-anchor="035f1eabd7-div-185-9">
          {title &&
        <div>
              <div className="card__title">{title}</div>
              {sub && <div className="card__sub">{sub}</div>}
            </div>
        }
          {actions && <div className="card__actions">{actions}</div>}
        </div>
      }
      <div className={`card__body${flush ? " card__body--flush" : ""}`}>{children}</div>
      {foot && <div className="card__foot">{foot}</div>}
    </div>);

}

function Metric({ label, value, delta, deltaDir, hint, accent, mom, momDir, yoy, yoyDir }) {
  return (
    <div className={`metric${accent ? " metric--accent" : ""}`}>
      <div className="metric__label">{label}</div>
      <div className="metric__value">{value}</div>
      {mom != null || yoy != null ?
      <div style={{ display: "flex", gap: 6, alignItems: "center", flexWrap: "wrap", marginTop: 2 }}>
          {mom != null &&
        <span className="metric__cmp">
              <span className="metric__cmp-lbl">MoM</span>
              <span className={`metric__delta metric__delta--${momDir === "down" ? "down" : "up"}`}>
                {momDir === "down" ? <Icon.ArrowDown size={11} /> : <Icon.ArrowUp size={11} />}{mom}
              </span>
            </span>
        }
          {yoy != null &&
        <span className="metric__cmp">
              <span className="metric__cmp-lbl">YoY</span>
              <span className={`metric__delta metric__delta--${yoyDir === "down" ? "down" : "up"}`}>
                {yoyDir === "down" ? <Icon.ArrowDown size={11} /> : <Icon.ArrowUp size={11} />}{yoy}
              </span>
            </span>
        }
          {hint && <span className="tiny muted" style={{ width: "100%" }}>{hint}</span>}
        </div> :
      <div style={{ display: "flex", gap: 8, alignItems: "center" }}>
        {delta != null &&
        <span className={`metric__delta metric__delta--${deltaDir === "down" ? "down" : "up"}`}>
            {deltaDir === "down" ? <Icon.ArrowDown size={12} /> : <Icon.ArrowUp size={12} />}
            {delta}
          </span>
        }
        {hint && <span className="tiny muted">{hint}</span>}
      </div>
      }
    </div>);

}

// ============================================================
// Modal (controlled)
// ============================================================
function Modal({ open, title, onClose, footer, size, children }) {
  if (!open) return null;
  return (
    <div className="modal-veil" onClick={onClose}>
      <div className={`modal${size === "lg" ? " modal--lg" : size === "xl" ? " modal--xl" : ""}`} onClick={(e) => e.stopPropagation()}>
        <div className="modal__head">
          <h3 className="modal__title">{title}</h3>
          <button className="modal__close" onClick={onClose} aria-label="Close"><Icon.X /></button>
        </div>
        <div className="modal__body" data-comment-anchor="ece0626a77-div-252-9">{children}</div>
        {footer && <div className="modal__foot">{footer}</div>}
      </div>
    </div>);

}

// ============================================================
// Pagination
// ============================================================
function Pager({ page = 1, pageSize = 10, total = 0, onPage }) {
  const totalPages = Math.max(1, Math.ceil(total / pageSize));
  const start = total === 0 ? 0 : (page - 1) * pageSize + 1;
  const end = Math.min(page * pageSize, total);
  const nums = [];
  const push = (n) => nums.push(n);
  push(1);
  if (page - 2 > 2) push("…");
  for (let i = Math.max(2, page - 1); i <= Math.min(totalPages - 1, page + 1); i++) push(i);
  if (page + 2 < totalPages - 1) push("…");
  if (totalPages > 1) push(totalPages);

  return (
    <div className="pager">
      <div className="muted">Showing <span className="bold tabular" style={{ color: "var(--ink-1)" }}>{start}–{end}</span> of <span className="bold tabular" style={{ color: "var(--ink-1)" }}>{total.toLocaleString()}</span></div>
      <div className="pager__nums">
        <button className="pager__num" onClick={() => onPage(Math.max(1, page - 1))} disabled={page <= 1}><Icon.ChevronLeft /></button>
        {nums.map((n, i) =>
        n === "…" ? <span key={"e" + i} className="pager__num" style={{ pointerEvents: "none", color: "var(--ink-4)" }}>…</span> :
        <button key={n} className={`pager__num${n === page ? " pager__num--active" : ""}`} onClick={() => onPage(n)}>{n}</button>
        )}
        <button className="pager__num" onClick={() => onPage(Math.min(totalPages, page + 1))} disabled={page >= totalPages}><Icon.ChevronRight /></button>
      </div>
    </div>);

}

// ============================================================
// Toast system (Stripe-style ephemeral confirmations)
// ============================================================
function Toaster() {
  var { useState, useEffect } = React;
  var [items, setItems] = useState([]);
  useEffect(() => {
    const handler = (e) => {
      const t = { id: Date.now() + Math.random(), ...e.detail };
      setItems((s) => [...s, t]);
      setTimeout(() => setItems((s) => s.filter((x) => x.id !== t.id)), t.duration || 3600);
    };
    window.addEventListener("toast", handler);
    return () => window.removeEventListener("toast", handler);
  }, []);
  return (
    <div style={{ position: "fixed", bottom: 20, right: 20, zIndex: 9999, display: "flex", flexDirection: "column", gap: 8, pointerEvents: "none" }}>
      {items.map((t) =>
      <div key={t.id} style={{
        minWidth: 280, maxWidth: 380,
        background: "#fff",
        border: "1px solid var(--border)",
        boxShadow: "var(--shadow-lg)",
        borderRadius: 10,
        padding: "12px 14px",
        display: "flex", gap: 10, alignItems: "flex-start",
        animation: "toast-in 220ms cubic-bezier(0.2, 0.7, 0.1, 1)",
        pointerEvents: "auto"
      }}>
          <span style={{
          width: 22, height: 22, borderRadius: 999, flexShrink: 0,
          display: "grid", placeItems: "center",
          background: t.tone === "danger" ? "var(--danger-bg)" : t.tone === "warning" ? "var(--warning-bg)" : "var(--success-bg)",
          color: t.tone === "danger" ? "var(--danger)" : t.tone === "warning" ? "var(--warning)" : "var(--success)"
        }}>
            {t.tone === "danger" ? <Icon.Warning size={12} stroke="currentColor" /> :
          t.tone === "warning" ? <Icon.Warning size={12} stroke="currentColor" /> :
          <Icon.Check size={12} stroke="currentColor" sw={2.2} />}
          </span>
          <div style={{ flex: 1, fontSize: 13.5, lineHeight: 1.45 }}>
            {t.title && <div className="bold">{t.title}</div>}
            {t.body && <div style={{ color: "var(--ink-3)", fontSize: 12.5 }}>{t.body}</div>}
          </div>
        </div>
      )}
      <style>{`@keyframes toast-in { from { transform: translateY(8px); opacity: 0 } to { transform: none; opacity: 1 } }`}</style>
    </div>);

}

function toast(detail) {
  window.dispatchEvent(new CustomEvent("toast", { detail }));
}

// ============================================================
// expose to window so other Babel scripts can use them
// ============================================================
Object.assign(window, {
  Icon, Badge, Tag, Avatar, Button, Field, Toggle, Tabs, Segmented, PeriodPicker,
  Card, Metric, Modal, Pager, Toaster, toast
});