yamchart 0.5.0 → 0.5.1

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.
@@ -1 +1 @@
1
- import{u,j as e,A as p}from"./index-uxK7mlHt.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-Ds6UbsJz.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 r,c as P,b as U,d as I,e as Y,f as q,g as _,F as z,S as G,C as K,D as X,h as Q,T as J,G as Z,W as ee,i as re,H as te,k as se,l as ae,m as ce,P as le,n as oe,B as ne,L as ie,a as de,o as xe}from"./index-uxK7mlHt.js";import{a as y}from"./echarts-DtOYsfLX.js";function he({title:a,description:c,loading:e=!1,error:o=null,cached:s,durationMs:l,hasDrillDown:N,onRefresh:t,children:h}){return r.jsxs("div",{className:"chart-container",children:[r.jsxs("div",{className:"flex items-start justify-between p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--yc-color-text)"},children:a}),N&&r.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:[r.jsx("title",{children:"Right-click to drill down"}),r.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"})]})]}),c&&r.jsx("p",{className:"text-sm mt-1",style:{color:"var(--yc-color-text-secondary)"},children:c})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[s!==void 0&&r.jsx("span",{className:"text-xs px-2 py-1 rounded",style:s?{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:s?"Cached":"Fresh"}),l!==void 0&&r.jsxs("span",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:[l,"ms"]}),t&&r.jsx("button",{onClick:t,disabled:e,className:"p-1.5 hover:bg-black/5 rounded transition-colors disabled:opacity-50",style:{color:"var(--yc-color-text-muted)"},title:"Refresh",children:r.jsx("svg",{className:P("w-4 h-4",e&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.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"})})})]})]}),r.jsx("div",{className:"p-4",children:o?r.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--yc-color-danger)"},children:r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"font-medium",children:"Failed to load chart"}),r.jsx("p",{className:"text-sm mt-1",children:o.message})]})}):h})]})}const me={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 ue({chartName:a}){const[c,e]=y.useState(!1),o=async()=>{const s=`{{${a}}}`;try{await navigator.clipboard.writeText(s),e(!0),setTimeout(()=>e(!1),2e3)}catch(l){console.error("Failed to copy:",l)}};return r.jsx("button",{onClick:o,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 {{${a}}} for use in markdown widgets`,children:c?r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",style:{color:"var(--yc-color-success)"},children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),r.jsx("span",{style:{color:"var(--yc-color-success)"},children:"Copied!"})]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),r.jsx("span",{children:"Copy Reference"})]})})}function M(a,c){if(!c)return a.toLocaleString();const e=c.decimals??0;switch(c.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:c.currency||"USD",minimumFractionDigits:e,maximumFractionDigits:e}).format(a);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:e,maximumFractionDigits:e}).format(a/100);default:return a.toLocaleString(void 0,{minimumFractionDigits:e,maximumFractionDigits:e})}}function ye(a,c){const e=a>=0?"+":"";return c==="percent_change"?`${e}${a.toFixed(1)}%`:`${e}${a.toLocaleString()}`}function fe({data:a,config:c,title:e,comparison:o}){var g,b,w;if(!(a!=null&&a[0])||!((g=c.value)!=null&&g.field))return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-muted)"},children:"No data available"});const s=a[0],l=s[c.value.field],N=M(l,c.format);let t=null,h="percent_change",D,k,f;if(o)t=o.change,h=o.changeType,D=o.currentPeriodLabel,k=o.previousPeriodLabel,f=M(o.previousValue,c.format);else if((b=c.comparison)!=null&&b.enabled&&c.comparison.field){const i=s[c.comparison.field];h=c.comparison.type,i&&i!==0&&(h==="percent_change"?t=(l-i)/i*100:t=l-i,f=M(i,c.format))}return r.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[r.jsxs("div",{className:"text-6xl font-bold tabular-nums",style:{color:"var(--yc-color-text)"},children:[N,c.unit&&r.jsx("span",{className:"text-3xl font-normal ml-2",style:{color:"var(--yc-color-text-muted)"},children:c.unit})]}),D&&r.jsx("div",{className:"text-sm mt-2",style:{color:"var(--yc-color-text-muted)"},children:D}),e&&r.jsx("div",{className:"text-lg mt-3",style:{color:"var(--yc-color-text-secondary)"},children:e}),t!==null&&r.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-lg font-medium px-3 py-1 rounded",style:t>=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:ye(t,h)}),f&&r.jsxs("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:["vs ",f]}),!f&&((w=c.comparison)==null?void 0:w.label)&&r.jsx("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:c.comparison.label})]}),k&&r.jsx("div",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:k})]})]})}function ve({chartName:a,drillParams:c}){var T,V,$,R;const{data:e,isLoading:o}=U(a),{data:s,isLoading:l,error:N}=I(a),{data:t}=Y(),h=q(),D=_(n=>n.getEffectiveFilters),k=_(n=>n.setChartFilter),f=o||l,g=c==null?void 0:c._from,b=c?Object.fromEntries(Object.entries(c).filter(([n])=>!n.startsWith("_"))):{},w=Object.keys(b).length>0,i=Object.entries(b).map(([n,x])=>`${n}: ${x}`).join(", ");y.useEffect(()=>{if(w)for(const[n,x]of Object.entries(b))k(a,n,x)},[a,w]);const[v,A]=y.useState(null),C=y.useCallback((n,x,m)=>{var u;(u=e==null?void 0:e.drillDown)!=null&&u.chart&&A({x:m.x,y:m.y,field:n,value:x})},[(T=e==null?void 0:e.drillDown)==null?void 0:T.chart]),H=y.useCallback(()=>{var m,u;if(!v||!((m=e==null?void 0:e.drillDown)!=null&&m.chart))return;const n=e.drillDown.field??((u=e.chart.x)==null?void 0:u.field)??v.field,x=new URLSearchParams({[n]:v.value,_from:a});window.location.hash=`/charts/${e.drillDown.chart}?${x.toString()}`,A(null)},[v,e,a]),S=D(a).granularity,d=S?me[S]:void 0,F=d==null?void 0:d.label,L=d==null?void 0:d.format;if(o)return r.jsxs("div",{className:"chart-container animate-pulse",children:[r.jsx("div",{className:"p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:r.jsx("div",{className:"h-6 rounded w-48",style:{backgroundColor:"var(--yc-color-surface-hover)"}})}),r.jsx("div",{className:"p-4",children:r.jsx("div",{className:"h-80 rounded",style:{backgroundColor:"var(--yc-color-surface-hover)"}})})]});if(!e)return r.jsxs("div",{className:"chart-container p-8 text-center",style:{color:"var(--yc-color-text-secondary)"},children:["Chart not found: ",a]});const O=()=>{var x,m,u,B,E,W;if(!s)return r.jsx("div",{className:"h-80 rounded animate-pulse",style:{backgroundColor:"var(--yc-color-surface-hover)"}});const n=e.chart.type;switch(n){case"line":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(x=e.drillDown)!=null&&x.chart?C:void 0;return r.jsx(ie,{data:s.rows,columns:s.columns,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"bar":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(m=e.drillDown)!=null&&m.chart?C:void 0;return r.jsx(ne,{data:s.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"area":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(u=e.drillDown)!=null&&u.chart?C:void 0;return r.jsx(oe,{data:s.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"pie":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing pie chart configuration"}):r.jsx(le,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,theme:t==null?void 0:t.theme,loading:l,onDrillDown:(B=e.drillDown)!=null&&B.chart?C:void 0});case"donut":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing donut chart configuration"}):r.jsx(ce,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,centerValue:e.chart.centerValue,theme:t==null?void 0:t.theme,loading:l,onDrillDown:(E=e.drillDown)!=null&&E.chart?C:void 0});case"scatter":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):r.jsx(ae,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"combo":if(!e.chart.x)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(W=e.drillDown)!=null&&W.chart?C:void 0;return r.jsx(se,{data:s.rows,xAxis:j,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"kpi":return r.jsx(fe,{data:s.rows,config:e.chart,title:e.title,comparison:s.comparison});case"heatmap":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):r.jsx(te,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"funnel":return r.jsx(re,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"waterfall":return r.jsx(ee,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"gauge":return r.jsx(Z,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"table":return r.jsx(J,{data:s.rows,columns:s.columns,chartConfig:e.chart,height:"100%",loading:l});default:return r.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',n,'" not yet implemented']})}};return r.jsxs("div",{className:"space-y-4",children:[g&&r.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:[r.jsx("button",{onClick:()=>{window.location.hash=`/charts/${g}`},className:"transition-colors hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:g}),r.jsx("span",{children:"/"}),r.jsx("span",{className:"font-medium",style:{color:"var(--yc-color-text)"},children:e.title}),i&&r.jsxs("span",{style:{color:"var(--yc-color-text-muted)"},children:["(",i,")"]})]}),r.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.parameters.length>0?r.jsx(z,{parameters:e.parameters,chartName:a}):r.jsx("div",{}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ue,{chartName:a}),r.jsx(G,{resourceType:"chart",resourceName:a})]})]}),r.jsx(he,{title:e.title,description:e.description,loading:f,cached:s==null?void 0:s.meta.cached,durationMs:s==null?void 0:s.meta.durationMs,hasDrillDown:!!((V=e.drillDown)!=null&&V.chart),onRefresh:()=>h(a),children:r.jsx(K,{isLoading:l,error:N,data:s==null?void 0:s.rows,onRetry:()=>h(a),children:O()})}),w&&s&&r.jsx(X,{data:s.rows,columns:s.columns,drillDownColumns:($=e.drillDown)==null?void 0:$.columns,filterDisplay:i,chartName:a}),v&&((R=e.drillDown)==null?void 0:R.chart)&&r.jsx(Q,{x:v.x,y:v.y,targetChartTitle:e.drillDown.chart,onDrillDown:H,onClose:()=>A(null)})]})}function be({parsed:a}){const c=a.params.token,[e,o]=y.useState(null),[s,l]=y.useState(!1);return y.useEffect(()=>{if(!c){o("No share token provided");return}de.getPublicConfig(c).then(()=>l(!0)).catch(()=>o("This link has expired or been revoked"))},[c]),e?r.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:r.jsx("div",{className:"text-center",children:r.jsx("div",{className:"text-gray-400 text-lg",children:e})})}):s?r.jsxs("div",{className:"min-h-screen bg-gray-50",children:[r.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:a.type==="public_chart"?r.jsx(ve,{chartName:a.name}):r.jsx(xe,{dashboardId:a.name,initialTab:a.params.tab})}),r.jsx("div",{className:"text-center py-4 text-xs text-gray-400",children:"Shared via yamchart"})]}):r.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:r.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{be as PublicViewer};
1
+ import{j as r,c as P,b as U,d as I,e as Y,f as q,g as _,F as z,S as G,C as K,D as X,h as Q,T as J,G as Z,W as ee,i as re,H as te,k as se,l as ae,m as ce,P as le,n as oe,B as ne,L as ie,a as de,o as xe}from"./index-Ds6UbsJz.js";import{a as y}from"./echarts-DtOYsfLX.js";function he({title:a,description:c,loading:e=!1,error:o=null,cached:s,durationMs:l,hasDrillDown:N,onRefresh:t,children:h}){return r.jsxs("div",{className:"chart-container",children:[r.jsxs("div",{className:"flex items-start justify-between p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h2",{className:"text-lg font-semibold",style:{color:"var(--yc-color-text)"},children:a}),N&&r.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:[r.jsx("title",{children:"Right-click to drill down"}),r.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"})]})]}),c&&r.jsx("p",{className:"text-sm mt-1",style:{color:"var(--yc-color-text-secondary)"},children:c})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[s!==void 0&&r.jsx("span",{className:"text-xs px-2 py-1 rounded",style:s?{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:s?"Cached":"Fresh"}),l!==void 0&&r.jsxs("span",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:[l,"ms"]}),t&&r.jsx("button",{onClick:t,disabled:e,className:"p-1.5 hover:bg-black/5 rounded transition-colors disabled:opacity-50",style:{color:"var(--yc-color-text-muted)"},title:"Refresh",children:r.jsx("svg",{className:P("w-4 h-4",e&&"animate-spin"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:r.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"})})})]})]}),r.jsx("div",{className:"p-4",children:o?r.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--yc-color-danger)"},children:r.jsxs("div",{className:"text-center",children:[r.jsx("p",{className:"font-medium",children:"Failed to load chart"}),r.jsx("p",{className:"text-sm mt-1",children:o.message})]})}):h})]})}const me={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 ue({chartName:a}){const[c,e]=y.useState(!1),o=async()=>{const s=`{{${a}}}`;try{await navigator.clipboard.writeText(s),e(!0),setTimeout(()=>e(!1),2e3)}catch(l){console.error("Failed to copy:",l)}};return r.jsx("button",{onClick:o,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 {{${a}}} for use in markdown widgets`,children:c?r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",style:{color:"var(--yc-color-success)"},children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),r.jsx("span",{style:{color:"var(--yc-color-success)"},children:"Copied!"})]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),r.jsx("span",{children:"Copy Reference"})]})})}function M(a,c){if(!c)return a.toLocaleString();const e=c.decimals??0;switch(c.type){case"currency":return new Intl.NumberFormat("en-US",{style:"currency",currency:c.currency||"USD",minimumFractionDigits:e,maximumFractionDigits:e}).format(a);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:e,maximumFractionDigits:e}).format(a/100);default:return a.toLocaleString(void 0,{minimumFractionDigits:e,maximumFractionDigits:e})}}function ye(a,c){const e=a>=0?"+":"";return c==="percent_change"?`${e}${a.toFixed(1)}%`:`${e}${a.toLocaleString()}`}function fe({data:a,config:c,title:e,comparison:o}){var g,b,w;if(!(a!=null&&a[0])||!((g=c.value)!=null&&g.field))return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-muted)"},children:"No data available"});const s=a[0],l=s[c.value.field],N=M(l,c.format);let t=null,h="percent_change",D,k,f;if(o)t=o.change,h=o.changeType,D=o.currentPeriodLabel,k=o.previousPeriodLabel,f=M(o.previousValue,c.format);else if((b=c.comparison)!=null&&b.enabled&&c.comparison.field){const i=s[c.comparison.field];h=c.comparison.type,i&&i!==0&&(h==="percent_change"?t=(l-i)/i*100:t=l-i,f=M(i,c.format))}return r.jsxs("div",{className:"h-80 flex flex-col items-center justify-center p-8",children:[r.jsxs("div",{className:"text-6xl font-bold tabular-nums",style:{color:"var(--yc-color-text)"},children:[N,c.unit&&r.jsx("span",{className:"text-3xl font-normal ml-2",style:{color:"var(--yc-color-text-muted)"},children:c.unit})]}),D&&r.jsx("div",{className:"text-sm mt-2",style:{color:"var(--yc-color-text-muted)"},children:D}),e&&r.jsx("div",{className:"text-lg mt-3",style:{color:"var(--yc-color-text-secondary)"},children:e}),t!==null&&r.jsxs("div",{className:"mt-4 flex flex-col items-center gap-1",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("span",{className:"text-lg font-medium px-3 py-1 rounded",style:t>=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:ye(t,h)}),f&&r.jsxs("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:["vs ",f]}),!f&&((w=c.comparison)==null?void 0:w.label)&&r.jsx("span",{className:"text-sm",style:{color:"var(--yc-color-text-muted)"},children:c.comparison.label})]}),k&&r.jsx("div",{className:"text-xs",style:{color:"var(--yc-color-text-muted)"},children:k})]})]})}function ve({chartName:a,drillParams:c}){var T,V,$,R;const{data:e,isLoading:o}=U(a),{data:s,isLoading:l,error:N}=I(a),{data:t}=Y(),h=q(),D=_(n=>n.getEffectiveFilters),k=_(n=>n.setChartFilter),f=o||l,g=c==null?void 0:c._from,b=c?Object.fromEntries(Object.entries(c).filter(([n])=>!n.startsWith("_"))):{},w=Object.keys(b).length>0,i=Object.entries(b).map(([n,x])=>`${n}: ${x}`).join(", ");y.useEffect(()=>{if(w)for(const[n,x]of Object.entries(b))k(a,n,x)},[a,w]);const[v,A]=y.useState(null),C=y.useCallback((n,x,m)=>{var u;(u=e==null?void 0:e.drillDown)!=null&&u.chart&&A({x:m.x,y:m.y,field:n,value:x})},[(T=e==null?void 0:e.drillDown)==null?void 0:T.chart]),H=y.useCallback(()=>{var m,u;if(!v||!((m=e==null?void 0:e.drillDown)!=null&&m.chart))return;const n=e.drillDown.field??((u=e.chart.x)==null?void 0:u.field)??v.field,x=new URLSearchParams({[n]:v.value,_from:a});window.location.hash=`/charts/${e.drillDown.chart}?${x.toString()}`,A(null)},[v,e,a]),S=D(a).granularity,d=S?me[S]:void 0,F=d==null?void 0:d.label,L=d==null?void 0:d.format;if(o)return r.jsxs("div",{className:"chart-container animate-pulse",children:[r.jsx("div",{className:"p-4 border-b",style:{borderColor:"var(--yc-color-border)"},children:r.jsx("div",{className:"h-6 rounded w-48",style:{backgroundColor:"var(--yc-color-surface-hover)"}})}),r.jsx("div",{className:"p-4",children:r.jsx("div",{className:"h-80 rounded",style:{backgroundColor:"var(--yc-color-surface-hover)"}})})]});if(!e)return r.jsxs("div",{className:"chart-container p-8 text-center",style:{color:"var(--yc-color-text-secondary)"},children:["Chart not found: ",a]});const O=()=>{var x,m,u,B,E,W;if(!s)return r.jsx("div",{className:"h-80 rounded animate-pulse",style:{backgroundColor:"var(--yc-color-surface-hover)"}});const n=e.chart.type;switch(n){case"line":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(x=e.drillDown)!=null&&x.chart?C:void 0;return r.jsx(ie,{data:s.rows,columns:s.columns,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"bar":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(m=e.drillDown)!=null&&m.chart?C:void 0;return r.jsx(ne,{data:s.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"area":if(!e.chart.x||!e.chart.y&&!e.chart.series)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(u=e.drillDown)!=null&&u.chart?C:void 0;return r.jsx(oe,{data:s.rows,xAxis:j,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"pie":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing pie chart configuration"}):r.jsx(le,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,theme:t==null?void 0:t.theme,loading:l,onDrillDown:(B=e.drillDown)!=null&&B.chart?C:void 0});case"donut":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing donut chart configuration"}):r.jsx(ce,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,centerValue:e.chart.centerValue,theme:t==null?void 0:t.theme,loading:l,onDrillDown:(E=e.drillDown)!=null&&E.chart?C:void 0});case"scatter":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):r.jsx(ae,{data:s.rows,xAxis:e.chart.x,yAxis:e.chart.y,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"combo":if(!e.chart.x)return r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"});{const j=d?{...e.chart.x,label:F,format:L}:e.chart.x,p=(W=e.drillDown)!=null&&W.chart?C:void 0;return r.jsx(se,{data:s.rows,xAxis:j,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l,onDrillDown:p})}case"kpi":return r.jsx(fe,{data:s.rows,config:e.chart,title:e.title,comparison:s.comparison});case"heatmap":return!e.chart.x||!e.chart.y?r.jsx("div",{className:"h-80 flex items-center justify-center",style:{color:"var(--yc-color-text-secondary)"},children:"Missing axis configuration"}):r.jsx(te,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"funnel":return r.jsx(re,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"waterfall":return r.jsx(ee,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"gauge":return r.jsx(Z,{data:s.rows,chartConfig:e.chart,theme:t==null?void 0:t.theme,loading:l});case"table":return r.jsx(J,{data:s.rows,columns:s.columns,chartConfig:e.chart,height:"100%",loading:l});default:return r.jsxs("div",{className:"h-80 flex items-center justify-center text-gray-500",children:['Chart type "',n,'" not yet implemented']})}};return r.jsxs("div",{className:"space-y-4",children:[g&&r.jsxs("div",{className:"flex items-center gap-2 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:[r.jsx("button",{onClick:()=>{window.location.hash=`/charts/${g}`},className:"transition-colors hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:g}),r.jsx("span",{children:"/"}),r.jsx("span",{className:"font-medium",style:{color:"var(--yc-color-text)"},children:e.title}),i&&r.jsxs("span",{style:{color:"var(--yc-color-text-muted)"},children:["(",i,")"]})]}),r.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.parameters.length>0?r.jsx(z,{parameters:e.parameters,chartName:a}):r.jsx("div",{}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ue,{chartName:a}),r.jsx(G,{resourceType:"chart",resourceName:a})]})]}),r.jsx(he,{title:e.title,description:e.description,loading:f,cached:s==null?void 0:s.meta.cached,durationMs:s==null?void 0:s.meta.durationMs,hasDrillDown:!!((V=e.drillDown)!=null&&V.chart),onRefresh:()=>h(a),children:r.jsx(K,{isLoading:l,error:N,data:s==null?void 0:s.rows,onRetry:()=>h(a),children:O()})}),w&&s&&r.jsx(X,{data:s.rows,columns:s.columns,drillDownColumns:($=e.drillDown)==null?void 0:$.columns,filterDisplay:i,chartName:a}),v&&((R=e.drillDown)==null?void 0:R.chart)&&r.jsx(Q,{x:v.x,y:v.y,targetChartTitle:e.drillDown.chart,onDrillDown:H,onClose:()=>A(null)})]})}function be({parsed:a}){const c=a.params.token,[e,o]=y.useState(null),[s,l]=y.useState(!1);return y.useEffect(()=>{if(!c){o("No share token provided");return}de.getPublicConfig(c).then(()=>l(!0)).catch(()=>o("This link has expired or been revoked"))},[c]),e?r.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:r.jsx("div",{className:"text-center",children:r.jsx("div",{className:"text-gray-400 text-lg",children:e})})}):s?r.jsxs("div",{className:"min-h-screen bg-gray-50",children:[r.jsx("div",{className:"max-w-7xl mx-auto py-6 px-4",children:a.type==="public_chart"?r.jsx(ve,{chartName:a.name}):r.jsx(xe,{dashboardId:a.name,initialTab:a.params.tab})}),r.jsx("div",{className:"text-center py-4 text-xs text-gray-400",children:"Shared via yamchart"})]}):r.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:r.jsx("div",{className:"text-gray-500",children:"Loading..."})})}export{be as PublicViewer};
@@ -1 +1 @@
1
- import{u as g,j as e,A as h}from"./index-uxK7mlHt.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-Ds6UbsJz.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-uxK7mlHt.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",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-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=>e.jsxs("tr",{className:"border-b last:border-0",style:{borderColor:"var(--yc-color-border)"},children:[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-Ds6UbsJz.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",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-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=>e.jsxs("tr",{className:"border-b last:border-0",style:{borderColor:"var(--yc-color-border)"},children:[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-uxK7mlHt.js";import{a as s}from"./echarts-DtOYsfLX.js";function O(){var A;const[i,N]=s.useState([]),[b,C]=s.useState(!0),[v,h]=s.useState(!1),[x,k]=s.useState(""),[l,g]=s.useState(null),[u,c]=s.useState([]),[m,y]=s.useState(!1),d=async()=>{try{const{users:r}=await p.authListUsers();N(r)}catch{k("Failed to load users")}finally{C(!1)}};s.useEffect(()=>{d()},[]);const a=async(r,t)=>{try{await p.authUpdateUser(r,{role:t}),await d()}catch(o){alert(o instanceof j?o.message:"Failed to update role")}},f=async(r,t)=>{if(confirm(`Delete user "${t}"? This cannot be undone.`))try{await p.authDeleteUser(r),await d()}catch(o){alert(o instanceof j?o.message:"Failed to delete user")}},U=r=>{if(l===r.id)g(null),c([]);else{g(r.id);const t=JSON.parse(r.attributes||"{}");c(Object.entries(t).map(([o,n])=>({key:o,value:n})))}},w=(r,t,o)=>{c(n=>n.map((S,M)=>M===r?{...S,[t]:o}:S))},E=()=>{c(r=>[...r,{key:"",value:""}])},L=r=>{c(t=>t.filter((o,n)=>n!==r))},D=async()=>{if(l){y(!0);try{const r={};for(const{key:t,value:o}of u){const n=t.trim();n&&(r[n]=o)}await p.authUpdateUser(l,{attributes:r}),await d(),c(Object.entries(r).map(([t,o])=>({key:t,value:o})))}catch(r){alert(r instanceof j?r.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",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-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(r=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text)"},children:r.name}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:r.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("select",{value:r.role,onChange:t=>a(r.id,t.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(r.created_at).toLocaleDateString()}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3",children:[e.jsx("button",{onClick:()=>U(r),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:l===r.id?"Hide Attrs":"Attrs"}),e.jsx("button",{onClick:()=>f(r.id,r.name),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Delete"})]})]},r.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(r=>r.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((r,t)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. department)",value:r.key,onChange:o=>w(t,"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:r.value,onChange:o=>w(t,"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(t),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"})})})]},t))})]}),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,k]=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.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=>k(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-Ds6UbsJz.js";import{a as s}from"./echarts-DtOYsfLX.js";function O(){var A;const[i,N]=s.useState([]),[b,C]=s.useState(!0),[v,h]=s.useState(!1),[x,k]=s.useState(""),[l,g]=s.useState(null),[u,c]=s.useState([]),[m,y]=s.useState(!1),d=async()=>{try{const{users:r}=await p.authListUsers();N(r)}catch{k("Failed to load users")}finally{C(!1)}};s.useEffect(()=>{d()},[]);const a=async(r,t)=>{try{await p.authUpdateUser(r,{role:t}),await d()}catch(o){alert(o instanceof j?o.message:"Failed to update role")}},f=async(r,t)=>{if(confirm(`Delete user "${t}"? This cannot be undone.`))try{await p.authDeleteUser(r),await d()}catch(o){alert(o instanceof j?o.message:"Failed to delete user")}},U=r=>{if(l===r.id)g(null),c([]);else{g(r.id);const t=JSON.parse(r.attributes||"{}");c(Object.entries(t).map(([o,n])=>({key:o,value:n})))}},w=(r,t,o)=>{c(n=>n.map((S,M)=>M===r?{...S,[t]:o}:S))},E=()=>{c(r=>[...r,{key:"",value:""}])},L=r=>{c(t=>t.filter((o,n)=>n!==r))},D=async()=>{if(l){y(!0);try{const r={};for(const{key:t,value:o}of u){const n=t.trim();n&&(r[n]=o)}await p.authUpdateUser(l,{attributes:r}),await d(),c(Object.entries(r).map(([t,o])=>({key:t,value:o})))}catch(r){alert(r instanceof j?r.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",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-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(r=>e.jsxs("tr",{className:"group",children:[e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text)"},children:r.name}),e.jsx("td",{className:"px-4 py-3 text-sm",style:{color:"var(--yc-color-text-secondary)"},children:r.email}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("select",{value:r.role,onChange:t=>a(r.id,t.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(r.created_at).toLocaleDateString()}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3",children:[e.jsx("button",{onClick:()=>U(r),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-primary)"},children:l===r.id?"Hide Attrs":"Attrs"}),e.jsx("button",{onClick:()=>f(r.id,r.name),className:"text-sm hover:opacity-80",style:{color:"var(--yc-color-danger)"},children:"Delete"})]})]},r.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(r=>r.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((r,t)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Key (e.g. department)",value:r.key,onChange:o=>w(t,"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:r.value,onChange:o=>w(t,"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(t),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"})})})]},t))})]}),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,k]=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.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=>k(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};