headroom-cms 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/admin/assets/AdminsPage-C4tJy6Vj.js +1 -0
  2. package/admin/assets/AllContentPage-DL0-UlYh.js +1 -0
  3. package/admin/assets/ApiKeysPage-pZ6nKCZ_.js +1 -0
  4. package/admin/assets/AuditPage-aVmcP6Ts.js +1 -0
  5. package/admin/assets/{BlockEditor-uSyk_TPt.js → BlockEditor-D0Jk8u7w.js} +54 -54
  6. package/admin/assets/BlockTypeEditPage-DIe2yYEr.js +1 -0
  7. package/admin/assets/BlockTypesPage-Q7keQKxn.js +1 -0
  8. package/admin/assets/BulkActionBar-BGDrNwCg.js +1 -0
  9. package/admin/assets/CollectionEditPage-Bq75MpXk.js +1 -0
  10. package/admin/assets/CollectionsPage-DDZ-5H7Y.js +1 -0
  11. package/admin/assets/ContentCreatePage-C3jn0Etf.js +1 -0
  12. package/admin/assets/ContentEditPage-9tODvFEv.js +2 -0
  13. package/admin/assets/ContentListPage-VCT6GTCF.js +1 -0
  14. package/admin/assets/{CustomBlockPreview-ers8OdZ0.js → CustomBlockPreview-f9j4g35U.js} +1 -1
  15. package/admin/assets/FieldBuilder-p1Y8RubR.js +3 -0
  16. package/admin/assets/{LoginPage-uxiw8K1J.js → LoginPage-9YUPS1YH.js} +1 -1
  17. package/admin/assets/MediaField-DJpYbUA8.js +1 -0
  18. package/admin/assets/MediaPage-BgDRQR21.js +1 -0
  19. package/admin/assets/SiteSettingsPage-Diy-PauR.js +1 -0
  20. package/admin/assets/SiteUsersPage-CtVaB0vq.js +1 -0
  21. package/admin/assets/SitesPage-B-sNyP-Y.js +1 -0
  22. package/admin/assets/SubmissionDetailPage-DW6QJvAy.js +1 -0
  23. package/admin/assets/SubmissionEditPage-CxYPdI9-.js +1 -0
  24. package/admin/assets/SubmissionListPage-BHF82NF3.js +1 -0
  25. package/admin/assets/TagInput-CrI2BIuz.js +1 -0
  26. package/admin/assets/TagsPage-BSX5KQvZ.js +1 -0
  27. package/admin/assets/UsersPage-BCTpWULa.js +1 -0
  28. package/admin/assets/WebhookEditPage-CQO3nmaT.js +1 -0
  29. package/admin/assets/WebhooksPage-ByaTlUGU.js +1 -0
  30. package/admin/assets/{card-C7fgQS_U.js → card-uKxSQehY.js} +1 -1
  31. package/admin/assets/checkbox-z1kYnX5o.js +1 -0
  32. package/admin/assets/command-CuWC4GrT.js +1 -0
  33. package/admin/assets/{core.esm-DRuhixPo.js → core.esm-B_kcYf6n.js} +2 -2
  34. package/admin/assets/index-HoCNSqv2.css +1 -0
  35. package/admin/assets/index-b-u0-VCO.js +18 -0
  36. package/admin/assets/media-url-DIg_vSyf.js +1 -0
  37. package/admin/assets/popover-rcnajqN6.js +1 -0
  38. package/admin/assets/{radix-lA_IxTIV.js → radix-C1kb_NqW.js} +2 -2
  39. package/admin/assets/react-vendor-C2CvUxFh.js +4 -0
  40. package/admin/assets/select-BKaV0BO_.js +1 -0
  41. package/admin/assets/serializeToText-BfR2RCzd.js +2 -0
  42. package/admin/assets/sortable.esm-BHilUL-2.js +1 -0
  43. package/admin/assets/{table-BjSue8Ev.js → table-Bozosvl6.js} +1 -1
  44. package/admin/assets/{tanstack-oFmRhGwV.js → tanstack-Bs3zYPPV.js} +1 -1
  45. package/admin/assets/textarea-BnjAxJtk.js +1 -0
  46. package/admin/assets/useAdminResolver-B0ady82Q.js +1 -0
  47. package/admin/assets/useContent-B2MUK4An.js +1 -0
  48. package/admin/assets/{useDebouncedValue-DHUCnm9B.js → useDebouncedValue-C-cQUcLG.js} +1 -1
  49. package/admin/assets/useMedia-CXQpRNYL.js +1 -0
  50. package/admin/assets/usePageTitle-Do4xyFdL.js +1 -0
  51. package/admin/assets/useSiteUsers-BfzIdhvs.js +1 -0
  52. package/admin/assets/{useTags-BuXf7_7H.js → useTags-B6FtXCHF.js} +1 -1
  53. package/admin/assets/{useWebhooks-Cx9tbBME.js → useWebhooks-iPRX5y4s.js} +1 -1
  54. package/admin/favicon-16x16.png +0 -0
  55. package/admin/favicon-32x32.png +0 -0
  56. package/admin/index.html +7 -6
  57. package/admin/sw.js +1 -1
  58. package/dist/api.d.ts.map +1 -1
  59. package/dist/api.js +8 -0
  60. package/dist/api.js.map +1 -1
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +12 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/scheduler.d.ts +25 -0
  66. package/dist/scheduler.d.ts.map +1 -0
  67. package/dist/scheduler.js +64 -0
  68. package/dist/scheduler.js.map +1 -0
  69. package/dist/storage.d.ts +1 -0
  70. package/dist/storage.d.ts.map +1 -1
  71. package/dist/storage.js +16 -0
  72. package/dist/storage.js.map +1 -1
  73. package/lambda/api/bootstrap +0 -0
  74. package/lambda/webhook-worker/bootstrap +0 -0
  75. package/package.json +1 -1
  76. package/src/api.ts +8 -0
  77. package/src/index.ts +16 -2
  78. package/src/scheduler.ts +83 -0
  79. package/src/sst-env.d.ts +4 -0
  80. package/src/storage.ts +17 -0
  81. package/admin/assets/AdminsPage-Cvqw6UOu.js +0 -1
  82. package/admin/assets/AllContentPage-Cnkt8Fgm.js +0 -1
  83. package/admin/assets/ApiKeysPage-FLex3Chc.js +0 -1
  84. package/admin/assets/AuditPage-ClgwR_8y.js +0 -1
  85. package/admin/assets/BlockTypeEditPage-Dr_yNLDI.js +0 -1
  86. package/admin/assets/BlockTypesPage-CwsGPuAZ.js +0 -1
  87. package/admin/assets/BulkActionBar-C-88Wnqw.js +0 -1
  88. package/admin/assets/CollectionEditPage-Cimkb84B.js +0 -1
  89. package/admin/assets/CollectionsPage-CxnSFPCH.js +0 -1
  90. package/admin/assets/ContentCreatePage-DZCyOcte.js +0 -1
  91. package/admin/assets/ContentEditPage-RtHbU_l4.js +0 -3
  92. package/admin/assets/ContentListPage-qFcZVzg9.js +0 -1
  93. package/admin/assets/FieldBuilder-Ds-agLm7.js +0 -3
  94. package/admin/assets/MediaPage-CeepVDHQ.js +0 -1
  95. package/admin/assets/SiteSettingsPage-xkngL15i.js +0 -1
  96. package/admin/assets/SitesPage-BD9tou9-.js +0 -1
  97. package/admin/assets/TagsPage-BxSwTLpQ.js +0 -1
  98. package/admin/assets/UsersPage-BayuQyLh.js +0 -1
  99. package/admin/assets/WebhookEditPage-BrXm8Dht.js +0 -1
  100. package/admin/assets/WebhooksPage-BUE6XuIP.js +0 -1
  101. package/admin/assets/badge-B8OxObuF.js +0 -1
  102. package/admin/assets/check-CxKAR64t.js +0 -1
  103. package/admin/assets/checkbox-BV2kjQBe.js +0 -1
  104. package/admin/assets/command-qGFnWxcS.js +0 -1
  105. package/admin/assets/copy-CgYzmj06.js +0 -1
  106. package/admin/assets/index-DX9xeoQx.js +0 -18
  107. package/admin/assets/index-PpbsYFRh.css +0 -1
  108. package/admin/assets/plus-HdRn2U0S.js +0 -1
  109. package/admin/assets/popover-Cou924mw.js +0 -1
  110. package/admin/assets/react-vendor-B0Dih9Pj.js +0 -4
  111. package/admin/assets/search-C-3Q9nn7.js +0 -1
  112. package/admin/assets/select-CHW5R8qv.js +0 -1
  113. package/admin/assets/sortable.esm-CBJBhe4k.js +0 -1
  114. package/admin/assets/trash-2-CWWRVuRB.js +0 -1
  115. package/admin/assets/use-mobile-C1r2eP64.js +0 -1
  116. package/admin/assets/useAdminResolver-D6B6RXnk.js +0 -1
  117. package/admin/assets/useContent-f19XHVlJ.js +0 -1
  118. package/admin/assets/useMedia-DkvP1QLG.js +0 -1
  119. package/admin/vite.svg +0 -1
