@object-ui/console 4.0.5 → 4.0.6

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 (50) hide show
  1. package/dist/assets/{AppManagementPage-ynJLzxVY.js → AppManagementPage-DvZRhEu3.js} +1 -1
  2. package/dist/assets/{ConsoleFloatingChatbot-C2rFxE3n.js → ConsoleFloatingChatbot-DSk3VUa6.js} +1 -1
  3. package/dist/assets/DashboardView-ClGhVUz7.js +1 -0
  4. package/dist/assets/{MetadataDetailPage-B9EzoQgu.js → MetadataDetailPage-Dn8QJ3Hw.js} +1 -1
  5. package/dist/assets/{MetadataFormDialog-BebGlAr3.js → MetadataFormDialog-Bf5wwigQ.js} +1 -1
  6. package/dist/assets/MetadataManagerPage-CLb0l4Pw.js +1 -0
  7. package/dist/assets/{PageView-C2GS-SQP.js → PageView-_R84mPfp.js} +2 -2
  8. package/dist/assets/ProfilePage-BFhufxnO.js +1 -0
  9. package/dist/assets/RecordDetailView-DROfHlhL.js +1 -0
  10. package/dist/assets/{RecordFormPage-B6mEBKMB.js → RecordFormPage-BqCa2Cez.js} +1 -1
  11. package/dist/assets/{ReportView-B16PsGer.js → ReportView-bv8vOOKb.js} +2 -2
  12. package/dist/assets/{SearchResultsPage-932jfRUX.js → SearchResultsPage-KJr5yhgC.js} +1 -1
  13. package/dist/assets/{SystemHubPage-CqrYgpYf.js → SystemHubPage-LGgCwgTn.js} +1 -1
  14. package/dist/assets/{data-adapter-BwfAq_h0.js → data-adapter-ChK5QXoY.js} +1 -1
  15. package/dist/assets/{getIcon-DF6zJOtU.js → getIcon-BKYKFGnN.js} +1 -1
  16. package/dist/assets/index-C_jWdyY_.css +2 -0
  17. package/dist/assets/index-DTdi5Ufa.js +2 -0
  18. package/dist/assets/{plugin-calendar-D1bCBBwe.js → plugin-calendar-CQkP8bUI.js} +1 -1
  19. package/dist/assets/{plugin-charts-x_9Q2-i_.js → plugin-charts-CJxtgGBd.js} +1 -1
  20. package/dist/assets/{plugin-chatbot-CgNZnFch.js → plugin-chatbot-CgD9fZFI.js} +14 -14
  21. package/dist/assets/plugin-form-BFt_k4to.js +1 -0
  22. package/dist/assets/plugin-gantt-BKC7uDlF.js +1 -0
  23. package/dist/assets/plugin-grid-C9RnYppl.js +8 -0
  24. package/dist/assets/plugin-kanban-Bi-sR7AW.js +1 -0
  25. package/dist/assets/{plugin-map-DZdVR1tc.js → plugin-map-zYnfrqC_.js} +1 -1
  26. package/dist/assets/{plugin-markdown-BlHuacDq.js → plugin-markdown-D1ozhgoT.js} +1 -1
  27. package/dist/assets/{plugin-timeline-OEB0nyvd.js → plugin-timeline-B93E4n2x.js} +1 -1
  28. package/dist/assets/plugin-view-B94g0Ssh.js +1 -0
  29. package/dist/assets/plugins-views-Bi5okDge.js +63 -0
  30. package/dist/assets/src-DwuebCF9.js +1 -0
  31. package/dist/assets/ui-components-BL3SEdAz.css +1 -0
  32. package/dist/assets/ui-components-DSSaN2w_.js +36 -0
  33. package/dist/assets/{ui-layout-jqAD528v.js → ui-layout-iDLUMX7R.js} +1 -1
  34. package/dist/index.html +4 -4
  35. package/package.json +30 -30
  36. package/dist/assets/DashboardView-x75VLMQW.js +0 -1
  37. package/dist/assets/MetadataManagerPage-B0xfI-4w.js +0 -1
  38. package/dist/assets/ProfilePage-BO3TRbTV.js +0 -1
  39. package/dist/assets/RecordDetailView-Clze41HE.js +0 -1
  40. package/dist/assets/index-CPatxDwz.js +0 -2
  41. package/dist/assets/index-vbGrAsEJ.css +0 -2
  42. package/dist/assets/plugin-form-DOfn-uRa.js +0 -1
  43. package/dist/assets/plugin-gantt-CHZ4HLjh.js +0 -1
  44. package/dist/assets/plugin-grid-Cn_T_wpz.js +0 -8
  45. package/dist/assets/plugin-kanban-BsgjJQam.js +0 -1
  46. package/dist/assets/plugin-view-CJFsgQ9v.js +0 -1
  47. package/dist/assets/plugins-views-DqZMtAOw.js +0 -63
  48. package/dist/assets/src-D5NTzWsi.js +0 -1
  49. package/dist/assets/ui-components-B5ROGaJH.css +0 -1
  50. package/dist/assets/ui-components-B7mlp0en.js +0 -36
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-BL3SEdAz.css","assets/plugins-views-DnNKJB60.css","assets/plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,a as n,c as r,d as i,f as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./vendor-react-B1k2FF9f.js";import{A as _,D as v,F as y,H as b,N as x,S,T as C,a as w,b as T,d as E,f as D,g as O,i as ee,p as k,u as te,w as A,y as ne}from"./framework-CoXA0nY6.js";import{a as j,c as M,d as re,i as ie,l as N,n as ae,o as P,r as F,s as oe,t as I,u as se}from"./infrastructure-Djv3I7gr.js";import{n as L,t as ce}from"./data-adapter-ChK5QXoY.js";import{i as R,n as le,r as z}from"./RecordFormPage-BqCa2Cez.js";import{a as ue,o as B}from"./vendor-ui-utils-Dyl9EYZi.js";import{a as V,c as H,i as de,n as fe,o as pe,r as me,s as he}from"./RecordDetailView-DROfHlhL.js";import{$n as U,$t as ge,Aj as _e,Bn as ve,Br as ye,Cb as W,DD as be,DL as xe,Dl as Se,Dt as Ce,Et as we,FA as Te,Fn as Ee,GM as De,Gn as Oe,Gt as ke,Hn as Ae,Ht as G,If as je,In as Me,It as Ne,Jk as Pe,Jt as Fe,Kn as Ie,Ld as Le,Ln as Re,Lt as ze,Mt as Be,Mv as Ve,NL as K,Nt as He,Ot as Ue,Ov as We,Ox as Ge,PC as Ke,Pt as qe,Qn as Je,Qt as Ye,R_ as Xe,Rn as Ze,SA as Qe,SE as $e,SO as et,SP as tt,Sd as nt,Sy as q,Tt as rt,Un as it,Vn as at,Wb as ot,Wn as st,Wt as ct,XA as lt,Xt as ut,Y as dt,YS as ft,Yt as pt,Yv as mt,Yy as ht,Z as gt,Zs as _t,Zt as vt,_n as yt,_r as bt,a_ as xt,ap as St,ar as Ct,at as wt,ax as Tt,bb as Et,bj as Dt,dn as Ot,dr as kt,ei as At,en as jt,fN as Mt,fd as Nt,fj as Pt,fn as Ft,fr as It,ft as Lt,gb as Rt,gc as zt,gn as Bt,gr as Vt,gt as Ht,hn as J,hr as Ut,ht as Wt,hx as Gt,ig as Kt,ir as qt,it as Jt,js as Yt,jt as Xt,kt as Zt,lm as Qt,ly as $t,mc as en,mh as tn,mn as nn,mr as rn,mt as an,na as on,nj as sn,nk as cn,nt as ln,ol as un,or as dn,pM as fn,pn,po as mn,pr as hn,pt as gn,qm as _n,qn as vn,qt as yn,r_ as bn,rt as xn,sI as Sn,sT as Cn,sr as wn,st as Tn,tO as En,tn as Dn,to as On,tt as kn,un as Y,ur as An,va as jn,vb as Mn,vr as X,wA as Nn,wd as Pn,wt as Fn,xn as In,zk as Ln,zn as Rn}from"./ui-components-DSSaN2w_.js";import{n as zn,t as Bn}from"./ui-layout-iDLUMX7R.js";import{a as Vn,i as Hn,o as Un,r as Z,t as Wn}from"./utils-DMMB8Xfh.js";import{a as Gn,o as Kn,s as qn}from"./plugins-views-Bi5okDge.js";import{r as Jn}from"./plugin-grid-C9RnYppl.js";import{n as Yn}from"./plugin-form-BFt_k4to.js";import{a as Xn,c as Zn,i as Qn,n as $n,o as er,r as tr,s as nr,t as rr}from"./plugin-view-B94g0Ssh.js";import"./DashboardView-ClGhVUz7.js";import"./PageView-_R84mPfp.js";import"./ReportView-bv8vOOKb.js";import"./SearchResultsPage-KJr5yhgC.js";import{n as ir}from"./src-DwuebCF9.js";var Q=e(t(),1),ar=e(o(),1),$=h();function or({children:e,adapter:t}){let[n,r]=(0,Q.useState)(t??null);return(0,Q.useEffect)(()=>{if(t){r(t);return}let e=!1;async function n(){try{let t=new ce({baseUrl:`https://demo.objectstack.ai`,fetch:se(),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});await t.connect(),e||r(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return n(),()=>{e=!0}},[t]),(0,$.jsx)(te.Provider,{value:n,children:e})}var sr=300*1e3,cr=[`app`,`view`],lr={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},ur=`objectui:metadata:`;function dr(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var fr=dr();function pr(...e){fr&&console.debug(`[MetadataProvider]`,...e)}function mr(e){return e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function hr(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function gr(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function _r(e,t){if(!e.length||!t.length)return e;let n={};for(let e of t){let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t)continue;let r=n[t]||={};if(e.list){let t=e.list.name||`default`;r[t]=e.list}if(e.listViews&&typeof e.listViews==`object`)for(let[t,n]of Object.entries(e.listViews))r[t]=n}return e.map(e=>{let t=n[e.name];if(!t)return e;let r=e.listViews||e.list_views||{};return{...e,listViews:{...t,...r}}})}function vr(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function yr(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(ur+e);if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function br(e,t){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(ur+e,JSON.stringify(t))}catch{}}function xr({children:e,adapter:t,ttlMs:n=sr}){let r=(0,Q.useRef)(new Map),i=(0,Q.useRef)(new Map),a=(0,Q.useRef)(t);a.current=t;let[o,s]=(0,Q.useState)(0),c=(0,Q.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>s(e=>e+1)):Promise.resolve().then(()=>s(e=>e+1))},[]),l=(0,Q.useCallback)(e=>{let t=r.current.get(e);return t||(t=vr(),r.current.set(e,t)),t},[]),u=(0,Q.useCallback)(e=>{let t=l(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return pr(`cache hit (fresh) type=${e} items=${t.items.length}`),Promise.resolve(t.items);let r=Date.now();t.status=`loading`,t.error=null;let i=a.current.getClient().meta.getItems(e).then(n=>{let i=mr(n);t.items=i,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of i)gr(e)&&t.byName.set(e.name,e);return e===`app`&&br(e,i),pr(`fetched type=${e} items=${i.length} in ${Date.now()-r}ms`),c(),i}).catch(n=>{let r=n instanceof Error?n:Error(String(n));return t.status=`error`,t.error=r,t.promise=null,pr(`fetch failed type=${e}`,r),c(),[]});return t.promise=i,i},[c,l,n]),d=(0,Q.useCallback)((e,t)=>{let n=l(e);if(n.byName.has(t))return pr(`item cache hit type=${e} name=${t}`),Promise.resolve(n.byName.get(t)??null);let r=i.current.get(e);r||(r=new Map,i.current.set(e,r));let o=r.get(t);if(o)return o;let s=Date.now(),c=a.current.getClient().meta.getItem(e,t).then(i=>{let a=hr(i);return a&&n.byName.set(t,a),pr(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),pr(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,c),c},[l]),f=(0,Q.useCallback)(async e=>{if(e){let t=l(e);t.fetchedAt=0,t.byName.clear(),await u(e);return}let t=Array.from(r.current.keys()).filter(e=>r.current.get(e).status!==`idle`);await Promise.all(t.map(e=>{let t=r.current.get(e);return t.fetchedAt=0,t.byName.clear(),u(e)}))},[u,l]),p=(0,Q.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),pr(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,pr(`invalidated type=${e}`)),c())},[c]),[m,h]=(0,Q.useState)(!0),[g,_]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=!1,t=yr(`app`);if(t){let e=l(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)gr(n)&&e.byName.set(n.name,n);c(),h(!1)}return(async()=>{for(let t of cr)try{await u(t),e||_(null)}catch(t){e||_(t instanceof Error?t:Error(String(t)))}e||h(!1)})(),()=>{e=!0}},[t,u,l,c]);let v=(0,Q.useMemo)(()=>{let e=e=>{let t=l(e);return t.status===`idle`&&u(e),t.items};return{apps:l(`app`).items,get objects(){let t=e(lr.objects),n=e(`view`);return n.length?_r(t,n):t},get dashboards(){return e(lr.dashboards)},get reports(){return e(lr.reports)},get pages(){return e(lr.pages)},loading:m,error:g??l(`app`).error,refresh:f,invalidate:p,ensureType:u,getItem:d,getItemsByType:t=>e(t)}},[o,m,g,u,d,l,f,p]);return(0,$.jsx)(E.Provider,{value:v,children:e})}function Sr({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i}){let o=g(),{appName:s}=a(),c=`/apps/${s}`,{execute:l,loading:u,error:d,runner:f}=C({context:{objectName:e,objectLabel:t||e,baseUrl:c}});return(0,Q.useEffect)(()=>{f.registerHandler(`create`,async()=>(r?.(null),{success:!0})),f.registerHandler(`delete`,async r=>{let a=r.params?.recordId||r.recordId;if(!a)return{success:!1,error:`No record ID provided`};try{return await n.delete(e,a),i?.(),B.success(`${t||e} deleted successfully`),{success:!0,reload:!0}}catch(n){return B.error(`Failed to delete ${t||e}`,{description:n.message}),{success:!1,error:n.message}}}),f.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&o(t.startsWith(`/`)?t:`${c}/${t}`),{success:!0}}),f.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[f,e,n,r,i,o,c]),{execute:l,create:(0,Q.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,Q.useCallback)(async e=>l({type:`delete`,confirmText:`Are you sure you want to delete this record?`,params:{recordId:e}}),[l]),navigateToView:(0,Q.useCallback)(t=>{o(`${c}/${e}/view/${t}`)},[o,c,e]),navigateToRecord:(0,Q.useCallback)(t=>{o(`${c}/${e}/record/${encodeURIComponent(t)}`)},[o,c,e]),loading:u,error:d}}var Cr=`objectui-recent-items`,wr=8;function Tr(){try{let e=localStorage.getItem(Cr);return e?JSON.parse(e):[]}catch{return[]}}function Er(e){try{localStorage.setItem(Cr,JSON.stringify(e))}catch{}}function Dr(){let[e,t]=(0,Q.useState)(Tr);return(0,Q.useEffect)(()=>{t(Tr())},[]),{recentItems:e,addRecentItem:(0,Q.useCallback)(e=>{t(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,wr);return Er(r),r})},[]),clearRecentItems:(0,Q.useCallback)(()=>{t([]),Er([])},[])}}var Or=`objectui-favorites`,kr=20;function Ar(){try{let e=localStorage.getItem(Or);return e?JSON.parse(e):[]}catch{return[]}}function jr(e){try{localStorage.setItem(Or,JSON.stringify(e))}catch{}}var Mr=(0,Q.createContext)(null);function Nr({children:e}){let[t,n]=(0,Q.useState)(Ar);(0,Q.useEffect)(()=>{n(Ar())},[]);let r=(0,Q.useCallback)(e=>{n(t=>{if(t.some(t=>t.id===e.id))return t;let n=[{...e,favoritedAt:new Date().toISOString()},...t].slice(0,kr);return jr(n),n})},[]),i=(0,Q.useCallback)(e=>{n(t=>{let n=t.filter(t=>t.id!==e);return jr(n),n})},[]),a=(0,Q.useCallback)(e=>{n(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):[{...e,favoritedAt:new Date().toISOString()},...t].slice(0,kr);return jr(n),n})},[]),o=(0,Q.useCallback)(()=>{n([]),jr([])},[]),s=(0,Q.useMemo)(()=>({favorites:t,addFavorite:r,removeFavorite:i,toggleFavorite:a,isFavorite:e=>t.some(t=>t.id===e),clearFavorites:o}),[t,r,i,a,o]);return(0,$.jsx)(Mr.Provider,{value:s,children:e})}function Pr(){return(0,Q.useContext)(Mr)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{}}}var Fr=(0,Q.createContext)({theme:`system`,setTheme:()=>null});function Ir({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Q.useState)(()=>localStorage.getItem(n)||t);(0,Q.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t);return}e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e)}};return(0,$.jsx)(Fr.Provider,{...r,value:o,children:e})}var Lr=()=>{let e=(0,Q.useContext)(Fr);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Rr(){return(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function zr({children:e}){return(0,$.jsx)(Ir,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,$.jsx)(he,{children:(0,$.jsx)(Nr,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Rr,{}),children:e})})})})}function Br({children:e}){return(0,$.jsx)(or,{children:(0,$.jsx)(Vr,{children:e})})}function Vr({children:e}){let t=D();return t?(0,$.jsx)(_,{dataSource:t,children:(0,$.jsx)(xr,{adapter:t,children:e})}):(0,$.jsx)(Rr,{})}function Hr({children:e}){let{activeOrganization:t,organizations:r,isOrganizationsLoading:i}=M();return i?(0,$.jsx)(Rr,{}):((r??[]).length>0||t)&&!t?(0,$.jsx)(n,{to:`/organizations`,replace:!0}):(0,$.jsx)($.Fragment,{children:e})}function Ur({children:e,requireOrganization:t=!0,loginPath:r=`/login`}){return(0,$.jsx)(oe,{fallback:(0,$.jsx)(n,{to:r}),loadingFallback:(0,$.jsx)(Rr,{}),children:(0,$.jsx)(Br,{children:t?(0,$.jsx)(Hr,{children:e}):e})})}function Wr(){let{loading:e}=k();return e?(0,$.jsx)(Rr,{}):(0,$.jsx)(n,{to:`/home`,replace:!0})}function Gr(){let e=c(),t=e.pathname.replace(/^\/system/,``);return(0,$.jsx)(n,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}function Kr(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var qr=new Map;function Jr(e){if(!e)return be;let t=qr.get(e);if(t)return t;let n=Kr(e),r=e=>Q.createElement(gt,{name:n,fallback:be,...e});return r.displayName=`LucideIcon(${e})`,qr.set(e,r),r}var Yr=`objectui-nav-pins`,Xr=20;function Zr(){try{let e=localStorage.getItem(Yr);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Qr(e){try{localStorage.setItem(Yr,JSON.stringify(e))}catch{}}function $r(){let[e,t]=(0,Q.useState)(Zr);(0,Q.useEffect)(()=>{t(Zr())},[]);let n=(0,Q.useCallback)((e,n)=>{t(t=>{let r=t.filter(t=>t!==e),i=n?[...r,e].slice(0,Xr):r;return Qr(i),i})},[]),r=(0,Q.useCallback)(t=>e.includes(t),[e]),i=(0,Q.useCallback)(t=>t.map(t=>{let n=e.includes(t.id),r=t.children?.length?i(t.children):t.children;return n!==(t.pinned??!1)||r!==t.children?{...t,pinned:n,children:r}:t}),[e]);return{pinnedIds:e,togglePin:n,isPinned:r,applyPins:i,clearPins:(0,Q.useCallback)(()=>{t([]),Qr([])},[])}}function ei(e){let t=`objectui-nav-order-${e}`,[n,r]=Q.useState(()=>{try{let e=localStorage.getItem(t);if(!e)return{};let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))return{};let r={};for(let[e,t]of Object.entries(n))Array.isArray(t)&&t.every(e=>typeof e==`string`)&&(r[e]=t);return r}catch{return{}}}),i=Q.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Q.useCallback(e=>{let t=n.__root__;if(!t)return e;let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}return r.forEach(e=>i.push(e)),i},[n]),handleReorder:Q.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function ti({activeAppName:e}){let{isMobile:t}=ze(),n=c(),{t:r}=w(),{objectLabel:i,dashboardLabel:a,navGroupLabel:o}=re(),{context:s,currentAppName:l}=H();Q.useEffect(()=>{let e=0,n=t=>{e=t.touches[0].clientX},r=n=>{let r=n.changedTouches[0].clientX-e;e<30&&r>50&&t&&document.querySelector(`[data-sidebar="trigger"]`)?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0}))};return document.addEventListener(`touchstart`,n,{passive:!0}),document.addEventListener(`touchend`,r,{passive:!0}),()=>{document.removeEventListener(`touchstart`,n),document.removeEventListener(`touchend`,r)}},[t]);let{recentItems:u}=Dr(),{favorites:d,removeFavorite:f}=Pr(),{apps:m}=k(),h=(m||[]).filter(e=>e.active!==!1),g=h.find(t=>t.name===(e||l))||h[0],{applyOrder:_,handleReorder:v}=ei(g?.name||`home`),{togglePin:y,applyPins:b}=$r(),x=g?.areas||[],[S,C]=Q.useState(()=>x.length>0?x[0].id:null);Q.useEffect(()=>{x.length>0?C(e=>x.some(t=>t.id===e)?e:x[0].id):C(null)},[g?.name,x.length]);let T=x.find(e=>e.id===S)?.navigation||g?.navigation||[],E=Q.useMemo(()=>[{id:`home-dashboard`,label:r(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`}],[r]),D=s===`home`?E:T,O=Q.useMemo(()=>b(_(D)),[D,_,b]),[ee,te]=Q.useState(!1),{evaluator:A}=R(),ne=Q.useCallback(e=>z(e,A),[A]),{can:j}=I(),M=Q.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return j(n,r)}),[j]),ie=s===`app`&&g?`/apps/${g.name}`:``;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Fn,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[(0,$.jsx)(rt,{className:`pt-2`,children:(0,$.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:s===`app`&&g?(0,$.jsxs)($.Fragment,{children:[x.length>1&&(0,$.jsxs)(Ce,{children:[(0,$.jsxs)(Zt,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(W,{className:`h-3.5 w-3.5`}),r(`sidebar.area`,{defaultValue:`Area`})]}),(0,$.jsx)(Ue,{children:(0,$.jsx)(Xt,{children:x.map(e=>{let t=Jr(e.icon);return(0,$.jsx)(qe,{children:(0,$.jsxs)(He,{isActive:e.id===S,tooltip:e.label,onClick:()=>C(e.id),children:[(0,$.jsx)(t,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,$.jsx)(Bn,{items:O,basePath:ie,evaluateVisibility:ne,checkPermission:M,enablePinning:!t,onPinToggle:y,enableReorder:!t,onReorder:v,resolveObjectLabel:(e,t)=>i({name:e,label:t}),resolveDashboardLabel:(e,t)=>a({name:e,label:t}),resolveGroupLabel:g?(e,t)=>o(g.name,e,t):void 0,t:r}),u.length>0&&(0,$.jsxs)(Ce,{children:[(0,$.jsxs)(Zt,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>te(e=>!e),children:[(0,$.jsx)(lt,{className:`h-3 w-3 transition-transform duration-150 ${ee?`rotate-90`:``}`}),(0,$.jsx)(cn,{className:`h-3.5 w-3.5`}),r(`sidebar.recent`,{defaultValue:`Recent`})]}),ee&&(0,$.jsx)(Ue,{children:(0,$.jsx)(Xt,{children:u.slice(0,5).map(e=>(0,$.jsx)(qe,{children:(0,$.jsx)(He,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),d.length>0&&(0,$.jsxs)(Ce,{children:[(0,$.jsxs)(Zt,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(en,{className:`h-3.5 w-3.5`}),r(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,$.jsx)(Ue,{children:(0,$.jsx)(Xt,{children:d.slice(0,8).map(e=>(0,$.jsxs)(qe,{children:[(0,$.jsx)(He,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Be,{showOnHover:!0,onClick:t=>{t.stopPropagation(),f(e.id)},"aria-label":r(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(zt,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ce,{children:(0,$.jsx)(Ue,{children:(0,$.jsx)(Xt,{children:E.map(e=>{let t=Jr(e.icon),r=n.pathname===e.url;return(0,$.jsx)(qe,{children:(0,$.jsx)(He,{asChild:!0,tooltip:e.label,isActive:r,children:(0,$.jsxs)(p,{to:e.url||`/home`,children:[(0,$.jsx)(t,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),d.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,$.jsxs)(Ce,{children:[(0,$.jsxs)(Zt,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(en,{className:`h-3.5 w-3.5`}),r(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,$.jsx)(Ue,{children:(0,$.jsx)(Xt,{children:d.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,$.jsxs)(qe,{children:[(0,$.jsx)(He,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Be,{showOnHover:!0,onClick:t=>{t.stopPropagation(),f(e.id)},"aria-label":r(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(zt,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,$.jsx)(we,{className:`border-t p-1`,children:(0,$.jsx)(Ne,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]}),t&&s===`app`&&(0,$.jsx)(`div`,{className:`fixed bottom-0 left-0 right-0 z-50 flex items-center justify-around border-t bg-background/95 backdrop-blur-sm px-2 py-1 sm:hidden safe-area-bottom`,children:O.filter(e=>e.type!==`group`).slice(0,5).map(e=>{let t=Jr(e.icon),n=e.url||`#`;return e.type===`object`?(n=`${ie}/${e.objectName}`,e.viewName&&(n+=`/view/${e.viewName}`)):e.type===`dashboard`?n=e.dashboardName?`${ie}/dashboard/${e.dashboardName}`:`#`:e.type===`page`&&(n=e.pageName?`${ie}/page/${e.pageName}`:`#`),(0,$.jsxs)(p,{to:n,className:`flex flex-col items-center gap-0.5 px-2 py-1.5 text-muted-foreground hover:text-foreground transition-colors min-w-[44px] min-h-[44px] justify-center`,children:[(0,$.jsx)(t,{className:`h-5 w-5`}),(0,$.jsx)(`span`,{className:`text-[10px] truncate max-w-[60px]`,children:Z(e.label,r)})]},e.id)})})]})}function ni(){let{theme:e,setTheme:t}=Lr(),{t:n}=w();return(0,$.jsxs)(Ft,{children:[(0,$.jsx)(In,{asChild:!0,children:(0,$.jsxs)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(_t,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,$.jsx)(bn,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,$.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,$.jsxs)(pn,{align:`end`,children:[(0,$.jsxs)(J,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,$.jsx)(_t,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(J,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,$.jsx)(bn,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(J,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,$.jsx)(xt,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var ri=[{code:`en`,label:`English`},{code:`zh`,label:`中文`},{code:`ja`,label:`日本語`},{code:`ko`,label:`한국어`},{code:`de`,label:`Deutsch`},{code:`fr`,label:`Français`},{code:`es`,label:`Español`},{code:`pt`,label:`Português`},{code:`ru`,label:`Русский`},{code:`ar`,label:`العربية`}];function ii(){let{t:e,language:t,changeLanguage:n}=w();return(0,$.jsxs)(Ft,{children:[(0,$.jsx)(In,{asChild:!0,children:(0,$.jsxs)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(ft,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,$.jsx)(pn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:ri.map(e=>(0,$.jsxs)(J,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var ai={connected:{label:`Connected`,color:`text-green-500`,icon:Nn},connecting:{label:`Connecting...`,color:`text-yellow-500`,icon:q},reconnecting:{label:`Reconnecting...`,color:`text-yellow-500`,icon:q},disconnected:{label:`Disconnected`,color:`text-muted-foreground`,icon:At},error:{label:`Connection Error`,color:`text-destructive`,icon:At}};function oi({state:e,className:t}){let n=ai[e],r=n.icon,[i,a]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(e===`connected`){a(!0);let e=setTimeout(()=>a(!1),2e3);return()=>clearTimeout(e)}a(!1)},[e]),e===`connected`&&!i?null:(0,$.jsxs)(`div`,{className:K(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:n.label,children:[(0,$.jsx)(r,{className:K(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:n.label})]})}var si={create:{icon:Qt,color:`text-green-500`},update:{icon:_n,color:`text-blue-500`},delete:{icon:mn,color:`text-red-500`},comment:{icon:Xe,color:`text-amber-500`}};function ci(e){let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=Math.floor((Date.now()-t)/1e3);if(n<60)return`${Math.max(n,0)}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function li({activities:e=[],className:t}){let[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)({create:!0,update:!0,delete:!0,comment:!0}),c=e=>{s(t=>({...t,[e]:!t[e]}))},l=e.filter(e=>o[e.type]);return(0,$.jsxs)(ct,{open:n,onOpenChange:r,children:[(0,$.jsx)(pt,{asChild:!0,children:(0,$.jsxs)(X,{variant:`ghost`,size:`icon`,className:t??`h-8 w-8`,"aria-label":`Activity feed`,children:[(0,$.jsx)(tt,{className:`h-4 w-4`}),e.length>0&&(0,$.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-3.5 w-3.5 rounded-full bg-primary text-[9px] font-bold text-primary-foreground flex items-center justify-center`,children:e.length>9?`9+`:e.length})]})}),(0,$.jsxs)(ke,{side:`right`,className:`w-80 sm:w-96`,children:[(0,$.jsx)(yn,{children:(0,$.jsxs)(Fe,{className:`flex items-center justify-between`,children:[`Recent Activity`,(0,$.jsxs)(X,{variant:i?`secondary`:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>a(!i),children:[(0,$.jsx)(Ke,{className:`h-3.5 w-3.5 mr-1`}),`Filter`]})]})}),i&&(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-3 px-1`,children:Object.keys(si).map(e=>{let{icon:t,color:n}=si[e],r=o[e];return(0,$.jsxs)(qt,{variant:r?`default`:`outline`,className:`cursor-pointer select-none gap-1 capitalize`,onClick:()=>c(e),children:[(0,$.jsx)(t,{className:`h-3 w-3 ${r?``:n}`}),e]},e)})}),l.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 py-16 text-muted-foreground`,children:[(0,$.jsx)(tt,{className:`h-8 w-8 opacity-40`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`No recent activity`})]}):(0,$.jsx)(`ul`,{className:`mt-4 space-y-1 overflow-y-auto max-h-[calc(100vh-8rem)]`,children:l.map(e=>{let{icon:t,color:n}=si[e.type];return(0,$.jsxs)(`li`,{className:`flex items-start gap-3 rounded-md px-2 py-2 hover:bg-muted/50 transition-colors`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0 ${n}`,children:(0,$.jsx)(t,{className:`h-4 w-4`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm leading-snug`,children:e.description}),(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[e.user,` · `,ci(e.timestamp)]})]})]},e.id)})})]})]})}function ui({activeAppName:e,onAppChange:t}){let{apps:n}=k(),{t:r}=w(),{appLabel:i}=re(),a=(n||[]).filter(e=>e.active!==!1),o=a.find(t=>t.name===e)||a[0];return o?(0,$.jsxs)(Ft,{children:[(0,$.jsx)(In,{asChild:!0,children:(0,$.jsxs)(`button`,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 hover:bg-accent hover:text-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[i({name:o.name,label:Z(o.label,r)}),(0,$.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,$.jsxs)(pn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,$.jsx)(Bt,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Application`}),(0,$.jsx)(yt,{}),a.map(e=>{let n=Jr(e.icon),a=i({name:e.name,label:Z(e.label,r)}),s=o.name===e.name;return(0,$.jsxs)(J,{onClick:()=>t(e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,$.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,$.jsx)(n,{className:`size-3`})}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a}),s&&(0,$.jsx)(Pt,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}function di(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function fi(){return(0,$.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var pi=[];function mi({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:i,activities:o,activeAppName:s,onAppChange:l}){let u=e??(t?`app`:`home`),d=u===`app`,f=c(),m=a(),h=g(),{isOnline:_}=T(),{user:v,signOut:y,organizations:b,activeOrganization:x,isOrganizationsLoading:S}=M(),C=D(),{t:E}=w(),{objectLabel:O,dashboardLabel:ee,pageLabel:te,reportLabel:A}=re(),{apps:ne,dashboards:j,pages:ie,reports:N}=k(),{currentAppName:ae,recordTitle:P}=H(),[oe,I]=(0,Q.useState)(null),[se,L]=(0,Q.useState)(null),ce=(0,Q.useRef)(!1),R=(0,Q.useRef)(!1),le=(0,Q.useCallback)(async()=>{if(!C||!d)return;let e=ce.current?Promise.resolve({data:[]}):C.find(`sys_presence`).catch(e=>(e?.status===404&&(ce.current=!0),{data:[]})),t=R.current?Promise.resolve({data:[]}):C.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(e=>(e?.status===404&&(R.current=!0),{data:[]}));try{let[n,r]=await Promise.all([e,t]);if(n.data?.length){let e=n.data.filter(e=>typeof e.userId==`string`);e.length&&I(e)}if(r.data?.length){let e=r.data.filter(e=>typeof e.type==`string`);e.length&&L(e)}}catch{}},[C,d]);(0,Q.useEffect)(()=>{le()},[le]);let z=i??oe??pi,ue=o??se??[],B=S||(b??[]).length>0||!!x,V=f.pathname.split(`/`).filter(Boolean),fe=m.appName||V[1],pe=V[2],me=`/apps/${fe}`,he=n??[],U=s||ae||fe,ge=(ne||[]).find(e=>e.name===U),_e=new Set,ve=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&_e.add(t.objectName),t.children&&ve(t.children)};ve(ge?.navigation||[]);for(let e of ge?.areas||[])ve(e.navigation||[]);let ye=(_e.size>0?he.filter(e=>_e.has(e.name)):he.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`))).map(e=>({label:O(e),href:`${me}/${e.name}`})),W=[];if(d){if(pe===`dashboard`){if(W.push({label:E(`console.breadcrumb.dashboards`),href:me}),V[3]){let e=V[3],t=(j||[]).find(t=>t.name===e)?.label||di(e);W.push({label:ee({name:e,label:t})})}}else if(pe===`page`){if(W.push({label:E(`console.breadcrumb.pages`),href:me}),V[3]){let e=V[3],t=(ie||[]).find(t=>t.name===e)?.label||di(e);W.push({label:te({name:e,label:t})})}}else if(pe===`report`){if(W.push({label:E(`console.breadcrumb.reports`),href:me}),V[3]){let e=V[3],t=(N||[]).find(t=>t.name===e)?.label||di(e);W.push({label:A({name:e,label:t})})}}else if(pe===`system`)W.push({label:E(`console.breadcrumb.system`)}),V[3]&&W.push({label:di(V[3])});else if(pe){let e=he.find(e=>e.name===pe);if(e){if(W.push({label:O(e),href:`${me}/${pe}`,siblings:ye}),V[3]===`record`&&V[4]){let e=V[4].length>12?`${V[4].slice(0,8)}…`:V[4],t=P?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;W.push({label:n||`#${e}`})}else if(V[3]===`view`&&V[4]){let t=V[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||di(t);W.push({label:r})}}}}let be=W[W.length-1]?.label||t||``;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,$.jsx)(p,{to:`/home`,className:`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:`ObjectStack`,children:(0,$.jsx)(Mt,{className:`h-4 w-4`})}),u===`home`&&(0,$.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:`ObjectStack`}),u===`orgs`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fi,{}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:E(`organizations.title`,{defaultValue:`Organizations`})})]}),d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ne,{className:`md:hidden shrink-0 ml-1`}),s&&l?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fi,{}),(0,$.jsx)(ui,{activeAppName:s,onAppChange:l})]}):t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fi,{}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,W.map((e,t)=>{let n=t===W.length-1;return(0,$.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,$.jsx)(fi,{}),e.siblings&&e.siblings.length>1?(0,$.jsxs)(Ft,{children:[(0,$.jsxs)(In,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium transition-colors outline-none hover:bg-accent hover:text-foreground ${n?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,$.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,$.jsxs)(pn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,$.jsx)(Bt,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,$.jsx)(yt,{}),e.siblings.map(e=>(0,$.jsx)(J,{asChild:!0,children:(0,$.jsx)(p,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,$.jsx)(p,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,$.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),(0,$.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:be})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!_&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 text-xs font-medium`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),`Offline`]}),d&&r&&(0,$.jsx)(oi,{state:r}),d&&z.length>0&&(0,$.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:`Users currently online`,children:(0,$.jsx)(de,{users:z,size:`sm`,maxVisible:3,showStatus:!0})}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,$.jsxs)(`button`,{onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),className:`hidden lg:flex relative items-center gap-2 w-48 xl:w-64 h-8 px-3 text-sm rounded-md border bg-muted/50 text-muted-foreground hover:bg-muted transition-colors`,children:[(0,$.jsx)(Le,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:E(`console.search`,{defaultValue:`Search...`})}),(0,$.jsxs)(`kbd`,{className:`pointer-events-none inline-flex h-5 items-center gap-0.5 rounded border bg-background px-1.5 text-[10px] font-medium text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),"aria-label":E(`console.search`,{defaultValue:`Search...`}),children:(0,$.jsx)(Le,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(`div`,{className:`hidden sm:flex shrink-0`,children:(0,$.jsx)(li,{activities:ue})}),(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,asChild:!0,"aria-label":E(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,$.jsx)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:(0,$.jsx)(Pe,{className:`h-4 w-4`})})})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(`div`,{className:`hidden sm:flex shrink-0`,children:(0,$.jsx)(ni,{})}),(0,$.jsx)(`div`,{className:`hidden sm:flex shrink-0`,children:(0,$.jsx)(ii,{})}),(0,$.jsxs)(Ft,{children:[(0,$.jsx)(In,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,$.jsxs)(Ct,{className:`h-7 w-7 rounded-full`,children:[(0,$.jsx)(wn,{src:v?.image,alt:v?.name??`User`}),(0,$.jsx)(dn,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:F(v)})]})})}),(0,$.jsxs)(pn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,$.jsx)(Bt,{className:`p-0 font-normal`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,$.jsxs)(Ct,{className:`h-8 w-8 rounded-lg`,children:[(0,$.jsx)(wn,{src:v?.image,alt:v?.name??`User`}),(0,$.jsx)(dn,{className:`rounded-lg bg-primary text-primary-foreground`,children:F(v)})]}),(0,$.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,$.jsx)(`span`,{className:`truncate font-semibold`,children:v?.name??`User`}),(0,$.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:v?.email??``})]})]})}),(0,$.jsx)(yt,{}),(0,$.jsxs)(nn,{children:[B&&(0,$.jsxs)(J,{onClick:()=>h(`/organizations`),className:`cursor-pointer`,children:[(0,$.jsx)(Mt,{className:`mr-2 h-4 w-4`}),E(`organizations.mine`,{defaultValue:`My Organizations`})]}),(0,$.jsxs)(J,{onClick:()=>h(`/apps/setup/system/profile`),children:[(0,$.jsx)(on,{className:`mr-2 h-4 w-4`}),E(`user.profile`,{defaultValue:`Profile`})]}),(0,$.jsxs)(J,{onClick:()=>h(`/apps/setup`),children:[(0,$.jsx)(nt,{className:`mr-2 h-4 w-4`}),E(`sidebar.settings`,{defaultValue:`Settings`})]})]}),(0,$.jsx)(yt,{}),(0,$.jsxs)(J,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,$.jsx)($t,{className:`mr-2 h-4 w-4`}),E(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})}var hi=768,gi=1024;function _i(){let{setOpen:e,isMobile:t}=ze();(0,Q.useEffect)(()=>{function t(){let t=window.innerWidth;t>=hi&&t<gi&&e(!1)}return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,t])}var vi=(0,Q.lazy)(()=>l(()=>import(`./ConsoleFloatingChatbot-DSk3VUa6.js`),__vite__mapDeps([0])));function yi({children:e}){return _i(),(0,$.jsx)($.Fragment,{children:e})}function bi({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a}){let o=Z(n?.label)||t,{isAiEnabled:s}=S(),c=s||!1,{setContext:l,setCurrentAppName:u}=H();return(0,Q.useEffect)(()=>{l(`app`),u(t)},[l,u,t]),(0,$.jsxs)(zn,{sidebar:(0,$.jsx)(ti,{activeAppName:t,onAppChange:r}),navbar:(0,$.jsx)(mi,{variant:`app`,appName:o,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-hidden bg-muted/5`,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,logo:n.branding.logo,title:n.label?`${Z(n.label)} — ObjectStack Console`:void 0}:void 0,children:[(0,$.jsx)(yi,{children:e}),c&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(vi,{appLabel:o,objects:i})})]})}function xi({apps:e,activeApp:t,objects:n,onAppChange:r}){let[i,o]=(0,Q.useState)(!1),s=g(),{appName:c}=a(),{setTheme:l}=Lr(),{evaluator:u}=R(),{t:d}=w();(0,Q.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),o(e=>!e))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]);let f=`/apps/${c||t?.name}`,p=(0,Q.useCallback)(e=>{o(!1),e()},[]),m=Si(t?.navigation||[]).filter(e=>z(e.visible??e.visibleOn,u));return(0,$.jsxs)(Ee,{open:i,onOpenChange:o,children:[(0,$.jsx)(Ze,{placeholder:d(`console.commandPalette.placeholder`)}),(0,$.jsxs)(ve,{children:[(0,$.jsx)(Me,{children:d(`console.commandPalette.noResults`)}),m.filter(e=>e.type===`object`).length>0&&(0,$.jsx)(Re,{heading:d(`console.commandPalette.objects`),children:m.filter(e=>e.type===`object`).map(e=>{let t=Jr(e.icon);return(0,$.jsxs)(Rn,{value:`object ${Z(e.label,d)} ${e.objectName}`,onSelect:()=>p(()=>s(`${f}/${e.objectName}`)),children:[(0,$.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:Z(e.label,d)})]},e.id)})}),m.filter(e=>e.type===`dashboard`).length>0&&(0,$.jsx)(Re,{heading:d(`console.commandPalette.dashboards`),children:m.filter(e=>e.type===`dashboard`).map(e=>(0,$.jsxs)(Rn,{value:`dashboard ${Z(e.label,d)} ${e.dashboardName}`,onSelect:()=>p(()=>s(`${f}/dashboard/${e.dashboardName}`)),children:[(0,$.jsx)(Et,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:Z(e.label,d)})]},e.id))}),m.filter(e=>e.type===`page`).length>0&&(0,$.jsx)(Re,{heading:d(`console.commandPalette.pages`),children:m.filter(e=>e.type===`page`).map(e=>(0,$.jsxs)(Rn,{value:`page ${Z(e.label,d)} ${e.pageName}`,onSelect:()=>p(()=>s(`${f}/page/${e.pageName}`)),children:[(0,$.jsx)(Cn,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:Z(e.label,d)})]},e.id))}),m.filter(e=>e.type===`report`).length>0&&(0,$.jsx)(Re,{heading:d(`console.commandPalette.reports`),children:m.filter(e=>e.type===`report`).map(e=>(0,$.jsxs)(Rn,{value:`report ${Z(e.label,d)} ${e.reportName}`,onSelect:()=>p(()=>s(`${f}/report/${e.reportName}`)),children:[(0,$.jsx)(_e,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:Z(e.label,d)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(at,{}),(0,$.jsx)(Re,{heading:d(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Jr(e.icon);return(0,$.jsxs)(Rn,{value:`app ${Z(e.label,d)} ${e.name}`,onSelect:()=>p(()=>r(e.name)),children:[(0,$.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:Z(e.label,d)}),e.name===t?.name&&(0,$.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:d(`console.commandPalette.current`)})]},e.name)})})]}),(0,$.jsx)(at,{}),(0,$.jsxs)(Re,{heading:d(`console.commandPalette.preferences`),children:[(0,$.jsxs)(Rn,{value:`theme light`,onSelect:()=>p(()=>l(`light`)),children:[(0,$.jsx)(_t,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:d(`console.commandPalette.lightTheme`)})]}),(0,$.jsxs)(Rn,{value:`theme dark`,onSelect:()=>p(()=>l(`dark`)),children:[(0,$.jsx)(bn,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:d(`console.commandPalette.darkTheme`)})]}),(0,$.jsxs)(Rn,{value:`theme system`,onSelect:()=>p(()=>l(`system`)),children:[(0,$.jsx)(xt,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:d(`console.commandPalette.systemTheme`)})]})]}),(0,$.jsx)(at,{}),(0,$.jsxs)(Re,{heading:d(`console.commandPalette.actions`),children:[(0,$.jsxs)(Rn,{value:`create new app application`,onSelect:()=>p(()=>s(`${f}/create-app`)),children:[(0,$.jsx)(Qt,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:d(`console.commandPalette.createApp`)})]}),(0,$.jsxs)(Rn,{value:`search all results full page`,onSelect:()=>p(()=>s(`${f}/search`)),children:[(0,$.jsx)(Le,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:d(`console.commandPalette.openFullSearch`)})]})]})]})]})}function Si(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Si(n.children)):t.push(n);return t}function Ci(){let{t:e}=w(),[t,n]=(0,Q.useState)(!1),r=(0,Q.useMemo)(()=>[{title:e(`console.shortcuts.groups.general`),shortcuts:[{keys:[`⌘`,`K`],description:e(`console.shortcuts.openCommandPalette`)},{keys:[`?`],description:e(`console.shortcuts.showShortcuts`)},{keys:[`Esc`],description:e(`console.shortcuts.closeDialog`)}]},{title:e(`console.shortcuts.groups.navigation`),shortcuts:[{keys:[`B`],description:e(`console.shortcuts.toggleSidebar`)},{keys:[`⌘`,`/`],description:e(`console.shortcuts.focusSearch`)}]},{title:e(`console.shortcuts.groups.dataViews`),shortcuts:[{keys:[`N`],description:e(`console.shortcuts.createRecord`)},{keys:[`R`],description:e(`console.shortcuts.refreshData`)},{keys:[`⌘`,`E`],description:e(`console.shortcuts.editRecord`)}]},{title:e(`console.shortcuts.groups.preferences`),shortcuts:[{keys:[`⌘`,`D`],description:e(`console.shortcuts.toggleDarkMode`)}]}],[e]);return(0,Q.useEffect)(()=>{function e(e){let t=e.target;t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable||e.key===`?`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),n(e=>!e))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,$.jsx)(Ae,{open:t,onOpenChange:n,children:(0,$.jsxs)(it,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(vn,{children:e(`console.shortcuts.title`)}),(0,$.jsx)(st,{children:e(`console.shortcuts.description`)})]}),(0,$.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,$.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function wi(){return null}var Ti={title:`ObjectUI Console`,initializing:`Initializing…`,steps:{connecting:`Connecting to server`,loadingConfig:`Loading configuration`,preparingWorkspace:`Preparing workspace`},error:{connectionFailed:`Cannot connect to server`,checkServer:`Please check your network connection or that the backend is running.`},actions:{retry:`Retry`,retrying:`Retrying…`}};function Ei({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Q.useState)(0),o=(0,Q.useMemo)(()=>[Ti.steps.connecting,Ti.steps.loadingConfig,Ti.steps.preparingWorkspace],[]);return(0,Q.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,o.length-1))},1200);return()=>clearInterval(n)},[e,t,o.length]),(0,$.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,$.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,$.jsx)(be,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,$.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,$.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:Ti.title}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:Ti.initializing})]}),t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-5 rounded-lg border border-destructive/30 bg-destructive/5 w-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,$.jsx)(Te,{className:`h-5 w-5 shrink-0`}),(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:Ti.error.connectionFailed})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:Ti.error.checkServer})]}),n&&(0,$.jsx)(X,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(q,{className:`h-4 w-4 animate-spin`}),Ti.actions.retrying]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(St,{className:`h-4 w-4`}),Ti.actions.retry]})})]}):e?(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,$.jsx)(kn,{className:`h-4 w-4 text-primary`}),(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:o.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 text-sm transition-opacity duration-300`,style:{opacity:t<=i?1:.3},children:[t<i?(0,$.jsx)(Nn,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,$.jsx)(q,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,$.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,$.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}var Di=1e4,Oi={timeout:`Connection timed out after 10 seconds.`,serverUnreachable:e=>`The server at ${e} is unreachable.`};function ki({children:e,authUrl:t}){let[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(void 0),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useCallback)(async(e=!1)=>{e&&d(!0),l(null);let t=`https://demo.objectstack.ai`,n=`${t.replace(/\/$/,``)}/api/v1/discovery`;try{let e=await L(t,async()=>{let e=new AbortController,t=setTimeout(()=>e.abort(),Di);try{let t=await fetch(n,{credentials:`include`,signal:e.signal});if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();return r&&typeof r.success==`boolean`&&`data`in r?r.data:r}catch(e){throw e.name===`AbortError`?Error(`timeout`):e}finally{clearTimeout(t)}});if(!e)throw Error(`empty discovery response`);e?.mode===`preview`?(a({autoLogin:e.previewMode?.autoLogin??!0,simulatedRole:e.previewMode?.simulatedRole??`admin`,simulatedUserName:e.previewMode?.simulatedUserName??`Preview User`,readOnly:e.previewMode?.readOnly??!1,expiresInSeconds:e.previewMode?.expiresInSeconds??0,bannerMessage:e.previewMode?.bannerMessage}),r(!1)):r(e?.services?.auth?.enabled??!0),s(!1)}catch(e){let t=e,r;r=t.message===`timeout`?Oi.timeout:t.message?.startsWith(`HTTP `)?`${Oi.serverUnreachable(n)} (${t.message})`:`${Oi.serverUnreachable(n)}${t.message?` (${t.message})`:``}`,console.warn(`[ConditionalAuthWrapper] Discovery failed:`,t),l(r),s(!0)}finally{d(!1)}},[]);return(0,Q.useEffect)(()=>{f()},[f]),o?(0,$.jsx)(Ei,{error:c,onRetry:c?()=>f(!0):void 0,retrying:u}):i?(0,$.jsx)(N,{authUrl:t,previewMode:i,children:e}):n?(0,$.jsx)(N,{authUrl:t,children:e}):(0,$.jsx)(N,{authUrl:t,enabled:!1,children:e})}function Ai(e){let{theme:t=`system`}=Lr();return(0,$.jsx)(ue,{theme:t,className:`toaster group`,icons:{success:(0,$.jsx)(Nn,{className:`h-4 w-4`}),info:(0,$.jsx)(Tt,{className:`h-4 w-4`}),warning:(0,$.jsx)(On,{className:`h-4 w-4`}),error:(0,$.jsx)(Kt,{className:`h-4 w-4`}),loading:(0,$.jsx)(q,{className:`h-4 w-4 animate-spin`})},toastOptions:{classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})}function ji({error:e,onReset:t}){let{t:n}=w();return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,$.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,$.jsxs)(xn,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,$.jsx)(On,{className:`h-6 w-6 text-destructive`})}),(0,$.jsx)(wt,{children:n(`console.errors.somethingWentWrong`)}),(0,$.jsx)(Jt,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,$.jsx)(je,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,$.jsxs)(X,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,$.jsx)(Ge,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Mi=class extends Q.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary] Caught error:`,e,t),this.props.onError?.(e,t)}resetErrorBoundary=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?typeof this.props.fallback==`function`?this.props.fallback({error:this.state.error,reset:this.resetErrorBoundary}):this.props.fallback:(0,$.jsx)(ji,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}};function Ni({sections:e,open:t}){if(!t)return null;let[n,r]=(0,Q.useState)([`0`]),[i,a]=(0,Q.useState)(null),o=async(e,t)=>{try{await navigator.clipboard.writeText(JSON.stringify(e,null,2)),a(t),setTimeout(()=>a(null),2e3)}catch(e){console.error(`Failed to copy:`,e)}},s=e=>{r(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])};return(0,$.jsxs)(`div`,{className:`w-80 border-l bg-background p-0 overflow-hidden flex flex-col shrink-0 z-20 transition-all`,children:[(0,$.jsxs)(`div`,{className:`px-4 py-3 border-b bg-muted/5 flex items-center justify-between`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:`Metadata Inspector`}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60`,children:`JSON`})]}),(0,$.jsx)(`div`,{className:`flex-1 overflow-auto`,children:e.map((e,t)=>{let r=String(t),a=n.includes(r),c=i===t;return(0,$.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 hover:bg-muted/5 transition-colors`,children:[(0,$.jsxs)(`button`,{onClick:()=>s(r),className:`flex-1 flex items-center justify-between text-left`,children:[(0,$.jsx)(`h4`,{className:`text-xs font-semibold text-foreground`,children:e.title}),a?(0,$.jsx)(sn,{className:`h-3 w-3 text-muted-foreground ml-2`}):(0,$.jsx)(lt,{className:`h-3 w-3 text-muted-foreground ml-2`})]}),(0,$.jsx)(`button`,{onClick:()=>o(e.data,t),className:`p-1 hover:bg-muted rounded transition-colors ml-2`,title:`Copy JSON`,children:c?(0,$.jsx)(Pt,{className:`h-3 w-3 text-green-600`}):(0,$.jsx)(En,{className:`h-3 w-3 text-muted-foreground`})})]}),a&&(0,$.jsx)(`div`,{className:`px-4 pb-4`,children:(0,$.jsx)(`div`,{className:`relative rounded-md border border-border/50 bg-muted/5 overflow-hidden`,children:(0,$.jsx)(`pre`,{className:`text-[11px] leading-relaxed p-3 overflow-auto max-h-96 font-mono text-foreground/90`,children:JSON.stringify(e.data,null,2)})})})]},t)})})]})}function Pi(){let[e,t]=(0,Q.useState)((0,Q.useMemo)(()=>{try{return typeof window<`u`?x(window.location.search).enabled:!1}catch{return!1}},[]));return{showDebug:e,toggleDebug:()=>t(e=>!e)}}function Fi({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s}){let{t:c}=w(),l=(0,Q.useRef)(null),u=(0,Q.useMemo)(()=>({id:`view_${Date.now()}`,label:c(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[],showSearch:!0,showFilters:!0,showSort:!0}),[]),d=(0,Q.useMemo)(()=>({...r}),[n===`create`?`create`:r.id]),{draft:f,isDirty:p,updateField:m,discard:h,undo:g,redo:_,canUndo:v,canRedo:y}=dt(n===`create`?u:d,{mode:n,onUpdate:a});(0,Q.useEffect)(()=>{e&&l.current&&l.current.focus()},[e]);let b=(0,Q.useMemo)(()=>tr(i),[i.fields]),x=(0,Q.useMemo)(()=>Qn(f.filter),[f.filter]),S=(0,Q.useMemo)(()=>Xn(f.sort),[f.sort]),C=(0,Q.useMemo)(()=>rr({t:c,fieldOptions:b,objectDef:i,updateField:m,filterGroupValue:x,sortItemsValue:S,essentialOnly:!0}),[c,b,i,m,x,S]),T=f.type||`grid`,E=(0,Q.useMemo)(()=>({...C,breadcrumb:[c(`console.objectView.page`),$n[T]||T]}),[C,c,T]),D=(0,Q.useCallback)(()=>{n===`create`?s?.(f):o?.(f),h()},[f,o,s,n,h]),O=(0,Q.useCallback)(()=>{if(n===`create`){t();return}h()},[h,n,t]),ee=c(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return(0,$.jsx)(Tn,{open:e,onClose:t,schema:E,draft:f,isDirty:p,onFieldChange:m,onSave:D,onDiscard:O,onUndo:g,onRedo:_,canUndo:v,canRedo:y,undoLabel:c(`designer.undo`),redoLabel:c(`designer.redo`),objectDef:i,saveLabel:c(`console.objectView.save`),discardLabel:c(`console.objectView.discard`),panelRef:l,role:`complementary`,ariaLabel:ee,tabIndex:-1,testId:`view-config-panel`,closeTitle:c(`console.objectView.closePanel`),footerTestId:`view-config-footer`,saveTestId:`view-config-save`,discardTestId:`view-config-discard`,className:`transition-all overflow-hidden`})}function Ii(e){return[{type:`grid`,icon:Mn,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:un,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:fn,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Gt,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:cn,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:Se,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:We,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:_e,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function Li(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Ri={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,filter:e=>e.type===`select`||e.type===`boolean`}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,filter:e=>e.type===`date`}],timeline:[{key:`dateField`,i18nKey:`console.objectView.dateField`,filter:e=>e.type===`date`}],gantt:[{key:`dateField`,i18nKey:`console.objectView.dateField`,filter:e=>e.type===`date`}],gallery:[{key:`imageField`,i18nKey:`console.objectView.imageField`}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,filter:e=>e.type===`number`},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,filter:e=>e.type===`number`}]};function zi({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=w(),s=(0,Q.useMemo)(()=>Ii(o),[o]),c=(0,Q.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,Q.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,Q.useMemo)(()=>a?tr(a):[],[a]),[d,f]=(0,Q.useState)(c[0]?.type??`grid`),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)({});(0,Q.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,Q.useEffect)(()=>{h||m(Li(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Ri[d]??[],b=e=>_[`${d}.${e}`]??``,x=(e,t)=>v(n=>({...n,[`${d}.${e}`]:t})),S=p.trim(),C=S.length>0&&l.has(S),T=y.every(e=>b(e.key).length>0),E=S.length>0&&!C&&T;(0,Q.useEffect)(()=>{y.length===0||u.length===0||y.forEach(e=>{if(b(e.key).length>0)return;let t=e.filter?u.filter(e.filter):u;t.length===1&&x(e.key,t[0].value)})},[d,u]);let D=()=>{if(!E)return;let e={};y.forEach(t=>{let n=b(t.key);n&&(e[t.key]=n)});let r={type:d,label:S};Object.keys(e).length>0&&(r[d]=e),n(r),t(!1)};return(0,$.jsx)(Ae,{open:e,onOpenChange:t,children:(0,$.jsxs)(it,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(vn,{children:o(`console.objectView.createView`)}),(0,$.jsx)(st,{children:o(`console.objectView.createViewDesc`)})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-4 gap-2 py-2`,"data-testid":`create-view-type-grid`,children:c.map(({type:e,label:t,description:n,icon:r})=>{let i=e===d;return(0,$.jsxs)(`button`,{type:`button`,"data-testid":`create-view-type-${e}`,"aria-pressed":i,onClick:()=>f(e),className:K(`group flex flex-col items-start gap-1 rounded-lg border bg-background p-3 text-left transition-colors`,`hover:border-primary/60 hover:bg-accent/40`,i?`border-primary ring-2 ring-primary/30 bg-accent/40`:`border-border`),children:[(0,$.jsx)(r,{className:K(`h-5 w-5`,i?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,$.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,$.jsx)(`div`,{className:`text-[10px] leading-tight text-muted-foreground line-clamp-2`,children:n})]},e)})}),y.length>0&&(0,$.jsx)(`div`,{className:`space-y-2 rounded-md border border-dashed bg-muted/30 p-3`,"data-testid":`create-view-required-fields`,children:y.map(e=>{let t=b(e.key),n=e.filter?u.filter(e.filter):u,r=u.length>0&&n.length===0;return(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,$.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,$.jsxs)(`select`,{id:`create-view-required-${e.key}`,"data-testid":`create-view-required-${e.key}`,value:t,onChange:t=>x(e.key,t.target.value),disabled:r,className:K(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,$.jsx)(`option`,{value:``,children:o(`console.objectView.selectField`)}),n.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),r&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,$.jsx)(Te,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,$.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,$.jsx)(Y,{id:`create-view-name-input`,"data-testid":`create-view-name-input`,autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(!0)},onKeyDown:e=>{e.key===`Enter`&&E&&D()},placeholder:o(`console.objectView.newView`),className:`h-9`}),C&&(0,$.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,$.jsxs)(Oe,{className:`mt-2`,children:[(0,$.jsx)(X,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,$.jsx)(X,{type:`button`,disabled:!E,onClick:D,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}var Bi=(0,Q.lazy)(()=>l(()=>import(`./plugin-charts-CJxtgGBd.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]))),Vi={grid:Yt,kanban:un,calendar:fn,gallery:Mn,timeline:xe,gantt:Dt,map:Ve,chart:_e},Hi={id:`current-user`,name:`Demo User`};function Ui({objectDef:e,recordId:t,dataSource:n,onEdit:r}){let{user:i}=M(),a=i?{id:i.id,name:i.name,avatar:i.image}:Hi,[o,s]=(0,Q.useState)([]);(0,Q.useEffect)(()=>{if(!n||!e?.name||!t)return;let r=`${e.name}:${t}`;n.find(`sys_comment`,{$filter:{threadId:r},$orderby:{createdAt:`asc`}}).then(e=>{e.data?.length&&s(e.data.map(e=>({id:e.id,type:`comment`,actor:e.author?.name??`Unknown`,actorAvatarUrl:e.author?.avatar,body:e.content,createdAt:e.createdAt,updatedAt:e.updatedAt,parentId:e.parentId,reactions:e.reactions?Object.entries(e.reactions).map(([e,t])=>({emoji:e,count:t.length,reacted:t.includes(a.id)})):void 0})))}).catch(()=>{})},[n,e?.name,t,a.id]);let c=(0,Q.useCallback)(async r=>{let i={id:crypto.randomUUID(),type:`comment`,actor:a.name,actorAvatarUrl:`avatar`in a?a.avatar:void 0,body:r,createdAt:new Date().toISOString()};if(s(e=>[...e,i]),n){let o=`${e.name}:${t}`;n.create(`sys_comment`,{id:i.id,threadId:o,author:a,content:r,mentions:[],createdAt:i.createdAt}).catch(()=>{})}},[a,n,e?.name,t]),l=(0,Q.useCallback)(async(r,i)=>{let o={id:crypto.randomUUID(),type:`comment`,actor:a.name,actorAvatarUrl:`avatar`in a?a.avatar:void 0,body:i,createdAt:new Date().toISOString(),parentId:r};if(s(e=>[...e,o].map(e=>e.id===r?{...e,replyCount:(e.replyCount??0)+1}:e)),n){let s=`${e.name}:${t}`;n.create(`sys_comment`,{id:o.id,threadId:s,author:a,content:i,mentions:[],createdAt:o.createdAt,parentId:r}).catch(()=>{})}},[a,n,e?.name,t]),u=(0,Q.useCallback)((e,t)=>{s(r=>r.map(r=>{if(r.id!==e)return r;let i=[...r.reactions??[]],o=i.findIndex(e=>e.emoji===t);if(o>=0){let e=i[o];e.reacted?e.count<=1?i.splice(o,1):i[o]={...e,count:e.count-1,reacted:!1}:i[o]={...e,count:e.count+1,reacted:!0}}else i.push({emoji:t,count:1,reacted:!0});let s={...r,reactions:i};return n&&n.update(`sys_comment`,String(e),{$toggleReaction:{emoji:t,userId:a.id}}).catch(()=>{}),s}))},[a.id,n]);return(0,$.jsxs)(`div`,{className:`h-full bg-background overflow-auto p-3 sm:p-4 lg:p-6`,children:[(0,$.jsx)(Kn,{schema:{type:`detail-view`,objectName:e.name,resourceId:t,showBack:!1,showEdit:!0,title:e.label,sections:[{title:`Details`,fields:Object.keys(e.fields||{}).map(t=>({name:t,label:e.fields[t].label||t,type:e.fields[t].type||`text`}))}]},dataSource:n,onEdit:()=>r({id:t})}),(0,$.jsx)(`div`,{className:`mt-6 border-t pt-6`,children:(0,$.jsx)(Gn,{config:{position:`bottom`,collapsible:!0,defaultCollapsed:!0,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:o,onAddComment:c,onAddReply:l,onToggleReaction:u})})]})}function Wi({dataSource:e,objects:t,onEdit:n}){let r=g(),{objectName:i,viewId:o}=a(),[s,c]=f(),{showDebug:l}=Pi(),{t:u}=w(),{objectLabel:d,objectDescription:p}=re(),[m,h]=(0,Q.useState)(!1),[_,y]=(0,Q.useState)(`edit`),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),D=(0,Q.useCallback)(t=>{if(E(t),P(e=>e+1),e?.updateViewConfig){let n=i,r=t.id;n&&r?e.updateViewConfig(n,r,t).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing objectName or viewId.`)}else console.warn(`[ViewConfigPanel] dataSource.updateViewConfig is not available. View config saved locally only.`)},[e,i]),ee=(0,Q.useCallback)(async n=>{try{let a;if(e?.create){let r=t?.find?.(e=>e.name===i),o=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),s=[];Array.isArray(r?.compactLayout)&&r.compactLayout.length>0?s=r.compactLayout.filter(e=>r.fields?.[e]):r?.fields&&(s=Object.entries(r.fields).filter(([e,t])=>t&&!t.hidden&&!o.has(e)).map(([e])=>e).slice(0,5));let c=Array.isArray(n.columns)&&n.columns.length>0?n.columns:s,l={objectName:i,...n,columns:c},u=await e.create(`sys_view`,l);a=u?.id??u?._id}h(!1),y(`edit`),P(e=>e+1),a&&(o?r(`../${a}`,{relative:`path`}):r(`view/${a}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,i,t,r,o]),[k,te]=(0,Q.useState)(void 0),{user:ne}=M(),j=ne?.role===`admin`,{can:ie}=I(),N=t.find(e=>e.name===i);if(!N)return(0,$.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,$.jsxs)(xn,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,$.jsx)(Yt,{className:`h-6 w-6 text-muted-foreground`})}),(0,$.jsx)(wt,{children:u(`console.objectView.objectNotFound`)}),(0,$.jsxs)(Jt,{children:[u(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,u(`console.objectView.objectNotFoundHint`)]})]})});let[ae,P]=(0,Q.useState)(0),[F,oe]=(0,Q.useState)([]);(0,Q.useEffect)(()=>{let t=!1;if(!e?.find||!i){oe([]);return}return e.find(`sys_view`,{$filter:[`objectName`,`=`,i],$orderby:[{field:`created_at`,order:`asc`}],$top:200}).then(e=>{t||oe((Array.isArray(e)?e:Array.isArray(e?.data)?e.data:Array.isArray(e?.records)?e.records:Array.isArray(e?.value)?e.value:[]).filter(e=>e&&e.objectName===i))}).catch(e=>{console.error(`[ObjectView] Failed to load sys_view records:`,e),t||oe([])}),()=>{t=!0}},[e,i,ae]);let L=(0,Q.useMemo)(()=>{let e=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),t=()=>Array.isArray(N.compactLayout)&&N.compactLayout.length>0?N.compactLayout.filter(e=>N.fields?.[e]):N.fields?Object.entries(N.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=N.listViews||N.list_views||{},r=Object.entries(n).map(([e,t])=>({id:e,...t,type:t.type||`grid`}));r.length===0&&r.push({id:`all`,label:u(`console.objectView.allRecords`),type:`grid`,columns:t()});let i=new Set(r.map(e=>e.id));for(let e of F){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t};if(i.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...n}}else r.push(n)}let a=new Set([`grid`,`list`,`table`]);for(let e of r)a.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let o=new Map(r.map((e,t)=>[e.id,t])),s=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${N.name}`):null;e&&(s=JSON.parse(e))}catch{}let c=new Map(s.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=c.get(e.id),r=c.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=F.find(t=>(t.id||t._id)===e.id),a=F.find(e=>(e.id||e._id)===t.id);if(!i&&!a)return(o.get(e.id)??0)-(o.get(t.id)??0);if(!i)return-1;if(!a)return 1;let s=typeof i.sortOrder==`number`?i.sortOrder:2**53-1,l=typeof a.sortOrder==`number`?a.sortOrder:2**53-1;return s===l?(i.created_at||``).localeCompare(a.created_at||``):s-l}),r},[N,F,u]),ce=(0,Q.useMemo)(()=>L.find(e=>e.isDefault)?.id,[L]),R=o||s.get(`view`)||ce||L[0]?.id,le=L.find(e=>e.id===R)||L[0],z=T&&T.id===le?.id?{...le,...T}:le,ue=(0,Q.useCallback)((e,t)=>{E(n=>({...n||{},id:le?.id,[e]:t}))},[le?.id]),H=e=>{let t=L.find(t=>t.id===e);t&&(t.id!==R&&h(!1),o?r(`../${t.id}`,{relative:`path`}):r(`view/${t.id}`))},de=(0,Q.useCallback)(()=>{x(!0)},[]),he=(0,Q.useCallback)((e,t)=>{if(e===`settings`){let e=L.find(e=>e.type===t);e&&H(e.id),y(`edit`),h(!0)}},[L,H]),U=(0,Q.useCallback)(e=>F.some(t=>(t.id||t._id)===e),[F]),ge=(0,Q.useCallback)(async(t,n)=>{if(e?.update){if(!U(t)){B.error(u(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{await e.update(`sys_view`,t,{label:n}),P(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),B.error(`Failed to rename view`)}}},[e,U,u]),[_e,ve]=(0,Q.useState)({open:!1,message:``}),[ye,W]=(0,Q.useState)({open:!1,params:[]}),be=(0,Q.useCallback)((e,t)=>new Promise(n=>{ve({open:!0,message:e,options:t,resolve:n})}),[]),xe=(0,Q.useCallback)(e=>new Promise(t=>{W({open:!0,params:e,resolve:t})}),[]),Se=(0,Q.useCallback)(async t=>{if(!e?.delete)return;if(!U(t)){B.error(u(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=L.find(e=>e.id===t)?.label||t;if(await be(u(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:u(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:u(`console.objectView.delete`)||`Delete`,cancelText:u(`console.objectView.cancel`)||`Cancel`}))try{if(await e.delete(`sys_view`,t),t===R){let e=L.find(e=>e.id!==t);e&&r(o?`../${e.id}`:`view/${e.id}`,o?{relative:`path`}:void 0)}P(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),B.error(`Failed to delete view`)}},[e,U,R,L,o,r,u,be]),Ce=(0,Q.useCallback)(async t=>{if(!e?.create)return;let n=L.find(e=>e.id===t);if(n)try{let{id:a,created_at:s,updated_at:c,...l}=n,u=`view_${Date.now()}`,d={...l,objectName:i,id:u,label:`${n.label||t} (Copy)`,isDefault:!1,isPinned:!1};await e.create(`sys_view`,d),P(e=>e+1),o?r(`../${u}`,{relative:`path`}):r(`view/${u}`)}catch(e){console.error(`[ViewTabBar] Failed to duplicate view:`,e),B.error(`Failed to duplicate view`)}},[e,L,i,r,o]),we=(0,Q.useCallback)(async(t,n)=>{if(e?.update){if(!U(t)){B.error(u(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{await e.update(`sys_view`,t,{isPinned:n}),P(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,U,u]),Te=(0,Q.useCallback)(async t=>{if(e?.update){if(!U(t)){B.error(u(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to mark a default.`);return}try{let n=F.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(t=>e.update(`sys_view`,t.id||t._id,{isDefault:!1}));n.push(e.update(`sys_view`,t,{isDefault:!0})),await Promise.all(n),P(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),B.error(`Failed to set default view`)}}},[e,F,U,u]),Ee=(0,Q.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${i}`,JSON.stringify(t))}catch{}if(e?.update){let n=new Set(F.map(e=>e.id||e._id)),r=t.filter(e=>n.has(e)).map((t,n)=>e.update(`sys_view`,t,{sortOrder:n}));try{await Promise.all(r)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}P(e=>e+1)},[e,F,i]),De=(0,Q.useCallback)(e=>{if(!U(e)){B.error(u(`console.objectView.cannotEditMetaView`)||`System view — duplicate it to make changes.`);return}e!==R&&H(e),y(`edit`),h(!0)},[R,H,U,u]),Oe=(0,Q.useCallback)(()=>{x(!0)},[]),ke=Sr({objectName:N.name,objectLabel:N.label,dataSource:e,onEdit:n,onRefresh:()=>P(e=>e+1)}),Ae=ne?{id:ne.id,name:ne.name,avatar:ne.image}:Hi,G=(0,Q.useCallback)((e,t)=>{t?.type===`error`?B.error(e):B.success(e)},[]),je=(0,Q.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):r(e)},[r]),Me=(0,Q.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};typeof e.execute==`function`?await e.execute(N.name,n,r):r.recordId&&Object.keys(r).length>1&&typeof e.update==`function`&&await e.update(N.name,r.recordId,r);let i=t.refreshAfter!==!1;return i&&P(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,N.name]),Ne=(0,Q.useMemo)(()=>se(),[]),Pe=(0,Q.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=e.params||{},r=await Ne(`https://demo.objectstack.ai/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,objectName:N.name,params:n})}),i=await r.json().catch(()=>null);if(!r.ok||i&&i.success===!1)return{success:!1,error:i?.error||`Flow "${t}" failed (HTTP ${r.status})`};let a=e.refreshAfter!==!1;return a&&P(e=>e+1),{success:!0,data:i?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Ne,N.name]),Fe=(0,Q.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{};try{let r=e.objectName||N.name||`global`,i=await Ne(`https://demo.objectstack.ai/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:n.recordId,params:n})}),a=await i.json().catch(()=>null);if(!i.ok||a&&a.success===!1)return{success:!1,error:a?.error||`Action "${t}" failed (HTTP ${i.status})`};let o=e.refreshAfter!==!1;return o&&P(e=>e+1),{success:!0,data:a?.data,reload:o}}catch(e){return{success:!1,error:e.message}}},[Ne,N.name]),{lastMessage:Ie}=pe({channel:`object:${N.name}`}),{hasConflicts:Le,resolveAllConflicts:Re}=V(N.name?`user-${N.name}`:`current-user`);(0,Q.useEffect)(()=>{Ie&&(Le&&Re(`remote`),P(e=>e+1))},[Ie,Le,Re]),(0,Q.useEffect)(()=>{e?.find&&N.name&&e.find(N.name,{limit:0}).then(e=>{typeof e?.total==`number`?te(e.total):Array.isArray(e?.data)?te(e.data.length):Array.isArray(e)&&te(e.length)}).catch(()=>{})},[e,N.name,ae]);let ze=(0,Q.useMemo)(()=>z?.navigation??N.navigation??{mode:`page`},[z?.navigation,N.navigation]),Be=s.get(`recordId`),Ve=(0,Q.useCallback)((e,t)=>{if(t===`new_window`){let t=window.location.pathname.replace(/\/view\/.*$/,``);window.open(`${t}/record/${encodeURIComponent(String(e))}`,`_blank`);return}o?r(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`}):r(`record/${encodeURIComponent(String(e))}`)},[r,o]),K=A({navigation:ze,objectName:N.name,onNavigate:Ve}),He=()=>{K.close();let e=new URLSearchParams(s);e.delete(`recordId`),c(e)};(0,Q.useEffect)(()=>{Be&&!K.isOpen?K.open({id:Be}):!Be&&K.isOpen&&K.close()},[Be]);let Ue=(0,Q.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:a})=>{let o=ae+(a||0),s=`${i}-${z.id}-${o}`,c=z;if(c.type===`chart`){let e=c.chart||{};return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,$.jsx)(Bi,{dataSource:t,schema:{type:`object-chart`,objectName:N.name,chartType:e.chartType,xAxisField:e.xAxisField,yAxisFields:e.yAxisFields,aggregation:e.aggregation,series:e.series,config:e.config,filter:e.filter}})},s)}return(0,$.jsx)(qn,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,inlineEdit:c.inlineEdit??c.editRecordsInline??e.inlineEdit,appearance:c.showDescription==null?e.appearance:{showDescription:c.showDescription},showSearch:c.showSearch??e.showSearch,showSort:c.showSort??e.showSort,showFilters:c.showFilters??e.showFilters,showHideFields:c.showHideFields??e.showHideFields,showGroup:c.showGroup??e.showGroup,showColor:c.showColor??e.showColor,showDensity:c.showDensity??e.showDensity,allowExport:c.allowExport??e.allowExport,exportOptions:c.allowExport===!1?void 0:c.exportOptions??e.exportOptions,striped:c.striped??e.striped,bordered:c.bordered??e.bordered,color:c.color??e.color,wrapHeaders:c.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:c.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:c.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:c.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:c.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:c.fieldTextColor??e.fieldTextColor,prefixField:c.prefixField??e.prefixField,showDescription:c.showDescription??e.showDescription,navigation:c.navigation??e.navigation,selection:c.selection??e.selection,pagination:c.pagination??e.pagination,searchableFields:c.searchableFields??e.searchableFields,filterableFields:c.filterableFields??e.filterableFields,resizable:c.resizable??e.resizable,hiddenFields:c.hiddenFields??e.hiddenFields,rowActions:c.rowActions??e.rowActions,bulkActions:c.bulkActions??e.bulkActions,sharing:c.sharing??e.sharing,addRecord:c.addRecord??e.addRecord,conditionalFormatting:c.conditionalFormatting??e.conditionalFormatting,quickFilters:c.quickFilters??e.quickFilters,userFilters:c.userFilters??e.userFilters,showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,virtualScroll:c.virtualScroll??e.virtualScroll,emptyState:c.emptyState??e.emptyState,aria:c.aria??e.aria,tabs:e.tabs,...c.filter?.length?{filters:c.filter}:{},...c.sort?.length?{sort:c.sort}:{},options:{kanban:{groupBy:c.kanban?.groupByField||c.kanban?.groupField||`status`,groupField:c.kanban?.groupByField||c.kanban?.groupField||`status`,titleField:c.kanban?.titleField||N.titleField||`name`,cardFields:c.kanban?.columns},calendar:{startDateField:c.calendar?.startDateField||`due_date`,endDateField:c.calendar?.endDateField,titleField:c.calendar?.titleField||`name`,colorField:c.calendar?.colorField,allDayField:c.calendar?.allDayField,defaultView:c.calendar?.defaultView},timeline:{dateField:c.timeline?.dateField||`due_date`,titleField:c.timeline?.titleField||N.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||N.titleField||`name`,latitudeField:c.map?.latitudeField,longitudeField:c.map?.longitudeField,zoom:c.map?.zoom,center:c.map?.center},gallery:{...c.gallery||{},imageField:c.gallery?.imageField||c.gallery?.coverField||`image`,coverField:c.gallery?.coverField||c.gallery?.imageField,titleField:c.gallery?.titleField||N.titleField||`name`,subtitleField:c.gallery?.subtitleField},gantt:{startDateField:c.gantt?.startDateField||`start_date`,endDateField:c.gantt?.endDateField||`end_date`,titleField:c.gantt?.titleField||`name`,progressField:c.gantt?.progressField,dependenciesField:c.gantt?.dependenciesField,colorField:c.gantt?.colorField},chart:{chartType:c.chart?.chartType,xAxisField:c.chart?.xAxisField,yAxisFields:c.chart?.yAxisFields,aggregation:c.chart?.aggregation,series:c.chart?.series,config:c.chart?.config}}},className:r,onEdit:n,onRowClick:e=>{K.handleClick(e)},dataSource:t},s)},[z,N,i,ae,K]),We=(0,Q.useMemo)(()=>L.map(e=>e.id===R&&T&&T.id===e.id?{...e,...T}:e),[L,R,T]),Ge=(0,Q.useMemo)(()=>({type:`object-view`,objectName:N.name,layout:`page`,showSearch:z?.showSearch!==!1,showFilters:z?.showFilters!==!1,showSort:z?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:j,viewActions:j?[{type:`settings`},{type:`share`},{type:`duplicate`},{type:`delete`}]:[],onNavigate:(e,t)=>{t===`edit`?n?.({id:e}):t===`view`&&(o?r(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`}):r(`record/${encodeURIComponent(String(e))}`))}}),[N.name,n,z?.showSearch,z?.showFilters,z?.showSort,r,o,j]);return(0,$.jsxs)(O,{context:{objectName:N.name,user:Ae},onConfirm:be,onToast:G,onNavigate:je,onParamCollection:xe,handlers:{api:Me,flow:Pe,script:Fe,modal:Fe},children:[(0,$.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between items-center py-2.5 sm:py-3 px-3 sm:px-4 border-b shrink-0 bg-background z-10`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`bg-primary/10 p-1.5 sm:p-2 rounded-md shrink-0`,children:(0,$.jsx)(Jr(N?.icon),{className:`h-4 w-4 text-primary`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`text-base sm:text-lg font-semibold tracking-tight text-foreground truncate`,children:d(N)}),N.description&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground truncate hidden sm:block max-w-md`,children:p(N)})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:[ie(N.name,`create`)&&(0,$.jsxs)(X,{size:`sm`,onClick:ke.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,$.jsx)(Qt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:u(`console.objectView.new`)})]}),N.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,$.jsx)(v,{schema:{type:`action:bar`,location:`list_toolbar`,actions:N.actions,size:`sm`,variant:`outline`}})]})]}),L.length>=1&&(()=>{let e=L.map(e=>{let t=F.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:e.label,type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?u(`console.objectView.systemViewReadonly`)||`System view defined in code — duplicate to customize.`:void 0}});return(0,$.jsxs)(`div`,{className:`border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,$.jsx)(nr,{views:e,activeViewId:R,onViewChange:H,viewTypeIcons:Vi,config:{reorderable:!1,showAddButton:j,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:j?Oe:void 0,onRenameView:j?ge:void 0,onDeleteView:j?Se:void 0,onDuplicateView:j?Ce:void 0,onPinView:j?we:void 0,onSetDefaultView:j?Te:void 0,onConfigView:j?De:void 0,onManageViews:j?()=>C(!0):void 0}),j&&(0,$.jsx)(er,{open:S,onOpenChange:C,views:e,activeViewId:R,viewTypeIcons:Vi,onRename:ge,onDelete:Se,onDuplicate:Ce,onSetDefault:Te,onSetPinned:we,onReorder:Ee,onAddView:Oe,onConfigView:De})]})})(),(0,$.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[K.mode===`split`&&K.isOpen?(0,$.jsx)(ln,{...K,setIsOpen:e=>{e||He()},title:d(N),mainContent:(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,$.jsx)(`div`,{className:`flex-1 relative overflow-auto p-3 sm:p-4`,children:(0,$.jsx)(Zn,{schema:Ge,dataSource:e,views:We,activeViewId:R,onViewChange:H,onEdit:e=>n?.(e),onRowClick:e=>{K.handleClick(e)},renderListView:Ue,onCreateView:de,onViewAction:he})}),typeof k==`number`&&(0,$.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:u(`console.objectView.recordCount`,{count:k})})]}),children:t=>(0,$.jsx)(Ui,{objectDef:N,recordId:t.id||t._id,dataSource:e,onEdit:n})}):(0,$.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,$.jsx)(`div`,{className:`flex-1 relative overflow-auto p-3 sm:p-4`,children:(0,$.jsx)(Zn,{schema:Ge,dataSource:e,views:We,activeViewId:R,onViewChange:H,onEdit:e=>n?.(e),onRowClick:e=>{K.handleClick(e)},renderListView:Ue,onCreateView:de,onViewAction:he})})}),(0,$.jsx)(Ni,{open:l&&j,sections:[{title:`View Configuration`,data:z},{title:`Object Definition`,data:N}]}),(0,$.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${m&&j?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,$.jsx)(Fi,{open:m&&j,onClose:()=>{h(!1),y(`edit`)},mode:_,activeView:z,objectDef:N,recordCount:k,onSave:D,onViewUpdate:ue,onCreate:ee})}),(0,$.jsx)(zi,{open:b&&j,onOpenChange:x,existingLabels:L.map(e=>e.label).filter(Boolean),objectDef:N,onCreate:e=>ee(e)})]}),K.mode!==`split`&&(0,$.jsx)(ln,{...K,setIsOpen:e=>{e||He()},title:N.label,className:K.mode===`drawer`?`w-[90vw] sm:max-w-2xl p-0 overflow-hidden`:void 0,children:t=>(0,$.jsx)(Ui,{objectDef:N,recordId:t.id||t._id,dataSource:e,onEdit:n})})]}),(0,$.jsx)(me,{state:_e,onOpenChange:e=>{e||ve({open:!1,message:``})}}),(0,$.jsx)(fe,{state:ye,onOpenChange:e=>{e||W({open:!1,params:[]})}})]})}function Gi({cards:e=6}){return(0,$.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(G,{className:`h-7 w-56`}),(0,$.jsx)(G,{className:`h-4 w-80`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:Array.from({length:4}).map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-2`,children:[(0,$.jsx)(G,{className:`h-4 w-20`}),(0,$.jsx)(G,{className:`h-8 w-24`}),(0,$.jsx)(G,{className:`h-3 w-16`})]},`stat-${t}`))}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:e}).map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border p-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(G,{className:`h-5 w-32`}),(0,$.jsx)(G,{className:`h-5 w-5 rounded-full`})]}),(0,$.jsx)(G,{className:`h-40 w-full`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(G,{className:`h-3 w-16`}),(0,$.jsx)(G,{className:`h-3 w-12`})]})]},`widget-${t}`))})]})}function Ki({fields:e=8,columns:t=2}){return(0,$.jsxs)(`div`,{className:`w-full space-y-6 p-4 sm:p-6`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(G,{className:`h-8 w-8 rounded`}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(G,{className:`h-6 w-48`}),(0,$.jsx)(G,{className:`h-4 w-32`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(G,{className:`h-9 w-20`}),(0,$.jsx)(G,{className:`h-9 w-20`})]})]}),(0,$.jsx)(G,{className:`h-5 w-24`}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 ${t===2?`md:grid-cols-2`:``} gap-4`,children:Array.from({length:e}).map((e,t)=>(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(G,{className:`h-4 w-24`}),(0,$.jsx)(G,{className:`h-9 w-full`})]},`field-${t}`))}),(0,$.jsxs)(`div`,{className:`space-y-3 pt-4 border-t`,children:[(0,$.jsx)(G,{className:`h-5 w-32`}),(0,$.jsx)(`div`,{className:`space-y-2`,children:Array.from({length:3}).map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 py-2`,children:[(0,$.jsx)(G,{className:`h-8 w-8 rounded-full`}),(0,$.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,$.jsx)(G,{className:`h-4 w-40`}),(0,$.jsx)(G,{className:`h-3 w-24`})]})]},`related-${t}`))})]})]})}function qi(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function Ji(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var Yi=class{constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=qi(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(Ji)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function Xi(){let e=D();return(0,Q.useMemo)(()=>e?new Yi(e):null,[e])}var Zi=0;function Qi(e=`nav`){return`${e}_${Date.now()}_${++Zi}`}function $i(e,t){return[...e,t]}function ea(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:ea(e.children,t,n)}:e)}function ta(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:ta(i.children,t,n,r)}:i})}function na(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function ra(){let e=D(),{apps:t,refresh:n}=k(),r=(0,Q.useRef)(e);r.current=e;let i=(0,Q.useRef)(n);i.current=n;let a=(0,Q.useCallback)(async(e,t)=>{let n=r.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await i.current?.()},[]),o=(0,Q.useCallback)(e=>t.find(t=>t.name===e),[t]),s=(0,Q.useCallback)(async(e,t,n)=>{let r=o(e);if(!r)return;let i=r.navigation??[],s=$i(i,{id:Qi(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),c={...r,navigation:s};try{await a(e,c),B.success(`Navigation updated: added page "${n||t}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...r,navigation:i}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),c=(0,Q.useCallback)(async(e,t,n)=>{let r=o(e);if(!r)return;let i=r.navigation??[],s=$i(i,{id:Qi(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),c={...r,navigation:s};try{await a(e,c),B.success(`Navigation updated: added dashboard "${n||t}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...r,navigation:i}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),l=(0,Q.useCallback)(async(e,t)=>{let n=o(e);if(!n)return;let r=n.navigation??[],i=ea(r,`page`,t);if(na(i,r))return;let s={...n,navigation:i};try{await a(e,s),B.success(`Navigation updated: removed page "${t}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...n,navigation:r}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),u=(0,Q.useCallback)(async(e,t)=>{let n=o(e);if(!n)return;let r=n.navigation??[],i=ea(r,`dashboard`,t);if(na(i,r))return;let s={...n,navigation:i};try{await a(e,s),B.success(`Navigation updated: removed dashboard "${t}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...n,navigation:r}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),d=(0,Q.useCallback)(async(e,t,n)=>{let r=o(e);if(!r)return;let i=r.navigation??[],s=ta(i,`page`,t,n);if(na(s,i))return;let c={...r,navigation:s};try{await a(e,c),B.success(`Navigation updated: renamed page "${t}" → "${n}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...r,navigation:i}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),f=(0,Q.useCallback)(async(e,t,n)=>{let r=o(e);if(!r)return;let i=r.navigation??[],s=ta(i,`dashboard`,t,n);if(na(s,i))return;let c={...r,navigation:s};try{await a(e,c),B.success(`Navigation updated: renamed dashboard "${t}" → "${n}"`,{action:{label:`Undo`,onClick:async()=>{try{await a(e,{...r,navigation:i}),B.info(`Navigation change undone`)}catch{B.error(`Failed to undo navigation change`)}}}})}catch{B.error(`Failed to update navigation`)}},[o,a]),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u,syncPageRenamed:d,syncDashboardRenamed:f,syncPageCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=p(r);t&&await s(t,e,n)}},[t,s]),syncDashboardCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=p(r);t&&await c(t,e,n)}},[t,c]),syncPageDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=p(n);t&&await l(t,e)}},[t,l]),syncDashboardDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=p(n);t&&await u(t,e)}},[t,u]),syncPageRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=p(r);t&&await d(t,e,n)}},[t,d]),syncDashboardRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=p(r);t&&await f(t,e,n)}},[t,f])}}function ia(){let{pages:e,dashboards:t,apps:n}=k(),r=D(),i=(0,Q.useRef)(r);i.current=r;let{syncPageCreated:a,syncDashboardCreated:o,syncPageDeleted:s,syncDashboardDeleted:c}=ra(),l=(0,Q.useRef)(null),u=(0,Q.useRef)(null),d=(0,Q.useRef)(0),f=(0,Q.useRef)(!1),p=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Q.useEffect)(()=>{if(f.current)return;let r=new Set((e??[]).map(e=>e.name).filter(Boolean)),i=new Set((t??[]).map(e=>e.name).filter(Boolean)),m=l.current,h=u.current;if(m===null||h===null){l.current=r,u.current=i;return}let g=[...r].filter(e=>!m.has(e)),_=[...m].filter(e=>!r.has(e)),v=[...i].filter(e=>!h.has(e)),y=[...h].filter(e=>!i.has(e));if(g.length===0&&_.length===0&&v.length===0&&y.length===0){l.current=r,u.current=i;return}let b=++d.current;f.current=!0;let x=!1;return(async()=>{try{for(let e of n){if(x||d.current!==b)break;let t=p(e);if(t){for(let e of g){if(x)break;await a(t,e)}for(let e of _){if(x)break;await s(t,e)}for(let e of v){if(x)break;await o(t,e)}for(let e of y){if(x)break;await c(t,e)}}}}finally{d.current===b&&(l.current=r,u.current=i,f.current=!1)}})(),()=>{x=!0}},[e,t,n,a,o,s,c]),null}var aa=(0,Q.lazy)(()=>l(()=>import(`./RecordDetailView-DROfHlhL.js`).then(e=>e.t).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0,1]))),oa=(0,Q.lazy)(()=>l(()=>import(`./DashboardView-ClGhVUz7.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]))),sa=(0,Q.lazy)(()=>l(()=>import(`./PageView-_R84mPfp.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]))),ca=(0,Q.lazy)(()=>l(()=>import(`./ReportView-bv8vOOKb.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0]))),la=(0,Q.lazy)(()=>l(()=>import(`./SearchResultsPage-KJr5yhgC.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]))),ua=(0,Q.lazy)(()=>l(()=>import(`./RecordFormPage-BqCa2Cez.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]))),da=(0,Q.lazy)(()=>l(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]))),fa=(0,Q.lazy)(()=>l(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0]))),pa=(0,Q.lazy)(()=>l(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.PageDesignPage})),__vite__mapDeps([0]))),ma=(0,Q.lazy)(()=>l(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0])));function ha({extraRoutes:e,extraRoutesNoApp:t}={}){let[i,o]=(0,Q.useState)(`disconnected`),{user:s}=M(),l=D(),u=g(),d=c(),{appName:f}=a(),{apps:p,objects:h,loading:_,ensureType:v}=k(),{t:b}=w(),{objectLabel:x}=re(),[S,T]=(0,Q.useState)(!v);(0,Q.useEffect)(()=>{if(!v){T(!0);return}let e=!1;return Promise.all([v(`object`),v(`dashboard`),v(`report`),v(`page`)]).finally(()=>{e||T(!0)}),()=>{e=!0}},[v]);let E=p.filter(e=>e.active!==!1),O=p.find(e=>e.name===f)||E.find(e=>e.isDefault===!0)||E[0],[ee,te]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(null),[ie,N]=(0,Q.useState)(0),{addRecentItem:ae}=Dr(),{execute:P,runner:F}=C();ne({dataSource:l??void 0,onUndo:e=>{B.info(`Undo: ${e.description}`,{duration:4e3}),N(e=>e+1)},onRedo:e=>{B.info(`Redo: ${e.description}`,{duration:3e3}),N(e=>e+1)}}),(0,Q.useEffect)(()=>{F.registerHandler(`crud_success`,async e=>(te(!1),N(e=>e+1),B.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),F.registerHandler(`dialog_cancel`,async()=>(te(!1),{success:!0})),F.registerHandler(`navigate_create`,async e=>{let t=Hn({action:e,context:F.getContext?.()??{},defaultBaseUrl:`/apps/${f??``}`});return t.success?(u(t.url),{success:!0}):t}),F.registerHandler(`navigate_edit`,async e=>{let t=Vn({action:e,context:F.getContext?.()??{},defaultBaseUrl:`/apps/${f??``}`});return t.success?(u(t.url),{success:!0}):t})},[F,u,f]),(0,Q.useEffect)(()=>{if(!l)return;let e=l.onConnectionStateChange(e=>{o(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return o(l.getConnectionState()),e},[l]);let oe=d.pathname.split(`/`).filter(Boolean)[2];(oe===`view`||oe===`record`||oe===`page`||oe===`dashboard`||oe===`design`)&&(oe=``);let I=h.find(e=>e.name===oe),se=(0,Q.useCallback)(()=>{let e=I?x(I):b(`common.record`,{defaultValue:`Record`});P({type:`crud_success`,params:{message:A?b(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):b(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[P,A,I,x,b]),L=(0,Q.useCallback)(()=>{P({type:`dialog_cancel`})},[P]);(0,Q.useEffect)(()=>{if(!O)return;let e=d.pathname.split(`/`).filter(Boolean),t=e[2];(t===`view`||t===`record`||t===`page`||t===`dashboard`||t===`design`)&&(t=``);let n=`/apps/${O.name}`;if(t){let e=h.find(e=>e.name===t);e&&ae({id:`object:${e.name}`,label:e.label||e.name,href:`${n}/${e.name}`,type:`object`})}else e[2]===`dashboard`&&e[3]?ae({id:`dashboard:${e[3]}`,label:e[3].replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),href:`${n}/dashboard/${e[3]}`,type:`dashboard`}):e[2]===`report`&&e[3]&&ae({id:`report:${e[3]}`,label:e[3].replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),href:`${n}/report/${e[3]}`,type:`report`})},[d.pathname,ae]);let ce=e=>{let t=Un({objectDef:I,baseUrl:O?.name?`/apps/${O.name}`:``,record:e});if(t.kind===`page`){u(t.url);return}j(e),te(!0)},R=e=>{u(`/apps/${e}`)},ue=(0,Q.useMemo)(()=>new y({user:s?{name:s.name,email:s.email,role:s.role??`user`}:{},app:O||{},data:A||{}}),[s,O,A]);if(!l||_||!S)return(0,$.jsx)(Ei,{});let V=d.pathname.endsWith(`/create-app`),H=d.pathname.includes(`/system`);return!O&&!V&&!H?(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(xn,{children:[(0,$.jsx)(wt,{children:`No Apps Configured`}),(0,$.jsx)(Jt,{children:`No applications have been registered. Create your first app or visit System Settings to configure your environment.`}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,$.jsx)(X,{onClick:()=>u(`/create-app`),"data-testid":`create-first-app-btn`,children:`Create Your First App`}),(0,$.jsx)(X,{variant:`outline`,onClick:()=>u(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:`System Settings`})]})]})}):!O&&(V||H)?(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ei,{}),children:(0,$.jsxs)(r,{children:[(0,$.jsx)(m,{path:`create-app`,element:(0,$.jsx)(da,{})}),t]})}):(0,$.jsxs)(le,{user:s?{name:s.name,email:s.email,role:s.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:O,data:{},children:[(0,$.jsx)(ia,{}),(0,$.jsxs)(bi,{activeAppName:O.name,activeApp:O,onAppChange:R,objects:h,connectionState:i,children:[(0,$.jsx)(xi,{apps:p,activeApp:O,objects:h,onAppChange:R}),(0,$.jsx)(Ci,{}),(0,$.jsx)(wi,{}),(0,$.jsx)(Mi,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ei,{}),children:(0,$.jsxs)(r,{children:[(0,$.jsx)(m,{path:`/`,element:(0,$.jsx)(n,{to:ga(O.navigation||[]),replace:!0})}),(0,$.jsx)(m,{path:`:objectName`,element:(0,$.jsx)(Wi,{dataSource:l,objects:h,onEdit:ce})}),(0,$.jsx)(m,{path:`:objectName/new`,element:(0,$.jsx)(ua,{mode:`create`})}),(0,$.jsx)(m,{path:`:objectName/view/:viewId`,element:(0,$.jsx)(Wi,{dataSource:l,objects:h,onEdit:ce})}),(0,$.jsx)(m,{path:`:objectName/record/:recordId`,element:(0,$.jsx)(aa,{dataSource:l,objects:h,onEdit:ce},ie)}),(0,$.jsx)(m,{path:`:objectName/record/:recordId/edit`,element:(0,$.jsx)(ua,{mode:`edit`})}),(0,$.jsx)(m,{path:`dashboard/:dashboardName`,element:(0,$.jsx)(oa,{dataSource:l})}),(0,$.jsx)(m,{path:`report/:reportName`,element:(0,$.jsx)(ca,{dataSource:l})}),(0,$.jsx)(m,{path:`page/:pageName`,element:(0,$.jsx)(sa,{})}),(0,$.jsx)(m,{path:`design/page/:pageName`,element:(0,$.jsx)(pa,{})}),(0,$.jsx)(m,{path:`design/dashboard/:dashboardName`,element:(0,$.jsx)(ma,{})}),(0,$.jsx)(m,{path:`search`,element:(0,$.jsx)(la,{})}),(0,$.jsx)(m,{path:`create-app`,element:(0,$.jsx)(da,{})}),(0,$.jsx)(m,{path:`edit-app/:editAppName`,element:(0,$.jsx)(fa,{})}),e]})})}),I&&(0,$.jsx)(Yn,{schema:{type:`object-form`,formType:`modal`,objectName:I.name,mode:A?`edit`:`create`,recordId:A?.id,title:b(A?`form.editTitle`:`form.createTitle`,{object:x(I)}),description:b(A?`form.editDescription`:`form.createDescription`,{object:x(I)}),open:ee,onOpenChange:te,layout:`vertical`,fields:I.fields?Array.isArray(I.fields)?I.fields.filter(e=>typeof e==`string`?!0:z(e.visible,ue)).map(e=>typeof e==`string`?e:e.name):Object.entries(I.fields).filter(([e,t])=>z(t.visible,ue)).map(([e])=>e):[],onSuccess:se,onCancel:L,showSubmit:!0,showCancel:!0,submitText:b(`form.saveRecord`),cancelText:b(`common.cancel`)},dataSource:l},A?.id||`new`)]})]})}function ga(e){if(!e||e.length===0)return``;for(let t of e){if(t.type===`object`)return t.viewName?`${t.objectName}/view/${t.viewName}`:`${t.objectName}`;if(t.type===`page`)return t.pageName?`page/${t.pageName}`:``;if(t.type===`dashboard`)return t.dashboardName?`dashboard/${t.dashboardName}`:``;if(t.type!==`url`&&t.type===`group`&&t.children){let e=ga(t.children);if(e!==``)return e}}return``}function _a({children:e}){return(0,$.jsxs)(`div`,{className:`flex min-h-screen`,children:[(0,$.jsx)(`div`,{className:`hidden lg:flex lg:w-1/2 items-center justify-center bg-primary p-12`,children:(0,$.jsxs)(`div`,{className:`max-w-md space-y-6 text-primary-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`h-10 w-10`,role:`img`,"aria-label":`ObjectStack logo`,children:[(0,$.jsx)(`title`,{children:`ObjectStack`}),(0,$.jsx)(`path`,{d:`M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3`})]}),(0,$.jsx)(`span`,{className:`text-2xl font-bold`,children:`ObjectStack`})]}),(0,$.jsx)(`h2`,{className:`text-3xl font-bold leading-tight`,children:`Build powerful business applications, faster.`}),(0,$.jsx)(`p`,{className:`text-lg opacity-90`,children:`The universal platform for enterprise data management, workflows, and analytics.`})]})}),(0,$.jsx)(`div`,{className:`flex w-full lg:w-1/2 items-center justify-center bg-background px-6 py-12`,children:e})]})}var va=({href:e,className:t,children:n})=>(0,$.jsx)(p,{to:e,className:t,children:n});function ya(){let e=g(),{t}=w();return(0,$.jsx)(_a,{children:(0,$.jsx)(P,{onSuccess:()=>e(`/`),registerUrl:`/register`,forgotPasswordUrl:`/forgot-password`,title:t(`auth.login.title`),description:t(`auth.login.description`),linkComponent:va,labels:{emailLabel:t(`auth.login.emailLabel`),emailPlaceholder:t(`auth.login.emailPlaceholder`),passwordLabel:t(`auth.login.passwordLabel`),passwordPlaceholder:t(`auth.login.passwordPlaceholder`),forgotPasswordText:t(`auth.login.forgotPasswordText`),submitButton:t(`auth.login.submitButton`),submittingButton:t(`auth.login.submittingButton`),noAccountText:t(`auth.login.noAccountText`),signUpText:t(`auth.login.signUpText`)}})})}var ba=({href:e,className:t,children:n})=>(0,$.jsx)(p,{to:e,className:t,children:n});function xa(){let e=g(),{t}=w();return(0,$.jsx)(_a,{children:(0,$.jsx)(j,{onSuccess:()=>e(`/`),loginUrl:`/login`,title:t(`auth.register.title`),description:t(`auth.register.description`),linkComponent:ba,labels:{nameLabel:t(`auth.register.nameLabel`),namePlaceholder:t(`auth.register.namePlaceholder`),emailLabel:t(`auth.register.emailLabel`),emailPlaceholder:t(`auth.register.emailPlaceholder`),passwordLabel:t(`auth.register.passwordLabel`),passwordPlaceholder:t(`auth.register.passwordPlaceholder`),confirmPasswordLabel:t(`auth.register.confirmPasswordLabel`),confirmPasswordPlaceholder:t(`auth.register.confirmPasswordPlaceholder`),passwordMismatchError:t(`auth.register.passwordMismatchError`),passwordTooShortError:t(`auth.register.passwordTooShortError`),submitButton:t(`auth.register.submitButton`),submittingButton:t(`auth.register.submittingButton`),hasAccountText:t(`auth.register.hasAccountText`),signInText:t(`auth.register.signInText`)}})})}var Sa=({href:e,className:t,children:n})=>(0,$.jsx)(p,{to:e,className:t,children:n});function Ca(){let{t:e}=w();return(0,$.jsx)(_a,{children:(0,$.jsx)(ie,{loginUrl:`/login`,title:e(`auth.forgotPassword.title`),description:e(`auth.forgotPassword.description`),linkComponent:Sa,labels:{emailLabel:e(`auth.forgotPassword.emailLabel`),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`),submitButton:e(`auth.forgotPassword.submitButton`),submittingButton:e(`auth.forgotPassword.submittingButton`),successTitle:e(`auth.forgotPassword.successTitle`),successDescription:e(`auth.forgotPassword.successDescription`),backToSignInText:e(`auth.forgotPassword.backToSignInText`),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`),signInText:e(`auth.forgotPassword.signInText`)}})})}var wa=(0,Q.lazy)(()=>l(()=>import(`./ConsoleFloatingChatbot-DSk3VUa6.js`),__vite__mapDeps([0])));function Ta({children:e}){let{setContext:t}=H(),{isAiEnabled:n}=S(),r=n||!1;return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(mi,{variant:`home`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e}),r&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(wa,{appLabel:`Workspace`,objects:[]})})]})}function Ea(){let e=g(),{t}=w(),n=[{id:`create-app`,label:t(`home.quickActions.createApp`,{defaultValue:`Create App`}),description:t(`home.quickActions.createAppDesc`,{defaultValue:`Start with a new application`}),icon:Qt,href:`/create-app`,color:`text-blue-600 dark:text-blue-400`},{id:`manage-objects`,label:t(`home.quickActions.manageObjects`,{defaultValue:`Manage Objects`}),description:t(`home.quickActions.manageObjectsDesc`,{defaultValue:`Configure data models`}),icon:be,href:`/apps/setup/system/metadata/object`,color:`text-purple-600 dark:text-purple-400`},{id:`system-settings`,label:t(`home.quickActions.systemSettings`,{defaultValue:`System Settings`}),description:t(`home.quickActions.systemSettingsDesc`,{defaultValue:`Configure your workspace`}),icon:nt,href:`/apps/setup`,color:`text-gray-600 dark:text-gray-400`}];return(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight mb-4`,children:t(`home.quickActions.title`,{defaultValue:`Quick Actions`})}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:n.map(t=>{let n=t.icon;return(0,$.jsx)(Je,{className:`cursor-pointer hover:shadow-md transition-shadow`,onClick:()=>e(t.href),"data-testid":`quick-action-${t.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},"aria-label":t.label,children:(0,$.jsx)(U,{className:`p-6`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,$.jsx)(`div`,{className:K(`p-3 rounded-lg bg-muted`,t.color),children:(0,$.jsx)(n,{className:`h-6 w-6`})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`h3`,{className:`font-semibold text-base mb-1`,children:t.label}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description})]})]})})},t.id)})})]})}function Da({app:e,onClick:t,isFavorite:n}){let{t:r}=w(),{appLabel:i,appDescription:a}=re(),{toggleFavorite:o}=Pr(),s=Jr(e.icon),c=i({name:e.name,label:Z(e.label,r)}),l=a({name:e.name,description:Z(e.description,r)}),u=e.branding?.primaryColor;return(0,$.jsx)(Je,{className:`cursor-pointer hover:shadow-lg transition-all group relative`,onClick:t,"data-testid":`app-card-${e.name}`,children:(0,$.jsxs)(U,{className:`p-6`,children:[(0,$.jsx)(X,{variant:`ghost`,size:`sm`,className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,onClick:t=>{t.stopPropagation(),o({id:`app:${e.name}`,label:c,href:`/apps/${e.name}`,type:`object`})},"aria-label":n?r(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`})+` — ${c}`:r(`common.addToFavorites`,{defaultValue:`Add to favorites`})+` — ${c}`,"aria-pressed":n,"data-testid":`favorite-btn-${e.name}`,children:n?(0,$.jsx)(en,{className:`h-4 w-4 fill-yellow-400 text-yellow-400`}):(0,$.jsx)(zt,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:K(`inline-flex p-3 rounded-lg mb-4`,u?``:`bg-primary/10`),style:u?{backgroundColor:`${u}20`}:{},children:(0,$.jsx)(s,{className:`h-8 w-8`,style:u?{color:u}:{}})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`font-semibold text-lg mb-1`,children:c}),l&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground line-clamp-2`,children:l}),!l&&(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`home.appCard.noDescription`,{defaultValue:`No description`})})]}),e.isDefault&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(qt,{variant:`secondary`,children:r(`home.appCard.default`,{defaultValue:`Default`})})})]})})}function Oa({items:e}){let t=g(),{t:n}=w();return e.length===0?null:(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(cn,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:e.map(e=>{let r=Jr(e.type),i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:Wn(e.type)});return(0,$.jsx)(Je,{className:`cursor-pointer hover:shadow-md transition-shadow`,onClick:()=>t(e.href),"data-testid":`recent-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,$.jsx)(U,{className:`p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 rounded-lg bg-muted shrink-0`,children:(0,$.jsx)(r,{className:`h-5 w-5`})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]})]})})},e.id)})})]})}function ka({items:e}){let t=g(),{t:n}=w();return e.length===0?null:(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,$.jsx)(en,{className:`h-5 w-5 text-yellow-500 fill-yellow-500`}),(0,$.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:e.map(e=>{let n=Jr(e.type);return(0,$.jsx)(Je,{className:`cursor-pointer hover:shadow-md transition-shadow`,onClick:()=>t(e.href),"data-testid":`starred-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,$.jsx)(U,{className:`p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`p-2 rounded-lg bg-muted shrink-0`,children:(0,$.jsx)(n,{className:`h-5 w-5`})}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Wn(e.type)})]})]})})},e.id)})})]})}function Aa(){let e=g(),{t}=w(),{apps:n,loading:r}=k(),{recentItems:i}=Dr(),{favorites:a}=Pr(),o=n.filter(e=>e.active!==!1),s=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,6),c=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8);return r?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading workspace...`})}):o.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:(0,$.jsxs)(xn,{children:[(0,$.jsx)(wt,{children:`Welcome to ObjectUI`}),(0,$.jsx)(Jt,{children:`Get started by creating your first application or configure your system settings.`}),(0,$.jsxs)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:[(0,$.jsxs)(X,{onClick:()=>e(`/create-app`),"data-testid":`create-first-app-btn`,children:[(0,$.jsx)(Qt,{className:`mr-2 h-4 w-4`}),`Create Your First App`]}),(0,$.jsxs)(X,{variant:`outline`,onClick:()=>e(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:[(0,$.jsx)(nt,{className:`mr-2 h-4 w-4`}),`System Settings`]})]})]})}):(0,$.jsxs)(`div`,{className:`bg-background`,children:[(0,$.jsxs)(`div`,{className:`px-4 sm:px-6 pt-6 pb-4`,children:[(0,$.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:t(`home.title`,{defaultValue:`Home`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:t(`home.subtitle`,{defaultValue:`Your workspace dashboard`})})]}),(0,$.jsxs)(`div`,{className:`px-4 sm:px-6 py-4 space-y-8`,children:[(0,$.jsx)(Ea,{}),c.length>0&&(0,$.jsx)(ka,{items:c}),s.length>0&&(0,$.jsx)(Oa,{items:s}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight mb-4`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:o.map(t=>(0,$.jsx)(Da,{app:t,onClick:()=>e(`/apps/${t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})]})}function ja({children:e}){let{setContext:t}=H();return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(mi,{variant:`orgs`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function Ma(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function Na({open:e,onOpenChange:t,onCreated:n}){let{t:r}=w(),{createOrganization:i}=M(),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{l||c(Ma(a))},[a,l]),(0,Q.useEffect)(()=>{e&&(o(``),c(``),u(!1),m(null))},[e]),(0,$.jsx)(Ae,{open:e,onOpenChange:t,children:(0,$.jsx)(it,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,$.jsxs)(`form`,{onSubmit:(0,Q.useCallback)(async e=>{if(e.preventDefault(),!(!a.trim()||!s.trim())){f(!0),m(null);try{let e=await i({name:a.trim(),slug:s.trim()});n?.(e)}catch(e){m(e instanceof Error?e.message:`Failed to create workspace`)}finally{f(!1)}}},[a,s,i,n]),children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(vn,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,$.jsx)(st,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,$.jsx)(Y,{id:`workspace-name`,placeholder:r(`workspace.namePlaceholder`,{defaultValue:`e.g., Acme Inc`}),value:a,onChange:e=>o(e.target.value),autoFocus:!0,"data-testid":`workspace-name-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,$.jsx)(Y,{id:`workspace-slug`,placeholder:`acme-inc`,value:s,onChange:e=>{c(e.target.value),u(!0)},"data-testid":`workspace-slug-input`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),p&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:p})]}),(0,$.jsxs)(Oe,{children:[(0,$.jsx)(X,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:d,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(X,{type:`submit`,disabled:d||!a.trim()||!s.trim(),"data-testid":`workspace-create-submit`,children:[d&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function Pa(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Fa(){let{t:e}=w(),t=g(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a}=M(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),f=n??[],p=(0,Q.useMemo)(()=>{let e=o.trim().toLowerCase();return e?f.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):f},[f,o]),m=async e=>{d(e.id);try{e.id!==r?.id&&await a(e.id);let t=`/console/`,n=t.endsWith(`/`)?t:`${t}/`;window.location.href=`${window.location.origin}${n}home`}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),d(null)}};return i?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,$.jsxs)(`div`,{className:`mb-8`,children:[(0,$.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select an organization to continue, or create a new one.`})})]}),(0,$.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,$.jsx)(Le,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(Y,{value:o,onChange:e=>s(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),(0,$.jsxs)(X,{onClick:()=>l(!0),"data-testid":`organizations-new`,children:[(0,$.jsx)(Qt,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),f.length===0?(0,$.jsxs)(xn,{children:[(0,$.jsx)(wt,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,$.jsx)(Jt,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),(0,$.jsxs)(X,{className:`mt-6`,onClick:()=>l(!0),children:[(0,$.jsx)(Qt,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):p.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No organizations match your search.`})}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:p.map(n=>{let i=n.id===r?.id,a=u===n.id;return(0,$.jsxs)(`button`,{onClick:()=>m(n),disabled:a,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,$.jsxs)(Ct,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,$.jsx)(wn,{src:n.logo,alt:n.name}),(0,$.jsx)(dn,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Pa(n.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,$.jsx)(`span`,{className:`text-xs text-primary underline-offset-4 hover:underline shrink-0`,onClick:e=>{e.stopPropagation(),t(`/organizations/${n.slug}/members`)},children:e(`organizations.manage`,{defaultValue:`Manage`})}),a&&(0,$.jsx)(q,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,$.jsx)(Na,{open:c,onOpenChange:l,onCreated:e=>{l(!1),m(e)}})]})}function Ia(){let{t:e}=w(),t=g(),{slug:n}=a(),{organizations:r,activeOrganization:i,isOrganizationsLoading:o,switchOrganization:c}=M(),{setContext:l}=H();(0,Q.useEffect)(()=>{l(`home`)},[l]);let u=(0,Q.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,Q.useEffect)(()=>{u&&i?.id!==u.id&&c(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,i,c]),o)return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,$.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,$.jsx)(X,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let f=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(mi,{variant:`orgs`})}),(0,$.jsx)(`div`,{className:`border-b`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(0,$.jsxs)(`button`,{onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(Sn,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,$.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:f.map(e=>(0,$.jsx)(s,{to:e.to,end:!0,className:({isActive:e})=>`border-b-2 px-3 py-2 text-sm font-medium transition-colors ${e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e.label},e.to))})]})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,$.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,$.jsx)(d,{context:{org:u}})})})]})}function La(){return i()}function Ra(e){let t=`/console/`,n=t.endsWith(`/`)?t:`${t}/`;return`${window.location.origin}${n}accept-invitation/${e}`}function za({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=w(),{inviteMember:a}=M(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(`member`),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),_(!1))},[t]);let v=(0,Q.useCallback)(async t=>{if(t.preventDefault(),o.trim()){d(!0),p(null);try{let t=await a({organizationId:e,email:o.trim(),role:c});h(t),r?.(t)}catch(e){p(e instanceof Error?e.message:`Failed to invite member`)}finally{d(!1)}}},[o,c,e,a,r]),y=(0,Q.useCallback)(async()=>{if(!m)return;let e=Ra(m.id);try{await navigator.clipboard.writeText(e),_(!0),B.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>_(!1),2e3)}catch{B.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,$.jsx)(Ae,{open:t,onOpenChange:n,children:(0,$.jsx)(it,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(vn,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,$.jsx)(st,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,$.jsx)(Ot,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Y,{readOnly:!0,value:Ra(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,$.jsx)(X,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,$.jsx)(Pt,{className:`h-4 w-4`}):(0,$.jsx)(En,{className:`h-4 w-4`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:m.email,role:m.role})})]}),(0,$.jsx)(Oe,{children:(0,$.jsx)(X,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,$.jsxs)(`form`,{onSubmit:v,children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(vn,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,$.jsx)(st,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,$.jsx)(Y,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,$.jsxs)(vt,{value:c,onValueChange:e=>l(e),children:[(0,$.jsx)(jt,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,$.jsx)(Dn,{})}),(0,$.jsxs)(Ye,{children:[(0,$.jsx)(ge,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,$.jsx)(ge,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,$.jsx)(ge,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,$.jsxs)(Oe,{children:[(0,$.jsx)(X,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(X,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function Ba(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Va(){let{t:e}=w(),{org:t}=La(),{getMembers:n,removeMember:r,updateMemberRole:i}=M(),[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),h=(0,Q.useCallback)(async()=>{c(!0),u(null);try{o(await n(t.id))}catch(e){u(e instanceof Error?e.message:`Failed to load members`)}finally{c(!1)}},[t.id,n]);(0,Q.useEffect)(()=>{h()},[h]);let g=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),B.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){B.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return s?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,$.jsx)(X,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,$.jsx)(X,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,$.jsx)(ut,{}),(0,$.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,$.jsxs)(Ct,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,$.jsx)(wn,{src:t.user.image,alt:t.user.name}),(0,$.jsx)(dn,{className:`text-xs font-medium`,children:Ba(t.user?.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,$.jsx)(qt,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),t.createdAt&&(0,$.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),(0,$.jsxs)(Ft,{children:[(0,$.jsx)(In,{asChild:!0,children:(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,$.jsx)($e,{className:`h-4 w-4`})})}),(0,$.jsxs)(pn,{align:`end`,children:[(0,$.jsxs)(J,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,$.jsx)(Nt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,$.jsxs)(J,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,$.jsx)(Nt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,$.jsxs)(J,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,$.jsx)(Nt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,$.jsxs)(J,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,$.jsx)(jn,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,$.jsx)(An,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,$.jsxs)(hn,{children:[(0,$.jsxs)(Vt,{children:[(0,$.jsx)(bt,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,$.jsx)(rn,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:p?.user?.name??p?.userId??``})})]}),(0,$.jsxs)(Ut,{children:[(0,$.jsx)(It,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(kt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),B.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){B.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,$.jsx)(za,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function Ha(e){let t=`/console/`,n=t.endsWith(`/`)?t:`${t}/`;return`${window.location.origin}${n}accept-invitation/${e}`}function Ua(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function Wa(){let{t:e}=w(),{org:t}=La(),{listInvitations:n,cancelInvitation:r}=M(),[i,a]=(0,Q.useState)([]),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(`all`),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),g=(0,Q.useCallback)(async()=>{s(!0),l(null);try{a(await n(t.id))}catch(e){l(e instanceof Error?e.message:`Failed to load invitations`)}finally{s(!1)}},[t.id,n]);(0,Q.useEffect)(()=>{g()},[g]);let _=async t=>{let n=Ha(t.id);try{await navigator.clipboard.writeText(n),h(t.id),B.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{B.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},v=async()=>{if(f)try{await r(f.id),B.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){B.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},y=u===`all`?i:i.filter(e=>e.status===u),b={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,$.jsx)(X,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,$.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,$.jsxs)(`button`,{onClick:()=>d(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${u===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),b[t]>0&&(0,$.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:b[t]})]},t))}),(0,$.jsx)(ut,{}),y.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,$.jsx)(`div`,{className:`space-y-2`,children:y.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,$.jsx)(Ct,{className:`h-9 w-9 shrink-0`,children:(0,$.jsx)(dn,{className:`text-xs`,children:(0,$.jsx)(mt,{className:`h-4 w-4`})})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,$.jsx)(qt,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,$.jsx)(qt,{variant:Ua(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,$.jsx)(Pt,{className:`h-4 w-4 text-green-600`}):(0,$.jsx)(En,{className:`h-4 w-4`})}),(0,$.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>p(t),"aria-label":`Cancel invitation`,children:(0,$.jsx)(ye,{className:`h-4 w-4`})})]})]},t.id))}),(0,$.jsx)(An,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,$.jsxs)(hn,{children:[(0,$.jsxs)(Vt,{children:[(0,$.jsx)(bt,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,$.jsx)(rn,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,$.jsxs)(Ut,{children:[(0,$.jsx)(It,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(kt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function Ga(){let{t:e}=w(),{org:t}=La(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=M(),s=g(),[c,l]=(0,Q.useState)(t.name),[u,d]=(0,Q.useState)(t.slug??``),[f,p]=(0,Q.useState)(t.logo??``),[m,h]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(!0),[x,S]=(0,Q.useState)(!1),[C,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(``),[O,ee]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{l(t.name),d(t.slug??``),p(t.logo??``)},[t]),(0,Q.useEffect)(()=>{let e=!1;return b(!0),r(t.id).then(t=>{e||v(t.find(e=>e.userId===n?.id)?.role===`owner`)}).catch(()=>{e||v(!1)}).finally(()=>{e||b(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let k=(0,Q.useCallback)(async n=>{n.preventDefault(),h(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.trim()||void 0}),B.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){B.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{h(!1)}},[t.id,c,u,f,i,e]);return y?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,$.jsx)(ut,{className:`my-4`}),_?(0,$.jsxs)(`form`,{onSubmit:k,className:`space-y-4 max-w-md`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,$.jsx)(Y,{id:`org-name`,value:c,onChange:e=>l(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,$.jsx)(Y,{id:`org-slug`,value:u,onChange:e=>d(e.target.value),"data-testid":`settings-slug-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(Ot,{htmlFor:`org-logo`,children:e(`organization.settings.logoLabel`,{defaultValue:`Logo URL (optional)`})}),(0,$.jsx)(Y,{id:`org-logo`,type:`url`,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/logo.png`,"data-testid":`settings-logo-input`})]}),(0,$.jsxs)(X,{type:`submit`,disabled:m,"data-testid":`settings-save-btn`,children:[m&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,$.jsx)(`div`,{className:`rounded-lg border bg-muted/50 p-4 text-sm text-muted-foreground`,children:e(`organization.settings.readOnlyNote`,{defaultValue:`Only owners can change settings.`})})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,$.jsx)(ut,{className:`my-4`}),(0,$.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,$.jsx)(X,{variant:`destructive`,size:`sm`,onClick:()=>S(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,$.jsx)(ut,{}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,$.jsx)(X,{variant:`destructive`,size:`sm`,onClick:()=>{D(``),T(!0)},disabled:!_,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,$.jsx)(An,{open:x,onOpenChange:S,children:(0,$.jsxs)(hn,{children:[(0,$.jsxs)(Vt,{children:[(0,$.jsx)(bt,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,$.jsx)(rn,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,$.jsxs)(Ut,{children:[(0,$.jsx)(It,{disabled:O,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(kt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await o(t.id),B.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){B.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{ee(!1)}},disabled:O,children:[O&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,$.jsx)(An,{open:C,onOpenChange:e=>{T(e),e||D(``)},children:(0,$.jsxs)(hn,{children:[(0,$.jsxs)(Vt,{children:[(0,$.jsx)(bt,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,$.jsx)(rn,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,$.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,$.jsx)(Ot,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,$.jsx)(Y,{id:`delete-confirm-slug`,className:`mt-2`,value:E,onChange:e=>D(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,$.jsxs)(Ut,{children:[(0,$.jsx)(It,{disabled:O,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(kt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await a(t.id),B.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){B.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{ee(!1)}},disabled:O||E!==t.slug,children:[O&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function Ka(){let{t:e}=w(),t=g(),{invitationId:n}=a(),{isAuthenticated:r,isLoading:i,getInvitation:o,acceptInvitation:s,rejectInvitation:c,switchOrganization:l}=M(),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{!i&&!r&&t(`/login?redirect=`+encodeURIComponent(window.location.pathname))},[r,i,t]),(0,Q.useEffect)(()=>{if(!n||!r)return;let e=!1;return p(!0),h(null),o(n).then(t=>{e||d(t)}).catch(t=>{e||h(t instanceof Error?t.message:`Invitation not found or expired`)}).finally(()=>{e||p(!1)}),()=>{e=!0}},[n,r,o]),i?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center`,children:(0,$.jsx)(q,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center px-4 py-12 bg-background`,children:(0,$.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-8 shadow-sm`,"data-testid":`accept-invitation-page`,children:f?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8`,children:[(0,$.jsx)(q,{className:`h-8 w-8 animate-spin text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`organization.accept.loading`,{defaultValue:`Loading invitation…`})})]}):m?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,$.jsx)(Ln,{className:`h-10 w-10 text-destructive`}),(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.accept.errorTitle`,{defaultValue:`Invitation unavailable`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:m}),(0,$.jsx)(X,{variant:`outline`,onClick:()=>t(`/organizations`),children:e(`organization.accept.goToOrgs`,{defaultValue:`Go to organizations`})})]}):u?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[(0,$.jsx)(`div`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-primary/10`,children:(0,$.jsx)(De,{className:`h-7 w-7 text-primary`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-xl font-bold`,children:e(`organization.accept.title`,{defaultValue:`You have been invited`})}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.accept.description`,{defaultValue:`You have been invited to join {{orgName}} as {{role}}.`,orgName:u.organizationName??u.organizationId,role:u.role})})]}),(0,$.jsxs)(`div`,{className:`w-full rounded-lg border bg-muted/50 p-4 text-left space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.organization`,{defaultValue:`Organization`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:u.organizationName??u.organizationId})]}),(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.role`,{defaultValue:`Role`})}),(0,$.jsx)(`span`,{className:`font-medium capitalize`,children:u.role})]}),u.expiresAt&&(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.expiresAt`,{defaultValue:`Expires`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:new Date(u.expiresAt).toLocaleDateString()})]})]}),(0,$.jsxs)(`div`,{className:`flex w-full gap-3`,children:[(0,$.jsxs)(X,{variant:`outline`,className:`flex-1`,onClick:async()=>{if(n){b(!0);try{await c(n),B.success(e(`organization.accept.declined`,{defaultValue:`Invitation declined`})),t(`/organizations`)}catch(t){B.error(t instanceof Error?t.message:e(`organization.accept.declineFailed`,{defaultValue:`Failed to decline invitation`})),b(!1)}}},disabled:y||_,children:[y&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.accept.decline`,{defaultValue:`Decline`})]}),(0,$.jsxs)(X,{className:`flex-1`,onClick:async()=>{if(!(!u||!n)){v(!0);try{await s(n),await l(u.organizationId).catch(()=>null),B.success(e(`organization.accept.accepted`,{defaultValue:`Invitation accepted`})),t(`/home`)}catch(t){B.error(t instanceof Error?t.message:e(`organization.accept.acceptFailed`,{defaultValue:`Failed to accept invitation`})),v(!1)}}},disabled:_||y,children:[_&&(0,$.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),(0,$.jsx)(Qe,{className:`mr-2 h-4 w-4`}),e(`organization.accept.accept`,{defaultValue:`Accept invitation`})]})]})]}):null})}):null}var qa=(0,Q.lazy)(()=>l(()=>import(`./SystemHubPage-LGgCwgTn.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]))),Ja=(0,Q.lazy)(()=>l(()=>import(`./AppManagementPage-DvZRhEu3.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]))),Ya=(0,Q.lazy)(()=>l(()=>import(`./ProfilePage-BFhufxnO.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]))),Xa=!1;(0,Q.lazy)(()=>l(()=>import(`./MetadataManagerPage-CLb0l4Pw.js`).then(e=>({default:e.MetadataManagerPage})),__vite__mapDeps([0]))),(0,Q.lazy)(()=>l(()=>import(`./MetadataDetailPage-Dn8QJ3Hw.js`).then(e=>({default:e.MetadataDetailPage})),__vite__mapDeps([0])));var Za=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{path:`system`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ei,{}),children:(0,$.jsx)(qa,{})})}),(0,$.jsx)(m,{path:`system/apps`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ei,{}),children:(0,$.jsx)(Ja,{})})}),(0,$.jsx)(m,{path:`system/profile`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ei,{}),children:(0,$.jsx)(Ya,{})})}),Xa]});function Qa(){return(0,$.jsx)(ha,{extraRoutes:Za,extraRoutesNoApp:Za})}var $a=(0,Q.lazy)(()=>l(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]))),eo=`/console/`?.replace(/\/$/,``)||`/`,to=`https://demo.objectstack.ai/api/v1/auth`,no=({children:e})=>(0,$.jsx)(ki,{authUrl:to,children:e});function ro(){return(0,$.jsxs)(no,{children:[(0,$.jsx)(ae,{}),(0,$.jsx)(u,{basename:eo,children:(0,$.jsxs)(zr,{children:[(0,$.jsx)(Ai,{position:`bottom-right`}),(0,$.jsxs)(r,{children:[(0,$.jsx)(m,{path:`/login`,element:(0,$.jsx)(ya,{})}),(0,$.jsx)(m,{path:`/register`,element:(0,$.jsx)(xa,{})}),(0,$.jsx)(m,{path:`/forgot-password`,element:(0,$.jsx)(Ca,{})}),(0,$.jsx)(m,{path:`/home`,element:(0,$.jsx)(Ur,{children:(0,$.jsx)(Ta,{children:(0,$.jsx)(Aa,{})})})}),(0,$.jsx)(m,{path:`/organizations`,element:(0,$.jsx)(Ur,{requireOrganization:!1,children:(0,$.jsx)(ja,{children:(0,$.jsx)(Fa,{})})})}),(0,$.jsxs)(m,{path:`/organizations/:slug`,element:(0,$.jsx)(Ur,{requireOrganization:!1,children:(0,$.jsx)(Ia,{})}),children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(n,{to:`members`,replace:!0})}),(0,$.jsx)(m,{path:`members`,element:(0,$.jsx)(Va,{})}),(0,$.jsx)(m,{path:`invitations`,element:(0,$.jsx)(Wa,{})}),(0,$.jsx)(m,{path:`settings`,element:(0,$.jsx)(Ga,{})})]}),(0,$.jsx)(m,{path:`/accept-invitation/:invitationId`,element:(0,$.jsx)(Ka,{})}),(0,$.jsx)(m,{path:`/system/*`,element:(0,$.jsx)(Gr,{})}),(0,$.jsx)(m,{path:`/create-app`,element:(0,$.jsx)(Ur,{requireOrganization:!1,children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Rr,{}),children:(0,$.jsx)($a,{})})})}),(0,$.jsx)(m,{path:`/apps/:appName/*`,element:(0,$.jsx)(Ur,{children:(0,$.jsx)(Qa,{})})}),(0,$.jsx)(m,{path:`/`,element:(0,$.jsx)(Br,{children:(0,$.jsx)(Wr,{})})}),(0,$.jsx)(m,{path:`*`,element:(0,$.jsx)(n,{to:`/`,replace:!0})})]})]})})]})}async function io(e){try{let t=await fetch(`https://demo.objectstack.ai/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,ao(r)?oo(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}function ao(e){let t=e.objects;if(!t||typeof t!=`object`||Array.isArray(t))return!1;for(let e of Object.values(t))if(e&&typeof e==`object`&&!Array.isArray(e)&&`fields`in e)return!0;return!1}function oo(e){let t={},n={},r={},i=e.objects;if(i)for(let[e,a]of Object.entries(i)){if(!a||typeof a!=`object`)continue;let i={label:a.label};if(a.pluralLabel&&(i.pluralLabel=a.pluralLabel),a.description&&(i.description=a.description),t[e]=i,a.fields&&typeof a.fields==`object`){n[e]={};for(let[t,i]of Object.entries(a.fields))i?.label&&(n[e][t]=i.label),i?.options&&typeof i.options==`object`&&Object.keys(i.options).length>0&&(r[e]||(r[e]={}),r[e][t]=i.options)}}let a={};return Object.keys(t).length>0&&(a.objects=t),Object.keys(n).length>0&&(a.fields=n),Object.keys(r).length>0&&(a.fieldOptions=r),e.apps&&(a.apps=e.apps),e.messages&&(a.messages=e.messages),e.validationMessages&&(a.validationMessages=e.validationMessages),e.dashboards&&(a.dashboards=e.dashboards),{app:a}}function so(e,t){let n=Array.isArray(e.fields)?e.fields:Object.values(e.fields||{});return{id:e.name||`obj_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,pluralLabel:e.pluralLabel||e.plural_label||void 0,description:typeof e.description==`object`?e.description.defaultValue:e.description||void 0,icon:e.icon||void 0,group:e.name?.startsWith(`sys_`)?`System Objects`:`Custom Objects`,sortOrder:t,isSystem:e.name?.startsWith(`sys_`)||!1,enabled:e.enabled!==!1,fieldCount:n.length,relationships:Array.isArray(e.relationships)?e.relationships.map(e=>({relatedObject:e.object||e.relatedObject||``,type:e.type||`one-to-many`,label:e.label||e.name||void 0,foreignKey:e.foreign_key||e.foreignKey||void 0})):void 0}}function co(e,t){return{id:e.name||`fld_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,type:e.type||`text`,group:e.group||void 0,sortOrder:t,description:e.description||e.help||void 0,required:e.required||!1,unique:e.unique||!1,readonly:e.readonly||!1,hidden:e.hidden||!1,defaultValue:e.defaultValue||e.default_value||void 0,placeholder:e.placeholder||void 0,options:Array.isArray(e.options)?e.options.map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label||e.value,value:e.value,color:e.color}):void 0,isSystem:e.readonly===!0&&(e.name===`id`||e.name===`createdAt`||e.name===`updatedAt`),externalId:e.externalId||!1,trackHistory:e.trackHistory||e.track_history||!1,indexed:e.indexed||!1,referenceTo:e.reference_to||e.referenceTo||void 0,formula:e.formula||void 0}}function lo(e){let{objects:t}=k(),n=(0,Q.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,Q.useMemo)(()=>n?so(n,0):null,[n]),fields:(0,Q.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(co):[],[n]),metadataObject:n}}function uo({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(t),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,Q.useCallback)(async()=>{if(c===t){s(!1);return}d(!0);try{await n(c),s(!1)}catch{}finally{d(!1)}},[c,t,n]),h=()=>{l(t),s(!1)},g=e=>{e.key===`Enter`&&!r&&(e.preventDefault(),m()),e.key===`Escape`&&h()};return(0,$.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,$.jsx)(`dd`,{children:o?(0,$.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,$.jsx)(Lt,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,$.jsx)(Y,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,$.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,$.jsx)(q,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Pt,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:h,disabled:u,className:`mt-0.5 p-1 rounded text-muted-foreground hover:bg-accent shrink-0`,"aria-label":`Cancel`,children:(0,$.jsx)(ye,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,$.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,$.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,$.jsx)(`button`,{onClick:p,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:bg-accent transition-opacity shrink-0`,"aria-label":`Edit ${e}`,children:(0,$.jsx)(_n,{className:`h-3 w-3`})})]})})]})}function fo({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=lo(t),{refresh:a}=k(),o=Xi(),s=(0,Q.useCallback)(async(e,n)=>{if(!o||!i)return;let r={...i,[e]:n};try{await o.saveMetadataItem(`object`,t,r),await a(),B.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw B.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,$.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,$.jsx)(uo,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,$.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,$.jsx)(uo,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,$.jsx)(uo,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,$.jsx)(`div`,{className:`sm:col-span-2`,children:(0,$.jsx)(uo,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(qt,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,$.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(qt,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var po=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function mo({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=lo(t),{refresh:i}=k(),a=Xi(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,Q.useCallback)(async()=>{if(!a||!r||!u.relatedObject.trim())return;let e={relatedObject:u.relatedObject.trim(),type:u.type,label:u.label.trim()||void 0,foreignKey:u.foreignKey.trim()||void 0},n={...r,relationships:[...Array.isArray(r.relationships)?r.relationships:[],e]};l(!0);try{await a.saveMetadataItem(`object`,t,n),await i(),B.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){B.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,Q.useCallback)(async e=>{if(!a||!r)return;let n=Array.isArray(r.relationships)?[...r.relationships]:[];n.splice(e,1);let o={...r,relationships:n};l(!0);try{await a.saveMetadataItem(`object`,t,o),await i(),B.success(`关联关系已删除`)}catch(e){B.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,$.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,$.jsxs)(X,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,$.jsx)(Qt,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,$.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,$.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,$.jsx)(Y,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,$.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:po.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,$.jsx)(Y,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,$.jsx)(Y,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,$.jsx)(X,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,$.jsxs)(X,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,$.jsx)(q,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,$.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,$.jsx)(qt,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:po.find(t=>t.value===e.type)?.label||e.type}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,$.jsx)(`button`,{onClick:()=>void p(t),disabled:c,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-destructive hover:bg-destructive/10 transition-all shrink-0`,"aria-label":`删除关联`,children:(0,$.jsx)(mn,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,$.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,$.jsx)(ht,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,$.jsxs)(X,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,$.jsx)(Qt,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function ho({schema:e}){let t=e.objectName,{fields:n}=lo(t),r=(0,Q.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,$.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,$.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,$.jsx)(qt,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,$.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,$.jsx)(ot,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function go(e){return(0,$.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,$.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-forms`,children:[(0,$.jsx)(tn,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-views`,children:[(0,$.jsx)(Rt,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,$.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-dashboards`,children:[(0,$.jsx)(_e,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function _o({schema:e}){let t=e.objectName,{object:n}=lo(t);return(0,$.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,$.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,$.jsx)(Yt,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,$.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function vo(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function yo(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var bo=class{constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=vo(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(yo)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function xo({schema:e}){let t=e.objectName,{objects:n,refresh:r}=k(),i=Xi(),a=(0,Q.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,Q.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(co):[],[a]),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(!1),d=s??o,f=(0,Q.useRef)(d),p=(0,Q.useCallback)(async e=>{let n=f.current;if(c(e),f.current=e,!i){B.error(`Service unavailable — changes saved locally only`);return}let a=bo.diffFields(n,e),o=a?a.type===`create`?`Field "${a.field.label||a.field.name}" created`:a.type===`update`?`Field "${a.field.label||a.field.name}" updated`:`Field "${a.field.label||a.field.name}" deleted`:`Field configuration updated`;u(!0);try{await i.saveFields(t,e),await r(),B.success(o)}catch(e){c(n),f.current=n,B.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,$.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,$.jsx)(q,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground bg-muted/50 rounded-md px-3 py-2`,"data-testid":`system-field-hint`,children:[(0,$.jsx)(Te,{className:`h-3.5 w-3.5 shrink-0`}),`System fields (e.g. id, createdAt, updatedAt) are read-only and cannot be edited or deleted.`]}),(0,$.jsx)(ir,{objectName:t,fields:d,onFieldsChange:p})]})}function So({schema:e}){let t=e.objectName,[n,r]=(0,Q.useState)(`details`),i={type:`object-properties`,id:`${t}-properties`,objectName:t},a={type:`object-field-designer`,id:`${t}-field-designer`,objectName:t},o={type:`object-relationships`,id:`${t}-relationships`,objectName:t},s={type:`object-keys`,id:`${t}-keys`,objectName:t},c={type:`object-data-experience`,id:`${t}-data-experience`,objectName:t},l={type:`object-data-preview`,id:`${t}-data-preview`,objectName:t};return(0,$.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,$.jsxs)(gn,{value:n,onValueChange:r,className:`w-full`,children:[(0,$.jsxs)(Wt,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,$.jsxs)(Ht,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,$.jsx)(Pn,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,$.jsxs)(Ht,{value:`fields`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,$.jsx)(et,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,$.jsxs)(Ht,{value:`relationships`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,$.jsx)(ht,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,$.jsxs)(Ht,{value:`data`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,$.jsx)(Yt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,$.jsx)(an,{value:`details`,className:`mt-6`,children:(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsx)(v,{schema:i})})}),(0,$.jsx)(an,{value:`fields`,className:`mt-6`,children:(0,$.jsx)(`div`,{className:`space-y-6`,children:(0,$.jsx)(v,{schema:a})})}),(0,$.jsx)(an,{value:`relationships`,className:`mt-6`,children:(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(v,{schema:o}),(0,$.jsx)(v,{schema:s})]})}),(0,$.jsx)(an,{value:`data`,className:`mt-6`,children:(0,$.jsxs)(`div`,{className:`space-y-6`,children:[(0,$.jsx)(v,{schema:l}),(0,$.jsx)(v,{schema:c})]})})]})})}var Co={namespace:`console`,category:`system`};b.register(`object-detail-tabs`,So,{...Co,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),b.register(`object-properties`,fo,{...Co,label:`Object Properties`,icon:`Settings2`}),b.register(`object-relationships`,mo,{...Co,label:`Object Relationships`,icon:`Link2`}),b.register(`object-keys`,ho,{...Co,label:`Object Keys`,icon:`KeyRound`}),b.register(`object-data-experience`,go,{...Co,label:`Data Experience`,icon:`LayoutList`}),b.register(`object-data-preview`,_o,{...Co,label:`Data Preview`,icon:`Table`}),b.register(`object-field-designer`,xo,{...Co,label:`Field Designer`,icon:`Columns`}),b.registerLazy(`object-map`,()=>l(()=>import(`./plugin-map-zYnfrqC_.js`).then(e=>e.t),__vite__mapDeps([0,2])),{namespace:`plugin-map`,category:`view`}),b.registerLazy(`map`,()=>l(()=>import(`./plugin-map-zYnfrqC_.js`).then(e=>e.t),__vite__mapDeps([0,2])),{namespace:`view`,category:`view`}),b.registerLazy(`chart`,()=>l(()=>import(`./plugin-charts-CJxtgGBd.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])b.registerLazy(e,()=>l(()=>import(`./plugin-charts-CJxtgGBd.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-charts`,category:`chart`});b.registerLazy(`object-gantt`,()=>l(()=>import(`./plugin-gantt-BKC7uDlF.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-gantt`,category:`view`}),b.registerLazy(`gantt`,()=>l(()=>import(`./plugin-gantt-BKC7uDlF.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`view`,category:`view`}),b.registerLazy(`markdown`,()=>l(()=>import(`./plugin-markdown-D1ozhgoT.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-markdown`,category:`display`}),b.registerLazy(`object-timeline`,()=>l(()=>import(`./plugin-timeline-B93E4n2x.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-timeline`,category:`view`}),b.registerLazy(`timeline`,()=>l(()=>import(`./plugin-timeline-B93E4n2x.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`view`,category:`view`}),b.registerLazy(`object-calendar`,()=>l(()=>import(`./plugin-calendar-CQkP8bUI.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-calendar`,category:`view`}),b.registerLazy(`calendar`,()=>l(()=>import(`./plugin-calendar-CQkP8bUI.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`view`,category:`view`}),b.registerLazy(`calendar-view`,()=>l(()=>import(`./plugin-calendar-CQkP8bUI.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-calendar`,category:`view`}),b.registerLazy(`object-kanban`,()=>l(()=>import(`./plugin-kanban-Bi-sR7AW.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-kanban`,category:`view`}),b.registerLazy(`kanban`,()=>l(()=>import(`./plugin-kanban-Bi-sR7AW.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])b.registerLazy(e,()=>l(()=>import(`./plugin-kanban-Bi-sR7AW.js`).then(e=>e.t),__vite__mapDeps([0])),{namespace:`plugin-kanban`,category:`view`});b.registerLazy(`report`,()=>l(()=>import(`./plugins-views-Bi5okDge.js`).then(e=>e.t),__vite__mapDeps([0,1])),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`report-builder`])b.registerLazy(e,()=>l(()=>import(`./plugins-views-Bi5okDge.js`).then(e=>e.t),__vite__mapDeps([0,1])),{namespace:`plugin-report`,category:`view`});ar.createRoot(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Jn,{pwa:{enabled:!0,name:`ObjectUI Console`,shortName:`Console`},children:(0,$.jsx)(ee,{loadLanguage:io,children:(0,$.jsx)(ro,{})})})}));export{Gi as a,Ki as i,so as n,Ni as o,Xi as r,Pi as s,bo as t};
@@ -1 +1 @@
1
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,t as r}from"./vendor-react-B1k2FF9f.js";import{H as i,L as a,M as o,R as s,a as c,w as l}from"./framework-CoXA0nY6.js";import{$A as u,$t as d,PL as f,Qt as p,Wt as m,ZA as h,cn as g,en as _,ir as v,ln as y,mM as b,nn as x,rt as S,tn as C,um as w,un as T,yr as E}from"./ui-components-B7mlp0en.js";import{i as D}from"./plugin-grid-Cn_T_wpz.js";var O=t(n(),1),k=r(),A=`bg-blue-500 text-white`,j=new Date,M={"calendar.today":`Today`,"calendar.month":`Month`,"calendar.week":`Week`,"calendar.day":`Day`,"calendar.newEvent":`New event`,"calendar.moreEvents":`+{{count}} more`};function N(){try{let e=c();return e.t(`calendar.today`)===`calendar.today`?{t:(e,t)=>{let n=M[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}:{t:e.t,language:e.language}}catch{return{t:(e,t)=>{let n=M[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}}}function P({events:e=[],view:t=`month`,currentDate:n=j,locale:r=`default`,onEventClick:i,onDateClick:a,onViewChange:o,onNavigate:s,onAddClick:c,onEventDrop:l,className:m}){let[S,D]=O.useState(t),[A,M]=O.useState(n),{t:P,language:I}=N(),L=r===`default`?I:r;O.useEffect(()=>{M(n)},[n]),O.useEffect(()=>{D(t)},[t]);let R=O.useRef(o);R.current=o,O.useEffect(()=>{let e=window.matchMedia(`(max-width: 639px)`),t=e=>{e.matches&&(D(`day`),R.current?.(`day`))};return t(e),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let H=()=>{let e=new Date(A);S===`month`?e.setMonth(e.getMonth()-1):S===`week`?e.setDate(e.getDate()-7):e.setDate(e.getDate()-1),M(e),s?.(e)},U=()=>{let e=new Date(A);S===`month`?e.setMonth(e.getMonth()+1):S===`week`?e.setDate(e.getDate()+7):e.setDate(e.getDate()+1),M(e),s?.(e)},W=()=>{let e=new Date;M(e),s?.(e)},G=e=>{D(e),o?.(e)},K=()=>{if(S===`month`)return A.toLocaleDateString(L,{month:`long`,year:`numeric`});if(S===`week`){let e=F(A),t=new Date(e);return t.setDate(t.getDate()+6),`${e.toLocaleDateString(L,{month:`short`,day:`numeric`})} - ${t.toLocaleDateString(L,{month:`short`,day:`numeric`,year:`numeric`})}`}else return A.toLocaleDateString(L,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})},q=O.useRef(0);return(0,k.jsxs)(`div`,{role:`region`,"aria-label":`Calendar`,className:f(`flex flex-col h-full bg-background min-w-0 overflow-hidden`,m),children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center bg-muted/50 rounded-lg p-1 gap-1`,children:[(0,k.jsx)(E,{variant:`ghost`,size:`sm`,onClick:W,className:`h-8`,"aria-label":`Go to today`,children:P(`calendar.today`)}),(0,k.jsx)(`div`,{className:`h-4 w-px bg-border mx-1`}),(0,k.jsx)(E,{variant:`ghost`,size:`icon`,"aria-label":`Previous period`,onClick:H,className:`h-8 w-8`,children:(0,k.jsx)(u,{className:`h-4 w-4`})}),(0,k.jsx)(E,{variant:`ghost`,size:`icon`,"aria-label":`Next period`,onClick:U,className:`h-8 w-8`,children:(0,k.jsx)(h,{className:`h-4 w-4`})})]}),(0,k.jsxs)(g,{children:[(0,k.jsx)(T,{asChild:!0,children:(0,k.jsxs)(E,{variant:`ghost`,"aria-label":`Current date: ${K()}`,className:f(`text-base sm:text-xl font-semibold h-auto px-2 sm:px-3 py-1 hover:bg-muted/50 transition-colors`,`flex items-center gap-2`),children:[(0,k.jsx)(b,{className:`h-5 w-5 text-muted-foreground`}),(0,k.jsx)(`span`,{children:K()})]})}),(0,k.jsx)(y,{className:`w-auto p-0`,align:`start`,children:(0,k.jsx)(v,{mode:`single`,selected:A,onSelect:e=>{e&&(M(e),s?.(e))},initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(p,{value:S,onValueChange:G,children:[(0,k.jsx)(C,{className:`w-32 bg-background`,children:(0,k.jsx)(x,{})}),(0,k.jsxs)(d,{children:[(0,k.jsx)(_,{value:`day`,children:P(`calendar.day`)}),(0,k.jsx)(_,{value:`week`,children:P(`calendar.week`)}),(0,k.jsx)(_,{value:`month`,children:P(`calendar.month`)})]})]}),c&&(0,k.jsxs)(E,{onClick:c,size:`sm`,className:`gap-1`,children:[(0,k.jsx)(w,{className:`h-4 w-4`}),P(`calendar.newEvent`)]})]})]}),(0,k.jsxs)(`div`,{className:`flex-1 overflow-auto`,onTouchStart:e=>{q.current=e.touches[0].clientX},onTouchEnd:e=>{let t=q.current-e.changedTouches[0].clientX;if(Math.abs(t)>50){let e=new Date(A);S===`day`?e.setDate(e.getDate()+(t>0?1:-1)):S===`week`?e.setDate(e.getDate()+(t>0?7:-7)):e.setMonth(e.getMonth()+(t>0?1:-1)),M(e),s?.(e)}},children:[S===`month`&&(0,k.jsx)(z,{date:A,events:e,locale:L,onEventClick:i,onDateClick:a,onEventDrop:l}),S===`week`&&(0,k.jsx)(B,{date:A,events:e,locale:L,onEventClick:i,onDateClick:a}),S===`day`&&(0,k.jsx)(V,{date:A,events:e,onEventClick:i,onDateClick:a})]})]})}function F(e){let t=new Date(e),n=t.getDay(),r=t.getDate()-n;return t.setDate(r),t}function I(e){let t=e.getFullYear(),n=e.getMonth(),r=new Date(t,n,1),i=new Date(t,n+1,0),a=r.getDay(),o=[];for(let e=a-1;e>=0;e--){let t=new Date(r.getTime());t.setDate(t.getDate()-(e+1)),o.push(t)}for(let e=1;e<=i.getDate();e++)o.push(new Date(t,n,e));let s=42-o.length;for(let e=1;e<=s;e++){let t=new Date(i.getTime());t.setDate(t.getDate()+e),o.push(t)}return o}function L(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function R(e,t){return t.filter(t=>{let n=new Date(t.start),r=t.end?new Date(t.end):new Date(n),i=new Date(e);i.setHours(0,0,0,0);let a=new Date(e);a.setHours(23,59,59,999);let o=new Date(n);o.setHours(0,0,0,0);let s=new Date(r);return s.setHours(23,59,59,999),i<=s&&a>=o})}function z({date:e,events:t,locale:n=`default`,onEventClick:r,onDateClick:i,onEventDrop:a}){let o=O.useMemo(()=>I(e),[e.getFullYear(),e.getMonth()]),s=O.useMemo(()=>new Date,[]),{t:c}=N(),l=O.useMemo(()=>{let e=new Date(2024,0,7);return Array.from({length:7},(t,r)=>{let i=new Date(e);return i.setDate(i.getDate()+r),i.toLocaleDateString(n,{weekday:`short`})})},[n]),[u,d]=O.useState(null),[p,m]=O.useState(null),h=O.useMemo(()=>{let e=new Map;for(let n of t){let t=new Date(n.start),r=n.end?new Date(n.end):new Date(t);t.setHours(0,0,0,0),r.setHours(0,0,0,0);let i=new Date(t);for(;i<=r;){let t=`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`,r=e.get(t);r?r.push(n):e.set(t,[n]),i.setDate(i.getDate()+1)}}return e},[t]),g=(e,t)=>{d(t.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(t.id))},_=()=>{d(null),m(null)},v=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},y=e=>{e.currentTarget.contains(e.relatedTarget)||m(null)},b=(e,n)=>{if(e.preventDefault(),m(null),d(null),!a)return;let r=e.dataTransfer.getData(`text/plain`),i=t.find(e=>String(e.id)===r);if(!i)return;let o=new Date(i.start),s=new Date(o);s.setHours(0,0,0,0);let c=new Date(n);c.setHours(0,0,0,0);let l=c.getTime()-s.getTime();if(l===0)return;let u=new Date(o.getTime()+l),f;i.end&&(f=new Date(new Date(i.end).getTime()+l)),a(i,u,f)};return(0,k.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,k.jsx)(`div`,{role:`row`,className:`grid grid-cols-7 border-b`,children:l.map(e=>(0,k.jsx)(`div`,{role:`columnheader`,className:`p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0`,children:e},e))}),(0,k.jsx)(`div`,{role:`grid`,"aria-label":`Calendar grid`,className:`grid grid-cols-7 flex-1 auto-rows-fr`,children:o.map((t,n)=>{let o=`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`,l=h.get(o)||[],d=t.getMonth()===e.getMonth(),m=L(t,s);return(0,k.jsxs)(`div`,{role:`gridcell`,"aria-label":`${t.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${l.length>0?`, ${l.length} event${l.length>1?`s`:``}`:``}`,className:f(`border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50`,!d&&`bg-muted/50 text-muted-foreground opacity-50`,p===n&&`ring-2 ring-primary`),onClick:()=>i?.(t),onDragOver:e=>v(e,n),onDragLeave:y,onDrop:e=>b(e,t),children:[(0,k.jsx)(`div`,{className:f(`text-sm font-medium mb-2`,m&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6`),...m?{"aria-current":`date`}:{},children:t.getDate()}),(0,k.jsxs)(`div`,{className:`space-y-1`,children:[l.slice(0,3).map(e=>(0,k.jsx)(`div`,{role:`button`,title:e.title,"aria-label":e.title,draggable:!!a,onDragStart:t=>g(t,e),onDragEnd:_,className:f(`text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A,u===e.id&&`opacity-50`),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:t=>{t.stopPropagation(),r?.(e)},children:e.title},e.id)),l.length>3&&(0,k.jsx)(`div`,{className:`text-xs text-muted-foreground px-2`,children:c(`calendar.moreEvents`,{count:l.length-3})})]})]},n)})})]})}function B({date:e,events:t,locale:n=`default`,onEventClick:r,onDateClick:i}){let a=O.useRef(null),o=e=>{i&&(a.current=setTimeout(()=>{i(e)},500))},s=()=>{a.current&&=(clearTimeout(a.current),null)},c=F(e),l=Array.from({length:7},(e,t)=>{let n=new Date(c);return n.setDate(n.getDate()+t),n}),u=new Date;return(0,k.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,k.jsx)(`div`,{className:`grid grid-cols-7 border-b`,children:l.map(e=>{let t=L(e,u);return(0,k.jsxs)(`div`,{className:`p-3 text-center border-r last:border-r-0`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium text-muted-foreground`,children:e.toLocaleDateString(n,{weekday:`short`})}),(0,k.jsx)(`div`,{className:f(`text-lg font-semibold mt-1`,t&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-8 w-8`),children:e.getDate()})]},e.toISOString())})}),(0,k.jsx)(`div`,{role:`grid`,className:`grid grid-cols-7 flex-1`,children:l.map(e=>{let n=R(e,t);return(0,k.jsx)(`div`,{role:`gridcell`,"aria-label":`${e.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${n.length>0?`, ${n.length} event${n.length>1?`s`:``}`:``}`,className:`border-r last:border-r-0 p-2 min-h-[400px] cursor-pointer hover:bg-accent/50`,onClick:()=>i?.(e),onTouchStart:()=>o(e),onTouchEnd:s,children:(0,k.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,k.jsxs)(`div`,{role:`button`,title:e.title,"aria-label":e.title,className:f(`text-xs sm:text-sm px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:t=>{t.stopPropagation(),r?.(e)},children:[(0,k.jsx)(`div`,{className:`font-medium truncate`,children:e.title}),!e.allDay&&(0,k.jsx)(`div`,{className:`text-xs opacity-90 mt-1`,children:e.start.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`})})]},e.id))})},e.toISOString())})})]})}function V({date:e,events:t,onEventClick:n,onDateClick:r}){let i=R(e,t),a=Array.from({length:24},(e,t)=>t),o=O.useRef(null),s=t=>{r&&(o.current=setTimeout(()=>{let n=new Date(e);n.setHours(t,0,0,0),r(n)},500))},c=()=>{o.current&&=(clearTimeout(o.current),null)};return(0,k.jsx)(`div`,{className:`flex flex-col h-full`,children:(0,k.jsx)(`div`,{role:`list`,className:`flex-1 overflow-auto`,children:a.map(e=>{let t=i.filter(t=>t.allDay?e===0:t.start.getHours()===e);return(0,k.jsxs)(`div`,{role:`listitem`,className:`flex border-b min-h-[60px]`,children:[(0,k.jsx)(`div`,{className:`w-20 p-2 text-sm text-muted-foreground border-r`,children:e===0?`12 AM`:e<12?`${e} AM`:e===12?`12 PM`:`${e-12} PM`}),(0,k.jsx)(`div`,{className:`flex-1 p-2 space-y-2`,onTouchStart:()=>s(e),onTouchEnd:c,children:t.map(e=>(0,k.jsxs)(`div`,{title:e.title,"aria-label":e.title,className:f(`px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:()=>n?.(e),children:[(0,k.jsx)(`div`,{className:`font-medium truncate`,children:e.title}),!e.allDay&&(0,k.jsxs)(`div`,{className:`text-xs opacity-90 mt-1`,children:[e.start.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`}),e.end&&` - ${e.end.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`})}`]})]},e.id))})]},e)})})})}function H(e){return`data`in e&&e.data?e.data:`staticData`in e&&e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function U(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function W(e){return`filter`in e&&e.filter&&typeof e.filter==`object`&&`calendar`in e.filter?e.filter.calendar:e.calendar?e.calendar:e.startDateField||e.dateField?{startDateField:e.startDateField||e.dateField,endDateField:e.endDateField||e.endField,titleField:e.titleField,colorField:e.colorField,allDayField:e.allDayField}:null}var G=({schema:e,dataSource:t,className:n,data:r,loading:i,onEventClick:o,onRowClick:c,onDateClick:u,onNavigate:d,onViewChange:f,onEventDrop:p,locale:h})=>{let g=Array.isArray(r),[_,v]=(0,O.useState)(g?r:[]),[y,b]=(0,O.useState)(g?i??!1:!0),[x,C]=(0,O.useState)(null),[w,T]=(0,O.useState)(null),[E,A]=(0,O.useState)(new Date),j=m(),M=e.defaultView,[N,F]=(0,O.useState)(()=>{let e=M===`day`||!M;return typeof window<`u`&&window.innerWidth<768&&e?`month`:M||`month`});(0,O.useEffect)(()=>{j&&N===`day`&&(M===`day`||!M)&&F(`month`)},[j]);let[I,L]=(0,O.useState)(0);(0,O.useEffect)(()=>{if(!g&&!(!t?.onMutation||!e.objectName))return t.onMutation(t=>{t.resource===e.objectName&&L(e=>e+1)})},[t,e.objectName,g]);let{ref:R,isRefreshing:z,pullDistance:B}=D({onRefresh:(0,O.useCallback)(async()=>{L(e=>e+1)},[]),enabled:!!t&&!!e.objectName}),V=(0,O.useMemo)(()=>H(e),[e.data,e.staticData,e.objectName]),G=(0,O.useMemo)(()=>W(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),K=V?.provider===`value`,q=(0,O.useRef)(null);q.current=w,(0,O.useEffect)(()=>{g&&v(r)},[r,g]),(0,O.useEffect)(()=>{g&&i!==void 0&&b(i)},[i,g]),(0,O.useEffect)(()=>{if(g)return;let n=!0;return(async()=>{try{if(!n)return;if(b(!0),K&&V?.provider===`value`){n&&(v(V.items),b(!1));return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(V?.provider===`object`){let r=V.object,i=a(q.current?.fields),o=s(await t.find(r,{$filter:e.filter,$orderby:U(e.sort),...i.length>0?{$expand:i}:{}}));n&&v(o)}else V?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectCalendar`),n&&v([]));n&&b(!1)}catch(e){console.error(`[ObjectCalendar] Error fetching data:`,e),n&&(C(e),b(!1))}})(),()=>{n=!1}},[g,V,t,K,e.filter,e.sort,I]),(0,O.useEffect)(()=>{!K&&t&&(async()=>{try{if(!t)return;let n=V?.provider===`object`?V.object:e.objectName;if(!n)return;T(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,K,V]);let J=(0,O.useMemo)(()=>{if(!G||!_.length)return[];let{startDateField:e,endDateField:t,titleField:n,colorField:r}=G,i=w?.titleFormat,a=w?.NAME_FIELD_KEY,o=[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`],s=(e,t)=>{let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=e.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=t[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r?i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim():``},c=e=>{let t;if(n&&(t=e[n],typeof t==`string`&&(t=t.trim())),!t&&i){let n=s(i,e);n&&(t=n)}if(!t&&a){let n=e[a];typeof n==`string`?t=n.trim():n&&(t=n)}if(!t)for(let n of o){let r=e[n],i=typeof r==`string`?r.trim():r;if(i){t=i;break}}return t||`Untitled`};return _.map((n,i)=>{let a=n[e],o=t?n[t]:null,s=c(n),l=r?n[r]:void 0;return{id:n.id||n._id||`event-${i}`,title:s,start:a?new Date(a):new Date,end:o?new Date(o):void 0,color:l,allDay:!o,data:n}}).filter(e=>!isNaN(e.start.getTime()))},[_,G,w]);(0,O.useCallback)(()=>{u?.(new Date)},[u]);let Y=l({navigation:e.navigation,objectName:e.objectName,onRowClick:c});return y?(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading calendar...`})})}):x?(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,x.message]})})}):G?(0,k.jsxs)(`div`,{ref:R,className:n,children:[B>0&&(0,k.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,k.jsx)(`div`,{className:`border rounded-lg bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]`,children:(0,k.jsx)(P,{events:J,currentDate:E,view:N,locale:h,onEventClick:e=>{Y.handleClick(e.data),o?.(e.data)},onDateClick:u,onNavigate:e=>{A(e),d?.(e)},onViewChange:e=>{F(e),f?.(e)},onAddClick:void 0,onEventDrop:p?(e,t,n)=>{p(e.data,t,n)}:void 0})}),Y.isOverlay&&(0,k.jsx)(S,{...Y,title:`Event Details`,children:e=>(0,k.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,k.jsxs)(`div`,{className:`flex flex-col`,children:[(0,k.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,k.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]}):(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsx)(`div`,{className:`text-muted-foreground`,children:`Calendar configuration required. Please specify startDateField and titleField.`})})})};i.register(`calendar-view`,({schema:e,className:t,onAction:n,...r})=>{let i=O.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((t,n)=>{let r=e.titleField||`title`,i=e.startDateField||`start`,a=e.endDateField||`end`,o=e.colorField||`color`,s=e.allDayField||`allDay`;return{id:t.id||t._id||n,title:t[r]||`Untitled Event`,start:new Date(t[i]),end:t[a]?new Date(t[a]):void 0,allDay:t[s],color:t[o],data:t}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField]);return(0,k.jsx)(P,{className:t,events:i,onEventClick:e=>{n?.({type:`event-click`,payload:e})},...r})},{namespace:`plugin-calendar`,label:`Calendar View`,inputs:[{name:`data`,type:`array`,label:`Data`,description:`Array of record objects to display as events`},{name:`titleField`,type:`string`,label:`Title Field`,defaultValue:`title`,description:`Field name to use for event title`},{name:`startDateField`,type:`string`,label:`Start Date Field`,defaultValue:`start`,description:`Field name for event start date`},{name:`endDateField`,type:`string`,label:`End Date Field`,defaultValue:`end`,description:`Field name for event end date (optional)`},{name:`allDayField`,type:`string`,label:`All Day Field`,defaultValue:`allDay`,description:`Field name for all-day flag`},{name:`colorField`,type:`string`,label:`Color Field`,defaultValue:`color`,description:`Field name for event color`},{name:`colorMapping`,type:`object`,label:`Color Mapping`,description:`Map field values to colors (e.g., {meeting: "blue", deadline: "red"})`},{name:`view`,type:`enum`,enum:[`month`,`week`,`day`],defaultValue:`month`,label:`View Mode`,description:`Calendar view mode (month, week, or day)`},{name:`currentDate`,type:`string`,label:`Current Date`,description:`ISO date string for initial calendar date`},{name:`allowCreate`,type:`boolean`,label:`Allow Create`,defaultValue:!1,description:`Allow creating events by clicking on dates`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{view:`month`,titleField:`title`,startDateField:`start`,endDateField:`end`,allDayField:`allDay`,colorField:`color`,allowCreate:!1,data:[{id:1,title:`Team Meeting`,start:new Date(new Date().setHours(10,0,0,0)).toISOString(),end:new Date(new Date().setHours(11,0,0,0)).toISOString(),color:`#3b82f6`,allDay:!1},{id:2,title:`Project Deadline`,start:new Date(new Date().setDate(new Date().getDate()+3)).toISOString(),color:`#ef4444`,allDay:!0},{id:3,title:`Conference`,start:new Date(new Date().setDate(new Date().getDate()+7)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()+9)).toISOString(),color:`#10b981`,allDay:!0}],className:`h-[600px] border rounded-lg`}});var K=e({CalendarView:()=>P,ObjectCalendar:()=>G,ObjectCalendarRenderer:()=>q}),q=({schema:e,...t})=>{let{dataSource:n}=o()||{};return(0,k.jsx)(G,{schema:e,dataSource:n,...t})};i.register(`object-calendar`,q,{namespace:`plugin-calendar`,label:`Object Calendar`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]}),i.register(`calendar`,q,{namespace:`view`,label:`Calendar View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]});export{K as t};
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,t as r}from"./vendor-react-B1k2FF9f.js";import{H as i,L as a,M as o,R as s,a as c,w as l}from"./framework-CoXA0nY6.js";import{$t as u,NL as d,QA as f,Qt as p,Ut as m,XA as h,Zt as g,cn as _,en as v,lm as y,ln as b,nt as x,pM as S,rr as C,sn as w,tn as T,vr as E}from"./ui-components-DSSaN2w_.js";import{i as D}from"./plugin-grid-C9RnYppl.js";var O=t(n(),1),k=r(),A=`bg-blue-500 text-white`,j=new Date,M={"calendar.today":`Today`,"calendar.month":`Month`,"calendar.week":`Week`,"calendar.day":`Day`,"calendar.newEvent":`New event`,"calendar.moreEvents":`+{{count}} more`};function N(){try{let e=c();return e.t(`calendar.today`)===`calendar.today`?{t:(e,t)=>{let n=M[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}:{t:e.t,language:e.language}}catch{return{t:(e,t)=>{let n=M[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n},language:`en`}}}function P({events:e=[],view:t=`month`,currentDate:n=j,locale:r=`default`,onEventClick:i,onDateClick:a,onViewChange:o,onNavigate:s,onAddClick:c,onEventDrop:l,className:m}){let[x,D]=O.useState(t),[A,M]=O.useState(n),{t:P,language:I}=N(),L=r===`default`?I:r;O.useEffect(()=>{M(n)},[n]),O.useEffect(()=>{D(t)},[t]);let R=O.useRef(o);R.current=o,O.useEffect(()=>{let e=window.matchMedia(`(max-width: 639px)`),t=e=>{e.matches&&(D(`day`),R.current?.(`day`))};return t(e),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let H=()=>{let e=new Date(A);x===`month`?e.setMonth(e.getMonth()-1):x===`week`?e.setDate(e.getDate()-7):e.setDate(e.getDate()-1),M(e),s?.(e)},U=()=>{let e=new Date(A);x===`month`?e.setMonth(e.getMonth()+1):x===`week`?e.setDate(e.getDate()+7):e.setDate(e.getDate()+1),M(e),s?.(e)},W=()=>{let e=new Date;M(e),s?.(e)},G=e=>{D(e),o?.(e)},K=()=>{if(x===`month`)return A.toLocaleDateString(L,{month:`long`,year:`numeric`});if(x===`week`){let e=F(A),t=new Date(e);return t.setDate(t.getDate()+6),`${e.toLocaleDateString(L,{month:`short`,day:`numeric`})} - ${t.toLocaleDateString(L,{month:`short`,day:`numeric`,year:`numeric`})}`}else return A.toLocaleDateString(L,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})},q=O.useRef(0);return(0,k.jsxs)(`div`,{role:`region`,"aria-label":`Calendar`,className:d(`flex flex-col h-full bg-background min-w-0 overflow-hidden`,m),children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 p-2 sm:p-4 border-b min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center bg-muted/50 rounded-lg p-1 gap-1`,children:[(0,k.jsx)(E,{variant:`ghost`,size:`sm`,onClick:W,className:`h-8`,"aria-label":`Go to today`,children:P(`calendar.today`)}),(0,k.jsx)(`div`,{className:`h-4 w-px bg-border mx-1`}),(0,k.jsx)(E,{variant:`ghost`,size:`icon`,"aria-label":`Previous period`,onClick:H,className:`h-8 w-8`,children:(0,k.jsx)(f,{className:`h-4 w-4`})}),(0,k.jsx)(E,{variant:`ghost`,size:`icon`,"aria-label":`Next period`,onClick:U,className:`h-8 w-8`,children:(0,k.jsx)(h,{className:`h-4 w-4`})})]}),(0,k.jsxs)(w,{children:[(0,k.jsx)(b,{asChild:!0,children:(0,k.jsxs)(E,{variant:`ghost`,"aria-label":`Current date: ${K()}`,className:d(`text-base sm:text-xl font-semibold h-auto px-2 sm:px-3 py-1 hover:bg-muted/50 transition-colors`,`flex items-center gap-2`),children:[(0,k.jsx)(S,{className:`h-5 w-5 text-muted-foreground`}),(0,k.jsx)(`span`,{children:K()})]})}),(0,k.jsx)(_,{className:`w-auto p-0`,align:`start`,children:(0,k.jsx)(C,{mode:`single`,selected:A,onSelect:e=>{e&&(M(e),s?.(e))},initialFocus:!0,fromYear:2e3,toYear:2050})})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(g,{value:x,onValueChange:G,children:[(0,k.jsx)(v,{className:`w-32 bg-background`,children:(0,k.jsx)(T,{})}),(0,k.jsxs)(p,{children:[(0,k.jsx)(u,{value:`day`,children:P(`calendar.day`)}),(0,k.jsx)(u,{value:`week`,children:P(`calendar.week`)}),(0,k.jsx)(u,{value:`month`,children:P(`calendar.month`)})]})]}),c&&(0,k.jsxs)(E,{onClick:c,size:`sm`,className:`gap-1`,children:[(0,k.jsx)(y,{className:`h-4 w-4`}),P(`calendar.newEvent`)]})]})]}),(0,k.jsxs)(`div`,{className:`flex-1 overflow-auto`,onTouchStart:e=>{q.current=e.touches[0].clientX},onTouchEnd:e=>{let t=q.current-e.changedTouches[0].clientX;if(Math.abs(t)>50){let e=new Date(A);x===`day`?e.setDate(e.getDate()+(t>0?1:-1)):x===`week`?e.setDate(e.getDate()+(t>0?7:-7)):e.setMonth(e.getMonth()+(t>0?1:-1)),M(e),s?.(e)}},children:[x===`month`&&(0,k.jsx)(z,{date:A,events:e,locale:L,onEventClick:i,onDateClick:a,onEventDrop:l}),x===`week`&&(0,k.jsx)(B,{date:A,events:e,locale:L,onEventClick:i,onDateClick:a}),x===`day`&&(0,k.jsx)(V,{date:A,events:e,onEventClick:i,onDateClick:a})]})]})}function F(e){let t=new Date(e),n=t.getDay(),r=t.getDate()-n;return t.setDate(r),t}function I(e){let t=e.getFullYear(),n=e.getMonth(),r=new Date(t,n,1),i=new Date(t,n+1,0),a=r.getDay(),o=[];for(let e=a-1;e>=0;e--){let t=new Date(r.getTime());t.setDate(t.getDate()-(e+1)),o.push(t)}for(let e=1;e<=i.getDate();e++)o.push(new Date(t,n,e));let s=42-o.length;for(let e=1;e<=s;e++){let t=new Date(i.getTime());t.setDate(t.getDate()+e),o.push(t)}return o}function L(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function R(e,t){return t.filter(t=>{let n=new Date(t.start),r=t.end?new Date(t.end):new Date(n),i=new Date(e);i.setHours(0,0,0,0);let a=new Date(e);a.setHours(23,59,59,999);let o=new Date(n);o.setHours(0,0,0,0);let s=new Date(r);return s.setHours(23,59,59,999),i<=s&&a>=o})}function z({date:e,events:t,locale:n=`default`,onEventClick:r,onDateClick:i,onEventDrop:a}){let o=O.useMemo(()=>I(e),[e.getFullYear(),e.getMonth()]),s=O.useMemo(()=>new Date,[]),{t:c}=N(),l=O.useMemo(()=>{let e=new Date(2024,0,7);return Array.from({length:7},(t,r)=>{let i=new Date(e);return i.setDate(i.getDate()+r),i.toLocaleDateString(n,{weekday:`short`})})},[n]),[u,f]=O.useState(null),[p,m]=O.useState(null),h=O.useMemo(()=>{let e=new Map;for(let n of t){let t=new Date(n.start),r=n.end?new Date(n.end):new Date(t);t.setHours(0,0,0,0),r.setHours(0,0,0,0);let i=new Date(t);for(;i<=r;){let t=`${i.getFullYear()}-${i.getMonth()}-${i.getDate()}`,r=e.get(t);r?r.push(n):e.set(t,[n]),i.setDate(i.getDate()+1)}}return e},[t]),g=(e,t)=>{f(t.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(t.id))},_=()=>{f(null),m(null)},v=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},y=e=>{e.currentTarget.contains(e.relatedTarget)||m(null)},b=(e,n)=>{if(e.preventDefault(),m(null),f(null),!a)return;let r=e.dataTransfer.getData(`text/plain`),i=t.find(e=>String(e.id)===r);if(!i)return;let o=new Date(i.start),s=new Date(o);s.setHours(0,0,0,0);let c=new Date(n);c.setHours(0,0,0,0);let l=c.getTime()-s.getTime();if(l===0)return;let u=new Date(o.getTime()+l),d;i.end&&(d=new Date(new Date(i.end).getTime()+l)),a(i,u,d)};return(0,k.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,k.jsx)(`div`,{role:`row`,className:`grid grid-cols-7 border-b`,children:l.map(e=>(0,k.jsx)(`div`,{role:`columnheader`,className:`p-2 text-center text-sm font-medium text-muted-foreground border-r last:border-r-0`,children:e},e))}),(0,k.jsx)(`div`,{role:`grid`,"aria-label":`Calendar grid`,className:`grid grid-cols-7 flex-1 auto-rows-fr`,children:o.map((t,n)=>{let o=`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`,l=h.get(o)||[],f=t.getMonth()===e.getMonth(),m=L(t,s);return(0,k.jsxs)(`div`,{role:`gridcell`,"aria-label":`${t.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${l.length>0?`, ${l.length} event${l.length>1?`s`:``}`:``}`,className:d(`border-b border-r last:border-r-0 p-2 min-h-[100px] cursor-pointer hover:bg-accent/50`,!f&&`bg-muted/50 text-muted-foreground opacity-50`,p===n&&`ring-2 ring-primary`),onClick:()=>i?.(t),onDragOver:e=>v(e,n),onDragLeave:y,onDrop:e=>b(e,t),children:[(0,k.jsx)(`div`,{className:d(`text-sm font-medium mb-2`,m&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-6 w-6`),...m?{"aria-current":`date`}:{},children:t.getDate()}),(0,k.jsxs)(`div`,{className:`space-y-1`,children:[l.slice(0,3).map(e=>(0,k.jsx)(`div`,{role:`button`,title:e.title,"aria-label":e.title,draggable:!!a,onDragStart:t=>g(t,e),onDragEnd:_,className:d(`text-xs px-2 py-1 rounded truncate cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A,u===e.id&&`opacity-50`),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:t=>{t.stopPropagation(),r?.(e)},children:e.title},e.id)),l.length>3&&(0,k.jsx)(`div`,{className:`text-xs text-muted-foreground px-2`,children:c(`calendar.moreEvents`,{count:l.length-3})})]})]},n)})})]})}function B({date:e,events:t,locale:n=`default`,onEventClick:r,onDateClick:i}){let a=O.useRef(null),o=e=>{i&&(a.current=setTimeout(()=>{i(e)},500))},s=()=>{a.current&&=(clearTimeout(a.current),null)},c=F(e),l=Array.from({length:7},(e,t)=>{let n=new Date(c);return n.setDate(n.getDate()+t),n}),u=new Date;return(0,k.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,k.jsx)(`div`,{className:`grid grid-cols-7 border-b`,children:l.map(e=>{let t=L(e,u);return(0,k.jsxs)(`div`,{className:`p-3 text-center border-r last:border-r-0`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium text-muted-foreground`,children:e.toLocaleDateString(n,{weekday:`short`})}),(0,k.jsx)(`div`,{className:d(`text-lg font-semibold mt-1`,t&&`inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground h-8 w-8`),children:e.getDate()})]},e.toISOString())})}),(0,k.jsx)(`div`,{role:`grid`,className:`grid grid-cols-7 flex-1`,children:l.map(e=>{let n=R(e,t);return(0,k.jsx)(`div`,{role:`gridcell`,"aria-label":`${e.toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}${n.length>0?`, ${n.length} event${n.length>1?`s`:``}`:``}`,className:`border-r last:border-r-0 p-2 min-h-[400px] cursor-pointer hover:bg-accent/50`,onClick:()=>i?.(e),onTouchStart:()=>o(e),onTouchEnd:s,children:(0,k.jsx)(`div`,{className:`space-y-2`,children:n.map(e=>(0,k.jsxs)(`div`,{role:`button`,title:e.title,"aria-label":e.title,className:d(`text-xs sm:text-sm px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:t=>{t.stopPropagation(),r?.(e)},children:[(0,k.jsx)(`div`,{className:`font-medium truncate`,children:e.title}),!e.allDay&&(0,k.jsx)(`div`,{className:`text-xs opacity-90 mt-1`,children:e.start.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`})})]},e.id))})},e.toISOString())})})]})}function V({date:e,events:t,onEventClick:n,onDateClick:r}){let i=R(e,t),a=Array.from({length:24},(e,t)=>t),o=O.useRef(null),s=t=>{r&&(o.current=setTimeout(()=>{let n=new Date(e);n.setHours(t,0,0,0),r(n)},500))},c=()=>{o.current&&=(clearTimeout(o.current),null)};return(0,k.jsx)(`div`,{className:`flex flex-col h-full`,children:(0,k.jsx)(`div`,{role:`list`,className:`flex-1 overflow-auto`,children:a.map(e=>{let t=i.filter(t=>t.allDay?e===0:t.start.getHours()===e);return(0,k.jsxs)(`div`,{role:`listitem`,className:`flex border-b min-h-[60px]`,children:[(0,k.jsx)(`div`,{className:`w-20 p-2 text-sm text-muted-foreground border-r`,children:e===0?`12 AM`:e<12?`${e} AM`:e===12?`12 PM`:`${e-12} PM`}),(0,k.jsx)(`div`,{className:`flex-1 p-2 space-y-2`,onTouchStart:()=>s(e),onTouchEnd:c,children:t.map(e=>(0,k.jsxs)(`div`,{title:e.title,"aria-label":e.title,className:d(`px-2 sm:px-3 py-1.5 sm:py-2 rounded cursor-pointer hover:opacity-80`,e.color?.startsWith(`#`)?`text-white`:e.color||A),style:e.color&&e.color.startsWith(`#`)?{backgroundColor:e.color}:void 0,onClick:()=>n?.(e),children:[(0,k.jsx)(`div`,{className:`font-medium truncate`,children:e.title}),!e.allDay&&(0,k.jsxs)(`div`,{className:`text-xs opacity-90 mt-1`,children:[e.start.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`}),e.end&&` - ${e.end.toLocaleTimeString(`default`,{hour:`numeric`,minute:`2-digit`})}`]})]},e.id))})]},e)})})})}function H(e){return`data`in e&&e.data?e.data:`staticData`in e&&e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function U(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function W(e){return`filter`in e&&e.filter&&typeof e.filter==`object`&&`calendar`in e.filter?e.filter.calendar:e.calendar?e.calendar:e.startDateField||e.dateField?{startDateField:e.startDateField||e.dateField,endDateField:e.endDateField||e.endField,titleField:e.titleField,colorField:e.colorField,allDayField:e.allDayField}:null}var G=({schema:e,dataSource:t,className:n,data:r,loading:i,onEventClick:o,onRowClick:c,onDateClick:u,onNavigate:d,onViewChange:f,onEventDrop:p,locale:h})=>{let g=Array.isArray(r),[_,v]=(0,O.useState)(g?r:[]),[y,b]=(0,O.useState)(g?i??!1:!0),[S,C]=(0,O.useState)(null),[w,T]=(0,O.useState)(null),[E,A]=(0,O.useState)(new Date),j=m(),M=e.defaultView,[N,F]=(0,O.useState)(()=>{let e=M===`day`||!M;return typeof window<`u`&&window.innerWidth<768&&e?`month`:M||`month`});(0,O.useEffect)(()=>{j&&N===`day`&&(M===`day`||!M)&&F(`month`)},[j]);let[I,L]=(0,O.useState)(0);(0,O.useEffect)(()=>{if(!g&&!(!t?.onMutation||!e.objectName))return t.onMutation(t=>{t.resource===e.objectName&&L(e=>e+1)})},[t,e.objectName,g]);let{ref:R,isRefreshing:z,pullDistance:B}=D({onRefresh:(0,O.useCallback)(async()=>{L(e=>e+1)},[]),enabled:!!t&&!!e.objectName}),V=(0,O.useMemo)(()=>H(e),[e.data,e.staticData,e.objectName]),G=(0,O.useMemo)(()=>W(e),[e.filter,e.calendar,e.dateField,e.endField,e.titleField,e.colorField]),K=V?.provider===`value`,q=(0,O.useRef)(null);q.current=w,(0,O.useEffect)(()=>{g&&v(r)},[r,g]),(0,O.useEffect)(()=>{g&&i!==void 0&&b(i)},[i,g]),(0,O.useEffect)(()=>{if(g)return;let n=!0;return(async()=>{try{if(!n)return;if(b(!0),K&&V?.provider===`value`){n&&(v(V.items),b(!1));return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(V?.provider===`object`){let r=V.object,i=a(q.current?.fields),o=s(await t.find(r,{$filter:e.filter,$orderby:U(e.sort),...i.length>0?{$expand:i}:{}}));n&&v(o)}else V?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectCalendar`),n&&v([]));n&&b(!1)}catch(e){console.error(`[ObjectCalendar] Error fetching data:`,e),n&&(C(e),b(!1))}})(),()=>{n=!1}},[g,V,t,K,e.filter,e.sort,I]),(0,O.useEffect)(()=>{!K&&t&&(async()=>{try{if(!t)return;let n=V?.provider===`object`?V.object:e.objectName;if(!n)return;T(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,K,V]);let J=(0,O.useMemo)(()=>{if(!G||!_.length)return[];let{startDateField:e,endDateField:t,titleField:n,colorField:r}=G,i=w?.titleFormat,a=w?.NAME_FIELD_KEY,o=[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`],s=(e,t)=>{let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=e.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=t[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r?i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim():``},c=e=>{let t;if(n&&(t=e[n],typeof t==`string`&&(t=t.trim())),!t&&i){let n=s(i,e);n&&(t=n)}if(!t&&a){let n=e[a];typeof n==`string`?t=n.trim():n&&(t=n)}if(!t)for(let n of o){let r=e[n],i=typeof r==`string`?r.trim():r;if(i){t=i;break}}return t||`Untitled`};return _.map((n,i)=>{let a=n[e],o=t?n[t]:null,s=c(n),l=r?n[r]:void 0;return{id:n.id||n._id||`event-${i}`,title:s,start:a?new Date(a):new Date,end:o?new Date(o):void 0,color:l,allDay:!o,data:n}}).filter(e=>!isNaN(e.start.getTime()))},[_,G,w]);(0,O.useCallback)(()=>{u?.(new Date)},[u]);let Y=l({navigation:e.navigation,objectName:e.objectName,onRowClick:c});return y?(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading calendar...`})})}):S?(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,S.message]})})}):G?(0,k.jsxs)(`div`,{ref:R,className:n,children:[B>0&&(0,k.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:B},children:z?`Refreshing…`:`Pull to refresh`}),(0,k.jsx)(`div`,{className:`border rounded-lg bg-background h-[calc(100vh-120px)] sm:h-[calc(100vh-160px)] md:h-[calc(100vh-200px)] min-h-[400px] sm:min-h-[600px]`,children:(0,k.jsx)(P,{events:J,currentDate:E,view:N,locale:h,onEventClick:e=>{Y.handleClick(e.data),o?.(e.data)},onDateClick:u,onNavigate:e=>{A(e),d?.(e)},onViewChange:e=>{F(e),f?.(e)},onAddClick:void 0,onEventDrop:p?(e,t,n)=>{p(e.data,t,n)}:void 0})}),Y.isOverlay&&(0,k.jsx)(x,{...Y,title:`Event Details`,children:e=>(0,k.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,k.jsxs)(`div`,{className:`flex flex-col`,children:[(0,k.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,k.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]}):(0,k.jsx)(`div`,{className:n,children:(0,k.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,k.jsx)(`div`,{className:`text-muted-foreground`,children:`Calendar configuration required. Please specify startDateField and titleField.`})})})};i.register(`calendar-view`,({schema:e,className:t,onAction:n,...r})=>{let i=O.useMemo(()=>!e.data||!Array.isArray(e.data)?[]:e.data.map((t,n)=>{let r=e.titleField||`title`,i=e.startDateField||`start`,a=e.endDateField||`end`,o=e.colorField||`color`,s=e.allDayField||`allDay`;return{id:t.id||t._id||n,title:t[r]||`Untitled Event`,start:new Date(t[i]),end:t[a]?new Date(t[a]):void 0,allDay:t[s],color:t[o],data:t}}),[e.data,e.titleField,e.startDateField,e.endDateField,e.colorField,e.allDayField]);return(0,k.jsx)(P,{className:t,events:i,onEventClick:e=>{n?.({type:`event-click`,payload:e})},...r})},{namespace:`plugin-calendar`,label:`Calendar View`,inputs:[{name:`data`,type:`array`,label:`Data`,description:`Array of record objects to display as events`},{name:`titleField`,type:`string`,label:`Title Field`,defaultValue:`title`,description:`Field name to use for event title`},{name:`startDateField`,type:`string`,label:`Start Date Field`,defaultValue:`start`,description:`Field name for event start date`},{name:`endDateField`,type:`string`,label:`End Date Field`,defaultValue:`end`,description:`Field name for event end date (optional)`},{name:`allDayField`,type:`string`,label:`All Day Field`,defaultValue:`allDay`,description:`Field name for all-day flag`},{name:`colorField`,type:`string`,label:`Color Field`,defaultValue:`color`,description:`Field name for event color`},{name:`colorMapping`,type:`object`,label:`Color Mapping`,description:`Map field values to colors (e.g., {meeting: "blue", deadline: "red"})`},{name:`view`,type:`enum`,enum:[`month`,`week`,`day`],defaultValue:`month`,label:`View Mode`,description:`Calendar view mode (month, week, or day)`},{name:`currentDate`,type:`string`,label:`Current Date`,description:`ISO date string for initial calendar date`},{name:`allowCreate`,type:`boolean`,label:`Allow Create`,defaultValue:!1,description:`Allow creating events by clicking on dates`},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{view:`month`,titleField:`title`,startDateField:`start`,endDateField:`end`,allDayField:`allDay`,colorField:`color`,allowCreate:!1,data:[{id:1,title:`Team Meeting`,start:new Date(new Date().setHours(10,0,0,0)).toISOString(),end:new Date(new Date().setHours(11,0,0,0)).toISOString(),color:`#3b82f6`,allDay:!1},{id:2,title:`Project Deadline`,start:new Date(new Date().setDate(new Date().getDate()+3)).toISOString(),color:`#ef4444`,allDay:!0},{id:3,title:`Conference`,start:new Date(new Date().setDate(new Date().getDate()+7)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()+9)).toISOString(),color:`#10b981`,allDay:!0}],className:`h-[600px] border rounded-lg`}});var K=e({CalendarView:()=>P,ObjectCalendar:()=>G,ObjectCalendarRenderer:()=>q}),q=({schema:e,...t})=>{let{dataSource:n}=o()||{};return(0,k.jsx)(G,{schema:e,dataSource:n,...t})};i.register(`object-calendar`,q,{namespace:`plugin-calendar`,label:`Object Calendar`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]}),i.register(`calendar`,q,{namespace:`view`,label:`Calendar View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`calendar`,type:`object`,label:`Calendar Config`,description:`startDateField, endDateField, titleField, colorField`}]});export{K as t};
@@ -1,4 +1,4 @@
1
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,m as r,t as i}from"./vendor-react-B1k2FF9f.js";import{H as a,R as o,j as s,k as c}from"./framework-CoXA0nY6.js";import{f as l}from"./infrastructure-Djv3I7gr.js";import{IA as u,Ut as d}from"./ui-components-B7mlp0en.js";import{C as f,S as p,_ as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,i as S,l as C,m as w,n as T,o as ee,p as E,r as D,s as O,t as k,u as A,v as j,x as M,y as N}from"./vendor-charts-D0g2ZI3F.js";var P=t(n(),1),F=i(),I=(...e)=>e.filter(Boolean).join(` `),te={light:``,dark:`.dark`},L=P.createContext(null);function R(){let e=P.useContext(L);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function z({id:e,className:t,children:n,config:r,...i}){let a=P.useId(),o=`chart-${e||a.replace(/:/g,``)}`;return(0,F.jsx)(L.Provider,{value:{config:r},children:(0,F.jsxs)(`div`,{"data-slot":`chart`,"data-chart":o,className:I(`flex w-full h-[350px] justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground`,t),...i,children:[(0,F.jsx)(B,{id:o,config:r}),(0,F.jsx)(f,{width:`100%`,height:`100%`,children:n})]})})}var B=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme||e.color);return n.length?(0,F.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(te).map(([t,r])=>`
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,m as r,t as i}from"./vendor-react-B1k2FF9f.js";import{H as a,R as o,j as s,k as c}from"./framework-CoXA0nY6.js";import{f as l}from"./infrastructure-Djv3I7gr.js";import{FA as u,Ht as d}from"./ui-components-DSSaN2w_.js";import{C as f,S as p,_ as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,i as S,l as C,m as w,n as T,o as ee,p as E,r as D,s as O,t as k,u as A,v as j,x as M,y as N}from"./vendor-charts-D0g2ZI3F.js";var P=t(n(),1),F=i(),I=(...e)=>e.filter(Boolean).join(` `),te={light:``,dark:`.dark`},L=P.createContext(null);function R(){let e=P.useContext(L);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function z({id:e,className:t,children:n,config:r,...i}){let a=P.useId(),o=`chart-${e||a.replace(/:/g,``)}`;return(0,F.jsx)(L.Provider,{value:{config:r},children:(0,F.jsxs)(`div`,{"data-slot":`chart`,"data-chart":o,className:I(`flex w-full h-[350px] justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground`,t),...i,children:[(0,F.jsx)(B,{id:o,config:r}),(0,F.jsx)(f,{width:`100%`,height:`100%`,children:n})]})})}var B=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme||e.color);return n.length?(0,F.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(te).map(([t,r])=>`
2
2
  ${r} [data-chart=${e}] {
3
3
  ${n.map(([e,n])=>{let r=n.theme?.[t]||n.color;return r?` --color-${e}: ${r};`:null}).join(`
4
4
  `)}