@objectstack/console 14.5.0 → 14.6.0

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 (52) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-VM9K3D39.js → AdapterProvider-cnK1q1oP.js} +1 -1
  3. package/dist/assets/{ApiConsolePage-CW5efCG0.js → ApiConsolePage-fUV9bmEg.js} +1 -1
  4. package/dist/assets/{AppDocsIndex-xfVoWnj-.js → AppDocsIndex-Bzh_4ehZ.js} +1 -1
  5. package/dist/assets/{AppManagementPage-DjerO44R.js → AppManagementPage-BRmzB5eR.js} +1 -1
  6. package/dist/assets/{ApprovalsInboxPage-CaCSwwcc.js → ApprovalsInboxPage-DKgnvZ-2.js} +1 -1
  7. package/dist/assets/ConsoleFloatingChatbot-BW-g5YTu.js +1 -0
  8. package/dist/assets/{CreateViewDialog-FNntBig_.js → CreateViewDialog-BhCe1ZPc.js} +1 -1
  9. package/dist/assets/{DashboardView-Bi3eGvU3.js → DashboardView-CUXRWKPH.js} +1 -1
  10. package/dist/assets/{FlowRunsPage-DUZnmBwd.js → FlowRunsPage-C4Setjuz.js} +1 -1
  11. package/dist/assets/{InterfaceListPage-2m_Tj1YU.js → InterfaceListPage-BFlwb0U7.js} +1 -1
  12. package/dist/assets/{MarketplaceInstalledPage-DVOm5x-8.js → MarketplaceInstalledPage-4MFyBXDW.js} +1 -1
  13. package/dist/assets/{MarketplacePackagePage-CjH5GQ5Z.js → MarketplacePackagePage-BDeaeKiT.js} +1 -1
  14. package/dist/assets/{MarketplacePage-gPtkwtQv.js → MarketplacePage-DXMWpCHb.js} +1 -1
  15. package/dist/assets/MetadataProvider-C8ABa_gQ.js +1 -0
  16. package/dist/assets/{ObjectDataPage-Dj2xHQH3.js → ObjectDataPage-BSvqdmym.js} +1 -1
  17. package/dist/assets/{PageView-l4f-5mgO.js → PageView-Dlpz3HgH.js} +1 -1
  18. package/dist/assets/{ProfilePage-CQlOfGDf.js → ProfilePage-2H6e2j4o.js} +1 -1
  19. package/dist/assets/{PublicFormsPage-Mu0E7e5y.js → PublicFormsPage-DXYBK10A.js} +1 -1
  20. package/dist/assets/RecordDetailView-CEdkDgV8.js +9 -0
  21. package/dist/assets/{RecordFormPage-BtK8VUj9.js → RecordFormPage-Bj3lDGqC.js} +1 -1
  22. package/dist/assets/{ReportDefaultInspector-Borp5kRd.js → ReportDefaultInspector-BNtsE5kW.js} +1 -1
  23. package/dist/assets/{ReportView-BrjYjp74.js → ReportView-COxfnluU.js} +1 -1
  24. package/dist/assets/{SearchResultsPage-CfxZkWx7.js → SearchResultsPage-B3ShD29d.js} +1 -1
  25. package/dist/assets/{SystemHubPage-_NMRZfpb.js → SystemHubPage-A9Z1FplZ.js} +1 -1
  26. package/dist/assets/data-adapter-CAqKExcJ.js +7 -0
  27. package/dist/assets/index-BhMd7RVY.js +2 -0
  28. package/dist/assets/infrastructure-DexdbqHf.js +3 -0
  29. package/dist/assets/{marketplaceApi-BN-VhaRz.js → marketplaceApi-1mMRJWDq.js} +1 -1
  30. package/dist/assets/{metadata-admin-BcCYhjRC.js → metadata-admin-R79BWSDJ.js} +2 -2
  31. package/dist/assets/{plugin-calendar-CSE3oYMl.js → plugin-calendar-GOvhSPjZ.js} +1 -1
  32. package/dist/assets/{plugin-form-mON2217z.js → plugin-form-QFhBvb96.js} +1 -1
  33. package/dist/assets/plugin-gantt-2HGBxhYq.js +93 -0
  34. package/dist/assets/{plugin-kanban-CAw-uo9I.js → plugin-kanban-D8kWLfql.js} +1 -1
  35. package/dist/assets/{plugin-view-BYrkl7Kl.js → plugin-view-CTBpbehM.js} +1 -1
  36. package/dist/assets/{plugins-views-Bf2gkCfN.js → plugins-views-BxKprmRN.js} +3 -3
  37. package/dist/assets/src-TG89vY9R.js +18 -0
  38. package/dist/assets/surfaceAgent-qmokOosD.js +1 -0
  39. package/dist/assets/useMetadata-DemWIEqg.js +1 -0
  40. package/dist/assets/{useRecordApprovals-CL4YRGv_.js → useRecordApprovals-R3Q7Bt7f.js} +1 -1
  41. package/dist/index.html +1 -1
  42. package/package.json +1 -1
  43. package/dist/assets/ConsoleFloatingChatbot-DtJ5G3pF.js +0 -1
  44. package/dist/assets/MetadataProvider-ByLpS5Ra.js +0 -1
  45. package/dist/assets/RecordDetailView-B_B-3fuJ.js +0 -9
  46. package/dist/assets/conversationLanguage-C4kzQvae.js +0 -1
  47. package/dist/assets/data-adapter-Cz11MUug.js +0 -7
  48. package/dist/assets/index-052ojABv.js +0 -2
  49. package/dist/assets/infrastructure-B9dLsgB4.js +0 -3
  50. package/dist/assets/plugin-gantt-BrBwlK5S.js +0 -93
  51. package/dist/assets/src-WC2Ki4jb.js +0 -18
  52. package/dist/assets/useMetadata-DdvHABxD.js +0 -1
