headroom-cms 0.1.3 → 0.1.4

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 (61) hide show
  1. package/admin/assets/{AdminsPage-DYJhlQnA.js → AdminsPage-Cvqw6UOu.js} +1 -1
  2. package/admin/assets/{AllContentPage-DShBvFru.js → AllContentPage-Cnkt8Fgm.js} +1 -1
  3. package/admin/assets/{ApiKeysPage-DONrd-TJ.js → ApiKeysPage-FLex3Chc.js} +1 -1
  4. package/admin/assets/{AuditPage-BwhYu96L.js → AuditPage-ClgwR_8y.js} +1 -1
  5. package/admin/assets/{BlockEditor-C0KaZUHQ.js → BlockEditor-uSyk_TPt.js} +1 -1
  6. package/admin/assets/{BlockTypeEditPage-BYJfEA6l.js → BlockTypeEditPage-Dr_yNLDI.js} +1 -1
  7. package/admin/assets/{BlockTypesPage-Pf9u78-O.js → BlockTypesPage-CwsGPuAZ.js} +1 -1
  8. package/admin/assets/{BulkActionBar-BX-t8fyM.js → BulkActionBar-C-88Wnqw.js} +1 -1
  9. package/admin/assets/{CollectionEditPage-CQGo9Cbu.js → CollectionEditPage-Cimkb84B.js} +1 -1
  10. package/admin/assets/{CollectionsPage-D-QTkoW_.js → CollectionsPage-CxnSFPCH.js} +1 -1
  11. package/admin/assets/{ContentCreatePage-DujNZXXj.js → ContentCreatePage-DZCyOcte.js} +1 -1
  12. package/admin/assets/ContentEditPage-RtHbU_l4.js +3 -0
  13. package/admin/assets/{ContentListPage-llAlhZTH.js → ContentListPage-qFcZVzg9.js} +1 -1
  14. package/admin/assets/{CustomBlockPreview-CCiZrZhi.js → CustomBlockPreview-ers8OdZ0.js} +1 -1
  15. package/admin/assets/{FieldBuilder-B3-3MTqp.js → FieldBuilder-Ds-agLm7.js} +1 -1
  16. package/admin/assets/{LoginPage-BlJXP0GH.js → LoginPage-uxiw8K1J.js} +1 -1
  17. package/admin/assets/{MediaPage-Cad4n33B.js → MediaPage-CeepVDHQ.js} +1 -1
  18. package/admin/assets/{SiteSettingsPage-xfAm3ZKQ.js → SiteSettingsPage-xkngL15i.js} +1 -1
  19. package/admin/assets/SitesPage-BD9tou9-.js +1 -0
  20. package/admin/assets/{TagsPage-DNlaoFCE.js → TagsPage-BxSwTLpQ.js} +1 -1
  21. package/admin/assets/{UsersPage-D_nOx6W9.js → UsersPage-BayuQyLh.js} +1 -1
  22. package/admin/assets/{WebhookEditPage-BUvLl4rY.js → WebhookEditPage-BrXm8Dht.js} +1 -1
  23. package/admin/assets/{WebhooksPage-CG7WC9Bq.js → WebhooksPage-BUE6XuIP.js} +1 -1
  24. package/admin/assets/{badge-ChZ2DZue.js → badge-B8OxObuF.js} +1 -1
  25. package/admin/assets/{card-DpNr7WTb.js → card-C7fgQS_U.js} +1 -1
  26. package/admin/assets/check-CxKAR64t.js +1 -0
  27. package/admin/assets/{checkbox-VtCfoGic.js → checkbox-BV2kjQBe.js} +1 -1
  28. package/admin/assets/{command-98iA8Va4.js → command-qGFnWxcS.js} +1 -1
  29. package/admin/assets/{copy-fXL6Ngxi.js → copy-CgYzmj06.js} +1 -1
  30. package/admin/assets/{core.esm-BtFZvlg0.js → core.esm-DRuhixPo.js} +1 -1
  31. package/admin/assets/index-DX9xeoQx.js +18 -0
  32. package/admin/assets/index-PpbsYFRh.css +1 -0
  33. package/admin/assets/{plus-2Ds_MoqB.js → plus-HdRn2U0S.js} +1 -1
  34. package/admin/assets/{popover-DFInMOpa.js → popover-Cou924mw.js} +1 -1
  35. package/admin/assets/{radix-n1vDIPi6.js → radix-lA_IxTIV.js} +1 -1
  36. package/admin/assets/{react-vendor-DNVhVxD7.js → react-vendor-B0Dih9Pj.js} +1 -1
  37. package/admin/assets/{search-DRNC6QB5.js → search-C-3Q9nn7.js} +1 -1
  38. package/admin/assets/{select-Cj54Wt-H.js → select-CHW5R8qv.js} +1 -1
  39. package/admin/assets/{sortable.esm-BUhmZW2_.js → sortable.esm-CBJBhe4k.js} +1 -1
  40. package/admin/assets/{table-D4rLgOKa.js → table-BjSue8Ev.js} +1 -1
  41. package/admin/assets/{tanstack-BO6c-AOu.js → tanstack-oFmRhGwV.js} +1 -1
  42. package/admin/assets/{trash-2-CbbWF_O4.js → trash-2-CWWRVuRB.js} +1 -1
  43. package/admin/assets/{use-mobile-Cvl5tIVY.js → use-mobile-C1r2eP64.js} +1 -1
  44. package/admin/assets/useAdminResolver-D6B6RXnk.js +1 -0
  45. package/admin/assets/useContent-f19XHVlJ.js +1 -0
  46. package/admin/assets/{useDebouncedValue-Bf8UizjU.js → useDebouncedValue-DHUCnm9B.js} +1 -1
  47. package/admin/assets/{useMedia-DjiNKMOU.js → useMedia-DkvP1QLG.js} +1 -1
  48. package/admin/assets/{useTags-BB47vbXO.js → useTags-BuXf7_7H.js} +1 -1
  49. package/admin/assets/{useWebhooks-DS4Ee8Wk.js → useWebhooks-Cx9tbBME.js} +1 -1
  50. package/admin/index.html +5 -5
  51. package/admin/sw.js +1 -1
  52. package/lambda/api/bootstrap +0 -0
  53. package/lambda/webhook-worker/bootstrap +0 -0
  54. package/package.json +1 -1
  55. package/admin/assets/ContentEditPage-DyqgEoAe.js +0 -3
  56. package/admin/assets/SitesPage-DnCiSu23.js +0 -1
  57. package/admin/assets/check-BMpruHpO.js +0 -1
  58. package/admin/assets/index-CwkwXbO-.js +0 -18
  59. package/admin/assets/index-FYfbavkE.css +0 -1
  60. package/admin/assets/useAdminResolver-B-_1f6SR.js +0 -1
  61. package/admin/assets/useContent-Cp41wBYR.js +0 -1
