yamchart 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dist/{chunk-7CD6UQAV.js → chunk-DZVT6PHW.js} +9 -1
  2. package/dist/chunk-DZVT6PHW.js.map +1 -0
  3. package/dist/{dev-7YLRQ6SA.js → dev-GWXHBBWB.js} +21 -6
  4. package/dist/{dev-7YLRQ6SA.js.map → dev-GWXHBBWB.js.map} +1 -1
  5. package/dist/{dist-NGQG7Z4G.js → dist-MIKFZKSD.js} +2 -2
  6. package/dist/index.js +2 -2
  7. package/dist/public/assets/{EventManagement-B7leMxfo.js → EventManagement-CTuAJ0eF.js} +1 -1
  8. package/dist/public/assets/{ExplorePage-zI1OiYlH.js → ExplorePage-ZJ3zNjNQ.js} +1 -1
  9. package/dist/public/assets/{LoginPage-Dyk2ILmo.js → LoginPage-wygea4BI.js} +1 -1
  10. package/dist/public/assets/{PublicViewer-C2tNYBR2.js → PublicViewer-8YqGrVVB.js} +1 -1
  11. package/dist/public/assets/{SetupWizard-BzZSJlbt.js → SetupWizard-DqDBwHrF.js} +1 -1
  12. package/dist/public/assets/{ShareManagement-C7RIZRWe.js → ShareManagement-TAAdI_gY.js} +1 -1
  13. package/dist/public/assets/{UserManagement-BD-lLbVH.js → UserManagement-B4kZHyri.js} +1 -1
  14. package/dist/public/assets/{index-lklRbe2I.js → index-BgzSjgIu.js} +3 -3
  15. package/dist/public/assets/{index.es-CLyC5-GY.js → index.es-AB-GdGyc.js} +1 -1
  16. package/dist/public/assets/{jspdf.es.min-CTZVk96E.js → jspdf.es.min-ChRx2mOQ.js} +3 -3
  17. package/dist/public/index.html +1 -1
  18. package/dist/{reset-password-HDCLH7PZ.js → reset-password-YVCZKZPC.js} +2 -2
  19. package/dist/templates/default/docs/yamchart-reference.md +4 -0
  20. package/package.json +4 -4
  21. package/dist/chunk-7CD6UQAV.js.map +0 -1
  22. /package/dist/{dist-NGQG7Z4G.js.map → dist-MIKFZKSD.js.map} +0 -0
  23. /package/dist/{reset-password-HDCLH7PZ.js.map → reset-password-YVCZKZPC.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  hashToken,
7
7
  parseTtl,
8
8
  verifyPassword
9
- } from "./chunk-7CD6UQAV.js";
9
+ } from "./chunk-DZVT6PHW.js";
10
10
  import "./chunk-7D4SUZUM.js";
11
11
  export {
12
12
  AuthDatabase,
@@ -17,4 +17,4 @@ export {
17
17
  parseTtl,
18
18
  verifyPassword
19
19
  };
20
- //# sourceMappingURL=dist-NGQG7Z4G.js.map
20
+ //# sourceMappingURL=dist-MIKFZKSD.js.map
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ program.command("dev").description("Start development server with hot reload").a
105
105
  process.exit(2);
106
106
  }
107
107
  const globalOpts = program.opts();
108
- const { runDevServer } = await import("./dev-7YLRQ6SA.js");
108
+ const { runDevServer } = await import("./dev-GWXHBBWB.js");
109
109
  await runDevServer(projectDir, {
110
110
  port: parseInt(options.port, 10),
111
111
  apiOnly: options.apiOnly ?? false,
@@ -268,7 +268,7 @@ program.command("reset-password").description("Reset a user password (requires a
268
268
  process.exit(2);
269
269
  }
270
270
  loadEnvFile(projectDir);
271
- const { resetPassword } = await import("./reset-password-HDCLH7PZ.js");
271
+ const { resetPassword } = await import("./reset-password-YVCZKZPC.js");
272
272
  await resetPassword(projectDir, options.email);
273
273
  });