@@ -1 +0,0 @@
1
- import{j as s}from"./tanstack-oFmRhGwV.js";import{u as T,e as D,r as C}from"./react-vendor-B0Dih9Pj.js";import{u as M,a as L,b as R,c as z}from"./useContent-f19XHVlJ.js";import{u as E,m as w}from"./use-mobile-C1r2eP64.js";import{v as H,t as r,S as F,w as V,B as _}from"./index-DX9xeoQx.js";import{B as h}from"./badge-B8OxObuF.js";import{C as q,c as G}from"./card-C7fgQS_U.js";import{C as m}from"./checkbox-BV2kjQBe.js";import{T as J,a as K,b as k,c as i,d as O,e as d}from"./table-BjSue8Ev.js";import{f as S}from"./format-C88SDH8g.js";import{B as Q}from"./BulkActionBar-C-88Wnqw.js";import"./radix-lA_IxTIV.js";import"./check-CxKAR64t.js";function ie(){const{host:c}=T(),p=D(),{collections:y}=H(),A=E(),[$,I]=C.useState(),[n,a]=C.useState(new Set),{data:o,isLoading:P}=M(c,$),f=L(c),j=R(c),g=z(c),b=new Map(y.map(e=>[e.name,e.label])),x=o?.items.map(e=>e.contentId)??[],N=x.length>0&&x.every(e=>n.has(e));function v(e){a(l=>{const t=new Set(l);return t.has(e)?t.delete(e):t.add(e),t})}function B(){a(N?new Set:new Set(x))}const U=f.isPending||j.isPending||g.isPending;return s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:"All Content"}),s.jsx("p",{className:"text-muted-foreground text-sm",children:"Recently updated content across all collections."})]}),n.size>0&&s.jsx(Q,{selectedCount:n.size,onPublish:async()=>{const e=[...n],t=(await f.mutateAsync(e)).filter(u=>u.status==="rejected").length;t?r.error(`${t} of ${e.length} failed to publish`):r.success(`${e.length} item(s) published`),a(new Set)},onUnpublish:async()=>{const e=[...n],t=(await j.mutateAsync(e)).filter(u=>u.status==="rejected").length;t?r.error(`${t} of ${e.length} failed to unpublish`):r.success(`${e.length} item(s) unpublished`),a(new Set)},onDelete:async()=>{const e=[...n],t=(await g.mutateAsync(e)).filter(u=>u.status==="rejected").length;t?r.error(`${t} of ${e.length} failed to delete`):r.success(`${e.length} item(s) deleted`),a(new Set)},onClear:()=>a(new Set),isPending:U}),P?s.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,l)=>s.jsx(F,{className:"h-12 w-full"},l))}):o?.items.length?s.jsxs(s.Fragment,{children:[A?s.jsx("div",{className:"grid gap-3","data-testid":"all-content-card-view",children:o.items.map(e=>{const l=e.coverUrl;return s.jsx(q,{className:V("cursor-pointer gap-0 overflow-hidden py-0 transition-shadow hover:shadow-md",n.has(e.contentId)&&"ring-2 ring-primary"),onClick:()=>p(`/sites/${c}/content/${e.collection}/${e.contentId}`),children:s.jsx(G,{className:"p-3",children:s.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[l&&s.jsx("img",{src:w(l),alt:"",className:"h-12 w-12 rounded object-cover flex-shrink-0"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("span",{className:"font-medium truncate",children:e.title||"Untitled"}),s.jsx(h,{variant:e.publishedAt?"default":"secondary",className:"shrink-0",children:e.publishedAt?"Published":"Draft"})]}),e.slug&&s.jsxs("p",{className:"text-xs text-muted-foreground truncate mt-0.5",children:["/",e.slug]}),s.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s.jsx(h,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:b.get(e.collection)??e.collection}),s.jsx("span",{className:"text-xs text-muted-foreground",children:e.publishedAt?S(e.publishedAt):"—"})]})]}),s.jsx(m,{checked:n.has(e.contentId),onCheckedChange:()=>v(e.contentId),onClick:t=>t.stopPropagation(),className:"mt-1"})]})})},e.contentId)})}):s.jsxs(J,{children:[s.jsx(K,{children:s.jsxs(k,{children:[s.jsx(i,{className:"w-10",children:s.jsx(m,{checked:N,onCheckedChange:B,"aria-label":"Select all"})}),s.jsx(i,{children:"Title"}),s.jsx(i,{children:"Slug"}),s.jsx(i,{children:"Collection"}),s.jsx(i,{children:"Status"}),s.jsx(i,{children:"Updated"})]})}),s.jsx(O,{children:o.items.map(e=>s.jsxs(k,{className:"cursor-pointer",onClick:()=>p(`/sites/${c}/content/${e.collection}/${e.contentId}`),children:[s.jsx(d,{onClick:l=>l.stopPropagation(),children:s.jsx(m,{checked:n.has(e.contentId),onCheckedChange:()=>v(e.contentId),"aria-label":`Select ${e.title||"Untitled"}`})}),s.jsx(d,{className:"font-medium",children:s.jsxs("div",{className:"flex items-center gap-3",children:[!!e.coverUrl&&s.jsx("img",{src:w(e.coverUrl),alt:"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}),s.jsx("span",{children:e.title||"Untitled"})]})}),s.jsx(d,{className:"text-muted-foreground text-sm",children:e.slug||"—"}),s.jsx(d,{children:s.jsx(h,{variant:"outline",children:b.get(e.collection)??e.collection})}),s.jsx(d,{children:s.jsx(h,{variant:e.publishedAt?"default":"secondary",children:e.publishedAt?"Published":"Draft"})}),s.jsx(d,{className:"text-muted-foreground",children:e.publishedAt?S(e.publishedAt):"—"})]},e.contentId))})]}),o.hasMore&&s.jsx("div",{className:"mt-4 flex justify-center",children:s.jsx(_,{variant:"outline",onClick:()=>I(o.cursor??void 0),children:"Load More"})})]}):s.jsx("p",{className:"text-muted-foreground",children:"No content yet."})]})}export{ie as AllContentPage};
@@ -1 +0,0 @@
1
- import{u as L,a as N,b as A,j as e}from"./tanstack-oFmRhGwV.js";import{u as q,r as m}from"./react-vendor-B0Dih9Pj.js";import{e as f,B as r,S as E,D as K,j as D,k as w,l as I,m as T,I as g,n as p,L as O,t as x}from"./index-DX9xeoQx.js";import{T as G,a as Q,b as k,c as d,d as R,e as u}from"./table-BjSue8Ev.js";import{f as C}from"./format-C88SDH8g.js";import{P as $}from"./plus-HdRn2U0S.js";import{T as B}from"./trash-2-CWWRVuRB.js";import{C as H}from"./copy-CgYzmj06.js";import"./radix-lA_IxTIV.js";function U(s){const t=f();return L({queryKey:["sites",s,"api-keys"],queryFn:async()=>({items:(await t.apiFetch(`/v1/admin/sites/${s}/api-keys`)).keys}),enabled:!!s})}function z(s){const t=f(),n=N();return A({mutationFn:i=>t.apiFetch(`/v1/admin/sites/${s}/api-keys`,{method:"POST",body:JSON.stringify(i)}),onSuccess:()=>n.invalidateQueries({queryKey:["sites",s,"api-keys"]})})}function J(s,t){const n=f(),i=N();return A({mutationFn:()=>n.apiFetch(`/v1/admin/sites/${s}/api-keys/${t}`,{method:"DELETE"}),onSuccess:()=>i.invalidateQueries({queryKey:["sites",s,"api-keys"]})})}function te(){const{host:s}=q(),{data:t,isLoading:n}=U(s),i=z(s),[h,l]=m.useState(!1),[b,y]=m.useState(""),[o,j]=m.useState(null),[P,v]=m.useState(null);async function F(a){a.preventDefault();try{const c=await i.mutateAsync({label:b});j(c.key),y("")}catch(c){x.error("Failed to create API key",{description:c instanceof Error?c.message:void 0})}}function S(){o&&(navigator.clipboard.writeText(o),x.success("Copied to clipboard"))}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:"API Keys"}),e.jsxs(r,{onClick:()=>l(!0),children:[e.jsx($,{className:"mr-2 h-4 w-4"}),"Generate Key"]})]}),n?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((a,c)=>e.jsx(E,{className:"h-12 w-full"},c))}):t?.items.length?e.jsxs(G,{children:[e.jsx(Q,{children:e.jsxs(k,{children:[e.jsx(d,{children:"Label"}),e.jsx(d,{children:"Key ID"}),e.jsx(d,{children:"Created"}),e.jsx(d,{children:"Last Used"}),e.jsx(d,{})]})}),e.jsx(R,{children:t.items.map(a=>e.jsxs(k,{children:[e.jsx(u,{className:"font-medium",children:a.label}),e.jsx(u,{className:"font-mono text-xs",children:a.keyId}),e.jsx(u,{className:"text-muted-foreground",children:C(a.createdAt)}),e.jsx(u,{className:"text-muted-foreground",children:a.lastUsedAt?C(a.lastUsedAt):"Never"}),e.jsx(u,{children:e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>v(a.keyId),children:e.jsx(B,{className:"h-4 w-4"})})})]},a.keyId))})]}):e.jsx("p",{className:"text-muted-foreground",children:"No API keys."}),e.jsx(K,{open:h,onOpenChange:a=>{l(a),a||(j(null),y(""))},children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(I,{children:o?"API Key Generated":"Generate API Key"}),e.jsx(T,{className:"sr-only",children:"Create a new API key for site access"})]}),o?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Copy this key now. You won't be able to see it again."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{value:o,readOnly:!0,className:"font-mono text-xs"}),e.jsx(r,{variant:"outline",size:"icon",onClick:S,children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsx(p,{children:e.jsx(r,{onClick:()=>{l(!1),j(null)},children:"Done"})})]}):e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"key-label",children:"Label"}),e.jsx(g,{id:"key-label",value:b,onChange:a=>y(a.target.value),required:!0,autoFocus:!0})]}),e.jsxs(p,{children:[e.jsx(r,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(r,{type:"submit",disabled:i.isPending,children:"Generate"})]})]})]})}),e.jsx(M,{host:s,keyId:P,onClose:()=>v(null)})]})}function M({host:s,keyId:t,onClose:n}){const i=J(s,t??"");async function h(){try{await i.mutateAsync(),x.success("API key revoked"),n()}catch(l){x.error("Failed to revoke",{description:l instanceof Error?l.message:void 0})}}return e.jsx(K,{open:!!t,onOpenChange:()=>n(),children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(I,{children:"Revoke API key?"}),e.jsx(T,{children:"This action cannot be undone. Any applications using this key will lose access."})]}),e.jsxs(p,{children:[e.jsx(r,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(r,{variant:"destructive",onClick:h,children:"Revoke"})]})]})})}export{te as ApiKeysPage};
@@ -1 +0,0 @@
1
- import{u as x,j as e}from"./tanstack-oFmRhGwV.js";import{u as h,r as f}from"./react-vendor-B0Dih9Pj.js";import{e as j,S as b,B as g}from"./index-DX9xeoQx.js";import{u as p}from"./useAdminResolver-D6B6RXnk.js";import{T as A,a as N,b as c,c as n,d as T,e as o}from"./table-BjSue8Ev.js";import{f as y}from"./format-C88SDH8g.js";import"./radix-lA_IxTIV.js";function S(a,t){const d=j(),s=new URLSearchParams;t?.action&&s.set("action",t.action),t?.before&&s.set("before",String(t.before));const r=s.toString();return x({queryKey:["sites",a,"audit",t?.action??"",t?.before??""],queryFn:()=>d.apiFetch(`/v1/admin/sites/${a}/audit${r?`?${r}`:""}`),enabled:!!a})}function C(){const{host:a}=h(),[t,d]=f.useState(),{data:s,isLoading:r}=S(a,{before:t}),l=s?.items.map(i=>i.adminId)??[],{resolve:m}=p(l);return e.jsxs("div",{children:[e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:"Audit Log"}),r?e.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((i,u)=>e.jsx(b,{className:"h-12 w-full"},u))}):s?.items.length?e.jsxs(e.Fragment,{children:[e.jsxs(A,{children:[e.jsx(N,{children:e.jsxs(c,{children:[e.jsx(n,{children:"Action"}),e.jsx(n,{children:"Admin"}),e.jsx(n,{children:"Status"}),e.jsx(n,{children:"Time"})]})}),e.jsx(T,{children:s.items.map(i=>e.jsxs(c,{children:[e.jsx(o,{className:"font-medium",children:i.action}),e.jsx(o,{className:"text-sm",children:m(i.adminId)}),e.jsx(o,{children:e.jsx("span",{className:"text-muted-foreground",children:i.status})}),e.jsx(o,{className:"text-muted-foreground",children:y(i.createdAt)})]},i.eventId))})]}),s.hasMore&&s.items.length>0&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(g,{variant:"outline",onClick:()=>d(s.items[s.items.length-1].createdAt),children:"Load More"})})]}):e.jsx("p",{className:"text-muted-foreground",children:"No audit events."})]})}export{C as AuditPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{u as A,e as H,r as o}from"./react-vendor-B0Dih9Pj.js";import{L as d,I as b,W as C,a3 as R,S as k,a4 as U,a5 as V,a6 as W,B as h,a as _,D as z,i as G,j as J,k as K,l as M,m as Q,n as X,t as j}from"./index-DX9xeoQx.js";import{I as Y,F as Z}from"./FieldBuilder-Ds-agLm7.js";import{i as ee}from"./format-C88SDH8g.js";import{T as ae,C as se,b as te,c as le}from"./sortable.esm-CBJBhe4k.js";import{C as ie,a as ne,b as re,c as oe}from"./card-C7fgQS_U.js";import{C as ce}from"./CustomBlockPreview-ers8OdZ0.js";import{u as T}from"./useDebouncedValue-DHUCnm9B.js";import{b as de}from"./core.esm-DRuhixPo.js";import{T as me}from"./trash-2-CWWRVuRB.js";import"./radix-lA_IxTIV.js";import"./select-CHW5R8qv.js";import"./check-CxKAR64t.js";import"./checkbox-BV2kjQBe.js";import"./plus-HdRn2U0S.js";function pe({fields:s,previewTemplate:t,previewData:a,onPreviewDataChange:n,blockTypeName:c,blockTypeLabel:m,blockTypeIcon:f}){const r=T(t,300),y=T(a,300);return e.jsxs("div",{className:"space-y-4",children:[s.map(i=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(d,{className:"text-xs",children:i.label}),e.jsx(b,{value:String(a[i.name]??""),onChange:v=>n({...a,[i.name]:v.target.value}),placeholder:`Sample ${i.label}...`})]},i.name)),e.jsx(C,{}),e.jsx("div",{className:"rounded-md border p-4",children:e.jsx(ce,{blockType:{name:c,label:m,icon:f,fields:s,previewTemplate:r},props:y})})]})}function Se(){const{host:s,name:t}=A(),a=t==="new",{data:n,isLoading:c}=R(s,a?"":t);return!a&&c?e.jsxs("div",{className:"space-y-4",children:[e.jsx(k,{className:"h-8 w-64"}),e.jsx(k,{className:"h-64 w-full"})]}):a?e.jsx(B,{host:s,isNew:!0}):n?e.jsx(B,{host:s,isNew:!1,blockType:n},n.name):e.jsx("p",{className:"text-muted-foreground",children:"Block type not found."})}function B({host:s,isNew:t,blockType:a}){const n=H(),c=U(s),m=V(s,a?.name??""),f=W(s,a?.name??""),[r,y]=o.useState(a?.name??""),[i,v]=o.useState(a?.label??""),[g,D]=o.useState(a?.icon??""),[S,F]=o.useState(!t),P=new Set((a?.fields??[]).map(l=>l.name).filter(Boolean)),[p,L]=o.useState(a?.fields??[]),[u,E]=o.useState(a?.previewTemplate??""),[x,I]=o.useState(a?.previewData??{}),[O,w]=o.useState(!1);async function $(l){l.preventDefault();try{t?(await c.mutateAsync({name:r,label:i,icon:g,fields:p,previewTemplate:u||void 0,previewData:Object.keys(x).length>0?x:void 0}),j.success("Block type created"),n(`/sites/${s}/settings/block-types/${r}`)):(await m.mutateAsync({label:i,icon:g,fields:p,previewTemplate:u||void 0,previewData:Object.keys(x).length>0?x:void 0}),j.success("Block type updated"))}catch(N){j.error(t?"Failed to create":"Failed to update",{description:N instanceof Error?N.message:void 0})}}async function q(){try{await f.mutateAsync(),j.success("Block type deleted"),n(`/sites/${s}/settings/block-types`)}catch(l){j.error("Failed to delete",{description:l instanceof Error?l.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:t?"New Block Type":`Edit: ${a?.label??r}`}),e.jsxs(ie,{children:[e.jsx(ne,{children:e.jsx(re,{children:"Block Type Settings"})}),e.jsx(oe,{children:e.jsxs("form",{onSubmit:$,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"name",children:"Name"}),e.jsx(Y,{id:"name",value:r,onChange:y,onBlur:()=>{r&&!S&&v(ee(r))},readOnly:!t,placeholder:"e.g. hero_banner",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"label",children:"Label"}),e.jsx(b,{id:"label",value:i,onChange:l=>{v(l.target.value),F(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"icon",children:"Icon"}),e.jsx(b,{id:"icon",value:g,onChange:l=>D(l.target.value)})]}),e.jsx(C,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{children:"Block Fields"}),e.jsx(Z,{fields:p,onChange:L,existingFieldNames:P})]}),e.jsx(C,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(d,{htmlFor:"preview-template",children:"Preview Template (Liquid + Tailwind)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Use Liquid syntax to render a preview. Block field values are available as template variables."}),e.jsx(ae,{id:"preview-template",value:u,onChange:l=>E(l.target.value),rows:6,placeholder:'<div class="p-4">{{ title }}</div>',className:"font-mono text-sm"})]}),(u||p.length>0)&&e.jsxs(se,{children:[e.jsxs(te,{className:"flex w-full items-center gap-2 text-sm font-medium",children:[e.jsx(de,{className:"h-4 w-4 transition-transform [[data-state=open]>&]:rotate-90"}),"Preview"]}),e.jsx(le,{className:"mt-2",children:e.jsx(pe,{fields:p,previewTemplate:u,previewData:x,onPreviewDataChange:I,blockTypeName:r,blockTypeLabel:i,blockTypeIcon:g})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(h,{type:"submit",disabled:c.isPending||m.isPending,children:[(c.isPending||m.isPending)&&e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),t?"Create":"Save"]}),e.jsx(h,{type:"button",variant:"outline",onClick:()=>n(`/sites/${s}/settings/block-types`),children:"Cancel"})]})]})})]}),!t&&e.jsx("div",{className:"mt-6",children:e.jsxs(z,{open:O,onOpenChange:w,children:[e.jsx(G,{asChild:!0,children:e.jsxs(h,{variant:"destructive",children:[e.jsx(me,{className:"mr-2 h-4 w-4"}),"Delete Block Type"]})}),e.jsxs(J,{children:[e.jsxs(K,{children:[e.jsx(M,{children:"Delete block type?"}),e.jsx(Q,{children:"This will permanently delete this block type."})]}),e.jsxs(X,{children:[e.jsx(h,{variant:"outline",onClick:()=>w(!1),children:"Cancel"}),e.jsx(h,{variant:"destructive",onClick:q,children:"Delete"})]})]})]})})]})}export{Se as BlockTypeEditPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{u as m,e as d}from"./react-vendor-B0Dih9Pj.js";import{a2 as x,B as h,S as j}from"./index-DX9xeoQx.js";import{T as p,a as f,b as c,c as a,d as u,e as l}from"./table-BjSue8Ev.js";import{P as N}from"./plus-HdRn2U0S.js";import"./radix-lA_IxTIV.js";function w(){const{host:n}=m(),i=d(),{data:r,isLoading:o}=x(n);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:"Block Types"}),e.jsxs(h,{onClick:()=>i(`/sites/${n}/settings/block-types/new`),children:[e.jsx(N,{className:"mr-2 h-4 w-4"}),"New Block Type"]})]}),o?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((s,t)=>e.jsx(j,{className:"h-12 w-full"},t))}):r?.items.length?e.jsxs(p,{children:[e.jsx(f,{children:e.jsxs(c,{children:[e.jsx(a,{children:"Name"}),e.jsx(a,{children:"Label"}),e.jsx(a,{children:"Icon"}),e.jsx(a,{children:"Fields"})]})}),e.jsx(u,{children:r.items.map(s=>e.jsxs(c,{className:"cursor-pointer",onClick:()=>i(`/sites/${n}/settings/block-types/${s.name}`),children:[e.jsx(l,{className:"font-mono text-sm",children:s.name}),e.jsx(l,{children:s.label}),e.jsx(l,{children:s.icon}),e.jsx(l,{className:"text-muted-foreground",children:s.fields?.length??0})]},s.name))})]}):e.jsx("p",{className:"text-muted-foreground",children:"No block types defined."})]})}export{w as BlockTypesPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{r as m}from"./react-vendor-B0Dih9Pj.js";import{B as a,a as t,X as x,D as h,j,k as p,l as u,m as D,n as b}from"./index-DX9xeoQx.js";function k({selectedCount:i,onPublish:n,onUnpublish:r,onDelete:c,onClear:o,isPending:s}){const[d,l]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-md border bg-muted/50 px-4 py-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:[i," selected"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a,{size:"sm",variant:"outline",onClick:n,disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Publish"]}),e.jsx(a,{size:"sm",variant:"outline",onClick:r,disabled:s,children:"Unpublish"}),e.jsx(a,{size:"sm",variant:"destructive",onClick:()=>l(!0),disabled:s,children:"Delete"})]}),e.jsx(a,{size:"sm",variant:"ghost",onClick:o,className:"ml-auto",disabled:s,children:e.jsx(x,{className:"h-4 w-4"})})]}),e.jsx(h,{open:d,onOpenChange:l,children:e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsxs(u,{children:["Delete ",i," item",i!==1?"s":"","?"]}),e.jsx(D,{children:"This action cannot be undone. The selected content items will be permanently deleted."})]}),e.jsxs(b,{children:[e.jsx(a,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(a,{variant:"destructive",onClick:async()=>{l(!1),await c()},disabled:s,children:[s&&e.jsx(t,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})})]})}export{k as B};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{r as c,u as Q,e as X}from"./react-vendor-B0Dih9Pj.js";import{o as Y,w as ee,B as C,I as E,Z as se,S as B,v as te,$ as ae,a0 as le,a1 as ne,L as f,W as T,a as ie,D as re,i as oe,j as ce,k as de,l as me,m as ue,n as xe,t as D}from"./index-DX9xeoQx.js";import{I as P,F as he}from"./FieldBuilder-Ds-agLm7.js";import{i as O,c as ge}from"./format-C88SDH8g.js";import{C as A}from"./checkbox-BV2kjQBe.js";import{C as je,a as pe,b as fe,c as Ce}from"./card-C7fgQS_U.js";import{C as be,G as ve,b as Se,u as Ne,a as ye,P as De,D as Ee,c as ke}from"./core.esm-DRuhixPo.js";import{u as we,C as Fe,b as Le,c as Re,S as Ie,v as Be,a as Te}from"./sortable.esm-CBJBhe4k.js";import{S as $e,a as Pe,b as Oe,c as Ae,d as _e}from"./select-CHW5R8qv.js";import{T as _}from"./trash-2-CWWRVuRB.js";import{P as qe}from"./plus-HdRn2U0S.js";import"./radix-lA_IxTIV.js";import"./check-CxKAR64t.js";const ze=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],Ve=Y("arrow-right",ze);function Ge({id:t,relationship:s,onChange:a,onRemove:d,collections:x,readOnlyName:u,defaultExpanded:g}){const[b,m]=c.useState(g??!1),[N,j]=c.useState(!!s.label),{attributes:v,listeners:r,setNodeRef:n,transform:o,transition:S}=we({id:t}),h={transform:be.Transform.toString(o),transition:S};function p(i){a({...s,...i})}const k=x.find(i=>i.name===s.targetCollection)?.label??s.targetCollection;return e.jsx("div",{ref:n,style:h,className:"rounded-md border bg-card",children:e.jsxs(Fe,{open:b,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,...r,children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx(Le,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(Se,{className:ee("h-4 w-4 transition-transform",b&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx(Ve,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:k}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(C,{type:"button",variant:"ghost",size:"sm",onClick:d,className:"text-destructive",children:e.jsx(_,{className:"h-3 w-3"})})]}),e.jsx(Re,{children:e.jsxs("div",{className:"space-y-3 border-t p-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(P,{value:s.name,onChange:i=>p({name:i}),onBlur:()=>{s.name&&!N&&p({label:O(s.name)})},readOnly:u,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(E,{value:s.label,onChange:i=>{p({label:i.target.value}),j(!0)},className:"h-8 text-sm"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Target Collection"}),e.jsxs($e,{value:s.targetCollection,onValueChange:i=>p({targetCollection:i}),children:[e.jsx(Pe,{className:"h-8 text-sm",children:e.jsx(Oe,{placeholder:"Select collection..."})}),e.jsx(Ae,{children:x.map(i=>e.jsx(_e,{value:i.name,children:i.label},i.name))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{id:`${t}-multiple`,checked:s.multiple,onCheckedChange:i=>p({multiple:!!i})}),e.jsx("label",{htmlFor:`${t}-multiple`,className:"text-sm",children:"Allow multiple"})]})]})})]})})}function He({relationships:t,onChange:s,collections:a,existingRelNames:d}){const x=Ne(ye(De)),u=t.map((r,n)=>`rel-${n}`),[g,b]=c.useState(null);function m(){b(t.length),s([...t,{name:"",label:"",targetCollection:"",multiple:!1}])}function N(r,n){const o=[...t];o[r]=n,s(o)}function j(r){s(t.filter((n,o)=>o!==r))}function v(r){const{active:n,over:o}=r;if(o&&n.id!==o.id){const S=u.indexOf(String(n.id)),h=u.indexOf(String(o.id));s(Te(t,S,h))}}return e.jsx(Ee,{sensors:x,collisionDetection:ke,onDragEnd:v,children:e.jsx(Ie,{items:u,strategy:Be,children:e.jsxs("div",{className:"space-y-2",children:[t.map((r,n)=>e.jsx(Ge,{id:`rel-${n}`,relationship:r,onChange:o=>N(n,o),onRemove:()=>j(n),collections:a,readOnlyName:!!(d?.has(r.name)&&r.name),defaultExpanded:n===g},`rel-${n}`)),e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:m,children:[e.jsx(qe,{className:"mr-2 h-3 w-3"})," Add Relationship"]})]})})})}function ns(){const{host:t,name:s}=Q(),a=s==="new",{data:d,isLoading:x}=se(t,a?"":s);return!a&&x?e.jsxs("div",{className:"space-y-4",children:[e.jsx(B,{className:"h-8 w-64"}),e.jsx(B,{className:"h-64 w-full"})]}):a?e.jsx($,{host:t,isNew:!0}):d?e.jsx($,{host:t,isNew:!1,collection:d},d.name):e.jsx("p",{className:"text-muted-foreground",children:"Collection not found."})}function $({host:t,isNew:s,collection:a}){const d=X(),{collections:x}=te(),u=ae(t),g=le(t,a?.name??""),b=ne(t,a?.name??""),[m,N]=c.useState(a?.name??""),[j,v]=c.useState(a?.label??""),[r,n]=c.useState(a?.labelSingular??""),[o,S]=c.useState(a?.slug??""),[h,p]=c.useState(a?.singleton??!1),[k,i]=c.useState(!s),[q,z]=c.useState(!s),[V,G]=c.useState(!s),H=new Set((a?.fields??[]).map(l=>l.name).filter(Boolean)),L=[{name:"blocks",label:"Blocks",type:"blocks",options:{}}],[w,R]=c.useState(a?.fields??(s&&!h?L:[])),[F,M]=c.useState(a?.relationships??[]),U=new Set((a?.relationships??[]).map(l=>l.name).filter(Boolean)),[W,I]=c.useState(!1);function Z(){if(!m)return;const l=O(m);k||v(l),q||n(ge(l)),V||S(m.replace(/_/g,"-"))}async function J(l){l.preventDefault();try{s?(await u.mutateAsync({name:m,label:j,labelSingular:r,slug:o,singleton:h,fields:w,relationships:F}),D.success("Collection created"),d(`/sites/${t}/settings/collections/${m}`)):(await g.mutateAsync({label:j,labelSingular:r,slug:o,singleton:h,fields:w,relationships:F}),D.success("Collection updated"))}catch(y){D.error(s?"Failed to create":"Failed to update",{description:y instanceof Error?y.message:void 0})}}async function K(){try{await b.mutateAsync(),D.success("Collection deleted"),d(`/sites/${t}/settings/collections`)}catch(l){D.error("Failed to delete",{description:l instanceof Error?l.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:s?"New Collection":`Edit: ${a?.label??m}`}),e.jsxs(je,{children:[e.jsx(pe,{children:e.jsx(fe,{children:"Collection Settings"})}),e.jsx(Ce,{children:e.jsxs("form",{onSubmit:J,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"name",children:"Name"}),e.jsx(P,{id:"name",value:m,onChange:N,onBlur:Z,readOnly:!s,placeholder:"e.g. blog_posts",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"label",children:"Label"}),e.jsx(E,{id:"label",value:j,onChange:l=>{v(l.target.value),i(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"label-singular",children:"Label Singular"}),e.jsx(E,{id:"label-singular",value:r,onChange:l=>{n(l.target.value),z(!0)},required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"slug",children:"Slug"}),e.jsx(E,{id:"slug",value:o,onChange:l=>{S(l.target.value),G(!0)},required:!0})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{id:"singleton",checked:h,onCheckedChange:l=>{const y=!!l;p(y),s&&R(y?[]:L)},disabled:!s}),e.jsx(f,{htmlFor:"singleton",children:"Singleton (single entry, no list)"})]}),e.jsx(T,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:"Fields"}),e.jsx(he,{fields:w,onChange:R,existingFieldNames:H})]}),e.jsx(T,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:"Relationships"}),e.jsx(He,{relationships:F,onChange:M,collections:x,existingRelNames:U})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{type:"submit",disabled:u.isPending||g.isPending,children:[(u.isPending||g.isPending)&&e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin"}),s?"Create":"Save"]}),e.jsx(C,{type:"button",variant:"outline",onClick:()=>d(`/sites/${t}/settings/collections`),children:"Cancel"})]})]})})]}),!s&&e.jsx("div",{className:"mt-6",children:e.jsxs(re,{open:W,onOpenChange:I,children:[e.jsx(oe,{asChild:!0,children:e.jsxs(C,{variant:"destructive",children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),"Delete Collection"]})}),e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(me,{children:"Delete collection?"}),e.jsx(ue,{children:"This will permanently delete the collection and all its content."})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>I(!1),children:"Cancel"}),e.jsx(C,{variant:"destructive",onClick:K,children:"Delete"})]})]})]})})]})}export{ns as CollectionEditPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{u as m,e as x}from"./react-vendor-B0Dih9Pj.js";import{Y as h,B as j,S as f}from"./index-DX9xeoQx.js";import{B as o}from"./badge-B8OxObuF.js";import{T as u,a as p,b as r,c as l,d as g,e as n}from"./table-BjSue8Ev.js";import{P as N}from"./plus-HdRn2U0S.js";import"./radix-lA_IxTIV.js";function P(){const{host:a}=m(),i=x(),{data:t,isLoading:c}=h(a);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:"Collections"}),e.jsxs(j,{onClick:()=>i(`/sites/${a}/settings/collections/new`),children:[e.jsx(N,{className:"mr-2 h-4 w-4"}),"New Collection"]})]}),c?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((s,d)=>e.jsx(f,{className:"h-12 w-full"},d))}):t?.items.length?e.jsxs(u,{children:[e.jsx(p,{children:e.jsxs(r,{children:[e.jsx(l,{children:"Name"}),e.jsx(l,{children:"Label"}),e.jsx(l,{children:"Type"}),e.jsx(l,{children:"Fields"})]})}),e.jsx(g,{children:t.items.map(s=>e.jsxs(r,{className:"cursor-pointer",onClick:()=>i(`/sites/${a}/settings/collections/${s.name}`),children:[e.jsx(n,{className:"font-mono text-sm",children:s.name}),e.jsx(n,{children:s.label}),e.jsx(n,{children:s.singleton?e.jsx(o,{variant:"secondary",children:"Singleton"}):e.jsx(o,{variant:"outline",children:"Collection"})}),e.jsx(n,{className:"text-muted-foreground",children:s.fields?.length??0})]},s.name))})]}):e.jsx("p",{className:"text-muted-foreground",children:"No collections defined."})]})}export{P as CollectionsPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{u as y,e as $,r as i,N as E}from"./react-vendor-B0Dih9Pj.js";import{v as w,L as g,I as h,B as f,a as I,t as p,x as F}from"./index-DX9xeoQx.js";import{e as P}from"./useContent-f19XHVlJ.js";import{C as T,a as A,b as L,c as B}from"./card-C7fgQS_U.js";import{s as D}from"./format-C88SDH8g.js";import"./radix-lA_IxTIV.js";function K(){const{host:n,collection:s}=y(),c=$(),{collections:C}=w(),o=P(n),[l,j]=i.useState(""),[u,d]=i.useState(""),[v,N]=i.useState(!1),[m,x]=i.useState(null),r=C.find(t=>t.name===s);if(r?.singleton){const t=r.singletonContentId?`/sites/${n}/content/${s}/${r.singletonContentId}`:`/sites/${n}/content/${s}`;return e.jsx(E,{to:t,replace:!0})}function S(t){j(t),v||d(D(t))}async function b(t){t.preventDefault(),x(null);try{const a=await o.mutateAsync({collection:s,title:l,slug:u||void 0});p.success("Content created"),c(`/sites/${n}/content/${s}/${a.contentId}`)}catch(a){a instanceof F&&a.status===409?x("A content item with this slug already exists. Choose a different slug."):p.error("Failed to create content",{description:a instanceof Error?a.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsxs("h1",{className:"mb-6 text-2xl font-semibold",children:["New ",r?.labelSingular??s]}),e.jsxs(T,{children:[e.jsx(A,{children:e.jsx(L,{children:"Details"})}),e.jsx(B,{children:e.jsxs("form",{onSubmit:b,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"title",children:"Title"}),e.jsx(h,{id:"title",value:l,onChange:t=>S(t.target.value),required:!0,autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"slug",children:"Slug"}),e.jsx(h,{id:"slug",value:u,onChange:t=>{d(t.target.value),N(!0)}})]}),m&&e.jsx("p",{className:"text-sm text-destructive",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{type:"submit",disabled:!l||o.isPending,children:[o.isPending&&e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}),"Create"]}),e.jsx(f,{type:"button",variant:"outline",onClick:()=>c(-1),children:"Cancel"})]})]})})]})]})}export{K as ContentCreatePage};
@@ -1,3 +0,0 @@
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 +0,0 @@
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,3 +0,0 @@
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
- `),onChange:s=>l("choices",s.target.value.split(`
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 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{r as u,R as S,L as kt,u as Dt}from"./react-vendor-B0Dih9Pj.js";import{F as St,l as Mt,m as Tt,n as _t,o as It,T as Pe,A as Oe,p as Rt,e as Ue,f as He,g as Le,h as Xe,i as Ye,j as Be,k as Ke,b as ct,q as At,r as zt,s as Et,E as $t,U as Ne,u as Ft,a as Pt,t as Ot,v as Ut,w as Ht}from"./useMedia-DkvP1QLG.js";import{o as L,w as O,M as dt,B as k,t as M,D as le,j as oe,k as ce,l as de,m as he,L as H,I as V,n as me,a as ee,X as pe,O as Lt,P as Xt,R as Yt,V as nt,z as Bt,A as Kt,E as Vt,S as Wt}from"./index-DX9xeoQx.js";import{C as qt,c as Qt}from"./card-C7fgQS_U.js";import{C as Te}from"./checkbox-BV2kjQBe.js";import{S as ge,a as fe,b as we,c as je,d as se,C as Gt,h as Zt}from"./select-CHW5R8qv.js";import{s as Jt,t as es,u as ts,v as ss,w as as,A as ns}from"./radix-lA_IxTIV.js";import{d as ht,G as rs,e as is,b as ls,u as os,a as cs,D as ds,f as hs,P as ms}from"./core.esm-DRuhixPo.js";import{b as ve,a as Ve,f as We}from"./format-C88SDH8g.js";import{m as W,u as us}from"./use-mobile-C1r2eP64.js";import{T as xs,a as ps,b as mt,c as B,d as gs,e as K}from"./table-BjSue8Ev.js";import{C as qe}from"./copy-CgYzmj06.js";import{B as Qe}from"./badge-B8OxObuF.js";import{T as fs}from"./trash-2-CWWRVuRB.js";import{P as ws}from"./plus-HdRn2U0S.js";import{C as js}from"./check-CxKAR64t.js";import{S as rt}from"./search-C-3Q9nn7.js";const vs=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],ys=L("chevron-left",vs);const bs=[["path",{d:"M6 2v14a2 2 0 0 0 2 2h14",key:"ron5a4"}],["path",{d:"M18 22V8a2 2 0 0 0-2-2H2",key:"7s9ehn"}]],Ns=L("crop",bs);const Cs=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12.5 8 15l2 2.5",key:"1tg20x"}],["path",{d:"m14 12.5 2 2.5-2 2.5",key:"yinavb"}]],ks=L("file-code",Cs);const Ds=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Ss=L("film",Ds);const Ms=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Ts=L("folder-open",Ms);const _s=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],te=L("folder",_s);const Is=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],Rs=L("layout-grid",Is);const As=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],zs=L("list",As);const Es=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]],$s=L("maximize-2",Es);const Fs=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],Ps=L("music",Fs);const Os=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Us=L("refresh-cw",Os);function Ce({delayDuration:a=0,...t}){return e.jsx(Jt,{"data-slot":"tooltip-provider",delayDuration:a,...t})}function ke({...a}){return e.jsx(es,{"data-slot":"tooltip",...a})}function De({...a}){return e.jsx(ts,{"data-slot":"tooltip-trigger",...a})}function Se({className:a,sideOffset:t=0,children:s,...l}){return e.jsx(ss,{children:e.jsxs(as,{"data-slot":"tooltip-content",sideOffset:t,className:O("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...l,children:[s,e.jsx(ns,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}function _e({mimeType:a,className:t}){return a==="application/pdf"?e.jsx(dt,{className:O("text-blue-500",t)}):a.startsWith("video/")?e.jsx(Ss,{className:O("text-purple-500",t)}):a.startsWith("audio/")?e.jsx(Ps,{className:O("text-green-500",t)}):a==="image/svg+xml"?e.jsx(ks,{className:O("text-orange-500",t)}):e.jsx(St,{className:O("text-muted-foreground",t)})}function Hs(a){return a==="application/pdf"?"PDF":a==="image/svg+xml"?"SVG":a.startsWith("image/")?"Image":a.startsWith("video/")?"Video":a.startsWith("audio/")?"Audio":a.split("/")[1]?.toUpperCase()??"File"}function Ls({item:a,selected:t,onToggle:s,onSelect:l,onLightbox:n,folderName:r}){const{attributes:c,listeners:h,setNodeRef:o,isDragging:i}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";return e.jsxs(mt,{ref:o,className:O("cursor-pointer",i&&"opacity-50"),onClick:l,children:[e.jsx(K,{onPointerDown:g=>g.stopPropagation(),onClick:g=>g.stopPropagation(),children:e.jsx(Te,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsx(K,{className:"w-6 p-1 hidden md:table-cell",children:e.jsx("div",{className:"cursor-grab text-muted-foreground",...c,...h,children:e.jsx(rs,{className:"h-4 w-4"})})}),e.jsx(K,{className:"p-1",children:x?e.jsx("img",{src:W(a.urls?.thumb_sm??a.url),alt:a.alt||a.filename,className:O("h-8 w-8 rounded object-cover",n&&"cursor-zoom-in"),onClick:n?g=>{g.stopPropagation(),n()}:void 0}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center",children:e.jsx(_e,{mimeType:a.mimeType,className:"h-5 w-5"})})}),e.jsxs(K,{className:"max-w-[200px]",children:[r&&e.jsx("span",{className:"text-muted-foreground block truncate text-xs",children:r}),e.jsx("span",{className:"block truncate text-sm font-medium",children:a.filename})]}),e.jsx(K,{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Hs(a.mimeType)})}),e.jsx(K,{className:"text-right",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ve(a.size)})}),e.jsx(K,{className:"hidden lg:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:a.width&&a.height?`${a.width}×${a.height}`:"—"})}),e.jsx(K,{className:"hidden lg:table-cell",children:a.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(g=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]",children:g},g)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})}),e.jsx(K,{className:"hidden md:table-cell",children:e.jsx(Ce,{children:e.jsxs(ke,{children:[e.jsx(De,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Ve(a.uploadedAt)})}),e.jsx(Se,{children:We(a.uploadedAt)})]})})}),e.jsx(K,{onPointerDown:g=>g.stopPropagation(),onClick:g=>g.stopPropagation(),children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(W(a.url)),M.success("URL copied to clipboard")},children:e.jsx(qe,{className:"h-3.5 w-3.5"})})})]})}function Xs({items:a,host:t,onSelect:s,selectedIds:l,onToggle:n,onToggleAll:r,allSelected:c,onLightbox:h,folderMap:o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(xs,{children:[e.jsx(ps,{children:e.jsxs(mt,{children:[e.jsx(B,{className:"w-10",children:e.jsx(Te,{checked:c,onCheckedChange:r,"aria-label":"Select all"})}),e.jsx(B,{className:"w-6 hidden md:table-cell"}),e.jsx(B,{className:"w-12"}),e.jsx(B,{children:"Filename"}),e.jsx(B,{className:"w-20 hidden md:table-cell",children:"Type"}),e.jsx(B,{className:"w-24 text-right",children:"Size"}),e.jsx(B,{className:"w-28 hidden lg:table-cell",children:"Dimensions"}),e.jsx(B,{className:"w-40 hidden lg:table-cell",children:"Tags"}),e.jsx(B,{className:"w-32 hidden md:table-cell",children:"Uploaded"}),e.jsx(B,{className:"w-10"})]})}),e.jsx(gs,{children:a.map(i=>e.jsx(Ls,{item:i,host:t,selected:l.has(i.mediaId),onToggle:()=>n(i.mediaId),onSelect:()=>s(i),folderName:o?.get(i.folderId??""),onLightbox:h&&i.mimeType.startsWith("image/")&&i.mimeType!=="image/svg+xml"?()=>h(i):void 0},i.mediaId))})]})})}var Ys=Object.defineProperty,Bs=(a,t,s)=>t in a?Ys(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,T=(a,t,s)=>Bs(a,typeof t!="symbol"?t+"":t,s);const Me={x:0,y:0,width:0,height:0,unit:"px"},ne=(a,t,s)=>Math.min(Math.max(a,t),s),Ks=(...a)=>a.filter(t=>t&&typeof t=="string").join(" "),it=(a,t)=>a===t||a.width===t.width&&a.height===t.height&&a.x===t.x&&a.y===t.y&&a.unit===t.unit;function re(a,t,s){return a.unit==="%"?{...Me,...a,unit:"%"}:{unit:"%",x:a.x?a.x/t*100:0,y:a.y?a.y/s*100:0,width:a.width?a.width/t*100:0,height:a.height?a.height/s*100:0}}function G(a,t,s){return a.unit?a.unit==="px"?{...Me,...a,unit:"px"}:{unit:"px",x:a.x?a.x*t/100:0,y:a.y?a.y*s/100:0,width:a.width?a.width*t/100:0,height:a.height?a.height*s/100:0}:{...Me,...a,unit:"px"}}function lt(a,t,s,l,n,r=0,c=0,h=l,o=n){const i={...a};let x=Math.min(r,l),g=Math.min(c,n),m=Math.min(h,l),d=Math.min(o,n);t&&(t>1?(x=c?c*t:x,g=x/t,m=h*t):(g=r?r/t:g,x=g*t,d=o/t)),i.y<0&&(i.height=Math.max(i.height+i.y,g),i.y=0),i.x<0&&(i.width=Math.max(i.width+i.x,x),i.x=0);const b=l-(i.x+i.width);b<0&&(i.x=Math.min(i.x,l-x),i.width+=b);const p=n-(i.y+i.height);if(p<0&&(i.y=Math.min(i.y,n-g),i.height+=p),i.width<x&&((s==="sw"||s=="nw")&&(i.x-=x-i.width),i.width=x),i.height<g&&((s==="nw"||s=="ne")&&(i.y-=g-i.height),i.height=g),i.width>m&&((s==="sw"||s=="nw")&&(i.x-=m-i.width),i.width=m),i.height>d&&((s==="nw"||s=="ne")&&(i.y-=d-i.height),i.height=d),t){const j=i.width/i.height;if(j<t){const w=Math.max(i.width/t,g);(s==="nw"||s=="ne")&&(i.y-=w-i.height),i.height=w}else if(j>t){const w=Math.max(i.height*t,x);(s==="sw"||s=="nw")&&(i.x-=w-i.width),i.width=w}}return i}function Vs(a,t,s,l){const n={...a};return t==="ArrowLeft"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="w"?(n.x-=s,n.width+=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="e"?n.width-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowRight"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="w"?(n.x+=s,n.width-=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="e"?n.width+=s:l==="se"&&(n.width+=s,n.height+=s)),t==="ArrowUp"?l==="nw"?(n.x-=s,n.y-=s,n.width+=s,n.height+=s):l==="n"?(n.y-=s,n.height+=s):l==="ne"?(n.y-=s,n.width+=s,n.height+=s):l==="sw"?(n.x+=s,n.width-=s,n.height-=s):l==="s"?n.height-=s:l==="se"&&(n.width-=s,n.height-=s):t==="ArrowDown"&&(l==="nw"?(n.x+=s,n.y+=s,n.width-=s,n.height-=s):l==="n"?(n.y+=s,n.height-=s):l==="ne"?(n.y+=s,n.width-=s,n.height-=s):l==="sw"?(n.x-=s,n.width+=s,n.height+=s):l==="s"?n.height+=s:l==="se"&&(n.width+=s,n.height+=s)),n}const ie={capture:!0,passive:!1};let Ws=0;const Z=class U extends u.PureComponent{constructor(){super(...arguments),T(this,"docMoveBound",!1),T(this,"mouseDownOnCrop",!1),T(this,"dragStarted",!1),T(this,"evData",{startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0}),T(this,"componentRef",u.createRef()),T(this,"mediaRef",u.createRef()),T(this,"resizeObserver"),T(this,"initChangeCalled",!1),T(this,"instanceId",`rc-${Ws++}`),T(this,"state",{cropIsActive:!1,newCropIsBeingDrawn:!1}),T(this,"onCropPointerDown",t=>{const{crop:s,disabled:l}=this.props,n=this.getBox();if(!s)return;const r=G(s,n.width,n.height);if(l)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const c=t.target.dataset.ord,h=!!c;let o=t.clientX,i=t.clientY,x=r.x,g=r.y;if(c){const m=t.clientX-n.x,d=t.clientY-n.y;let b=0,p=0;c==="ne"||c=="e"?(b=m-(r.x+r.width),p=d-r.y,x=r.x,g=r.y+r.height):c==="se"||c==="s"?(b=m-(r.x+r.width),p=d-(r.y+r.height),x=r.x,g=r.y):c==="sw"||c=="w"?(b=m-r.x,p=d-(r.y+r.height),x=r.x+r.width,g=r.y):(c==="nw"||c=="n")&&(b=m-r.x,p=d-r.y,x=r.x+r.width,g=r.y+r.height),o=x+n.x+b,i=g+n.y+p}this.evData={startClientX:o,startClientY:i,startCropX:x,startCropY:g,clientX:t.clientX,clientY:t.clientY,isResize:h,ord:c},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})}),T(this,"onComponentPointerDown",t=>{const{crop:s,disabled:l,locked:n,keepSelection:r,onChange:c}=this.props,h=this.getBox();if(l||n||r&&s)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const o=t.clientX-h.x,i=t.clientY-h.y,x={unit:"px",x:o,y:i,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:o,startCropY:i,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,c(G(x,h.width,h.height),re(x,h.width,h.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})}),T(this,"onDocPointerMove",t=>{const{crop:s,disabled:l,onChange:n,onDragStart:r}=this.props,c=this.getBox();if(l||!s||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,r&&r(t));const{evData:h}=this;h.clientX=t.clientX,h.clientY=t.clientY;let o;h.isResize?o=this.resizeCrop():o=this.dragCrop(),it(s,o)||n(G(o,c.width,c.height),re(o,c.width,c.height))}),T(this,"onComponentKeyDown",t=>{const{crop:s,disabled:l,onChange:n,onComplete:r}=this.props;if(l)return;const c=t.key;let h=!1;if(!s)return;const o=this.getBox(),i=this.makePixelCrop(o),x=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep;if(c==="ArrowLeft"?(i.x-=x,h=!0):c==="ArrowRight"?(i.x+=x,h=!0):c==="ArrowUp"?(i.y-=x,h=!0):c==="ArrowDown"&&(i.y+=x,h=!0),h){t.cancelable&&t.preventDefault(),i.x=ne(i.x,0,o.width-i.width),i.y=ne(i.y,0,o.height-i.height);const g=G(i,o.width,o.height),m=re(i,o.width,o.height);n(g,m),r&&r(g,m)}}),T(this,"onHandlerKeyDown",(t,s)=>{const{aspect:l=0,crop:n,disabled:r,minWidth:c=0,minHeight:h=0,maxWidth:o,maxHeight:i,onChange:x,onComplete:g}=this.props,m=this.getBox();if(r||!n)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const d=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep,b=G(n,m.width,m.height),p=Vs(b,t.key,d,s),j=lt(p,l,s,m.width,m.height,c,h,o,i);if(!it(n,j)){const w=re(j,m.width,m.height);x(j,w),g&&g(j,w)}}),T(this,"onDocPointerDone",t=>{const{crop:s,disabled:l,onComplete:n,onDragEnd:r}=this.props,c=this.getBox();this.unbindDocMove(),!(l||!s)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,r&&r(t),n&&n(G(s,c.width,c.height),re(s,c.width,c.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))}),T(this,"onDragFocus",()=>{var t;(t=this.componentRef.current)==null||t.scrollTo(0,0)})}get document(){return document}getBox(){const t=this.mediaRef.current;if(!t)return{x:0,y:0,width:0,height:0};const{x:s,y:l,width:n,height:r}=t.getBoundingClientRect();return{x:s,y:l,width:n,height:r}}componentDidUpdate(t){const{crop:s,onComplete:l}=this.props;if(l&&!t.crop&&s){const{width:n,height:r}=this.getBox();n&&r&&l(G(s,n,r),re(s,n,r))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,ie),this.document.addEventListener("pointerup",this.onDocPointerDone,ie),this.document.addEventListener("pointercancel",this.onDocPointerDone,ie),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,ie),this.document.removeEventListener("pointerup",this.onDocPointerDone,ie),this.document.removeEventListener("pointercancel",this.onDocPointerDone,ie),this.docMoveBound=!1)}getCropStyle(){const{crop:t}=this.props;if(t)return{top:`${t.y}${t.unit}`,left:`${t.x}${t.unit}`,width:`${t.width}${t.unit}`,height:`${t.height}${t.unit}`}}dragCrop(){const{evData:t}=this,s=this.getBox(),l=this.makePixelCrop(s),n=t.clientX-t.startClientX,r=t.clientY-t.startClientY;return l.x=ne(t.startCropX+n,0,s.width-l.width),l.y=ne(t.startCropY+r,0,s.height-l.height),l}getPointRegion(t,s,l,n){const{evData:r}=this,c=r.clientX-t.x,h=r.clientY-t.y;let o;n&&s?o=s==="nw"||s==="n"||s==="ne":o=h<r.startCropY;let i;return l&&s?i=s==="nw"||s==="w"||s==="sw":i=c<r.startCropX,i?o?"nw":"sw":o?"ne":"se"}resolveMinDimensions(t,s,l=0,n=0){const r=Math.min(l,t.width),c=Math.min(n,t.height);return!s||!r&&!c?[r,c]:s>1?r?[r,r/s]:[c*s,c]:c?[c*s,c]:[r,r/s]}resizeCrop(){const{evData:t}=this,{aspect:s=0,maxWidth:l,maxHeight:n}=this.props,r=this.getBox(),[c,h]=this.resolveMinDimensions(r,s,this.props.minWidth,this.props.minHeight);let o=this.makePixelCrop(r);const i=this.getPointRegion(r,t.ord,c,h),x=t.ord||i;let g=t.clientX-t.startClientX,m=t.clientY-t.startClientY;(c&&x==="nw"||x==="w"||x==="sw")&&(g=Math.min(g,-c)),(h&&x==="nw"||x==="n"||x==="ne")&&(m=Math.min(m,-h));const d={unit:"px",x:0,y:0,width:0,height:0};i==="ne"?(d.x=t.startCropX,d.width=g,s?(d.height=d.width/s,d.y=t.startCropY-d.height):(d.height=Math.abs(m),d.y=t.startCropY-d.height)):i==="se"?(d.x=t.startCropX,d.y=t.startCropY,d.width=g,s?d.height=d.width/s:d.height=m):i==="sw"?(d.x=t.startCropX+g,d.y=t.startCropY,d.width=Math.abs(g),s?d.height=d.width/s:d.height=m):i==="nw"&&(d.x=t.startCropX+g,d.width=Math.abs(g),s?(d.height=d.width/s,d.y=t.startCropY-d.height):(d.height=Math.abs(m),d.y=t.startCropY+m));const b=lt(d,s,i,r.width,r.height,c,h,l,n);return s||U.xyOrds.indexOf(x)>-1?o=b:U.xOrds.indexOf(x)>-1?(o.x=b.x,o.width=b.width):U.yOrds.indexOf(x)>-1&&(o.y=b.y,o.height=b.height),o.x=ne(o.x,0,r.width-o.width),o.y=ne(o.y,0,r.height-o.height),o}renderCropSelection(){const{ariaLabels:t=U.defaultProps.ariaLabels,disabled:s,locked:l,renderSelectionAddon:n,ruleOfThirds:r,crop:c}=this.props,h=this.getCropStyle();if(c)return S.createElement("div",{style:h,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!s&&!l&&S.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},S.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),S.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),S.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),S.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw",tabIndex:0,"aria-label":t.nwDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"nw"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n",tabIndex:0,"aria-label":t.nDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"n"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne",tabIndex:0,"aria-label":t.neDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"ne"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e",tabIndex:0,"aria-label":t.eDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"e"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se",tabIndex:0,"aria-label":t.seDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"se"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s",tabIndex:0,"aria-label":t.sDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"s"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw",tabIndex:0,"aria-label":t.swDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"sw"),role:"button"}),S.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w",tabIndex:0,"aria-label":t.wDragHandle,onKeyDown:o=>this.onHandlerKeyDown(o,"w"),role:"button"})),n&&S.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:o=>o.stopPropagation()},n(this.state)),r&&S.createElement(S.Fragment,null,S.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),S.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const s={...Me,...this.props.crop||{}};return G(s,t.width,t.height)}render(){const{aspect:t,children:s,circularCrop:l,className:n,crop:r,disabled:c,locked:h,style:o,ruleOfThirds:i}=this.props,{cropIsActive:x,newCropIsBeingDrawn:g}=this.state,m=r?this.renderCropSelection():null,d=Ks("ReactCrop",n,x&&"ReactCrop--active",c&&"ReactCrop--disabled",h&&"ReactCrop--locked",g&&"ReactCrop--new-crop",r&&t&&"ReactCrop--fixed-aspect",r&&l&&"ReactCrop--circular-crop",r&&i&&"ReactCrop--rule-of-thirds",!this.dragStarted&&r&&!r.width&&!r.height&&"ReactCrop--invisible-crop",l&&"ReactCrop--no-animate");return S.createElement("div",{ref:this.componentRef,className:d,style:o},S.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},s),r?S.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},S.createElement("defs",null,S.createElement("mask",{id:`hole-${this.instanceId}`},S.createElement("rect",{width:"100%",height:"100%",fill:"white"}),l?S.createElement("ellipse",{cx:`${r.x+r.width/2}${r.unit}`,cy:`${r.y+r.height/2}${r.unit}`,rx:`${r.width/2}${r.unit}`,ry:`${r.height/2}${r.unit}`,fill:"black"}):S.createElement("rect",{x:`${r.x}${r.unit}`,y:`${r.y}${r.unit}`,width:`${r.width}${r.unit}`,height:`${r.height}${r.unit}`,fill:"black"}))),S.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,m)}};T(Z,"xOrds",["e","w"]),T(Z,"yOrds",["n","s"]),T(Z,"xyOrds",["nw","ne","se","sw"]),T(Z,"nudgeStep",1),T(Z,"nudgeStepMedium",10),T(Z,"nudgeStepLarge",100),T(Z,"defaultProps",{ariaLabels:{cropArea:"Use the arrow keys to move the crop selection area",nwDragHandle:"Use the arrow keys to move the north west drag handle to change the crop selection area",nDragHandle:"Use the up and down arrow keys to move the north drag handle to change the crop selection area",neDragHandle:"Use the arrow keys to move the north east drag handle to change the crop selection area",eDragHandle:"Use the up and down arrow keys to move the east drag handle to change the crop selection area",seDragHandle:"Use the arrow keys to move the south east drag handle to change the crop selection area",sDragHandle:"Use the up and down arrow keys to move the south drag handle to change the crop selection area",swDragHandle:"Use the arrow keys to move the south west drag handle to change the crop selection area",wDragHandle:"Use the up and down arrow keys to move the west drag handle to change the crop selection area"}});let qs=Z;const Qs=[{label:"Free",value:""},{label:"1:1 Square",value:"1"},{label:"4:3",value:"4/3"},{label:"3:2",value:"3/2"},{label:"16:9",value:"16/9"},{label:"2:3",value:"2/3"},{label:"3:4",value:"3/4"}],ut=[{label:"Original",value:"",ext:""},{label:"JPEG",value:"jpeg",ext:".jpg"},{label:"PNG",value:"png",ext:".png"},{label:"WebP",value:"webp",ext:".webp"},{label:"AVIF",value:"avif",ext:".avif"}],Gs={"image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/tiff":".tiff"};function $e(a,t){return a?ut.find(s=>s.value===a)?.ext||`.${a}`:Gs[t]||".jpg"}function Zs(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Js({host:a,media:t,onClose:s,onSaved:l}){const n=u.useRef(null),[r,c]=u.useState(),[h,o]=u.useState(),[i,x]=u.useState(""),[g,m]=u.useState(""),[d,b]=u.useState(""),[p,j]=u.useState(""),[w,A]=u.useState("80"),[_,I]=u.useState(()=>{const v=$e("",t.mimeType),R=t.filename.lastIndexOf(".");return`${R>0?t.filename.substring(0,R):t.filename}-transformed${v}`});function E(v){const R=v==="__original__"?"":v;j(R);const q=$e(R,t.mimeType);I(ae=>Zs(ae,q))}const F=Mt(a,t.mediaId),[y,N]=u.useState(null),P=u.useCallback(()=>{if(!h||!y)return null;const v=(t.width??y.width)/y.width,R=(t.height??y.height)/y.height;return{cropX:Math.round(h.x*v),cropY:Math.round(h.y*R),cropW:Math.round(h.width*v),cropH:Math.round(h.height*R)}},[h,t.width,t.height,y]),X=u.useMemo(()=>P(),[P]);async function ue(){const v=X,R=g?parseInt(g):void 0,q=d?parseInt(d):void 0;if(!v&&!R&&!q&&!p){M.error("Please specify a crop, resize, or format change");return}if(!_.trim()){M.error("Filename is required");return}const ae=$e(p,t.mimeType);if(!_.trim().toLowerCase().endsWith(ae)){M.error(`Filename must end with ${ae} to match the output format`);return}try{const $=await F.mutateAsync({...v??{},...R?{width:R}:{},...q?{height:q}:{},...p?{format:p}:{},...w?{quality:parseInt(w)}:{},filename:_.trim()});M.success("Transform saved as new media"),l?.($),s()}catch($){M.error("Transform failed",{description:$ instanceof Error?$.message:void 0})}}function J(v){x(v==="__free__"?"":v),c(void 0),o(void 0)}function Ge(v){if(!v)return;const R=v.split("/");return R.length===2?Number(R[0])/Number(R[1]):Number(v)||void 0}const xe=Ge(i);return e.jsx(le,{open:!0,onOpenChange:()=>s(),children:e.jsxs(oe,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ce,{children:[e.jsx(de,{children:"Transform Image"}),e.jsx(he,{className:"sr-only",children:"Crop, resize, or convert image format"})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_280px] gap-6",children:[e.jsx("div",{className:"min-h-0 overflow-hidden rounded border bg-muted/30 flex items-center justify-center",children:e.jsx(qs,{crop:r,onChange:v=>c(v),onComplete:v=>o(v),aspect:xe,children:e.jsx("img",{ref:n,src:W(t.url),alt:t.alt||t.filename,className:"max-h-[60vh] max-w-full object-contain",onLoad:v=>{const R=v.currentTarget;N({width:R.naturalWidth,height:R.naturalHeight})}})})}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:["Original: ",t.width,"×",t.height]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Crop aspect ratio"}),e.jsxs(ge,{value:i||"__free__",onValueChange:J,children:[e.jsx(fe,{children:e.jsx(we,{placeholder:"Free"})}),e.jsx(je,{children:Qs.map(v=>e.jsx(se,{value:v.value||"__free__",children:v.label},v.value||"__free__"))})]}),h&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Crop: ",X?.cropW,"×",X?.cropH," at (",X?.cropX,", ",X?.cropY,")"]}),h&&e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>{c(void 0),o(void 0)},children:"Clear crop"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Resize (optional)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{children:e.jsx(V,{type:"number",placeholder:"Width",value:g,onChange:v=>m(v.target.value),min:1,max:2048})}),e.jsx("div",{children:e.jsx(V,{type:"number",placeholder:"Height",value:d,onChange:v=>b(v.target.value),min:1,max:2048})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Output format"}),e.jsxs(ge,{value:p||"__original__",onValueChange:E,children:[e.jsx(fe,{children:e.jsx(we,{placeholder:"Original"})}),e.jsx(je,{children:ut.map(v=>e.jsx(se,{value:v.value||"__original__",children:v.label},v.value||"__original__"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Quality (1-100)"}),e.jsx(V,{type:"number",value:w,onChange:v=>A(v.target.value),min:1,max:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Save as filename"}),e.jsx(V,{value:_,onChange:v=>I(v.target.value)})]})]})]}),e.jsxs(me,{children:[e.jsx(k,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs(k,{onClick:ue,disabled:F.isPending,children:[F.isPending&&e.jsx(ee,{className:"mr-2 h-4 w-4 animate-spin"}),"Save as New Image"]})]})]})})}const ea=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function ta({host:a,media:t,onClose:s,onDeleted:l,folders:n,tagSuggestions:r}){const[c,h]=u.useState(t.alt??""),[o,i]=u.useState(t.caption??""),[x,g]=u.useState(t.userTags??[]),[m,d]=u.useState(t.folderId||"__none__"),[b,p]=u.useState(!1),j=ea.has(t.mimeType),w=Tt(a,t.mediaId),A=_t(a,t.mediaId),{data:_,isLoading:I}=It(a,t.mediaId),E=t.tags.filter(N=>!t.userTags?.includes(N));async function F(){try{await w.mutateAsync({alt:c,caption:o,userTags:x,folderId:m==="__none__"?"":m}),M.success("Media updated"),s()}catch(N){M.error("Failed to update",{description:N instanceof Error?N.message:void 0})}}async function y(){try{await A.mutateAsync(),M.success("Media deleted"),l?.(t.mediaId),s()}catch(N){M.error("Failed to delete",{description:N instanceof Error?N.message:void 0})}}return e.jsxs(le,{open:!0,onOpenChange:()=>s(),children:[e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsx(de,{children:t.filename}),e.jsx(he,{className:"sr-only",children:"View and edit media details"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-muted-foreground text-sm",children:[t.mimeType," · ",ve(t.size),t.width&&t.height&&` · ${t.width}×${t.height}`," · ",We(t.uploadedAt)]}),e.jsxs("div",{className:"flex gap-2",children:[j&&e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>p(!0),children:[e.jsx(Ns,{className:"mr-1.5 h-3.5 w-3.5"}),"Transform"]}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(W(t.url)),M.success("URL copied to clipboard")},children:[e.jsx(qe,{className:"mr-1.5 h-3.5 w-3.5"}),"Copy URL"]})]})]}),E.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(H,{className:"text-xs text-muted-foreground",children:"Auto-detected tags"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:E.map(N=>e.jsx(Qe,{variant:"outline",className:"text-xs",children:N},N))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Tags"}),e.jsx(Pe,{tags:x,onChange:g,placeholder:"Add tags...",suggestions:r})]}),n&&n.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:"Folder"}),e.jsxs(ge,{value:m,onValueChange:d,children:[e.jsx(fe,{children:e.jsx(we,{placeholder:"No folder"})}),e.jsxs(je,{children:[e.jsx(se,{value:"__none__",children:"No folder"}),n.map(N=>e.jsx(se,{value:N.folderId,children:N.name},N.folderId))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{htmlFor:"alt",children:"Alt text"}),e.jsx(V,{id:"alt",value:c,onChange:N=>h(N.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{htmlFor:"caption",children:"Caption"}),e.jsx(V,{id:"caption",value:o,onChange:N=>i(N.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{className:"text-xs text-muted-foreground",children:"Used in"}),I?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ee,{className:"h-3.5 w-3.5 animate-spin"}),"Checking usage..."]}):_?.references.length?e.jsxs("div",{className:"space-y-1",children:[_.references.map(N=>e.jsxs(kt,{to:`/sites/${a}/content/${N.collection}/${N.contentId}`,className:"flex items-center gap-2 rounded px-2 py-1 text-sm hover:bg-muted",onClick:s,children:[e.jsx(dt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:N.title||N.contentId}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",N.collection,")"]})]},N.contentId)),_.note&&e.jsx("p",{className:"text-muted-foreground text-xs italic",children:_.note})]}):e.jsx("p",{className:"text-muted-foreground text-sm",children:"Not referenced in any content."})]})]}),e.jsxs(me,{className:"flex justify-between",children:[e.jsxs(Oe,{children:[e.jsx(Rt,{asChild:!0,children:e.jsxs(k,{variant:"destructive",size:"sm",children:[e.jsx(fs,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ue,{children:[e.jsxs(He,{children:[e.jsx(Le,{children:"Delete media?"}),e.jsxs(Xe,{children:["This will permanently delete “",t.filename,"”. This action cannot be undone."]})]}),e.jsxs(Ye,{children:[e.jsx(Be,{children:"Cancel"}),e.jsx(Ke,{onClick:y,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(k,{onClick:F,children:"Save"})]})]})]}),b&&e.jsx(Js,{host:a,media:t,onClose:()=>p(!1),onSaved:()=>s()})]})}function sa({tags:a,activeTag:t,onTagChange:s}){return a.length===0?null:e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-1.5",children:[a.map(l=>e.jsx(Qe,{variant:t===l?"default":"secondary",className:"cursor-pointer select-none",onClick:()=>s(t===l?void 0:l),children:l},l)),t&&e.jsxs(k,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s(void 0),children:[e.jsx(pe,{className:"mr-1 h-3 w-3"}),"Clear"]})]})}function Fe({id:a,children:t}){const{setNodeRef:s,isOver:l}=is({id:a,data:{type:"folder"}});return e.jsx("div",{ref:s,children:t(l)})}function ot({host:a,selectedFolderId:t,onSelect:s}){const{data:l}=ct(a),n=At(a),r=zt(a),c=Et(a),[h,o]=u.useState(!1),[i,x]=u.useState(""),[g,m]=u.useState(null),[d,b]=u.useState(""),[p,j]=u.useState(null),w=u.useRef(null),A=u.useRef(null),_=l?.items??[];u.useEffect(()=>{h&&w.current?.focus()},[h]),u.useEffect(()=>{g&&A.current?.focus()},[g]);async function I(){const y=i.trim();if(!y){o(!1),x("");return}try{await n.mutateAsync(y),M.success("Folder created")}catch(N){M.error("Failed to create folder",{description:N instanceof Error?N.message:void 0})}o(!1),x("")}async function E(y){const N=d.trim();if(!N){m(null);return}try{await r.mutateAsync({folderId:y,name:N}),M.success("Folder renamed")}catch(P){M.error("Failed to rename folder",{description:P instanceof Error?P.message:void 0})}m(null)}async function F(){if(p){try{await c.mutateAsync(p.folderId),M.success("Folder deleted"),t===p.folderId&&s(null)}catch(y){M.error("Failed to delete folder",{description:y instanceof Error?y.message:void 0})}j(null)}}return e.jsxs("div",{className:"flex w-48 shrink-0 flex-col border-r",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Folders"}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>o(!0),children:e.jsx(ws,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[e.jsx(Fe,{id:"all-media",children:y=>e.jsx("button",{className:O("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t===null&&"bg-accent font-medium",y&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s(null),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4"}),"All Media"]})})}),_.map(y=>e.jsx(Fe,{id:y.folderId,children:N=>e.jsx("div",{className:O("group flex w-full items-center justify-between px-3 py-1.5 text-sm hover:bg-accent/50",t===y.folderId&&"bg-accent font-medium",N&&"ring-2 ring-primary bg-primary/10"),children:g===y.folderId?e.jsx(V,{ref:A,value:d,onChange:P=>b(P.target.value),onKeyDown:P=>{P.key==="Enter"&&E(y.folderId),P.key==="Escape"&&m(null)},onBlur:()=>E(y.folderId),className:"h-6 text-sm"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"flex flex-1 items-center gap-2 text-left",onClick:()=>s(y.folderId),children:[e.jsx(te,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:y.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:y.count}),e.jsxs(Lt,{children:[e.jsx(Xt,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100",children:e.jsx($t,{className:"h-3.5 w-3.5"})})}),e.jsxs(Yt,{align:"end",children:[e.jsx(nt,{onClick:()=>{m(y.folderId),b(y.name)},children:"Rename"}),e.jsx(nt,{disabled:y.count>0,onClick:()=>j(y),children:"Delete"})]})]})]})]})})},y.folderId)),e.jsx(Fe,{id:"unfiled",children:y=>e.jsx("button",{className:O("flex w-full items-center justify-between px-3 py-1.5 text-left text-sm hover:bg-accent/50",t==="unfiled"&&"bg-accent font-medium",y&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s("unfiled"),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-4 w-4"}),"Unfiled"]})})}),h&&e.jsx("div",{className:"px-3 py-1.5",children:e.jsx(V,{ref:w,value:i,onChange:y=>x(y.target.value),onKeyDown:y=>{y.key==="Enter"&&I(),y.key==="Escape"&&(o(!1),x(""))},onBlur:I,placeholder:"Folder name...",className:"h-7 text-sm"})})]}),e.jsx(Oe,{open:!!p,onOpenChange:()=>j(null),children:e.jsxs(Ue,{children:[e.jsxs(He,{children:[e.jsx(Le,{children:"Delete folder?"}),e.jsxs(Xe,{children:["This will delete the folder “",p?.name,"”. Media items in this folder will become unfiled."]})]}),e.jsxs(Ye,{children:[e.jsx(Be,{children:"Cancel"}),e.jsx(Ke,{onClick:F,children:"Delete"})]})]})})]})}function aa({selectedCount:a,folders:t,onDelete:s,onMove:l,onAddTags:n,onRemoveTags:r,onClear:c,isPending:h}){const[o,i]=u.useState(null),[x,g]=u.useState(""),[m,d]=u.useState([]);function b(){i(null),g(""),d([])}return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 min-w-0",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:[a," selected"]}),e.jsx(k,{size:"sm",variant:"ghost",onClick:c,disabled:h,children:e.jsx(pe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto rounded-md border bg-muted/50 px-3 py-2 max-w-[calc(100vw-1.5rem)]",children:[e.jsx(k,{size:"sm",variant:"destructive",onClick:()=>i("delete"),disabled:h,className:"shrink-0",children:"Delete"}),e.jsx(k,{size:"sm",variant:"outline",onClick:()=>i("move"),disabled:h,className:"shrink-0",children:"Move to…"}),e.jsx(k,{size:"sm",variant:"outline",onClick:()=>i("addTags"),disabled:h,className:"shrink-0",children:"Add tags"}),e.jsx(k,{size:"sm",variant:"outline",onClick:()=>i("removeTags"),disabled:h,className:"shrink-0",children:"Remove tags"})]})]}),e.jsx(le,{open:o==="delete",onOpenChange:p=>!p&&b(),children:e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsxs(de,{children:["Delete ",a," item",a!==1?"s":"","?"]}),e.jsx(he,{children:"This action cannot be undone. The selected media items will be permanently deleted."})]}),e.jsxs(me,{children:[e.jsx(k,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(k,{variant:"destructive",onClick:async()=>{b(),await s()},disabled:h,children:[h&&e.jsx(ee,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})}),e.jsx(le,{open:o==="move",onOpenChange:p=>!p&&b(),children:e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsxs(de,{children:["Move ",a," item",a!==1?"s":""]}),e.jsx(he,{children:"Choose a destination folder."})]}),e.jsxs(ge,{value:x,onValueChange:g,children:[e.jsx(fe,{children:e.jsx(we,{placeholder:"Select folder..."})}),e.jsxs(je,{children:[e.jsx(se,{value:"__unfiled__",children:"Unfiled"}),t.map(p=>e.jsx(se,{value:p.folderId,children:p.name},p.folderId))]})]}),e.jsxs(me,{children:[e.jsx(k,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(k,{onClick:async()=>{const p=x==="__unfiled__"?"":x;b(),await l(p)},disabled:!x||h,children:[h&&e.jsx(ee,{className:"mr-1 h-3 w-3 animate-spin"}),"Move"]})]})]})}),e.jsx(le,{open:o==="addTags",onOpenChange:p=>!p&&b(),children:e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsxs(de,{children:["Add tags to ",a," item",a!==1?"s":""]}),e.jsx(he,{className:"sr-only",children:"Select tags to add to the selected items"})]}),e.jsx(Pe,{tags:m,onChange:d,placeholder:"Add tags..."}),e.jsxs(me,{children:[e.jsx(k,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(k,{onClick:async()=>{const p=[...m];b(),await n(p)},disabled:m.length===0||h,children:[h&&e.jsx(ee,{className:"mr-1 h-3 w-3 animate-spin"}),"Add"]})]})]})}),e.jsx(le,{open:o==="removeTags",onOpenChange:p=>!p&&b(),children:e.jsxs(oe,{children:[e.jsxs(ce,{children:[e.jsxs(de,{children:["Remove tags from ",a," item",a!==1?"s":""]}),e.jsx(he,{className:"sr-only",children:"Select tags to remove from the selected items"})]}),e.jsx(Pe,{tags:m,onChange:d,placeholder:"Tags to remove..."}),e.jsxs(me,{children:[e.jsx(k,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(k,{onClick:async()=>{const p=[...m];b(),await r(p)},disabled:m.length===0||h,children:[h&&e.jsx(ee,{className:"mr-1 h-3 w-3 animate-spin"}),"Remove"]})]})]})})]})}function na({onFiles:a,children:t}){const[s,l]=u.useState(!1),n=u.useRef(0),r=u.useCallback(i=>{i.preventDefault(),i.dataTransfer.types.includes("Files")&&(n.current++,l(!0))},[]),c=u.useCallback(i=>{i.preventDefault(),n.current--,n.current===0&&l(!1)},[]),h=u.useCallback(i=>{i.preventDefault(),i.dataTransfer.dropEffect="copy"},[]),o=u.useCallback(i=>{i.preventDefault(),n.current=0,l(!1);const x=Array.from(i.dataTransfer.files);x.length>0&&a(x)},[a]);return e.jsxs("div",{className:"relative flex-1",onDragEnter:r,onDragLeave:c,onDragOver:h,onDrop:o,children:[t,s&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/5",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg bg-background/90 px-6 py-4 shadow-lg",children:[e.jsx(Ne,{className:"h-8 w-8 text-primary"}),e.jsx("p",{className:"text-lg font-medium",children:"Drop files to upload"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Files will be uploaded to the current folder"})]})})]})}function ra({queue:a}){const{items:t,retry:s,dismiss:l,clearCompleted:n}=a,[r,c]=u.useState(!1),h=t.filter(d=>d.status==="uploading").length,o=t.filter(d=>d.status==="pending").length,i=t.filter(d=>d.status==="complete").length,x=t.filter(d=>d.status==="error").length,g=h===0&&o===0;if(u.useEffect(()=>{if(g&&t.length>0){const d=setTimeout(()=>c(!0),2e3);return()=>clearTimeout(d)}},[g,t.length]),t.length===0)return null;const m=g?`${i} uploaded${x?`, ${x} failed`:""}`:`Uploading ${h+o} file${h+o!==1?"s":""}`;return e.jsxs("div",{className:"fixed bottom-4 right-4 z-50 w-80 rounded-lg border bg-background shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:m}),e.jsxs("div",{className:"flex items-center gap-1",children:[g&&e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:n,children:"Clear"}),e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>c(!r),children:r?e.jsx(Gt,{className:"h-4 w-4"}):e.jsx(Zt,{className:"h-4 w-4"})})]})]}),!r&&e.jsx("div",{className:"max-h-60 overflow-y-auto",children:t.map(d=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-sm",children:[d.status==="uploading"&&e.jsx(ee,{className:"h-4 w-4 shrink-0 animate-spin"}),d.status==="complete"&&e.jsx(js,{className:"h-4 w-4 shrink-0 text-green-500"}),d.status==="error"&&e.jsx(pe,{className:"h-4 w-4 shrink-0 text-destructive"}),d.status==="pending"&&e.jsx("div",{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate",children:d.file.name}),d.status==="uploading"&&e.jsx("div",{className:"bg-muted mt-0.5 h-1 w-full rounded-full",children:e.jsx("div",{className:"bg-primary h-full rounded-full transition-all",style:{width:`${d.progress}%`}})}),d.status==="error"&&e.jsx("p",{className:"text-destructive truncate text-xs",children:d.error})]}),d.status==="error"&&e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>s(d.id),children:e.jsx(Us,{className:"h-3 w-3"})}),(d.status==="complete"||d.status==="error")&&e.jsx(k,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>l(d.id),children:e.jsx(pe,{className:"h-3 w-3"})})]},d.id))})]})}const ia=3;let la=0;function oa(a,t){const[s,l]=u.useState([]),n=Ft(a),r=Pt(a),c=u.useRef(0),h=u.useRef(s);h.current=s;const o=u.useRef(new Map),i=u.useCallback(async p=>{c.current++,l(j=>j.map(w=>w.id===p.id?{...w,status:"uploading",progress:0}:w));try{const{uploadUrl:j,mediaId:w}=await n.mutateAsync({filename:p.file.name,contentType:p.file.type,size:p.file.size});await new Promise((A,_)=>{const I=new XMLHttpRequest;o.current.set(p.id,I),I.upload.onprogress=E=>{if(E.lengthComputable){const F=Math.round(E.loaded/E.total*100);l(y=>y.map(N=>N.id===p.id?{...N,progress:F}:N))}},I.onload=()=>{o.current.delete(p.id),I.status>=200&&I.status<300?A():_(new Error(`Upload failed: ${I.status}`))},I.onerror=()=>{o.current.delete(p.id),_(new Error("Network error"))},I.onabort=()=>{o.current.delete(p.id),_(new Error("Upload aborted"))},I.open("PUT",j),I.setRequestHeader("Content-Type",p.file.type),I.send(p.file)}),await r.mutateAsync({mediaId:w,filename:p.file.name,folderId:p.folderId}),l(A=>A.map(_=>_.id===p.id?{..._,status:"complete",progress:100}:_))}catch(j){l(w=>w.map(A=>A.id===p.id?{...A,status:"error",error:j instanceof Error?j.message:"Upload failed"}:A))}finally{c.current--}},[n,r]),x=u.useRef(i);x.current=i,u.useEffect(()=>{const p=s.filter(w=>w.status==="pending"),j=ia-c.current;for(let w=0;w<Math.min(p.length,j);w++)x.current(p[w])},[s]),u.useEffect(()=>{const p=o.current;return()=>{p.forEach(j=>j.abort())}},[]);const g=u.useCallback(p=>{const j=Array.from(p).map(w=>({id:`upload-${la++}`,file:w,folderId:t||void 0,status:"pending",progress:0}));l(w=>[...w,...j])},[t]),m=u.useCallback(p=>{l(j=>j.map(w=>w.id===p?{...w,status:"pending",progress:0,error:void 0}:w))},[]),d=u.useCallback(p=>{l(j=>j.filter(w=>w.id!==p))},[]),b=u.useCallback(()=>{l(p=>p.filter(j=>j.status!=="complete"&&j.status!=="error"))},[]);return{items:s,addFiles:g,retry:m,dismiss:d,clearCompleted:b}}function ca({items:a,currentIndex:t,onClose:s,onNavigate:l}){const n=a[t],r=t>0,c=t<a.length-1,h=u.useRef(null),o=u.useCallback(i=>{i.key==="Escape"?s():i.key==="ArrowLeft"&&r?l(t-1):i.key==="ArrowRight"&&c&&l(t+1)},[s,l,t,r,c]);return u.useEffect(()=>(document.addEventListener("keydown",o),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",o),document.body.style.overflow=""}),[o]),n?e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col bg-black/90",onClick:s,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 text-white",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"min-w-0 flex-1 text-sm",children:[e.jsx("span",{className:"font-medium truncate block",children:n.filename}),e.jsxs("span",{className:"opacity-70 text-xs",children:[n.width&&n.height&&`${n.width}×${n.height} · `,ve(n.size)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"text-sm opacity-70",children:[t+1," / ",a.length]}),e.jsx(k,{variant:"ghost",size:"icon",className:"text-white hover:bg-white/20",onClick:s,children:e.jsx(pe,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"relative flex flex-1 items-center justify-center px-4 md:px-16",onClick:i=>i.stopPropagation(),onTouchStart:i=>{h.current=i.touches[0].clientX},onTouchEnd:i=>{if(h.current===null)return;const x=i.changedTouches[0].clientX-h.current;h.current=null,x>50&&r?l(t-1):x<-50&&c&&l(t+1)},children:[e.jsx("img",{src:W(n.url),alt:n.alt||n.filename,className:"max-h-full max-w-full object-contain"}),r&&e.jsx(k,{variant:"ghost",size:"icon",className:"absolute left-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t-1),children:e.jsx(ys,{className:"h-8 w-8"})}),c&&e.jsx(k,{variant:"ghost",size:"icon",className:"absolute right-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/20",onClick:()=>l(t+1),children:e.jsx(ls,{className:"h-8 w-8"})})]})]}):null}function da({open:a,duplicates:t,fileCount:s,onContinue:l,onCancel:n}){return e.jsx(Oe,{open:a,onOpenChange:r=>!r&&n(),children:e.jsxs(Ue,{children:[e.jsxs(He,{children:[e.jsx(Le,{children:"Possible duplicates found"}),e.jsx(Xe,{children:s===1?"A file with the same name and size already exists:":`${t.length} of ${s} files may already exist:`})]}),e.jsx("div",{className:"max-h-48 space-y-2 overflow-y-auto",children:t.map(r=>e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[r.mimeType.startsWith("image/")&&r.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(r.urls?.thumb_sm??r.url),alt:r.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(_e,{mimeType:r.mimeType,className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:r.filename}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[ve(r.size)," ·"," ",Ve(r.uploadedAt)]})]})]},r.mediaId))}),e.jsxs(Ye,{children:[e.jsx(Be,{onClick:n,children:"Cancel"}),e.jsx(Ke,{onClick:l,children:"Upload Anyway"})]})]})})}function ha(a){const[t,s]=u.useState(()=>{try{const n=localStorage.getItem(`viewMode:${a}`);if(n==="grid"||n==="list")return n}catch{}return"grid"}),l=u.useCallback(n=>{s(n);try{localStorage.setItem(`viewMode:${a}`,n)}catch{}},[a]);return[t,l]}const ma=({activatorEvent:a,draggingNodeRect:t,transform:s})=>{if(a&&t){const l=a;if(l.clientX!==void 0)return{...s,x:s.x+l.clientX-t.left-t.width/2,y:s.y+l.clientY-t.top-t.height/2}}return s},ua=[{value:"date_desc",label:"Newest first"},{value:"date_asc",label:"Oldest first"},{value:"name_asc",label:"Name A-Z"},{value:"name_desc",label:"Name Z-A"},{value:"size_desc",label:"Size (largest)"},{value:"size_asc",label:"Size (smallest)"}];function xa({item:a,selected:t,onToggle:s,onClick:l,folderName:n,onLightbox:r}){const{attributes:c,listeners:h,setNodeRef:o,isDragging:i}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";function g(m){m.stopPropagation(),navigator.clipboard.writeText(W(a.url)),M.success("URL copied to clipboard")}return e.jsx(qt,{ref:o,...c,...h,className:O("group relative cursor-pointer overflow-hidden",i&&"opacity-50",t&&"ring-2 ring-primary"),onClick:l,children:e.jsxs(Qt,{className:"p-0",children:[e.jsx("div",{className:O("absolute left-2 top-2 z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100 [@media(hover:none)]:rounded [@media(hover:none)]:bg-black/30 [@media(hover:none)]:p-0.5",t&&"opacity-100"),onPointerDown:m=>m.stopPropagation(),onClick:m=>m.stopPropagation(),children:e.jsx(Te,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsxs("div",{className:"absolute right-2 top-2 z-10 flex gap-1 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onPointerDown:m=>m.stopPropagation(),onClick:m=>m.stopPropagation(),children:[e.jsx(Ce,{children:e.jsxs(ke,{children:[e.jsx(De,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:g,children:e.jsx(qe,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"Copy URL"})]})}),x&&r&&e.jsx(Ce,{children:e.jsxs(ke,{children:[e.jsx(De,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:m=>{m.stopPropagation(),r()},children:e.jsx($s,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"View full size"})]})})]}),x?e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx("img",{src:W(a.urls?.thumb_md??a.url),alt:a.alt||a.filename,className:"h-full w-full object-cover"})}):e.jsx("div",{className:"bg-muted flex aspect-square items-center justify-center",children:e.jsx(_e,{mimeType:a.mimeType,className:"h-12 w-12"})}),e.jsxs("div",{className:"p-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:a.filename}),n&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(te,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate text-xs",children:n})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:ve(a.size)}),e.jsx(Ce,{children:e.jsxs(ke,{children:[e.jsx(De,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Ve(a.uploadedAt)})}),e.jsx(Se,{children:We(a.uploadedAt)})]})})]}),a.tags.length>0&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(m=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]",children:m},m)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})]})]})})}function Aa(){const{host:a}=Dt(),t=us(),[s,l]=ha("media"),[n,r]=u.useState("date_desc"),[c,h]=u.useState(""),[o,i]=u.useState(""),[x,g]=u.useState(null),[m,d]=u.useState(null),[b,p]=u.useState(void 0),[j,w]=u.useState(new Set),[A,_]=u.useState(null),[I,E]=u.useState(null),[F,y]=u.useState(null),[N,P]=u.useState([]),[X,ue]=u.useState(!1),J=u.useRef(null),xe=oa(a,m&&m!=="unfiled"?m:void 0),v=Ot(a),R=Ut(a),q=os(cs(ms,{activationConstraint:{distance:t?1e5:8}}));u.useEffect(()=>{const f=setTimeout(()=>{i(C=>{const D=c;return C!==D&&w(new Set),D})},300);return()=>clearTimeout(f)},[c]);const ae=m===null?void 0:m==="unfiled"?"":m,{data:$,isLoading:xt}=Ht(a,{sort:n,q:o||void 0,folderId:ae,tag:b}),{data:Ze}=ct(a),ye=u.useMemo(()=>Ze?.items??[],[Ze?.items]),Ie=u.useMemo(()=>{const f=new Map;for(const C of ye)f.set(C.folderId,C.name);return f},[ye]),be=u.useMemo(()=>($?.items??[]).filter(f=>f.mimeType.startsWith("image/")&&f.mimeType!=="image/svg+xml"),[$?.items]),Re=u.useMemo(()=>{const f=new Map;return be.forEach((C,D)=>f.set(C.mediaId,D)),f},[be]),{allTags:pt,allUserTags:gt}=u.useMemo(()=>{const f=$?.items??[],C=new Set,D=new Set;for(const z of f){for(const Y of z.tags)C.add(Y);for(const Y of z.userTags??[])D.add(Y)}return{allTags:Array.from(C).sort(),allUserTags:Array.from(D).sort()}},[$?.items]),Ae=$?.items.map(f=>f.mediaId)??[],ze=Ae.length>0&&Ae.every(f=>j.has(f));function Je(f){w(C=>{const D=new Set(C);return D.has(f)?D.delete(f):D.add(f),D})}function et(){w(ze?new Set:new Set(Ae))}async function ft(){const f=[...j],D=(await v.mutateAsync({mediaIds:f,action:"delete"})).failed.length;D?M.error(`${D} of ${f.length} failed to delete`):M.success(`${f.length} item(s) deleted`),w(new Set)}async function wt(f){const C=[...j],z=(await v.mutateAsync({mediaIds:C,action:"move",folderId:f})).failed.length;z?M.error(`${z} of ${C.length} failed to move`):M.success(`${C.length} item(s) moved`),w(new Set)}async function jt(f){const C=[...j],z=(await v.mutateAsync({mediaIds:C,action:"addTags",tags:f})).failed.length;z?M.error(`${z} of ${C.length} failed`):M.success(`Tags added to ${C.length} item(s)`),w(new Set)}async function vt(f){const C=[...j],z=(await v.mutateAsync({mediaIds:C,action:"removeTags",tags:f})).failed.length;z?M.error(`${z} of ${C.length} failed`):M.success(`Tags removed from ${C.length} item(s)`),w(new Set)}async function tt(f){const C=Array.from(f),D=C.slice(0,5),z=[];for(const Y of D)try{const Ee=await R.mutateAsync({filename:Y.name,size:Y.size});z.push(...Ee.duplicates)}catch{}z.length>0?(y(C),P(z)):xe.addFiles(C)}function yt(f){f.target.files&&tt(f.target.files),J.current&&(J.current.value="")}function bt(f){_(String(f.active.id))}function Nt(f){_(null);const{active:C,over:D}=f;if(!D||D.data.current?.type!=="folder")return;const z=D.id==="unfiled"||D.id==="all-media"?"":String(D.id),Y=j.has(String(C.id))?[...j]:[String(C.id)];v.mutateAsync({mediaIds:Y,action:"move",folderId:z}).then(Ee=>{const at=Ee.failed.length;at?M.error(`${at} of ${Y.length} failed to move`):M.success(`${Y.length} item(s) moved`)})}function Ct(){_(null)}const Q=A?$?.items.find(f=>f.mediaId===A):null,st=A&&j.has(A)?j.size:1;return e.jsxs(ds,{sensors:q,modifiers:[ma],onDragStart:bt,onDragEnd:Nt,onDragCancel:Ct,children:[e.jsxs("div",{className:"-m-2 md:-m-6 relative flex min-h-[calc(100dvh-3.5rem)] md:h-[calc(100vh-3.5rem)]",children:[e.jsx("div",{className:"hidden md:block",children:e.jsx(ot,{host:a,selectedFolderId:m,onSelect:f=>{d(f),w(new Set)}})}),e.jsx(Bt,{open:X,onOpenChange:ue,children:e.jsxs(Kt,{side:"left",className:"w-64 p-0 pt-[env(safe-area-inset-top,0px)] pl-[env(safe-area-inset-left,0px)] [&_[data-slot=sheet-close]]:top-[calc(1rem+env(safe-area-inset-top,0px))]","data-testid":"folder-overlay-backdrop",children:[e.jsx(Vt,{className:"sr-only",children:"Folders"}),e.jsx(ot,{host:a,selectedFolderId:m,onSelect:f=>{d(f),w(new Set),ue(!1)}})]})}),e.jsxs(na,{onFiles:f=>tt(f),children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-2 md:p-6",children:[e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Media"}),e.jsxs("div",{children:[e.jsx("input",{ref:J,type:"file",multiple:!0,className:"hidden",onChange:yt}),e.jsxs(k,{onClick:()=>J.current?.click(),children:[e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Upload"]})]})]}),j.size>0?e.jsx(aa,{selectedCount:j.size,folders:ye,onDelete:ft,onMove:wt,onAddTags:jt,onRemoveTags:vt,onClear:()=>w(new Set),isPending:v.isPending}):e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative min-w-[200px] max-w-sm flex-1",children:[e.jsx(rt,{className:"text-muted-foreground absolute left-2.5 top-2.5 h-4 w-4"}),e.jsx(V,{placeholder:"Search media...",value:c,onChange:f=>h(f.target.value),className:"pl-9"})]}),e.jsxs(ge,{value:n,onValueChange:r,children:[e.jsx(fe,{className:"w-[160px]",children:e.jsx(we,{})}),e.jsx(je,{children:ua.map(f=>e.jsx(se,{value:f.value,children:f.label},f.value))})]}),e.jsx(k,{variant:X?"secondary":"ghost",size:"sm",className:"md:hidden px-2",onClick:()=>ue(!X),"aria-label":"Toggle folders",children:e.jsx(Ts,{className:"h-4 w-4"})}),!X&&m!==null&&t&&e.jsxs(Qe,{variant:"secondary",className:"gap-1 md:hidden",children:[e.jsx(te,{className:"h-3 w-3"}),m==="unfiled"?"Unfiled":Ie.get(m)??"All Media"]}),e.jsxs("div",{className:"flex rounded-md border",children:[e.jsx(k,{variant:s==="grid"?"secondary":"ghost",size:"sm",className:"rounded-r-none px-2",onClick:()=>l("grid"),children:e.jsx(Rs,{className:"h-4 w-4"})}),e.jsx(k,{variant:s==="list"?"secondary":"ghost",size:"sm",className:"rounded-l-none px-2",onClick:()=>l("list"),children:e.jsx(zs,{className:"h-4 w-4"})})]})]}),e.jsx(sa,{tags:pt,activeTag:b,onTagChange:f=>{p(f),w(new Set)}}),s==="grid"&&($?.items.length??0)>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Te,{checked:ze,onCheckedChange:et,"aria-label":"Select all"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:j.size>0?`${j.size} of ${$.items.length} selected`:"Select all"})]}),xt?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4",children:Array.from({length:8}).map((f,C)=>e.jsx(Wt,{className:"aspect-square"},C))}):$?.items.length?s==="list"?e.jsx(Xs,{items:$.items,host:a,onSelect:g,selectedIds:j,onToggle:Je,onToggleAll:et,allSelected:ze,folderMap:m===null?Ie:void 0,onLightbox:f=>{const C=Re.get(f.mediaId);C!==void 0&&E(C)}}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4",children:$.items.map(f=>e.jsx(xa,{item:f,selected:j.has(f.mediaId),onToggle:()=>Je(f.mediaId),onClick:()=>g(f),folderName:m===null?Ie.get(f.folderId??""):void 0,onLightbox:Re.has(f.mediaId)?()=>E(Re.get(f.mediaId)):void 0},f.mediaId))}):e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:o||b?e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No results found"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Try adjusting your search or filters."})]}):m==="unfiled"?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No unfiled media"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"All media items are organized in folders."})]}):m?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"This folder is empty"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload files or drag media into this folder."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"text-muted-foreground mb-3 h-10 w-10"}),e.jsx("p",{className:"text-muted-foreground text-lg font-medium",children:"No media yet"}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Upload your first file to get started."}),e.jsxs(k,{className:"mt-4",onClick:()=>J.current?.click(),children:[e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Upload"]})]})}),x&&e.jsx(ta,{host:a,media:x,onClose:()=>g(null),onDeleted:f=>{w(C=>{if(!C.has(f))return C;const D=new Set(C);return D.delete(f),D})},folders:ye,tagSuggestions:gt})]}),e.jsx(ra,{queue:xe})]})]}),I!==null&&be.length>0&&e.jsx(ca,{items:be,currentIndex:I,host:a,onClose:()=>E(null),onNavigate:E}),e.jsx(da,{open:N.length>0,host:a,duplicates:N,fileCount:F?Array.from(F).length:0,onContinue:()=>{F&&xe.addFiles(F),y(null),P([])},onCancel:()=>{y(null),P([])}}),e.jsx(hs,{children:A&&Q&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border bg-background p-2 shadow-lg",children:[Q.mimeType.startsWith("image/")&&Q.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(Q.urls?.thumb_sm??Q.url),alt:Q.filename,className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center",children:e.jsx(_e,{mimeType:Q.mimeType,className:"h-6 w-6"})}),e.jsx("span",{className:"text-sm font-medium",children:st>1?`Moving ${st} items`:Q.filename})]})})]})}export{Aa as MediaPage};
@@ -1 +0,0 @@
1
- import{j as e,a as Q}from"./tanstack-oFmRhGwV.js";import{u as R,e as G,r as h}from"./react-vendor-B0Dih9Pj.js";import{a8 as K,S as b,ac as Z,ad as z,ae as J,a7 as M,L as m,I as c,B as i,a as u,af as V,D as A,j as P,k,l as T,m as F,n as E,t as n}from"./index-DX9xeoQx.js";import{B as W}from"./badge-B8OxObuF.js";import{C as g,a as p,b as f,c as S}from"./card-C7fgQS_U.js";import{f as X}from"./format-C88SDH8g.js";import"./radix-lA_IxTIV.js";function re(){const{host:a}=R(),{data:r,isLoading:t}=K(a);return t?e.jsxs("div",{className:"space-y-4",children:[e.jsx(b,{className:"h-8 w-64"}),e.jsx(b,{className:"h-48 w-full"})]}):r?e.jsx(Y,{site:r},r.host):e.jsx("p",{className:"text-muted-foreground",children:"Site not found."})}function Y({site:a}){const r=Q(),t=Z(a.host),x=z(a.host),j=J(a.host),y=G(),C=M()==="admin",v=a.status==="archived",[N,O]=h.useState(a.name),[B,l]=h.useState(!1),[L,d]=h.useState(!1),[D,o]=h.useState("");async function U(s){s.preventDefault();try{await t.mutateAsync({name:N}),n.success("Site updated")}catch(w){n.error("Failed to update site",{description:w instanceof Error?w.message:void 0})}}async function q(){try{await t.mutateAsync({status:"archived"}),n.success("Site archived"),l(!1),y("/sites")}catch(s){n.error("Failed to archive site",{description:s instanceof Error?s.message:void 0})}}async function H(){try{await t.mutateAsync({status:"active"}),n.success("Site unarchived")}catch(s){n.error("Failed to unarchive site",{description:s instanceof Error?s.message:void 0})}}async function I(){try{await x.mutateAsync(),await j.mutateAsync(),await r.invalidateQueries({queryKey:["sites"]}),n.success("Site deleted"),d(!1),o(""),y("/sites")}catch(s){n.error("Failed to delete site",{description:s instanceof Error?s.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:"Site Settings"}),e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{children:"General"})}),e.jsx(S,{children:e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"name",children:"Site Name"}),e.jsx(c,{id:"name",value:N,onChange:s=>O(s.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Host"}),e.jsx(c,{value:a.host,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Status"}),e.jsx("div",{className:"flex items-center gap-2",children:v?e.jsx(W,{variant:"outline",children:"Archived"}):e.jsx(c,{value:a.status,disabled:!0})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Created"}),e.jsx(c,{value:X(a.createdAt),disabled:!0})]}),e.jsxs(i,{type:"submit",disabled:t.isPending,children:[t.isPending&&e.jsx(u,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})]})})]}),C&&e.jsxs(g,{className:"mt-6",children:[e.jsx(p,{children:e.jsx(f,{children:"Site Status"})}),e.jsx(S,{className:"space-y-4",children:v?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"This site is archived. Unarchive it to allow content changes."}),e.jsxs(i,{variant:"outline",onClick:H,disabled:t.isPending,children:[t.isPending&&e.jsx(u,{className:"mr-2 h-4 w-4 animate-spin"}),"Unarchive Site"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Archiving a site makes it read-only. Content cannot be created or modified while archived."}),e.jsxs(i,{variant:"outline",onClick:()=>l(!0),children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Archive Site"]}),e.jsx(A,{open:B,onOpenChange:l,children:e.jsxs(P,{children:[e.jsxs(k,{children:[e.jsx(T,{children:"Archive Site"}),e.jsxs(F,{children:["Are you sure you want to archive ",e.jsx("strong",{children:a.host}),"? The site will become read-only."]})]}),e.jsxs(E,{children:[e.jsx(i,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsxs(i,{onClick:q,disabled:t.isPending,children:[t.isPending&&e.jsx(u,{className:"mr-2 h-4 w-4 animate-spin"}),"Archive"]})]})]})})]})})]}),C&&v&&e.jsxs(g,{className:"border-destructive mt-6",children:[e.jsx(p,{children:e.jsx(f,{className:"text-destructive",children:"Danger Zone"})}),e.jsxs(S,{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Permanently delete this site and all its content, media, collections, and block types. This action cannot be undone."}),e.jsx(i,{variant:"destructive",onClick:()=>d(!0),children:"Delete Site"}),e.jsx(A,{open:L,onOpenChange:s=>{d(s),s||o("")},children:e.jsxs(P,{children:[e.jsxs(k,{children:[e.jsx(T,{children:"Delete Site"}),e.jsxs(F,{children:["This will permanently delete this site and all its content. Type ",e.jsx("strong",{children:a.host})," to confirm."]})]}),e.jsx(c,{placeholder:a.host,value:D,onChange:s=>o(s.target.value)}),e.jsxs(E,{children:[e.jsx(i,{variant:"outline",onClick:()=>{d(!1),o("")},children:"Cancel"}),e.jsxs(i,{variant:"destructive",onClick:I,disabled:D!==a.host||x.isPending||j.isPending,children:[(x.isPending||j.isPending)&&e.jsx(u,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete Everything"]})]})]})})]})]})]})}export{re as SiteSettingsPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./tanstack-oFmRhGwV.js";import{r as u,e as V}from"./react-vendor-B0Dih9Pj.js";import{b as X,u as Z,d as ee,e as te,g as se,h as ae,H as U,D as G,i as J,B as k,U as ne,j as oe,k as ie,l as le,m as re,L as R,I as W,n as ce}from"./index-DX9xeoQx.js";import{C as de,a as me,b as he,d as ue}from"./card-C7fgQS_U.js";import{B as ge}from"./badge-B8OxObuF.js";import{C as b}from"./checkbox-BV2kjQBe.js";import{P as Y}from"./plus-HdRn2U0S.js";import"./radix-lA_IxTIV.js";import"./check-CxKAR64t.js";const pe={name:"pages",label:"Pages",labelSingular:"Page",slug:"pages",singleton:!1,fields:[{name:"content",label:"Content",type:"blocks",options:{}}]},xe={name:"posts",label:"Blog Posts",labelSingular:"Blog Post",slug:"/blog",singleton:!1,fields:[{name:"author",label:"Author",type:"text",options:{}},{name:"content",label:"Content",type:"blocks",options:{}}]},fe={name:"site-settings",label:"Site Settings",labelSingular:"Site Settings",slug:"site-settings",singleton:!0,fields:[{name:"siteName",label:"Site Name",type:"text",options:{}},{name:"tagline",label:"Tagline",type:"text",options:{}},{name:"footerText",label:"Footer Text",type:"text",options:{}},{name:"menuItems",label:"Menu Items",type:"array",options:{itemFields:[{name:"label",label:"Label",type:"text",options:{}},{name:"href",label:"URL",type:"text",options:{}}]}}]};function C(s,o){return{id:o,type:"paragraph",props:{textColor:"default",backgroundColor:"default",textAlignment:"left"},content:[{type:"text",text:s}],children:[]}}function $(s,o,d){return{id:d,type:"heading",props:{textColor:"default",backgroundColor:"default",textAlignment:"left",level:o},content:[{type:"text",text:s}],children:[]}}const z=[{title:"Home",slug:"home",body:{content:[$("Welcome to Headroom",1,"home-h1"),C("This is your new site powered by Headroom CMS. Edit this page to add your own content.","home-p1"),$("Getting Started",2,"home-h2"),C("Head over to the admin panel to manage your content, collections, and media.","home-p2")]}},{title:"About",slug:"about",body:{content:[$("About Us",1,"about-h1"),C("Tell your visitors about your company, team, or project. This is a great place to share your story.","about-p1")]}},{title:"Contact",slug:"contact",body:{content:[$("Contact",1,"contact-h1"),C("Get in touch with us. Replace this with your contact information or a contact form.","contact-p1")]}}],K=[{title:"Welcome to Headroom",slug:"welcome-to-headroom",body:{author:"Admin",content:[C("This is your first blog post. You can edit or delete it and start writing your own content.","post-p1"),C("Headroom makes it easy to create and manage your content with a powerful block editor, media library, and flexible collections.","post-p2")]}}],Se={siteName:"Headroom Site",tagline:"A site powered by Headroom CMS",footerText:"© 2026 Headroom Site. Built with Headroom CMS.",menuItems:[{label:"Home",href:"/"},{label:"About",href:"/about"},{label:"Blog",href:"/blog"},{label:"Contact",href:"/contact"}]};function Q(s){const d=[s.createPages,s.createPosts,s.createSettings].filter(Boolean).length;if(!s.addSampleContent)return d;let g=0;return s.createPages&&(g+=z.length*2),s.createPosts&&(g+=K.length*2),s.createSettings&&(g+=3),d+g}async function be(s,o,d,g){const r={collectionsCreated:[],contentCreated:[],errors:[]},x=Q(d);let a=0;const m=t=>{g?.({completed:a,total:x,label:t})},y=[{key:"pages",enabled:d.createPages,schema:pe},{key:"posts",enabled:d.createPosts,schema:xe},{key:"site-settings",enabled:d.createSettings,schema:fe}],p=new Set;for(const{key:t,enabled:n,schema:f}of y)if(n){m(`Creating ${t} collection...`);try{await s.apiFetch(`/v1/admin/sites/${o}/collections`,{method:"POST",body:JSON.stringify(f)}),r.collectionsCreated.push(t),p.add(t)}catch(h){r.errors.push(`Failed to create ${t} collection: ${h instanceof Error?h.message:String(h)}`)}a++}if(!d.addSampleContent)return m("Done"),r;if(p.has("pages"))for(const t of z){m(`Creating page "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"pages",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing page "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`pages/${t.slug}`)}catch(n){r.errors.push(`Failed to create page "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("posts"))for(const t of K){m(`Creating post "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"posts",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing post "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`posts/${t.slug}`)}catch(n){r.errors.push(`Failed to create post "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("site-settings")){m("Configuring settings...");try{const t=await s.apiFetch(`/v1/admin/sites/${o}/collections/site-settings`);a++,t.singletonContentId?(m("Saving settings draft..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/draft`,{method:"PUT",body:JSON.stringify({title:"Site Settings",slug:"site-settings",body:Se})}),a++,m("Publishing settings..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/publish`,{method:"POST"}),a++,r.contentCreated.push("site-settings")):a+=2}catch(t){r.errors.push(`Failed to populate settings: ${t instanceof Error?t.message:String(t)}`),a+=3}}return m("Done"),r}function $e(){const[s,o]=u.useState(!1),{data:d,isLoading:g}=X(s),r=V(),x=u.useMemo(()=>[...d?.items??[]].sort((l,A)=>(l.name||l.host).localeCompare(A.name||A.host)),[d]),{user:a}=Z(),{data:m}=ee(),y=a?(m?.superAdminIds??[]).includes(a.sub):!1,p=te(),t=se(),[n,f]=u.useState(!1),[h,j]=u.useState(""),[S,c]=u.useState(""),[N,i]=u.useState(!0),[v,D]=u.useState(!0),[w,O]=u.useState(!0),[P,E]=u.useState(!0),[F,L]=u.useState(!1),[H,T]=u.useState(null),I=()=>{j(""),c(""),i(!0),D(!0),O(!0),E(!0),L(!1),T(null)},B=l=>{f(l),l||I()};if(g)return e.jsx(ae,{});const _=async()=>{if(h.trim())try{await t.mutateAsync({host:h.trim(),name:S.trim()||h.trim()});const l={createPages:v,createPosts:w,createSettings:P,addSampleContent:F};if(N&&(v||w||P)){const A=Q(l);T({completed:0,total:A,label:"Setting up collections..."});const M=await be(p,h.trim(),l,T);M.errors.length>0&&console.warn("Scaffold warnings:",M.errors)}f(!1),I()}catch{T(null)}};return x.length===0?e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"No sites available."}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4"}),"Create Site"]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]}):e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex-1 p-4 sm:p-8",children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Select a site"}),y&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:s,onCheckedChange:l=>o(l===!0)}),"Show archived sites"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{variant:"outline",onClick:()=>r("/users"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"All Users"})]}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Create Site"})]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]})]}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:x.map(l=>e.jsx(de,{className:"cursor-pointer transition-shadow hover:shadow-md",onClick:()=>r(`/sites/${l.host}/content`),children:e.jsxs(me,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{children:l.name||l.host}),l.status==="archived"&&e.jsx(ge,{variant:"outline",children:"Archived"})]}),e.jsx(ue,{children:l.host})]})},l.host))})]})]})}function q({newHost:s,setNewHost:o,newName:d,setNewName:g,createDefaults:r,setCreateDefaults:x,createPages:a,setCreatePages:m,createPosts:y,setCreatePosts:p,createSettings:t,setCreateSettings:n,addSampleContent:f,setAddSampleContent:h,onSubmit:j,isPending:S,scaffoldProgress:c}){const N=S||!!c;return e.jsxs(oe,{children:[e.jsxs(ie,{children:[e.jsx(le,{children:"Create Site"}),e.jsx(re,{className:"sr-only",children:"Enter details for the new site"})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"host",children:"Host"}),e.jsx(W,{id:"host",placeholder:"example.com",value:s,onChange:i=>o(i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{htmlFor:"name",children:"Display Name"}),e.jsx(W,{id:"name",placeholder:"My Site",value:d,onChange:i=>g(i.target.value)})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(b,{checked:r,onCheckedChange:i=>x(i===!0)}),"Create Default Collections"]}),r&&e.jsxs("div",{className:"ml-6 mt-3 space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:a,onCheckedChange:i=>m(i===!0)}),"Pages"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:y,onCheckedChange:i=>p(i===!0)}),"Posts"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:t,onCheckedChange:i=>n(i===!0)}),"Site Settings"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(b,{checked:f,onCheckedChange:i=>h(i===!0)}),"Add Sample Content"]})]})]})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300",style:{width:`${c.total>0?c.completed/c.total*100:0}%`},role:"progressbar","aria-valuenow":c.completed,"aria-valuemin":0,"aria-valuemax":c.total})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.label," ","(",c.completed,"/",c.total,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please wait while your site is being set up. Do not close this tab."})]}),e.jsx(ce,{children:e.jsx(k,{onClick:j,disabled:!s.trim()||N,children:c?c.label:S?"Creating...":"Create"})})]})}export{$e as SitesPage};