@@ -0,0 +1,3 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BlockEditor-uSyk_TPt.js","assets/tanstack-oFmRhGwV.js","assets/react-vendor-B0Dih9Pj.js","assets/index-DX9xeoQx.js","assets/radix-lA_IxTIV.js","assets/index-PpbsYFRh.css","assets/command-qGFnWxcS.js","assets/search-C-3Q9nn7.js","assets/badge-B8OxObuF.js","assets/use-mobile-C1r2eP64.js","assets/CustomBlockPreview-ers8OdZ0.js","assets/useContent-f19XHVlJ.js","assets/useAdminResolver-D6B6RXnk.js","assets/select-CHW5R8qv.js","assets/check-CxKAR64t.js","assets/format-C88SDH8g.js","assets/sortable.esm-CBJBhe4k.js","assets/core.esm-DRuhixPo.js","assets/card-C7fgQS_U.js","assets/useMedia-DkvP1QLG.js","assets/useTags-BuXf7_7H.js","assets/popover-Cou924mw.js","assets/useDebouncedValue-DHUCnm9B.js","assets/plus-HdRn2U0S.js","assets/checkbox-BV2kjQBe.js","assets/trash-2-CWWRVuRB.js","assets/contentStatus-BmaiYVOm.js","assets/BlockEditor-Cp_wZ2xN.css"])))=>i.map(i=>d[i]);
2
+ import{j as e,u as zs}from"./tanstack-oFmRhGwV.js";import{r as x,u as Pe,e as Bs,L as Hs}from"./react-vendor-B0Dih9Pj.js";import{f as qs,g as Ht,h as Js,i as qt,j as Gs,k as Qs,l as Ys,m as Xs,n as Zs,o as Ks,p as en,q as tn,r as Jt}from"./useContent-f19XHVlJ.js";import{o as De,x as $e,t as A,y as sn,w as K,z as nn,A as an,C as ln,E as rn,S as F,T as Gt,F as Qt,G as ve,J as ye,D as be,j as Ne,k as Ce,l as we,m as Se,I as oe,B as v,a as z,K as Je,e as Yt,M as ee,X as te,N as on,_ as cn,L as ie,v as dn,O as Tt,P as Lt,Q as un,R as _t,V as Me,n as Ue,W as hn,i as mn}from"./index-DX9xeoQx.js";import{u as pn}from"./useAdminResolver-D6B6RXnk.js";import{m as Ge,u as Xt}from"./use-mobile-C1r2eP64.js";import{S as Qe,a as Ye,b as Xe,c as Ze,d as G,e as xn,f as fn,g as gn}from"./select-CHW5R8qv.js";import{f as q,a as Ee}from"./format-C88SDH8g.js";import{u as Zt,S as Ke,v as et,a as tt,T as Kt,C as es,b as ts,c as ss}from"./sortable.esm-CBJBhe4k.js";import{B as ce}from"./badge-B8OxObuF.js";import{C as B,a as Ve,b as We,c as J}from"./card-C7fgQS_U.js";import{u as jn,a as vn,b as yn,c as bn,U as Nn,F as Cn,d as ns,T as wn,E as Sn,A as kn,e as Pn,f as Dn,g as In,h as An,i as Tn,j as Ln,k as _n}from"./useMedia-DkvP1QLG.js";import{u as On}from"./useTags-BuXf7_7H.js";import{C as as,G as ls,u as st,a as nt,P as at,D as lt,c as it,b as is}from"./core.esm-DRuhixPo.js";import{P as Fn,a as Mn,b as En}from"./popover-Cou924mw.js";import{C as Rn,a as $n,b as Un,c as Vn,d as Wn,e as zn}from"./command-qGFnWxcS.js";import{u as Bn}from"./useDebouncedValue-DHUCnm9B.js";import{P as rt}from"./plus-HdRn2U0S.js";import{C as Hn}from"./checkbox-BV2kjQBe.js";import{T as rs}from"./trash-2-CWWRVuRB.js";import{g as qn,a as Jn,b as Gn}from"./contentStatus-BmaiYVOm.js";import{C as Ot}from"./check-CxKAR64t.js";const Qn=[["path",{d:"M16 14v2.2l1.6 1",key:"fo4ql5"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],Ft=De("calendar-clock",Qn);const Yn=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Xn=De("eye",Yn);const Zn=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],Kn=De("pencil",Zn);const ea=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],ta=De("rotate-ccw",ea),sa=3e3,na="__HEADROOM_API_URL__".replace(/\/+$/,"");function aa(a,t,s,l){const n=qs(a,t),i=x.useRef(null),r=x.useRef(s?JSON.stringify(s):""),o=x.useRef(void 0),[c,u]=x.useState(null),[p,b]=x.useState(null),h=x.useRef(!1),f=x.useCallback(m=>{JSON.stringify(m)!==r.current&&(i.current=m,clearTimeout(o.current),o.current=window.setTimeout(()=>{if(i.current){const P=i.current,C=JSON.stringify(P);i.current=null,n.mutate(P,{onSuccess:w=>{if(h.current){h.current=!1;return}r.current=C,u(Date.now()),w?.blockId&&b(w.blockId)},onError:w=>{w instanceof $e&&w.code==="SLUG_TAKEN"?l?.():w instanceof $e&&w.status===400&&A.error("Auto-save failed",{description:w.message})}})}},sa))},[n,l]),g=x.useCallback(async m=>{if(clearTimeout(o.current),i.current){const y={...i.current};m?.createVersion&&(y.createVersion=!0);const P=JSON.stringify(i.current);i.current=null;const C=await n.mutateAsync(y);r.current=P,u(Date.now()),C?.blockId&&b(C.blockId)}else if(m?.createVersion&&r.current){const P={...JSON.parse(r.current),createVersion:!0},C=await n.mutateAsync(P);u(Date.now()),C?.blockId&&b(C.blockId)}},[n]),N=x.useCallback(()=>{clearTimeout(o.current),i.current=null},[]),S=x.useCallback(m=>{r.current=JSON.stringify(m)},[]),k=x.useCallback(()=>{clearTimeout(o.current),i.current=null,h.current=!0,b(null)},[]);return x.useEffect(()=>()=>{if(clearTimeout(o.current),i.current){const m=JSON.stringify(i.current),y=sn(),P=`${na}/v1/admin/sites/${a}/content/${t}/draft`;fetch(P,{method:"PUT",body:m,headers:{"Content-Type":"application/json",...y?{Authorization:`Bearer ${y}`}:{}},keepalive:!0}).catch(()=>{}),i.current=null}},[a,t]),{schedule:f,flush:g,cancel:N,resetBaseline:S,discard:k,isSaving:n.isPending,lastSavedAt:c,lastSavedBlockId:p}}function la({lines:a}){return e.jsx("div",{className:"font-mono text-sm leading-relaxed",children:a.map((t,s)=>e.jsx("div",{style:{paddingLeft:`${t.indent*1.5}rem`},className:K("min-h-[1.5em]",t.type==="label"&&"text-muted-foreground font-semibold mt-1",t.type==="heading"&&"font-bold",t.type==="empty"&&"h-2"),children:t.text},s))})}class os{diff(t,s,l={}){let n;typeof l=="function"?(n=l,l={}):"callback"in l&&(n=l.callback);const i=this.castInput(t,l),r=this.castInput(s,l),o=this.removeEmpty(this.tokenize(i,l)),c=this.removeEmpty(this.tokenize(r,l));return this.diffWithOptionsObj(o,c,l,n)}diffWithOptionsObj(t,s,l,n){var i;const r=m=>{if(m=this.postProcess(m,l),n){setTimeout(function(){n(m)},0);return}else return m},o=s.length,c=t.length;let u=1,p=o+c;l.maxEditLength!=null&&(p=Math.min(p,l.maxEditLength));const b=(i=l.timeout)!==null&&i!==void 0?i:1/0,h=Date.now()+b,f=[{oldPos:-1,lastComponent:void 0}];let g=this.extractCommon(f[0],s,t,0,l);if(f[0].oldPos+1>=c&&g+1>=o)return r(this.buildValues(f[0].lastComponent,s,t));let N=-1/0,S=1/0;const k=()=>{for(let m=Math.max(N,-u);m<=Math.min(S,u);m+=2){let y;const P=f[m-1],C=f[m+1];P&&(f[m-1]=void 0);let w=!1;if(C){const I=C.oldPos-m;w=C&&0<=I&&I<o}const T=P&&P.oldPos+1<c;if(!w&&!T){f[m]=void 0;continue}if(!T||w&&P.oldPos<C.oldPos?y=this.addToPath(C,!0,!1,0,l):y=this.addToPath(P,!1,!0,1,l),g=this.extractCommon(y,s,t,m,l),y.oldPos+1>=c&&g+1>=o)return r(this.buildValues(y.lastComponent,s,t))||!0;f[m]=y,y.oldPos+1>=c&&(S=Math.min(S,m-1)),g+1>=o&&(N=Math.max(N,m+1))}u++};if(n)(function m(){setTimeout(function(){if(u>p||Date.now()>h)return n(void 0);k()||m()},0)})();else for(;u<=p&&Date.now()<=h;){const m=k();if(m)return m}}addToPath(t,s,l,n,i){const r=t.lastComponent;return r&&!i.oneChangePerToken&&r.added===s&&r.removed===l?{oldPos:t.oldPos+n,lastComponent:{count:r.count+1,added:s,removed:l,previousComponent:r.previousComponent}}:{oldPos:t.oldPos+n,lastComponent:{count:1,added:s,removed:l,previousComponent:r}}}extractCommon(t,s,l,n,i){const r=s.length,o=l.length;let c=t.oldPos,u=c-n,p=0;for(;u+1<r&&c+1<o&&this.equals(l[c+1],s[u+1],i);)u++,c++,p++,i.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return p&&!i.oneChangePerToken&&(t.lastComponent={count:p,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=c,u}equals(t,s,l){return l.comparator?l.comparator(t,s):t===s||!!l.ignoreCase&&t.toLowerCase()===s.toLowerCase()}removeEmpty(t){const s=[];for(let l=0;l<t.length;l++)t[l]&&s.push(t[l]);return s}castInput(t,s){return t}tokenize(t,s){return Array.from(t)}join(t){return t.join("")}postProcess(t,s){return t}get useLongestToken(){return!1}buildValues(t,s,l){const n=[];let i;for(;t;)n.push(t),i=t.previousComponent,delete t.previousComponent,t=i;n.reverse();const r=n.length;let o=0,c=0,u=0;for(;o<r;o++){const p=n[o];if(p.removed)p.value=this.join(l.slice(u,u+p.count)),u+=p.count;else{if(!p.added&&this.useLongestToken){let b=s.slice(c,c+p.count);b=b.map(function(h,f){const g=l[u+f];return g.length>h.length?g:h}),p.value=this.join(b)}else p.value=this.join(s.slice(c,c+p.count));c+=p.count,p.added||(u+=p.count)}}return n}}function Mt(a,t){let s;for(s=0;s<a.length&&s<t.length;s++)if(a[s]!=t[s])return a.slice(0,s);return a.slice(0,s)}function Et(a,t){let s;if(!a||!t||a[a.length-1]!=t[t.length-1])return"";for(s=0;s<a.length&&s<t.length;s++)if(a[a.length-(s+1)]!=t[t.length-(s+1)])return a.slice(-s);return a.slice(-s)}function ze(a,t,s){if(a.slice(0,t.length)!=t)throw Error(`string ${JSON.stringify(a)} doesn't start with prefix ${JSON.stringify(t)}; this is a bug`);return s+a.slice(t.length)}function Be(a,t,s){if(!t)return a+s;if(a.slice(-t.length)!=t)throw Error(`string ${JSON.stringify(a)} doesn't end with suffix ${JSON.stringify(t)}; this is a bug`);return a.slice(0,-t.length)+s}function ae(a,t){return ze(a,t,"")}function je(a,t){return Be(a,t,"")}function Rt(a,t){return t.slice(0,ia(a,t))}function ia(a,t){let s=0;a.length>t.length&&(s=a.length-t.length);let l=t.length;a.length<t.length&&(l=a.length);const n=Array(l);let i=0;n[0]=0;for(let r=1;r<l;r++){for(t[r]==t[i]?n[r]=n[i]:n[r]=i;i>0&&t[r]!=t[i];)i=n[i];t[r]==t[i]&&i++}i=0;for(let r=s;r<a.length;r++){for(;i>0&&a[r]!=t[i];)i=n[i];a[r]==t[i]&&i++}return i}function le(a){let t;for(t=a.length-1;t>=0&&a[t].match(/\s/);t--);return a.substring(t+1)}function W(a){const t=a.match(/^\s*/);return t?t[0]:""}const $t="a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}",ra=new RegExp(`[${$t}]+|\\s+|[^${$t}]`,"ug");class oa extends os{equals(t,s,l){return l.ignoreCase&&(t=t.toLowerCase(),s=s.toLowerCase()),t.trim()===s.trim()}tokenize(t,s={}){let l;if(s.intlSegmenter){const r=s.intlSegmenter;if(r.resolvedOptions().granularity!="word")throw new Error('The segmenter passed must have a granularity of "word"');l=[];for(const o of Array.from(r.segment(t))){const c=o.segment;l.length&&/\s/.test(l[l.length-1])&&/\s/.test(c)?l[l.length-1]+=c:l.push(c)}}else l=t.match(ra)||[];const n=[];let i=null;return l.forEach(r=>{/\s/.test(r)?i==null?n.push(r):n.push(n.pop()+r):i!=null&&/\s/.test(i)?n[n.length-1]==i?n.push(n.pop()+r):n.push(i+r):n.push(r),i=r}),n}join(t){return t.map((s,l)=>l==0?s:s.replace(/^\s+/,"")).join("")}postProcess(t,s){if(!t||s.oneChangePerToken)return t;let l=null,n=null,i=null;return t.forEach(r=>{r.added?n=r:r.removed?i=r:((n||i)&&Ut(l,i,n,r),l=r,n=null,i=null)}),(n||i)&&Ut(l,i,n,null),t}}const ca=new oa;function da(a,t,s){return ca.diff(a,t,s)}function Ut(a,t,s,l){if(t&&s){const n=W(t.value),i=le(t.value),r=W(s.value),o=le(s.value);if(a){const c=Mt(n,r);a.value=Be(a.value,r,c),t.value=ae(t.value,c),s.value=ae(s.value,c)}if(l){const c=Et(i,o);l.value=ze(l.value,o,c),t.value=je(t.value,c),s.value=je(s.value,c)}}else if(s){if(a){const n=W(s.value);s.value=s.value.substring(n.length)}if(l){const n=W(l.value);l.value=l.value.substring(n.length)}}else if(a&&l){const n=W(l.value),i=W(t.value),r=le(t.value),o=Mt(n,i);t.value=ae(t.value,o);const c=Et(ae(n,o),r);t.value=je(t.value,c),l.value=ze(l.value,n,c),a.value=Be(a.value,n,n.slice(0,n.length-c.length))}else if(l){const n=W(l.value),i=le(t.value),r=Rt(i,n);t.value=je(t.value,r)}else if(a){const n=le(a.value),i=W(t.value),r=Rt(n,i);t.value=ae(t.value,r)}}class ua extends os{tokenize(t){return t.slice()}join(t){return t}removeEmpty(t){return t}}const ha=new ua;function cs(a,t,s){return ha.diff(a,t,s)}const ma=5;function pa({published:a,draft:t,leftLabel:s="Published",rightLabel:l="Draft"}){const n=x.useMemo(()=>ja(a,t),[a,t]),i=x.useMemo(()=>va(n),[n]);return n.every(r=>r.type==="unchanged")?e.jsxs("p",{className:"text-sm text-muted-foreground italic py-4",children:["No changes between ",s," and ",l," versions."]}):e.jsxs("div",{className:"font-mono text-xs leading-relaxed border rounded-md overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-2 border-b bg-muted/50 text-muted-foreground text-[10px] font-semibold",children:[e.jsx("div",{className:"px-3 py-1.5",children:s}),e.jsx("div",{className:"px-3 py-1.5 border-l",children:l})]}),e.jsx("div",{children:i.map((r,o)=>e.jsx(xa,{segment:r},o))})]})}function xa({segment:a}){const[t,s]=x.useState(!1);return a.type==="collapsed"&&!t?e.jsxs("button",{onClick:()=>s(!0),className:"w-full grid grid-cols-2 text-[10px] text-muted-foreground bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[e.jsxs("div",{className:"px-3 py-1 text-center border-b",children:["... ",a.count," unchanged lines ..."]}),e.jsxs("div",{className:"px-3 py-1 text-center border-l border-b",children:["... ",a.count," unchanged lines ..."]})]}):a.type==="collapsed"?null:e.jsx(e.Fragment,{children:a.rows.map((l,n)=>e.jsx(fa,{row:l},n))})}function Vt({oldText:a,newText:t,side:s}){const l=da(a,t);return e.jsx(e.Fragment,{children:l.map((n,i)=>n.added?s==="right"?e.jsx("span",{className:"font-bold bg-green-200 dark:bg-green-800/50",children:n.value},i):null:n.removed?s==="left"?e.jsx("span",{className:"line-through bg-red-200 dark:bg-red-800/50",children:n.value},i):null:e.jsx("span",{children:n.value},i))})}function fa({row:a}){const t=a.type==="modified";return e.jsxs("div",{className:"grid grid-cols-2 border-b last:border-b-0",children:[e.jsx("div",{className:K("px-3 py-0.5 min-h-[1.5em]",(a.type==="removed"||t)&&"bg-red-50 dark:bg-red-950/30"),style:a.left?{paddingLeft:`calc(0.75rem + ${a.left.indent*1}rem)`}:void 0,children:e.jsx("span",{className:K(a.left?.type==="label"&&"text-muted-foreground font-semibold",a.left?.type==="heading"&&"font-bold"),children:t&&a.left&&a.right?e.jsx(Vt,{oldText:a.left.text,newText:a.right.text,side:"left"}):a.left?.text??""})}),e.jsx("div",{className:K("px-3 py-0.5 min-h-[1.5em] border-l",(a.type==="added"||t)&&"bg-green-50 dark:bg-green-950/30"),style:a.right?{paddingLeft:`calc(0.75rem + ${a.right.indent*1}rem)`}:void 0,children:e.jsx("span",{className:K(a.right?.type==="label"&&"text-muted-foreground font-semibold",a.right?.type==="heading"&&"font-bold"),children:t&&a.left&&a.right?e.jsx(Vt,{oldText:a.left.text,newText:a.right.text,side:"right"}):a.right?.text??""})})]})}function ga(a,t){const s=[],l=new Set;for(const n of a){if(!n.text){s.push({type:"removed",left:n});continue}let i=-1,r=-1;for(let o=0;o<t.length;o++){if(l.has(o)||!t[o].text)continue;let c=1;t[o].indent===n.indent&&c++,t[o].type===n.type&&c++,c>r&&(r=c,i=o)}i>=0?(l.add(i),s.push({type:"modified",left:n,right:t[i]})):s.push({type:"removed",left:n})}for(let n=0;n<t.length;n++)l.has(n)||s.push({type:"added",right:t[n]});return s}function ja(a,t){const s=cs(a,t,{comparator:(n,i)=>n.text===i.text&&n.indent===i.indent&&n.type===i.type}),l=[];for(let n=0;n<s.length;n++){const i=s[n],r=s[n+1];if(i.removed&&r?.added){const o=i.value,c=r.value,u=ga(o,c);l.push(...u),n++}else if(i.added)for(const o of i.value)l.push({type:"added",right:o});else if(i.removed)for(const o of i.value)l.push({type:"removed",left:o});else for(const o of i.value)l.push({type:"unchanged",left:o,right:o})}return l}function va(a){const t=[];let s=[];function l(){if(s.length!==0){if(s.length>ma){const r=s.slice(0,2),o=s.slice(-2),c=s.length-4;t.push({type:"rows",rows:r}),c>0&&t.push({type:"collapsed",count:c}),t.push({type:"rows",rows:o})}else t.push({type:"rows",rows:s});s=[]}}let n=[];function i(){n.length!==0&&(t.push({type:"rows",rows:n}),n=[])}for(const r of a)r.type==="unchanged"?(i(),s.push(r)):(l(),n.push(r));return i(),l(),t}function He(a){switch(a.kind){case"draft":return"Draft";case"published":return"Published";case"history":return q(a.createdAt)}}function ke(a){switch(a.kind){case"draft":return"draft";case"published":return"published";case"history":return`history:${a.blockId}`}}function Wt({value:a,onChange:t,isPublished:s,versions:l,exclude:n,size:i}){const r=n?ke(n):null;function o(c){if(c==="draft")t({kind:"draft"});else if(c==="published")t({kind:"published"});else if(c.startsWith("history:")){const u=c.slice(8),p=l.find(b=>b.blockId===u);p&&t({kind:"history",blockId:p.blockId,createdAt:p.createdAt,title:p.title})}}return e.jsxs(Qe,{value:ke(a),onValueChange:o,children:[e.jsx(Ye,{size:i,children:e.jsx(Xe,{children:He(a)})}),e.jsxs(Ze,{position:"popper",children:[r!=="draft"&&e.jsx(G,{value:"draft",children:"Draft"}),s&&r!=="published"&&e.jsx(G,{value:"published",children:"Published"}),l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(xn,{}),e.jsxs(fn,{children:[e.jsx(gn,{children:"Version History"}),l.map(c=>{const u=`history:${c.blockId}`;return u===r?null:e.jsx(G,{value:u,children:q(c.createdAt)},u)})]})]})]})]})}function ds(a,t){if(t==null||t==="")return[{text:"(empty)",indent:0,type:"value"}];switch(a.type){case"text":case"url":case"email":case"date":case"number":case"select":return[{text:String(t),indent:0,type:"value"}];case"textarea":return String(t).split(`
3
+ `).map(s=>({text:s,indent:0,type:"value"}));case"boolean":return[{text:t?"Yes":"No",indent:0,type:"value"}];case"media":return[{text:`[Media: ${t}]`,indent:0,type:"value"}];case"blocks":return qe(t);case"array":return Na(a,t);default:return[{text:String(t),indent:0,type:"value"}]}}function re(a,t,s,l){const n=[];s&&(s.title!==void 0&&(n.push({text:"Title",indent:0,type:"label"}),n.push({text:s.title||"(empty)",indent:0,type:"value"}),n.push({text:"",indent:0,type:"empty"})),s.slug!==void 0&&(n.push({text:"Slug",indent:0,type:"label"}),n.push({text:s.slug||"(empty)",indent:0,type:"value"}),n.push({text:"",indent:0,type:"empty"})),s.snippet!==void 0&&(n.push({text:"Snippet",indent:0,type:"label"}),n.push({text:s.snippet||"(empty)",indent:0,type:"value"}),n.push({text:"",indent:0,type:"empty"})),s.tags!==void 0&&(n.push({text:"Tags",indent:0,type:"label"}),n.push({text:s.tags.length>0?s.tags.join(", "):"(empty)",indent:0,type:"value"}),n.push({text:"",indent:0,type:"empty"})));for(const i of a){n.push({text:i.label,indent:0,type:"label"});const r=ds(i,t[i.name]);n.push(...r),n.push({text:"",indent:0,type:"empty"})}if(l&&l.defs.length>0)for(const i of l.defs){n.push({text:i.label,indent:0,type:"label"});const r=l.values[i.name]??[];r.length===0?n.push({text:"(empty)",indent:0,type:"value"}):n.push({text:r.map(o=>o.title).join(", "),indent:0,type:"value"}),n.push({text:"",indent:0,type:"empty"})}return n.length>0&&n[n.length-1].type==="empty"&&n.pop(),n}const ya=[["bold","**","**"],["italic","_","_"],["underline","__","__"],["strike","~~","~~"],["code","`","`"]];function ba(a,t){if(!t||!a)return a;let s=a;for(const[l,n,i]of ya)t[l]===!0&&(s=n+s+i);return s}function Z(a){return Array.isArray(a)?a.map(t=>typeof t.text=="string"?ba(t.text,t.styles):t.type==="link"&&Array.isArray(t.content)?`[${Z(t.content)}](${t.href??""})`:"").join(""):""}function qe(a,t=0){if(!Array.isArray(a))return[{text:"(empty)",indent:0,type:"value"}];if(a.length===0)return[{text:"(empty)",indent:0,type:"value"}];const s=[];let l=0;for(const n of a){if(typeof n!="object"||n===null)continue;const i=n,r=i.type??"";switch(r!=="numberedListItem"&&(l=0),r){case"paragraph":{const o=Z(i.content);s.push({text:o||"",indent:t,type:"value"});break}case"heading":{const o=i.props?.level??1,c="#".repeat(Math.min(o,6))+" ",u=Z(i.content);s.push({text:c+u,indent:t,type:"heading"});break}case"bulletListItem":{const o=Z(i.content);s.push({text:`- ${o}`,indent:t,type:"list-item"});break}case"numberedListItem":{l++;const o=Z(i.content);s.push({text:`${l}. ${o}`,indent:t,type:"list-item"});break}case"image":case"HeadroomImage":{const o=i.props?.alt,c=i.props?.mediaId,u=o||c||"image";s.push({text:`[Image: ${u}]`,indent:t,type:"value"});break}default:{if(i.props&&typeof i.props=="object"){const o=i.props,c=Object.entries(o).filter(([u])=>!["textAlignment","level"].includes(u));if(c.length>0){s.push({text:`[${r}]`,indent:t,type:"label"});for(const[u,p]of c)p==null||p===""||(Array.isArray(p)?(s.push({text:`${u}:`,indent:t+1,type:"label"}),s.push(...qe(p,t+2))):s.push({text:`${u}: ${String(p)}`,indent:t+1,type:"value"}))}else s.push({text:`[${r}]`,indent:t,type:"value"})}else{const o=Z(i.content);o&&s.push({text:o,indent:t,type:"value"})}break}}Array.isArray(i.children)&&i.children.length>0&&s.push(...qe(i.children,t+1))}return s}function Na(a,t){if(!Array.isArray(t)||t.length===0)return[{text:"(empty)",indent:0,type:"value"}];const l=a.options?.itemFields??[],n=[];for(let i=0;i<t.length;i++){n.push({text:`${i+1}.`,indent:0,type:"list-item"});const r=t[i];if(l.length>0)for(const o of l){n.push({text:o.label+":",indent:1,type:"label"});const c=ds(o,r[o.name]);n.push(...c.map(u=>({...u,indent:u.indent+1})))}else n.push({text:JSON.stringify(r,null,2),indent:1,type:"value"})}return n}function zt({ref:a,host:t,contentId:s,collectionFields:l,isSingleton:n,draftBody:i,draftMetadata:r,collectionRelationships:o,draftRelationships:c}){const u=a?.kind==="published",p=a?.kind==="history",b=p?a.blockId:null,{data:h,isLoading:f}=Ht(t,s,u),{data:g,isLoading:N}=Js(t,s,p?b:null),S=x.useMemo(()=>(o??[]).map(y=>({name:y.name,label:y.label})),[o]);function k(y){if(S.length!==0)return{defs:S,values:y??{}}}const m=x.useMemo(()=>{if(!a)return[];if(a.kind==="draft")return i?re(l,i,n?void 0:r,k(c)):[];if(a.kind==="published"){if(!h)return[];const C=n?void 0:{title:h.title,slug:h.slug,snippet:h.snippet,tags:h.tags},w=h.relationships;return re(l,h.body??{},C,k(w))}if(!g)return[];const y=n?void 0:{title:g.title,slug:g.slug,snippet:g.snippet,tags:g.tags},P=g.relationships;return re(l,g.body??{},y,k(P))},[a,i,r,c,h,g,l,n,S]);return a?a.kind==="draft"?{lines:m,isLoading:!1,hasData:!!i}:a.kind==="published"?{lines:m,isLoading:f,hasData:!!h}:{lines:m,isLoading:N,hasData:!!g}:{lines:[],isLoading:!1,hasData:!1}}function Ca({open:a,onOpenChange:t,host:s,contentId:l,collectionFields:n,isSingleton:i,isPublished:r,draftBody:o,draftMetadata:c,initialVersion:u,collectionRelationships:p,draftRelationships:b}){const[h,f]=x.useState(u??{kind:"published"}),[g,N]=x.useState({kind:"draft"}),[S,k]=x.useState(a),[m,y]=x.useState(u);if((a!==S||u!==m)&&(k(a),y(u),a)){const L=u??{kind:"published"};f(L),N(L.kind==="draft"?{kind:"published"}:{kind:"draft"})}ke(h)===ke(g)&&(h.kind!=="draft"?N({kind:"draft"}):r&&N({kind:"published"}));const{data:P}=qt(s,l),C=P?.items??[],w={host:s,contentId:l,collectionFields:n,isSingleton:i,draftBody:o,draftMetadata:c,collectionRelationships:p,draftRelationships:b},T=zt({ref:h,...w}),I=zt({ref:g,...w}),j=T.isLoading;return e.jsx(nn,{open:a,onOpenChange:t,children:e.jsxs(an,{className:"w-[calc(100vw-2rem)] sm:max-w-2xl overflow-y-auto pt-[env(safe-area-inset-top,0px)] pr-[env(safe-area-inset-right,0px)]",children:[e.jsx(ln,{children:e.jsxs(rn,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-sm font-normal",children:"Viewing"}),e.jsx(Wt,{value:h,onChange:f,isPublished:r,versions:C,size:"sm"})]})}),j&&e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(F,{className:"h-6 w-48"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-2/3"})]}),!j&&!T.hasData&&e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No data available for this version."}),!j&&T.hasData&&e.jsx("div",{className:"p-4",children:e.jsxs(Gt,{defaultValue:"changes",children:[e.jsxs(Qt,{variant:"line",className:"mb-4",children:[e.jsx(ve,{value:"content",children:"Content"}),e.jsx(ve,{value:"changes",children:"Changes"})]}),e.jsx(ye,{value:"content",children:e.jsx(la,{lines:T.lines})}),e.jsxs(ye,{value:"changes",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Compare with"}),e.jsx(Wt,{value:g,onChange:N,isPublished:r,versions:C,exclude:h,size:"sm"})]}),I.isLoading?e.jsxs("div",{className:"space-y-4",children:[e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-full"}),e.jsx(F,{className:"h-4 w-2/3"})]}):I.hasData?e.jsx(pa,{published:T.lines,draft:I.lines,leftLabel:He(h),rightLabel:He(g)}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No data available for comparison."})]})]})})]})})}function us({open:a,onSelect:t,onClose:s,allowedTypes:l}){const{host:n}=Pe(),[i,r]=x.useState(""),[o,c]=x.useState("__all__"),u=x.useRef(null),p=jn(n),b=vn(n),{data:h}=yn(n),f=h?.items??[],g=o==="__all__"?void 0:o==="__unfiled__"?"":o,{data:N,fetchNextPage:S,hasNextPage:k,isFetchingNextPage:m}=bn(n,{folderId:g}),[y,P]=x.useState(!1),w=(N?.pages.flatMap(j=>j.items)??[]).filter(j=>l&&!l.some(E=>E.endsWith("/*")?j.mimeType.startsWith(E.slice(0,-1)):j.mimeType===E)?!1:i?j.filename.toLowerCase().includes(i.toLowerCase())||j.alt?.toLowerCase().includes(i.toLowerCase()):!0);async function T(j){P(!0);try{const{uploadUrl:L,mediaId:E}=await p.mutateAsync({filename:j.name,contentType:j.type,size:j.size});await fetch(L,{method:"PUT",body:j,headers:{"Content-Type":j.type}});const O=await b.mutateAsync({mediaId:E,filename:j.name});t(O),s()}catch(L){A.error("Upload failed",{description:L instanceof Error?L.message:void 0})}finally{P(!1)}}function I(j){return j.startsWith("image/")}return e.jsx(be,{open:a,onOpenChange:()=>s(),children:e.jsxs(Ne,{className:"max-w-3xl",children:[e.jsxs(Ce,{children:[e.jsx(we,{children:"Select Media"}),e.jsx(Se,{className:"sr-only",children:"Browse and select media files"})]}),e.jsxs("div",{className:"mb-4 flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(oe,{placeholder:"Search by filename...",value:i,onChange:j=>r(j.target.value),className:"max-w-xs"}),f.length>0&&e.jsxs(Qe,{value:o,onValueChange:c,children:[e.jsx(Ye,{className:"w-[150px]",children:e.jsx(Xe,{})}),e.jsxs(Ze,{children:[e.jsx(G,{value:"__all__",children:"All folders"}),f.map(j=>e.jsx(G,{value:j.folderId,children:j.name},j.folderId)),e.jsx(G,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:u,type:"file",className:"hidden",accept:l?.join(",")??void 0,onChange:j=>j.target.files?.[0]&&T(j.target.files[0])}),e.jsxs(v,{variant:"outline",onClick:()=>u.current?.click(),disabled:y,children:[y?e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Nn,{className:"mr-2 h-4 w-4"}),"Upload New"]})]})]}),e.jsx("div",{className:"grid max-h-96 grid-cols-4 gap-3 overflow-y-auto",children:w.map(j=>e.jsxs(B,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{t(j),s()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:I(j.mimeType)?e.jsx("img",{src:Ge(j.urls?.thumb_md??j.url),alt:j.alt??j.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[j.mimeType.startsWith("image/")?e.jsx(Je,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(Cn,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:j.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:j.filename})})]},j.mediaId))}),w.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),k&&e.jsxs(v,{variant:"ghost",className:"mt-2 w-full",onClick:()=>S(),disabled:m,children:[m?e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function wa(a,t,s){const l=Yt(),n=s?.length===1?s[0]:void 0,i=new URLSearchParams;return t?(i.set("q",t),i.set("search","full")):i.set("limit","5"),n&&i.set("collection",n),zs({queryKey:["sites",a,"content-search",t,s??[]],queryFn:async()=>{const r=await l.apiFetch(`/v1/admin/sites/${a}/content?${i.toString()}`);return s&&s.length>1?{...r,items:r.items.filter(o=>s.includes(o.collection))}:r},enabled:!!a,staleTime:3e4})}function Sa({field:a,value:t,onChange:s}){const{host:l}=Pe(),n=a.options,i=!!n?.multiple,r=n?.collections;return i?e.jsx(Pa,{host:l,collections:r,value:t??[],onChange:s}):e.jsx(ka,{host:l,collections:r,value:t,onChange:s})}function ka({host:a,collections:t,value:s,onChange:l}){const[n,i]=x.useState(!1),r=s?[s.contentId]:[];function o(c){l(c),i(!1)}return e.jsx("div",{children:s?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:s.title}),e.jsx(ce,{variant:"secondary",children:s.collection}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>l(null),children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsx(Ie,{host:a,collections:t,selectedIds:r,open:n,onOpenChange:i,onSelect:o,trigger:e.jsxs(v,{type:"button",variant:"outline",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function Pa({host:a,collections:t,value:s,onChange:l}){const n=st(nt(at)),[i,r]=x.useState(!1),o=s??[],c=o.map(f=>f.contentId),u=o.map(f=>f.contentId);function p(f){l([...o,f]),r(!1)}function b(f){l(o.filter((g,N)=>N!==f))}function h(f){const{active:g,over:N}=f;if(N&&g.id!==N.id){const S=o.findIndex(m=>m.contentId===String(g.id)),k=o.findIndex(m=>m.contentId===String(N.id));S!==-1&&k!==-1&&l(tt(o,S,k))}}return e.jsx(lt,{sensors:n,collisionDetection:it,onDragEnd:h,children:e.jsx(Ke,{items:c,strategy:et,children:e.jsxs("div",{className:"space-y-2",children:[o.map(f=>e.jsx(hs,{id:f.contentId,contentRef:f,onRemove:()=>b(o.indexOf(f))},f.contentId)),e.jsx(Ie,{host:a,collections:t,selectedIds:u,open:i,onOpenChange:r,onSelect:p,trigger:e.jsxs(v,{type:"button",variant:"outline",size:"sm",children:[e.jsx(rt,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function hs({id:a,contentRef:t,onRemove:s}){const{attributes:l,listeners:n,setNodeRef:i,transform:r,transition:o}=Zt({id:a}),c={transform:as.Transform.toString(r),transition:o};return e.jsxs("div",{ref:i,style:c,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...l,...n,children:e.jsx(ls,{className:"h-4 w-4"})}),e.jsx(ee,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(ce,{variant:"secondary",children:t.collection}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:s,className:"text-destructive",children:e.jsx(te,{className:"h-3 w-3"})})]})}function Ie({host:a,collections:t,selectedIds:s,open:l,onOpenChange:n,onSelect:i,trigger:r}){const[o,c]=x.useState(""),u=Bn(o,300),{data:p,isLoading:b}=wa(a,u,t);return e.jsxs(Fn,{open:l,onOpenChange:n,children:[e.jsx(Mn,{asChild:!0,children:r}),e.jsx(En,{className:"w-80 p-0",align:"start",children:e.jsxs(Rn,{shouldFilter:!1,children:[e.jsx($n,{placeholder:"Search content...",value:o,onValueChange:c}),e.jsx(Un,{children:b?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(Vn,{children:"No content found."}),e.jsx(Wn,{heading:u.length===0?"Recent":void 0,children:p?.items.map(h=>{const f=s.includes(h.contentId);return e.jsxs(zn,{value:h.contentId,disabled:f,onSelect:()=>i({contentId:h.contentId,collection:h.collection,slug:h.slug??"",title:h.title}),children:[e.jsx(ee,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:h.title}),e.jsx(ce,{variant:"outline",className:"text-xs",children:h.collection})]},h.contentId)})})]})})]})})]})}function Da({relationships:a,values:t,onChange:s,host:l}){return e.jsxs(B,{children:[e.jsx(Ve,{children:e.jsx(We,{children:"Relationships"})}),e.jsx(J,{className:"space-y-4",children:a.map(n=>n.multiple?e.jsx(Aa,{rel:n,items:t[n.name]??[],host:l,onChange:i=>s({...t,[n.name]:i})},n.name):e.jsx(Ia,{rel:n,value:t[n.name]?.[0]??null,host:l,onChange:i=>s({...t,[n.name]:i?[i]:[]})},n.name))})]})}function Ia({rel:a,value:t,host:s,onChange:l}){const[n,i]=x.useState(!1),r=t?[t.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:a.label}),t?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(ee,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(ce,{variant:"secondary",children:t.collection}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>l(null),children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsx(Ie,{host:s,collections:[a.targetCollection],selectedIds:r,open:n,onOpenChange:i,onSelect:o=>{l(o),i(!1)},trigger:e.jsxs(v,{type:"button",variant:"outline",size:"sm",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Select ",a.label]})})]})}function Aa({rel:a,items:t,host:s,onChange:l}){const n=st(nt(at)),[i,r]=x.useState(!1),o=t.map(h=>h.contentId),c=t.map(h=>h.contentId);function u(h){l([...t,h]),r(!1)}function p(h){l(t.filter((f,g)=>g!==h))}function b(h){const{active:f,over:g}=h;if(g&&f.id!==g.id){const N=t.findIndex(k=>k.contentId===String(f.id)),S=t.findIndex(k=>k.contentId===String(g.id));N!==-1&&S!==-1&&l(tt(t,N,S))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:a.label}),e.jsx(lt,{sensors:n,collisionDetection:it,onDragEnd:b,children:e.jsx(Ke,{items:o,strategy:et,children:e.jsxs("div",{className:"space-y-2",children:[t.map(h=>e.jsx(hs,{id:h.contentId,contentRef:h,onRemove:()=>p(t.indexOf(h))},h.contentId)),e.jsx(Ie,{host:s,collections:[a.targetCollection],selectedIds:c,open:i,onOpenChange:r,onSelect:u,trigger:e.jsxs(v,{type:"button",variant:"outline",size:"sm",children:[e.jsx(rt,{className:"mr-2 h-3 w-3"}),"Add ",a.label]})})]})})})]})}function Re({field:a,value:t,onChange:s}){const l=a.options;return e.jsx(oe,{value:t??"",onChange:n=>s(n.target.value),placeholder:l?.placeholder,maxLength:l?.maxLength,required:!!l?.required,type:a.type==="url"?"url":a.type==="email"?"email":"text"})}function Ta({field:a,value:t,onChange:s}){const l=a.options;return e.jsx(Kt,{value:t??"",onChange:n=>s(n.target.value),placeholder:l?.placeholder,maxLength:l?.maxLength,required:!!l?.required,rows:4})}function La({field:a,value:t,onChange:s}){const l=a.options;return e.jsx(oe,{type:"number",value:t??"",onChange:n=>s(n.target.value===""?void 0:Number(n.target.value)),min:l?.min,max:l?.max,step:l?.step,required:!!l?.required})}function _a({field:a,value:t,onChange:s}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Hn,{id:`field-${a.name}`,checked:!!t,onCheckedChange:l=>s(!!l)}),e.jsx("label",{htmlFor:`field-${a.name}`,className:"text-sm text-muted-foreground",children:a.label})]})}function Oa({field:a,value:t,onChange:s}){const n=a.options?.choices??[];return e.jsxs(Qe,{value:t??"",onValueChange:i=>s(i),children:[e.jsx(Ye,{children:e.jsx(Xe,{placeholder:"Select..."})}),e.jsx(Ze,{children:n.map(i=>e.jsx(G,{value:i,children:i},i))})]})}function Fa({field:a,value:t,onChange:s}){const{host:l}=Pe(),[n,i]=x.useState(!1),o=a.options?.allowedTypes,c=typeof t=="string"?t:t?.mediaId??"",{data:u}=ns(l,c);return e.jsxs("div",{children:[c?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>i(!0),children:[u?.url&&e.jsx("img",{src:Ge(u.urls?.thumb_sm??u.url),alt:u?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:u?.filename??"Loading..."}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:p=>{p.stopPropagation(),s("")},children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsxs(v,{type:"button",variant:"outline",onClick:()=>i(!0),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Select Media"]}),e.jsx(us,{open:n,onClose:()=>i(!1),onSelect:p=>{s({mediaId:p.mediaId,url:p.url,width:p.width??0,height:p.height??0,filename:p.filename}),i(!1)},allowedTypes:o})]})}function Ma({field:a,value:t,onChange:s}){const l=st(nt(at)),n=t??[],r=a.options?.itemFields??[],o=n.map((h,f)=>`item-${f}`);function c(){s([...n,{}])}function u(h){s(n.filter((f,g)=>g!==h))}function p(h,f){const g=[...n];g[h]=f,s(g)}function b(h){const{active:f,over:g}=h;if(g&&f.id!==g.id){const N=o.indexOf(String(f.id)),S=o.indexOf(String(g.id));s(tt(n,N,S))}}return e.jsx(lt,{sensors:l,collisionDetection:it,onDragEnd:b,children:e.jsx(Ke,{items:o,strategy:et,children:e.jsxs("div",{className:"space-y-3",children:[n.map((h,f)=>e.jsx(Ea,{id:`item-${f}`,itemFields:r,item:h,onUpdate:g=>p(f,g),onRemove:()=>u(f)},`item-${f}`)),e.jsxs(v,{type:"button",variant:"outline",size:"sm",onClick:c,children:[e.jsx(rt,{className:"mr-2 h-3 w-3"})," Add Item"]})]})})})}function Ea({id:a,itemFields:t,item:s,onUpdate:l,onRemove:n}){const{attributes:i,listeners:r,setNodeRef:o,transform:c,transition:u}=Zt({id:a}),p={transform:as.Transform.toString(c),transition:u};return e.jsx(B,{ref:o,style:p,children:e.jsxs(J,{className:"flex gap-2 p-3",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...i,...r,children:e.jsx(ls,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(ms,{fields:t,values:s,onChange:l})}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:n,className:"text-destructive",children:e.jsx(rs,{className:"h-3 w-3"})})]})})}const Ra=x.lazy(()=>cn(()=>import("./BlockEditor-uSyk_TPt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]))),$a=2,Bt=x.createContext(0);function Ua({value:a,onChange:t,compact:s=!0}){const l=x.useContext(Bt),i=on()?.blockTypes??[],r=Xt();return l>=$a?e.jsx("div",{className:"rounded-md border border-muted p-4 text-sm text-muted-foreground",children:"Maximum nesting depth reached. Cannot embed another block editor here."}):e.jsx(Bt.Provider,{value:l+1,children:e.jsx("div",{className:r?"":"rounded-md border",children:e.jsx(x.Suspense,{fallback:e.jsx(F,{className:"h-48"}),children:e.jsx(Ra,{initialBlocks:a??[],onChange:t,blockTypes:i,compact:s})})})})}function ms({fields:a,values:t,onChange:s}){function l(n,i){s({...t,[n]:i})}return e.jsx("div",{className:"space-y-4",children:a.map(n=>e.jsxs("div",{className:"space-y-2",children:[n.type!=="boolean"&&e.jsx(ie,{children:n.label}),Va(n,t[n.name],i=>l(n.name,i))]},n.name))})}function Va(a,t,s){switch(a.type){case"text":case"url":case"email":return e.jsx(Re,{field:a,value:t,onChange:s});case"textarea":return e.jsx(Ta,{field:a,value:t,onChange:s});case"number":return e.jsx(La,{field:a,value:t,onChange:s});case"boolean":return e.jsx(_a,{field:a,value:t,onChange:s});case"select":return e.jsx(Oa,{field:a,value:t,onChange:s});case"media":return e.jsx(Fa,{field:a,value:t,onChange:s});case"content":return e.jsx(Sa,{field:a,value:t,onChange:s});case"blocks":return e.jsx(Ua,{field:a,value:t,onChange:s});case"array":return e.jsx(Ma,{field:a,value:t,onChange:s});case"date":return e.jsx(Re,{field:{...a,type:"text"},value:t,onChange:s});default:return e.jsx(Re,{field:a,value:t,onChange:s})}}function Wa(){const{host:a,collection:t,id:s}=Pe(),{data:l,isLoading:n}=Gs(a,s);return n?e.jsxs("div",{className:"space-y-4",children:[e.jsx(F,{className:"h-8 w-64"}),e.jsx(F,{className:"h-64 w-full"})]}):l?.content?e.jsx(za,{host:a,collection:t,contentId:s,content:l.content,draft:l.draft,publishedBlockId:l.publishedBlockId}):e.jsx("p",{className:"text-muted-foreground",children:"Content not found."})}function za({host:a,collection:t,contentId:s,content:l,draft:n,publishedBlockId:i}){const r=Bs(),o=Yt(),{collections:c}=dn(),u=Qs(a,s),p=Ys(a,s),b=Xs(a,s),h=Zs(a,s),f=Ks(a,s),g=en(a,s),N=n?{title:n.title??l.title,slug:n.slug??l.slug??"",snippet:n.snippet??l.snippet??"",tags:n.tags??l.tags??[],coverUrl:n.coverUrl??l.coverUrl??"",coverMediaId:n.coverMediaId??l.coverMediaId??"",coverWidth:n.coverWidth??l.coverWidth??0,coverHeight:n.coverHeight??l.coverHeight??0,body:n.body??{},relationships:n.relationships??{}}:void 0,[S,k]=x.useState(null),m=aa(a,s,N,()=>{k("This slug is already in use by another item in this collection")}),{data:y}=On(a),P=y?.map(d=>d.tag),C=c.find(d=>d.name===t),w=x.useMemo(()=>C?.fields??[],[C?.fields]),T=x.useMemo(()=>C?.relationships??[],[C?.relationships]),I=C?.singleton??!1,j=Xt(),[L,E]=x.useState(n?.title??l.title),[O,ot]=x.useState(n?.slug??l.slug??""),[R,ct]=x.useState(n?.snippet??l.snippet??""),dt=n?.autoSnippet??"",[Q,ut]=x.useState(n?.tags??l.tags??[]),[Ae,ht]=x.useState(n?.coverUrl??l.coverUrl??""),[de,mt]=x.useState(n?.coverMediaId??l.coverMediaId??""),[pt,xt]=x.useState(n?.coverWidth??l.coverWidth??0),[ft,gt]=x.useState(n?.coverHeight??l.coverHeight??0),[Y,jt]=x.useState(n?.body??{}),[X,vt]=x.useState(n?.relationships??{}),[ps,xs]=x.useState(0),[fs,gs]=x.useState(!1),[js,ue]=x.useState(!1),[vs,se]=x.useState(!1),[ys,he]=x.useState(null),[Te,me]=x.useState(!1),[bs,pe]=x.useState(!1),[Ns,xe]=x.useState(!1),[fe,yt]=x.useState(""),[Cs,Le]=x.useState(!1),[_e,bt]=x.useState(""),Nt=tn(a,s),{data:Ct}=ns(a,de),H=x.useCallback(()=>({title:L,slug:O,snippet:R,tags:Q,coverUrl:Ae,coverMediaId:de,coverWidth:pt,coverHeight:ft,body:Y,relationships:X}),[L,O,R,Q,Ae,de,pt,ft,Y,X]);function ws(d){E(d),m.schedule({...H(),title:d})}function Ss(d){ot(d),k(null),m.schedule({...H(),slug:d})}function ks(d){ct(d),m.schedule({...H(),snippet:d})}function Ps(d){ut(d),m.schedule({...H(),tags:d})}function wt(d,D,V,ne){ht(d),mt(D),xt(V),gt(ne),m.schedule({...H(),coverUrl:d,coverMediaId:D,coverWidth:V,coverHeight:ne})}function Ds(d){jt(d),m.schedule({...H(),body:d})}function Is(d){vt(d),m.schedule({...H(),relationships:d})}const As=m.lastSavedBlockId??n?.blockId,$=qn(l.publishedAt,l.lastPublishedAt,i,As,l.scheduledAt,l.scheduledFailed),St=Jn($),kt=Gn($),{data:U}=Ht(a,s,!!l.publishedAt),M=x.useMemo(()=>{if(!Te||!U)return null;const d=I?void 0:{title:U.title,slug:U.slug,snippet:U.snippet,tags:U.tags},D=T.map(_=>({name:_.name,label:_.label})),V=U.relationships,ne=D.length>0?{defs:D,values:V??{}}:void 0,Rs=re(w,U.body??{},d,ne),$s=I?void 0:{title:L,slug:O,snippet:R,tags:Q},Us=D.length>0?{defs:D,values:X}:void 0,Vs=re(w,Y,$s,Us),Ws=cs(Rs,Vs,{comparator:(_,Fe)=>_.text===Fe.text&&_.indent===Fe.indent&&_.type===Fe.type});let It=0,At=0;for(const _ of Ws)_.added?It+=_.count??0:_.removed&&(At+=_.count??0);return{added:It,removed:At}},[Te,U,w,T,I,L,O,R,Q,Y,X]);function Ts(){if(l.publishedAt&&l.slug&&O!==l.slug){pe(!0);return}$==="published-changes"?me(!0):ge()}async function ge(){try{m.cancel(),await m.flush({createVersion:!0}),await u.mutateAsync(void 0),A.success("Content published")}catch(d){if(d instanceof $e&&d.code==="SLUG_TAKEN"){k("This slug is already in use by another item in this collection"),A.error("Slug already in use",{description:"Please choose a different slug before publishing."});return}A.error("Failed to publish",{description:d instanceof Error?d.message:void 0})}}async function Ls(){try{await p.mutateAsync(),se(!1),A.success("Content unpublished")}catch(d){A.error("Failed to unpublish",{description:d instanceof Error?d.message:void 0})}}async function _s(){try{m.discard();const d=await o.apiFetch(`/v1/admin/sites/${a}/content/${s}/published`);await Nt.mutateAsync();const D={title:d.title??"",slug:d.slug??"",snippet:d.snippet??"",tags:d.tags??[],coverUrl:d.coverUrl??"",coverMediaId:d.coverMediaId??"",coverWidth:d.coverWidth??0,coverHeight:d.coverHeight??0,body:d.body??{},relationships:d.relationships??{}};E(D.title),ot(D.slug),ct(D.snippet),ut(D.tags),ht(D.coverUrl),mt(D.coverMediaId),xt(D.coverWidth),gt(D.coverHeight),jt(D.body),vt(D.relationships),xs(V=>V+1),m.resetBaseline(D),A.success("Changes discarded")}catch(d){A.error("Failed to discard changes",{description:d instanceof Error?d.message:void 0})}}async function Os(){try{await b.mutateAsync(),A.success("Content deleted"),r(`/sites/${a}/content/${t}`)}catch(d){A.error("Failed to delete",{description:d instanceof Error?d.message:void 0})}}async function Fs(){if(fe)try{m.cancel(),await m.flush({createVersion:!0});const d=new Date(fe).getTime();await f.mutateAsync(d),xe(!1),yt(""),A.success("Content scheduled for publishing")}catch(d){A.error("Failed to schedule",{description:d instanceof Error?d.message:void 0})}}async function Ms(){try{await g.mutateAsync(),A.success("Schedule cancelled")}catch(d){A.error("Failed to cancel schedule",{description:d instanceof Error?d.message:void 0})}}async function Es(){if(_e)try{const d=new Date(_e).getTime();await h.mutateAsync(d),Le(!1),A.success("Publish date updated")}catch(d){A.error("Failed to update publish date",{description:d instanceof Error?d.message:void 0})}}function Oe(d){const D=new Date(d),V=D.getTimezoneOffset();return new Date(D.getTime()-V*6e4).toISOString().slice(0,16)}const Pt=e.jsx("div",{className:"space-y-6",children:w.length>0?e.jsx(ms,{fields:w,values:Y,onChange:Ds},ps):e.jsx(B,{children:e.jsx(J,{className:"py-8 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No fields defined for this collection."," ",e.jsx(Hs,{to:`/sites/${a}/settings/collections/${t}`,className:"underline",children:"Configure fields"})]})})})}),Dt=e.jsxs("div",{className:"space-y-6",children:[!I&&e.jsx(B,{children:e.jsxs(J,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{htmlFor:"title",children:"Title"}),e.jsx(oe,{id:"title",value:L,onChange:d=>ws(d.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{htmlFor:"slug",children:"Slug"}),e.jsx(oe,{id:"slug",value:O,onChange:d=>Ss(d.target.value),className:S?"border-destructive":""}),S&&e.jsx("p",{className:"text-sm text-destructive",children:S})]}),e.jsxs(es,{defaultOpen:!!R,children:[e.jsxs(ts,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(is,{className:"h-4 w-4 transition-transform [[data-state=open]>&]:rotate-90"}),"Snippet",e.jsx("span",{className:"text-xs text-muted-foreground",children:"(auto-generated if empty)"})]}),e.jsxs(ss,{className:"mt-2 space-y-2",children:[e.jsx(Kt,{id:"snippet",value:R,onChange:d=>ks(d.target.value),rows:3,placeholder:"Brief summary of this content..."}),!R&&dt&&e.jsxs("p",{className:"text-xs italic text-muted-foreground",children:["Auto-generated: ",dt]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{children:"Cover Image"}),de?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>ue(!0),children:[e.jsx("img",{src:Ge(Ae),alt:Ct?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:Ct?.filename??"Loading..."}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:d=>{d.stopPropagation(),wt("","",0,0)},children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsxs(v,{type:"button",variant:"outline",className:"w-full",onClick:()=>ue(!0),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Select Image"]}),e.jsx(us,{open:js,onClose:()=>ue(!1),onSelect:d=>{wt(d.url,d.mediaId,d.width??0,d.height??0),ue(!1)},allowedTypes:["image/*"]})]})]})}),!I&&e.jsxs(B,{children:[e.jsx(Ve,{children:e.jsx(We,{children:"Tags"})}),e.jsx(J,{children:e.jsx(wn,{tags:Q,onChange:Ps,suggestions:P})})]}),T.length>0&&e.jsx(Da,{relationships:T,values:X,onChange:Is,host:a}),e.jsxs(B,{children:[e.jsx(Ve,{children:e.jsx(We,{children:"Info"})}),e.jsxs(J,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Collection"}),e.jsx("span",{children:l.collection})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"ID"}),e.jsx("span",{className:"font-mono text-xs",children:l.contentId})]}),l.publishedAt?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Published"}),Cs?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{type:"datetime-local",value:_e,onChange:d=>bt(d.target.value),className:"text-xs border rounded px-1 py-0.5",max:Oe(Date.now())}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Es,disabled:h.isPending,children:e.jsx(Ot,{className:"h-3 w-3"})}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>Le(!1),children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsxs("span",{className:"cursor-pointer hover:underline",title:q(l.publishedAt),onClick:()=>{bt(Oe(l.publishedAt)),Le(!0)},children:[Ee(l.publishedAt),e.jsx(Kn,{className:"inline ml-1 h-3 w-3 text-muted-foreground"})]})]}),l.lastPublishedAt&&l.lastPublishedAt!==l.publishedAt&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:q(l.lastPublishedAt),children:Ee(l.lastPublishedAt)})]})]}):l.lastPublishedAt?e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last published"}),e.jsx("span",{title:q(l.lastPublishedAt),children:Ee(l.lastPublishedAt)})]}):null,$==="scheduled"&&l.scheduledAt&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Scheduled for"}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ft,{className:"h-3 w-3"}),q(l.scheduledAt)]})]}),$==="schedule-failed"&&e.jsx("div",{className:"text-destructive text-xs",children:"Scheduled publishing failed after multiple attempts."}),l.publishedAt&&e.jsxs(v,{variant:"outline",size:"sm",className:"w-full mt-2",onClick:()=>{he({kind:"published"}),se(!0)},children:[e.jsx(Xn,{className:"mr-2 h-4 w-4"}),"View published"]})]})]}),e.jsx(qa,{host:a,contentId:s,onViewVersion:d=>{he({kind:"history",blockId:d.blockId,createdAt:d.createdAt,title:d.title}),se(!0)}}),!I&&e.jsx(Ha,{deleteOpen:fs,setDeleteOpen:gs,onDelete:Os,host:a,contentId:s})]});return e.jsxs("div",{className:"mx-auto max-w-6xl",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 md:mb-6 md:flex-nowrap md:gap-3 md:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 md:gap-3",children:[e.jsx("h1",{className:"truncate text-xl font-semibold md:text-2xl",children:I?C?.label??t:L||"Untitled"}),e.jsx(ce,{variant:St.variant,children:St.label}),m.isSaving&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(z,{className:"h-3 w-3 animate-spin"}),"Saving..."]}),!m.isSaving&&m.lastSavedAt&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ot,{className:"h-3 w-3"}),"Saved"]})]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(v,{variant:"outline",onClick:()=>m.flush({createVersion:!0}),disabled:m.isSaving,children:[m.isSaving&&e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}),"Save Draft"]}),$==="scheduled"&&e.jsxs(e.Fragment,{children:[e.jsxs(v,{variant:"outline",onClick:Ms,disabled:g.isPending,children:[g.isPending&&e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancel Schedule"]}),e.jsxs(v,{onClick:()=>void ge(),disabled:u.isPending,children:[u.isPending&&e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}),"Publish Now"]})]}),$!=="scheduled"&&kt&&e.jsxs("div",{className:"flex",children:[e.jsxs(v,{onClick:Ts,disabled:u.isPending,className:"rounded-r-none",children:[u.isPending&&e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}),kt]}),!l.publishedAt&&e.jsxs(Tt,{children:[e.jsx(Lt,{asChild:!0,children:e.jsx(v,{className:"rounded-l-none border-l px-2",disabled:u.isPending,children:e.jsx(un,{className:"h-4 w-4"})})}),e.jsx(_t,{align:"end",children:e.jsxs(Me,{onClick:()=>xe(!0),children:[e.jsx(Ft,{className:"mr-2 h-4 w-4"}),"Schedule for later"]})})]})]}),l.publishedAt&&e.jsxs(Tt,{children:[e.jsx(Lt,{asChild:!0,children:e.jsx(v,{variant:"outline",size:"icon",children:e.jsx(Sn,{className:"h-4 w-4"})})}),e.jsxs(_t,{align:"end",children:[$==="published-changes"&&e.jsxs(Me,{onClick:_s,disabled:Nt.isPending,children:[e.jsx(ta,{className:"mr-2 h-4 w-4"}),"Discard Changes"]}),e.jsx(Me,{onClick:Ls,className:"text-destructive focus:text-destructive",children:"Unpublish"})]})]})]})]}),j?e.jsxs(Gt,{defaultValue:"content",children:[e.jsxs(Qt,{variant:"line",className:"mb-2",children:[e.jsx(ve,{value:"content",children:"Content"}),e.jsx(ve,{value:"info",children:"Info"})]}),e.jsx(ye,{value:"content",className:"mt-0",children:Pt}),e.jsx(ye,{value:"info",className:"mt-0",children:Dt})]}):e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:"lg:col-span-2",children:Pt}),e.jsx("div",{children:Dt})]}),e.jsx(Ca,{open:vs,onOpenChange:d=>{se(d),d||he(null)},host:a,contentId:s,collectionFields:w,isSingleton:I,isPublished:!!l.publishedAt,draftBody:Y,draftMetadata:I?void 0:{title:L,slug:O,snippet:R,tags:Q},initialVersion:ys,collectionRelationships:T,draftRelationships:X}),e.jsx(kn,{open:Te,onOpenChange:me,children:e.jsxs(Pn,{children:[e.jsxs(Dn,{children:[e.jsx(In,{children:"Publish changes?"}),e.jsx(An,{children:M?e.jsxs(e.Fragment,{children:[M.added>0&&e.jsxs("span",{className:"text-green-600",children:["+",M.added," added"]}),M.added>0&&M.removed>0&&", ",M.removed>0&&e.jsxs("span",{className:"text-red-600",children:["-",M.removed," removed"]}),M.added===0&&M.removed===0&&e.jsx("span",{children:"No visible changes detected."})]}):"This will update the published version with your current changes."})]}),e.jsx("div",{className:"mb-2",children:e.jsx(v,{variant:"link",className:"p-0 h-auto text-sm",onClick:()=>{me(!1),he({kind:"published"}),se(!0)},children:"View full diff"})}),e.jsxs(Tn,{children:[e.jsx(Ln,{children:"Cancel"}),e.jsx(_n,{onClick:()=>{me(!1),ge()},children:"Publish Update"})]})]})}),e.jsx(be,{open:bs,onOpenChange:pe,children:e.jsxs(Ne,{children:[e.jsxs(Ce,{children:[e.jsx(we,{children:"Slug change detected"}),e.jsxs(Se,{children:["You are changing the slug from “",l.slug,"” to “",O,"”. This may break external bookmarks and SEO links."]})]}),e.jsx(Ba,{host:a,contentId:s}),e.jsxs(Ue,{children:[e.jsx(v,{variant:"outline",onClick:()=>pe(!1),children:"Cancel"}),e.jsx(v,{onClick:()=>{pe(!1),ge()},children:"Publish Anyway"})]})]})}),e.jsx(be,{open:Ns,onOpenChange:xe,children:e.jsxs(Ne,{children:[e.jsxs(Ce,{children:[e.jsx(we,{children:"Schedule publishing"}),e.jsx(Se,{children:"Choose a date and time to automatically publish this content. Times are rounded to the nearest 15-minute interval."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{htmlFor:"schedule-date",children:"Publish at"}),e.jsx("input",{id:"schedule-date",type:"datetime-local",value:fe,onChange:d=>yt(d.target.value),min:Oe(Date.now()+1200*1e3),className:"w-full rounded-md border px-3 py-2 text-sm",step:"900"})]}),e.jsxs(Ue,{children:[e.jsx(v,{variant:"outline",onClick:()=>xe(!1),children:"Cancel"}),e.jsxs(v,{onClick:Fs,disabled:!fe||f.isPending,children:[f.isPending&&e.jsx(z,{className:"mr-2 h-4 w-4 animate-spin"}),"Schedule"]})]})]})})]})}function Ba({host:a,contentId:t}){const{data:s}=Jt(a,t,!0);return!s||s.count===0?null:e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-50 p-3 text-sm dark:bg-yellow-950/30",children:[e.jsxs("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:["This content is referenced by ",s.count," other"," ",s.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[s.items.slice(0,5).map(l=>e.jsxs("li",{children:[l.title," (",l.collection,")"]},`${l.contentId}-${l.fieldName}`)),s.items.length>5&&e.jsxs("li",{children:["and ",s.items.length-5," more..."]})]})]})}function Ha({deleteOpen:a,setDeleteOpen:t,onDelete:s,host:l,contentId:n}){const{data:i}=Jt(l,n,a);return e.jsxs(e.Fragment,{children:[e.jsx(hn,{}),e.jsxs(be,{open:a,onOpenChange:t,children:[e.jsx(mn,{asChild:!0,children:e.jsxs(v,{variant:"destructive",className:"w-full",children:[e.jsx(rs,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ne,{children:[e.jsxs(Ce,{children:[e.jsx(we,{children:"Delete content?"}),e.jsx(Se,{children:"This action cannot be undone. The content will be permanently deleted."})]}),i&&i.count>0&&e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-50 p-3 text-sm dark:bg-yellow-950/30",children:[e.jsxs("p",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:["This content is referenced by ",i.count," other"," ",i.count===1?"item":"items",":"]}),e.jsxs("ul",{className:"mt-1 list-disc pl-5 text-yellow-700 dark:text-yellow-300",children:[i.items.slice(0,5).map(r=>e.jsxs("li",{children:[r.title," (",r.collection,")"]},`${r.contentId}-${r.fieldName}`)),i.items.length>5&&e.jsxs("li",{children:["and ",i.items.length-5," more..."]})]})]}),e.jsxs(Ue,{children:[e.jsx(v,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(v,{variant:"destructive",onClick:s,children:"Delete"})]})]})]})]})}function qa({host:a,contentId:t,onViewVersion:s}){const{data:l}=qt(a,t),[n,i]=x.useState(!1),r=l?.items??[],o=r.map(u=>u.createdBy).filter(Boolean),{resolve:c}=pn(o);return r.length===0?null:e.jsx(B,{children:e.jsx(J,{className:"pt-4",children:e.jsxs(es,{open:n,onOpenChange:i,children:[e.jsxs(ts,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(is,{className:K("h-4 w-4 transition",n&&"rotate-90")}),"Version History (",r.length,")"]}),e.jsx(ss,{className:"mt-2",children:e.jsx("div",{className:"space-y-1",children:r.map((u,p)=>e.jsxs("button",{className:"py-1 text-sm hover:bg-muted rounded px-1 -mx-1 transition-colors w-full text-left",onClick:()=>s(u),children:[e.jsx("span",{children:q(u.createdAt)}),u.createdBy&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:c(u.createdBy)}),u.title&&e.jsx("span",{className:"ml-2 text-muted-foreground",children:u.title})]},`${u.createdAt}-${p}`))})})]})})})}const xl=Object.freeze(Object.defineProperty({__proto__:null,ContentEditPage:Wa},Symbol.toStringTag,{value:"Module"}));export{Ie as C,ms as F,us as M,Kn as P,xl as a};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-BO6c-AOu.js";import{u as fe,e as ve,r as o}from"./react-vendor-DNVhVxD7.js";import{o as be,v as Ne,B,t as m,I as le,X as I,L as U,S as Se,a as Ce,w as we}from"./index-CwkwXbO-.js";import{d as ke,e as ye,a as _e,b as Ae,c as Ie}from"./useContent-Cp41wBYR.js";import{u as Pe}from"./useTags-BB47vbXO.js";import{u as Te}from"./useDebouncedValue-Bf8UizjU.js";import{u as $e,m as te}from"./use-mobile-Cvl5tIVY.js";import{B as N}from"./badge-ChZ2DZue.js";import{C as Me,c as Be}from"./card-DpNr7WTb.js";import{C as F}from"./checkbox-VtCfoGic.js";import{P as Ue,a as De,b as Ve}from"./popover-DFInMOpa.js";import{S as j,a as p,b as g,c as f,d as r}from"./select-Cj54Wt-H.js";import{T as Le,a as qe,b as ne,c as P,d as ze,e as T}from"./table-D4rLgOKa.js";import{a as D,f as ce}from"./format-C88SDH8g.js";import{g as re,a as ie}from"./contentStatus-BmaiYVOm.js";import{B as Oe}from"./BulkActionBar-BX-t8fyM.js";import{P as Fe}from"./plus-2Ds_MoqB.js";import{S as de}from"./search-DRNC6QB5.js";import"./radix-n1vDIPi6.js";import"./check-BMpruHpO.js";const He=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Re=be("sliders-horizontal",He),V=3,oe=[{value:"updated_desc",label:"Last updated"},{value:"updated_asc",label:"Oldest updated"},{value:"title_asc",label:"Title A–Z",requiresCollection:!0},{value:"title_desc",label:"Title Z–A",requiresCollection:!0},{value:"created_desc",label:"Newest created"},{value:"created_asc",label:"Oldest created"}],H=[{value:"all",label:"All statuses"},{value:"draft",label:"Draft"},{value:"published",label:"Published"},{value:"changed",label:"Changed"},{value:"unpublished",label:"Unpublished"},{value:"scheduled",label:"Scheduled"}];function us(){const{host:i,collection:n}=fe(),w=ve(),{collections:ue}=Ne(),[k,y]=o.useState(""),[_,R]=o.useState("prefix"),[u,L]=o.useState(),[h,q]=o.useState(),[S,E]=o.useState("updated_desc"),[he,X]=o.useState(),[d,v]=o.useState(new Set),Z=$e(),b=Te(k,300),l=o.useCallback(()=>X(void 0),[]),xe=o.useMemo(()=>{const s={};return b&&(s.q=b,s.search=_),u&&(s.tag=u),h&&(s.status=h),S!=="updated_desc"&&(s.sort=S),s},[b,_,u,h,S]),C=ue.find(s=>s.name===n),{data:A,isLoading:me}=ke(i,n,xe,he),z=ye(i),G=_e(i),Q=Ae(i),J=Ie(i),{data:K}=Pe(i),$=o.useMemo(()=>K?.map(s=>s.tag)??[],[K]);if(C?.singleton&&A?.items.length===1)return w(`/sites/${i}/content/${n}/${A.items[0].contentId}`,{replace:!0}),null;const M=A?.items,O=M?.map(s=>s.contentId)??[],W=O.length>0&&O.every(s=>d.has(s));function Y(s){v(c=>{const a=new Set(c);return a.has(s)?a.delete(s):a.add(s),a})}function je(){v(W?new Set:new Set(O))}const ee=!!(b||u||h),se=!!b,ae=[_!=="prefix"?1:0,u?1:0,h?1:0,S!=="updated_desc"?1:0].reduce((s,c)=>s+c,0),pe=G.isPending||Q.isPending||J.isPending;async function ge(){try{const s=await z.mutateAsync({collection:n,title:C?.label??n});m.success("Singleton content recreated"),w(`/sites/${i}/content/${n}/${s.contentId}`)}catch(s){m.error("Failed to recreate singleton",{description:s instanceof Error?s.message:void 0})}}return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:C?.label??n}),!C?.singleton&&e.jsxs(B,{onClick:()=>w(`/sites/${i}/content/${n}/new`),children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),"New"]})]}),d.size>0?e.jsx(Oe,{selectedCount:d.size,onPublish:async()=>{const s=[...d],a=(await G.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to publish`):m.success(`${s.length} item(s) published`),v(new Set)},onUnpublish:async()=>{const s=[...d],a=(await Q.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to unpublish`):m.success(`${s.length} item(s) unpublished`),v(new Set)},onDelete:async()=>{const s=[...d],a=(await J.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to delete`):m.success(`${s.length} item(s) deleted`),v(new Set)},onClear:()=>v(new Set),isPending:pe}):Z?e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"Search...",value:k,onChange:s=>{y(s.target.value),l()},className:"pl-8 pr-8"}),k&&e.jsx("button",{onClick:()=>{y(""),l()},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:e.jsx(I,{className:"h-4 w-4"})})]}),e.jsxs(Ue,{children:[e.jsx(De,{asChild:!0,children:e.jsxs(B,{variant:"outline",size:"icon",className:"relative shrink-0","aria-label":"Filters",children:[e.jsx(Re,{className:"h-4 w-4"}),ae>0&&e.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] text-primary-foreground",children:ae})]})}),e.jsxs(Ve,{className:"w-64 space-y-3",align:"end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Search Mode"}),e.jsxs(j,{value:_,onValueChange:s=>{R(s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"prefix",children:"Starts with"}),e.jsx(r,{value:"full",children:"Contains"})]})]})]}),$.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Tag"}),e.jsxs(j,{value:u??"__all__",onValueChange:s=>{L(s==="__all__"?void 0:s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"__all__",children:"All tags"}),$.map(s=>e.jsx(r,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Status"}),e.jsxs(j,{value:h??"all",onValueChange:s=>{q(s==="all"?void 0:s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsx(f,{children:H.map(s=>e.jsx(r,{value:s.value??"all",children:s.label},s.value??"all"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Sort"}),e.jsxs(j,{value:S,onValueChange:s=>{E(s),l()},disabled:se,children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsx(f,{children:oe.map(s=>e.jsx(r,{value:s.value,disabled:s.requiresCollection&&!n,children:s.label},s.value))})]})]})]})]})]}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(de,{className:"absolute left-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"Search titles...",value:k,onChange:s=>{y(s.target.value),l()},className:"w-56 pl-8 pr-8"}),k&&e.jsx("button",{onClick:()=>{y(""),l()},className:"absolute right-2 text-muted-foreground hover:text-foreground",children:e.jsx(I,{className:"h-4 w-4"})})]}),e.jsxs(j,{value:_,onValueChange:s=>{R(s),l()},children:[e.jsx(p,{className:"w-[130px]",children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"prefix",children:"Starts with"}),e.jsx(r,{value:"full",children:"Contains"})]})]}),$.length>0&&e.jsxs(j,{value:u??"__all__",onValueChange:s=>{L(s==="__all__"?void 0:s),l()},children:[e.jsx(p,{className:"w-[140px]",children:e.jsx(g,{placeholder:"Tag"})}),e.jsxs(f,{children:[e.jsx(r,{value:"__all__",children:"All tags"}),$.map(s=>e.jsx(r,{value:s,children:s},s))]})]}),e.jsxs(j,{value:h??"all",onValueChange:s=>{q(s==="all"?void 0:s),l()},children:[e.jsx(p,{className:"w-[150px]",children:e.jsx(g,{})}),e.jsx(f,{children:H.map(s=>e.jsx(r,{value:s.value??"all",children:s.label},s.value??"all"))})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(j,{value:S,onValueChange:s=>{E(s),l()},disabled:se,children:[e.jsx(p,{className:"w-[170px]",children:e.jsx(g,{})}),e.jsx(f,{children:oe.map(s=>e.jsx(r,{value:s.value,disabled:s.requiresCollection&&!n,children:s.label},s.value))})]})})]}),ee&&d.size===0&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[b&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Search: ",b,e.jsx("button",{onClick:()=>{y(""),l()},children:e.jsx(I,{className:"h-3 w-3"})})]}),u&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Tag: ",u,e.jsx("button",{onClick:()=>{L(void 0),l()},children:e.jsx(I,{className:"h-3 w-3"})})]}),h&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Status: ",H.find(s=>s.value===h)?.label,e.jsx("button",{onClick:()=>{q(void 0),l()},children:e.jsx(I,{className:"h-3 w-3"})})]})]}),me?e.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((s,c)=>e.jsx(Se,{className:"h-12 w-full"},c))}):M?.length?e.jsxs(e.Fragment,{children:[Z?e.jsx("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"content-card-view",children:M.map(s=>{const c=re(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId,s.scheduledAt,s.scheduledFailed),a=ie(c),t=s.tags??[];return e.jsx(Me,{className:we("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",d.has(s.contentId)&&"ring-2 ring-primary"),onClick:()=>w(`/sites/${i}/content/${n}/${s.contentId}`),children:e.jsxs(Be,{className:"p-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[s.coverUrl&&e.jsx("img",{src:te(s.coverUrl),alt:"",className:"h-12 w-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"font-medium truncate",children:s.title||"Untitled"}),e.jsx(N,{variant:a.variant,className:"shrink-0",children:a.label})]}),s.slug&&e.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["/",s.slug]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.lastDraftAt?D(s.lastDraftAt):"—"})]}),e.jsx(F,{checked:d.has(s.contentId),onCheckedChange:()=>Y(s.contentId),onClick:x=>x.stopPropagation(),className:"mt-1"})]}),t.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:t.slice(0,V).map(x=>e.jsx(N,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:x},x))})]})},s.contentId)})}):e.jsxs(Le,{children:[e.jsx(qe,{children:e.jsxs(ne,{children:[e.jsx(P,{className:"w-10",children:e.jsx(F,{checked:W,onCheckedChange:je,"aria-label":"Select all"})}),e.jsx(P,{children:"Title"}),e.jsx(P,{children:"Slug"}),e.jsx(P,{children:"Status"}),e.jsx(P,{children:"Updated"})]})}),e.jsx(ze,{children:M.map(s=>{const c=re(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId),a=ie(c),t=s.tags??[];return e.jsxs(ne,{className:"cursor-pointer",onClick:()=>w(`/sites/${i}/content/${n}/${s.contentId}`),children:[e.jsx(T,{onClick:x=>x.stopPropagation(),children:e.jsx(F,{checked:d.has(s.contentId),onCheckedChange:()=>Y(s.contentId),"aria-label":`Select ${s.title||"Untitled"}`})}),e.jsx(T,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-3",children:[s.coverUrl&&e.jsx("img",{src:te(s.coverUrl),alt:"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:s.title||"Untitled"}),t.length>0&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap gap-1",children:[t.slice(0,V).map(x=>e.jsx(N,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal text-muted-foreground",children:x},x)),t.length>V&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",t.length-V," more"]})]})]})]})}),e.jsx(T,{className:"text-muted-foreground text-sm",children:s.slug||"—"}),e.jsx(T,{children:e.jsx(N,{variant:a.variant,children:a.label})}),e.jsx(T,{className:"text-muted-foreground",children:s.scheduledAt&&!s.publishedAt?e.jsxs("span",{title:ce(s.scheduledAt),children:["Scheduled ",D(s.scheduledAt)]}):s.publishedAt?e.jsx("span",{title:ce(s.publishedAt),children:D(s.publishedAt)}):s.lastDraftAt?D(s.lastDraftAt):"—"})]},s.contentId)})})]}),A?.hasMore&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(B,{variant:"outline",onClick:()=>X(A.cursor??void 0),children:"Load More"})})]}):C?.singleton?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Singleton content is missing. Click below to recreate it."}),e.jsxs(B,{onClick:ge,disabled:z.isPending,children:[z.isPending&&e.jsx(Ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Recreate ",C.label]})]}):e.jsx("p",{className:"text-muted-foreground",children:ee?"No content matches the current filters.":"No content yet."})]})}export{us as ContentListPage};
1
+ import{j as e}from"./tanstack-oFmRhGwV.js";import{u as fe,e as ve,r as o}from"./react-vendor-B0Dih9Pj.js";import{o as be,v as Ne,B,t as m,I as le,X as I,L as U,S as Se,a as Ce,w as we}from"./index-DX9xeoQx.js";import{d as ke,e as ye,a as _e,b as Ae,c as Ie}from"./useContent-f19XHVlJ.js";import{u as Pe}from"./useTags-BuXf7_7H.js";import{u as Te}from"./useDebouncedValue-DHUCnm9B.js";import{u as $e,m as te}from"./use-mobile-C1r2eP64.js";import{B as N}from"./badge-B8OxObuF.js";import{C as Me,c as Be}from"./card-C7fgQS_U.js";import{C as F}from"./checkbox-BV2kjQBe.js";import{P as Ue,a as De,b as Ve}from"./popover-Cou924mw.js";import{S as j,a as p,b as g,c as f,d as r}from"./select-CHW5R8qv.js";import{T as Le,a as qe,b as ne,c as P,d as ze,e as T}from"./table-BjSue8Ev.js";import{a as D,f as ce}from"./format-C88SDH8g.js";import{g as re,a as ie}from"./contentStatus-BmaiYVOm.js";import{B as Oe}from"./BulkActionBar-C-88Wnqw.js";import{P as Fe}from"./plus-HdRn2U0S.js";import{S as de}from"./search-C-3Q9nn7.js";import"./radix-lA_IxTIV.js";import"./check-CxKAR64t.js";const He=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Re=be("sliders-horizontal",He),V=3,oe=[{value:"updated_desc",label:"Last updated"},{value:"updated_asc",label:"Oldest updated"},{value:"title_asc",label:"Title A–Z",requiresCollection:!0},{value:"title_desc",label:"Title Z–A",requiresCollection:!0},{value:"created_desc",label:"Newest created"},{value:"created_asc",label:"Oldest created"}],H=[{value:"all",label:"All statuses"},{value:"draft",label:"Draft"},{value:"published",label:"Published"},{value:"changed",label:"Changed"},{value:"unpublished",label:"Unpublished"},{value:"scheduled",label:"Scheduled"}];function us(){const{host:i,collection:n}=fe(),w=ve(),{collections:ue}=Ne(),[k,y]=o.useState(""),[_,R]=o.useState("prefix"),[u,L]=o.useState(),[h,q]=o.useState(),[S,E]=o.useState("updated_desc"),[he,X]=o.useState(),[d,v]=o.useState(new Set),Z=$e(),b=Te(k,300),l=o.useCallback(()=>X(void 0),[]),xe=o.useMemo(()=>{const s={};return b&&(s.q=b,s.search=_),u&&(s.tag=u),h&&(s.status=h),S!=="updated_desc"&&(s.sort=S),s},[b,_,u,h,S]),C=ue.find(s=>s.name===n),{data:A,isLoading:me}=ke(i,n,xe,he),z=ye(i),G=_e(i),Q=Ae(i),J=Ie(i),{data:K}=Pe(i),$=o.useMemo(()=>K?.map(s=>s.tag)??[],[K]);if(C?.singleton&&A?.items.length===1)return w(`/sites/${i}/content/${n}/${A.items[0].contentId}`,{replace:!0}),null;const M=A?.items,O=M?.map(s=>s.contentId)??[],W=O.length>0&&O.every(s=>d.has(s));function Y(s){v(c=>{const a=new Set(c);return a.has(s)?a.delete(s):a.add(s),a})}function je(){v(W?new Set:new Set(O))}const ee=!!(b||u||h),se=!!b,ae=[_!=="prefix"?1:0,u?1:0,h?1:0,S!=="updated_desc"?1:0].reduce((s,c)=>s+c,0),pe=G.isPending||Q.isPending||J.isPending;async function ge(){try{const s=await z.mutateAsync({collection:n,title:C?.label??n});m.success("Singleton content recreated"),w(`/sites/${i}/content/${n}/${s.contentId}`)}catch(s){m.error("Failed to recreate singleton",{description:s instanceof Error?s.message:void 0})}}return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:C?.label??n}),!C?.singleton&&e.jsxs(B,{onClick:()=>w(`/sites/${i}/content/${n}/new`),children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),"New"]})]}),d.size>0?e.jsx(Oe,{selectedCount:d.size,onPublish:async()=>{const s=[...d],a=(await G.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to publish`):m.success(`${s.length} item(s) published`),v(new Set)},onUnpublish:async()=>{const s=[...d],a=(await Q.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to unpublish`):m.success(`${s.length} item(s) unpublished`),v(new Set)},onDelete:async()=>{const s=[...d],a=(await J.mutateAsync(s)).filter(t=>t.status==="rejected").length;a?m.error(`${a} of ${s.length} failed to delete`):m.success(`${s.length} item(s) deleted`),v(new Set)},onClear:()=>v(new Set),isPending:pe}):Z?e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(de,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"Search...",value:k,onChange:s=>{y(s.target.value),l()},className:"pl-8 pr-8"}),k&&e.jsx("button",{onClick:()=>{y(""),l()},className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:e.jsx(I,{className:"h-4 w-4"})})]}),e.jsxs(Ue,{children:[e.jsx(De,{asChild:!0,children:e.jsxs(B,{variant:"outline",size:"icon",className:"relative shrink-0","aria-label":"Filters",children:[e.jsx(Re,{className:"h-4 w-4"}),ae>0&&e.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] text-primary-foreground",children:ae})]})}),e.jsxs(Ve,{className:"w-64 space-y-3",align:"end",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Search Mode"}),e.jsxs(j,{value:_,onValueChange:s=>{R(s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"prefix",children:"Starts with"}),e.jsx(r,{value:"full",children:"Contains"})]})]})]}),$.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Tag"}),e.jsxs(j,{value:u??"__all__",onValueChange:s=>{L(s==="__all__"?void 0:s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"__all__",children:"All tags"}),$.map(s=>e.jsx(r,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Status"}),e.jsxs(j,{value:h??"all",onValueChange:s=>{q(s==="all"?void 0:s),l()},children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsx(f,{children:H.map(s=>e.jsx(r,{value:s.value??"all",children:s.label},s.value??"all"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{className:"text-xs font-medium",children:"Sort"}),e.jsxs(j,{value:S,onValueChange:s=>{E(s),l()},disabled:se,children:[e.jsx(p,{children:e.jsx(g,{})}),e.jsx(f,{children:oe.map(s=>e.jsx(r,{value:s.value,disabled:s.requiresCollection&&!n,children:s.label},s.value))})]})]})]})]})]}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx(de,{className:"absolute left-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(le,{placeholder:"Search titles...",value:k,onChange:s=>{y(s.target.value),l()},className:"w-56 pl-8 pr-8"}),k&&e.jsx("button",{onClick:()=>{y(""),l()},className:"absolute right-2 text-muted-foreground hover:text-foreground",children:e.jsx(I,{className:"h-4 w-4"})})]}),e.jsxs(j,{value:_,onValueChange:s=>{R(s),l()},children:[e.jsx(p,{className:"w-[130px]",children:e.jsx(g,{})}),e.jsxs(f,{children:[e.jsx(r,{value:"prefix",children:"Starts with"}),e.jsx(r,{value:"full",children:"Contains"})]})]}),$.length>0&&e.jsxs(j,{value:u??"__all__",onValueChange:s=>{L(s==="__all__"?void 0:s),l()},children:[e.jsx(p,{className:"w-[140px]",children:e.jsx(g,{placeholder:"Tag"})}),e.jsxs(f,{children:[e.jsx(r,{value:"__all__",children:"All tags"}),$.map(s=>e.jsx(r,{value:s,children:s},s))]})]}),e.jsxs(j,{value:h??"all",onValueChange:s=>{q(s==="all"?void 0:s),l()},children:[e.jsx(p,{className:"w-[150px]",children:e.jsx(g,{})}),e.jsx(f,{children:H.map(s=>e.jsx(r,{value:s.value??"all",children:s.label},s.value??"all"))})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(j,{value:S,onValueChange:s=>{E(s),l()},disabled:se,children:[e.jsx(p,{className:"w-[170px]",children:e.jsx(g,{})}),e.jsx(f,{children:oe.map(s=>e.jsx(r,{value:s.value,disabled:s.requiresCollection&&!n,children:s.label},s.value))})]})})]}),ee&&d.size===0&&e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[b&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Search: ",b,e.jsx("button",{onClick:()=>{y(""),l()},children:e.jsx(I,{className:"h-3 w-3"})})]}),u&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Tag: ",u,e.jsx("button",{onClick:()=>{L(void 0),l()},children:e.jsx(I,{className:"h-3 w-3"})})]}),h&&e.jsxs(N,{variant:"secondary",className:"gap-1",children:["Status: ",H.find(s=>s.value===h)?.label,e.jsx("button",{onClick:()=>{q(void 0),l()},children:e.jsx(I,{className:"h-3 w-3"})})]})]}),me?e.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((s,c)=>e.jsx(Se,{className:"h-12 w-full"},c))}):M?.length?e.jsxs(e.Fragment,{children:[Z?e.jsx("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"content-card-view",children:M.map(s=>{const c=re(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId,s.scheduledAt,s.scheduledFailed),a=ie(c),t=s.tags??[];return e.jsx(Me,{className:we("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",d.has(s.contentId)&&"ring-2 ring-primary"),onClick:()=>w(`/sites/${i}/content/${n}/${s.contentId}`),children:e.jsxs(Be,{className:"p-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[s.coverUrl&&e.jsx("img",{src:te(s.coverUrl),alt:"",className:"h-12 w-12 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"font-medium truncate",children:s.title||"Untitled"}),e.jsx(N,{variant:a.variant,className:"shrink-0",children:a.label})]}),s.slug&&e.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["/",s.slug]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.lastDraftAt?D(s.lastDraftAt):"—"})]}),e.jsx(F,{checked:d.has(s.contentId),onCheckedChange:()=>Y(s.contentId),onClick:x=>x.stopPropagation(),className:"mt-1"})]}),t.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1",children:t.slice(0,V).map(x=>e.jsx(N,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:x},x))})]})},s.contentId)})}):e.jsxs(Le,{children:[e.jsx(qe,{children:e.jsxs(ne,{children:[e.jsx(P,{className:"w-10",children:e.jsx(F,{checked:W,onCheckedChange:je,"aria-label":"Select all"})}),e.jsx(P,{children:"Title"}),e.jsx(P,{children:"Slug"}),e.jsx(P,{children:"Status"}),e.jsx(P,{children:"Updated"})]})}),e.jsx(ze,{children:M.map(s=>{const c=re(s.publishedAt,s.lastPublishedAt,s.publishedBlockId,s.lastDraftBlockId),a=ie(c),t=s.tags??[];return e.jsxs(ne,{className:"cursor-pointer",onClick:()=>w(`/sites/${i}/content/${n}/${s.contentId}`),children:[e.jsx(T,{onClick:x=>x.stopPropagation(),children:e.jsx(F,{checked:d.has(s.contentId),onCheckedChange:()=>Y(s.contentId),"aria-label":`Select ${s.title||"Untitled"}`})}),e.jsx(T,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-3",children:[s.coverUrl&&e.jsx("img",{src:te(s.coverUrl),alt:"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{children:s.title||"Untitled"}),t.length>0&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap gap-1",children:[t.slice(0,V).map(x=>e.jsx(N,{variant:"outline",className:"text-[10px] px-1.5 py-0 font-normal text-muted-foreground",children:x},x)),t.length>V&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",t.length-V," more"]})]})]})]})}),e.jsx(T,{className:"text-muted-foreground text-sm",children:s.slug||"—"}),e.jsx(T,{children:e.jsx(N,{variant:a.variant,children:a.label})}),e.jsx(T,{className:"text-muted-foreground",children:s.scheduledAt&&!s.publishedAt?e.jsxs("span",{title:ce(s.scheduledAt),children:["Scheduled ",D(s.scheduledAt)]}):s.publishedAt?e.jsx("span",{title:ce(s.publishedAt),children:D(s.publishedAt)}):s.lastDraftAt?D(s.lastDraftAt):"—"})]},s.contentId)})})]}),A?.hasMore&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(B,{variant:"outline",onClick:()=>X(A.cursor??void 0),children:"Load More"})})]}):C?.singleton?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Singleton content is missing. Click below to recreate it."}),e.jsxs(B,{onClick:ge,disabled:z.isPending,children:[z.isPending&&e.jsx(Ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Recreate ",C.label]})]}):e.jsx("p",{className:"text-muted-foreground",children:ee?"No content matches the current filters.":"No content yet."})]})}export{us as ContentListPage};
@@ -1,4 +1,4 @@
1
- import{_ as Qt}from"./index-CwkwXbO-.js";import{j as q}from"./tanstack-BO6c-AOu.js";import{r as ie}from"./react-vendor-DNVhVxD7.js";class z{constructor(e,n,r,s,i){this.kind=e,this.input=n,this.begin=r,this.end=s,this.file=i}getText(){return this.input.slice(this.begin,this.end)}getPosition(){let[e,n]=[1,1];for(let r=0;r<this.begin;r++)this.input[r]===`
1
+ import{_ as Qt}from"./index-DX9xeoQx.js";import{j as q}from"./tanstack-oFmRhGwV.js";import{r as ie}from"./react-vendor-B0Dih9Pj.js";class z{constructor(e,n,r,s,i){this.kind=e,this.input=n,this.begin=r,this.end=s,this.file=i}getText(){return this.input.slice(this.begin,this.end)}getPosition(){let[e,n]=[1,1];for(let r=0;r<this.begin;r++)this.input[r]===`
2
2
  `?(e++,n=1):n++;return[e,n]}size(){return this.end-this.begin}}class J{liquidMethodMissing(e,n){}}const Gt=Object.prototype.toString,He=String.prototype.toLowerCase,Re=Object.hasOwnProperty;function f(t){return typeof t=="string"}function T(t){return typeof t=="function"}function Xt(t){return t&&T(t.then)}function he(t){return t&&T(t.next)&&T(t.throw)&&T(t.return)}function Kt(t){return t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function u(t){return t=p(t),f(t)?t:O(t)?"":_(t)?t.map(e=>u(e)).join(""):String(t)}function se(t){return t=p(t),_(t)?t:f(t)&&t.length>0?[t]:tn(t)?Array.from(t):me(t)?Object.keys(t).map(e=>[e,t[e]]):[]}function v(t){return t=p(t),O(t)?[]:_(t)?t:[t]}function p(t){return t instanceof J&&T(t.valueOf)?t.valueOf():t}function Se(t){return+p(t)||0}function ge(t){return typeof t=="number"}function wt(t){return t&&T(t.toLiquid)?wt(t.toLiquid()):t}function O(t){return t==null}function en(t){return t===void 0}function _(t){return Gt.call(t)==="[object Array]"}function bt(t){return t&&ge(t.length)}function tn(t){return me(t)&&Symbol.iterator in t}function We(t,e){t=t||{};for(const n in t)if(Re.call(t,n)&&e(t[n],n,t)===!1)break;return t}function xt(t){return t[t.length-1]}function me(t){const e=typeof t;return t!==null&&(e==="object"||e==="function")}function Tt(t,e,n=1){const r=[];for(let s=t;s<e;s+=n)r.push(s);return r}function re(t,e,n=" "){return vt(t,e,n,(r,s)=>s+r)}function nn(t,e,n=" "){return vt(t,e,n,(r,s)=>r+s)}function vt(t,e,n,r){t=String(t);let s=e-t.length;for(;s-- >0;)t=r(t,n);return t}function _t(t){return t}function rn(t){return[...t].some(n=>n>="a"&&n<="z")?t.toUpperCase():t.toLowerCase()}function sn(t,e){return t.length>e?t.slice(0,e-3)+"...":t}function Ye(t,e){return t==null&&e==null?0:t==null?1:e==null||(t=He.call(t),e=He.call(e),t<e)?-1:t>e?1:0}function ye(t){return function(...e){return t.call(this,...e.map(p))}}function D(t){return function(...e){return t.call(this,...e.map(Se))}}function Ee(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function*oe(t){const e=new Set;for(const n of t){const r=JSON.stringify(n);e.has(r)||(e.add(r),yield n)}}const Je="__liquidClass__";class Z extends Error{constructor(e,n){super(typeof e=="string"?e:e.message),this.context="",typeof e!="string"&&Object.defineProperty(this,"originalError",{value:e,enumerable:!1}),Object.defineProperty(this,"token",{value:n,enumerable:!1}),Object.defineProperty(this,Je,{value:"LiquidError",enumerable:!1})}update(){Object.defineProperty(this,"context",{value:fn(this.token),enumerable:!1}),this.message=dn(this.message,this.token),this.stack=this.message+`
3
3
  `+this.context+`
4
4
  `+this.stack,this.originalError&&(this.stack+=`
@@ -1,3 +1,3 @@
1
- import{j as e}from"./tanstack-BO6c-AOu.js";import{r as j}from"./react-vendor-DNVhVxD7.js";import{C as O,G as D,b as M,u as P,a as q,P as A,D as $,c as z}from"./core.esm-BtFZvlg0.js";import{T as V,u as _,C as G,b as U,c as Y,S as H,v as J,a as K}from"./sortable.esm-BUhmZW2_.js";import{I as p,w as T,N as Q,L as d,B as k}from"./index-CwkwXbO-.js";import{S as E,a as I,b as L,c as B,d as R}from"./select-Cj54Wt-H.js";import{d as F,i as W}from"./format-C88SDH8g.js";import{C as w}from"./checkbox-VtCfoGic.js";import{P as X}from"./plus-2Ds_MoqB.js";import{T as Z}from"./trash-2-CbbWF_O4.js";function ee({value:t,onChange:a,onBlur:x,readOnly:h,className:l,...s}){const[n,u]=j.useState(!1),m=j.useRef(void 0);j.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const g=j.useCallback(v=>{const N=v.target.value,f=F(N,"leading");a(f),N!==f&&N.length>0?(u(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>u(!1),2e3)):u(!1)},[a]),y=j.useCallback(()=>{const v=F(t,"all");v!==t&&a(v),x?.()},[t,a,x]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{value:t,onChange:g,onBlur:y,disabled:h,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:T("font-mono",l),...s}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function se({type:t,options:a,onChange:x}){const h=Q();function l(s,n){x({...a,[s]:n})}return e.jsxs("div",{className:"space-y-3",children:[!["boolean","blocks","array"].includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{id:"opt-required",checked:!!a.required,onCheckedChange:s=>l("required",!!s)}),e.jsx(d,{htmlFor:"opt-required",className:"text-sm",children:"Required"})]}),["text","textarea"].includes(t)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Placeholder"}),e.jsx(p,{value:a.placeholder??"",onChange:s=>l("placeholder",s.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Max Length"}),e.jsx(p,{type:"number",value:a.maxLength??"",onChange:s=>l("maxLength",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="number"&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Min"}),e.jsx(p,{type:"number",value:a.min??"",onChange:s=>l("min",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Max"}),e.jsx(p,{type:"number",value:a.max??"",onChange:s=>l("max",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Step"}),e.jsx(p,{type:"number",value:a.step??"",onChange:s=>l("step",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="select"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(V,{value:(a.choices??[]).join(`
1
+ import{j as e}from"./tanstack-oFmRhGwV.js";import{r as j}from"./react-vendor-B0Dih9Pj.js";import{C as O,G as D,b as M,u as P,a as q,P as A,D as $,c as z}from"./core.esm-DRuhixPo.js";import{T as V,u as _,C as G,b as U,c as Y,S as H,v as J,a as K}from"./sortable.esm-CBJBhe4k.js";import{I as p,w as T,N as Q,L as d,B as k}from"./index-DX9xeoQx.js";import{S as E,a as I,b as L,c as B,d as R}from"./select-CHW5R8qv.js";import{d as F,i as W}from"./format-C88SDH8g.js";import{C as w}from"./checkbox-BV2kjQBe.js";import{P as X}from"./plus-HdRn2U0S.js";import{T as Z}from"./trash-2-CWWRVuRB.js";function ee({value:t,onChange:a,onBlur:x,readOnly:h,className:l,...s}){const[n,u]=j.useState(!1),m=j.useRef(void 0);j.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const g=j.useCallback(v=>{const N=v.target.value,f=F(N,"leading");a(f),N!==f&&N.length>0?(u(!0),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>u(!1),2e3)):u(!1)},[a]),y=j.useCallback(()=>{const v=F(t,"all");v!==t&&a(v),x?.()},[t,a,x]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(p,{value:t,onChange:g,onBlur:y,disabled:h,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:T("font-mono",l),...s}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function se({type:t,options:a,onChange:x}){const h=Q();function l(s,n){x({...a,[s]:n})}return e.jsxs("div",{className:"space-y-3",children:[!["boolean","blocks","array"].includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{id:"opt-required",checked:!!a.required,onCheckedChange:s=>l("required",!!s)}),e.jsx(d,{htmlFor:"opt-required",className:"text-sm",children:"Required"})]}),["text","textarea"].includes(t)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Placeholder"}),e.jsx(p,{value:a.placeholder??"",onChange:s=>l("placeholder",s.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Max Length"}),e.jsx(p,{type:"number",value:a.maxLength??"",onChange:s=>l("maxLength",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="number"&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Min"}),e.jsx(p,{type:"number",value:a.min??"",onChange:s=>l("min",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Max"}),e.jsx(p,{type:"number",value:a.max??"",onChange:s=>l("max",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Step"}),e.jsx(p,{type:"number",value:a.step??"",onChange:s=>l("step",s.target.value?Number(s.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="select"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(V,{value:(a.choices??[]).join(`
2
2
  `),onChange:s=>l("choices",s.target.value.split(`
3
3
  `).map(n=>n.trim()).filter(Boolean)),rows:4,className:"text-sm"})]}),t==="media"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Allowed Types (e.g., image/*, video/*)"}),e.jsx(p,{value:(a.allowedTypes??[]).join(", "),onChange:s=>l("allowedTypes",s.target.value.split(",").map(n=>n.trim()).filter(Boolean)),className:"h-8 text-sm"})]}),t==="content"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Allowed Collections"}),h&&h.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:h.collections.map(s=>{const n=a.collections??[],u=n.includes(s.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(w,{id:`col-${s.name}`,checked:u,onCheckedChange:m=>{m?l("collections",[...n,s.name]):l("collections",n.filter(g=>g!==s.name))}}),e.jsx(d,{htmlFor:`col-${s.name}`,className:"text-xs font-normal",children:s.label||s.name})]},s.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(p,{value:(a.collections??[]).join(", "),onChange:s=>l("collections",s.target.value.split(",").map(n=>n.trim()).filter(Boolean)),placeholder:"Comma-separated, leave empty for all",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{id:"opt-multiple",checked:!!a.multiple,onCheckedChange:s=>l("multiple",!!s)}),e.jsx(d,{htmlFor:"opt-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:"Item Fields"}),e.jsx(te,{fields:a.itemFields??[],onChange:s=>l("itemFields",s),excludeTypes:["array"]})]})]})}const C=[{value:"text",label:"Text"},{value:"textarea",label:"Textarea"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"select",label:"Select"},{value:"url",label:"URL"},{value:"email",label:"Email"},{value:"date",label:"Date"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"}];function ae({id:t,field:a,onChange:x,onRemove:h,excludeTypes:l,readOnlyName:s,defaultExpanded:n}){const[u,m]=j.useState(n??!1),[g,y]=j.useState(!!a.label),{attributes:v,listeners:N,setNodeRef:f,transform:S,transition:r}=_({id:t}),i=l?C.filter(c=>!l.includes(c.value)):C,o={transform:O.Transform.toString(S),transition:r};function b(c){x({...a,...c})}return e.jsx("div",{ref:f,style:o,className:"rounded-md border bg-card",children:e.jsxs(G,{open:u,onOpenChange:m,children:[e.jsxs("div",{className:"flex items-center gap-2 p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...v,...N,children:e.jsx(D,{className:"h-4 w-4"})}),e.jsx(U,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(M,{className:T("h-4 w-4 transition-transform",u&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:a.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:a.label}),e.jsx(k,{type:"button",variant:"ghost",size:"sm",onClick:h,className:"text-destructive",children:e.jsx(Z,{className:"h-3 w-3"})})]}),e.jsx(Y,{children:e.jsxs("div",{className:"space-y-3 border-t p-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(ee,{value:a.name,onChange:c=>b({name:c}),onBlur:()=>{a.name&&!g&&b({label:W(a.name)})},readOnly:s,className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Label"}),e.jsx(p,{value:a.label,onChange:c=>{b({label:c.target.value}),y(!0)},className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Type"}),e.jsxs(E,{value:a.type,onValueChange:c=>b({type:c,options:{}}),children:[e.jsx(I,{className:"h-8 text-sm",children:e.jsx(L,{})}),e.jsx(B,{children:i.map(c=>e.jsx(R,{value:c.value,children:c.label},c.value))})]})]})]}),e.jsx(se,{type:a.type,options:a.options??{},onChange:c=>b({options:c})})]})})]})})}function te({fields:t,onChange:a,excludeTypes:x,existingFieldNames:h}){const l=P(q(A)),s=t.map((r,i)=>`field-${i}`),[n,u]=j.useState("text"),[m,g]=j.useState(null),y=x?C.filter(r=>!x.includes(r.value)):C;function v(){g(t.length),a([...t,{name:"",label:"",type:n,options:{}}])}function N(r,i){const o=[...t];o[r]=i,a(o)}function f(r){a(t.filter((i,o)=>o!==r))}function S(r){const{active:i,over:o}=r;if(o&&i.id!==o.id){const b=s.indexOf(String(i.id)),c=s.indexOf(String(o.id));a(K(t,b,c))}}return e.jsx($,{sensors:l,collisionDetection:z,onDragEnd:S,children:e.jsx(H,{items:s,strategy:J,children:e.jsxs("div",{className:"space-y-2",children:[t.map((r,i)=>e.jsx(ae,{id:`field-${i}`,field:r,onChange:o=>N(i,o),onRemove:()=>f(i),excludeTypes:x,readOnlyName:!!(h?.has(r.name)&&r.name),defaultExpanded:i===m},`field-${i}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(E,{value:n,onValueChange:u,children:[e.jsx(I,{className:"h-8 w-[130px] text-sm",children:e.jsx(L,{})}),e.jsx(B,{children:y.map(r=>e.jsx(R,{value:r.value,children:r.label},r.value))})]}),e.jsxs(k,{type:"button",variant:"outline",size:"sm",onClick:v,children:[e.jsx(X,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}export{te as F,ee as I};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-BO6c-AOu.js";import{r as o,N as Y}from"./react-vendor-DNVhVxD7.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-CwkwXbO-.js";import{C as J,a as X,b as Z,c as $}from"./card-DpNr7WTb.js";import"./radix-n1vDIPi6.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};
1
+ import{j as e}from"./tanstack-oFmRhGwV.js";import{r as o,N as Y}from"./react-vendor-B0Dih9Pj.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-DX9xeoQx.js";import{C as J,a as X,b as Z,c as $}from"./card-C7fgQS_U.js";import"./radix-lA_IxTIV.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};