@@ -1,3 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";var r=e(n(),1),i=new Set,a={emit(e){for(let t of Array.from(i))try{t(e)}catch{}},subscribe(e){return i.add(e),()=>{i.delete(e)}}};function o(e,t){if(e!==403||!t||typeof t!=`object`)return null;let n=t.error;if(!n||typeof n!=`object`)return null;let r=n.code;if(r===`MFA_REQUIRED`||r===`PASSWORD_EXPIRED`){let e=n.message;return{code:r,message:typeof e==`string`?e:``}}return null}var s=(0,r.createContext)(null);s.displayName=`AuthContext`;var c=`1.6.23`,l=Symbol.for(`better-auth:broadcast-channel`),u=()=>Math.floor(Date.now()/1e3),d=class{listeners=new Set;name;constructor(e=`better-auth.message`){this.name=e}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}post(e){if(!(typeof window>`u`))try{localStorage.setItem(this.name,JSON.stringify({...e,timestamp:u()}))}catch{}}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=e=>{if(e.key!==this.name)return;let t=JSON.parse(e.newValue??`{}`);t?.event!==`session`||!t?.data||this.listeners.forEach(e=>e(t))};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}}};function f(e=`better-auth.message`){return globalThis[l]||(globalThis[l]=new d(e)),globalThis[l]}var p=[],m=0,h=null,g=4,_=globalThis.nanostoresGlobal||={epoch:0},v=()=>{for(m=0;m<p.length;m+=g)p[m](p[m+1].value,p[m+2],p[m+3]);p.length=0},y=e=>{let t=[],n={get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(e){return n.lc=t.push(e),()=>{for(let t=m+g;t<p.length;)p[t]===e?p.splice(t,g):t+=g;let r=t.indexOf(e);~r&&(t.splice(r,1),--n.lc||n.off())}},notify(e,r){_.epoch++;let i=!p.length&&!0;for(let i of t)h?.has(i)||(h?.add(i),p.push(i,n,e,r));i&&v()},off(){},set(e){let t=n.value;t!==e&&(n.value=e,n.notify(t))},subscribe(e){let t=n.listen(e);return e(n.value),t},value:e};return n},b=2,x=5,S=6,C=10,w=(e,t,n,r)=>(e.events=e.events||{},e.events[n+C]||(e.events[n+C]=r(t=>{e.events[n].reduceRight((e,t)=>(t(e),e),{shared:{},...t})})),e.events[n]=e.events[n]||[],e.events[n].push(t),()=>{let r=e.events[n],i=r.indexOf(t);r.splice(i,1),r.length||(delete e.events[n],e.events[n+C](),delete e.events[n+C])}),T=(e,t)=>w(e,t,b,t=>{let n=e.set,r=e.setKey;return e.setKey&&=(n,i)=>{let a;if(t({abort:()=>{a=!0},changed:n,newValue:{...e.value,[n]:i}}),!a)return r(n,i)},e.set=e=>{let r;if(t({abort:()=>{r=!0},newValue:e}),!r)return n(e)},()=>{e.set=n,e.setKey=r}}),E=1e3,D=(e,t)=>w(e,n=>{let r=t(n);r&&e.events[S].push(r)},x,t=>{let n=e.listen;e.listen=(...r)=>(!e.lc&&!e.active&&(e.active=!0,t()),n(...r));let r=e.off;return e.events[S]=[],e.off=()=>{r(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let t of e.events[S])t();e.events[S]=[]}},E)},()=>{e.listen=n,e.off=r}});function O(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function k(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!k(e[n],t[n]))return!1;return!0}if(O(e)&&O(t)){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!(r in t)||!k(e[r],t[r]))return!1;return!0}return!1}function ee(e,t){return T(e,({newValue:n,abort:r})=>{t(e.value,n)&&r()})}var A=Symbol.for(`better-auth:focus-manager`),j=class{listeners=new Set;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setFocused(e){this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||typeof document>`u`||window.addEventListener===void 0)return()=>{};let e=()=>{document.visibilityState===`visible`&&this.setFocused(!0)};return document.addEventListener(`visibilitychange`,e,!1),()=>{document.removeEventListener(`visibilitychange`,e,!1)}}};function te(){return globalThis[A]||(globalThis[A]=new j),globalThis[A]}var M=Symbol.for(`better-auth:online-manager`),N=class{listeners=new Set;isOnline=typeof navigator<`u`?navigator.onLine:!0;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setOnline(e){this.isOnline=e,this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=()=>this.setOnline(!0),t=()=>this.setOnline(!1);return window.addEventListener(`online`,e,!1),window.addEventListener(`offline`,t,!1),()=>{window.removeEventListener(`online`,e,!1),window.removeEventListener(`offline`,t,!1)}}};function P(){return globalThis[M]||(globalThis[M]=new N),globalThis[M]}var ne={proto:/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,constructor:/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},re=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,F={true:!0,false:!1,null:null,undefined:void 0,nan:NaN,infinity:1/0,"-infinity":-1/0},ie=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function I(e){return e instanceof Date&&!isNaN(e.getTime())}function ae(e){let t=ie.exec(e);if(!t)return null;let[,n,r,i,a,o,s,c,l,u,d]=t,f=new Date(Date.UTC(parseInt(n,10),parseInt(r,10)-1,parseInt(i,10),parseInt(a,10),parseInt(o,10),parseInt(s,10),c?parseInt(c.padEnd(3,`0`),10):0));if(l){let e=(parseInt(u,10)*60+parseInt(d,10))*(l===`+`?-1:1);f.setUTCMinutes(f.getUTCMinutes()+e)}return I(f)?f:null}function L(e,t={}){let{strict:n=!1,warnings:r=!1,reviver:i,parseDates:a=!0}=t;if(typeof e!=`string`)return e;let o=e.trim(),s=o.toLowerCase();if(s.length<=9&&s in F)return F[s];if(!re.test(o)){if(n)throw SyntaxError(`[better-json] Invalid JSON`);return e}if(Object.entries(ne).some(([e,t])=>{let n=t.test(o);return n&&r&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${e} pattern`),n})&&n)throw Error(`[better-json] Potential prototype pollution attempt detected`);try{return JSON.parse(o,(e,t)=>{if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){r&&console.warn(`[better-json] Dropping "${e}" key to prevent prototype pollution`);return}if(a&&typeof t==`string`){let e=ae(t);if(e)return e}return i?i(e,t):t})}catch(t){if(n)throw t;return e}}function oe(e,t={strict:!0}){return L(e,t)}var se=()=>typeof window>`u`;function R(e,t){return k(e.data,t.data)&&e.error===t.error&&e.isPending===t.isPending&&e.isRefetching===t.isRefetching&&e.refetch===t.refetch}var z=(e,t,n,r)=>{let i=y({data:null,error:null,isPending:!0,isRefetching:!1,refetch:e=>a(e)});ee(i,R);let a=async e=>new Promise(a=>{let o=typeof r==`function`?r({data:i.get().data,error:i.get().error,isPending:i.get().isPending}):r;n(t,{...o,query:{...o?.query,...e?.query},async onSuccess(e){let t=i.get(),n=t.data!=null&&e.data!=null&&k(t.data,e.data)?t.data:e.data;i.set({data:n,error:null,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onSuccess?.(e)},async onError(e){let{request:t}=e,n=typeof t.retry==`number`?t.retry:t.retry?.attempts,r=t.retryAttempt||0;if(n&&r<n)return;let a=e.error.status===401;i.set({error:e.error,data:a?null:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch}),await o?.onError?.(e)},async onRequest(e){let t=i.get();i.set({isPending:t.data===null,data:t.data,error:null,isRefetching:!0,refetch:i.value.refetch}),await o?.onRequest?.(e)}}).catch(e=>{i.set({error:e,data:i.get().data,isPending:!1,isRefetching:!1,refetch:i.value.refetch})}).finally(()=>{a(void 0)})});e=Array.isArray(e)?e:[e];let o=!1,s=[];for(let t of e){let e=t.subscribe(async()=>{se()||(o?await a():D(i,()=>{let e=setTimeout(async()=>{o||(o=!0,await a())},0);return()=>{for(let e of s)e();clearTimeout(e)}}))});s.push(e)}return i},B=()=>Math.floor(Date.now()/1e3),ce=5;function le(e){let{fetchSession:t,shouldPollSession:n=()=>!0,sessionSignal:r,options:i={}}=e,a=i.sessionOptions?.refetchInterval??0,o=i.sessionOptions?.refetchOnWindowFocus??!0,s=i.sessionOptions?.refetchWhenOffline??!1,c={isInitialized:!1,lastSessionRequest:0},l=()=>s||P().isOnline,u=e=>{if(l()){if(e?.event===`storage`){t();return}if(e?.event===`poll`){c.lastSessionRequest=B(),t();return}if(e?.event===`visibilitychange`){if(B()-c.lastSessionRequest<ce)return;c.lastSessionRequest=B(),t();return}t()}},d=e=>{f().post({event:`session`,data:{trigger:e},clientId:Math.random().toString(36).substring(7)})},p=()=>{a&&a>0&&(c.pollInterval=setInterval(()=>{n()&&u({event:`poll`})},a*1e3))},m=()=>{c.unsubscribeBroadcast=f().subscribe(()=>{u({event:`storage`})})},h=()=>{o&&(c.unsubscribeFocus=te().subscribe(()=>{u({event:`visibilitychange`})}))},g=()=>{c.unsubscribeOnline=P().subscribe(e=>{e&&u({event:`visibilitychange`})})},_=()=>{c.unsubscribeSignal=r.listen(()=>{t()})};return{init:()=>{c.isInitialized||(c.isInitialized=!0,p(),m(),h(),g(),_(),c.cleanupBroadcastSetup=f().setup(),c.cleanupFocusSetup=te().setup(),c.cleanupOnlineSetup=P().setup())},cleanup:()=>{c.isInitialized&&(c.pollInterval&&=(clearInterval(c.pollInterval),void 0),c.unsubscribeBroadcast&&=(c.unsubscribeBroadcast(),void 0),c.unsubscribeFocus&&=(c.unsubscribeFocus(),void 0),c.unsubscribeOnline&&=(c.unsubscribeOnline(),void 0),c.unsubscribeSignal&&=(c.unsubscribeSignal(),void 0),c.cleanupBroadcastSetup&&=(c.cleanupBroadcastSetup(),void 0),c.cleanupFocusSetup&&=(c.cleanupFocusSetup(),void 0),c.cleanupOnlineSetup&&=(c.cleanupOnlineSetup(),void 0),c.isInitialized=!1,c.lastSessionRequest=0)},triggerRefetch:u,broadcastSessionUpdate:d}}var ue=Object.create(null),V=e=>({}),H=new Proxy(ue,{get(e,t){return V()[t]??ue[t]},has(e,t){return t in V()||t in ue},set(e,t,n){let r=V(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=V(!0);return delete n[t],!0},ownKeys(){let e=V(!0);return Object.keys(e)}});H.NODE_ENV;function U(e,t){return typeof process<`u`?{}[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}Object.freeze({get BETTER_AUTH_SECRET(){return U(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return U(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return U(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return U(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return U(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return U(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return U(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}});function de(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{code:e,message:t,toString:()=>e}]))}function fe(){let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.prototype.hasOwnProperty.call(e,`writable`)?e.writable:e.set!==void 0}function pe(e){let t=e.split(`
2
- at `);return t.length<=1?e:(t.splice(1,1),t.join(`
3
- at `))}function me(e,t){class n extends e{#e;constructor(...e){if(fe()){let t=Error.stackTraceLimit;Error.stackTraceLimit=0,super(...e),Error.stackTraceLimit=t}else super(...e);let t=Error().stack;t&&(this.#e=pe(t.replace(/^Error/,this.name)))}get errorStack(){return this.#e}}return Object.defineProperty(n.prototype,"constructor",{get(){return t},enumerable:!1,configurable:!0}),n}var he={OK:200,CREATED:201,ACCEPTED:202,NO_CONTENT:204,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,TEMPORARY_REDIRECT:307,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,"I'M_A_TEAPOT":418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511};me(class extends Error{constructor(e=`INTERNAL_SERVER_ERROR`,t=void 0,n={},r=typeof e==`number`?e:he[e]){super(t?.message,t?.cause?{cause:t.cause}:void 0),this.status=e,this.body=t,this.headers=n,this.statusCode=r,this.name=`APIError`,this.status=e,this.headers=n,this.statusCode=r,this.body=t}},Error);var W=class extends Error{constructor(e,t){super(e,t),this.name=`BetterAuthError`,this.message=e,this.stack=``}},ge=47;function _e(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===ge;)t--;return t===e.length?e:e.slice(0,t)}function ve(e){try{return(_e(new URL(e).pathname)||`/`)!==`/`}catch{throw new W(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function ye(e){try{let t=new URL(e);if(t.protocol!==`http:`&&t.protocol!==`https:`)throw new W(`Invalid base URL: ${e}. URL must include 'http://' or 'https://'`)}catch(t){throw t instanceof W?t:new W(`Invalid base URL: ${e}. Please provide a valid base URL.`,{cause:t})}}function G(e,t=`/api/auth`){if(ye(e),ve(e))return e;let n=_e(e);return!t||t===`/`?n:(t=t.startsWith(`/`)?t:`/${t}`,`${n}${t}`)}function be(e,t){return!e||e.trim()===``?!1:t===`proto`?e===`http`||e===`https`:t===`host`?[/\.\./,/\0/,/[\s]/,/^[.]/,/[<>'"]/,/javascript:/i,/file:/i,/data:/i].some(t=>t.test(e))?!1:/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(e)||/^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(e)||/^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(e)||/^localhost(:[0-9]{1,5})?$/i.test(e):!1}function xe(e,t,n,r,i){if(e)return G(e,t);if(r!==!1){let e=H.BETTER_AUTH_URL||H.NEXT_PUBLIC_BETTER_AUTH_URL||H.PUBLIC_BETTER_AUTH_URL||H.NUXT_PUBLIC_BETTER_AUTH_URL||H.NUXT_PUBLIC_AUTH_URL||(H.BASE_URL===`/`?void 0:H.BASE_URL);if(e)return G(e,t)}let a=n?.headers.get(`x-forwarded-host`),o=n?.headers.get(`x-forwarded-proto`);if(a&&o&&i&&be(o,`proto`)&&be(a,`host`))try{return G(`${o}://${a}`,t)}catch{}if(n){let e=Se(n.url);if(!e)throw new W(`Could not get origin from request. Please provide a valid base URL.`);return G(e,t)}if(typeof window<`u`&&window.location)return G(window.location.origin,t)}function Se(e){try{let t=new URL(e);return t.origin===`null`?null:t.origin}catch{return null}}var Ce=[`javascript:`,`data:`,`vbscript:`];function we(e){let t;try{t=new URL(e)}catch{return!0}return!Ce.includes(t.protocol)}var Te={id:`redirect`,name:`Redirect`,hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&we(e.data.url)&&typeof window<`u`&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}},Ee=()=>typeof window>`u`;function De(e){return typeof e==`object`&&e&&`data`in e&&`error`in e?e:{data:e,error:null}}function Oe(e){return!e||e.session===null&&e.user===null?null:e}function ke(e,t){return k(e.data,t.data)&&e.error===t.error&&e.isPending===t.isPending&&e.isRefetching===t.isRefetching&&e.refetch===t.refetch}function Ae(e,t){let n=y(!1),r,i=e=>s(e),a=y({data:null,error:null,isPending:!0,isRefetching:!1,refetch:i});ee(a,ke);let o=e=>{if(r!==e)return;let t=a.get();r=void 0,!(!t.isPending&&!t.isRefetching)&&a.set({...t,isPending:!1,isRefetching:!1,refetch:i})},s=async t=>{r?.abort();let n=new AbortController;r=n;let s=a.get();a.set({...s,isPending:s.data===null,isRefetching:!0,error:null,refetch:i});try{let r=await e(`/get-session`,{method:`GET`,query:t?.query,signal:n.signal});if(n.signal.aborted){o(n);return}let{data:s,error:c}=De(r);if(s?.needsRefresh)try{let t=await e(`/get-session`,{method:`POST`,signal:n.signal});if(n.signal.aborted){o(n);return}({data:s,error:c}=De(t))}catch{if(n.signal.aborted){o(n);return}}if(c){let e=a.get(),t=c?.status===401;a.set({data:t?null:e.data,error:c,isPending:!1,isRefetching:!1,refetch:i});return}let l=Oe(s),u=a.get(),d=u.data!=null&&l!=null&&k(u.data,l)?u.data:l;a.set({data:d,error:null,isPending:!1,isRefetching:!1,refetch:i})}catch(e){if(n.signal.aborted){o(n);return}let t=a.get();a.set({data:t.data,error:e,isPending:!1,isRefetching:!1,refetch:i})}},c=()=>{};return D(a,()=>{let e;Ee()||(e=setTimeout(()=>{s()},0));let i=le({fetchSession:s,shouldPollSession:()=>a.get().data!=null,sessionSignal:n,options:t});return i.init(),c=i.broadcastSessionUpdate,()=>{e&&clearTimeout(e);let t=r;t?.abort(),t&&o(t),i.cleanup()}}),{session:a,$sessionSignal:n,broadcastSessionUpdate:e=>c(e)}}function je(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function Me(e,t,n=`.`,r){if(!je(t))return Me(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(Array.isArray(a)&&Array.isArray(i[t])?i[t]=[...a,...i[t]]:je(a)&&je(i[t])?i[t]=Me(a,i[t],(n?`${n}.`:``)+t.toString(),r):i[t]=a))}return i}function Ne(e){return(...t)=>t.reduce((t,n)=>Me(t,n,``,e),{})}var Pe=Ne(),Fe=Object.defineProperty,Ie=Object.defineProperties,Le=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,ze=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,K=(e,t)=>{for(var n in t||={})ze.call(t,n)&&Ve(e,n,t[n]);if(Re)for(var n of Re(t))Be.call(t,n)&&Ve(e,n,t[n]);return e},q=(e,t)=>Ie(e,Le(t)),He=class extends Error{constructor(e,t,n){super(t||e.toString(),{cause:n}),this.status=e,this.statusText=t,this.error=n,Error.captureStackTrace(this,this.constructor)}},Ue=async(e,t)=>{let n=t||{},r={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:n,hooks:r};for(let i of t?.plugins||[]){if(i.init){let r=await i.init?.call(i,e.toString(),t);n=r.options||n,e=r.url}r.onRequest.push(i.hooks?.onRequest),r.onResponse.push(i.hooks?.onResponse),r.onSuccess.push(i.hooks?.onSuccess),r.onError.push(i.hooks?.onError),r.onRetry.push(i.hooks?.onRetry)}return{url:e,options:n,hooks:r}},We=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},Ge=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function Ke(e){if(typeof e==`number`)return new We({type:`linear`,attempts:e,delay:1e3});switch(e.type){case`linear`:return new We(e);case`exponential`:return new Ge(e);default:throw Error(`Invalid retry strategy`)}}var qe=async e=>{let t={},n=async e=>typeof e==`function`?await e():e;if(e?.auth){if(e.auth.type===`Bearer`){let r=await n(e.auth.token);if(!r)return t;t.authorization=`Bearer ${r}`}else if(e.auth.type===`Basic`){let[r,i]=await Promise.all([n(e.auth.username),n(e.auth.password)]);if(!r||!i)return t;t.authorization=`Basic ${btoa(`${r}:${i}`)}`}else if(e.auth.type===`Custom`){let[r,i]=await Promise.all([n(e.auth.prefix),n(e.auth.value)]);if(!i)return t;t.authorization=`${r??``} ${i}`}}return t},Je=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Ye(e){let t=e.headers.get(`content-type`),n=new Set([`image/svg`,`application/xml`,`application/xhtml`,`application/html`]);if(!t)return`json`;let r=t.split(`;`).shift()||``;return Je.test(r)?`json`:n.has(r)||r.startsWith(`text/`)?`text`:`blob`}function Xe(e){try{return JSON.parse(e),!0}catch{return!1}}function Ze(e){if(e===void 0)return!1;let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===null?!0:t===`object`?Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name===`Object`||typeof e.toJSON==`function`:!1}function Qe(e){try{return JSON.parse(e)}catch{return e}}function $e(e){return typeof e==`function`}function et(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<`u`&&$e(globalThis.fetch))return globalThis.fetch;if(typeof window<`u`&&$e(window.fetch))return window.fetch;throw Error(`No fetch implementation found`)}function tt(...e){let t={};for(let n of e)if(n)if(n instanceof Headers)n.forEach((e,n)=>{t[n]=e});else{let e=Array.isArray(n)?n:Object.entries(n);for(let[n,r]of e)r!=null&&(t[n]=r)}return t}async function nt(e){let t=new Headers(tt(e?.headers,await qe(e)));if(!t.has(`content-type`)){let n=rt(e?.body);n&&t.set(`content-type`,n)}return t}function rt(e){return Ze(e)?`application/json`:null}function it(e){let t=e.get(`content-type`);return t?t.split(`;`)[0].trim().toLowerCase():null}function at(e,t){let{body:n}=e;return n?!Ze(n)||typeof n==`string`?n:it(t)===`application/x-www-form-urlencoded`?new URLSearchParams(n).toString():JSON.stringify(n):null}function ot(e,t){if(t?.method)return t.method.toUpperCase();if(e.startsWith(`@`)){let n=e.split(`@`)[1]?.split(`/`)[0];return ut.includes(n)?n.toUpperCase():t?.body?`POST`:`GET`}return t?.body?`POST`:`GET`}function st(e,t){let n;return!e?.signal&&e?.timeout&&(n=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:n,clearTimeout:()=>{n&&clearTimeout(n)}}}var ct=class e extends Error{constructor(t,n){super(n||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,e.prototype)}};async function lt(e,t){let n=await e[`~standard`].validate(t);if(n.issues)throw new ct(n.issues);return n.value}var ut=[`get`,`post`,`put`,`patch`,`delete`],dt=e=>({id:`apply-schema`,name:`Apply Schema`,version:`1.0.0`,async init(t,n){let r=e.plugins?.find(e=>e.schema?.config?t.startsWith(e.schema.config.baseURL||``)||t.startsWith(e.schema.config.prefix||``):!1)?.schema||e.schema;if(r){let e=t;r.config?.prefix&&e.startsWith(r.config.prefix)&&(e=e.replace(r.config.prefix,``),r.config.baseURL&&(t=t.replace(r.config.prefix,r.config.baseURL))),r.config?.baseURL&&e.startsWith(r.config.baseURL)&&(e=e.replace(r.config.baseURL,``)),e.startsWith(`/`)&&e.charAt(1)===`@`&&(e=e.substring(1));let i=r.schema[e];if(i){let e=n?.headers;if(i.headers&&!n?.disableValidation){let t={};if(n?.headers){if(n.headers instanceof Headers)n.headers.forEach((e,n)=>{t[n.toLowerCase()]=e});else if(typeof n.headers==`object`)for(let[e,r]of Object.entries(n.headers))r!=null&&(t[e.toLowerCase()]=r)}let r=await lt(i.headers,t),a={};for(let[e,t]of Object.entries(r))a[e.toLowerCase()]=t;e=a}let r=q(K({},n),{method:i.method,output:i.output,headers:e});return n?.disableValidation||(r=q(K({},r),{body:i.input?await lt(i.input,n?.body):n?.body,params:i.params?await lt(i.params,n?.params):n?.params,query:i.query?await lt(i.query,n?.query):n?.query})),{url:t,options:r}}}return{url:t,options:n}}}),ft=e=>{async function t(t,n){let r=q(K(K({},e),n),{headers:tt(e?.headers,n?.headers),plugins:[...e?.plugins||[],dt(e||{}),...n?.plugins||[]]});if(e?.catchAllError)try{return await gt(t,r)}catch(e){return{data:null,error:{status:500,statusText:`Fetch Error`,message:`Fetch related error. Captured by catchAllError option. See error property for more details.`,error:e}}}return await gt(t,r)}return t},pt=e=>e===`.`||e===`..`;function mt(e,t){let n=e;for(let[e,r]of t)n=n.replace(e,r);if(pt(n))throw TypeError(`Path parameters cannot be reserved path segments`);return encodeURIComponent(n)}function ht(e,t){let{baseURL:n,params:r,query:i}=t||{query:{},params:{},baseURL:``},a=e.startsWith(`http`)?e.split(`/`).slice(0,3).join(`/`):n||``;if(e.startsWith(`@`)){let t=e.toString().split(`@`)[1].split(`/`)[0];ut.includes(t)&&(e=e.replace(`@${t}/`,`/`))}a.endsWith(`/`)||(a+=`/`);let[o,s]=e.replace(a,``).split(`?`),c=new URLSearchParams(s);for(let[e,t]of Object.entries(i||{})){if(t==null)continue;let n;if(typeof t==`string`)n=t;else if(Array.isArray(t)){for(let n of t)c.append(e,n);continue}else n=JSON.stringify(t);c.set(e,n)}let l=new Map;if(r)if(Array.isArray(r)){let e=o.split(`/`).filter(e=>e.startsWith(`:`));for(let[t,n]of e.entries()){let e=r[t];l.set(n,String(e))}}else for(let[e,t]of Object.entries(r))l.set(`:${e}`,String(t));o=o.split(`/`).map(e=>mt(e,l)).join(`/`),o=o.replace(/^\/+/,``);let u=c.toString();return u=u.length>0?`?${u}`.replace(/\+/g,`%20`):``,a.startsWith(`http`)?new URL(`${o}${u}`,a):`${a}${o}${u}`}var gt=async(e,t)=>{let{hooks:n,url:r,options:i}=await Ue(e,t),a=et(i),o=new AbortController,s=i.signal??o.signal,c=ht(r,i),l=await nt(i),u=at(i,l),d=ot(r,i),f=q(K({},i),{url:c,headers:l,body:u,method:d,signal:s});for(let e of n.onRequest)if(e){let t=await e(f);typeof t==`object`&&t&&Object.assign(f,t)}(`pipeTo`in f&&typeof f.pipeTo==`function`||typeof t?.body?.pipe==`function`)&&(`duplex`in f||(f.duplex=`half`));let{clearTimeout:p}=st(i,o),m=await a(f.url,f);p();let h={response:m,request:f};for(let e of n.onResponse)if(e){let n=await e(q(K({},h),{response:t?.hookOptions?.cloneResponse?m.clone():m}));n instanceof Response?m=n:typeof n==`object`&&n&&(m=n.response)}if(m.ok){if(f.method===`HEAD`)return{data:``,error:null};let e=Ye(m),r={data:null,response:m,request:f};if(e===`json`||e===`text`){let e=await m.text();r.data=await(f.jsonParser??Qe)(e)}else r.data=await m[e]();f?.output&&f.output&&!f.disableValidation&&(r.data=await lt(f.output,r.data));for(let e of n.onSuccess)e&&await e(q(K({},r),{response:t?.hookOptions?.cloneResponse?m.clone():m}));return t?.throw?r.data:{data:r.data,error:null}}let g=t?.jsonParser??Qe,_=await m.text(),v=Xe(_),y=v?await g(_):null,b={response:m,responseText:_,request:f,error:q(K({},y),{status:m.status,statusText:m.statusText})};for(let e of n.onError)e&&await e(q(K({},b),{response:t?.hookOptions?.cloneResponse?m.clone():m}));if(t?.retry){let r=Ke(t.retry),i=t.retryAttempt??0;if(await r.shouldAttemptRetry(i,m)){for(let e of n.onRetry)e&&await e(h);let a=r.getDelay(i);return await new Promise(e=>setTimeout(e,a)),await gt(e,q(K({},t),{retryAttempt:i+1}))}}if(t?.throw)throw new He(m.status,m.statusText,v?y:_);return{data:null,error:q(K({},y),{status:m.status,statusText:m.statusText})}},_t=e=>{if(typeof process>`u`)return;let t=e??`/api/auth`;if({}.NEXT_PUBLIC_AUTH_URL)return{}.NEXT_PUBLIC_AUTH_URL;if(typeof window>`u`){if({}.NEXTAUTH_URL)try{return{}.NEXTAUTH_URL}catch{}if({}.VERCEL_URL)try{let e={}.VERCEL_URL.startsWith(`http`)?``:`https://`;return`${new URL(`${e}${{}.VERCEL_URL}`).origin}${t}`}catch{}}},vt=(e,t)=>{let n=`credentials`in Request.prototype,r=xe(e?.baseURL,e?.basePath,void 0,t)??_t(e?.basePath)??`/api/auth`,i=e?.plugins?.flatMap(e=>e.fetchPlugins).filter(e=>e!==void 0)||[],a={id:`lifecycle-hooks`,name:`lifecycle-hooks`,hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:s,onRequest:c,onResponse:l,...u}=e?.fetchOptions||{},d=ft({baseURL:r,...n?{credentials:`include`}:{},method:`GET`,jsonParser(e){return e?oe(e,{strict:!1}):null},customFetchImpl:fetch,...u,plugins:[a,...u.plugins||[],...e?.disableDefaultFetchPlugins?[]:[Te],...i]}),{$sessionSignal:f,session:p,broadcastSessionUpdate:m}=Ae(d,e),h=e?.plugins||[],g={},_={$sessionSignal:f,session:p},v={"/sign-out":`POST`,"/revoke-sessions":`POST`,"/revoke-other-sessions":`POST`,"/delete-user":`POST`},y=[{signal:`$sessionSignal`,matcher(e){return e===`/sign-out`||e===`/update-user`||e===`/update-session`||e===`/sign-up/email`||e===`/sign-in/email`||e===`/delete-user`||e===`/verify-email`||e===`/revoke-sessions`||e===`/revoke-session`||e===`/revoke-other-sessions`||e===`/change-email`||e===`/change-password`},callback(e){e===`/sign-out`?m(`signout`):(e===`/update-user`||e===`/update-session`)&&m(`updateUser`)}}];for(let e of h)e.getAtoms&&Object.assign(_,e.getAtoms?.(d)),e.pathMethods&&Object.assign(v,e.pathMethods),e.atomListeners&&y.push(...e.atomListeners);let b={notify:e=>{_[e].set(!_[e].get())},listen:(e,t)=>{_[e].subscribe(t)},atoms:_};for(let t of h)t.getActions&&(g=Pe(t.getActions?.(d,b,e)??{},g));return{get baseURL(){return r},pluginsActions:g,pluginsAtoms:_,pluginPathMethods:v,atomListeners:y,$fetch:d,$store:b}};function yt(e){return typeof e==`object`&&!!e&&`get`in e&&typeof e.get==`function`&&`lc`in e&&typeof e.lc==`number`}function bt(e){return e.charAt(0).toUpperCase()+e.slice(1)}var xt=/[\p{Ll}\d]+|\p{Lu}+(?!\p{Ll})|\p{Lu}[\p{Ll}\d]+|\p{Lo}+/gu,St=/['\u2019]/g;function Ct(e){return e.replace(St,``).match(xt)??[]}function wt(e){return Ct(e).map(e=>e.toLowerCase()).join(`-`)}function Tt(e,t,n){let r=t[e],{fetchOptions:i,query:a,...o}=n||{};return r||(i?.method?i.method:o&&Object.keys(o).length>0?`POST`:`GET`)}function Et(e,t,n,r,i){function a(o=[]){return new Proxy(function(){},{get(t,n){if(typeof n!=`string`||n===`then`||n===`catch`||n===`finally`)return;let r=[...o,n],i=e;for(let e of r)if(i&&typeof i==`object`&&e in i)i=i[e];else{i=void 0;break}return typeof i==`function`||yt(i)?i:a(r)},apply:async(e,a,s)=>{let c=`/`+o.map(wt).join(`/`),l=s[0]||{},u=s[1]||{},{query:d,fetchOptions:f,...p}=l,m={...u,...f},h=Tt(c,n,l);return await t(c,{...m,body:h===`GET`?void 0:{...p,...m?.body||{}},query:d||m?.query,method:h,async onSuccess(e){if(await m?.onSuccess?.(e),!i||m.disableSignal)return;let t=i.filter(e=>e.matcher(c));if(!t.length)return;let n=new Set;for(let e of t){let t=r[e.signal];if(!t)return;if(n.has(e.signal))continue;n.add(e.signal);let i=t.get();setTimeout(()=>{t.set(!i)},10),e.callback?.(c)}}})}})}return a()}function Dt(e){let{pluginPathMethods:t,pluginsActions:n,pluginsAtoms:r,$fetch:i,atomListeners:a,$store:o}=vt(e),s={};for(let[e,t]of Object.entries(r))s[`use${bt(e)}`]=t;return Et({...n,...s,$fetch:i,$store:o},i,t,r,a)}function Ot(e){return{success:!1,error:`You are not allowed to access resource: ${e}`}}function kt(e){return{success:!1,error:`unauthorized to access resource "${e}"`}}function At(e){return e===`OR`?`OR`:`AND`}function jt(e){return Array.isArray(e)}function Mt(e){if(jt(e))return{actions:e,connector:`AND`};if(!e||typeof e!=`object`)throw new W(`Invalid access control request`);let{actions:t,connector:n}=e;return jt(t)?{actions:t,connector:At(n)}:{actions:[],connector:At(n)}}function Nt(e,t){return typeof t==`string`&&e.includes(t)}function Pt(e,{actions:t,connector:n}){return t.length===0?!1:n===`OR`?t.some(t=>Nt(e,t)):t.every(t=>Nt(e,t))}function Ft(e){return{authorize(t,n=`AND`){let r=!1;for(let[i,a]of Object.entries(t)){let t=e[i];if(!t){if(n===`AND`)return Ot(i);continue}let o=Pt(t,Mt(a));if(o&&(r=!0),o&&n===`OR`)return{success:!0};if(!o&&n===`AND`)return kt(i)}return r?{success:!0}:{success:!1,error:`Not authorized`}},statements:e}}function It(e){return{newRole(e){return Ft(e)},statements:e}}var Lt=de({YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION:`You are not allowed to create a new organization`,YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS:`You have reached the maximum number of organizations`,ORGANIZATION_ALREADY_EXISTS:`Organization already exists`,ORGANIZATION_SLUG_ALREADY_TAKEN:`Organization slug already taken`,ORGANIZATION_NOT_FOUND:`Organization not found`,USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION:`User is not a member of the organization`,YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_ORGANIZATION:`You are not allowed to update this organization`,YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_ORGANIZATION:`You are not allowed to delete this organization`,NO_ACTIVE_ORGANIZATION:`No active organization`,USER_IS_ALREADY_A_MEMBER_OF_THIS_ORGANIZATION:`User is already a member of this organization`,MEMBER_NOT_FOUND:`Member not found`,ROLE_NOT_FOUND:`Role not found`,YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM:`You are not allowed to create a new team`,TEAM_ALREADY_EXISTS:`Team already exists`,TEAM_NOT_FOUND:`Team not found`,YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER:`You cannot leave the organization as the only owner`,YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER:`You cannot leave the organization without an owner`,YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_MEMBER:`You are not allowed to delete this member`,YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION:`You are not allowed to invite users to this organization`,USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION:`User is already invited to this organization`,INVITATION_NOT_FOUND:`Invitation not found`,YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION:`You are not the recipient of the invitation`,EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION:`Email verification required before accepting or rejecting invitation`,EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION:`Email verification required to view or list invitations for the session email`,YOU_ARE_NOT_ALLOWED_TO_CANCEL_THIS_INVITATION:`You are not allowed to cancel this invitation`,INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION:`Inviter is no longer a member of the organization`,YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE:`You are not allowed to invite a user with this role`,FAILED_TO_RETRIEVE_INVITATION:`Failed to retrieve invitation`,YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS:`You have reached the maximum number of teams`,UNABLE_TO_REMOVE_LAST_TEAM:`Unable to remove last team`,YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_MEMBER:`You are not allowed to update this member`,ORGANIZATION_MEMBERSHIP_LIMIT_REACHED:`Organization membership limit reached`,YOU_ARE_NOT_ALLOWED_TO_CREATE_TEAMS_IN_THIS_ORGANIZATION:`You are not allowed to create teams in this organization`,YOU_ARE_NOT_ALLOWED_TO_DELETE_TEAMS_IN_THIS_ORGANIZATION:`You are not allowed to delete teams in this organization`,YOU_ARE_NOT_ALLOWED_TO_UPDATE_THIS_TEAM:`You are not allowed to update this team`,YOU_ARE_NOT_ALLOWED_TO_DELETE_THIS_TEAM:`You are not allowed to delete this team`,INVITATION_LIMIT_REACHED:`Invitation limit reached`,TEAM_MEMBER_LIMIT_REACHED:`Team member limit reached`,USER_IS_NOT_A_MEMBER_OF_THE_TEAM:`User is not a member of the team`,YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM:`You are not allowed to list the members of this team`,YOU_DO_NOT_HAVE_AN_ACTIVE_TEAM:`You do not have an active team`,YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_TEAM_MEMBER:`You are not allowed to create a new member`,YOU_ARE_NOT_ALLOWED_TO_REMOVE_A_TEAM_MEMBER:`You are not allowed to remove a team member`,YOU_ARE_NOT_ALLOWED_TO_ACCESS_THIS_ORGANIZATION:`You are not allowed to access this organization as an owner`,YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION:`You are not a member of this organization`,MISSING_AC_INSTANCE:`Dynamic Access Control requires a pre-defined ac instance on the server auth plugin. Read server logs for more information`,YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE:`You must be in an organization to create a role`,YOU_ARE_NOT_ALLOWED_TO_CREATE_A_ROLE:`You are not allowed to create a role`,YOU_ARE_NOT_ALLOWED_TO_UPDATE_A_ROLE:`You are not allowed to update a role`,YOU_ARE_NOT_ALLOWED_TO_DELETE_A_ROLE:`You are not allowed to delete a role`,YOU_ARE_NOT_ALLOWED_TO_READ_A_ROLE:`You are not allowed to read a role`,YOU_ARE_NOT_ALLOWED_TO_LIST_A_ROLE:`You are not allowed to list a role`,YOU_ARE_NOT_ALLOWED_TO_GET_A_ROLE:`You are not allowed to get a role`,TOO_MANY_ROLES:`This organization has too many roles`,INVALID_RESOURCE:`The provided permission includes an invalid resource`,ROLE_NAME_IS_ALREADY_TAKEN:`That role name is already taken`,CANNOT_DELETE_A_PRE_DEFINED_ROLE:`Cannot delete a pre-defined role`,ROLE_IS_ASSIGNED_TO_MEMBERS:`Cannot delete a role that is assigned to members. Please reassign the members to a different role first`,INVALID_TEAM_ID:`Team id contains a reserved character`}),Rt=It({organization:[`update`,`delete`],member:[`create`,`update`,`delete`],invitation:[`create`,`cancel`],team:[`create`,`update`,`delete`],ac:[`create`,`read`,`update`,`delete`]}),zt=Rt.newRole({organization:[`update`],invitation:[`create`,`cancel`],member:[`create`,`update`,`delete`],team:[`create`,`update`,`delete`],ac:[`create`,`read`,`update`,`delete`]}),Bt=Rt.newRole({organization:[`update`,`delete`],member:[`create`,`update`,`delete`],invitation:[`create`,`cancel`],team:[`create`,`update`,`delete`],ac:[`create`,`read`,`update`,`delete`]}),Vt=Rt.newRole({organization:[],member:[],invitation:[],team:[],ac:[`read`]}),Ht={admin:zt,owner:Bt,member:Vt},Ut=(e,t)=>{if(!e.permissions)return!1;let n=e.role.split(`,`),r=e.options.creatorRole||`owner`,i=n.includes(r),a=e.allowCreatorAllPermissions||!1;if(i&&a)return!0;for(let r of n)if(t[r]?.authorize(e.permissions)?.success)return!0;return!1},Wt=e=>Ut(e,e.options.roles||Ht),Gt=e=>{let t=y(!1),n=y(!1),r=y(!1),i=y(!1),a={admin:zt,member:Vt,owner:Bt,...e?.roles};return{id:`organization`,version:c,$InferServerPlugin:{},getActions:(t,n,r)=>({$Infer:{ActiveOrganization:{},Organization:{},Invitation:{},Member:{},Team:{}},organization:{checkRolePermission:t=>Wt({role:t.role,options:{ac:e?.ac,roles:a},permissions:t.permissions})}}),getAtoms:e=>{let a=z(t,`/organization/list`,e,{method:`GET`});return{$listOrg:t,$activeOrgSignal:n,$activeMemberSignal:r,$activeMemberRoleSignal:i,activeOrganization:z([n],`/organization/get-full-organization`,e,()=>({method:`GET`})),listOrganizations:a,activeMember:z([n,r],`/organization/get-active-member`,e,{method:`GET`}),activeMemberRole:z([n,i],`/organization/get-active-member-role`,e,{method:`GET`})}},pathMethods:{"/organization/get-full-organization":`GET`,"/organization/list-user-teams":`GET`},atomListeners:[{matcher(e){return e===`/organization/create`||e===`/organization/delete`||e===`/organization/update`},signal:`$listOrg`},{matcher(e){return e===`/sign-out`||e.startsWith(`/organization`)},signal:`$activeOrgSignal`},{matcher(e){return e.startsWith(`/organization/set-active`)||e===`/organization/create`||e===`/organization/delete`||e===`/organization/remove-member`||e===`/organization/leave`||e===`/organization/accept-invitation`},signal:`$sessionSignal`},{matcher(e){return e.includes(`/organization/update-member-role`)||e.startsWith(`/organization/set-active`)},signal:`$activeMemberSignal`},{matcher(e){return e.includes(`/organization/update-member-role`)||e.startsWith(`/organization/set-active`)},signal:`$activeMemberRoleSignal`}],$ERROR_CODES:Lt}},Kt=de({OTP_NOT_ENABLED:`OTP not enabled`,OTP_HAS_EXPIRED:`OTP has expired`,TOTP_NOT_ENABLED:`TOTP not enabled`,TWO_FACTOR_NOT_ENABLED:`Two factor isn't enabled`,BACKUP_CODES_NOT_ENABLED:`Backup codes aren't enabled`,INVALID_BACKUP_CODE:`Invalid backup code`,INVALID_CODE:`Invalid code`,TOO_MANY_ATTEMPTS_REQUEST_NEW_CODE:`Too many attempts. Please request a new code.`,ACCOUNT_TEMPORARILY_LOCKED:`Too many failed verification attempts. Your account is temporarily locked. Please try again later.`,INVALID_TWO_FACTOR_COOKIE:`Invalid two factor cookie`}),qt=e=>({id:`two-factor`,version:c,$InferServerPlugin:{},atomListeners:[{matcher:e=>e.startsWith(`/two-factor/`),signal:`$sessionSignal`}],pathMethods:{"/two-factor/disable":`POST`,"/two-factor/enable":`POST`,"/two-factor/send-otp":`POST`,"/two-factor/generate-backup-codes":`POST`,"/two-factor/get-totp-uri":`POST`,"/two-factor/verify-totp":`POST`,"/two-factor/verify-otp":`POST`,"/two-factor/verify-backup-code":`POST`},fetchPlugins:[{id:`two-factor`,name:`two-factor`,hooks:{async onSuccess(t){if(t.data?.twoFactorRedirect){if(e?.onTwoFactorRedirect){await e.onTwoFactorRedirect({twoFactorMethods:t.data.twoFactorMethods});return}e?.twoFactorPage&&typeof window<`u`&&we(e.twoFactorPage)&&(window.location.href=e.twoFactorPage)}}}}],$ERROR_CODES:Kt}),Jt=`auth-session-token`,J={_memoryToken:null,get(){try{if(typeof localStorage<`u`)return localStorage.getItem(Jt)}catch{}return this._memoryToken},set(e){this._memoryToken=e;try{typeof localStorage<`u`&&localStorage.setItem(Jt,e)}catch{}},clear(){this._memoryToken=null;try{typeof localStorage<`u`&&localStorage.removeItem(Jt)}catch{}}};function Yt(e){let t=Error(e.message??`Auth request failed with status ${e.status}`);return e.code&&(t.code=e.code),t}function Xt(e){try{let t=new URL(e);return{origin:t.origin,basePath:t.pathname.replace(/\/$/,``)}}catch{return{origin:Zt()??`http://localhost`,basePath:e.replace(/\/$/,``)}}}function Zt(){try{if(typeof window<`u`&&window.location?.origin)return window.location.origin}catch{}}function Qt(){try{if(typeof document<`u`){let e=document.querySelector(`base`)?.getAttribute(`href`);if(e)return`${new URL(e,Zt()??`http://localhost`).pathname.replace(/\/$/,``)}/reset-password`}}catch{}return`/reset-password`}function $t(e){let t=e||globalThis.fetch.bind(globalThis);return async(e,n)=>{let r=new Headers(n?.headers),i=J.get();if(i){let t=typeof e==`string`?e:e instanceof URL?e.href:e.url;/\/api\//i.test(t)&&r.set(`Authorization`,`Bearer ${i}`)}let a=await t(e,{...n,headers:r}),o=a.headers.get(`set-auth-token`);return o&&J.set(o),a}}function en(e){let{baseURL:t,fetchFn:n}=e,{origin:r,basePath:i}=Xt(t),a=$t(n),o=Dt({baseURL:r,basePath:i,disableDefaultFetchPlugins:!0,fetchOptions:{customFetchImpl:a},plugins:[Gt(),qt()]});async function s(e,t){let n=await a(`${r}${i}${e}`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify(t)}),o=await n.json().catch(()=>({}));if(!n.ok){let e=Error(o?.message??`Auth request failed with status ${n.status}`);throw o?.code&&(e.code=o.code),e.status=n.status,e}return o??{}}return{async signIn(e){let{data:t,error:n}=await o.signIn.email({email:e.email,password:e.password});if(n)throw Yt(n);let r=t;return r.session?.token&&J.set(r.session.token),{user:r.user,session:r.session}},async signUp(e){let{data:t,error:n}=await o.signUp.email({email:e.email,password:e.password,name:e.name});if(n)throw Yt(n);let r=t,i=r.token??r.session?.token??null;i&&J.set(i);let a=r.session??null;return!a&&i&&(a={token:i}),{user:r.user,session:a,requiresVerification:i===null}},async sendVerificationEmail(e,t){let{error:n}=await o.sendVerificationEmail({email:e,callbackURL:t});if(n)throw Error(n.message??`Auth request failed with status ${n.status}`)},async signOut(){let{error:e}=await o.signOut();if(J.clear(),e)throw Error(e.message??`Auth request failed with status ${e.status}`)},async getSession(){let e=null;try{let t=await o.getSession();t.error||(e=t.data)}catch{}if(e){let t=e;return t.session?.token&&J.set(t.session.token),{user:t.user,session:t.session}}if(J.get())try{let e=await(n||globalThis.fetch.bind(globalThis))(`${r}${i}/get-session`,{method:`GET`,credentials:`include`,headers:{"Content-Type":`application/json`}});if(e.ok){let t=await e.json().catch(()=>null);if(t?.user&&t?.session)return t.session.token?J.set(t.session.token):J.clear(),{user:t.user,session:t.session};J.clear()}}catch{}return null},async forgotPassword(e){let t=o,n=t.requestPasswordReset??t.forgetPassword;if(typeof n!=`function`)throw Error(`password reset is not available on this auth backend`);let{error:r}=await n({email:e,redirectTo:Qt()});if(r)throw Error(r.message??`Auth request failed with status ${r.status}`)},async resetPassword(e,t){let{error:n}=await o.resetPassword({token:e,newPassword:t});if(n)throw Error(n.message??`Auth request failed with status ${n.status}`)},async sendPhoneOtp(e){await s(`/phone-number/send-otp`,{phoneNumber:e})},async signInWithPhoneOtp(e,t){let n=await s(`/phone-number/verify`,{phoneNumber:e,code:t}),r=typeof n.token==`string`?n.token:void 0,i=n.user??null;if(!r||!i)throw Error(`No account is registered for this phone number.`);return J.set(r),{user:i,session:{token:r}}},async requestPhonePasswordReset(e){await s(`/phone-number/request-password-reset`,{phoneNumber:e})},async resetPasswordWithPhoneOtp(e,t,n){await s(`/phone-number/reset-password`,{phoneNumber:e,otp:t,newPassword:n})},async changePassword(e,t,n){let r=o.changePassword;if(typeof r!=`function`)throw Error(`change-password is not available on this auth backend`);let{error:i}=await r({currentPassword:e,newPassword:t,...n?.revokeOtherSessions==null?{}:{revokeOtherSessions:n.revokeOtherSessions}});if(i)throw Error(i.message??`Auth request failed with status ${i.status}`)},async enrollTotp(e){let t=o.twoFactor;if(!t||typeof t.enable!=`function`)throw Error(`two-factor enrollment is not available on this auth backend`);let{data:n,error:r}=await t.enable({password:e});if(r)throw Error(r.message??`Two-factor enable failed (${r.status??`?`})`);return{totpURI:n?.totpURI??``,backupCodes:n?.backupCodes??[]}},async verifyTotp(e){let t=o.twoFactor;if(!t||typeof t.verifyTotp!=`function`)throw Error(`two-factor verification is not available on this auth backend`);let{error:n}=await t.verifyTotp({code:e});if(n)throw Error(n.message??`Two-factor verification failed (${n.status??`?`})`)},async setInitialPassword(e){let t=`${r}${i}/set-initial-password`,n=await a(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({newPassword:e})});if(!n.ok){let e=`Set password failed with status ${n.status}`;try{let t=await n.json();t?.error?.message&&(e=t.error.message)}catch{}throw Error(e)}},async hasLocalPassword(){let e=`${r}${i}/list-accounts`;try{let t=await a(e,{method:`GET`,headers:{"Content-Type":`application/json`}});if(!t.ok)return!1;let n=await t.json();return(Array.isArray(n)?n:n&&`data`in n&&Array.isArray(n.data)?n.data:[]).some(e=>e?.providerId===`credential`)}catch{return!1}},async updateUser(e){let{data:t,error:n}=await o.updateUser(e);if(n)throw Error(n.message??`Auth request failed with status ${n.status}`);if(!t)throw Error(`Update user returned no data`);let r=t;return r&&typeof r==`object`&&`user`in r?r.user:r},async getConfig(){let e=`${r}${i}/config`,t=await a(e,{method:`GET`,headers:{"Content-Type":`application/json`}});if(!t.ok)throw Error(`Failed to load auth config (status ${t.status})`);let n=await t.json();return n&&typeof n==`object`&&`data`in n&&n.data?n.data:n},async signInWithProvider(e,t={}){let{type:n=`social`,callbackURL:r,errorCallbackURL:i}=t;if(n===`oidc`){let t=o.signIn.oauth2;if(!t)throw Error(`OIDC sign-in is not supported by this auth client build`);let{data:n,error:a}=await t({providerId:e,callbackURL:r,errorCallbackURL:i});if(a)throw Error(a.message??`Auth request failed with status ${a.status}`);n?.url&&typeof window<`u`&&(window.location.href=n.url);return}let{data:a,error:s}=await o.signIn.social({provider:e,callbackURL:r,errorCallbackURL:i});if(s)throw Error(s.message??`Auth request failed with status ${s.status}`);let c=a?.url;c&&typeof window<`u`&&(window.location.href=c)},async listOrganizations(){let{data:e,error:t}=await o.organization.list();if(t)throw Error(t.message??`Failed to list organizations`);return e??[]},async createOrganization(e){let{data:t,error:n}=await o.organization.create({name:e.name,slug:e.slug,logo:e.logo});if(n)throw Error(n.message??`Failed to create organization`);return t},async setActiveOrganization(e){let{data:t,error:n}=await o.organization.setActive({organizationId:e});if(n)throw Error(n.message??`Failed to set active organization`);return t??null},async getActiveOrganization(){let{data:e,error:t}=await o.organization.getFullOrganization();return t||!e?null:e},async getActiveMember(){let e=o.organization?.getActiveMember;if(typeof e!=`function`)return null;let{data:t,error:n}=await e();return n||!t?null:t},async getMembers(e){let{data:t,error:n}=await o.organization.listMembers({query:{organizationId:e}});if(n)throw Error(n.message??`Failed to get members`);let r=t;return Array.isArray(r)?r:r?.members??[]},async inviteMember(e){let{data:t,error:n}=await o.organization.inviteMember({organizationId:e.organizationId,email:e.email,role:e.role});if(n)throw Error(n.message??`Failed to invite member`);return t},async removeMember(e){let{error:t}=await o.organization.removeMember({organizationId:e.organizationId,memberIdOrUserId:e.memberIdOrUserId});if(t)throw Error(t.message??`Failed to remove member`)},async updateMemberRole(e){let{error:t}=await o.organization.updateMemberRole({organizationId:e.organizationId,memberId:e.memberId,role:e.role});if(t)throw Error(t.message??`Failed to update member role`)},async updateOrganization(e,t){let{data:n,error:r}=await o.organization.update({organizationId:e,data:t});if(r)throw Error(r.message??`Failed to update organization`);return n},async deleteOrganization(e){let{error:t}=await o.organization.delete({organizationId:e});if(t)throw Error(t.message??`Failed to delete organization`)},async leaveOrganization(e){let{error:t}=await o.organization.leave({organizationId:e});if(t)throw Error(t.message??`Failed to leave organization`)},async listInvitations(e){let{data:t,error:n}=await o.organization.listInvitations({query:{organizationId:e}});if(n)throw Error(n.message??`Failed to list invitations`);return t??[]},async cancelInvitation(e){let{error:t}=await o.organization.cancelInvitation({invitationId:e});if(t)throw Error(t.message??`Failed to cancel invitation`)},async getInvitation(e){let{data:t,error:n}=await o.organization.getInvitation({query:{id:e}});if(n)throw Error(n.message??`Failed to load invitation`);return t},async acceptInvitation(e){let{error:t}=await o.organization.acceptInvitation({invitationId:e});if(t)throw Error(t.message??`Failed to accept invitation`)},async rejectInvitation(e){let{error:t}=await o.organization.rejectInvitation({invitationId:e});if(t)throw Error(t.message??`Failed to reject invitation`)},async listUserInvitations(){let{data:e,error:t}=await o.organization.listUserInvitations();if(t)throw Error(t.message??`Failed to list invitations`);return e??[]}}}var tn=`auth-active-organization-id`,nn={_memoryValue:null,get(){try{if(typeof localStorage<`u`)return localStorage.getItem(tn)}catch{}return this._memoryValue},set(e){this._memoryValue=e;try{typeof localStorage<`u`&&localStorage.setItem(tn,e)}catch{}},clear(){this._memoryValue=null;try{typeof localStorage<`u`&&localStorage.removeItem(tn)}catch{}}};function rn(){return async(e,t)=>{let n=new Headers(t?.headers),r=typeof e==`string`?e:e instanceof URL?e.href:e.url,i=/\/api\//i.test(r),s=J.get();s&&i&&n.set(`Authorization`,`Bearer ${s}`);let c=nn.get();if(c&&n.set(`X-Tenant-ID`,c),i&&!n.has(`Accept-Language`)&&typeof document<`u`){let e=document.documentElement.lang;e&&n.set(`Accept-Language`,e)}let l=await fetch(e,{...t,headers:n});if(i&&l.status===403)try{let e=o(l.status,await l.clone().json());e&&a.emit(e)}catch{}return l}}var Y=t();function an({authUrl:e,client:t,onAuthStateChange:n,enabled:i=!0,previewMode:o,children:c}){let l=(0,r.useMemo)(()=>t??en({baseURL:e}),[t,e]),[u,d]=(0,r.useState)(null),[f,p]=(0,r.useState)(null),[m,h]=(0,r.useState)(!0),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(null),[w,T]=(0,r.useState)(null),[E,D]=(0,r.useState)(!1),O=o!=null,k=i&&!O?u!==null&&f!==null:!0;(0,r.useEffect)(()=>{if(O){let e=o.simulatedRole??`admin`,t=o.simulatedUserName??`Preview User`,n=o.expiresInSeconds??0;d({id:`preview-user`,email:`preview@preview.local`,name:t,role:e,roles:[e]}),p({token:`preview-token`,expiresAt:n>0?new Date(Date.now()+n*1e3):new Date(Date.now()+365*24*60*60*1e3)}),h(!1);return}if(!i){d({id:`guest`,email:`guest@local`,name:`Guest User`,role:`admin`}),p({token:`guest-token`,expiresAt:new Date(Date.now()+365*24*60*60*1e3)}),h(!1);return}let e=!1;async function t(){try{let t=await l.getSession();if(e)return;t&&(d(t.user),p(t.session))}catch(t){if(e)return;_(t instanceof Error?t:Error(String(t)))}finally{e||h(!1)}}return t(),()=>{e=!0}},[l,i,O,o]),(0,r.useEffect)(()=>{n?.({user:u,session:f,isAuthenticated:k,isLoading:m,error:g})},[u,f,k,m,g,n]);let ee=(0,r.useCallback)(async(e,t)=>{h(!0),_(null);try{let n=await l.signIn({email:e,password:t});d(n.user),p(n.session)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}finally{h(!1)}},[l]),A=(0,r.useCallback)(async(e,t,n)=>{h(!0),_(null);try{let r=await l.signUp({name:e,email:t,password:n});return r.requiresVerification?{requiresVerification:!0}:(d(r.user),p(r.session),{requiresVerification:!1})}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}finally{h(!1)}},[l]),j=(0,r.useCallback)(async()=>{h(!0);try{await l.signOut(),d(null),p(null),_(null)}catch(e){_(e instanceof Error?e:Error(String(e)))}finally{h(!1)}},[l]),te=(0,r.useCallback)(async e=>{_(null);try{let t=await l.updateUser(e);d(t)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),M=(0,r.useCallback)(async e=>{_(null);try{await l.forgotPassword(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),N=(0,r.useCallback)(async(e,t)=>{_(null);try{await l.sendVerificationEmail(e,t)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),P=(0,r.useCallback)(async(e,t)=>{_(null);try{await l.resetPassword(e,t)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),ne=(0,r.useCallback)(async e=>{_(null);try{await l.sendPhoneOtp(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),re=(0,r.useCallback)(async(e,t)=>{h(!0),_(null);try{let n=await l.signInWithPhoneOtp(e,t);d(n.user),p(n.session)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}finally{h(!1)}},[l]),F=(0,r.useCallback)(async e=>{_(null);try{await l.requestPhonePasswordReset(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),ie=(0,r.useCallback)(async(e,t,n)=>{_(null);try{await l.resetPasswordWithPhoneOtp(e,t,n)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]);(0,r.useEffect)(()=>a.subscribe(e=>{y(t=>t??e)}),[]);let I=(0,r.useCallback)(e=>l.enrollTotp(e),[l]),ae=(0,r.useCallback)(e=>l.verifyTotp(e),[l]),L=(0,r.useCallback)(async(e,t,n)=>{_(null);try{await l.changePassword(e,t,n)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),oe=(0,r.useCallback)(async e=>{_(null);try{await l.setInitialPassword(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),se=(0,r.useCallback)(()=>l.hasLocalPassword(),[l]),R=(0,r.useCallback)(()=>l.getConfig(),[l]),z=(0,r.useCallback)(async(e,t)=>{_(null);try{await l.signInWithProvider(e,t)}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),B=(0,r.useCallback)(async e=>{if(!(!i||O)){D(!0);try{let t=await l.listOrganizations();if(e?.())return t;if(x(t),t.length>0&&!S){let n=null;try{n=await l.getActiveOrganization()}catch{n=null}if(!n&&t.length===1)try{n=await l.setActiveOrganization(t[0].id)}catch{n=null}n&&!e?.()&&(C(n),nn.set(n.id))}return t}catch(t){e?.()||console.warn(`[AuthProvider] Failed to load organizations:`,t)}finally{e?.()||D(!1)}}},[l,i,O,S]),ce=(0,r.useCallback)(async()=>{if(!i||O){let e=O?o?.simulatedRole??`admin`:`admin`;T({id:`preview-member`,organizationId:S?.id??`preview-org`,userId:`preview-user`,role:e});return}if(!S){T(null);return}try{let e=await l.getActiveMember();T(e)}catch(e){console.warn(`[AuthProvider] Failed to load active member:`,e),T(null)}},[l,i,O,o,S]);(0,r.useEffect)(()=>{ce()},[ce]),(0,r.useEffect)(()=>{if(!(u&&i&&!O))return;let e=!1;return B(()=>e),()=>{e=!0}},[u,i,O]);let le=(0,r.useCallback)(async e=>{_(null);try{let t=await l.setActiveOrganization(e);C(t),t?nn.set(t.id):nn.clear()}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l]),ue=(0,r.useCallback)(async e=>{_(null);try{let t=await l.createOrganization(e);return await B(),await le(t.id),t}catch(e){let t=e instanceof Error?e:Error(String(e));throw _(t),t}},[l,B,le]),V=(0,r.useCallback)(async(e,t)=>{let n=await l.updateOrganization(e,t);return await B(),S?.id===e&&C(n),n},[l,B,S]),H=(0,r.useCallback)(async e=>{await l.deleteOrganization(e),S?.id===e&&(C(null),nn.clear()),await B()},[l,S,B]),U=(0,r.useCallback)(async e=>{await l.leaveOrganization(e),S?.id===e&&(C(null),nn.clear()),await B()},[l,S,B]),de=(0,r.useCallback)(e=>l.getMembers(e),[l]),fe=(0,r.useCallback)(e=>l.inviteMember(e),[l]),pe=(0,r.useCallback)(e=>l.removeMember(e),[l]),me=(0,r.useCallback)(e=>l.updateMemberRole(e),[l]),he=(0,r.useCallback)(e=>l.listInvitations(e),[l]),W=(0,r.useCallback)(e=>l.cancelInvitation(e),[l]),ge=(0,r.useCallback)(e=>l.getInvitation(e),[l]),_e=(0,r.useCallback)(async e=>{await l.acceptInvitation(e),await B()},[l,B]),ve=(0,r.useCallback)(e=>l.rejectInvitation(e),[l]),ye=(0,r.useCallback)(()=>l.listUserInvitations(),[l]),G=i&&!O,be=(0,r.useMemo)(()=>({user:u,session:f,isAuthenticated:k,isAuthEnabled:G,isLoading:m,error:g,isPreviewMode:O,previewMode:O?o:null,signIn:ee,signUp:A,signOut:j,updateUser:te,forgotPassword:M,sendVerificationEmail:N,resetPassword:P,sendPhoneOtp:ne,signInWithPhoneOtp:re,requestPhonePasswordReset:F,resetPasswordWithPhoneOtp:ie,changePassword:L,remediationRequired:v,setRemediationRequired:y,enrollTotp:I,verifyTotp:ae,setInitialPassword:oe,hasLocalPassword:se,getAuthConfig:R,signInWithProvider:z,organizations:b,activeOrganization:S,activeMember:w,isOrganizationsLoading:E,switchOrganization:le,createOrganization:ue,refreshOrganizations:B,updateOrganization:V,deleteOrganization:H,leaveOrganization:U,getMembers:de,inviteMember:fe,removeMember:pe,updateMemberRole:me,listInvitations:he,cancelInvitation:W,getInvitation:ge,acceptInvitation:_e,rejectInvitation:ve,listUserInvitations:ye}),[u,f,k,G,m,g,O,o,ee,A,j,te,M,N,P,L,oe,se,R,z,ne,re,F,ie,v,I,ae,b,S,w,E,le,ue,B,V,H,U,de,fe,pe,me,he,W,ge,_e,ve,ye]);return(0,Y.jsx)(s.Provider,{value:be,children:c})}function X(){return(0,r.useContext)(s)||{user:null,session:null,isAuthenticated:!1,isAuthEnabled:!1,isLoading:!1,error:null,isPreviewMode:!1,previewMode:null,signIn:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},signUp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},signOut:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},updateUser:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},forgotPassword:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},sendVerificationEmail:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},resetPassword:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},sendPhoneOtp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},signInWithPhoneOtp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},requestPhonePasswordReset:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},resetPasswordWithPhoneOtp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},changePassword:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},remediationRequired:null,setRemediationRequired:()=>{},enrollTotp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},verifyTotp:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},setInitialPassword:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},hasLocalPassword:async()=>!1,getAuthConfig:async()=>({}),signInWithProvider:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},organizations:[],activeOrganization:null,activeMember:null,isOrganizationsLoading:!1,switchOrganization:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},createOrganization:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},refreshOrganizations:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},updateOrganization:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},deleteOrganization:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},leaveOrganization:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},getMembers:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},inviteMember:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},removeMember:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},updateMemberRole:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},listInvitations:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},cancelInvitation:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},getInvitation:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},acceptInvitation:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},rejectInvitation:async()=>{throw Error(`useAuth must be used within an AuthProvider`)},listUserInvitations:async()=>{throw Error(`useAuth must be used within an AuthProvider`)}}}var on=new Set([`owner`,`admin`,`super_admin`,`superadmin`,`platform_admin`,`system_admin`,`org_owner`,`org_admin`]);function sn(e){return typeof e==`string`&&on.has(e.toLowerCase())}function cn(){let{activeMember:e,user:t}=X();return!!(sn(e?.role)||sn(t?.role)||Array.isArray(t?.roles)&&t.roles.some(sn))}function ln({fallback:e=null,requiredRoles:t,loadingFallback:n,children:r}){let{isAuthenticated:i,isLoading:a,user:o}=X();if(a)return(0,Y.jsx)(Y.Fragment,{children:n??null});if(!i)return(0,Y.jsx)(Y.Fragment,{children:e});if(t&&t.length>0&&o){let n=o.roles??(o.role?[o.role]:[]);if(!t.some(e=>n.includes(e)))return(0,Y.jsx)(Y.Fragment,{children:e})}return(0,Y.jsx)(Y.Fragment,{children:r})}var un={google:`Google`,github:`GitHub`,microsoft:`Microsoft`,apple:`Apple`,facebook:`Facebook`,twitter:`Twitter`,discord:`Discord`,gitlab:`GitLab`,linkedin:`LinkedIn`},dn={google:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{fill:`#EA4335`,d:`M12 10.2v3.9h5.5c-.24 1.4-1.7 4.1-5.5 4.1-3.3 0-6-2.74-6-6.1s2.7-6.1 6-6.1c1.88 0 3.14.8 3.86 1.5l2.64-2.55C16.84 3.36 14.66 2.4 12 2.4 6.92 2.4 2.8 6.52 2.8 11.6S6.92 20.8 12 20.8c6.92 0 9.2-4.86 9.2-7.4 0-.5-.06-.88-.14-1.2H12z`})}),github:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4 fill-current`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{d:`M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.11.79-.25.79-.56v-2.07c-3.2.7-3.87-1.37-3.87-1.37-.52-1.33-1.27-1.69-1.27-1.69-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.18 1.76 1.18 1.02 1.75 2.68 1.25 3.34.96.1-.74.4-1.25.73-1.54-2.55-.29-5.24-1.28-5.24-5.69 0-1.26.45-2.29 1.18-3.1-.12-.29-.51-1.46.11-3.04 0 0 .97-.31 3.18 1.18a11.04 11.04 0 015.79 0c2.21-1.49 3.18-1.18 3.18-1.18.62 1.58.23 2.75.11 3.04.74.81 1.18 1.84 1.18 3.1 0 4.42-2.7 5.39-5.27 5.68.41.36.78 1.06.78 2.13v3.16c0 .31.21.68.8.56C20.21 21.39 23.5 17.08 23.5 12 23.5 5.65 18.35.5 12 .5z`})}),microsoft:(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:[(0,Y.jsx)(`path`,{fill:`#F25022`,d:`M2 2h9.5v9.5H2z`}),(0,Y.jsx)(`path`,{fill:`#7FBA00`,d:`M12.5 2H22v9.5h-9.5z`}),(0,Y.jsx)(`path`,{fill:`#00A4EF`,d:`M2 12.5h9.5V22H2z`}),(0,Y.jsx)(`path`,{fill:`#FFB900`,d:`M12.5 12.5H22V22h-9.5z`})]}),apple:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4 fill-current`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{d:`M16.37 12.55c-.02-2.27 1.85-3.36 1.94-3.42-1.06-1.55-2.71-1.76-3.3-1.79-1.4-.14-2.74.83-3.45.83-.71 0-1.81-.81-2.98-.79-1.53.02-2.95.89-3.74 2.27-1.6 2.77-.41 6.86 1.14 9.11.76 1.1 1.66 2.34 2.83 2.3 1.14-.05 1.57-.74 2.94-.74 1.37 0 1.76.74 2.96.71 1.22-.02 2-1.12 2.75-2.23.87-1.28 1.22-2.52 1.24-2.59-.03-.01-2.38-.91-2.4-3.66zM14.1 5.31c.62-.76 1.05-1.81.93-2.86-.9.04-2 .6-2.65 1.35-.58.66-1.1 1.74-.96 2.76 1.01.08 2.04-.51 2.68-1.25z`})}),facebook:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{fill:`#1877F2`,d:`M24 12C24 5.37 18.63 0 12 0S0 5.37 0 12c0 5.99 4.39 10.95 10.13 11.85V15.47H7.08V12h3.05V9.36c0-3.01 1.79-4.67 4.53-4.67 1.31 0 2.69.23 2.69.23v2.96h-1.51c-1.49 0-1.96.93-1.96 1.88V12h3.33l-.53 3.47h-2.8v8.38C19.61 22.95 24 17.99 24 12z`})}),twitter:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4 fill-current`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{d:`M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z`})}),discord:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{fill:`#5865F2`,d:`M20.32 4.37A19.79 19.79 0 0016.56 3l-.18.36a18.27 18.27 0 00-8.76 0L7.44 3a19.79 19.79 0 00-3.76 1.37C.99 8.4.27 12.34.63 16.22a19.94 19.94 0 006.07 3.07l.49-.7a13.2 13.2 0 01-2.07-.99c.17-.13.34-.27.5-.41a14.13 14.13 0 0012.76 0c.16.14.33.28.5.41-.66.4-1.36.73-2.07.99l.49.7a19.92 19.92 0 006.07-3.07c.43-4.5-.66-8.41-2.95-11.85zM8.52 14.12c-1.18 0-2.15-1.08-2.15-2.41 0-1.33.95-2.42 2.15-2.42 1.2 0 2.17 1.09 2.15 2.42 0 1.33-.96 2.41-2.15 2.41zm6.96 0c-1.18 0-2.15-1.08-2.15-2.41 0-1.33.95-2.42 2.15-2.42 1.2 0 2.17 1.09 2.15 2.42 0 1.33-.95 2.41-2.15 2.41z`})}),gitlab:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{fill:`#FC6D26`,d:`M23.6 9.6L23.57 9.5 20.3.81a.84.84 0 00-1.6.05L16.5 7.6H7.5L5.3.86a.84.84 0 00-1.6-.05L.43 9.5l-.03.1a5.84 5.84 0 001.94 6.74l.01.01.03.02 4.8 3.6 2.38 1.8 1.45 1.1a1 1 0 001.2 0l1.45-1.1 2.38-1.8 4.83-3.62.01-.01a5.84 5.84 0 001.93-6.74z`})}),linkedin:(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,className:`h-4 w-4`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{fill:`#0A66C2`,d:`M20.45 20.45h-3.55v-5.57c0-1.33-.02-3.04-1.85-3.04-1.85 0-2.13 1.45-2.13 2.94v5.67H9.36V9h3.41v1.56h.05c.48-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.45v6.29zM5.34 7.43a2.06 2.06 0 11.01-4.13 2.06 2.06 0 010 4.13zM7.12 20.45H3.56V9h3.56v11.45zM22.22 0H1.77C.79 0 0 .77 0 1.72v20.56C0 23.23.79 24 1.77 24h20.45c.98 0 1.78-.77 1.78-1.72V1.72C24 .77 23.2 0 22.22 0z`})})};function fn({id:e}){let t=dn[e];return t?(0,Y.jsx)(`span`,{className:`mr-2 flex h-4 w-4 items-center justify-center`,children:t}):(0,Y.jsx)(`span`,{className:`mr-2 flex h-4 w-4 items-center justify-center rounded-sm bg-muted text-[10px] font-bold uppercase`,children:e[0]})}function pn({mode:e=`sign-in`,callbackURL:t,errorCallbackURL:n,dividerText:i=`or continue with email`,onProvidersResolved:a}){let{getAuthConfig:o,signInWithProvider:s}=X(),[c,l]=(0,r.useState)([]),[u,d]=(0,r.useState)(!0),[f,p]=(0,r.useState)(null);if((0,r.useEffect)(()=>{let e=!1;return Promise.resolve().then(()=>o()).then(t=>{if(e)return;let n=(t?.socialProviders??[]).filter(e=>e.enabled);l(n),a?.(n.length>0)}).catch(t=>{e||(console.warn(`[SocialSignInButtons] failed to load auth config`,t),a?.(!1))}).finally(()=>{e||d(!1)}),()=>{e=!0}},[o]),u||c.length===0)return null;let m=e===`sign-in`?`Continue with`:`Sign up with`,h=typeof window<`u`?window.location.href:void 0,g=async e=>{p(null);try{await s(e.id,{callbackURL:t??h,errorCallbackURL:n??t??h,type:e.type??`social`})}catch(e){p(e instanceof Error?e.message:String(e))}};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[f&&(0,Y.jsx)(`div`,{className:`rounded-md bg-destructive/15 p-3 text-sm text-destructive`,role:`alert`,children:f}),c.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g(e),className:`inline-flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,children:[(0,Y.jsx)(fn,{id:e.id}),m,` `,un[e.id]??e.name]},e.id)),(0,Y.jsxs)(`div`,{className:`relative my-1`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,Y.jsx)(`span`,{className:`w-full border-t`})}),(0,Y.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,Y.jsx)(`span`,{className:`bg-background px-2 text-muted-foreground`,children:i})})]})]})}var Z=`flex h-11 w-full rounded-lg border border-input bg-background px-3.5 py-2 text-sm shadow-sm ring-offset-background transition-colors placeholder:text-muted-foreground hover:border-primary/40 focus-visible:border-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30 focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50`,mn=`inline-flex h-11 w-full items-center justify-center gap-2 rounded-lg bg-gradient-to-r from-primary to-primary/85 px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm ring-offset-background transition-[box-shadow,background-color,transform] hover:shadow-md hover:from-primary hover:to-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:ring-offset-2 active:scale-[0.99] disabled:pointer-events-none disabled:opacity-60 motion-reduce:transition-none motion-reduce:active:transform-none`,Q=`text-sm font-medium leading-none text-foreground`;function $(){return(0,Y.jsxs)(`svg`,{className:`h-4 w-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,Y.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,Y.jsx)(`path`,{className:`opacity-90`,d:`M4 12a8 8 0 018-8`,stroke:`currentColor`,strokeWidth:`4`,strokeLinecap:`round`})]})}function hn({className:e}){return(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e??`h-4 w-4 shrink-0`,"aria-hidden":`true`,children:[(0,Y.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,Y.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,Y.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}function gn({className:e}){return(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,className:e??`h-7 w-7`,"aria-hidden":`true`,children:[(0,Y.jsx)(`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`}),(0,Y.jsx)(`path`,{d:`m22 6-10 7L2 6`})]})}function _n({icon:e,title:t,description:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center space-y-3 text-center`,children:[e&&(0,Y.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary ring-1 ring-primary/15`,children:e}),(0,Y.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground sm:text-[1.6rem]`,children:t}),n&&(0,Y.jsx)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:n})]})}function vn({message:e}){return(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-sm text-destructive`,role:`alert`,children:[(0,Y.jsx)(hn,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{className:`leading-snug`,children:e})]})}function yn({label:e=`or`}){return(0,Y.jsxs)(`div`,{className:`relative my-1`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 flex items-center`,"aria-hidden":`true`,children:(0,Y.jsx)(`span`,{className:`w-full border-t border-border`})}),(0,Y.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase tracking-wider`,children:(0,Y.jsx)(`span`,{className:`bg-background px-3 text-muted-foreground`,children:e})})]})}var bn=({href:e,className:t,children:n})=>(0,Y.jsx)(`a`,{href:e,className:t,children:n}),xn=()=>(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`h-6 w-6`,"aria-hidden":`true`,children:[(0,Y.jsx)(`rect`,{x:`3`,y:`11`,width:`18`,height:`11`,rx:`2`}),(0,Y.jsx)(`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`})]});function Sn({onSuccess:e,onError:t,registerUrl:n=`/register`,forgotPasswordUrl:i=`/forgot-password`,title:a=`Sign in to your account`,description:o=`Enter your email and password to continue`,icon:s,hideIcon:c=!1,linkComponent:l=bn,labels:u={},errorMessages:d}){let{signIn:f,isLoading:p,getAuthConfig:m,sendPhoneOtp:h,signInWithPhoneOtp:g}=X(),[_,v]=(0,r.useState)(``),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(null),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)(`password`),[D,O]=(0,r.useState)(``),[k,ee]=(0,r.useState)(``),[A,j]=(0,r.useState)(!1),[te,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(0),[ne,re]=(0,r.useState)(!1),[F,ie]=(0,r.useState)(!1),[I,ae]=(0,r.useState)(!1),[L,oe]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=!1;return Promise.resolve().then(()=>m()).then(t=>{e||(ie(t?.features?.sso===!0),w(t?.features?.phoneNumberOtp===!0),ae(t?.features?.ssoEnforced===!0||t?.emailPassword?.enabled===!1))}).catch(()=>{}),()=>{e=!0}},[m]);let se=!I||L,R={emailLabel:u.emailLabel??`Email`,emailPlaceholder:u.emailPlaceholder??`name@example.com`,passwordLabel:u.passwordLabel??`Password`,passwordPlaceholder:u.passwordPlaceholder??`Enter your password`,forgotPasswordText:u.forgotPasswordText??`Forgot password?`,submitButton:u.submitButton??`Sign In`,submittingButton:u.submittingButton??`Signing in…`,noAccountText:u.noAccountText??`Don't have an account?`,signUpText:u.signUpText??`Sign up`,orText:u.orText??`or`,ssoButton:u.ssoButton??`Sign in with SSO`,usePasswordText:u.usePasswordText??`Use a password instead`,backToSsoText:u.backToSsoText??`Back to single sign-on`,ssoOnlyDescription:u.ssoOnlyDescription??`Sign in with your organization's single sign-on`,phoneLabel:u.phoneLabel??`Phone number`,phonePlaceholder:u.phonePlaceholder??`+1 555 000 0000`,otpCodeLabel:u.otpCodeLabel??`Verification code`,otpCodePlaceholder:u.otpCodePlaceholder??`6-digit code`,sendOtpButton:u.sendOtpButton??`Get code`,resendOtpCountdownText:u.resendOtpCountdownText??`Resend in {seconds}s`,usePhoneOtpText:u.usePhoneOtpText??`Sign in with verification code`,usePasswordSignInText:u.usePasswordSignInText??`Sign in with password instead`};(0,r.useEffect)(()=>{if(N<=0)return;let e=setTimeout(()=>P(e=>e>1?e-1:0),1e3);return()=>clearTimeout(e)},[N]);let z=async n=>{n.preventDefault(),S(null);try{T===`phone-otp`?await g(D.trim(),k.trim()):await f(_,y),e?.()}catch(e){let n=e instanceof Error?e:Error(String(e)),r=n.code;S(r&&d?.[r]||n.message),t?.(n)}},B=async()=>{if(!(!D.trim()||A||N>0)){S(null),j(!0);try{await h(D.trim()),M(!0),P(60)}catch(e){let n=e instanceof Error?e:Error(String(e)),r=n.code;S(r&&d?.[r]||n.message),t?.(n)}finally{j(!1)}}},ce=e=>{E(e),S(null)};return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]`,children:[(0,Y.jsx)(_n,{icon:c?void 0:s??(0,Y.jsx)(xn,{}),title:a,description:I&&!L?R.ssoOnlyDescription:o}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsx)(pn,{mode:`sign-in`,onProvidersResolved:e=>re(e)}),se?T===`phone-otp`?(0,Y.jsxs)(`form`,{onSubmit:z,className:`space-y-4`,children:[ne&&(0,Y.jsx)(yn,{label:R.orText}),x&&(0,Y.jsx)(vn,{message:x}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`login-phone`,className:Q,children:R.phoneLabel}),(0,Y.jsx)(`input`,{id:`login-phone`,type:`tel`,placeholder:R.phonePlaceholder,value:D,onChange:e=>O(e.target.value),required:!0,autoComplete:`tel`,disabled:p,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`login-otp`,className:Q,children:R.otpCodeLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{id:`login-otp`,type:`text`,inputMode:`numeric`,placeholder:R.otpCodePlaceholder,value:k,onChange:e=>ee(e.target.value),required:!0,autoComplete:`one-time-code`,disabled:p,className:Z}),(0,Y.jsxs)(`button`,{type:`button`,onClick:B,disabled:A||N>0||!D.trim()||p,className:`shrink-0 rounded-md border border-input bg-background px-3 py-2 text-sm font-medium transition-colors hover:bg-accent disabled:opacity-50`,children:[A&&(0,Y.jsx)($,{}),N>0?R.resendOtpCountdownText.replace(`{seconds}`,String(N)):R.sendOtpButton]})]})]}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p||!te,className:mn,children:[p&&(0,Y.jsx)($,{}),p?R.submittingButton:R.submitButton]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ce(`password`),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:R.usePasswordSignInText})]}):(0,Y.jsxs)(`form`,{onSubmit:z,className:`space-y-4`,children:[ne&&(0,Y.jsx)(yn,{label:R.orText}),x&&(0,Y.jsx)(vn,{message:x}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`login-email`,className:Q,children:R.emailLabel}),(0,Y.jsx)(`input`,{id:`login-email`,type:`email`,placeholder:R.emailPlaceholder,value:_,onChange:e=>v(e.target.value),required:!0,autoComplete:`email`,disabled:p,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`label`,{htmlFor:`login-password`,className:Q,children:R.passwordLabel}),i&&(0,Y.jsx)(l,{href:i,className:`text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:R.forgotPasswordText})]}),(0,Y.jsx)(`input`,{id:`login-password`,type:`password`,placeholder:R.passwordPlaceholder,value:y,onChange:e=>b(e.target.value),required:!0,autoComplete:`current-password`,disabled:p,className:Z})]}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p,className:mn,children:[p&&(0,Y.jsx)($,{}),p?R.submittingButton:R.submitButton]}),F&&(0,Y.jsx)(`button`,{type:`button`,onClick:async()=>{S(null);try{let e=window.location.pathname.replace(/\/login(?:\/.*)?$/,``),t=await fetch(`/api/v1/auth/sign-in/sso`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({email:_,callbackURL:e+`/home`}),credentials:`include`}),n=await t.json().catch(()=>({}));if(t.ok&&typeof n.url==`string`){window.location.href=n.url;return}S(n.message||`No SSO provider is configured for this email domain.`)}catch(e){S(e instanceof Error?e.message:String(e))}},disabled:p,className:`flex w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent disabled:opacity-50`,children:R.ssoButton}),C&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>ce(`phone-otp`),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:R.usePhoneOtpText}),I&&L&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>oe(!1),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:R.backToSsoText})]}):(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[x&&(0,Y.jsx)(vn,{message:x}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>oe(!0),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:R.usePasswordText})]})]}),n&&!I&&(0,Y.jsxs)(`p`,{className:`px-8 text-center text-sm text-muted-foreground`,children:[R.noAccountText,` `,(0,Y.jsx)(l,{href:n,className:`font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:underline`,children:R.signUpText})]})]})}var Cn=({href:e,className:t,children:n})=>(0,Y.jsx)(`a`,{href:e,className:t,children:n}),wn=()=>(0,Y.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`h-6 w-6`,"aria-hidden":`true`,children:[(0,Y.jsx)(`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`}),(0,Y.jsx)(`circle`,{cx:`9`,cy:`7`,r:`4`}),(0,Y.jsx)(`line`,{x1:`19`,y1:`8`,x2:`19`,y2:`14`}),(0,Y.jsx)(`line`,{x1:`22`,y1:`11`,x2:`16`,y2:`11`})]});function Tn({onSuccess:e,onVerificationRequired:t,onError:n,loginUrl:i=`/login`,title:a=`Create an account`,description:o=`Enter your information to get started`,icon:s,hideIcon:c=!1,linkComponent:l=Cn,labels:u={},errorMessages:d}){let{signUp:f,isLoading:p}=X(),[m,h]=(0,r.useState)(``),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(``),[S,C]=(0,r.useState)(null),[w,T]=(0,r.useState)(!1),E={nameLabel:u.nameLabel??`Name`,namePlaceholder:u.namePlaceholder??`John Doe`,emailLabel:u.emailLabel??`Email`,emailPlaceholder:u.emailPlaceholder??`name@example.com`,passwordLabel:u.passwordLabel??`Password`,passwordPlaceholder:u.passwordPlaceholder??`Create a password (min. 8 characters)`,confirmPasswordLabel:u.confirmPasswordLabel??`Confirm Password`,confirmPasswordPlaceholder:u.confirmPasswordPlaceholder??`Confirm your password`,passwordMismatchError:u.passwordMismatchError??`Passwords do not match`,passwordTooShortError:u.passwordTooShortError??`Password must be at least 8 characters`,submitButton:u.submitButton??`Create Account`,submittingButton:u.submittingButton??`Creating account…`,hasAccountText:u.hasAccountText??`Already have an account?`,signInText:u.signInText??`Sign in`,orText:u.orText??`or`};return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]`,children:[(0,Y.jsx)(_n,{icon:c?void 0:s??(0,Y.jsx)(wn,{}),title:a,description:o}),(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsx)(pn,{mode:`sign-up`,onProvidersResolved:e=>T(e)}),(0,Y.jsxs)(`form`,{onSubmit:async r=>{if(r.preventDefault(),C(null),v!==b){C(E.passwordMismatchError);return}if(v.length<8){C(E.passwordTooShortError);return}try{if((await f(m,g,v))?.requiresVerification){t?.(g);return}e?.()}catch(e){let t=e instanceof Error?e:Error(String(e)),r=t.code;C(r&&d?.[r]||t.message),n?.(t)}},className:`space-y-4`,children:[w&&(0,Y.jsx)(yn,{label:E.orText}),S&&(0,Y.jsx)(vn,{message:S}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`register-name`,className:Q,children:E.nameLabel}),(0,Y.jsx)(`input`,{id:`register-name`,type:`text`,placeholder:E.namePlaceholder,value:m,onChange:e=>h(e.target.value),required:!0,autoComplete:`name`,disabled:p,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`register-email`,className:Q,children:E.emailLabel}),(0,Y.jsx)(`input`,{id:`register-email`,type:`email`,placeholder:E.emailPlaceholder,value:g,onChange:e=>_(e.target.value),required:!0,autoComplete:`email`,disabled:p,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`register-password`,className:Q,children:E.passwordLabel}),(0,Y.jsx)(`input`,{id:`register-password`,type:`password`,placeholder:E.passwordPlaceholder,value:v,onChange:e=>y(e.target.value),required:!0,minLength:8,autoComplete:`new-password`,disabled:p,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`register-confirm-password`,className:Q,children:E.confirmPasswordLabel}),(0,Y.jsx)(`input`,{id:`register-confirm-password`,type:`password`,placeholder:E.confirmPasswordPlaceholder,value:b,onChange:e=>x(e.target.value),required:!0,minLength:8,autoComplete:`new-password`,disabled:p,className:Z})]}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:p,className:mn,children:[p&&(0,Y.jsx)($,{}),p?E.submittingButton:E.submitButton]})]})]}),i&&(0,Y.jsxs)(`p`,{className:`px-8 text-center text-sm text-muted-foreground`,children:[E.hasAccountText,` `,(0,Y.jsx)(l,{href:i,className:`font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:underline`,children:E.signInText})]})]})}var En=({href:e,className:t,children:n})=>(0,Y.jsx)(`a`,{href:e,className:t,children:n}),Dn=()=>(0,Y.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`h-6 w-6`,"aria-hidden":`true`,children:(0,Y.jsx)(`path`,{d:`M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4`})});function On({onSuccess:e,onError:t,loginUrl:n=`/login`,title:i=`Reset your password`,description:a=`Enter your email address and we'll send you a link to reset your password`,icon:o,hideIcon:s=!1,linkComponent:c=En,labels:l={}}){let{forgotPassword:u,isLoading:d,getAuthConfig:f,requestPhonePasswordReset:p,resetPasswordWithPhoneOtp:m}=X(),[h,g]=(0,r.useState)(``),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(`email`),[T,E]=(0,r.useState)(``),[D,O]=(0,r.useState)(``),[k,ee]=(0,r.useState)(``),[A,j]=(0,r.useState)(!1),[te,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(0),[ne,re]=(0,r.useState)(!1),[F,ie]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=!1;return Promise.resolve().then(()=>f()).then(t=>{e||S(t?.features?.phoneNumberOtp===!0)}).catch(()=>{}),()=>{e=!0}},[f]),(0,r.useEffect)(()=>{if(N<=0)return;let e=setTimeout(()=>P(e=>e>1?e-1:0),1e3);return()=>clearTimeout(e)},[N]);let I={emailLabel:l.emailLabel??`Email`,emailPlaceholder:l.emailPlaceholder??`name@example.com`,submitButton:l.submitButton??`Send Reset Link`,submittingButton:l.submittingButton??`Sending…`,successTitle:l.successTitle??`Check your email`,successDescription:l.successDescription??`We've sent a password reset link to {{email}}. Please check your inbox.`,backToSignInText:l.backToSignInText??`Back to sign in`,rememberPasswordText:l.rememberPasswordText??`Remember your password?`,signInText:l.signInText??`Sign in`,phoneLabel:l.phoneLabel??`Phone number`,phonePlaceholder:l.phonePlaceholder??`+1 555 000 0000`,otpCodeLabel:l.otpCodeLabel??`Verification code`,otpCodePlaceholder:l.otpCodePlaceholder??`6-digit code`,sendOtpButton:l.sendOtpButton??`Get code`,resendOtpCountdownText:l.resendOtpCountdownText??`Resend in {seconds}s`,newPasswordLabel:l.newPasswordLabel??`New password`,newPasswordPlaceholder:l.newPasswordPlaceholder??`Enter a new password`,resetButton:l.resetButton??`Reset Password`,usePhoneResetText:l.usePhoneResetText??`Reset via SMS code`,useEmailResetText:l.useEmailResetText??`Reset via email instead`,phoneSuccessTitle:l.phoneSuccessTitle??`Password reset`,phoneSuccessDescription:l.phoneSuccessDescription??`Your password has been reset. You can now sign in with your new password.`},ae=async n=>{n.preventDefault(),v(null);try{await u(h),b(!0),e?.()}catch(e){let n=e instanceof Error?e:Error(String(e));v(n.message),t?.(n)}},L=async()=>{if(!(!T.trim()||A||N>0)){v(null),j(!0);try{await p(T.trim()),M(!0),P(60)}catch(e){let n=e instanceof Error?e:Error(String(e));v(n.message),t?.(n)}finally{j(!1)}}},oe=async n=>{n.preventDefault(),v(null),ie(!0);try{await m(T.trim(),D.trim(),k),re(!0),e?.()}catch(e){let n=e instanceof Error?e:Error(String(e));v(n.message),t?.(n)}finally{ie(!1)}},se=e=>{w(e),v(null)};if(ne)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]`,children:[(0,Y.jsx)(_n,{icon:(0,Y.jsx)(`span`,{className:`flex h-12 w-12 items-center justify-center rounded-2xl bg-emerald-500/10 text-emerald-600 ring-1 ring-emerald-500/15 dark:text-emerald-400`,children:(0,Y.jsx)(gn,{})}),title:I.phoneSuccessTitle,description:I.phoneSuccessDescription}),n&&(0,Y.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:(0,Y.jsxs)(c,{href:n,className:`font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:underline`,children:[`← `,I.backToSignInText]})})]});if(y){let e=I.successDescription.includes(`{{email}}`)?I.successDescription.replace(`{{email}}`,h):`${I.successDescription} ${h}`;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]`,children:[(0,Y.jsx)(_n,{icon:(0,Y.jsx)(`span`,{className:`flex h-12 w-12 items-center justify-center rounded-2xl bg-emerald-500/10 text-emerald-600 ring-1 ring-emerald-500/15 dark:text-emerald-400`,children:(0,Y.jsx)(gn,{})}),title:I.successTitle,description:e}),n&&(0,Y.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:(0,Y.jsxs)(c,{href:n,className:`font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:underline`,children:[`← `,I.backToSignInText]})})]})}return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full flex-col justify-center space-y-7 sm:w-[400px]`,children:[(0,Y.jsx)(_n,{icon:s?void 0:o??(0,Y.jsx)(Dn,{}),title:i,description:a}),C===`phone`?(0,Y.jsxs)(`form`,{onSubmit:oe,className:`space-y-4`,children:[_&&(0,Y.jsx)(vn,{message:_}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`forgot-phone`,className:Q,children:I.phoneLabel}),(0,Y.jsx)(`input`,{id:`forgot-phone`,type:`tel`,placeholder:I.phonePlaceholder,value:T,onChange:e=>E(e.target.value),required:!0,autoComplete:`tel`,disabled:F,className:Z})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`forgot-otp`,className:Q,children:I.otpCodeLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{id:`forgot-otp`,type:`text`,inputMode:`numeric`,placeholder:I.otpCodePlaceholder,value:D,onChange:e=>O(e.target.value),required:!0,autoComplete:`one-time-code`,disabled:F,className:Z}),(0,Y.jsxs)(`button`,{type:`button`,onClick:L,disabled:A||N>0||!T.trim()||F,className:`shrink-0 rounded-md border border-input bg-background px-3 py-2 text-sm font-medium transition-colors hover:bg-accent disabled:opacity-50`,children:[A&&(0,Y.jsx)($,{}),N>0?I.resendOtpCountdownText.replace(`{seconds}`,String(N)):I.sendOtpButton]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`forgot-new-password`,className:Q,children:I.newPasswordLabel}),(0,Y.jsx)(`input`,{id:`forgot-new-password`,type:`password`,placeholder:I.newPasswordPlaceholder,value:k,onChange:e=>ee(e.target.value),required:!0,autoComplete:`new-password`,disabled:F,className:Z})]}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:F||!te,className:mn,children:[F&&(0,Y.jsx)($,{}),F?I.submittingButton:I.resetButton]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>se(`email`),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:I.useEmailResetText})]}):(0,Y.jsxs)(`form`,{onSubmit:ae,className:`space-y-4`,children:[_&&(0,Y.jsx)(vn,{message:_}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{htmlFor:`forgot-email`,className:Q,children:I.emailLabel}),(0,Y.jsx)(`input`,{id:`forgot-email`,type:`email`,placeholder:I.emailPlaceholder,value:h,onChange:e=>g(e.target.value),required:!0,autoComplete:`email`,disabled:d,className:Z})]}),(0,Y.jsxs)(`button`,{type:`submit`,disabled:d,className:mn,children:[d&&(0,Y.jsx)($,{}),d?I.submittingButton:I.submitButton]}),x&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>se(`phone`),className:`w-full text-center text-xs text-muted-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:I.usePhoneResetText})]}),n&&(0,Y.jsxs)(`p`,{className:`px-8 text-center text-sm text-muted-foreground`,children:[I.rememberPasswordText,` `,(0,Y.jsx)(c,{href:n,className:`font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:underline`,children:I.signInText})]})]})}function kn(e){return e?e.name?e.name.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2):e.email?.[0]?.toUpperCase()??`?`:`?`}function An(e){if(!e)return!1;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}var jn=[`apps`,`messages`,`validationMessages`,`dashboards`,`globalActions`];function Mn(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={};a.label&&(i.label=a.label),a.pluralLabel&&(i.pluralLabel=a.pluralLabel),a.description&&(i.description=a.description);for(let[e,t]of Object.entries(a))e.startsWith(`_`)&&(i[e]=t);if(t[e]=i,a.fields&&typeof a.fields==`object`){let t=Object.entries(a.fields);for(let[i,a]of t)a?.label&&(n[e]||(n[e]={}),n[e][i]=a.label),a?.options&&typeof a.options==`object`&&Object.keys(a.options).length>0&&(r[e]||(r[e]={}),r[e][i]=a.options)}}let a={};Object.keys(t).length>0&&(a.objects=t),Object.keys(n).length>0&&(a.fields=n),Object.keys(r).length>0&&(a.fieldOptions=r);for(let t of jn)e[t]!==void 0&&(a[t]=e[t]);let o=new Set([`objects`,...jn]);for(let[t,n]of Object.entries(e))o.has(t)||(a[t]=n);return{app:a}}var Nn=(0,r.createContext)(null);Nn.displayName=`PermissionContext`;var Pn=`/api/v1/auth/me/permissions`;function Fn({endpoint:e=Pn,initialPermissions:t,loadingFallback:n=null,errorFallback:i,children:a}){let[o,s]=(0,r.useState)(t??null),[c,l]=(0,r.useState)(null),[u,d]=(0,r.useState)(!t),f=(0,r.useCallback)(async()=>{d(!0),l(null);try{let t=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(`Permissions endpoint returned ${t.status}`);let n=await t.json();s(n)}catch(e){l(e instanceof Error?e:Error(String(e)))}finally{d(!1)}},[e]);(0,r.useEffect)(()=>{t||f()},[f,t]);let p=(0,r.useCallback)((e,t,n)=>{if(!o)return!1;let r=(e??``).toLowerCase(),i=`${r}.${t}`,a=o.fields?.[i]??o.fields?.[`${e}.${t}`];if(a)return n===`read`?a.readable!==!1:a.editable!==!1;let s=o.objects?.[r]??o.objects?.[e]??o.objects?.[`*`];return s?n===`read`?s.allowRead!==!1:s.allowEdit!==!1:!0},[o]),m=(0,r.useCallback)((e,t)=>{if(!o)return{allowed:!1,reason:`permissions-loading`};let n=o.objects?.[e]??o.objects?.[`*`],r={read:`allowRead`,view:`allowRead`,create:`allowCreate`,update:`allowEdit`,edit:`allowEdit`,delete:`allowDelete`}[t]??`allowRead`,i=n?n[r]!==!1:!0;return{allowed:i,reason:i?void 0:`denied-by-permission-set`}},[o]),h=(0,r.useCallback)(e=>{if(!o)return[];let t=`${e}.`,n=[];for(let[e,r]of Object.entries(o.fields??{})){if(!e.startsWith(t))continue;let i=e.slice(t.length);n.push({field:i,read:r.readable!==!1,write:r.editable!==!1})}return n},[o]),g=(0,r.useCallback)(()=>void 0,[]),_=(0,r.useMemo)(()=>({check:m,checkField:p,getFieldPermissions:h,getRowFilter:g,roles:o?.roles??[],systemPermissions:o?.systemPermissions??[],hasCapabilities:e=>{let t=new Set(o?.systemPermissions??[]);return e.every(e=>t.has(e))},isLoaded:!u&&!c&&o!==null}),[m,p,h,g,o,u,c]);return u&&!o?(0,Y.jsx)(Y.Fragment,{children:n}):c&&!o?i?(0,Y.jsx)(Y.Fragment,{children:i(c,f)}):(0,Y.jsx)(Y.Fragment,{children:n}):(0,Y.jsx)(Nn.Provider,{value:_,children:a})}function In(){let e=(0,r.useContext)(Nn);return(0,r.useMemo)(()=>e?{...e,can:(t,n)=>e.check(t,n).allowed,cannot:(t,n)=>!e.check(t,n).allowed}:{check:()=>({allowed:!0}),checkField:()=>!0,getFieldPermissions:()=>[],getRowFilter:()=>void 0,roles:[],systemPermissions:[],hasCapabilities:()=>!0,isLoaded:!1,can:()=>!0,cannot:()=>!1},[e])}function Ln(e){let{checkField:t,getFieldPermissions:n}=In(),i=(0,r.useMemo)(()=>n(e),[n,e]);return(0,r.useMemo)(()=>({permissions:i,canRead:n=>t(e,n,`read`),canWrite:n=>t(e,n,`write`),readableFields:n=>n.filter(n=>t(e,n,`read`)),writableFields:n=>n.filter(n=>t(e,n,`write`))}),[i,t,e])}export{Mn as a,Tn as c,cn as d,X as f,J as h,An as i,Sn as l,rn as m,In as n,kn as o,an as p,Fn as r,On as s,Ln as t,ln as u};
@@ -1,93 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{r as n,y as r}from"./vendor-react-BGDDiZfJ.js";import{Kt as i,Ut as a,Wt as o,ct as s,l as c,ot as l,q as u}from"./framework-CWU64Lvg.js";import{h as d}from"./vendor-objectstack-6Mgxtaa1.js";import{$o as f,Bs as p,Cr as m,Dr as h,Er as g,Fa as _,Fr as ee,Hs as te,Ki as v,M as y,Nc as ne,Oc as re,Pi as ie,Uo as ae,Va as oe,Vs as se,Wr as ce,_r as le,a as ue,as as de,br as fe,c as pe,f as b,fa as me,gr as x,ha as he,hr as ge,i as _e,jc as ve,ka as ye,kc as S,l as be,m as xe,mr as Se,o as Ce,p as we,vr as C,xr as Te,yr as w}from"./ui-components-DHIW7RSX.js";import{a as Ee,o as De}from"./plugins-views-Bf2gkCfN.js";var T=e(r(),1),Oe=1e3*60*60*24,ke=e=>e.toISOString().slice(0,10);function E(e,t){if(t.skipWeekends){let t=e.getUTCDay();if(t===0||t===6)return!1}return!(t.holidays&&t.holidays.has(ke(e)))}function D(e){let t=new Date(e);return t.setUTCHours(0,0,0,0),t}function O(e,t){let n=D(e);for(;!E(n,t);)n=new Date(n.getTime()+Oe);return n.getTime()}function k(e,t,n){if(t<=e)return 0;let r=0,i=D(e),a=D(t).getTime();for(;i.getTime()<a;)E(i,n)&&r++,i=new Date(i.getTime()+Oe);return r}function Ae(e,t,n){if(t<=0)return D(e).getTime();let r=D(e),i=t;for(;i>0;)E(r,n)&&i--,r=new Date(r.getTime()+Oe);return r.getTime()}function A(e,t,n){if(t<=0)return D(e).getTime();let r=D(e),i=t;for(;i>0;)r=new Date(r.getTime()-Oe),E(r,n)&&i--;return r.getTime()}var j=e=>String(e);function M(e){return e===`ss`||e===`ff`||e===`sf`?e:`fs`}function je(e){let t=new Set(e.map(e=>j(e.id))),n=[];for(let r of e){let e=j(r.id);for(let i of r.dependencies??[]){let r=typeof i==`object`&&!!i,a=r?i.id:i;if(a==null||a===``)continue;let o=j(a);o===e||!t.has(o)||n.push({pred:o,succ:e,type:M(r?i.type:void 0)})}}return n}function Me(e){let t=new Set;for(let n of e)n.parent!=null&&n.parent!==``&&t.add(j(n.parent));return t}function Ne(e,t){let n=new Map,r=new Map;for(let t of e)n.set(t,0),r.set(t,[]);for(let e of t)r.get(e.pred).push(e.succ),n.set(e.succ,(n.get(e.succ)??0)+1);let i=e.filter(e=>(n.get(e)??0)===0),a=[];for(;i.length;){let e=i.shift();a.push(e);for(let t of r.get(e)??[]){let e=(n.get(t)??0)-1;n.set(t,e),e===0&&i.push(t)}}if(a.length<e.length){let t=new Set(a);for(let n of e)t.has(n)||a.push(n);return{order:a,hasCycle:!0}}return{order:a,hasCycle:!1}}function Pe(e,t){let n={criticalIds:new Set,criticalEdges:new Set};if(!e.length)return n;let r=new Map;for(let n of e){let e=t?k(n.start.getTime(),n.end.getTime(),t):(n.end.getTime()-n.start.getTime())/Oe;r.set(j(n.id),Number.isFinite(e)&&e>0?e:0)}let i=je(e),a=e.map(e=>j(e.id)),{order:o,hasCycle:s}=Ne(a,i);if(s)return n;let c=new Map,l=new Map;for(let e of a)c.set(e,[]),l.set(e,[]);for(let e of i)c.get(e.succ).push(e),l.get(e.pred).push(e);let u=new Map,d=new Map;for(let e of o){let t=0;for(let n of c.get(e)??[])t=Math.max(t,d.get(n.pred)??0);u.set(e,t),d.set(e,t+(r.get(e)??0))}let f=Math.max(0,...a.map(e=>d.get(e)??0)),p=new Map,m=new Map;for(let e=o.length-1;e>=0;e--){let t=o[e],n=l.get(t)??[],i=f;n.length&&(i=Math.min(...n.map(e=>m.get(e.succ)??f))),p.set(t,i),m.set(t,i-(r.get(t)??0))}let h=1e-6,g=new Set;for(let e of a){let t=(m.get(e)??0)-(u.get(e)??0);Math.abs(t)<=h&&g.add(e)}let _=new Set;for(let e of i)_.add(e.pred),_.add(e.succ);for(let e of[...g])!_.has(e)&&(r.get(e)??0)===0&&g.delete(e);let ee=new Set;for(let e of i)!g.has(e.pred)||!g.has(e.succ)||Math.abs((d.get(e.pred)??0)-(u.get(e.succ)??0))<=h&&ee.add(`${e.pred}->${e.succ}`);return{criticalIds:g,criticalEdges:ee}}function Fe(e,t){if(!e.length)return[];let n=je(e),r=e.map(e=>j(e.id)),{order:i,hasCycle:a}=Ne(r,n);if(a)return[];let o=Me(e),s=new Map;for(let t of e)s.set(j(t.id),t);let c=new Map;for(let e of r)c.set(e,[]);for(let e of n)c.get(e.succ).push(e);let l=new Map,u=new Map;for(let t of e)l.set(j(t.id),t.start.getTime()),u.set(j(t.id),t.end.getTime());for(let e of i){let n=s.get(e);if(!n)continue;let r=t?k(l.get(e),u.get(e),t):u.get(e)-l.get(e),i=n.start.getTime();for(let n of c.get(e)??[]){let e=l.get(n.pred),a=u.get(n.pred),o;switch(n.type){case`ss`:o=e;break;case`ff`:o=t?A(a,r,t):a-r;break;case`sf`:o=t?A(e,r,t):e-r;break;default:o=a;break}o>i&&(i=o)}if(!o.has(e))if(t){let n=O(i,t);l.set(e,n),u.set(e,Ae(n,r,t))}else l.set(e,i),u.set(e,i+r)}let d=[];for(let t of e){let e=j(t.id);if(o.has(e))continue;let n=l.get(e),r=u.get(e);(n!==t.start.getTime()||r!==t.end.getTime())&&d.push({id:e,start:new Date(n),end:new Date(r)})}return d}var N=6e4;1440*N;var P=1440;function F(e){if(typeof e!=`string`)return null;let t=/^(\d{1,2}):(\d{2})$/.exec(e.trim());if(!t)return null;let n=Number(t[1]),r=Number(t[2]);return n<0||n>23||r<0||r>59?null:n*60+r}function Ie(e){if(!e||!Array.isArray(e.bands)||e.bands.length===0)return null;let t=F(e.dayStart)??0,n=[];for(let t=0;t<e.bands.length;t++){let r=e.bands[t],i=F(r.start),a=F(r.end);if(i==null||a==null||!r.label)return null;let o=(a-i+P)%P||P;n.push({key:r.key??`band${t}`,label:r.label,color:r.color,durMs:o*N})}return{dayStartMin:t,bands:n,showMidnight:e.showMidnight!==!1}}function Le(e,t){let n=new Date(e);return n.setHours(0,0,0,0),n.setMinutes(t),n.getTime()>e.getTime()&&n.setDate(n.getDate()-1),n}function Re(e,t){if(t.bands.length===0)return null;let n=Le(e,t.dayStartMin).getTime(),r=e.getTime()-n,i=0;for(let e of t.bands)if(i+=e.durMs,r<i)return e;return t.bands[t.bands.length-1]}var ze={"gantt.column.taskName":`Task Name`,"gantt.column.start":`Start`,"gantt.column.end":`End`,"gantt.toolbar.prevPeriod":`Previous period`,"gantt.toolbar.nextPeriod":`Next period`,"gantt.toolbar.zoomIn":`Zoom in`,"gantt.toolbar.zoomOut":`Zoom out`,"gantt.toolbar.jumpToToday":`Jump to today`,"gantt.toolbar.today":`Today`,"gantt.toolbar.thisWeek":`This week`,"gantt.toolbar.thisMonth":`This month`,"gantt.toolbar.exportPdf":`Export PDF`,"gantt.toolbar.saveLayout":`Save layout`,"gantt.toolbar.showTaskList":`Show task list`,"gantt.toolbar.hideTaskList":`Hide task list`,"gantt.toolbar.viewMode":`Timeline granularity`,"gantt.toolbar.enterFullscreen":`Enter fullscreen`,"gantt.toolbar.exitFullscreen":`Exit fullscreen`,"gantt.toolbar.criticalPath":`Highlight critical path`,"gantt.toolbar.autoSchedule":`Auto-schedule dependencies`,"gantt.toolbar.exportPng":`Export as PNG`,"gantt.toolbar.undo":`Undo`,"gantt.toolbar.redo":`Redo`,"gantt.viewMode.day":`Day`,"gantt.viewMode.week":`Week`,"gantt.viewMode.month":`Month`,"gantt.viewMode.quarter":`Quarter`,"gantt.viewMode.year":`Year`,"gantt.row.expand":`Expand`,"gantt.row.collapse":`Collapse`,"gantt.row.locate":`Locate on timeline`,"gantt.aria.taskList":`Task list`,"gantt.tooltip.days":`d`,"gantt.menu.view":`View details`,"gantt.menu.edit":`Edit inline`,"gantt.menu.delete":`Delete`,"gantt.menu.addPredecessor":`Add predecessor…`,"gantt.menu.addSuccessor":`Add successor…`,"gantt.menu.removeDependency":`Remove dependency`,"gantt.menu.noCandidates":`No available tasks`,"gantt.linkType.fs":`Finish → Start`,"gantt.linkType.ss":`Start → Start`,"gantt.linkType.ff":`Finish → Finish`,"gantt.linkType.sf":`Start → Finish`,"gantt.linkEnd.start":`start`,"gantt.linkEnd.end":`end`,"gantt.conflict.title":`Schedule conflict`,"gantt.conflict.body":`This move conflicts with dependency constraints. Auto-reschedule {count} affected task(s)?`,"gantt.conflict.confirm":`Auto-reschedule`,"gantt.conflict.cancel":`Keep as is`,"gantt.resource.header":`Resource`,"gantt.resource.peak":`Peak`,"gantt.resource.over":`overloaded`,"gantt.resource.empty":`No tasks to allocate.`,"gantt.readOnly":`Read-only`,"gantt.readOnlyHint":`Editing is disabled for this view.`};function Be(e,t){let n=ze[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}function Ve(){try{let e=c();return{t:(t,n)=>{let r=e.t(t,n);return typeof r==`string`&&r!==t?r:Be(t,n)},language:e.language}}catch{return{t:Be,language:void 0}}}var I=n();function He(e){return 110}function Ue(e){return e<640?140:e<1024?220:320}function We(e){return e>=280}function Ge(e){return e<640?32:40}var Ke=[`day`,`week`,`month`,`quarter`,`year`],qe={day:1,week:7,month:30.44,quarter:91.31,year:365.25},Je=1e3*60*60*24;function Ye(e,t){let n=new Date(e);return n.setHours(0,0,0,0),t===`week`?n.setDate(n.getDate()-(n.getDay()+6)%7):t===`month`?n.setDate(1):t===`quarter`?n.setMonth(Math.floor(n.getMonth()/3)*3,1):t===`year`&&n.setMonth(0,1),n}function Xe(e,t,n){let r=e.length-1,i=0;for(;i<r&&e[i+1]<t;)i++;let a=i;for(;a<r&&e[a]<n;)a++;return{start:i,end:a}}function Ze(e,t,n){let r=new Date(e);if(n===`day`)r.setDate(r.getDate()+t);else if(n===`week`)r.setDate(r.getDate()+t*7);else{let e=t*(n===`month`?1:n===`quarter`?3:12),i=r.getDate();r.setDate(1),r.setMonth(r.getMonth()+e);let a=new Date(r.getFullYear(),r.getMonth()+1,0).getDate();r.setDate(Math.min(i,a))}return r}function Qe(e,t,n,r=2){return new Promise(i=>{let a=new Blob([e],{type:`image/svg+xml;charset=utf-8`}),o=URL.createObjectURL(a),s=new Image;s.onload=()=>{let e=document.createElement(`canvas`);e.width=t*r,e.height=n*r;let a=e.getContext(`2d`);a&&(a.fillStyle=`#ffffff`,a.fillRect(0,0,e.width,e.height),a.scale(r,r),a.drawImage(s,0,0)),URL.revokeObjectURL(o),i(e)},s.onerror=()=>{URL.revokeObjectURL(o),i(null)},s.src=o})}function $e(e,t){let n=document.createElement(`a`);n.href=URL.createObjectURL(e),n.download=t,document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(n.href),1e3)}function et(e,t,n){let r=e=>{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t},i=`q ${t} 0 0 ${n} 0 0 cm /Im0 Do Q`,a=[],o=[],s=0,c=e=>{a.push(e),s+=e.length},l=()=>{o.push(s)};c(r(`%PDF-1.3
2
- %ÿÿÿÿ
3
- `)),l(),c(r(`1 0 obj
4
- << /Type /Catalog /Pages 2 0 R >>
5
- endobj
6
- `)),l(),c(r(`2 0 obj
7
- << /Type /Pages /Kids [3 0 R] /Count 1 >>
8
- endobj
9
- `)),l(),c(r(`3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${t} ${n}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>\nendobj\n`)),l(),c(r(`4 0 obj\n<< /Type /XObject /Subtype /Image /Width ${t} /Height ${n} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${e.length} >>\nstream\n`)),c(e),c(r(`
10
- endstream
11
- endobj
12
- `)),l(),c(r(`5 0 obj\n<< /Length ${i.length} >>\nstream\n${i}\nendstream\nendobj\n`));let u=s,d=`xref
13
- 0 6
14
- 0000000000 65535 f
15
- `;for(let e of o)d+=`${String(e).padStart(10,`0`)} 00000 n \n`;return d+=`trailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n${u}\n%%EOF\n`,c(r(d)),new Blob(a,{type:`application/pdf`})}function tt(e){let t=e.slice(e.indexOf(`,`)+1),n=atob(t),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}var nt=`gantt-layout:`;function rt(e){if(!e||typeof window>`u`)return null;try{let t=window.localStorage.getItem(nt+e);if(!t)return null;let n=JSON.parse(t),r=n.viewMode&&Ke.includes(n.viewMode)?n.viewMode:null;if(!r)return null;let i=typeof n.columnWidth==`number`&&isFinite(n.columnWidth)?n.columnWidth:null,a=typeof n.taskListWidth==`number`&&isFinite(n.taskListWidth)?n.taskListWidth:null;return{viewMode:r,columnWidth:i,taskListCollapsed:!!n.taskListCollapsed,taskListWidth:a}}catch{return null}}function it(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(nt+e,JSON.stringify(t))}catch{}}function L({tasks:e,viewMode:t,startDate:n,endDate:r,markers:i,onTaskClick:a,onTaskUpdate:o,onTaskDelete:s,onViewChange:c,onDependencyCreate:l,onDependencyDelete:u,onTaskReorder:d,className:ne,inlineEdit:le=!1,autoSchedule:ue=!1,rescheduleOnConflict:fe=!1,criticalPathDefault:pe=!1,workingCalendar:b,shiftSegments:x,showBaselines:ge=!0,readOnly:_e=!1,mobileReadOnly:ve=!1,groupBy:be,ungroupedLabel:xe=`Ungrouped`,defaultCollapsedDepth:Se,persistLayoutKey:Ce,onLayoutChange:we}){let{t:C,language:Te}=Ve(),w=Te||void 0,[Ee,De]=T.useState(new Date),Oe=T.useRef(null),{width:ke}=y(Oe),E=ke||(typeof window<`u`?window.innerWidth:1024),D=E<640,O=_e||ve&&D,k=O?void 0:o,Ae=O?void 0:s,A=O?void 0:l,j=O?void 0:u,M=O?void 0:d,je=O?!1:le,Me=O?!1:ue,Ne=O?!1:fe,N=Ge(E),P=He(E),F=T.useRef(void 0);F.current===void 0&&(F.current=rt(Ce));let Ie=F.current,[Re,ze]=T.useState(Ie?Ie.columnWidth:null),[Be,nt]=T.useState(Ie?Ie.taskListWidth??null:null),[L,at]=T.useState(t&&Ke.includes(t)?t:Ie?.viewMode??`day`);T.useEffect(()=>{t&&Ke.includes(t)&&at(t)},[t]);let ot=T.useRef(null),st=T.useRef(null),ct=T.useRef(!0),[R,lt]=T.useState(Ie?Ie.taskListCollapsed:!1),ut=T.useRef(!1);T.useEffect(()=>{!ut.current&&D&&(lt(!0),ut.current=!0)},[D]);let dt=Math.max(160,E-200),z=R?0:Be==null?Ue(E):Math.max(160,Math.min(Be,dt)),ft=T.useMemo(()=>{if(Re!=null||r||e.length===0)return null;let t=n?new Date(n):new Date(Math.min(...e.map(e=>e.start.getTime()))),i=new Date(Math.max(...e.map(e=>e.end.getTime())));n||t.setDate(t.getDate()-7),i.setDate(i.getDate()+14),t=Ye(t,L),i.setHours(23,59,59,999);let a=Math.max(1,(i.getTime()-t.getTime())/Je),o=Math.max(0,E-z);if(o<=0)return null;let s=o/a*qe[L];if(s<=P)return null;let c=Math.min(s,o*.6);return c>P?c:null},[Re,e,n,r,L,E,z,P]),B=Re??ft??P,pt=B/qe[L],mt=We(z),[ht,gt]=T.useState(null),[_t,vt]=T.useState({}),[yt,bt]=T.useState(null),V=T.useMemo(()=>{if(!be)return e;let t=new Set;for(let n of e){let e=n.parent!=null&&n.parent!==``?String(n.parent):null;e&&t.add(e)}let n=new Map;for(let r of e){if(t.has(String(r.id)))continue;let e=be(r),i=e?String(e.key):`__ungrouped__`,a=e?e.label:xe,o=n.get(i);o||(o={key:i,label:a,items:[]},n.set(i,o)),o.items.push(r)}let r=[];for(let e of n.values()){let t=`__group__${e.key}`,n=e.items[0];r.push({id:t,title:e.label,start:n.start,end:n.end,progress:0,type:`summary`,parent:null,data:{__group:!0}});for(let n of e.items)r.push({...n,parent:t})}return r},[be,e,xe]),xt=T.useMemo(()=>{let e=new Set(V.map(e=>String(e.id))),t=new Map;for(let n of V){let r=n.parent!=null&&n.parent!==``?String(n.parent):null;if(r&&r!==String(n.id)&&e.has(r)){let e=t.get(r);e?e.push(n):t.set(r,[n])}}return t},[V]),St=T.useMemo(()=>{let e=new Map;for(let t of V)e.set(String(t.id),t);return e},[V]),Ct=T.useCallback(e=>{let t=[],n=new Set,r=e=>{for(let i of xt.get(e)??[]){let e=String(i.id);n.has(e)||(n.add(e),t.push(i),r(e))}};return r(String(e)),t},[xt]),[H,wt]=T.useState(null),Tt=T.useRef(null);T.useEffect(()=>{Tt.current=H},[H]);let Et=T.useRef(!1),Dt=T.useCallback(e=>{let t=L===`day`&&x&&x.bands.length>0&&x?Math.min(...x.bands.map(e=>e.durMs)):Je,n=(e,t)=>wn.current?wn.current(e,t):Ze(e,t,L),r=new Date(e.originStart),i=new Date(e.originEnd);return e.mode===`move`?(r=n(e.originStart,e.unitDelta),i=new Date(e.originEnd.getTime()+(r.getTime()-e.originStart.getTime()))):e.mode===`resize-left`?(r=n(e.originStart,e.unitDelta),i.getTime()-r.getTime()<t&&(r=new Date(i.getTime()-t))):e.mode===`resize-right`&&(i=n(e.originEnd,e.unitDelta),i.getTime()-r.getTime()<t&&(i=new Date(r.getTime()+t))),{start:r,end:i}},[L,x]),Ot=T.useRef(e);Ot.current=e;let kt=T.useRef([]),At=T.useRef([]),[jt,Mt]=T.useState(0),Nt=T.useCallback(e=>{if(!k)return;let t=[];for(let{task:n,changes:r}of e){let e={},i={},a=!1;for(let t of Object.keys(r)){let o=r[t],s=n[t],c=o instanceof Date&&s instanceof Date?o.getTime()===s.getTime():o===s;e[t]=s,i[t]=o,c||(a=!0)}k(n,r),a&&t.push({taskId:String(n.id),before:e,after:i})}t.length&&(kt.current.push(t),At.current=[],Mt(e=>e+1))},[k]),[Pt,Ft]=T.useState(null),It=T.useCallback(e=>{if(!Ne)return;let t=new Map;for(let{task:n,changes:r}of e)t.set(String(n.id),{start:r.start??n.start,end:r.end??n.end});let n=Fe(Ot.current.map(e=>{let n=t.get(String(e.id));return n?{...e,start:n.start,end:n.end}:e}),b).filter(e=>{let n=t.get(e.id);return!n||e.start.getTime()!==n.start.getTime()||e.end.getTime()!==n.end.getTime()});n.length&&Ft(n)},[Ne,b]),Lt=T.useCallback(()=>{if(!Pt)return;let e=Pt.map(e=>{let t=Ot.current.find(t=>String(t.id)===e.id);return t?{task:t,changes:{start:e.start,end:e.end}}:null}).filter(Boolean);e.length&&Nt(e),Ft(null)},[Pt,Nt]),Rt=T.useCallback((e,t)=>{if(k)for(let n of e){let e=Ot.current.find(e=>String(e.id)===n.taskId);e&&k(e,t===`undo`?n.before:n.after)}},[k]),zt=T.useCallback(()=>{let e=kt.current.pop();e&&(Rt(e,`undo`),At.current.push(e),Mt(e=>e+1))},[Rt]),Bt=T.useCallback(()=>{let e=At.current.pop();e&&(Rt(e,`redo`),kt.current.push(e),Mt(e=>e+1))},[Rt]),{canUndo:Vt,canRedo:Ht}=T.useMemo(()=>({canUndo:kt.current.length>0,canRedo:At.current.length>0}),[jt]);T.useEffect(()=>{if(!H)return;let t=L===`day`&&x&&x.bands.length>0&&x?pt*Math.min(...x.bands.map(e=>e.durMs))/Je:B,n=e=>{let n=Tt.current;if(!n)return;let r=Math.round((e.clientX-n.originClientX)/Math.max(t,1));r!==n.unitDelta&&wt({...n,unitDelta:r})},r=()=>{let t=Tt.current;if(t){if(t.unitDelta!==0){let n=e.find(e=>e.id===t.taskId);if(n&&k){let{start:e,end:r}=Dt(t);if(t.group){let r=e.getTime()-t.originStart.getTime(),i=[n,...Ct(n.id)].map(e=>({task:e,changes:{start:new Date(e.start.getTime()+r),end:new Date(e.end.getTime()+r)}}));Nt(i),It(i)}else{let t=[{task:n,changes:{start:e,end:r}}];Nt(t),It(t)}}Et.current=!0,window.setTimeout(()=>{Et.current=!1},0)}wt(null)}};return window.addEventListener(`pointermove`,n),window.addEventListener(`pointerup`,r),window.addEventListener(`pointercancel`,r),()=>{window.removeEventListener(`pointermove`,n),window.removeEventListener(`pointerup`,r),window.removeEventListener(`pointercancel`,r)}},[H,B,pt,L,x,e,k,Dt,Ct,Nt,It]);let Ut=T.useCallback((e,t,n,r)=>{!k||e.data?.__group||(n.stopPropagation(),n.preventDefault(),wt({taskId:e.id,mode:t,group:r?.group??!1,originStart:new Date(r?.originStart??e.start),originEnd:new Date(r?.originEnd??e.end),originClientX:n.clientX,unitDelta:0}))},[k]),[Wt,Gt]=T.useState(null),Kt=T.useRef(null);T.useEffect(()=>{Kt.current=Wt},[Wt]),T.useEffect(()=>{if(!Wt)return;let t=e=>{let t=Kt.current;if(!t)return;let n=Math.min(100,Math.max(0,Math.round(t.originProgress+(e.clientX-t.originClientX)/Math.max(t.barWidth,1)*100)));n!==t.value&&Gt({...t,value:n})},n=()=>{let t=Kt.current;if(t){if(t.value!==t.originProgress){let n=e.find(e=>e.id===t.taskId);n&&k&&Nt([{task:n,changes:{progress:t.value}}]),Et.current=!0,window.setTimeout(()=>{Et.current=!1},0)}Gt(null)}};return window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n)}},[Wt,e,k,Nt]);let qt=T.useRef(null),[U,Jt]=T.useState(null),Yt=T.useRef(null);T.useEffect(()=>{Yt.current=U},[U]),T.useEffect(()=>{if(!U)return;let t=e=>{let t=qt.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,r=e.clientY-t.top;Jt(e=>e&&{...e,x:n,y:r})},n=()=>{let t=Yt.current;if(t&&t.targetId!=null&&String(t.targetId)!==String(t.sourceId)&&A){let n=e.find(e=>String(e.id)===String(t.sourceId)),r=e.find(e=>String(e.id)===String(t.targetId)),i=t.targetEnd??`start`,a=`${t.sourceEnd===`end`?`f`:`s`}${i===`end`?`f`:`s`}`;n&&r&&A(n,r,a)}Et.current=!0,window.setTimeout(()=>{Et.current=!1},0),Jt(null)};return window.addEventListener(`pointermove`,t),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,t),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n)}},[U,e,A]);let[Xt,Zt]=T.useState(null),Qt=T.useRef(null);T.useEffect(()=>{if(!Xt)return;let e=e=>{Qt.current&&e.target instanceof Node&&Qt.current.contains(e.target)||Zt(null)},t=e=>{e.key===`Escape`&&Zt(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[Xt]);let[W,$t]=T.useState(null),en=T.useRef(null);T.useEffect(()=>{if(!W)return;let e=e=>{en.current&&e.target instanceof Node&&en.current.contains(e.target)||$t(null)},t=e=>{e.key===`Escape`&&$t(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[W]);let[tn,nn]=T.useState(null),rn=T.useRef(null);T.useEffect(()=>{if(!tn)return;let e=e=>{rn.current&&e.target instanceof Node&&rn.current.contains(e.target)||nn(null)},t=e=>{e.key===`Escape`&&nn(null)};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,t)}},[tn]);let[an,on]=T.useState(null),sn=!!(a||k||A||Ae),cn=T.useCallback((e,t)=>{t.preventDefault(),t.stopPropagation(),on(e.id),sn&&Zt({x:t.clientX,y:t.clientY,taskId:e.id})},[sn]),ln=T.useCallback((e,t,n,r)=>{r.preventDefault(),r.stopPropagation(),!(!A&&!j)&&$t({x:r.clientX,y:r.clientY,sourceId:e,targetId:t,type:n})},[A,j]),[un,dn]=T.useState(()=>new Set),fn=T.useCallback(e=>{dn(t=>{let n=new Set(t),r=String(e);return n.has(r)?n.delete(r):n.add(r),n})},[]),pn=T.useRef(!1);T.useEffect(()=>{if(pn.current||Se==null||V.length===0)return;pn.current=!0;let e=new Map(V.map(e=>[String(e.id),e])),t=new Set;for(let n of V){let r=n.parent!=null&&n.parent!==``?String(n.parent):null;r&&r!==String(n.id)&&e.has(r)&&t.add(r)}let n=t=>{let n=0,r=new Set([String(t.id)]),i=t.parent!=null&&t.parent!==``?e.get(String(t.parent)):void 0;for(;i&&!r.has(String(i.id));)n+=1,r.add(String(i.id)),i=i.parent!=null&&i.parent!==``?e.get(String(i.parent)):void 0;return n},r=new Set;for(let e of V){let i=String(e.id);t.has(i)&&n(e)>=Se&&r.add(i)}r.size&&dn(e=>e.size?e:r)},[Se,V]);let G=T.useMemo(()=>{let e=new Set(V.map(e=>String(e.id))),t=new Map,n=[];for(let r of V){let i=r.parent!=null&&r.parent!==``?String(r.parent):null;if(i&&i!==String(r.id)&&e.has(i)){let e=t.get(i);e?e.push(r):t.set(i,[r])}else n.push(r)}let r=new Map,i=(e,n)=>{let a=String(e.id),o=r.get(a);if(o)return o;let s=t.get(a)??[],c;if(!s.length||n.has(a))c={start:e.start,end:e.end,progress:e.progress};else{n.add(a);let e=null,t=null,r=0,o=0;for(let a of s){let s=i(a,n);(!e||s.start<e)&&(e=s.start),(!t||s.end>t)&&(t=s.end);let c=Math.max(s.end.getTime()-s.start.getTime(),Je);r+=c*s.progress,o+=c}n.delete(a),c={start:e,end:t,progress:o?r/o:0}}return r.set(a,c),c},a=[],o=new Set,s=e=>{for(let n of t.get(String(e.id))??[])o.has(String(n.id))||(o.add(String(n.id)),s(n))},c=(e,n)=>{let r=String(e.id);if(o.has(r))return;o.add(r);let l=t.get(r)??[],u=l.length>0,d=u||e.type===`summary`,f=u?i(e,new Set):{start:e.start,end:e.end,progress:e.progress},p=!d&&(e.type===`milestone`||e.end.getTime()<=e.start.getTime());if(a.push({task:e,depth:n,hasChildren:u,isSummary:d,isMilestone:p,...f}),u)if(un.has(r))s(e);else for(let e of l)c(e,n+1)};for(let e of n)c(e,0);for(let e of V)o.has(String(e.id))||c(e,0);return a},[V,un]),mn=T.useCallback(e=>{if(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement)return;if((e.ctrlKey||e.metaKey)&&(e.key===`z`||e.key===`Z`)){e.preventDefault(),e.shiftKey?Bt():zt();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`Y`)){e.preventDefault(),Bt();return}if(!G.length)return;let t=an==null?-1:G.findIndex(e=>String(e.task.id)===String(an));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?Math.min(G.length-1,t+1):Math.max(0,t<=0?0:t-1);on(G[n].task.id);let r=X.current;if(r){let e=n*N;e<r.scrollTop?r.scrollTop=e:e+N>r.scrollTop+r.clientHeight&&(r.scrollTop=e+N-r.clientHeight)}return}if(t<0)return;let n=G[t];e.key===`Enter`?(e.preventDefault(),a?.(n.task)):e.key===`Delete`||e.key===`Backspace`?Ae&&(e.preventDefault(),Ae(n.task)):(e.key===`ArrowRight`&&n.hasChildren&&un.has(String(n.task.id))||e.key===`ArrowLeft`&&n.hasChildren&&!un.has(String(n.task.id)))&&(e.preventDefault(),fn(n.task.id))},[G,an,a,Ae,un,fn,N,zt,Bt]),K=T.useMemo(()=>{let t=n?new Date(n):new Date,i=r?new Date(r):new Date;return!n&&e.length>0&&(t=new Date(Math.min(...e.map(e=>e.start.getTime()))),t.setDate(t.getDate()-7)),!r&&e.length>0&&(i=new Date(Math.max(...e.map(e=>e.end.getTime()))),i.setDate(i.getDate()+14)),t=L===`day`&&x&&x.bands.length>0?Le(t,x.dayStartMin):Ye(t,L),i.setHours(23,59,59,999),{start:t,end:i}},[n,r,e,L,x]),hn=L===`day`&&!!x&&x.bands.length>0,gn=!hn&&L===`day`&&!!b&&(!!b.skipWeekends||!!(b.holidays&&b.holidays.size)),_n=T.useCallback(e=>{if(!b)return!0;if(b.skipWeekends){let t=e.getDay();if(t===0||t===6)return!1}if(b.holidays&&b.holidays.size){let t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;if(b.holidays.has(t))return!1}return!0},[b]),q=T.useMemo(()=>{let e=[];if(hn&&x){let t=new Date(K.start);for(;t<=K.end;)for(let n of x.bands){let r=n.durMs/Je*pt;e.push({date:new Date(t),label:n.label,isWeekend:!1,width:r,realMs:n.durMs,bandColor:n.color}),t=new Date(t.getTime()+n.durMs)}return e}let t=new Date(K.start);for(;t<=K.end;){let n=Ze(t,1,L);if(gn&&!_n(t)){t=n;continue}let r=(n.getTime()-t.getTime())/Je*pt,i,a;L===`day`?(i=String(t.getDate()),a=t.toLocaleDateString(w,{weekday:`narrow`})):i=L===`week`?t.toLocaleDateString(w,{month:`numeric`,day:`numeric`}):L===`month`?t.toLocaleDateString(w,{month:`short`}):L===`quarter`?`Q${Math.floor(t.getMonth()/3)+1}`:String(t.getFullYear()),e.push({date:new Date(t),label:i,sublabel:a,isWeekend:L===`day`&&(t.getDay()===0||t.getDay()===6),width:r}),t=n}return e},[K,L,pt,w,gn,_n,hn,x]),J=T.useMemo(()=>{let e=Array(q.length+1),t=0;for(let n=0;n<q.length;n++)e[n]=t,t+=q[n].width;return e[q.length]=t,e},[q]),vn=J[J.length-1],yn=T.useMemo(()=>q.map(e=>e.date.getTime()),[q]),bn=T.useMemo(()=>q.map(e=>e.realMs==null?Ze(e.date,1,L).getTime()-e.date.getTime():e.realMs),[q,L]),Y=T.useCallback(e=>{let t=q.length;if(t===0)return 0;let n=e.getTime(),r=0,i=t-1,a=0;for(;r<=i;){let e=r+i>>1;yn[e]<=n?(a=e,r=e+1):i=e-1}let o=bn[a]||864e5,s=(n-yn[a])/o;return(gn||hn)&&(s=Math.max(0,Math.min(s,1))),J[a]+s*q[a].width},[q,yn,bn,J,gn,hn]),xn=T.useCallback(e=>{let t=q.length;if(t===0)return new Date(K.start);let n=0,r=t-1,i=0;for(;n<=r;){let t=n+r>>1;J[t]<=e?(i=t,n=t+1):r=t-1}let a=q[i].width||1,o=(e-J[i])/a;return new Date(yn[i]+o*(bn[i]||864e5))},[q,yn,bn,J,K]),Sn=T.useCallback(e=>{let t=X.current;st.current==null&&t&&t.clientWidth>0&&(st.current=xn(t.scrollLeft)),ot.current=st.current,ct.current=!0,at(e),c?.(e)},[c,xn]);T.useLayoutEffect(()=>{let e=ot.current;if(e==null)return;ot.current=null;let t=X.current;if(!t||t.clientWidth===0)return;let n=Math.max(0,t.scrollWidth-t.clientWidth),r=Math.max(0,Math.min(Math.round(Y(Ye(e,L))),n));t.scrollLeft!==r&&(t.scrollLeft=r)},[L,Y]);let Cn=T.useCallback((e,t)=>{let n=q.length;if(n===0||t===0)return new Date(e);let r=e.getTime(),i=0,a=n-1,o=0;for(;i<=a;){let e=i+a>>1;yn[e]<=r?(o=e,i=e+1):a=e-1}let s=Math.min(n-1,Math.max(0,o+t)),c=r-yn[o];return new Date(yn[s]+c)},[q,yn]),wn=T.useRef(null);wn.current=gn||hn?Cn:null;let Tn=T.useMemo(()=>{let e=[];if(hn&&x){let t=0;for(let n of q){let r=String(Le(n.date,x.dayStartMin).getTime()),i=e[e.length-1];i&&i.key===r?i.width+=n.width:e.push({key:r,label:n.date.toLocaleDateString(w,{month:`short`,day:`numeric`}),width:n.width,offset:t}),t+=n.width}return e}let t=L===`year`?`decade`:L===`month`||L===`quarter`?`year`:`month`,n=0;for(let r of q){let i=r.date.getFullYear(),a=Math.floor(i/10)*10,o=t===`decade`?String(a):t===`year`?String(i):`${i}-${r.date.getMonth()}`,s=e[e.length-1];s&&s.key===o?s.width+=r.width:e.push({key:o,label:t===`decade`?`${a}s`:t===`year`?String(i):r.date.toLocaleDateString(w,{month:`short`,year:`numeric`}),width:r.width,offset:n}),n+=r.width}return e},[q,L,w,hn,x]),En=T.useMemo(()=>(i??[]).map((e,t)=>{let n=e.date instanceof Date?e.date:new Date(e.date);return{index:t,label:e.label,color:e.color||`hsl(var(--primary))`,left:Math.round(Y(n)),valid:!isNaN(n.getTime())&&n>=K.start&&n<=K.end}}).filter(e=>e.valid),[i,K,Y]),Dn=T.useRef(null),On=T.useRef(null),kn=T.useRef(null),X=T.useRef(null);T.useEffect(()=>{let e=X.current;if(!e)return;let t=()=>{ct.current=!1},n=new Set([`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `,`Spacebar`]),r=e=>{n.has(e.key)&&t()};return e.addEventListener(`wheel`,t,{passive:!0}),e.addEventListener(`touchstart`,t,{passive:!0}),e.addEventListener(`pointerdown`,t,{passive:!0}),e.addEventListener(`keydown`,r),()=>{e.removeEventListener(`wheel`,t),e.removeEventListener(`touchstart`,t),e.removeEventListener(`pointerdown`,t),e.removeEventListener(`keydown`,r)}},[]);let[An,jn]=T.useState(null),Mn=T.useRef([]),Nn=T.useRef(null),[Pn,Fn]=T.useState({top:0,left:0}),[In,Ln]=T.useState({width:4e3,height:600}),Rn=T.useCallback(()=>{let e=X.current;if(!e)return;let t=e.clientWidth||4e3,n=e.clientHeight||600;Ln(e=>e.width===t&&e.height===n?e:{width:t,height:n})},[]);T.useLayoutEffect(()=>{Rn();let e=X.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(Rn);return t.observe(e),()=>t.disconnect()},[Rn]);let zn=T.useMemo(()=>Xe(J,Pn.left-240,Pn.left+In.width+240),[J,Pn.left,In.width]),Bn=T.useMemo(()=>{let e=Tn.map(e=>e.offset);return e.push(vn),e},[Tn,vn]),Vn=T.useMemo(()=>Xe(Bn,Pn.left-240,Pn.left+In.width+240),[Bn,Pn.left,In.width]),Z=T.useMemo(()=>({startIdx:Math.max(0,Math.floor(Pn.top/N)-6),endIdx:Math.min(G.length,Math.ceil((Pn.top+In.height)/N)+6)}),[Pn.top,In.height,N,G.length]),Hn=G.length*N,[Un,Wn]=T.useState(!1);T.useEffect(()=>{let e=()=>Wn(!!document.fullscreenElement);return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[]);let Gn=T.useCallback(()=>{let e=Oe.current;e&&(document.fullscreenElement?document.exitFullscreen?.():e.requestFullscreen?.())},[]),Kn=T.useRef(null),qn=T.useCallback(e=>{if(e.touches.length===2){let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY;Kn.current={baseDistance:Math.max(1,Math.sqrt(t*t+n*n)),baseColumn:B}}},[B]),Jn=T.useCallback(e=>{if(e.touches.length!==2||!Kn.current)return;let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY,r=Math.max(1,Math.sqrt(t*t+n*n))/Kn.current.baseDistance,i=Math.max(15,Math.min(120,Math.round(Kn.current.baseColumn*r)));ze(i)},[]),Yn=T.useCallback(()=>{Kn.current=null},[]),Q=T.useMemo(()=>{let e=new Date;return e<K.start||e>K.end?null:Math.round(Y(e))},[K,Y]),Xn=T.useCallback(()=>{if(Q==null||!X.current)return;let e=Math.max(0,Q-X.current.clientWidth/2);X.current.scrollTo({left:e,behavior:`smooth`})},[Q]),Zn=T.useRef(!1);T.useEffect(()=>{if(Zn.current||e.length===0)return;let t=window.requestAnimationFrame(()=>{let t=X.current;if(!t||t.clientWidth===0)return;let n=Q;if(n==null){let t=new Date(Math.min(...e.map(e=>e.start.getTime())));n=Math.round(Y(t))}t.scrollLeft=Math.max(0,n-t.clientWidth/2),Zn.current=!0});return()=>window.cancelAnimationFrame(t)},[e,Q,Y]);let Qn=T.useCallback((e,t=`left`)=>{let n=X.current;if(!n||e<K.start||e>K.end)return!1;let r=Math.round(Y(e)),i=t===`center`?r-n.clientWidth/2:r-24;return n.scrollTo({left:Math.max(0,i),behavior:`smooth`}),!0},[K,Y]),$n=T.useCallback((e,t,n)=>{let r=X.current;if(!r)return;let i=Y(e),a=Y(t),o=Math.max(0,r.scrollWidth-r.clientWidth),s=Math.min(96,r.clientWidth*.15),c=a-i<=r.clientWidth-s?(i+a)/2-r.clientWidth/2:i-s,l=Math.max(0,Math.min(c,o));Mn.current.forEach(e=>window.clearTimeout(e)),Mn.current=[],Nn.current?.(),Nn.current=null,jn(null);let u=()=>{if(n==null)return;let e=window.requestAnimationFrame(()=>{jn(n),Mn.current.push(window.setTimeout(()=>jn(e=>e===n?null:e),1500))});Nn.current=()=>window.cancelAnimationFrame(e)},d=Math.abs(r.scrollLeft-l)>2;if(r.scrollTo({left:l,behavior:`smooth`}),!d){u();return}let f=`onscrollend`in r,p=!1,m=()=>{p||(p=!0,r.removeEventListener(`scrollend`,m),u())};r.addEventListener(`scrollend`,m),Mn.current.push(window.setTimeout(m,f?1500:500)),Nn.current=()=>r.removeEventListener(`scrollend`,m)},[Y]);T.useEffect(()=>()=>{Mn.current.forEach(e=>window.clearTimeout(e)),Nn.current?.()},[]);let er=T.useCallback(()=>Qn(Ye(new Date,`week`)),[Qn]),tr=T.useCallback(()=>Qn(Ye(new Date,`month`)),[Qn]),nr=e=>{let t=e.currentTarget;!ct.current&&t.clientWidth>0&&(st.current=xn(t.scrollLeft)),Dn.current&&(Dn.current.scrollLeft=t.scrollLeft),On.current&&On.current.scrollTop!==t.scrollTop&&(On.current.scrollTop=t.scrollTop),Fn(e=>e.top===t.scrollTop&&e.left===t.scrollLeft?e:{top:t.scrollTop,left:t.scrollLeft}),Rn()},rr=e=>{let t=e.currentTarget,n=X.current;n&&n.scrollTop!==t.scrollTop&&(n.scrollTop=t.scrollTop),Fn(e=>e.top===t.scrollTop?e:{...e,top:t.scrollTop})},ir=(e,t)=>{let n=Y(e),r=hn&&x?pt*Math.min(...x.bands.map(e=>e.durMs))/Je:pt;return{left:n,width:Math.max(Y(t)-n,r,3)}},ar=H?.group?H.taskId:null,or=T.useMemo(()=>{if(ar==null)return null;let e=new Set([String(ar)]);for(let t of Ct(ar))e.add(String(t.id));return e},[ar,Ct]),sr=T.useMemo(()=>{if(!H||H.group)return null;let e=new Set,t=new Set,n=St.get(String(H.taskId));for(;n&&n.parent!=null&&n.parent!==``;){let r=String(n.parent);if(t.has(r)||!St.has(r))break;t.add(r),e.add(r),n=St.get(r)}return e.size?e:null},[H,St]),cr=e=>{if(H){if(or?.has(String(e.task.id))){let t=Dt(H).start.getTime()-H.originStart.getTime();return ir(new Date(e.start.getTime()+t),new Date(e.end.getTime()+t))}if(!e.isSummary&&H.taskId===e.task.id){let e=Dt(H);return ir(e.start,e.end)}if(e.isSummary&&sr?.has(String(e.task.id))){let t=Dt(H),n=String(H.taskId),r=null,i=null;for(let a of Ct(e.task.id)){if((xt.get(String(a.id))??[]).length!==0)continue;let e=String(a.id)===n?t.start:a.start,o=String(a.id)===n?t.end:a.end;(!r||e<r)&&(r=e),(!i||o>i)&&(i=o)}if(r&&i)return ir(r,i)}}return ir(e.start,e.end)},lr=T.useMemo(()=>{let e=new Map;G.forEach((t,n)=>e.set(String(t.task.id),n));let t=[];return G.forEach(({task:n},r)=>{for(let i of n.dependencies??[]){let a=typeof i==`object`&&!!i,o=a?i.id:i;if(o==null||o===``)continue;let s=e.get(String(o));if(s==null||s===r)continue;let c=a?i.type:void 0,l=c===`ss`||c===`ff`||c===`sf`?c:`fs`;t.push({key:`${String(o)}->${String(n.id)}:${l}`,sourceId:o,targetId:n.id,type:l,sourceIndex:s,targetIndex:r})}}),t},[G]),ur=Math.max(2,Math.round(N/2)-14),dr=N-ur*2,fr=Math.round(dr/2),pr=Math.max(Math.round(N*.4),12),mr=pr*Math.SQRT2/2,hr=dr,gr=ur,_r=Math.max(3,Math.round(N*.13)),vr=N-_r-1,yr=`rgba(100, 116, 139, 0.35)`,br=`rgba(100, 116, 139, 0.6)`,xr=e=>{let t=G[e.sourceIndex],n=G[e.targetIndex];if(!t||!n)return null;let r=cr(t),i=cr(n),a=e=>e.isSummary?gr+hr/2:N/2,o=e.sourceIndex*N+a(t),s=e.targetIndex*N+a(n),c=e.type===`fs`||e.type===`ff`,l=e.type===`ff`||e.type===`sf`,u=t.isMilestone?r.left+(c?mr:-mr):c?r.left+r.width:r.left,d=n.isMilestone?i.left+(l?mr:-mr):l?i.left+i.width:i.left,f=u+(c?10:-10),p=d+(l?10:-10),m=Math.round,h=[`M ${m(u)} ${m(o)}`,`L ${m(f)} ${m(o)}`];if(l?f>=p:f<=p)h.push(`L ${m(f)} ${m(s)}`,`L ${m(d)} ${m(s)}`);else{let t=s>=o?(e.sourceIndex+1)*N:e.sourceIndex*N;h.push(`L ${m(f)} ${m(t)}`,`L ${m(p)} ${m(t)}`,`L ${m(p)} ${m(s)}`,`L ${m(d)} ${m(s)}`)}return h.join(` `)},Sr=H?.taskId??yt,[Cr,wr]=T.useState(pe),Tr=T.useMemo(()=>Cr?Pe(e,b):null,[Cr,e,b]),Er=T.useCallback(e=>Tr?.criticalIds.has(String(e))??!1,[Tr]),$=`#dc2626`,Dr=T.useCallback(()=>{if(!k)return;let t=Fe(e,b),n=[];for(let r of t){let t=e.find(e=>String(e.id)===r.id);t&&n.push({task:t,changes:{start:r.start,end:r.end}})}Nt(n)},[e,k,b,Nt]),Or=T.useCallback(()=>{if(typeof document>`u`||!e.length)return null;let t=e=>String(e).replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e]),n=Math.max(z,200),r=Math.ceil(n+vn),i=Math.ceil(36+G.length*N),a=Tr?.criticalEdges??null,o=[];o.push(`<rect x="0" y="0" width="${r}" height="${i}" fill="#ffffff"/>`),o.push(`<rect x="0" y="0" width="${r}" height="36" fill="#f8fafc"/>`),o.push(`<g transform="translate(${n},0)" font-family="sans-serif" font-size="10" fill="#475569">`),Tn.forEach(e=>{o.push(`<line x1="${e.offset.toFixed(1)}" y1="0" x2="${e.offset.toFixed(1)}" y2="36" stroke="#e2e8f0"/>`),o.push(`<text x="${(e.offset+e.width/2).toFixed(1)}" y="12" text-anchor="middle" font-weight="600">${t(e.label)}</text>`)}),q.forEach((e,n)=>{let r=J[n];o.push(`<line x1="${r.toFixed(1)}" y1="18" x2="${r.toFixed(1)}" y2="${i}" stroke="#eef2f7"/>`),o.push(`<text x="${(r+e.width/2).toFixed(1)}" y="30" text-anchor="middle" fill="#1f2937">${t(e.label)}</text>`)}),o.push(`</g>`),o.push(`<line x1="0" y1="18" x2="${r}" y2="18" stroke="#e2e8f0"/>`),o.push(`<line x1="0" y1="36" x2="${r}" y2="36" stroke="#cbd5e1"/>`),o.push(`<line x1="${n}" y1="0" x2="${n}" y2="${i}" stroke="#cbd5e1"/>`),o.push(`<g transform="translate(0,36)" font-family="sans-serif" font-size="11" fill="#1f2937">`),G.forEach((e,r)=>{let i=r*N;o.push(`<line x1="0" y1="${(i+N).toFixed(1)}" x2="${n}" y2="${(i+N).toFixed(1)}" stroke="#f1f5f9"/>`);let a=8+e.depth*14,s=Math.max(4,Math.floor((n-a)/6.5)),c=e.task.title.length>s?e.task.title.slice(0,s-1)+`…`:e.task.title,l=e.isSummary?` font-weight="600"`:``;o.push(`<text x="${a}" y="${(i+N/2+4).toFixed(1)}"${l}>${t(c)}</text>`)}),o.push(`</g>`),o.push(`<g transform="translate(${n},36)" font-family="sans-serif" font-size="9">`),G.forEach((e,t)=>{let n=t*N,{left:r,width:i}=ir(e.start,e.end),a=Er(e.task.id),s=a?` stroke="${$}" stroke-width="2"`:``;if(ge&&e.task.baselineStart&&e.task.baselineEnd){let t=ir(e.task.baselineStart,e.task.baselineEnd);o.push(`<rect x="${t.left.toFixed(1)}" y="${(n+vr).toFixed(1)}" width="${Math.max(2,t.width).toFixed(1)}" height="${_r}" rx="1" fill="${yr}" stroke="${br}"/>`)}if(e.isMilestone){let t=r,i=n+N/2,s=pr/2,c=a?$:e.task.color||`#3b82f6`;o.push(`<polygon points="${t},${i-s} ${t+s},${i} ${t},${i+s} ${t-s},${i}" fill="${c}"/>`)}else if(e.isSummary){let t=e.task.color||`#64748b`;o.push(`<rect x="${r.toFixed(1)}" y="${(n+gr).toFixed(1)}" width="${i.toFixed(1)}" height="${hr}" rx="3" fill="${t}"${s}/>`);let a=i*Math.min(100,Math.max(0,e.progress))/100;o.push(`<rect x="${r.toFixed(1)}" y="${(n+gr).toFixed(1)}" width="${a.toFixed(1)}" height="${hr}" rx="3" fill="rgba(0,0,0,0.2)"/>`)}else{let t=e.task.color||`#3b82f6`;o.push(`<rect x="${r.toFixed(1)}" y="${(n+ur).toFixed(1)}" width="${i.toFixed(1)}" height="${dr}" rx="3" fill="${t}"${s}/>`);let a=i*Math.min(100,Math.max(0,e.progress))/100;o.push(`<rect x="${r.toFixed(1)}" y="${(n+ur).toFixed(1)}" width="${a.toFixed(1)}" height="${dr}" rx="3" fill="rgba(0,0,0,0.18)"/>`),i>=24&&o.push(`<text x="${(r+i/2).toFixed(1)}" y="${(n+N/2+3).toFixed(1)}" text-anchor="middle" fill="#ffffff">${Math.round(e.progress)}%</text>`)}}),lr.forEach(e=>{let t=xr(e);if(!t)return;let n=a?.has(`${String(e.sourceId)}->${String(e.targetId)}`)??!1,r=n?$:`#94a3b8`;o.push(`<path d="${t}" fill="none" stroke="${r}" stroke-width="${n?2:1.5}"/>`)}),Q!=null&&o.push(`<line x1="${Q.toFixed(1)}" y1="0" x2="${Q.toFixed(1)}" y2="${G.length*N}" stroke="#ef4444" stroke-width="1.5"/>`);let s=G.length*N;return En.forEach(e=>{let n=/var\(/.test(e.color)?`#6366f1`:e.color;if(o.push(`<line x1="${e.left.toFixed(1)}" y1="0" x2="${e.left.toFixed(1)}" y2="${s}" stroke="${t(n)}" stroke-width="1.5"/>`),e.label){let r=e.label.length*6+8;o.push(`<rect x="${(e.left-r/2).toFixed(1)}" y="0" width="${r}" height="14" rx="2" fill="${t(n)}"/>`),o.push(`<text x="${e.left.toFixed(1)}" y="10" text-anchor="middle" font-size="9" font-weight="600" fill="#ffffff">${t(e.label)}</text>`)}}),o.push(`</g>`),{svg:`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${i}" viewBox="0 0 ${r} ${i}">${o.join(``)}</svg>`,W:r,H:i}},[e,G,lr,xr,ir,Er,Tr,q,J,vn,z,N,ur,dr,gr,hr,pr,Q,L,ge,vr,_r,yr,br,En,Tn]),kr=T.useCallback(async()=>{let e=Or();if(!e)return;let t=await Qe(e.svg,e.W,e.H);t&&t.toBlob(e=>{e&&$e(e,`gantt-${L}.png`)},`image/png`)},[Or,L]),Ar=T.useCallback(async()=>{let e=Or();if(!e)return;let t=await Qe(e.svg,e.W,e.H);t&&$e(et(tt(t.toDataURL(`image/jpeg`,.92)),t.width,t.height),`gantt-${L}.pdf`)},[Or,L]),[jr,Mr]=T.useState(!1),Nr=T.useCallback(()=>{let e={viewMode:L,columnWidth:Re,taskListCollapsed:R,taskListWidth:Be};Ce&&it(Ce,e),we?.(e),Mr(!0)},[L,Re,R,Be,Ce,we]);return T.useEffect(()=>{if(!jr)return;let e=setTimeout(()=>Mr(!1),1500);return()=>clearTimeout(e)},[jr]),(0,I.jsxs)(`div`,{ref:Oe,className:S(`flex flex-col h-full bg-background overflow-hidden min-w-0`,ne),"data-readonly":O?`true`:void 0,"data-mobile-readonly":ve&&D?`true`:void 0,children:[(0,I.jsx)(`style`,{children:`
16
- .gantt-resize-handle:hover { background-color: rgba(255, 255, 255, 0.4); }
17
- .gantt-bar-hover:hover { filter: brightness(1.1); }
18
- .gantt-locate-btn { opacity: 0; transition: opacity 0.15s ease; }
19
- .group\\/task-row:hover .gantt-locate-btn { opacity: 0.6; }
20
- .gantt-locate-btn:hover, .gantt-locate-btn:focus-visible { opacity: 1; }
21
- /* 定位闪烁: blink the located bar 3× with a thick ring + colored glow so
22
- it's hard to miss. The ring is an outline (not box-shadow) and the glow
23
- is a drop-shadow *filter* — both stay clear of the critical-path bar's
24
- inline box-shadow, which they'd otherwise clobber. */
25
- @keyframes gantt-flash {
26
- 0%, 25%, 50%, 100% {
27
- outline-color: rgba(37, 99, 235, 0);
28
- filter: drop-shadow(0 0 0 rgba(37, 99, 235, 0));
29
- }
30
- 12%, 37%, 62% {
31
- outline-color: rgba(37, 99, 235, 1);
32
- filter: drop-shadow(0 0 9px rgba(37, 99, 235, 0.9));
33
- }
34
- }
35
- .gantt-flash {
36
- outline: 3px solid transparent;
37
- outline-offset: 3px;
38
- border-radius: 2px;
39
- animation: gantt-flash 1.5s ease-in-out;
40
- }
41
- @media (min-width: 640px) {
42
- .gantt-sm-h50 { height: 50px; }
43
- .gantt-sm-w20 { width: 80px; }
44
- .gantt-sm-hidden { display: none; }
45
- }
46
- /* Persistent, grabbable timeline scrollbars. macOS (and iOS) default to
47
- overlay scrollbars that collapse to 0px and auto-hide, so the
48
- timeline's vertical scrollbar was nearly impossible to find. Defining
49
- ::-webkit-scrollbar opts this pane into a classic, always-visible bar
50
- regardless of the OS overlay preference. The thumb gets a min size so
51
- that with thousands of virtualized rows (scrollHeight in the hundreds
52
- of thousands of px) it never shrinks to an un-grabbable sliver. Scoped
53
- to the gantt pane so the host app's own scrollbars are untouched, and
54
- themed with neutral rgba (not theme utilities, which don't always
55
- reach a consuming app) so it's visible on any background. */
56
- /* Firefox (and any engine without ::-webkit-scrollbar) only: the
57
- standard props. We must NOT set these unconditionally — modern Chrome
58
- now honors scrollbar-width and, when it's present, IGNORES the
59
- ::-webkit-scrollbar rule below, falling back to the 0px auto-hiding
60
- overlay bar we're trying to replace. */
61
- @supports not selector(::-webkit-scrollbar) {
62
- [data-testid="gantt-timeline"] {
63
- scrollbar-width: thin;
64
- scrollbar-color: rgba(130,130,130,0.55) transparent;
65
- }
66
- }
67
- [data-testid="gantt-timeline"]::-webkit-scrollbar {
68
- width: 14px;
69
- height: 14px;
70
- }
71
- [data-testid="gantt-timeline"]::-webkit-scrollbar-track {
72
- background: transparent;
73
- }
74
- [data-testid="gantt-timeline"]::-webkit-scrollbar-thumb {
75
- background-color: rgba(130,130,130,0.55);
76
- border-radius: 8px;
77
- border: 3px solid transparent;
78
- background-clip: padding-box;
79
- min-height: 40px;
80
- min-width: 40px;
81
- }
82
- [data-testid="gantt-timeline"]::-webkit-scrollbar-thumb:hover {
83
- background-color: rgba(110,110,110,0.85);
84
- }
85
- [data-testid="gantt-timeline"]::-webkit-scrollbar-corner {
86
- background: transparent;
87
- }
88
- /* The task-list pane scrolls in lockstep with the timeline, so its own
89
- vertical scrollbar (butted against the divider) was a confusing second
90
- bar. Hide it — the pane stays wheel/drag-scrollable and synced. */
91
- .gantt-task-list::-webkit-scrollbar { width: 0; height: 0; }
92
- .gantt-task-list { scrollbar-width: none; }
93
- `}),(0,I.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 p-2 border-b bg-card`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":C(`gantt.toolbar.prevPeriod`),children:(0,I.jsx)(se,{className:`h-4 w-4`})}),(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":C(`gantt.toolbar.nextPeriod`),children:(0,I.jsx)(p,{className:`h-4 w-4`})}),(0,I.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:K.start.toLocaleDateString(w,{month:`long`,year:`numeric`})}),O&&(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground`,"data-testid":`gantt-readonly-badge`,title:C(`gantt.readOnlyHint`),children:[(0,I.jsx)(oe,{className:`h-3 w-3`}),C(`gantt.readOnly`)]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:`flex bg-muted rounded-md p-1`,role:`group`,"aria-label":C(`gantt.toolbar.viewMode`),children:Ke.map(e=>(0,I.jsx)(m,{variant:`ghost`,size:`sm`,className:S(`h-6 px-1.5 sm:px-2 text-xs`,L===e&&`bg-background shadow-sm hover:bg-background`),onClick:()=>Sn(e),"aria-pressed":L===e,"data-testid":`gantt-view-mode-${e}`,children:C(`gantt.viewMode.${e}`)},e))}),(0,I.jsxs)(`div`,{className:`flex bg-muted rounded-md p-1`,children:[(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>{if(B>15)ze(Math.max(15,B-10));else{let e=Ke.indexOf(L);e<Ke.length-1&&(Sn(Ke[e+1]),ze(P))}},"aria-label":C(`gantt.toolbar.zoomOut`),children:(0,I.jsx)(g,{className:`h-3 w-3`})}),(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>{if(B<120)ze(Math.min(120,B+10));else{let e=Ke.indexOf(L);e>0&&(Sn(Ke[e-1]),ze(P))}},"aria-label":C(`gantt.toolbar.zoomIn`),children:(0,I.jsx)(h,{className:`h-3 w-3`})})]}),(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>lt(e=>!e),"aria-label":C(R?`gantt.toolbar.showTaskList`:`gantt.toolbar.hideTaskList`),"aria-pressed":R,"data-testid":`gantt-toggle-task-list`,children:R?(0,I.jsx)(me,{className:`h-4 w-4`}):(0,I.jsx)(he,{className:`h-4 w-4`})}),(0,I.jsx)(m,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:Xn,disabled:Q==null,"aria-label":C(`gantt.toolbar.jumpToToday`),"data-testid":`gantt-jump-today`,children:C(`gantt.toolbar.today`)}),(0,I.jsx)(m,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:er,"aria-label":C(`gantt.toolbar.thisWeek`),"data-testid":`gantt-jump-week`,children:C(`gantt.toolbar.thisWeek`)}),(0,I.jsx)(m,{variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:tr,"aria-label":C(`gantt.toolbar.thisMonth`),"data-testid":`gantt-jump-month`,children:C(`gantt.toolbar.thisMonth`)}),k?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:zt,disabled:!Vt,"aria-label":C(`gantt.toolbar.undo`),"data-testid":`gantt-undo`,children:(0,I.jsx)(ce,{className:`h-4 w-4`})}),(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Bt,disabled:!Ht,"aria-label":C(`gantt.toolbar.redo`),"data-testid":`gantt-redo`,children:(0,I.jsx)(v,{className:`h-4 w-4`})})]}):null,(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>wr(e=>!e),"aria-label":C(`gantt.toolbar.criticalPath`),"aria-pressed":Cr,"data-testid":`gantt-critical-path`,style:Cr?{color:$}:void 0,children:(0,I.jsx)(re,{className:`h-4 w-4`})}),Me&&k?(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Dr,"aria-label":C(`gantt.toolbar.autoSchedule`),"data-testid":`gantt-auto-schedule`,children:(0,I.jsx)(ee,{className:`h-4 w-4`})}):null,(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:kr,"aria-label":C(`gantt.toolbar.exportPng`),"data-testid":`gantt-export-png`,children:(0,I.jsx)(f,{className:`h-4 w-4`})}),(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Ar,"aria-label":C(`gantt.toolbar.exportPdf`),"data-testid":`gantt-export-pdf`,children:(0,I.jsx)(ae,{className:`h-4 w-4`})}),we||Ce?(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Nr,"aria-label":C(`gantt.toolbar.saveLayout`),"aria-pressed":jr,"data-testid":`gantt-save-layout`,style:jr?{color:$}:void 0,children:(0,I.jsx)(ie,{className:`h-4 w-4`})}):null,(0,I.jsx)(m,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:Gn,"aria-label":C(Un?`gantt.toolbar.exitFullscreen`:`gantt.toolbar.enterFullscreen`),"aria-pressed":Un,"data-testid":`gantt-fullscreen`,children:Un?(0,I.jsx)(ye,{className:`h-4 w-4`}):(0,I.jsx)(_,{className:`h-4 w-4`})})]})]}),(0,I.jsxs)(`div`,{className:`relative flex flex-col flex-1 overflow-hidden outline-none focus-visible:ring-1 focus-visible:ring-ring`,tabIndex:0,onKeyDown:mn,"data-testid":`gantt-body`,children:[!R&&z>0&&(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0 z-30 group/splitter`,style:{left:z-3,width:7,cursor:`col-resize`},"data-testid":`gantt-list-resize`,role:`separator`,"aria-orientation":`vertical`,onPointerDown:e=>{if(e.button!==0)return;e.preventDefault();let t=e.clientX,n=z,r=Math.max(160,E-200),i=e=>{let i=Math.max(160,Math.min(n+(e.clientX-t),r));nt(i)},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a),document.body.style.cursor=``};document.body.style.cursor=`col-resize`,window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},onDoubleClick:()=>nt(null),children:(0,I.jsx)(`div`,{className:`absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover/splitter:w-[3px] group-hover/splitter:bg-primary transition-all`})}),(0,I.jsxs)(`div`,{className:`flex border-b bg-muted/30 shrink-0 h-10 gantt-sm-h50`,children:[(0,I.jsxs)(`div`,{className:`flex items-center font-medium text-xs text-muted-foreground px-2 sm:px-4 border-r bg-card z-20 shadow-sm`,style:{width:z,minWidth:z},children:[(0,I.jsx)(`div`,{className:`flex-1 truncate`,children:C(`gantt.column.taskName`)}),mt&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right`,children:C(`gantt.column.start`)}),(0,I.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right`,children:C(`gantt.column.end`)})]})]}),(0,I.jsx)(`div`,{className:`flex-1 overflow-hidden`,ref:Dn,children:(0,I.jsxs)(`div`,{className:`flex flex-col h-full`,style:{width:vn},children:[(0,I.jsx)(`div`,{className:`relative border-b`,style:{height:`45%`},"data-testid":`gantt-header-groups`,children:Tn.slice(Vn.start,Vn.end).map(e=>(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0 flex items-center justify-center border-r text-[10px] font-medium text-muted-foreground overflow-hidden`,style:{left:e.offset,width:e.width},children:(0,I.jsx)(`span`,{className:`truncate px-1`,children:e.label})},e.key))}),(0,I.jsx)(`div`,{className:`relative flex-1`,"data-testid":`gantt-header-units`,children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t;return(0,I.jsxs)(`div`,{className:S(`absolute top-0 bottom-0 flex items-center justify-center gap-1 border-r text-xs text-muted-foreground overflow-hidden`,e.isWeekend&&`bg-muted/50`),style:{left:J[n],width:e.width,backgroundColor:e.bandColor?`color-mix(in srgb, ${e.bandColor} 16%, transparent)`:void 0},children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground truncate`,children:e.label}),e.sublabel&&B>=32&&(0,I.jsx)(`span`,{className:`text-[10px] opacity-70`,children:e.sublabel})]},n)})})]})})]}),(0,I.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,I.jsxs)(`div`,{className:`gantt-task-list overflow-y-auto overflow-x-hidden border-r bg-card z-10 shadow-sm`,ref:On,onScroll:rr,style:{width:z,minWidth:z},role:`tree`,"aria-label":C(`gantt.aria.taskList`),children:[Z.startIdx>0&&(0,I.jsx)(`div`,{style:{height:Z.startIdx*N},"aria-hidden":`true`}),G.slice(Z.startIdx,Z.endIdx).map(e=>{let t=e.task,n=je&&ht===t.id,r=un.has(String(t.id)),i=an!=null&&String(an)===String(t.id);return(0,I.jsxs)(`div`,{className:S(`group/task-row relative flex items-center border-b px-2 sm:px-4 hover:bg-accent/50 cursor-pointer transition-colors`,i&&`bg-accent/50`),style:{height:N,touchAction:`manipulation`},role:`treeitem`,"aria-level":e.depth+1,"aria-selected":i,"aria-expanded":e.hasChildren?!r:void 0,draggable:!!M&&!n&&!t.locked,onDragStart:M?e=>{e.dataTransfer.setData(`text/plain`,String(t.id)),e.dataTransfer.effectAllowed=`move`}:void 0,onDragOver:M?e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`}:void 0,onDrop:M?e=>{e.preventDefault();let n=e.dataTransfer.getData(`text/plain`);if(!n||n===String(t.id))return;let r=St.get(n);r&&String(r.parent??``)===String(t.parent??``)&&M(r,t)}:void 0,onContextMenu:e=>cn(t,e),onClick:()=>{on(t.id),n||a?.(t)},onDoubleClick:()=>{je&&k&&!e.isSummary&&!t.locked&&(gt(t.id),vt({title:t.title,start:t.start.toLocaleDateString(`en-CA`),end:t.end.toLocaleDateString(`en-CA`),progress:String(t.progress)}))},children:[(0,I.jsxs)(`div`,{className:`flex-1 truncate font-medium text-xs sm:text-sm flex items-center gap-2`,style:e.depth>0?{paddingLeft:e.depth*14}:void 0,children:[e.hasChildren?(0,I.jsx)(`button`,{type:`button`,className:`h-4 w-4 shrink-0 flex items-center justify-center text-muted-foreground hover:text-foreground`,style:{marginLeft:-4},onClick:e=>{e.stopPropagation(),fn(t.id)},"aria-expanded":!r,"aria-label":C(r?`gantt.row.expand`:`gantt.row.collapse`),"data-testid":`gantt-row-toggle-${t.id}`,children:r?(0,I.jsx)(p,{className:`h-3.5 w-3.5`}):(0,I.jsx)(te,{className:`h-3.5 w-3.5`})}):(0,I.jsx)(`span`,{className:`w-3 shrink-0`,style:{marginLeft:-4},"aria-hidden":`true`}),(0,I.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0`,style:{backgroundColor:t.color||`#3b82f6`}}),n?(0,I.jsx)(`input`,{className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.title||``,onChange:e=>vt(t=>({...t,title:e.target.value})),onKeyDown:e=>{e.key===`Enter`?(Nt([{task:t,changes:{title:_t.title,start:new Date(_t.start),end:new Date(_t.end),progress:Number(_t.progress)||0}}]),gt(null)):e.key===`Escape`&&gt(null)},onClick:e=>e.stopPropagation(),autoFocus:!0}):(0,I.jsxs)(`span`,{className:`flex flex-col min-w-0`,children:[(0,I.jsx)(`span`,{className:S(`truncate`,e.isSummary&&`font-semibold`),children:t.title}),(0,I.jsxs)(`span`,{className:`text-[10px] text-muted-foreground gantt-sm-hidden`,children:[e.start.toLocaleDateString(w,{month:`numeric`,day:`numeric`}),` → `,e.end.toLocaleDateString(w,{month:`numeric`,day:`numeric`})]})]})]}),(0,I.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right text-xs text-muted-foreground hidden sm:block`,hidden:!mt,style:mt?void 0:{display:`none`},children:n?(0,I.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.start||``,onChange:e=>vt(t=>({...t,start:e.target.value})),onClick:e=>e.stopPropagation()}):e.start.toLocaleDateString(w,{month:`numeric`,day:`numeric`})}),(0,I.jsx)(`div`,{className:`w-16 gantt-sm-w20 text-right text-xs text-muted-foreground hidden sm:block`,hidden:!mt,style:mt?void 0:{display:`none`},children:n?(0,I.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:_t.end||``,onChange:e=>vt(t=>({...t,end:e.target.value})),onClick:e=>e.stopPropagation()}):e.end.toLocaleDateString(w,{month:`numeric`,day:`numeric`})}),!n&&(0,I.jsx)(`button`,{type:`button`,title:C(`gantt.row.locate`),"aria-label":C(`gantt.row.locate`),className:`gantt-locate-btn hidden sm:block absolute top-1/2 -translate-y-1/2`,style:{right:1},onClick:t=>{t.stopPropagation(),$n(e.start,e.end,e.task.id)},children:(0,I.jsx)(de,{className:`w-3 h-3`})})]},t.id)}),Z.endIdx<G.length&&(0,I.jsx)(`div`,{style:{height:(G.length-Z.endIdx)*N},"aria-hidden":`true`})]}),(0,I.jsx)(`div`,{className:`flex-1 overflow-auto bg-background/50 relative [-webkit-overflow-scrolling:touch]`,ref:e=>{kn.current=e,X.current=e},onScroll:nr,onTouchStart:qn,onTouchMove:Jn,onTouchEnd:Yn,"data-testid":`gantt-timeline`,children:(0,I.jsxs)(`div`,{className:`relative`,style:{width:vn},children:[Q!=null&&(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px z-20 pointer-events-none`,style:{left:Q,backgroundColor:`rgba(239, 68, 68, 0.8)`},"data-testid":`gantt-today-marker`,"aria-label":C(`gantt.toolbar.today`),children:(0,I.jsx)(`div`,{className:`absolute -translate-x-1/2 left-0 text-[10px] font-semibold text-white rounded-sm px-1 py-0.5 whitespace-nowrap z-30`,style:{top:2,backgroundColor:`#ef4444`},children:C(`gantt.toolbar.today`)})}),En.map(e=>(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px z-20 pointer-events-none`,style:{left:e.left,backgroundColor:e.color},"data-testid":`gantt-marker-${e.index}`,"aria-label":e.label,children:e.label&&(0,I.jsx)(`div`,{className:`absolute -translate-x-1/2 left-0 text-[10px] font-semibold text-white rounded-sm px-1 py-0.5 whitespace-nowrap z-30`,style:{top:2,backgroundColor:e.color},children:e.label})},e.index)),(0,I.jsxs)(`div`,{className:`relative`,ref:qt,children:[(0,I.jsx)(`div`,{className:`absolute inset-0 pointer-events-none`,style:{zIndex:0},children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t;return(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0 border-r`,style:{left:J[n],width:e.width,backgroundColor:e.bandColor?`color-mix(in srgb, ${e.bandColor} 8%, transparent)`:e.isWeekend?`hsl(var(--muted) / 0.4)`:void 0}},n)})}),hn&&x&&x.showMidnight&&(0,I.jsx)(`div`,{className:`absolute inset-0 pointer-events-none`,style:{zIndex:0},children:q.slice(zn.start,zn.end).map((e,t)=>{let n=zn.start+t,r=e.realMs??0;if(!r)return null;let i=e.date.getTime(),a=e.date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate()+1,0,0,0,0).getTime();return o<=i||o>=i+r?null:(0,I.jsx)(`div`,{className:`absolute top-0 bottom-0`,style:{left:J[n]+(o-i)/r*e.width,borderLeft:`1px dashed hsl(var(--muted-foreground) / 0.4)`},"data-testid":`gantt-midnight-${n}`,"aria-hidden":`true`},`midnight-${n}`)})}),Z.startIdx>0&&(0,I.jsx)(`div`,{style:{height:Z.startIdx*N},"aria-hidden":`true`}),G.slice(Z.startIdx,Z.endIdx).map(e=>{let t=e.task,n=Er(t.id),r=ir(e.start,e.end),i=ge&&t.baselineStart&&t.baselineEnd?ir(t.baselineStart,t.baselineEnd):null,a=i?(0,I.jsx)(`div`,{className:`absolute pointer-events-none rounded-[1px]`,style:{left:i.left,width:Math.max(2,i.width),top:vr,height:_r,backgroundColor:yr,border:`1px solid ${br}`},"data-testid":`gantt-baseline-${t.id}`,"aria-hidden":`true`}):null,o=H?.taskId===t.id,s=or?.has(String(t.id))??!1,c=sr?.has(String(t.id))??!1,l=o||s||c?cr(e):r,u=!!t.locked,d=!!k&&!e.isSummary&&!u,f=U!=null&&U.targetId!=null&&String(U.targetId)===String(t.id)&&String(U.sourceId)!==String(t.id),p=U?e=>{let n=e.currentTarget.getBoundingClientRect(),r=n.width>0&&e.clientX-n.left>n.width/2?`end`:`start`;Jt(e=>e&&String(e.sourceId)!==String(t.id)?{...e,targetId:t.id,targetEnd:r}:e)}:void 0,m=U?e=>{e.target===e.currentTarget&&Jt(e=>e&&{...e,targetId:null,targetEnd:null})}:void 0,h=Math.max(1,Math.round((e.end.getTime()-e.start.getTime())/Je)),g=yt===t.id&&!H&&!Wt&&!U?(0,I.jsxs)(`div`,{className:`absolute z-30 pointer-events-none rounded-md border bg-popover text-popover-foreground px-2.5 py-1.5 text-xs shadow-md whitespace-nowrap`,style:{left:Math.max(l.left+8,4),top:N-8},role:`tooltip`,"data-testid":`gantt-tooltip-${t.id}`,children:[(0,I.jsx)(`div`,{className:`font-semibold`,children:t.title}),t.fields&&t.fields.length>0?(0,I.jsx)(`div`,{style:{display:`grid`,gridTemplateColumns:`auto 1fr`,columnGap:10,rowGap:2,marginTop:4},children:t.fields.map((e,t)=>(0,I.jsxs)(T.Fragment,{children:[(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,I.jsx)(`span`,{style:{fontWeight:500},children:e.value})]},t))}):(0,I.jsxs)(`div`,{className:`text-muted-foreground`,children:[e.start.toLocaleDateString(w,{month:`short`,day:`numeric`}),` → `,e.end.toLocaleDateString(w,{month:`short`,day:`numeric`}),` · `,h,C(`gantt.tooltip.days`),` · `,Math.round(e.progress),`%`]})]}):null;if(t.type===`group`)return(0,I.jsx)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:N},onPointerMove:m,children:g},t.id);if(e.isSummary){let r=t.color||`#0d9488`;return(0,I.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:N},onPointerMove:m,children:[a,(0,I.jsxs)(`div`,{className:S(`gantt-bar-hover absolute rounded-sm border shadow-sm flex items-center px-2 select-none`,k?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o&&`ring-2 ring-primary z-10`,An===t.id&&`gantt-flash z-10`),style:{left:l.left,width:l.width,top:gr,height:hr,backgroundColor:r,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-summary-bar-${t.id}`,"data-progress":Math.round(e.progress),onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),onPointerDown:n=>{n.button===0&&Ut(t,`move`,n,{group:!0,originStart:e.start,originEnd:e.end})},onClick:()=>{Et.current||on(t.id)},onContextMenu:e=>cn(t,e),children:[(0,I.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 pointer-events-none`,style:{width:`${Math.round(e.progress)}%`,backgroundColor:`rgba(0, 0, 0, 0.2)`,borderTopLeftRadius:`var(--radius-sm)`,borderBottomLeftRadius:`var(--radius-sm)`}}),(0,I.jsx)(`span`,{className:`relative text-[10px] text-white font-medium truncate pointer-events-none`,children:t.title})]}),o&&H&&(0,I.jsxs)(`div`,{className:`absolute z-30 pointer-events-none rounded border bg-popover text-popover-foreground px-1.5 py-0.5 text-[10px] shadow whitespace-nowrap`,style:{left:Math.max(l.left,4),top:gr+hr+2},"data-testid":`gantt-summary-drag-chip-${t.id}`,children:[Dt(H).start.toLocaleDateString(w,{month:`numeric`,day:`numeric`}),` → `,Dt(H).end.toLocaleDateString(w,{month:`numeric`,day:`numeric`})]}),g]},t.id)}if(e.isMilestone){let e=pr;return(0,I.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:N},onPointerMove:m,children:[a,(0,I.jsx)(`div`,{className:S(`gantt-bar-hover absolute rotate-45 rounded-[2px] border shadow-sm select-none`,d?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o&&`ring-2 ring-primary z-10`,f&&`ring-2 ring-primary`,An===t.id&&`gantt-flash z-10`),style:{left:l.left-e/2,top:(N-e)/2,width:e,height:e,backgroundColor:n?$:t.color||`#3b82f6`,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-milestone-${t.id}`,onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),onClick:()=>{Et.current||on(t.id)},onContextMenu:e=>cn(t,e),onPointerMove:p,onPointerDown:d?e=>{e.button===0&&Ut(t,`move`,e)}:void 0}),g]},t.id)}let _=Wt&&Wt.taskId===t.id?Wt.value:t.progress;return(0,I.jsxs)(`div`,{className:`relative border-b hover:bg-accent/50`,style:{height:N},onPointerMove:m,onMouseEnter:()=>bt(t.id),onMouseLeave:()=>bt(e=>e===t.id?null:e),children:[o&&(0,I.jsx)(`div`,{className:`absolute rounded-sm border border-dashed pointer-events-none`,style:{left:r.left,width:r.width,top:ur,height:dr,opacity:.35,borderColor:`hsl(var(--primary) / 0.6)`},"aria-hidden":`true`}),a,(0,I.jsxs)(`div`,{className:S(`gantt-bar-hover absolute rounded-sm bg-primary border shadow-sm flex items-center px-2 group select-none`,d?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o&&`ring-2 ring-primary z-10`,f&&`ring-2 ring-primary`,An===t.id&&`gantt-flash z-10`),style:{left:l.left,width:l.width,top:ur,height:dr,backgroundColor:t.color||`#3b82f6`,borderColor:n?$:`hsl(var(--primary-foreground) / 0.2)`,boxShadow:n?`0 0 0 2px ${$}`:void 0},"data-critical":n?`true`:void 0,"data-testid":`gantt-task-bar-${t.id}`,onClick:()=>{Et.current||on(t.id)},onContextMenu:e=>cn(t,e),onPointerMove:p,onPointerDown:d?e=>{e.button===0&&Ut(t,`move`,e)}:void 0,children:[d&&l.width>=14&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`gantt-resize-handle absolute left-0 top-0`,style:{width:6,height:fr,cursor:`ew-resize`},"data-testid":`gantt-task-resize-left-${t.id}`,onPointerDown:e=>{e.button===0&&Ut(t,`resize-left`,e)},onClick:e=>e.stopPropagation()}),(0,I.jsx)(`div`,{className:`gantt-resize-handle absolute right-0 top-0`,style:{width:6,height:fr,cursor:`ew-resize`},"data-testid":`gantt-task-resize-right-${t.id}`,onPointerDown:e=>{e.button===0&&Ut(t,`resize-right`,e)},onClick:e=>e.stopPropagation()})]}),_>0&&(0,I.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 pointer-events-none`,style:{width:`${_}%`,backgroundColor:`rgba(0, 0, 0, 0.2)`,borderTopLeftRadius:`var(--radius-sm)`,borderBottomLeftRadius:`var(--radius-sm)`}}),d&&l.width>=30&&(0,I.jsx)(`div`,{className:S(`absolute bottom-0 h-1/2 w-4 -translate-x-1/2 cursor-col-resize flex items-end justify-center pb-px`,Wt?.taskId===t.id?`opacity-100`:`opacity-0 group-hover:opacity-100 transition-opacity`),style:{left:`${_}%`},"data-testid":`gantt-progress-handle-${t.id}`,onPointerDown:e=>{e.button===0&&(e.stopPropagation(),e.preventDefault(),Gt({taskId:t.id,originClientX:e.clientX,originProgress:t.progress,barWidth:l.width,value:t.progress}))},onClick:e=>e.stopPropagation(),children:(0,I.jsx)(`div`,{style:{width:0,height:0,borderLeft:`5px solid transparent`,borderRight:`5px solid transparent`,borderBottom:`7px solid #fff`,filter:`drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35))`}})}),A&&!u&&[`start`,`end`].map(e=>{let n=U!=null&&String(U.sourceId)===String(t.id)&&U.sourceEnd===e,r=n||yt===t.id,i=r&&U==null;return(0,I.jsx)(`div`,{className:`absolute top-1/2 -translate-y-1/2 z-20 flex items-center transition-opacity`,style:{[e===`start`?`left`:`right`]:-28,height:24,width:30,cursor:`crosshair`,opacity:+!!r,pointerEvents:i?`auto`:`none`,justifyContent:e===`start`?`flex-start`:`flex-end`,paddingLeft:e===`start`?4:0,paddingRight:e===`end`?4:0},"data-testid":`gantt-link-dot-${e}-${t.id}`,onPointerDown:n=>{if(n.button!==0)return;n.stopPropagation(),n.preventDefault();let r=qt.current?.getBoundingClientRect();Jt({sourceId:t.id,sourceEnd:e,x:r?n.clientX-r.left:0,y:r?n.clientY-r.top:0,targetId:null,targetEnd:null})},onClick:e=>e.stopPropagation(),children:(0,I.jsx)(`div`,{className:`rounded-full`,style:{height:12,width:12,backgroundColor:`hsl(var(--background))`,border:`2px solid hsl(var(--primary))`,boxShadow:n?`0 0 0 3px hsl(var(--primary) / 0.25)`:`0 1px 2px rgba(0,0,0,0.25)`}})},e)}),(0,I.jsx)(`span`,{className:`relative text-[10px] text-white font-medium truncate pointer-events-none group-hover:opacity-0 transition-opacity`,children:t.title}),(0,I.jsx)(`span`,{className:`absolute inset-0 flex items-center px-2 text-[10px] text-white font-medium truncate opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none`,children:o?`${Dt(H).start.toLocaleDateString(w,{month:`numeric`,day:`numeric`})} → ${Dt(H).end.toLocaleDateString(w,{month:`numeric`,day:`numeric`})}`:`${Math.round(_)}%`})]}),g]},t.id)}),Z.endIdx<G.length&&(0,I.jsx)(`div`,{style:{height:(G.length-Z.endIdx)*N},"aria-hidden":`true`}),(lr.length>0||U)&&(0,I.jsxs)(`svg`,{className:`absolute top-0 left-0 pointer-events-none z-10`,width:vn,height:Hn,"data-testid":`gantt-links`,"aria-hidden":`true`,children:[(0,I.jsxs)(`defs`,{children:[(0,I.jsx)(`marker`,{id:`gantt-link-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,I.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:`hsl(var(--muted-foreground))`})}),(0,I.jsx)(`marker`,{id:`gantt-link-arrow-active`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,I.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:`hsl(var(--primary))`})}),(0,I.jsx)(`marker`,{id:`gantt-link-arrow-critical`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`6`,markerHeight:`6`,orient:`auto`,children:(0,I.jsx)(`path`,{d:`M 0 0 L 8 4 L 0 8 z`,fill:$})})]}),lr.map(e=>{let t=Math.min(e.sourceIndex,e.targetIndex);if(Math.max(e.sourceIndex,e.targetIndex)<Z.startIdx-6||t>Z.endIdx+6)return null;let n=xr(e);if(!n)return null;let r=Sr!=null&&(String(e.sourceId)===String(Sr)||String(e.targetId)===String(Sr)),i=Tr?.criticalEdges.has(`${String(e.sourceId)}->${String(e.targetId)}`)??!1,a=i?`gantt-link-arrow-critical`:r?`gantt-link-arrow-active`:`gantt-link-arrow`,o=!!(j||A);return(0,I.jsxs)(T.Fragment,{children:[(0,I.jsx)(`path`,{d:n,fill:`none`,stroke:i?$:r?`hsl(var(--primary))`:`hsl(var(--muted-foreground))`,strokeOpacity:i||r?1:.7,strokeWidth:i||r?2:1.5,markerEnd:`url(#${a})`,"data-testid":`gantt-link-${e.sourceId}-${e.targetId}`,"data-link-type":e.type,"data-active":r?`true`:`false`,"data-critical":i?`true`:void 0}),o&&(0,I.jsx)(`path`,{d:n,fill:`none`,stroke:`transparent`,strokeWidth:10,style:{pointerEvents:`stroke`,cursor:`context-menu`},"data-testid":`gantt-link-hit-${e.sourceId}-${e.targetId}`,onContextMenu:t=>ln(e.sourceId,e.targetId,e.type,t)})]},e.key)}),U&&(()=>{let e=G.findIndex(e=>String(e.task.id)===String(U.sourceId));if(e<0)return null;let t=cr(G[e]),n=G[e].isMilestone?t.left+(U.sourceEnd===`start`?-mr:mr):U.sourceEnd===`start`?t.left:t.left+t.width,r=e*N+N/2;return(0,I.jsx)(`path`,{d:`M ${Math.round(n)} ${Math.round(r)} L ${Math.round(U.x)} ${Math.round(U.y)}`,fill:`none`,stroke:`hsl(var(--primary))`,strokeWidth:1.5,strokeDasharray:`4 3`,"data-testid":`gantt-link-draft`})})()]}),U&&(()=>{let t=e.find(e=>String(e.id)===String(U.sourceId));if(!t)return null;let n=U.targetId==null?null:e.find(e=>String(e.id)===String(U.targetId)),r=e=>C(`gantt.linkEnd.${e}`),i=n?`${t.title} (${r(U.sourceEnd)}) → ${n.title} (${r(U.targetEnd??`start`)})`:`${t.title} (${r(U.sourceEnd)})`;return(0,I.jsx)(`div`,{className:`absolute z-30 pointer-events-none rounded-md border bg-popover text-popover-foreground px-2 py-1 text-[11px] font-medium shadow-md whitespace-nowrap`,style:{left:U.x+12,top:U.y+12},"data-testid":`gantt-link-draft-hint`,children:i})})()]})]})})]})]}),Xt&&(()=>{let t=e.find(e=>String(e.id)===String(Xt.taskId));if(!t)return null;let n=G.find(e=>String(e.task.id)===String(Xt.taskId)),r=`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none`;return(0,I.jsxs)(`div`,{ref:Qt,className:`fixed z-50 min-w-[160px] rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:Xt.x,top:Xt.y},role:`menu`,"data-testid":`gantt-context-menu`,children:[a&&(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-view`,onClick:()=>{Zt(null),a(t)},children:C(`gantt.menu.view`)}),je&&k&&n&&!n.isSummary&&!t.locked&&(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-edit`,onClick:()=>{Zt(null),gt(t.id),vt({title:t.title,start:t.start.toLocaleDateString(`en-CA`),end:t.end.toLocaleDateString(`en-CA`),progress:String(t.progress)})},children:C(`gantt.menu.edit`)}),A&&n&&!n.isMilestone&&!t.locked&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-add-predecessor`,onClick:()=>{let e=Xt;Zt(null),nn({x:e.x,y:e.y,taskId:t.id,relation:`pred`})},children:C(`gantt.menu.addPredecessor`)}),(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:r,"data-testid":`gantt-context-menu-add-successor`,onClick:()=>{let e=Xt;Zt(null),nn({x:e.x,y:e.y,taskId:t.id,relation:`succ`})},children:C(`gantt.menu.addSuccessor`)})]}),Ae&&!t.locked&&(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:S(r,`text-destructive`),"data-testid":`gantt-context-menu-delete`,onClick:()=>{Zt(null),Ae(t)},children:C(`gantt.menu.delete`)})]})})(),W&&(()=>{let t=e.find(e=>String(e.id)===String(W.sourceId)),n=e.find(e=>String(e.id)===String(W.targetId));if(!t||!n)return null;let r=`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none`;return(0,I.jsxs)(`div`,{ref:en,className:`fixed z-50 min-w-[180px] rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:W.x,top:W.y},role:`menu`,"data-testid":`gantt-link-context-menu`,children:[(0,I.jsxs)(`div`,{className:`px-3 py-1 text-xs text-muted-foreground truncate`,children:[t.title,` → `,n.title]}),A&&[`fs`,`ss`,`ff`,`sf`].map(e=>(0,I.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":W.type===e,className:S(r,W.type===e&&`font-semibold`),"data-testid":`gantt-link-menu-type-${e}`,onClick:()=>{$t(null),e!==W.type&&A(t,n,e)},children:[W.type===e?`✓ `:`\xA0\xA0`,C(`gantt.linkType.${e}`)]},e)),j&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`my-1 border-t`}),(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:S(r,`text-destructive`),"data-testid":`gantt-link-menu-remove`,onClick:()=>{$t(null),j(t,n)},children:C(`gantt.menu.removeDependency`)})]})]})})(),tn&&A&&(()=>{let t=e.find(e=>String(e.id)===String(tn.taskId));if(!t)return null;let n=new Set(lr.map(e=>`${String(e.sourceId)}->${String(e.targetId)}`)),r=e.filter(e=>{if(String(e.id)===String(t.id)||e.type===`summary`)return!1;let r=tn.relation===`pred`?`${String(e.id)}->${String(t.id)}`:`${String(t.id)}->${String(e.id)}`;return!n.has(r)});return(0,I.jsxs)(`div`,{ref:rn,className:`fixed z-50 min-w-[200px] max-h-[280px] overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md py-1 text-sm`,style:{left:tn.x,top:tn.y},role:`menu`,"data-testid":`gantt-dep-picker`,children:[(0,I.jsx)(`div`,{className:`px-3 py-1 text-xs text-muted-foreground`,children:tn.relation===`pred`?C(`gantt.menu.addPredecessor`):C(`gantt.menu.addSuccessor`)}),r.length===0?(0,I.jsx)(`div`,{className:`px-3 py-1.5 text-muted-foreground`,children:C(`gantt.menu.noCandidates`)}):r.map(e=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`w-full text-left px-3 py-1.5 hover:bg-accent focus:bg-accent outline-none truncate`,"data-testid":`gantt-dep-picker-option-${e.id}`,onClick:()=>{nn(null),tn.relation===`pred`?A(e,t,`fs`):A(t,e,`fs`)},children:e.title},String(e.id)))]})})(),Pt&&(0,I.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/30`,"data-testid":`gantt-conflict-overlay`,onClick:()=>Ft(null),children:(0,I.jsxs)(`div`,{className:`min-w-[280px] max-w-[360px] rounded-lg border bg-popover text-popover-foreground shadow-lg p-4`,role:`alertdialog`,"aria-modal":`true`,"data-testid":`gantt-conflict-dialog`,onClick:e=>e.stopPropagation(),children:[(0,I.jsx)(`div`,{className:`text-sm font-semibold mb-1`,"data-testid":`gantt-conflict-title`,children:C(`gantt.conflict.title`)}),(0,I.jsx)(`div`,{className:`text-sm text-muted-foreground mb-3`,children:C(`gantt.conflict.body`).replace(`{count}`,String(Pt.length))}),(0,I.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-sm rounded-md border hover:bg-accent outline-none`,"data-testid":`gantt-conflict-cancel`,onClick:()=>Ft(null),children:C(`gantt.conflict.cancel`)}),(0,I.jsx)(`button`,{type:`button`,className:`px-3 py-1.5 text-sm rounded-md bg-primary text-primary-foreground hover:opacity-90 outline-none`,"data-testid":`gantt-conflict-confirm`,onClick:Lt,children:C(`gantt.conflict.confirm`)})]})]})})]})}function at(e,t,n,r){return t.getTime()===e.getTime()?e.getTime()>=n.getTime()&&e.getTime()<r.getTime():e.getTime()<r.getTime()&&t.getTime()>n.getTime()}function ot(e,t,n){let{assignee:r,effort:i,capacity:a=1,unassignedLabel:o=`Unassigned`}=n,s=e=>typeof a==`function`?a(e):a,c=e=>{let t=i?i(e):1;return Number.isFinite(t)&&t>0?t:0},l=new Map;for(let t of e){let e=r(t),n=e?String(e.key):`__unassigned__`,i=e?e.label:o,a=l.get(n);a||(a={key:n,label:i,items:[]},l.set(n,a)),a.items.push(t)}let u=[];for(let e of l.values()){let n=s(e.key),r=0,i=0,a=t.map(t=>{let a=0;for(let n of e.items)at(n.start,n.end,t.start,t.end)&&(a+=c(n));a>r&&(r=a);let o=a>n+1e-9;return o&&i++,{load:a,capacity:n,overloaded:o}});u.push({key:e.key,label:e.label,capacity:n,cells:a,peak:r,overloadedCount:i})}return u}var st={day:26,week:56,month:76,quarter:88,year:104},ct=48,R=34,lt=180;function ut(e,t,n){return t===`day`?String(e.getDate()):t===`week`?e.toLocaleDateString(n,{month:`numeric`,day:`numeric`}):t===`month`?e.toLocaleDateString(n,{month:`short`}):t===`year`?String(e.getFullYear()):`Q${Math.floor(e.getMonth()/3)+1}`}function dt({tasks:e,assignee:t,effort:n,capacity:r=1,viewMode:i=`day`,unassignedLabel:a=`Unassigned`,className:o}){let{t:s,language:c}=Ve(),l=c||void 0,u=st[i],d=T.useMemo(()=>{if(!e.length)return[];let t=new Date(Math.min(...e.map(e=>e.start.getTime()))),n=new Date(Math.max(...e.map(e=>e.end.getTime()))),r=Ye(t,i),a=Ze(Ye(n,i),1,i),o=[],s=0;for(;r<a&&s++<4e3;){let e=Ze(r,1,i);o.push({date:new Date(r),col:{start:new Date(r),end:new Date(e)},label:ut(r,i,l)}),r=e}return o},[e,i,l]),f=T.useMemo(()=>ot(e,d.map(e=>e.col),{assignee:t,effort:n,capacity:r,unassignedLabel:a}),[e,d,t,n,r,a]),p=T.useMemo(()=>{let e=0;for(let t of f)e=Math.max(e,t.peak,t.capacity);return e||1},[f]),m=d.length*u;return e.length?(0,I.jsx)(`div`,{className:o,"data-testid":`resource-workload`,style:{display:`flex`,flexDirection:`column`,height:`100%`,overflow:`auto`},children:(0,I.jsxs)(`div`,{style:{display:`flex`,minWidth:lt+m},children:[(0,I.jsxs)(`div`,{style:{width:lt,flexShrink:0},children:[(0,I.jsx)(`div`,{style:{height:28,display:`flex`,alignItems:`center`,padding:`0 12px`,fontSize:12,fontWeight:600,borderBottom:`1px solid hsl(var(--border))`},children:s(`gantt.resource.header`)}),f.map(e=>(0,I.jsxs)(`div`,{"data-testid":`resource-row-${e.key}`,style:{height:ct,display:`flex`,flexDirection:`column`,justifyContent:`center`,padding:`0 12px`,borderBottom:`1px solid hsl(var(--border) / 0.5)`},children:[(0,I.jsx)(`span`,{style:{fontSize:13,fontWeight:500,whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},children:e.label}),(0,I.jsxs)(`span`,{"data-testid":`resource-peak-${e.key}`,"data-overloaded":e.overloadedCount>0?`true`:void 0,style:{fontSize:10,color:e.overloadedCount>0?`hsl(var(--destructive))`:`hsl(var(--muted-foreground))`},children:[s(`gantt.resource.peak`),`: `,Math.round(e.peak*100)/100,` / `,e.capacity,e.overloadedCount>0?` · ${e.overloadedCount} ${s(`gantt.resource.over`)}`:``]})]},e.key))]}),(0,I.jsxs)(`div`,{style:{flex:1},children:[(0,I.jsx)(`div`,{style:{display:`flex`,height:28,borderBottom:`1px solid hsl(var(--border))`},children:d.map((e,t)=>(0,I.jsx)(`div`,{style:{width:u,flexShrink:0,textAlign:`center`,fontSize:10,color:`hsl(var(--muted-foreground))`,borderLeft:`1px solid hsl(var(--border) / 0.4)`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:e.label},t))}),f.map(e=>{let t=R*(1-Math.min(e.capacity/p,1));return(0,I.jsxs)(`div`,{style:{position:`relative`,display:`flex`,height:ct,borderBottom:`1px solid hsl(var(--border) / 0.5)`},children:[(0,I.jsx)(`div`,{"aria-hidden":`true`,style:{position:`absolute`,left:0,right:0,top:(ct-R)/2+t,borderTop:`1px dashed hsl(var(--muted-foreground) / 0.6)`,pointerEvents:`none`,zIndex:1}}),e.cells.map((t,n)=>{let r=Math.max(t.load>0?2:0,R*Math.min(t.load/p,1));return(0,I.jsx)(`div`,{"data-testid":`resource-cell-${e.key}-${n}`,"data-load":t.load,"data-overloaded":t.overloaded?`true`:void 0,title:`${d[n]?.date.toLocaleDateString(l)} — ${Math.round(t.load*100)/100} / ${t.capacity}`,style:{width:u,flexShrink:0,position:`relative`,borderLeft:`1px solid hsl(var(--border) / 0.4)`,display:`flex`,alignItems:`flex-end`,justifyContent:`center`,paddingBottom:(ct-R)/2},children:t.load>0&&(0,I.jsx)(`div`,{style:{width:u-6,height:r,borderRadius:2,backgroundColor:t.overloaded?`hsl(var(--destructive))`:`hsl(var(--primary))`,opacity:t.overloaded?.9:.75}})},n)})]},e.key)})]})]})}):(0,I.jsx)(`div`,{className:o,"data-testid":`resource-workload`,children:(0,I.jsx)(`div`,{className:`flex items-center justify-center h-40 text-sm text-muted-foreground`,children:s(`gantt.resource.empty`)})})}var z={display:`flex`,flexWrap:`wrap`,alignItems:`center`,gap:8,padding:`8px 12px`,borderBottom:`1px solid hsl(var(--border))`,background:`hsl(var(--background))`,fontSize:13},ft={display:`inline-flex`,alignItems:`center`,gap:6,height:30,padding:`0 10px`,borderRadius:6,border:`1px solid hsl(var(--border))`,background:`hsl(var(--background))`,color:`hsl(var(--foreground))`,cursor:`pointer`,whiteSpace:`nowrap`,lineHeight:`28px`},B={position:`absolute`,top:`calc(100% + 4px)`,left:0,zIndex:50,minWidth:200,maxHeight:320,overflowY:`auto`,padding:4,borderRadius:8,border:`1px solid hsl(var(--border))`,background:`hsl(var(--popover, var(--background)))`,color:`hsl(var(--popover-foreground, var(--foreground)))`,boxShadow:`0 8px 24px rgba(0,0,0,0.18)`},pt={display:`flex`,alignItems:`center`,gap:8,padding:`6px 8px`,borderRadius:6,cursor:`pointer`,userSelect:`none`};function mt({checked:e}){return(0,I.jsx)(`span`,{"aria-hidden":!0,style:{display:`inline-flex`,alignItems:`center`,justifyContent:`center`,width:15,height:15,flex:`0 0 auto`,borderRadius:3,border:`1px solid ${e?`hsl(var(--primary))`:`hsl(var(--border))`}`,background:e?`hsl(var(--primary))`:`transparent`,color:`hsl(var(--primary-foreground, var(--background)))`,fontSize:11,lineHeight:1},children:e?`✓`:``})}function ht({filter:e,selected:t,onChange:n,labels:r}){let[i,a]=(0,T.useState)(!1),o=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=new Set(t),c=t.length,l=e.options.length>0&&c===e.options.length,u=t=>{let r=new Set(s);r.has(t)?r.delete(t):r.add(t),r.size===e.options.length?n([]):n([...r])},d=()=>{n(c>0?[]:e.options.map(e=>e.value))},f=c===0?e.label:c===1?`${e.label}: ${e.options.find(e=>e.value===t[0])?.label??t[0]}`:`${e.label} · ${c}`;return(0,I.jsxs)(`div`,{ref:o,style:{position:`relative`},"data-testid":`quick-filter-${e.field}`,children:[(0,I.jsxs)(`button`,{type:`button`,style:{...ft,borderColor:c>0?`hsl(var(--primary))`:`hsl(var(--border))`,color:c>0?`hsl(var(--primary))`:`hsl(var(--foreground))`},"aria-haspopup":`listbox`,"aria-expanded":i,"data-testid":`quick-filter-trigger-${e.field}`,onClick:()=>a(e=>!e),children:[(0,I.jsx)(`span`,{children:f}),(0,I.jsx)(`span`,{"aria-hidden":!0,style:{fontSize:10,opacity:.7},children:`▾`})]}),i&&(0,I.jsx)(`div`,{role:`listbox`,style:B,"data-testid":`quick-filter-panel-${e.field}`,children:e.options.length===0?(0,I.jsx)(`div`,{style:{...pt,cursor:`default`,opacity:.6},children:r.empty}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{role:`option`,"aria-selected":l,style:{...pt,fontWeight:600},"data-testid":`quick-filter-all-${e.field}`,onClick:()=>d(),children:[(0,I.jsx)(mt,{checked:l}),(0,I.jsx)(`span`,{children:r.all})]}),(0,I.jsx)(`div`,{style:{height:1,background:`hsl(var(--border))`,margin:`2px 0`}}),e.options.map(t=>{let n=s.has(t.value);return(0,I.jsxs)(`div`,{role:`option`,"aria-selected":n,style:{...pt,background:n?`hsl(var(--accent, var(--muted)))`:`transparent`},"data-testid":`quick-filter-option-${e.field}-${t.value}`,onClick:()=>u(t.value),children:[(0,I.jsx)(mt,{checked:n}),(0,I.jsx)(`span`,{children:t.label})]},t.value)})]})})]})}var gt=({filters:e,value:t,onChange:n,onClear:r,resultCount:i,totalCount:a,labels:o,className:s})=>{if(!e.length)return null;let c=o?.all??`All`,l=o?.empty??`No options`,u=o?.clear??`Clear`,d=e.some(e=>(t[e.field]?.length??0)>0);return(0,I.jsxs)(`div`,{style:z,className:s,"data-testid":`quick-filter-bar`,children:[e.map(e=>(0,I.jsx)(ht,{filter:e,selected:t[e.field]??[],onChange:t=>n(e.field,t),labels:{all:c,empty:l}},e.field)),d&&(0,I.jsx)(`button`,{type:`button`,style:{...ft,height:28,color:`hsl(var(--muted-foreground))`},"data-testid":`quick-filter-clear`,onClick:r,children:u}),o?.resultSummary&&i!=null&&a!=null&&(0,I.jsx)(`span`,{"data-testid":`quick-filter-summary`,style:{marginLeft:`auto`,color:`hsl(var(--muted-foreground))`},children:o.resultSummary(i,a)})]})};function _t(e){if(e==null)return;let t=String(e).toLowerCase().trim();if(t===`milestone`)return`milestone`;if(t===`group`||t===`folder`)return`group`;if(t===`summary`||t===`project`||t===`phase`)return`summary`;if(t===`task`)return`task`}var vt={fs:`fs`,ss:`ss`,ff:`ff`,sf:`sf`,finish_to_start:`fs`,start_to_start:`ss`,finish_to_finish:`ff`,start_to_finish:`sf`,end_to_start:`fs`,end_to_end:`ff`,start_to_end:`sf`};function yt(e){if(e==null||e===``)return[];if(typeof e==`string`)return e.split(`,`).map(e=>e.trim()).filter(Boolean);if(typeof e==`number`)return[e];if(!Array.isArray(e))return[];let t=[];for(let n of e)if(!(n==null||n===``))if(typeof n==`object`){let e=n.id??n._id??n.task??n.target;if(e==null||e===``)continue;let r=vt[String(n.type??``).toLowerCase().replace(/-/g,`_`)];t.push(r?{id:e,type:r}:{id:e})}else t.push(n);return t}function bt(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function V(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 xt(e){let t=null;if(e.startDateField&&e.endDateField)return t={startDateField:e.startDateField,endDateField:e.endDateField,titleField:e.titleField||`name`,progressField:e.progressField,dependenciesField:e.dependenciesField||e.dependencyField,colorField:e.colorField,parentField:e.parentField,typeField:e.typeField,lockField:e.lockField,defaultCollapsedDepth:e.defaultCollapsedDepth,tooltipFields:e.tooltipFields,baselineStartField:e.baselineStartField,baselineEndField:e.baselineEndField,groupByField:e.groupByField,resourceView:e.resourceView,assigneeField:e.assigneeField,effortField:e.effortField,capacity:e.capacity,quickFilters:e.quickFilters,autoZoomToFilter:e.autoZoomToFilter,timeSegments:e.timeSegments},t;if(e.gantt&&(t=e.gantt),t){let e=d.safeParse(t);return e.success||console.warn(`[ObjectGantt] Invalid gantt configuration:`,e.error.format()),t}return null}var St=({schema:e,dataSource:t,className:n,onTaskClick:r,onRowClick:i,...c})=>{let[l,d]=(0,T.useState)([]),[f,p]=(0,T.useState)(!0),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),{currency:ee}=ne(),te=bt(e),v=(0,T.useMemo)(()=>te,[JSON.stringify(te)]),y=xt(e),re=v?.provider===`value`;(0,T.useEffect)(()=>{(async()=>{try{if(p(!0),c.data&&Array.isArray(c.data)){d(c.data),p(!1);return}if(re&&v?.provider===`value`){d(v.items),p(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(v?.provider===`object`){let n=v.object,r=a(g?.fields),i=o(await t.find(n,{$filter:e.filter,$orderby:V(e.sort),...r.length>0?{$expand:r}:{}}));d(i)}else v?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectGantt`),d([]));p(!1)}catch(e){h(e),p(!1)}})()},[v,t,re,e.filter,e.sort,g]),(0,T.useEffect)(()=>{!re&&t&&(async()=>{try{if(!t)return;let n=v?.provider===`object`?v.object:e.objectName;if(!n)return;let r=await t.getObjectSchema(n);_(r)}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,re,v]);let ie=(0,T.useMemo)(()=>{if(!y||!l.length)return[];let{startDateField:e,endDateField:t,titleField:n,progressField:r,dependenciesField:i,colorField:a,parentField:o,typeField:c,lockField:u,tooltipFields:d,baselineStartField:f,baselineEndField:p}=y,m=g?.fields??{},h=(e,t)=>{if(!t)return;let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r},_=e=>{let t=[h(e,n),e?.account?.name,e?.opportunity?.name,e?.contact&&[e.contact.first_name,e.contact.last_name].filter(Boolean).join(` `)];for(let e of t)if(e!=null&&String(e).trim()!==``)return String(e);return s(g,e)},te=(e,t)=>{if(t)return t;let n=m[e]??m[e.split(`.`)[0]];return n?.label?n.label:xe(e)},v=(e,t)=>{if(e==null||e===``)return`—`;let n=m[t]??m[t.split(`.`)[0]],r=n?.type,i=n?.options;if(Array.isArray(i)&&i.length){let t=i.find(t=>String(t.value)===String(e));if(t)return t.label}switch(r){case`date`:return ue(e);case`datetime`:return Ce(e);case`number`:case`integer`:case`float`:case`decimal`:return pe(Number(e));case`currency`:return _e(Number(e),ve(n,ee));case`percent`:return be(Number(e));case`boolean`:case`checkbox`:return e?`Yes`:`No`;default:if(Array.isArray(e)){let t=e.map(e=>{if(e==null)return``;if(typeof e==`object`){let t=e;return String(t.name??t.label??t.title??t.id??``)}return String(e)}).filter(Boolean);return t.length?t.join(`, `):`—`}if(typeof e==`object`){let t=e;return String(t.name??t.label??t.title??t.id??`—`)}return String(e)}},ne=e=>{if(!d||!d.length)return;let t=[];for(let n of d){let r=typeof n==`string`?n:n?.field;if(!r)continue;let i=typeof n==`object`?n.label:void 0;t.push({label:te(r,i),value:v(h(e,r),r)})}return t.length?t:void 0};return l.map((n,s)=>{let l=n[e],d=n[t],m=f?n[f]:void 0,h=p?n[p]:void 0,g=m?new Date(m):void 0,ee=h?new Date(h):void 0,te=_(n),v=r?n[r]:0,y=i?n[i]:[],re=a?n[a]:void 0;if(!re){let e=n.status??n.state??n.priority??n.severity;if(e!=null&&e!==``){let t=b(void 0,e);t&&(re=we(t))}}return{id:n.id||n._id||`task-${s}`,title:te,start:l?new Date(l):new Date,end:d?new Date(d):new Date,progress:Math.min(100,Math.max(0,v||0)),dependencies:yt(y),parent:o?n[o]??null:void 0,type:c?_t(n[c]):void 0,locked:u?!!n[u]:void 0,color:re,baselineStart:g&&!isNaN(g.getTime())?g:void 0,baselineEnd:ee&&!isNaN(ee.getTime())?ee:void 0,fields:ne(n),data:n}}).filter(e=>!isNaN(e.start.getTime())&&!isNaN(e.end.getTime()))},[l,y,g]),ae=(0,T.useMemo)(()=>{let e=y?.groupByField;if(!e)return;let t=g?.fields??{},n=(e,t)=>{if(!t)return;let n=e;for(let e of t.split(`.`)){if(n==null)return;n=n[e]}return n},r=n=>{let r=(t[e]??t[e.split(`.`)[0]])?.options;if(Array.isArray(r)&&r.length){let e=r.find(e=>String(e.value)===String(n));if(e)return e.label}if(typeof n==`object`&&n){let e=n;return String(e.name??e.label??e.title??e.id??n)}return String(n)};return t=>{let i=n(t.data,e);return i==null||i===``?null:{key:typeof i==`object`&&i?String(i.id??i._id??r(i)):i,label:r(i)}}},[y?.groupByField,g]),oe=(0,T.useMemo)(()=>{let e=y?.assigneeField;if(!e)return;let t=g?.fields??{},n=(e,t)=>{if(!t)return;let n=e;for(let e of t.split(`.`)){if(n==null)return;n=n[e]}return n},r=n=>{let r=(t[e]??t[e.split(`.`)[0]])?.options;if(Array.isArray(r)&&r.length){let e=r.find(e=>String(e.value)===String(n));if(e)return e.label}if(typeof n==`object`&&n){let e=n;return String(e.name??e.label??e.title??e.id??n)}return String(n)};return t=>{let i=n(t.data,e);return i==null||i===``?null:{key:typeof i==`object`&&i?String(i.id??i._id??r(i)):i,label:r(i)}}},[y?.assigneeField,g]),se=(0,T.useMemo)(()=>{let e=y?.effortField;if(e)return t=>{let n=t.data?.[e],r=Number(n);return Number.isFinite(r)&&r>0?r:1}},[y?.effortField]),ce=(0,T.useMemo)(()=>{let t=e.skipWeekends,n=e.holidays;if(!(!t&&(!n||n.length===0)))return{skipWeekends:!!t,holidays:n&&n.length?new Set(n):void 0}},[e]),de=(0,T.useMemo)(()=>Ie(y?.timeSegments),[y?.timeSegments]),me=(0,T.useCallback)((e,t)=>{if(!e||!t)return null;let n=e;for(let e of t.split(`.`)){if(n==null)return null;n=n[e]}if(n==null||n===``)return null;if(typeof n==`object`){let e=n;return String(e.id??e._id??e.value??e.name??``)}return String(n)},[]),he=y?.quickFilters,[ye,S]=(0,T.useState)({});(0,T.useEffect)(()=>{if(!he?.length||!t||typeof t.find!=`function`)return;let e=g?.fields??{},n=!1;return(async()=>{let r={};for(let n of he){if(n.options)continue;let i=e[n.field]??e[n.field.split(`.`)[0]],a=i?.type;if(a!==`lookup`&&a!==`master_detail`)continue;let s=i?.reference_to??i?.referenceTo;if(s)try{let e=o(await t.find(s,{$top:1e3}));r[n.field]=e.map(e=>({value:String(e.id??e._id??e.value??``),label:String(e.name??e.label??e.title??e.id??e._id??``)}))}catch(e){console.warn(`[ObjectGantt] Failed to load quick-filter options for "${n.field}":`,e)}}n||S(e=>({...e,...r}))})(),()=>{n=!0}},[JSON.stringify(he),t,g]);let Oe=(0,T.useMemo)(()=>{if(!he?.length)return[];let e=g?.fields??{};return he.map(t=>{let n=e[t.field]??e[t.field.split(`.`)[0]],r=t.label??n?.label??xe(t.field),i=[];if(t.options?.length)i=t.options.map(e=>typeof e==`object`?{value:String(e.value),label:String(e.label??e.value)}:{value:String(e),label:String(e)});else if(Array.isArray(n?.options)&&n.options.length)i=n.options.map(e=>({value:String(e.value??e),label:String(e.label??e.value??e)}));else if(ye[t.field]?.length)i=ye[t.field];else{let e=new Map;for(let n of l){let r=me(n,t.field);if(r!=null&&!e.has(r)){let i=n;for(let e of t.field.split(`.`))i=i?.[e];let a=i&&typeof i==`object`?String(i.name??i.label??i.title??r):r;e.set(r,a)}}i=[...e.entries()].map(([e,t])=>({value:e,label:t}))}return{field:t.field,label:r,options:i}})},[he,g,ye,l,me]),[ke,E]=(0,T.useState)({}),D=(0,T.useCallback)((e,t)=>{E(n=>({...n,[e]:t}))},[]),O=(0,T.useCallback)(()=>E({}),[]),k=(0,T.useMemo)(()=>{let e=Object.entries(ke).filter(([,e])=>e.length>0);return e.length?ie.filter(t=>e.every(([e,n])=>{let r=me(t.data,e);return r!=null&&n.includes(r)})):ie},[ie,ke,me]),Ae=(0,T.useMemo)(()=>{if(y?.autoZoomToFilter!==!1||!ie.length)return null;let e=ie[0].start.getTime(),t=ie[0].end.getTime();for(let n of ie)e=Math.min(e,n.start.getTime()),t=Math.max(t,n.end.getTime());return{start:new Date(e),end:new Date(t)}},[ie,y?.autoZoomToFilter]),A=e.navigation??{mode:`drawer`,width:`min(960px, 60vw)`},j=A.mode===`drawer`||A.mode===`modal`||A.mode===`split`||A.mode===`popover`,M=u({navigation:A,objectName:e.objectName,onRowClick:j?void 0:i}),je=(0,T.useCallback)(async(n,r)=>{if(!y)return;let i=v?.provider===`object`?v.object:e.objectName;if(!i||!t||typeof t.update!=`function`)return;let{startDateField:a,endDateField:o,titleField:s,progressField:c}=y,u={};if(r.start instanceof Date&&(u[a]=r.start.toISOString()),r.end instanceof Date&&(u[o]=r.end.toISOString()),typeof r.title==`string`&&s&&(u[s]=r.title),typeof r.progress==`number`&&c&&(u[c]=r.progress),Object.keys(u).length===0)return;let f=n.data?.id??n.data?._id??n.id;if(f==null)return;let p=l;d(e=>e.map(e=>String(e.id??e._id)===String(f)?{...e,...u}:e));try{await t.update(i,String(f),u)}catch(e){console.error(`[ObjectGantt] Failed to persist task update:`,e),d(p)}},[y,v,t,e.objectName,l]),Me=(e,t)=>{let n=t.some(e=>typeof e==`object`&&e.type&&e.type!==`fs`);return!n&&typeof e==`string`?t.map(e=>String(typeof e==`object`?e.id:e)).join(`,`):n?t.map(e=>typeof e==`object`?e.type&&e.type!==`fs`?{id:e.id,type:e.type}:e.id:e):t.map(e=>typeof e==`object`?e.id:e)},Ne=(0,T.useCallback)(async(n,r,i)=>{let a=y?.dependenciesField;if(!a)return;let o=v?.provider===`object`?v.object:e.objectName;if(!o||!t||typeof t.update!=`function`)return;let s=Me(r,i),c=l;d(e=>e.map(e=>String(e.id??e._id)===String(n)?{...e,[a]:s}:e));try{await t.update(o,String(n),{[a]:s})}catch(e){console.error(`[ObjectGantt] Failed to persist dependency:`,e),d(c)}},[y,v,t,e.objectName,l]),Pe=(0,T.useCallback)(async(e,t,n=`fs`)=>{let r=e.data?.id??e.data?._id??e.id,i=t.data?.id??t.data?._id??t.id;if(r==null||i==null)return;let a=y?.dependenciesField;if(!a)return;let o=l.find(e=>String(e.id??e._id)===String(i))?.[a],s=yt(o),c=e=>String(typeof e==`object`?e.id:e),u=s.find(e=>c(e)===String(r)),d=u&&typeof u==`object`?u.type??`fs`:`fs`;if(u&&d===n)return;let f=n===`fs`?r:{id:r,type:n},p=u?s.map(e=>c(e)===String(r)?f:e):[...s,f];await Ne(i,o,p)},[y,l,Ne]),Fe=(0,T.useCallback)(async(e,t)=>{let n=e.data?.id??e.data?._id??e.id,r=t.data?.id??t.data?._id??t.id;if(n==null||r==null)return;let i=y?.dependenciesField;if(!i)return;let a=l.find(e=>String(e.id??e._id)===String(r))?.[i],o=yt(a),s=e=>String(typeof e==`object`?e.id:e),c=o.filter(e=>s(e)!==String(n));c.length!==o.length&&await Ne(r,a,c)},[y,l,Ne]),[N,P]=(0,T.useState)(null),[F,Le]=(0,T.useState)(!1),Re=(0,T.useCallback)(e=>{P(e)},[]),ze=(0,T.useCallback)(async()=>{if(!N)return;let n=v?.provider===`object`?v.object:e.objectName;if(!n||!t?.delete){P(null);return}let r=N.data?.id??N.data?._id??N.id;if(r==null){P(null);return}Le(!0);let i=l;d(e=>e.filter(e=>String(e.id??e._id)!==String(r)));try{await t.delete(n,String(r)),P(null)}catch(e){console.error(`[ObjectGantt] Failed to delete:`,e),d(i),P(null)}finally{Le(!1)}},[N,v,t,e.objectName,l]);return f?(0,I.jsx)(`div`,{className:n,children:(0,I.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,I.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading Gantt chart...`})})}):m?(0,I.jsx)(`div`,{className:n,children:(0,I.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,I.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,m.message]})})}):y?(0,I.jsxs)(`div`,{className:n,children:[Oe.length>0&&(0,I.jsx)(gt,{filters:Oe,value:ke,onChange:D,onClear:O,resultCount:k.length,totalCount:ie.length,labels:{all:`全部`,clear:`清除筛选`,empty:`无可选项`,resultSummary:(e,t)=>`显示 ${e} / ${t} 项任务`}}),(0,I.jsx)(`div`,{className:`h-[calc(100vh-200px)] min-h-[600px]`,children:y?.resourceView&&oe?(0,I.jsx)(dt,{tasks:k,assignee:oe,effort:se,capacity:y?.capacity??1,viewMode:e.viewMode||`day`}):(0,I.jsx)(L,{tasks:k,startDate:Ae?.start,endDate:Ae?.end,onTaskClick:e=>{M.handleClick(e.data),r?.(e.data)},onTaskUpdate:je,onTaskDelete:Re,onDependencyCreate:y?.dependenciesField?Pe:void 0,onDependencyDelete:y?.dependenciesField?Fe:void 0,markers:e.markers,autoSchedule:!!y?.dependenciesField,rescheduleOnConflict:!!y?.dependenciesField,criticalPathDefault:!!e.criticalPath,workingCalendar:ce,shiftSegments:de,showBaselines:e.showBaselines!==!1,readOnly:!!e.readOnly,mobileReadOnly:e.mobileReadOnly!==!1,persistLayoutKey:e.persistLayout===!1?void 0:`${e.objectName||(v?.provider===`object`?v.object:``)||`gantt`}:${e.viewName||`default`}`,groupBy:ae,defaultCollapsedDepth:y?.defaultCollapsedDepth,inlineEdit:!0})}),M.isOverlay&&M.isOpen&&M.selectedRecord&&(()=>{let n=v?.provider===`object`?v.object:e.objectName,r=M.selectedRecord,i=r.id??r._id;if(!n||i==null)return null;let a=y?.titleField?String(r[y.titleField]??`Task Details`):`Task Details`;return(0,I.jsx)(Ee,{open:!0,onClose:M.close,title:a,record:r,objectName:n,recordId:i,dataSource:t,objectSchema:g,width:M.width,fullPageHref:De(n,i)??void 0,onFieldSave:async(e,r)=>{t?.update&&(await t.update(n,String(i),{[e]:r}),d(t=>t.map(t=>String(t.id??t._id)===String(i)?{...t,[e]:r}:t)))},onDelete:async()=>{t?.delete&&(await t.delete(n,String(i)),d(e=>e.filter(e=>String(e.id??e._id)!==String(i))))}})})(),(0,I.jsx)(Se,{open:!!N,onOpenChange:e=>{!e&&!F&&P(null)},children:(0,I.jsxs)(le,{children:[(0,I.jsxs)(fe,{children:[(0,I.jsx)(Te,{children:`Delete this task?`}),(0,I.jsx)(C,{children:N?(0,I.jsxs)(I.Fragment,{children:[`"`,N.title,`" will be permanently removed. This action cannot be undone.`]}):null})]}),(0,I.jsxs)(w,{children:[(0,I.jsx)(x,{disabled:F,children:`Cancel`}),(0,I.jsx)(ge,{onClick:e=>{e.preventDefault(),ze()},disabled:F,"data-testid":`gantt-delete-confirm`,className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:F?`Deleting…`:`Delete`})]})]})})]}):(0,I.jsx)(`div`,{className:n,children:(0,I.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,I.jsx)(`div`,{className:`text-muted-foreground`,children:`Gantt configuration required. Please specify startDateField, endDateField, and titleField.`})})})},Ct=t({GanttView:()=>L,ObjectGantt:()=>St,ObjectGanttRenderer:()=>H,QuickFilterBar:()=>gt,ResourceWorkload:()=>dt,bandAt:()=>Re,computeWorkload:()=>ot,normalizeDependencies:()=>yt,normalizeShiftSegments:()=>Ie,normalizeTaskType:()=>_t,parseHHMM:()=>F,shiftDayStart:()=>Le}),H=({schema:e})=>{let{dataSource:t}=l()||{};return(0,I.jsx)(St,{schema:e,dataSource:t})};i.register(`object-gantt`,H,{namespace:`plugin-gantt`,label:`Object Gantt`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]}),i.register(`gantt`,H,{namespace:`view`,label:`Gantt View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]});export{Ct as t};