274
274
  program.command("tables").description("List tables and views in the connected database").option("-c, --connection <name>", "Connection to use (overrides default)").option("-s, --schema <name>", "Filter to schema").option("-d, --database <name>", "Filter to database (Snowflake/Databricks)").option("--json", "Output as JSON").option("--source <type>", "Data source: auto, catalog, model, or db (default: auto)").option("--compare", "Compare local metadata against live database").action(async (options) => {
@@ -1,4 +1,4 @@
1
- import{t as xe,u as he,v as me,e as be,w as $,j as t,x as E,E as ce,M as fe,y as ve,z as je,I as Ce,a as S}from"./index-lklRbe2I.js";import{a as s}from"./echarts-DtOYsfLX.js";const ge=`
1
+ import{t as xe,u as he,v as me,e as be,w as $,j as t,x as E,E as ce,M as fe,y as ve,z as je,I as Ce,a as S}from"./index-BgzSjgIu.js";import{a as s}from"./echarts-DtOYsfLX.js";const ge=`
2
2
  .rdp-root {
3
3
  --rdp-accent-color: var(--yc-color-primary, #2563eb);
4
4
  --rdp-accent-background-color: color-mix(in srgb, var(--yc-color-primary, #2563eb) 15%, transparent);
@@ -1 +1 @@
1
- import{j as e,i as k,J as E,K as B,v as M,N as W,O as $,a as D}from"./index-lklRbe2I.js";import{a}from"./echarts-DtOYsfLX.js";const T=["What data do I have?","Show me recent trends","What are the top items by revenue?","Compare this month to last month"];function P({summary:t,onPromptClick:i}){return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-6 py-12 gap-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",style:{color:"var(--yc-color-text)"},children:"Data Explorer"}),e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"Ask questions about your data in plain English"})]}),t&&(t.tableCount>0||t.modelCount>0)&&e.jsxs("div",{className:"rounded-xl px-5 py-4 w-full max-w-md flex flex-col gap-3",style:{background:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Connected data"}),e.jsxs("div",{className:"flex gap-6",children:[t.tableCount>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xl font-bold",style:{color:"var(--yc-color-text)"},children:t.tableCount}),e.jsx("span",{className:"text-xs ml-1",style:{color:"var(--yc-color-text-secondary)"},children:t.tableCount===1?"table":"tables"})]}),t.modelCount>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xl font-bold",style:{color:"var(--yc-color-text)"},children:t.modelCount}),e.jsx("span",{className:"text-xs ml-1",style:{color:"var(--yc-color-text-secondary)"},children:t.modelCount===1?"model":"models"})]})]}),t.connections.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.connections.map(l=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full",style:{background:"var(--yc-color-bg)",color:"var(--yc-color-text-secondary)",border:"1px solid var(--yc-color-border)"},children:l.name},l.name))})]}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-lg",children:T.map(l=>e.jsx("button",{onClick:()=>i(l),className:"text-sm px-3 py-1.5 rounded-full transition-opacity hover:opacity-80",style:{background:"var(--yc-color-surface)",color:"var(--yc-color-text)",border:"1px solid var(--yc-color-border)"},children:l},l))})]})}function R({summary:t,onTableClick:i}){const[l,x]=a.useState(new Set),[n,h]=a.useState(new Set),v=s=>{x(o=>{const c=new Set(o);return c.has(s)?c.delete(s):c.add(s),c})},f=s=>{h(o=>{const c=new Set(o);return c.has(s)?c.delete(s):c.add(s),c})},y=((t==null?void 0:t.connections)??[]).map(s=>({connection:s.name,tables:((t==null?void 0:t.tables)??[]).filter(o=>o.connection===s.name)})),u=(t==null?void 0:t.models)??[];return e.jsxs("div",{className:"w-64 flex-shrink-0 flex flex-col h-full overflow-y-auto",style:{borderRight:"1px solid var(--yc-color-border)",background:"var(--yc-color-surface)"},children:[e.jsx("div",{className:"px-3 py-2 flex items-center",style:{borderBottom:"1px solid var(--yc-color-border)"},children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Catalog"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-2",children:[y.map(s=>e.jsxs("div",{children:[e.jsxs("button",{className:"w-full flex items-center gap-1.5 px-3 py-1.5 hover:opacity-80 text-left",onClick:()=>v(s.connection),children:[e.jsx(g,{expanded:l.has(s.connection)}),e.jsx(I,{}),e.jsx("span",{className:"text-xs font-medium truncate",style:{color:"var(--yc-color-text)"},children:s.connection}),e.jsx("span",{className:"ml-auto text-xs",style:{color:"var(--yc-color-text-secondary)"},children:s.tables.length})]}),l.has(s.connection)&&e.jsx("div",{children:s.tables.map(o=>{const c=`${s.connection}:${o.name}`,m=n.has(c);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1 pl-6 pr-2 py-1 group",children:[e.jsxs("button",{className:"flex items-center gap-1 flex-1 min-w-0 hover:opacity-80 text-left",onClick:()=>f(c),children:[e.jsx(g,{expanded:m}),e.jsx(A,{}),e.jsx("span",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:o.schema?`${o.schema}.${o.name}`:o.name})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-xs px-1.5 py-0.5 rounded transition-opacity flex-shrink-0",style:{background:"var(--yc-color-primary)",color:"#fff"},onClick:()=>i(o.schema?`${o.schema}.${o.name}`:o.name),title:`Ask about ${o.name}`,children:"Ask"})]}),m&&o.columns.length>0&&e.jsx("div",{className:"pl-12 pb-1",children:o.columns.map(d=>e.jsxs("div",{className:"flex items-center gap-1.5 py-0.5 pr-2",children:[e.jsx("span",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:d.name}),d.type&&e.jsx("span",{className:"text-xs ml-auto flex-shrink-0",style:{color:"var(--yc-color-text-secondary)"},children:d.type})]},d.name))})]},c)})})]},s.connection)),u.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-3 py-1.5",style:{borderTop:"1px solid var(--yc-color-border)"},children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Models"})}),u.map(s=>e.jsxs("div",{className:"flex items-center gap-1.5 pl-3 pr-2 py-1.5 group",children:[e.jsx(O,{}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:s.name}),s.description&&e.jsx("p",{className:"text-xs truncate",style:{color:"var(--yc-color-text-secondary)"},children:s.description})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-xs px-1.5 py-0.5 rounded transition-opacity flex-shrink-0",style:{background:"var(--yc-color-primary)",color:"#fff"},onClick:()=>i(s.name),title:`Ask about ${s.name}`,children:"Ask"})]},s.name))]}),!t||y.length===0&&u.length===0?e.jsx("div",{className:"px-3 py-4 text-center",children:e.jsxs("p",{className:"text-xs",style:{color:"var(--yc-color-text-secondary)"},children:["No catalog data available. Run ",e.jsx("code",{className:"font-mono",children:"yamchart sync-warehouse"})," to populate."]})}):null]})]})}function g({expanded:t}){return e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",transform:t?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s",flexShrink:0},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})}function I(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]})}function A(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M3 9h18M3 15h18M9 3v18"})]})}function O(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]})}function q(){const t=k(n=>n.savedCharts),[i,l]=a.useState(!1),x=a.useRef(null);return a.useEffect(()=>{if(!i)return;function n(h){x.current&&!x.current.contains(h.target)&&l(!1)}return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[i]),t.length===0?null:e.jsxs("div",{className:"relative",ref:x,children:[e.jsxs("button",{onClick:()=>l(n=>!n),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-opacity hover:opacity-80",style:{background:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)",color:"var(--yc-color-text)"},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]}),e.jsxs("span",{children:[t.length," saved ",t.length===1?"chart":"charts"]}),e.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold text-white",style:{background:"var(--yc-color-primary)"},children:t.length})]}),i&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-56 rounded-lg shadow-lg z-50 py-1",style:{background:"var(--yc-color-bg)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("p",{className:"px-3 py-1.5 text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Saved charts"}),t.map(n=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-primary)",flexShrink:0},children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{className:"text-sm truncate",style:{color:"var(--yc-color-text)"},children:n})]},n))]})]})}function V(){const t=E(),{messages:i,isStreaming:l,savedCharts:x,openPanel:n,setPanelMode:h,snapshotExploreHistory:v,clearConversation:f}=k(),[y,u]=a.useState(!0),[s,o]=a.useState(void 0),c=a.useRef(null);a.useEffect(()=>(h("explore"),n({type:"explore"}),()=>{h("panel")}),[h,n]),a.useEffect(()=>{var r;(r=c.current)==null||r.scrollIntoView({behavior:"smooth"})},[i]);const m=a.useCallback((r,p,S)=>{v(p),h("panel");const L=r==="chart"?"charts":"dashboards";window.location.hash=`/${L}/${encodeURIComponent(p)}${S?"?edit=true":""}`,n({type:r==="chart"?"chart":"dashboard",name:p})},[v,h,n]),{sendMessage:d}=B(m),{data:j}=M({queryKey:["catalog-summary"],queryFn:()=>D.getCatalogSummary(),staleTime:6e4,retry:!1}),b=a.useCallback(r=>{o(`Tell me about the ${r} table`)},[]),w=a.useCallback(r=>{d(r)},[d]),N=a.useCallback(r=>{d(r),o(void 0)},[d]),C=a.useCallback(()=>{const r=x.join(", ");d(`Build a dashboard using these charts: ${r}. Arrange them in a logical layout.`)},[x,d]);return t==="sm"?e.jsx("div",{className:"flex items-center justify-center h-screen px-6",style:{background:"var(--yc-color-bg)"},children:e.jsxs("div",{className:"text-center max-w-xs",children:[e.jsx("p",{className:"text-lg font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Desktop required"}),e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"Data Explorer is designed for larger screens. Please open it on a desktop or laptop."})]})}):e.jsxs("div",{className:"flex h-screen overflow-hidden",style:{background:"var(--yc-color-bg)"},children:[y&&e.jsx(R,{summary:j??null,onTableClick:b}),e.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{borderBottom:"1px solid var(--yc-color-border)"},children:[e.jsxs("a",{href:"#/",className:"flex items-center gap-1.5 text-sm hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:r=>{r.preventDefault(),window.location.hash="/"},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Dashboards"]}),e.jsx("div",{className:"w-px h-4 mx-1",style:{background:"var(--yc-color-border)"}}),e.jsx("button",{className:"p-1.5 rounded hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:()=>u(r=>!r),title:y?"Hide catalog":"Show catalog",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M9 3v18"})]})}),e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--yc-color-text)"},children:"Data Explorer"}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(q,{}),e.jsxs("button",{disabled:x.length===0||l,onClick:C,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-opacity disabled:opacity-40",style:{background:"var(--yc-color-primary)",color:"#fff"},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]}),"Build Dashboard"]}),i.length>0&&e.jsx("button",{className:"p-1.5 rounded hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:f,title:"New conversation",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 20h9"}),e.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4 flex flex-col gap-3 min-h-0",children:i.length===0?e.jsx(P,{summary:j??null,onPromptClick:w}):e.jsxs(e.Fragment,{children:[i.map((r,p)=>e.jsx(W,{message:r,isStreaming:l&&p===i.length-1&&r.role==="assistant",onSendMessage:d},p)),e.jsx("div",{ref:c})]})}),e.jsx("div",{className:"px-6 py-3 flex-shrink-0",style:{borderTop:"1px solid var(--yc-color-border)"},children:e.jsx($,{onSend:N,placeholder:"Ask about your data...",disabled:l,initialValue:s})})]})]})}export{V as default};
1
+ import{j as e,i as k,J as E,K as B,v as M,N as W,O as $,a as D}from"./index-BgzSjgIu.js";import{a}from"./echarts-DtOYsfLX.js";const T=["What data do I have?","Show me recent trends","What are the top items by revenue?","Compare this month to last month"];function P({summary:t,onPromptClick:i}){return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-6 py-12 gap-8",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",style:{color:"var(--yc-color-text)"},children:"Data Explorer"}),e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"Ask questions about your data in plain English"})]}),t&&(t.tableCount>0||t.modelCount>0)&&e.jsxs("div",{className:"rounded-xl px-5 py-4 w-full max-w-md flex flex-col gap-3",style:{background:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Connected data"}),e.jsxs("div",{className:"flex gap-6",children:[t.tableCount>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xl font-bold",style:{color:"var(--yc-color-text)"},children:t.tableCount}),e.jsx("span",{className:"text-xs ml-1",style:{color:"var(--yc-color-text-secondary)"},children:t.tableCount===1?"table":"tables"})]}),t.modelCount>0&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xl font-bold",style:{color:"var(--yc-color-text)"},children:t.modelCount}),e.jsx("span",{className:"text-xs ml-1",style:{color:"var(--yc-color-text-secondary)"},children:t.modelCount===1?"model":"models"})]})]}),t.connections.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.connections.map(l=>e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full",style:{background:"var(--yc-color-bg)",color:"var(--yc-color-text-secondary)",border:"1px solid var(--yc-color-border)"},children:l.name},l.name))})]}),e.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-lg",children:T.map(l=>e.jsx("button",{onClick:()=>i(l),className:"text-sm px-3 py-1.5 rounded-full transition-opacity hover:opacity-80",style:{background:"var(--yc-color-surface)",color:"var(--yc-color-text)",border:"1px solid var(--yc-color-border)"},children:l},l))})]})}function R({summary:t,onTableClick:i}){const[l,x]=a.useState(new Set),[n,h]=a.useState(new Set),v=s=>{x(o=>{const c=new Set(o);return c.has(s)?c.delete(s):c.add(s),c})},f=s=>{h(o=>{const c=new Set(o);return c.has(s)?c.delete(s):c.add(s),c})},y=((t==null?void 0:t.connections)??[]).map(s=>({connection:s.name,tables:((t==null?void 0:t.tables)??[]).filter(o=>o.connection===s.name)})),u=(t==null?void 0:t.models)??[];return e.jsxs("div",{className:"w-64 flex-shrink-0 flex flex-col h-full overflow-y-auto",style:{borderRight:"1px solid var(--yc-color-border)",background:"var(--yc-color-surface)"},children:[e.jsx("div",{className:"px-3 py-2 flex items-center",style:{borderBottom:"1px solid var(--yc-color-border)"},children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Catalog"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-2",children:[y.map(s=>e.jsxs("div",{children:[e.jsxs("button",{className:"w-full flex items-center gap-1.5 px-3 py-1.5 hover:opacity-80 text-left",onClick:()=>v(s.connection),children:[e.jsx(g,{expanded:l.has(s.connection)}),e.jsx(I,{}),e.jsx("span",{className:"text-xs font-medium truncate",style:{color:"var(--yc-color-text)"},children:s.connection}),e.jsx("span",{className:"ml-auto text-xs",style:{color:"var(--yc-color-text-secondary)"},children:s.tables.length})]}),l.has(s.connection)&&e.jsx("div",{children:s.tables.map(o=>{const c=`${s.connection}:${o.name}`,m=n.has(c);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1 pl-6 pr-2 py-1 group",children:[e.jsxs("button",{className:"flex items-center gap-1 flex-1 min-w-0 hover:opacity-80 text-left",onClick:()=>f(c),children:[e.jsx(g,{expanded:m}),e.jsx(A,{}),e.jsx("span",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:o.schema?`${o.schema}.${o.name}`:o.name})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-xs px-1.5 py-0.5 rounded transition-opacity flex-shrink-0",style:{background:"var(--yc-color-primary)",color:"#fff"},onClick:()=>i(o.schema?`${o.schema}.${o.name}`:o.name),title:`Ask about ${o.name}`,children:"Ask"})]}),m&&o.columns.length>0&&e.jsx("div",{className:"pl-12 pb-1",children:o.columns.map(d=>e.jsxs("div",{className:"flex items-center gap-1.5 py-0.5 pr-2",children:[e.jsx("span",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:d.name}),d.type&&e.jsx("span",{className:"text-xs ml-auto flex-shrink-0",style:{color:"var(--yc-color-text-secondary)"},children:d.type})]},d.name))})]},c)})})]},s.connection)),u.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"px-3 py-1.5",style:{borderTop:"1px solid var(--yc-color-border)"},children:e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Models"})}),u.map(s=>e.jsxs("div",{className:"flex items-center gap-1.5 pl-3 pr-2 py-1.5 group",children:[e.jsx(O,{}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs truncate",style:{color:"var(--yc-color-text)"},children:s.name}),s.description&&e.jsx("p",{className:"text-xs truncate",style:{color:"var(--yc-color-text-secondary)"},children:s.description})]}),e.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-xs px-1.5 py-0.5 rounded transition-opacity flex-shrink-0",style:{background:"var(--yc-color-primary)",color:"#fff"},onClick:()=>i(s.name),title:`Ask about ${s.name}`,children:"Ask"})]},s.name))]}),!t||y.length===0&&u.length===0?e.jsx("div",{className:"px-3 py-4 text-center",children:e.jsxs("p",{className:"text-xs",style:{color:"var(--yc-color-text-secondary)"},children:["No catalog data available. Run ",e.jsx("code",{className:"font-mono",children:"yamchart sync-warehouse"})," to populate."]})}):null]})]})}function g({expanded:t}){return e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",transform:t?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s",flexShrink:0},children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})}function I(){return e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"}),e.jsx("path",{d:"M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"})]})}function A(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M3 9h18M3 15h18M9 3v18"})]})}function O(){return e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-text-secondary)",flexShrink:0},children:[e.jsx("polyline",{points:"16 18 22 12 16 6"}),e.jsx("polyline",{points:"8 6 2 12 8 18"})]})}function q(){const t=k(n=>n.savedCharts),[i,l]=a.useState(!1),x=a.useRef(null);return a.useEffect(()=>{if(!i)return;function n(h){x.current&&!x.current.contains(h.target)&&l(!1)}return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[i]),t.length===0?null:e.jsxs("div",{className:"relative",ref:x,children:[e.jsxs("button",{onClick:()=>l(n=>!n),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-opacity hover:opacity-80",style:{background:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)",color:"var(--yc-color-text)"},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]}),e.jsxs("span",{children:[t.length," saved ",t.length===1?"chart":"charts"]}),e.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold text-white",style:{background:"var(--yc-color-primary)"},children:t.length})]}),i&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-56 rounded-lg shadow-lg z-50 py-1",style:{background:"var(--yc-color-bg)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("p",{className:"px-3 py-1.5 text-xs font-semibold uppercase tracking-wide",style:{color:"var(--yc-color-text-secondary)"},children:"Saved charts"}),t.map(n=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--yc-color-primary)",flexShrink:0},children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{className:"text-sm truncate",style:{color:"var(--yc-color-text)"},children:n})]},n))]})]})}function V(){const t=E(),{messages:i,isStreaming:l,savedCharts:x,openPanel:n,setPanelMode:h,snapshotExploreHistory:v,clearConversation:f}=k(),[y,u]=a.useState(!0),[s,o]=a.useState(void 0),c=a.useRef(null);a.useEffect(()=>(h("explore"),n({type:"explore"}),()=>{h("panel")}),[h,n]),a.useEffect(()=>{var r;(r=c.current)==null||r.scrollIntoView({behavior:"smooth"})},[i]);const m=a.useCallback((r,p,S)=>{v(p),h("panel");const L=r==="chart"?"charts":"dashboards";window.location.hash=`/${L}/${encodeURIComponent(p)}${S?"?edit=true":""}`,n({type:r==="chart"?"chart":"dashboard",name:p})},[v,h,n]),{sendMessage:d}=B(m),{data:j}=M({queryKey:["catalog-summary"],queryFn:()=>D.getCatalogSummary(),staleTime:6e4,retry:!1}),b=a.useCallback(r=>{o(`Tell me about the ${r} table`)},[]),w=a.useCallback(r=>{d(r)},[d]),N=a.useCallback(r=>{d(r),o(void 0)},[d]),C=a.useCallback(()=>{const r=x.join(", ");d(`Build a dashboard using these charts: ${r}. Arrange them in a logical layout.`)},[x,d]);return t==="sm"?e.jsx("div",{className:"flex items-center justify-center h-screen px-6",style:{background:"var(--yc-color-bg)"},children:e.jsxs("div",{className:"text-center max-w-xs",children:[e.jsx("p",{className:"text-lg font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Desktop required"}),e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"Data Explorer is designed for larger screens. Please open it on a desktop or laptop."})]})}):e.jsxs("div",{className:"flex h-screen overflow-hidden",style:{background:"var(--yc-color-bg)"},children:[y&&e.jsx(R,{summary:j??null,onTableClick:b}),e.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{borderBottom:"1px solid var(--yc-color-border)"},children:[e.jsxs("a",{href:"#/",className:"flex items-center gap-1.5 text-sm hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:r=>{r.preventDefault(),window.location.hash="/"},children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Dashboards"]}),e.jsx("div",{className:"w-px h-4 mx-1",style:{background:"var(--yc-color-border)"}}),e.jsx("button",{className:"p-1.5 rounded hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:()=>u(r=>!r),title:y?"Hide catalog":"Show catalog",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M9 3v18"})]})}),e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--yc-color-text)"},children:"Data Explorer"}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(q,{}),e.jsxs("button",{disabled:x.length===0||l,onClick:C,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-opacity disabled:opacity-40",style:{background:"var(--yc-color-primary)",color:"#fff"},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"})]}),"Build Dashboard"]}),i.length>0&&e.jsx("button",{className:"p-1.5 rounded hover:opacity-80",style:{color:"var(--yc-color-text-secondary)"},onClick:f,title:"New conversation",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 20h9"}),e.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4 flex flex-col gap-3 min-h-0",children:i.length===0?e.jsx(P,{summary:j??null,onPromptClick:w}):e.jsxs(e.Fragment,{children:[i.map((r,p)=>e.jsx(W,{message:r,isStreaming:l&&p===i.length-1&&r.role==="assistant",onSendMessage:d},p)),e.jsx("div",{ref:c})]})}),e.jsx("div",{className:"px-6 py-3 flex-shrink-0",style:{borderTop:"1px solid var(--yc-color-border)"},children:e.jsx($,{onSend:N,placeholder:"Ask about your data...",disabled:l,initialValue:s})})]})]})}export{V as default};
@@ -1 +1 @@
1
- import{u,j as e,A as p}from"./index-lklRbe2I.js";import{a as r}from"./echarts-DtOYsfLX.js";const f="",g={google:"Google",microsoft:"Microsoft",oidc:"SSO"};function j(){const m=u(o=>o.login),l=u(o=>o.providers),[a,x]=r.useState(""),[t,b]=r.useState(""),[c,s]=r.useState(""),[n,d]=r.useState(!1);r.useEffect(()=>{window.location.hash.includes("error=account_conflict")&&(s("An account with this email already exists. Please sign in with your password."),window.location.hash="#/")},[]);const y=async o=>{o.preventDefault(),s(""),d(!0);try{await m(a,t)}catch(i){i instanceof p?s(i.message):s("An unexpected error occurred")}finally{d(!1)}},h=o=>{window.location.href=`${f}/api/auth/sso/${o}`};return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"var(--yc-color-background)"},children:e.jsxs("div",{className:"rounded-lg shadow-sm p-8 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("h1",{className:"text-2xl font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Sign in to Yamchart"}),e.jsx("p",{className:"text-sm mb-6",style:{color:"var(--yc-color-text-secondary)"},children:"Enter your credentials to access dashboards."}),c&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:c}),l.length>0&&e.jsxs("div",{className:"space-y-2 mb-6",children:[l.map(o=>e.jsxs("button",{onClick:()=>h(o),className:"w-full py-2 px-4 text-sm font-medium rounded-md hover:bg-black/5",style:{border:"1px solid var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:["Sign in with ",g[o]??o]},o)),e.jsxs("div",{className:"relative my-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t",style:{borderColor:"var(--yc-color-border)"}})}),e.jsx("div",{className:"relative flex justify-center text-xs",style:{color:"var(--yc-color-text-muted)"},children:e.jsx("span",{className:"px-2",style:{backgroundColor:"var(--yc-color-surface)"},children:"or"})})]})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{id:"email",type:"email",value:a,onChange:o=>x(o.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"you@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Password"}),e.jsx("input",{id:"password",type:"password",value:t,onChange:o=>b(o.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Password"})]}),e.jsx("button",{type:"submit",disabled:n,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:n?"Signing in...":"Sign in"})]})]})})}export{j as LoginPage};
1
+ import{u,j as e,A as p}from"./index-BgzSjgIu.js";import{a as r}from"./echarts-DtOYsfLX.js";const f="",g={google:"Google",microsoft:"Microsoft",oidc:"SSO"};function j(){const m=u(o=>o.login),l=u(o=>o.providers),[a,x]=r.useState(""),[t,b]=r.useState(""),[c,s]=r.useState(""),[n,d]=r.useState(!1);r.useEffect(()=>{window.location.hash.includes("error=account_conflict")&&(s("An account with this email already exists. Please sign in with your password."),window.location.hash="#/")},[]);const y=async o=>{o.preventDefault(),s(""),d(!0);try{await m(a,t)}catch(i){i instanceof p?s(i.message):s("An unexpected error occurred")}finally{d(!1)}},h=o=>{window.location.href=`${f}/api/auth/sso/${o}`};return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"var(--yc-color-background)"},children:e.jsxs("div",{className:"rounded-lg shadow-sm p-8 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("h1",{className:"text-2xl font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Sign in to Yamchart"}),e.jsx("p",{className:"text-sm mb-6",style:{color:"var(--yc-color-text-secondary)"},children:"Enter your credentials to access dashboards."}),c&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:c}),l.length>0&&e.jsxs("div",{className:"space-y-2 mb-6",children:[l.map(o=>e.jsxs("button",{onClick:()=>h(o),className:"w-full py-2 px-4 text-sm font-medium rounded-md hover:bg-black/5",style:{border:"1px solid var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:["Sign in with ",g[o]??o]},o)),e.jsxs("div",{className:"relative my-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t",style:{borderColor:"var(--yc-color-border)"}})}),e.jsx("div",{className:"relative flex justify-center text-xs",style:{color:"var(--yc-color-text-muted)"},children:e.jsx("span",{className:"px-2",style:{backgroundColor:"var(--yc-color-surface)"},children:"or"})})]})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{id:"email",type:"email",value:a,onChange:o=>x(o.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"you@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Password"}),e.jsx("input",{id:"password",type:"password",value:t,onChange:o=>b(o.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Password"})]}),e.jsx("button",{type:"submit",disabled:n,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:n?"Signing in...":"Sign in"})]})]})})}export{j as LoginPage};
@@ -1 +1 @@
1
- import{j as e,c as ee,b as re,d as te,e as se,f as ae,g as K,h as le,a as R,F as oe,S as ce,i as ne,C as ie,D as de,k as he,T as xe,G as ue,W as me,l as ye,m as fe,H as ve,n as ge,o as je,p as pe,P as be,q as Ce,B as we,L as ke,r as Ne,s as De}from"./index-lklRbe2I.js";import{a as m}from"./echarts-DtOYsfLX.js";function Fe({title:s,description:l,loading:r=!1,error:i=null,cached:t,durationMs:c,hasDrillDown:N,onRefresh:a,children:v}){return e.jsxs("div",{className:"chart-container",children:[e.jsxs("div",{className:"flex items-start justify-between p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--yc-color-text)"},children:s}),N&&e.jsxs("svg",{className:"w-4 h-4 flex-shrink-0",style:{color:"var(--yc-color-text-muted)"},viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[e.jsx("title",{children:"Right-click to drill down"}),e.jsx("path",{fillRule:"evenodd",d:"M5.22 14.78a.75.75 0 001.06 0l7.22-7.22v5.69a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75h-7.5a.75.75 0 000 1.5h5.69l-7.22 7.22a.75.75 0 000 1.06z",clipRule:"evenodd"})]})]}),l&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--yc-color-text-secondary)"},children:l})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t!==void 0&&e.jsx("span",{className:"text-xs px-2 py-1 rounded",style:t?{backgroundColor:"color-mix(in srgb, var(--yc-color-success) 15%, transparent)",color:"var(--yc-color-success)"}:{backgroundColor:"color-mix(in srgb, var(--yc-color-primary) 15%, transparent)",color:"var(--yc-color-primary)"},children:t?"Cached":"Fresh"}),c!==void 0&&e.jsxs("span",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:[c,"ms"]}),a&&e.jsx("button",{onClick:a,disabled:r,className:"p-1.5 hover:bg-black/5 rounded transition-colors disabled:opacity-50",style:{color:"var(--yc-color-text-muted)"},title:"Refresh",children:e.jsx("svg",{className:ee("w-4 h-4",r&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]})]}),e.jsx("div",{className:"p-4",children:i?e.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--yc-color-danger)"},children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium",children:"Failed to load chart"}),e.jsx("p",{className:"text-sm mt-1",children:i.message})]})}):v})]})}const Le={day:{label:"Date",format:"%b %d, %Y"},week:{label:"Week Starting",format:"%b %d"},month:{label:"Month",format:"%b '%y"},quarter:{label:"Quarter",format:"quarter"},year:{label:"Year",format:"%Y"}};function Se({chartName:s}){const[l,r]=m.useState(!1),i=async()=>{const t=`{{${s}}}`;try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch(c){console.error("Failed to copy:",c)}};return e.jsx("button",{onClick:i,className:"text-sm flex items-center gap-1.5 px-2 py-1 rounded hover:bg-black/5 transition-colors",style:{color:"var(--yc-color-text-secondary)"},title:`Copy {{${s}}} for use in markdown widgets`,children:l?e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",style:{color:"var(--yc-color-success)"},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{style:{color:"var(--yc-color-success)"},children:"Copied!"})]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),e.jsx("span",{children:"Copy Reference"})]})})}function S(s,l){if(!l)return s.toLocaleString();const r=l.decimals??0;switch(l.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:l.currency||"USD",minimumFractionDigits:r,maximumFractionDigits:r}).format(s);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:r,maximumFractionDigits:r}).format(s/100);default:return s.toLocaleString(void 0,{minimumFractionDigits:r,maximumFractionDigits:r})}}function Ae(s,l){const r=s>=0?"+":"";return l==="percent_change"?`${r}${s.toFixed(1)}%`:`${r}${s.toLocaleString()}`}function Me({data:s,config:l,title:r,comparison:i}){var w,k,L;if(!(s!=null&&s[0])||!((w=l.value)!=null&&w.field))return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-muted)"},children:"No data available"});const t=s[0],c=t[l.value.field],N=S(c,l.format);let a=null,v="percent_change",g,D,p;if(i)a=i.change,v=i.changeType,g=i.currentPeriodLabel,D=i.previousPeriodLabel,p=S(i.previousValue,l.format);else if((k=l.comparison)!=null&&k.enabled&&l.comparison.field){const h=t[l.comparison.field];v=l.comparison.type,h&&h!==0&&(v==="percent_change"?a=(c-h)/h*100:a=c-h,p=S(h,l.format))}const y=l.goal,b=y&&y.value!==0?Math.max(0,Math.min(c/y.value*100,100)):null,F=y?c>=y.value?"var(--yc-color-success)":"var(--yc-color-danger)":void 0;return e.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[e.jsxs("div",{className:"text-6xl font-bold tabular-nums",style:{color:"var(--yc-color-text)"},children:[N,l.unit&&e.jsx("span",{className:"text-3xl font-normal ml-2",style:{color:"var(--yc-color-text-muted)"},children:l.unit})]}),g&&e.jsx("div",{className:"text-sm mt-2",style:{color:"var(--yc-color-text-muted)"},children:g}),r&&e.jsx("div",{className:"text-lg mt-3",style:{color:"var(--yc-color-text-secondary)"},children:r}),a!==null&&e.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg font-medium px-3 py-1 rounded",style:a>=0?{backgroundColor:"color-mix(in srgb, var(--yc-color-success) 15%, transparent)",color:"var(--yc-color-success)"}:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 15%, transparent)",color:"var(--yc-color-danger)"},children:Ae(a,v)}),p&&e.jsxs("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:["vs ",p]}),!p&&((L=l.comparison)==null?void 0:L.label)&&e.jsx("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:l.comparison.label})]}),D&&e.jsx("div",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:D})]}),y&&b!==null&&e.jsxs("div",{className:"mt-4 w-full max-w-[280px]",children:[y.show_progress&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",style:{color:"var(--yc-color-text-muted)"},children:[e.jsxs("span",{children:[S(c,l.format)," / ",S(y.value,l.format)]}),e.jsxs("span",{children:[b.toFixed(0),"%"]})]}),e.jsx("div",{className:"w-full h-2 rounded-full",style:{backgroundColor:"var(--yc-color-surface-hover)"},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${b}%`,backgroundColor:F}})})]}),y.label&&e.jsx("div",{className:"text-sm mt-1 text-center",style:{color:"var(--yc-color-text-muted)"},children:y.label})]})]})}function _e({chartName:s,drillParams:l}){var O,P,W,U,H,I,q,z;const{data:r,isLoading:i}=re(s),{data:t,isLoading:c,error:N}=te(s),{data:a}=se(),v=ae(),g=K(o=>o.getEffectiveFilters),D=K(o=>o.setChartFilter),p=le(),y=i||c,b=l==null?void 0:l._from,F=l?Object.fromEntries(Object.entries(l).filter(([o])=>!o.startsWith("_"))):{},w=Object.keys(F).length>0,k=Object.entries(F).map(([o,u])=>`${o}: ${u}`).join(", ");m.useEffect(()=>{if(w)for(const[o,u]of Object.entries(F))D(s,o,u)},[s,w]);const L=((O=t==null?void 0:t.meta)==null?void 0:O.serverPaginated)===!0,[h,A]=m.useState(null),M=m.useRef(!0);m.useEffect(()=>{A(null),M.current=!0},[(P=t==null?void 0:t.meta)==null?void 0:P.cacheKey]);const Y=m.useCallback(async(o,u,n,j)=>{if(M.current&&o===0&&!n){M.current=!1;return}M.current=!1,A(d=>({rows:(d==null?void 0:d.rows)??[],page:o,loading:!0}));try{const d=g(s),$={...Object.fromEntries(Object.entries(d).filter(([Ee,G])=>G!=null&&G!=="")),_server_paginated:!0,_page:o,_page_size:u,...n?{_sort_field:n,_sort_dir:j??"asc"}:{}},T=await R.queryChart(s,$);A({rows:T.rows,summaryValues:T.summaryValues,page:o,loading:!1})}catch{A(d=>d?{...d,loading:!1}:null)}},[s,g]),X=m.useMemo(()=>{var n;if(!t||((n=r==null?void 0:r.chart)==null?void 0:n.type)!=="table")return;const o=g(s),u=Object.fromEntries(Object.entries(o).filter(([j,d])=>d!=null&&d!==""));return R.getExportUrl(s,u)},[t,r,s,g]),[x,_]=m.useState(null),C=m.useCallback((o,u,n)=>{_({x:n.x,y:n.y,field:o,value:u})},[]),Q=m.useCallback(()=>{var j,d;if(!x||!((j=r==null?void 0:r.drillDown)!=null&&j.model))return;const o=r.drillDown,u=o.fields?typeof o.fields=="string"?o.fields:o.fields[0]:o.field??((d=r.chart.x)==null?void 0:d.field)??x.field,n=new URLSearchParams;if(x.allFields)for(const[$,T]of Object.entries(x.allFields))n.set($,T);else n.set(u,x.value);n.set("_from",s),window.location.hash=`/charts/${s}/detail?${n.toString()}`,_(null)},[x,r,s]),J=m.useCallback(()=>{var j,d;if(!x||!((j=r==null?void 0:r.drillDown)!=null&&j.chart))return;const o=r.drillDown,u=o.fields?typeof o.fields=="string"?o.fields:o.fields[0]:o.field??((d=r.chart.x)==null?void 0:d.field)??x.field,n=new URLSearchParams({[u]:x.value,_from:s});window.location.hash=`/charts/${r.drillDown.chart}?${n.toString()}`,_(null)},[x,r,s]),B=g(s).granularity,f=B?Le[B]:void 0,V=f==null?void 0:f.label,E=f==null?void 0:f.format;if(i)return e.jsxs("div",{className:"chart-container animate-pulse",children:[e.jsx("div",{className:"p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:e.jsx("div",{className:"h-6 rounded w-48",style:{backgroundColor:"var(--yc-color-surface-hover)"}})}),e.jsx("div",{className:"p-4",children:e.jsx("div",{className:"h-80 rounded",style:{backgroundColor:"var(--yc-color-surface-hover)"}})})]});if(!r)return e.jsxs("div",{className:"chart-container p-8 text-center",style:{color:"var(--yc-color-text-secondary)"},children:["Chart not found: ",s]});const Z=()=>{var u;if(!t)return e.jsx("div",{className:"h-80 rounded animate-pulse",style:{backgroundColor:"var(--yc-color-surface-hover)"}});const o=r.chart.type;switch(o){case"line":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(ke,{data:t.rows,columns:t.columns,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"bar":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(we,{data:t.rows,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"area":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(Ce,{data:t.rows,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"pie":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing pie chart configuration"}):e.jsx(be,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"donut":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing donut chart configuration"}):e.jsx(pe,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,centerValue:r.chart.centerValue,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"scatter":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):e.jsx(je,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"combo":if(!r.chart.x)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(ge,{data:t.rows,xAxis:n,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"kpi":return e.jsx(Me,{data:t.rows,config:r.chart,title:r.title,comparison:t.comparison});case"heatmap":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):e.jsx(ve,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"funnel":return e.jsx(fe,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"sankey":return e.jsx(ye,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"waterfall":return e.jsx(me,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"gauge":return e.jsx(ue,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"table":return e.jsx(xe,{data:(h==null?void 0:h.rows)??t.rows,columns:t.columns,chartConfig:r.chart,height:"100%",loading:c||((h==null?void 0:h.loading)??!1),serverPaginated:L,totalCount:(u=t.meta)==null?void 0:u.totalCount,serverSummaryValues:(h==null?void 0:h.summaryValues)??t.summaryValues,onServerPageChange:L?Y:void 0,exportUrl:X});default:return e.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',o,'" not yet implemented']})}};return e.jsxs("div",{className:"space-y-4",children:[b&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:[e.jsx("button",{onClick:()=>{window.location.hash=`/charts/${b}`},className:"transition-colors hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:b}),e.jsx("span",{children:"/"}),e.jsx("span",{className:"font-medium",style:{color:"var(--yc-color-text)"},children:r.title}),k&&e.jsxs("span",{style:{color:"var(--yc-color-text-muted)"},children:["(",k,")"]})]}),e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[r.parameters.length>0?e.jsx(oe,{parameters:r.parameters,chartName:s}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{chartName:s}),e.jsx(ce,{resourceType:"chart",resourceName:s}),p&&e.jsxs("button",{onClick:()=>ne.getState().openPanel({type:"chart",name:s}),className:"text-sm flex items-center gap-1 px-2 py-1 rounded hover:bg-black/5 transition-colors",style:{color:"var(--yc-color-text-secondary)"},title:"Ask AI about this chart",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),"Ask AI"]})]})]}),e.jsx(Fe,{title:r.title,description:r.description,loading:y,cached:t==null?void 0:t.meta.cached,durationMs:t==null?void 0:t.meta.durationMs,hasDrillDown:!!((W=r.drillDown)!=null&&W.chart),onRefresh:()=>v(s),children:e.jsx(ie,{isLoading:c,error:N,data:t==null?void 0:t.rows,onRetry:()=>v(s),children:Z()})}),w&&t&&e.jsx(de,{data:t.rows,columns:t.columns,drillDownColumns:(U=r.drillDown)==null?void 0:U.columns,filterDisplay:k,chartName:s}),x&&e.jsx(he,{x:x.x,y:x.y,field:x.field,value:x.value,allFields:x.allFields,onViewDetails:(H=r.drillDown)!=null&&H.model?Q:void 0,onGoToChart:(I=r.drillDown)!=null&&I.chart?J:void 0,detailModel:(q=r.drillDown)==null?void 0:q.model,targetChart:(z=r.drillDown)==null?void 0:z.chart,onClose:()=>_(null)})]})}function Re({parsed:s}){const l=s.params.token,[r,i]=m.useState(null),[t,c]=m.useState(!1);return m.useEffect(()=>{if(!l){i("No share token provided");return}R.getPublicConfig(l).then(()=>c(!0)).catch(()=>i("This link has expired or been revoked"))},[l]),r?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsx("div",{className:"text-center",children:e.jsx("div",{className:"text-gray-400 text-lg",children:r})})}):t?e.jsx(Ne,{value:l??null,children:e.jsxs("div",{className:"min-h-screen",style:{backgroundColor:"var(--yc-color-bg, #f9fafb)"},children:[s.type==="public_chart"?e.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:e.jsx(_e,{chartName:s.name})}):e.jsx(De,{dashboardId:s.name,initialTab:s.params.tab}),e.jsx("div",{className:"text-center py-4 text-xs",style:{color:"var(--yc-color-text-muted, #9ca3af)"},children:"Shared via yamchart"})]})}):e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{Re as PublicViewer};
1
+ import{j as e,c as ee,b as re,d as te,e as se,f as ae,g as K,h as le,a as R,F as oe,S as ce,i as ne,C as ie,D as de,k as he,T as xe,G as ue,W as me,l as ye,m as fe,H as ve,n as ge,o as je,p as pe,P as be,q as Ce,B as we,L as ke,r as Ne,s as De}from"./index-BgzSjgIu.js";import{a as m}from"./echarts-DtOYsfLX.js";function Fe({title:s,description:l,loading:r=!1,error:i=null,cached:t,durationMs:c,hasDrillDown:N,onRefresh:a,children:v}){return e.jsxs("div",{className:"chart-container",children:[e.jsxs("div",{className:"flex items-start justify-between p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--yc-color-text)"},children:s}),N&&e.jsxs("svg",{className:"w-4 h-4 flex-shrink-0",style:{color:"var(--yc-color-text-muted)"},viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[e.jsx("title",{children:"Right-click to drill down"}),e.jsx("path",{fillRule:"evenodd",d:"M5.22 14.78a.75.75 0 001.06 0l7.22-7.22v5.69a.75.75 0 001.5 0v-7.5a.75.75 0 00-.75-.75h-7.5a.75.75 0 000 1.5h5.69l-7.22 7.22a.75.75 0 000 1.06z",clipRule:"evenodd"})]})]}),l&&e.jsx("p",{className:"text-sm mt-1",style:{color:"var(--yc-color-text-secondary)"},children:l})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t!==void 0&&e.jsx("span",{className:"text-xs px-2 py-1 rounded",style:t?{backgroundColor:"color-mix(in srgb, var(--yc-color-success) 15%, transparent)",color:"var(--yc-color-success)"}:{backgroundColor:"color-mix(in srgb, var(--yc-color-primary) 15%, transparent)",color:"var(--yc-color-primary)"},children:t?"Cached":"Fresh"}),c!==void 0&&e.jsxs("span",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:[c,"ms"]}),a&&e.jsx("button",{onClick:a,disabled:r,className:"p-1.5 hover:bg-black/5 rounded transition-colors disabled:opacity-50",style:{color:"var(--yc-color-text-muted)"},title:"Refresh",children:e.jsx("svg",{className:ee("w-4 h-4",r&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]})]}),e.jsx("div",{className:"p-4",children:i?e.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--yc-color-danger)"},children:e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"font-medium",children:"Failed to load chart"}),e.jsx("p",{className:"text-sm mt-1",children:i.message})]})}):v})]})}const Le={day:{label:"Date",format:"%b %d, %Y"},week:{label:"Week Starting",format:"%b %d"},month:{label:"Month",format:"%b '%y"},quarter:{label:"Quarter",format:"quarter"},year:{label:"Year",format:"%Y"}};function Se({chartName:s}){const[l,r]=m.useState(!1),i=async()=>{const t=`{{${s}}}`;try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),2e3)}catch(c){console.error("Failed to copy:",c)}};return e.jsx("button",{onClick:i,className:"text-sm flex items-center gap-1.5 px-2 py-1 rounded hover:bg-black/5 transition-colors",style:{color:"var(--yc-color-text-secondary)"},title:`Copy {{${s}}} for use in markdown widgets`,children:l?e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",style:{color:"var(--yc-color-success)"},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("span",{style:{color:"var(--yc-color-success)"},children:"Copied!"})]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})}),e.jsx("span",{children:"Copy Reference"})]})})}function S(s,l){if(!l)return s.toLocaleString();const r=l.decimals??0;switch(l.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:l.currency||"USD",minimumFractionDigits:r,maximumFractionDigits:r}).format(s);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:r,maximumFractionDigits:r}).format(s/100);default:return s.toLocaleString(void 0,{minimumFractionDigits:r,maximumFractionDigits:r})}}function Ae(s,l){const r=s>=0?"+":"";return l==="percent_change"?`${r}${s.toFixed(1)}%`:`${r}${s.toLocaleString()}`}function Me({data:s,config:l,title:r,comparison:i}){var w,k,L;if(!(s!=null&&s[0])||!((w=l.value)!=null&&w.field))return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-muted)"},children:"No data available"});const t=s[0],c=t[l.value.field],N=S(c,l.format);let a=null,v="percent_change",g,D,p;if(i)a=i.change,v=i.changeType,g=i.currentPeriodLabel,D=i.previousPeriodLabel,p=S(i.previousValue,l.format);else if((k=l.comparison)!=null&&k.enabled&&l.comparison.field){const h=t[l.comparison.field];v=l.comparison.type,h&&h!==0&&(v==="percent_change"?a=(c-h)/h*100:a=c-h,p=S(h,l.format))}const y=l.goal,b=y&&y.value!==0?Math.max(0,Math.min(c/y.value*100,100)):null,F=y?c>=y.value?"var(--yc-color-success)":"var(--yc-color-danger)":void 0;return e.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[e.jsxs("div",{className:"text-6xl font-bold tabular-nums",style:{color:"var(--yc-color-text)"},children:[N,l.unit&&e.jsx("span",{className:"text-3xl font-normal ml-2",style:{color:"var(--yc-color-text-muted)"},children:l.unit})]}),g&&e.jsx("div",{className:"text-sm mt-2",style:{color:"var(--yc-color-text-muted)"},children:g}),r&&e.jsx("div",{className:"text-lg mt-3",style:{color:"var(--yc-color-text-secondary)"},children:r}),a!==null&&e.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg font-medium px-3 py-1 rounded",style:a>=0?{backgroundColor:"color-mix(in srgb, var(--yc-color-success) 15%, transparent)",color:"var(--yc-color-success)"}:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 15%, transparent)",color:"var(--yc-color-danger)"},children:Ae(a,v)}),p&&e.jsxs("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:["vs ",p]}),!p&&((L=l.comparison)==null?void 0:L.label)&&e.jsx("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:l.comparison.label})]}),D&&e.jsx("div",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:D})]}),y&&b!==null&&e.jsxs("div",{className:"mt-4 w-full max-w-[280px]",children:[y.show_progress&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",style:{color:"var(--yc-color-text-muted)"},children:[e.jsxs("span",{children:[S(c,l.format)," / ",S(y.value,l.format)]}),e.jsxs("span",{children:[b.toFixed(0),"%"]})]}),e.jsx("div",{className:"w-full h-2 rounded-full",style:{backgroundColor:"var(--yc-color-surface-hover)"},children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${b}%`,backgroundColor:F}})})]}),y.label&&e.jsx("div",{className:"text-sm mt-1 text-center",style:{color:"var(--yc-color-text-muted)"},children:y.label})]})]})}function _e({chartName:s,drillParams:l}){var O,P,W,U,H,I,q,z;const{data:r,isLoading:i}=re(s),{data:t,isLoading:c,error:N}=te(s),{data:a}=se(),v=ae(),g=K(o=>o.getEffectiveFilters),D=K(o=>o.setChartFilter),p=le(),y=i||c,b=l==null?void 0:l._from,F=l?Object.fromEntries(Object.entries(l).filter(([o])=>!o.startsWith("_"))):{},w=Object.keys(F).length>0,k=Object.entries(F).map(([o,u])=>`${o}: ${u}`).join(", ");m.useEffect(()=>{if(w)for(const[o,u]of Object.entries(F))D(s,o,u)},[s,w]);const L=((O=t==null?void 0:t.meta)==null?void 0:O.serverPaginated)===!0,[h,A]=m.useState(null),M=m.useRef(!0);m.useEffect(()=>{A(null),M.current=!0},[(P=t==null?void 0:t.meta)==null?void 0:P.cacheKey]);const Y=m.useCallback(async(o,u,n,j)=>{if(M.current&&o===0&&!n){M.current=!1;return}M.current=!1,A(d=>({rows:(d==null?void 0:d.rows)??[],page:o,loading:!0}));try{const d=g(s),$={...Object.fromEntries(Object.entries(d).filter(([Ee,G])=>G!=null&&G!=="")),_server_paginated:!0,_page:o,_page_size:u,...n?{_sort_field:n,_sort_dir:j??"asc"}:{}},T=await R.queryChart(s,$);A({rows:T.rows,summaryValues:T.summaryValues,page:o,loading:!1})}catch{A(d=>d?{...d,loading:!1}:null)}},[s,g]),X=m.useMemo(()=>{var n;if(!t||((n=r==null?void 0:r.chart)==null?void 0:n.type)!=="table")return;const o=g(s),u=Object.fromEntries(Object.entries(o).filter(([j,d])=>d!=null&&d!==""));return R.getExportUrl(s,u)},[t,r,s,g]),[x,_]=m.useState(null),C=m.useCallback((o,u,n)=>{_({x:n.x,y:n.y,field:o,value:u})},[]),Q=m.useCallback(()=>{var j,d;if(!x||!((j=r==null?void 0:r.drillDown)!=null&&j.model))return;const o=r.drillDown,u=o.fields?typeof o.fields=="string"?o.fields:o.fields[0]:o.field??((d=r.chart.x)==null?void 0:d.field)??x.field,n=new URLSearchParams;if(x.allFields)for(const[$,T]of Object.entries(x.allFields))n.set($,T);else n.set(u,x.value);n.set("_from",s),window.location.hash=`/charts/${s}/detail?${n.toString()}`,_(null)},[x,r,s]),J=m.useCallback(()=>{var j,d;if(!x||!((j=r==null?void 0:r.drillDown)!=null&&j.chart))return;const o=r.drillDown,u=o.fields?typeof o.fields=="string"?o.fields:o.fields[0]:o.field??((d=r.chart.x)==null?void 0:d.field)??x.field,n=new URLSearchParams({[u]:x.value,_from:s});window.location.hash=`/charts/${r.drillDown.chart}?${n.toString()}`,_(null)},[x,r,s]),B=g(s).granularity,f=B?Le[B]:void 0,V=f==null?void 0:f.label,E=f==null?void 0:f.format;if(i)return e.jsxs("div",{className:"chart-container animate-pulse",children:[e.jsx("div",{className:"p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:e.jsx("div",{className:"h-6 rounded w-48",style:{backgroundColor:"var(--yc-color-surface-hover)"}})}),e.jsx("div",{className:"p-4",children:e.jsx("div",{className:"h-80 rounded",style:{backgroundColor:"var(--yc-color-surface-hover)"}})})]});if(!r)return e.jsxs("div",{className:"chart-container p-8 text-center",style:{color:"var(--yc-color-text-secondary)"},children:["Chart not found: ",s]});const Z=()=>{var u;if(!t)return e.jsx("div",{className:"h-80 rounded animate-pulse",style:{backgroundColor:"var(--yc-color-surface-hover)"}});const o=r.chart.type;switch(o){case"line":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(ke,{data:t.rows,columns:t.columns,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"bar":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(we,{data:t.rows,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"area":if(!r.chart.x||!r.chart.y&&!r.chart.series)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(Ce,{data:t.rows,xAxis:n,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"pie":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing pie chart configuration"}):e.jsx(be,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"donut":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing donut chart configuration"}):e.jsx(pe,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,centerValue:r.chart.centerValue,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"scatter":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):e.jsx(je,{data:t.rows,xAxis:r.chart.x,yAxis:r.chart.y,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"combo":if(!r.chart.x)return e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const n=f?{...r.chart.x,label:V,format:E}:r.chart.x;return e.jsx(ge,{data:t.rows,xAxis:n,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C,goalData:t.goalData,compareData:t.compareData})}case"kpi":return e.jsx(Me,{data:t.rows,config:r.chart,title:r.title,comparison:t.comparison});case"heatmap":return!r.chart.x||!r.chart.y?e.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):e.jsx(ve,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"funnel":return e.jsx(fe,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"sankey":return e.jsx(ye,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c,onChartClick:C});case"waterfall":return e.jsx(me,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"gauge":return e.jsx(ue,{data:t.rows,chartConfig:r.chart,theme:a==null?void 0:a.theme,loading:c});case"table":return e.jsx(xe,{data:(h==null?void 0:h.rows)??t.rows,columns:t.columns,chartConfig:r.chart,height:"100%",loading:c||((h==null?void 0:h.loading)??!1),serverPaginated:L,totalCount:(u=t.meta)==null?void 0:u.totalCount,serverSummaryValues:(h==null?void 0:h.summaryValues)??t.summaryValues,onServerPageChange:L?Y:void 0,exportUrl:X});default:return e.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',o,'" not yet implemented']})}};return e.jsxs("div",{className:"space-y-4",children:[b&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:[e.jsx("button",{onClick:()=>{window.location.hash=`/charts/${b}`},className:"transition-colors hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:b}),e.jsx("span",{children:"/"}),e.jsx("span",{className:"font-medium",style:{color:"var(--yc-color-text)"},children:r.title}),k&&e.jsxs("span",{style:{color:"var(--yc-color-text-muted)"},children:["(",k,")"]})]}),e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[r.parameters.length>0?e.jsx(oe,{parameters:r.parameters,chartName:s}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Se,{chartName:s}),e.jsx(ce,{resourceType:"chart",resourceName:s}),p&&e.jsxs("button",{onClick:()=>ne.getState().openPanel({type:"chart",name:s}),className:"text-sm flex items-center gap-1 px-2 py-1 rounded hover:bg-black/5 transition-colors",style:{color:"var(--yc-color-text-secondary)"},title:"Ask AI about this chart",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),"Ask AI"]})]})]}),e.jsx(Fe,{title:r.title,description:r.description,loading:y,cached:t==null?void 0:t.meta.cached,durationMs:t==null?void 0:t.meta.durationMs,hasDrillDown:!!((W=r.drillDown)!=null&&W.chart),onRefresh:()=>v(s),children:e.jsx(ie,{isLoading:c,error:N,data:t==null?void 0:t.rows,onRetry:()=>v(s),children:Z()})}),w&&t&&e.jsx(de,{data:t.rows,columns:t.columns,drillDownColumns:(U=r.drillDown)==null?void 0:U.columns,filterDisplay:k,chartName:s}),x&&e.jsx(he,{x:x.x,y:x.y,field:x.field,value:x.value,allFields:x.allFields,onViewDetails:(H=r.drillDown)!=null&&H.model?Q:void 0,onGoToChart:(I=r.drillDown)!=null&&I.chart?J:void 0,detailModel:(q=r.drillDown)==null?void 0:q.model,targetChart:(z=r.drillDown)==null?void 0:z.chart,onClose:()=>_(null)})]})}function Re({parsed:s}){const l=s.params.token,[r,i]=m.useState(null),[t,c]=m.useState(!1);return m.useEffect(()=>{if(!l){i("No share token provided");return}R.getPublicConfig(l).then(()=>c(!0)).catch(()=>i("This link has expired or been revoked"))},[l]),r?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsx("div",{className:"text-center",children:e.jsx("div",{className:"text-gray-400 text-lg",children:r})})}):t?e.jsx(Ne,{value:l??null,children:e.jsxs("div",{className:"min-h-screen",style:{backgroundColor:"var(--yc-color-bg, #f9fafb)"},children:[s.type==="public_chart"?e.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:e.jsx(_e,{chartName:s.name})}):e.jsx(De,{dashboardId:s.name,initialTab:s.params.tab}),e.jsx("div",{className:"text-center py-4 text-xs",style:{color:"var(--yc-color-text-muted, #9ca3af)"},children:"Shared via yamchart"})]})}):e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:e.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{Re as PublicViewer};
@@ -1 +1 @@
1
- import{u as g,j as e,A as h}from"./index-lklRbe2I.js";import{a as o}from"./echarts-DtOYsfLX.js";function j(){const m=g(r=>r.setup),[a,b]=o.useState(""),[l,x]=o.useState(""),[t,p]=o.useState(""),[c,y]=o.useState(""),[n,s]=o.useState(""),[d,u]=o.useState(!1),f=async r=>{if(r.preventDefault(),s(""),t!==c){s("Passwords do not match");return}if(t.length<8){s("Password must be at least 8 characters");return}u(!0);try{await m(a,l,t)}catch(i){i instanceof h?s(i.message):s("An unexpected error occurred")}finally{u(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"var(--yc-color-background)"},children:e.jsxs("div",{className:"rounded-lg shadow-sm p-8 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("h1",{className:"text-2xl font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Welcome to Yamchart"}),e.jsx("p",{className:"text-sm mb-6",style:{color:"var(--yc-color-text-secondary)"},children:"Create your admin account to get started."}),n&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:n}),e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"name",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Name"}),e.jsx("input",{id:"name",type:"text",value:l,onChange:r=>x(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Your Name"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-email",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{id:"setup-email",type:"email",value:a,onChange:r=>b(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"admin@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Password"}),e.jsx("input",{id:"setup-password",type:"password",value:t,onChange:r=>p(r.target.value),required:!0,minLength:8,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"At least 8 characters"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Confirm Password"}),e.jsx("input",{id:"confirm-password",type:"password",value:c,onChange:r=>y(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Confirm password"})]}),e.jsx("button",{type:"submit",disabled:d,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:d?"Creating account...":"Create Admin Account"})]})]})})}export{j as SetupWizard};
1
+ import{u as g,j as e,A as h}from"./index-BgzSjgIu.js";import{a as o}from"./echarts-DtOYsfLX.js";function j(){const m=g(r=>r.setup),[a,b]=o.useState(""),[l,x]=o.useState(""),[t,p]=o.useState(""),[c,y]=o.useState(""),[n,s]=o.useState(""),[d,u]=o.useState(!1),f=async r=>{if(r.preventDefault(),s(""),t!==c){s("Passwords do not match");return}if(t.length<8){s("Password must be at least 8 characters");return}u(!0);try{await m(a,l,t)}catch(i){i instanceof h?s(i.message):s("An unexpected error occurred")}finally{u(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center",style:{backgroundColor:"var(--yc-color-background)"},children:e.jsxs("div",{className:"rounded-lg shadow-sm p-8 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsx("h1",{className:"text-2xl font-semibold mb-2",style:{color:"var(--yc-color-text)"},children:"Welcome to Yamchart"}),e.jsx("p",{className:"text-sm mb-6",style:{color:"var(--yc-color-text-secondary)"},children:"Create your admin account to get started."}),n&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:n}),e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"name",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Name"}),e.jsx("input",{id:"name",type:"text",value:l,onChange:r=>x(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Your Name"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-email",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{id:"setup-email",type:"email",value:a,onChange:r=>b(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"admin@example.com"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"setup-password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Password"}),e.jsx("input",{id:"setup-password",type:"password",value:t,onChange:r=>p(r.target.value),required:!0,minLength:8,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"At least 8 characters"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Confirm Password"}),e.jsx("input",{id:"confirm-password",type:"password",value:c,onChange:r=>y(r.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},placeholder:"Confirm password"})]}),e.jsx("button",{type:"submit",disabled:d,className:"w-full py-2 px-4 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:d?"Creating account...":"Create Admin Account"})]})]})})}export{j as SetupWizard};
@@ -1 +1 @@
1
- import{j as e,a as c}from"./index-lklRbe2I.js";import{a as s}from"./echarts-DtOYsfLX.js";function h(){const[o,a]=s.useState([]),[l,d]=s.useState(!0),n=async()=>{try{const r=await c.listShareLinks();a(r.links)}catch(r){console.error("Failed to load share links:",r)}finally{d(!1)}};s.useEffect(()=>{n()},[]);const i=async r=>{try{await c.revokeShareLink(r),a(t=>t.filter(x=>x.id!==r))}catch(t){console.error("Failed to revoke share link:",t)}};return l?e.jsx("div",{className:"p-6",style:{color:"var(--yc-color-text-secondary)"},children:"Loading..."}):e.jsxs("div",{className:"p-6 max-w-4xl",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",style:{color:"var(--yc-color-text)"},children:"Shared Links"}),o.length===0?e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"No active share links."}):e.jsx("div",{className:"rounded-lg overflow-hidden",style:{border:"1px solid var(--yc-color-border)"},children:e.jsxs("table",{className:"w-full text-sm yc-table",children:[e.jsx("thead",{className:"border-b",style:{backgroundColor:"var(--yc-color-input-bg)",borderColor:"var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-3 py-2 font-medium w-10",style:{color:"var(--yc-color-text-muted)"},children:"#"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Resource"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Created"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Expires"}),e.jsx("th",{className:"px-4 py-2"})]})}),e.jsx("tbody",{children:o.map((r,t)=>e.jsxs("tr",{className:"border-b last:border-0",style:{borderColor:"var(--yc-color-border)"},children:[e.jsx("td",{className:"px-3 py-3 text-right yc-row-num w-10",children:t+1}),e.jsx("td",{className:"px-4 py-3 font-medium",style:{color:"var(--yc-color-text)"},children:r.resource_name}),e.jsx("td",{className:"px-4 py-3 capitalize",style:{color:"var(--yc-color-text-secondary)"},children:r.resource_type}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--yc-color-text-secondary)"},children:new Date(r.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--yc-color-text-secondary)"},children:r.expires_at?new Date(r.expires_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>i(r.id),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Revoke"})})]},r.id))})]})})]})}export{h as ShareManagement};
1
+ import{j as e,a as c}from"./index-BgzSjgIu.js";import{a as s}from"./echarts-DtOYsfLX.js";function h(){const[o,a]=s.useState([]),[l,d]=s.useState(!0),n=async()=>{try{const r=await c.listShareLinks();a(r.links)}catch(r){console.error("Failed to load share links:",r)}finally{d(!1)}};s.useEffect(()=>{n()},[]);const i=async r=>{try{await c.revokeShareLink(r),a(t=>t.filter(x=>x.id!==r))}catch(t){console.error("Failed to revoke share link:",t)}};return l?e.jsx("div",{className:"p-6",style:{color:"var(--yc-color-text-secondary)"},children:"Loading..."}):e.jsxs("div",{className:"p-6 max-w-4xl",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",style:{color:"var(--yc-color-text)"},children:"Shared Links"}),o.length===0?e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-secondary)"},children:"No active share links."}):e.jsx("div",{className:"rounded-lg overflow-hidden",style:{border:"1px solid var(--yc-color-border)"},children:e.jsxs("table",{className:"w-full text-sm yc-table",children:[e.jsx("thead",{className:"border-b",style:{backgroundColor:"var(--yc-color-input-bg)",borderColor:"var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-3 py-2 font-medium w-10",style:{color:"var(--yc-color-text-muted)"},children:"#"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Resource"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Type"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Created"}),e.jsx("th",{className:"text-left px-4 py-2 font-medium",children:"Expires"}),e.jsx("th",{className:"px-4 py-2"})]})}),e.jsx("tbody",{children:o.map((r,t)=>e.jsxs("tr",{className:"border-b last:border-0",style:{borderColor:"var(--yc-color-border)"},children:[e.jsx("td",{className:"px-3 py-3 text-right yc-row-num w-10",children:t+1}),e.jsx("td",{className:"px-4 py-3 font-medium",style:{color:"var(--yc-color-text)"},children:r.resource_name}),e.jsx("td",{className:"px-4 py-3 capitalize",style:{color:"var(--yc-color-text-secondary)"},children:r.resource_type}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--yc-color-text-secondary)"},children:new Date(r.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3",style:{color:"var(--yc-color-text-secondary)"},children:r.expires_at?new Date(r.expires_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>i(r.id),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Revoke"})})]},r.id))})]})})]})}export{h as ShareManagement};
@@ -1 +1 @@
1
- import{j as e,a as p,A as j}from"./index-lklRbe2I.js";import{a as s}from"./echarts-DtOYsfLX.js";function O(){var A;const[i,N]=s.useState([]),[b,C]=s.useState(!0),[h,v]=s.useState(!1),[x,w]=s.useState(""),[l,g]=s.useState(null),[u,c]=s.useState([]),[m,y]=s.useState(!1),d=async()=>{try{const{users:t}=await p.authListUsers();N(t)}catch{w("Failed to load users")}finally{C(!1)}};s.useEffect(()=>{d()},[]);const a=async(t,r)=>{try{await p.authUpdateUser(t,{role:r}),await d()}catch(o){alert(o instanceof j?o.message:"Failed to update role")}},f=async(t,r)=>{if(confirm(`Delete user "${r}"? This cannot be undone.`))try{await p.authDeleteUser(t),await d()}catch(o){alert(o instanceof j?o.message:"Failed to delete user")}},U=t=>{if(l===t.id)g(null),c([]);else{g(t.id);const r=JSON.parse(t.attributes||"{}");c(Object.entries(r).map(([o,n])=>({key:o,value:n})))}},k=(t,r,o)=>{c(n=>n.map((S,M)=>M===t?{...S,[r]:o}:S))},E=()=>{c(t=>[...t,{key:"",value:""}])},L=t=>{c(r=>r.filter((o,n)=>n!==t))},D=async()=>{if(l){y(!0);try{const t={};for(const{key:r,value:o}of u){const n=r.trim();n&&(t[n]=o)}await p.authUpdateUser(l,{attributes:t}),await d(),c(Object.entries(t).map(([r,o])=>({key:r,value:o})))}catch(t){alert(t instanceof j?t.message:"Failed to save attributes")}finally{y(!1)}}};return b?e.jsx("div",{className:"p-6",style:{color:"var(--yc-color-text-secondary)"},children:"Loading users..."}):e.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-xl font-semibold",style:{color:"var(--yc-color-text)"},children:"User Management"}),e.jsx("button",{onClick:()=>v(!0),className:"px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700",children:"Add User"})]}),x&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:x}),e.jsx("div",{className:"rounded-lg overflow-hidden",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:e.jsxs("table",{className:"w-full yc-table",children:[e.jsx("thead",{className:"border-b",style:{backgroundColor:"var(--yc-color-input-bg)",borderColor:"var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-3 text-right text-xs font-medium w-10",style:{color:"var(--yc-color-text-muted)"},children:"#"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Email"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Role"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Created"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",style:{borderColor:"var(--yc-color-border)"},children:i.map((t,r)=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"px-3 py-3 text-right text-sm yc-row-num w-10",children:r+1}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text)"},children:t.name}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:t.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("select",{value:t.role,onChange:o=>a(t.id,o.target.value),className:"text-sm border rounded px-2 py-1",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},children:[e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"viewer",children:"Viewer"})]})}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:new Date(t.created_at).toLocaleDateString()}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3",children:[e.jsx("button",{onClick:()=>U(t),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:l===t.id?"Hide Attrs":"Attrs"}),e.jsx("button",{onClick:()=>f(t.id,t.name),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Delete"})]})]},t.id))})]})}),l&&e.jsxs("div",{className:"mt-4 rounded-lg p-4",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium",style:{color:"var(--yc-color-text-secondary)"},children:["Attributes for ",(A=i.find(t=>t.id===l))==null?void 0:A.name]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:E,className:"px-3 py-1 text-xs font-medium rounded hover:opacity-80",style:{color:"var(--yc-color-primary)",border:"1px solid color-mix(in srgb, var(--yc-color-primary) 50%, transparent)"},children:"Add Attribute"}),e.jsx("button",{onClick:D,disabled:m,className:"px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded hover:bg-blue-700 disabled:opacity-50",children:m?"Saving...":"Save"})]})]}),u.length===0?e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:'No attributes. Click "Add Attribute" to define key-value pairs for row-level security.'}):e.jsx("div",{className:"space-y-2",children:u.map((t,r)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. department)",value:t.key,onChange:o=>k(r,"key",o.target.value),className:"flex-1 px-3 py-1.5 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}}),e.jsx("input",{type:"text",placeholder:"Value (e.g. Sales)",value:t.value,onChange:o=>k(r,"value",o.target.value),className:"flex-1 px-3 py-1.5 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}}),e.jsx("button",{onClick:()=>L(r),className:"p-1.5 hover:opacity-80",style:{color:"var(--yc-color-text-muted)"},title:"Remove attribute",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},r))})]}),h&&e.jsx(R,{onClose:()=>v(!1),onCreated:d})]})}function R({onClose:i,onCreated:N}){const[b,C]=s.useState(""),[h,v]=s.useState(""),[x,w]=s.useState(""),[l,g]=s.useState("viewer"),[u,c]=s.useState(""),[m,y]=s.useState(!1),d=async a=>{a.preventDefault(),c(""),y(!0);try{await p.authCreateUser({email:b,name:h,password:x,role:l}),N(),i()}catch(f){c(f instanceof j?f.message:"Failed to create user")}finally{y(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:i,children:e.jsxs("div",{className:"rounded-lg shadow-lg p-6 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)"},onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",style:{color:"var(--yc-color-text)"},children:"Add User"}),u&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:u}),e.jsxs("form",{onSubmit:d,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Name"}),e.jsx("input",{type:"text",value:h,onChange:a=>v(a.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{type:"email",value:b,onChange:a=>C(a.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Temporary Password"}),e.jsx("input",{type:"password",value:x,onChange:a=>w(a.target.value),required:!0,minLength:8,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Role"}),e.jsxs("select",{value:l,onChange:a=>g(a.target.value),className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},children:[e.jsx("option",{value:"viewer",children:"Viewer"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"admin",children:"Admin"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:i,className:"px-4 py-2 text-sm hover:bg-black/5 rounded-md",style:{color:"var(--yc-color-text-secondary)"},children:"Cancel"}),e.jsx("button",{type:"submit",disabled:m,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50",children:m?"Creating...":"Create User"})]})]})]})})}export{O as UserManagement};
1
+ import{j as e,a as p,A as j}from"./index-BgzSjgIu.js";import{a as s}from"./echarts-DtOYsfLX.js";function P(){var A;const[i,N]=s.useState([]),[b,C]=s.useState(!0),[v,h]=s.useState(!1),[x,w]=s.useState(""),[l,g]=s.useState(null),[u,c]=s.useState([]),[m,y]=s.useState(!1),d=async()=>{try{const{users:t}=await p.authListUsers();N(t)}catch{w("Failed to load users")}finally{C(!1)}};s.useEffect(()=>{d()},[]);const a=async(t,r)=>{try{await p.authUpdateUser(t,{role:r}),await d()}catch(o){alert(o instanceof j?o.message:"Failed to update role")}},f=async(t,r)=>{if(confirm(`Delete user "${r}"? This cannot be undone.`))try{await p.authDeleteUser(t),await d()}catch(o){alert(o instanceof j?o.message:"Failed to delete user")}},U=t=>{if(l===t.id)g(null),c([]);else{g(t.id);const r=JSON.parse(t.attributes||"{}");c(Object.entries(r).map(([o,n])=>({key:o,value:n})))}},k=(t,r,o)=>{c(n=>n.map((S,M)=>M===t?{...S,[r]:o}:S))},E=()=>{c(t=>[...t,{key:"",value:""}])},L=t=>{c(r=>r.filter((o,n)=>n!==t))},D=async()=>{if(l){y(!0);try{const t={};for(const{key:r,value:o}of u){const n=r.trim();n&&(t[n]=o)}await p.authUpdateUser(l,{attributes:t}),await d(),c(Object.entries(t).map(([r,o])=>({key:r,value:o})))}catch(t){alert(t instanceof j?t.message:"Failed to save attributes")}finally{y(!1)}}};return b?e.jsx("div",{className:"p-6",style:{color:"var(--yc-color-text-secondary)"},children:"Loading users..."}):e.jsxs("div",{className:"p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-xl font-semibold",style:{color:"var(--yc-color-text)"},children:"User Management"}),e.jsx("button",{onClick:()=>h(!0),className:"px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-md hover:bg-blue-700",children:"Add User"})]}),x&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:x}),e.jsx("div",{className:"rounded-lg overflow-hidden",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:e.jsxs("table",{className:"w-full yc-table",children:[e.jsx("thead",{className:"border-b",style:{backgroundColor:"var(--yc-color-input-bg)",borderColor:"var(--yc-color-border)",color:"var(--yc-color-text-secondary)"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-3 text-right text-xs font-medium w-10",style:{color:"var(--yc-color-text-muted)"},children:"#"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Name"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Email"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Role"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium uppercase",children:"Created"}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium uppercase",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y",style:{borderColor:"var(--yc-color-border)"},children:i.map((t,r)=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"px-3 py-3 text-right text-sm yc-row-num w-10",children:r+1}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text)"},children:t.name}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:t.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("select",{value:t.role,onChange:o=>a(t.id,o.target.value),className:"text-sm border rounded px-2 py-1",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},children:[e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"viewer",children:"Viewer"})]})}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:new Date(t.created_at).toLocaleDateString()}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3",children:[e.jsx("button",{onClick:()=>U(t),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:l===t.id?"Hide Attrs":"Attrs"}),e.jsx("button",{onClick:()=>f(t.id,t.name),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Delete"})]})]},t.id))})]})}),l&&e.jsxs("div",{className:"mt-4 rounded-lg p-4",style:{backgroundColor:"var(--yc-color-surface)",border:"1px solid var(--yc-color-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium",style:{color:"var(--yc-color-text-secondary)"},children:["Attributes for ",(A=i.find(t=>t.id===l))==null?void 0:A.name]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:E,className:"px-3 py-1 text-xs font-medium rounded hover:opacity-80",style:{color:"var(--yc-color-primary)",border:"1px solid color-mix(in srgb, var(--yc-color-primary) 50%, transparent)"},children:"Add Attribute"}),e.jsx("button",{onClick:D,disabled:m,className:"px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded hover:bg-blue-700 disabled:opacity-50",children:m?"Saving...":"Save"})]})]}),u.length===0?e.jsx("p",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:'No attributes. Click "Add Attribute" to define key-value pairs for row-level security.'}):e.jsx("div",{className:"space-y-2",children:u.map((t,r)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. department)",value:t.key,onChange:o=>k(r,"key",o.target.value),className:"flex-1 px-3 py-1.5 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}}),e.jsx("input",{type:"text",placeholder:"Value (e.g. Sales)",value:t.value,onChange:o=>k(r,"value",o.target.value),className:"flex-1 px-3 py-1.5 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}}),e.jsx("button",{onClick:()=>L(r),className:"p-1.5 hover:opacity-80",style:{color:"var(--yc-color-text-muted)"},title:"Remove attribute",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},r))})]}),v&&e.jsx(R,{onClose:()=>h(!1),onCreated:d})]})}function R({onClose:i,onCreated:N}){const[b,C]=s.useState(""),[v,h]=s.useState(""),[x,w]=s.useState(""),[l,g]=s.useState("viewer"),[u,c]=s.useState(""),[m,y]=s.useState(!1),d=async a=>{a.preventDefault(),c(""),y(!0);try{await p.authCreateUser({email:b,name:v,password:x,role:l}),N(),i()}catch(f){c(f instanceof j?f.message:"Failed to create user")}finally{y(!1)}};return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:i,children:e.jsxs("div",{className:"rounded-lg shadow-lg p-6 w-full max-w-md",style:{backgroundColor:"var(--yc-color-surface)"},onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",style:{color:"var(--yc-color-text)"},children:"Add User"}),u&&e.jsx("div",{className:"text-sm rounded-md px-4 py-3 mb-4",style:{backgroundColor:"color-mix(in srgb, var(--yc-color-danger) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--yc-color-danger) 30%, transparent)",color:"var(--yc-color-danger)"},children:u}),e.jsxs("form",{onSubmit:d,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Name"}),e.jsx("input",{type:"text",value:v,onChange:a=>h(a.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Email"}),e.jsx("input",{type:"email",value:b,onChange:a=>C(a.target.value),required:!0,className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:["Temporary Password ",e.jsx("span",{style:{color:"var(--yc-color-text-secondary)"},children:"(optional)"})]}),e.jsx("input",{type:"password",value:x,onChange:a=>w(a.target.value),minLength:8,placeholder:"Leave blank to invite via SSO",className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"}}),e.jsx("p",{className:"mt-1 text-xs",style:{color:"var(--yc-color-text-secondary)"},children:"Leave blank to invite an SSO user — they sign in with their provider, no password."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",style:{color:"var(--yc-color-text-secondary)"},children:"Role"}),e.jsxs("select",{value:l,onChange:a=>g(a.target.value),className:"w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",style:{backgroundColor:"var(--yc-color-input-bg)",color:"var(--yc-color-text)",borderColor:"var(--yc-color-border)"},children:[e.jsx("option",{value:"viewer",children:"Viewer"}),e.jsx("option",{value:"editor",children:"Editor"}),e.jsx("option",{value:"admin",children:"Admin"})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:i,className:"px-4 py-2 text-sm hover:bg-black/5 rounded-md",style:{color:"var(--yc-color-text-secondary)"},children:"Cancel"}),e.jsx("button",{type:"submit",disabled:m,className:"px-4 py-2 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50",children:m?"Creating...":"Create User"})]})]})]})})}export{P as UserManagement};