headroom-cms 0.1.10 → 0.1.11

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 (104) hide show
  1. package/README.md +11 -6
  2. package/admin/assets/{AdminsPage-BIWASote.js → AdminsPage-BnzH9TL3.js} +1 -1
  3. package/admin/assets/{AllContentPage-1gXe2OC7.js → AllContentPage-BtObN6oy.js} +1 -1
  4. package/admin/assets/{ApiKeysPage-BBW4ATBx.js → ApiKeysPage-DEAa8eyC.js} +1 -1
  5. package/admin/assets/{AuditPage-B5GGFWGG.js → AuditPage-BN9yNsxh.js} +1 -1
  6. package/admin/assets/{BlockEditor-ClskiZoX.js → BlockEditor-3wnisTOZ.js} +3 -3
  7. package/admin/assets/{BlockTypeEditPage-CY0gCPei.js → BlockTypeEditPage-C2evAESK.js} +1 -1
  8. package/admin/assets/{BlockTypesPage-D8Me6OeX.js → BlockTypesPage-Dhkho6T_.js} +1 -1
  9. package/admin/assets/{BulkActionBar--35xjnOP.js → BulkActionBar-BxdfUSrN.js} +1 -1
  10. package/admin/assets/CollectionEditPage-lOb4hEZy.js +1 -0
  11. package/admin/assets/{CollectionsPage-BQmGXpvW.js → CollectionsPage-CgtOloa1.js} +1 -1
  12. package/admin/assets/{ContentCreatePage-DlgxamOe.js → ContentCreatePage-LeQjahp_.js} +1 -1
  13. package/admin/assets/ContentEditPage-xczr4d_h.js +1 -0
  14. package/admin/assets/{ContentField-D04Uo1Ov.js → ContentField-pilCbdnA.js} +1 -1
  15. package/admin/assets/{ContentListPage-BDMx7pWb.js → ContentListPage-BAKDn1Xy.js} +1 -1
  16. package/admin/assets/{CustomBlockPreview-Cs9bFDh4.js → CustomBlockPreview-DNnTFM0z.js} +1 -1
  17. package/admin/assets/FieldRenderer-DiOKvkWV.js +2 -0
  18. package/admin/assets/{FilterBar-kFcOLffg.js → FilterBar-BZoa63zh.js} +1 -1
  19. package/admin/assets/{FloatingComposerController-D4uLQfUX-C0Lhbmda.js → FloatingComposerController-D4uLQfUX-BMIvFCoE.js} +1 -1
  20. package/admin/assets/{IconPicker-BrgSAsa_.js → IconPicker-CpIgiQTC.js} +2 -2
  21. package/admin/assets/{LoginPage-Bi7TBzK4.js → LoginPage-D9ZsGLIi.js} +1 -1
  22. package/admin/assets/{MediaField-B-Cz8TlK.js → MediaField-CxccCFGQ.js} +1 -1
  23. package/admin/assets/{MediaPage-C84p9d1U.js → MediaPage-QvMaH2YJ.js} +1 -1
  24. package/admin/assets/{Pagination-CuHwUPHi.js → Pagination-Df9nQ7Z0.js} +1 -1
  25. package/admin/assets/{RelationshipPicker-Dv7GaLcU.js → RelationshipPicker-B3Ftmqxp.js} +1 -1
  26. package/admin/assets/{SiteSettingsPage-nBT7NzkA.js → SiteSettingsPage-6NvH7CiQ.js} +1 -1
  27. package/admin/assets/{SiteUserEditPage-DroUTii9.js → SiteUserEditPage-D5VaQ1Xq.js} +1 -1
  28. package/admin/assets/{SiteUsersPage-iVXPCBPe.js → SiteUsersPage-BYVduiqs.js} +1 -1
  29. package/admin/assets/{SitesPage-BefZeWuJ.js → SitesPage-rfWWE0yK.js} +1 -1
  30. package/admin/assets/{SubmissionDetailPage-ktmzzOE1.js → SubmissionDetailPage-BSUR685F.js} +1 -1
  31. package/admin/assets/{SubmissionEditPage-C-ykTI2t.js → SubmissionEditPage-DjLXHjWU.js} +1 -1
  32. package/admin/assets/{SubmissionListPage-DA-8deUy.js → SubmissionListPage-DBxNEvde.js} +1 -1
  33. package/admin/assets/{TagInput-d-Hw1fkL.js → TagInput-57c4DG1w.js} +1 -1
  34. package/admin/assets/{TagsPage-BZzDvcKa.js → TagsPage-BEO5AwCv.js} +1 -1
  35. package/admin/assets/{UsersPage-CnQAOOGF.js → UsersPage-BpIRorJ1.js} +1 -1
  36. package/admin/assets/{WebhookEditPage-KeS8hmdW.js → WebhookEditPage-D5xgi56h.js} +1 -1
  37. package/admin/assets/{WebhooksPage-CASjmlPN.js → WebhooksPage-BY7AaiGr.js} +1 -1
  38. package/admin/assets/{card-CZTHR2Qa.js → card-C9hfyHXf.js} +1 -1
  39. package/admin/assets/{checkbox-DEgzM8H9.js → checkbox-DVJcwUt1.js} +1 -1
  40. package/admin/assets/{command-CdzYw11U.js → command-Bfmj0MEL.js} +1 -1
  41. package/admin/assets/index-BB9Syqw2.css +1 -0
  42. package/admin/assets/{index-BA3y7HJs.js → index-Ce5pmRMj.js} +2 -2
  43. package/admin/assets/media-url-DdCoIedP.js +1 -0
  44. package/admin/assets/{popover-BFw_h3j6.js → popover-CzaQYEEP.js} +1 -1
  45. package/admin/assets/{select-dX9e6VDt.js → select-CrRhFGIi.js} +1 -1
  46. package/admin/assets/serializeToText-2VrsuRUh.js +2 -0
  47. package/admin/assets/{table-Dk7eeOt2.js → table-_3bMY0_z.js} +1 -1
  48. package/admin/assets/{textarea-CpDSUg2s.js → textarea-6fq0R6VV.js} +1 -1
  49. package/admin/assets/{useAdminResolver-Bljb4XGQ.js → useAdminResolver-BJNPz3OG.js} +1 -1
  50. package/admin/assets/{useContent-CW0tm0FY.js → useContent-Bs7nel7C.js} +1 -1
  51. package/admin/assets/{useContentSearch-_bwacEth.js → useContentSearch-B3aTjuCu.js} +1 -1
  52. package/admin/assets/{useMedia-Cu5N4rY8.js → useMedia-ae3s_ajC.js} +1 -1
  53. package/admin/assets/{usePageTitle-DYvuJQp6.js → usePageTitle-C1r1-C00.js} +1 -1
  54. package/admin/assets/{useSiteUsers-CKtC_8Jc.js → useSiteUsers-DIaqgNSp.js} +1 -1
  55. package/admin/assets/{useTags-ybsMbCst.js → useTags-B-HgMVwo.js} +1 -1
  56. package/admin/assets/{useWebhooks-BAB-3sLa.js → useWebhooks-BvZjUJkJ.js} +1 -1
  57. package/admin/favicon-16x16.png +0 -0
  58. package/admin/favicon-32x32.png +0 -0
  59. package/admin/icons/icon-180x180.png +0 -0
  60. package/admin/icons/icon-192x192.png +0 -0
  61. package/admin/icons/icon-512x512.png +0 -0
  62. package/admin/icons/maskable-icon-512x512.png +0 -0
  63. package/admin/index.html +2 -2
  64. package/admin/sw.js +1 -1
  65. package/dist/admin-site.d.ts +4 -2
  66. package/dist/admin-site.d.ts.map +1 -1
  67. package/dist/admin-site.js +3 -3
  68. package/dist/admin-site.js.map +1 -1
  69. package/dist/cdn-api.d.ts +25 -0
  70. package/dist/cdn-api.d.ts.map +1 -0
  71. package/dist/{cdn.js → cdn-api.js} +7 -139
  72. package/dist/cdn-api.js.map +1 -0
  73. package/dist/cdn-media.d.ts +26 -0
  74. package/dist/cdn-media.d.ts.map +1 -0
  75. package/dist/cdn-media.js +202 -0
  76. package/dist/cdn-media.js.map +1 -0
  77. package/dist/index.d.ts +15 -3
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +19 -9
  80. package/dist/index.js.map +1 -1
  81. package/lambda/api/bootstrap +0 -0
  82. package/lambda/image-lambda/node_modules/.package-lock.json +3 -3
  83. package/lambda/image-lambda/node_modules/semver/README.md +19 -4
  84. package/lambda/image-lambda/node_modules/semver/bin/semver.js +14 -10
  85. package/lambda/image-lambda/node_modules/semver/functions/truncate.js +48 -0
  86. package/lambda/image-lambda/node_modules/semver/index.js +2 -0
  87. package/lambda/image-lambda/node_modules/semver/internal/re.js +1 -1
  88. package/lambda/image-lambda/node_modules/semver/package.json +3 -3
  89. package/lambda/image-lambda/node_modules/semver/range.bnf +5 -4
  90. package/lambda/webhook-worker/bootstrap +0 -0
  91. package/package.json +1 -1
  92. package/src/admin-site.ts +7 -5
  93. package/src/{cdn.ts → cdn-api.ts} +8 -161
  94. package/src/cdn-media.ts +250 -0
  95. package/src/index.ts +34 -11
  96. package/admin/assets/CollectionEditPage-y8t0ZO89.js +0 -1
  97. package/admin/assets/ContentEditPage-WkSbCnnG.js +0 -1
  98. package/admin/assets/FieldRenderer-wE-mtqZB.js +0 -2
  99. package/admin/assets/index-c7UygSvP.css +0 -1
  100. package/admin/assets/media-url-DIg_vSyf.js +0 -1
  101. package/admin/assets/serializeToText-Zin3gYPm.js +0 -2
  102. package/dist/cdn.d.ts +0 -27
  103. package/dist/cdn.d.ts.map +0 -1
  104. package/dist/cdn.js.map +0 -1
@@ -1,3 +1,3 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as j}from"./react-vendor-C2CvUxFh.js";import{C as z,b as A,c as R,P as U,D as q,e as V}from"./core.esm-DdQHdRkd.js";import{u as $,S as G,v as H,a as _}from"./sortable.esm-qVEMoaTg.js";import{I as x,y as F,aJ as J,L as o,ai as K,a0 as W,B as S,T as Y,P as Z,aL as T,aE as L}from"./index-BA3y7HJs.js";import{S as P,a as B,b as M,c as O,d as D}from"./select-dX9e6VDt.js";import{d as E,i as Q}from"./format-C88SDH8g.js";import{C as X,a as ee,b as ae}from"./collapsible-D3d29uJp.js";import{C as y}from"./checkbox-DEgzM8H9.js";import{T as se}from"./textarea-CpDSUg2s.js";import{P as te,a as le,b as ne}from"./popover-BFw_h3j6.js";function re({value:t,onChange:s,onBlur:u,readOnly:m,className:l,...a}){const[n,r]=j.useState(!1),p=j.useRef(void 0);j.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const v=j.useCallback(g=>{const N=g.target.value,f=E(N,"leading");s(f),N!==f&&N.length>0?(r(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>r(!1),2e3)):r(!1)},[s]),C=j.useCallback(()=>{const g=E(t,"all");g!==t&&s(g),u?.()},[t,s,u]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{value:t,onChange:v,onBlur:C,disabled:m,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:F("font-mono",l),...a}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function ce({type:t,options:s,onChange:u}){const m=J();function l(a,n){u({...s,[a]:n})}return e.jsxs("div",{className:"space-y-3",children:[!["boolean","blocks","array","container"].includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-required",checked:!!s.required,onCheckedChange:a=>l("required",!!a)}),e.jsx(o,{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(o,{className:"text-xs",children:"Placeholder"}),e.jsx(x,{value:s.placeholder??"",onChange:a=>l("placeholder",a.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Length"}),e.jsx(x,{type:"number",value:s.maxLength??"",onChange:a=>l("maxLength",a.target.value?Number(a.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(o,{className:"text-xs",children:"Min"}),e.jsx(x,{type:"number",value:s.min??"",onChange:a=>l("min",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max"}),e.jsx(x,{type:"number",value:s.max??"",onChange:a=>l("max",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Step"}),e.jsx(x,{type:"number",value:s.step??"",onChange:a=>l("step",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="select"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(se,{value:(s.choices??[]).join(`
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as j}from"./react-vendor-C2CvUxFh.js";import{C as z,b as A,c as R,P as U,D as q,e as V}from"./core.esm-DdQHdRkd.js";import{u as $,S as G,v as H,a as _}from"./sortable.esm-qVEMoaTg.js";import{I as x,y as F,aJ as J,L as o,ai as K,a0 as W,B as S,T as Y,P as Z,aL as T,aE as L}from"./index-Ce5pmRMj.js";import{S as P,a as B,b as M,c as D,d as O}from"./select-CrRhFGIi.js";import{d as E,i as Q}from"./format-C88SDH8g.js";import{C as X,a as ee,b as ae}from"./collapsible-D3d29uJp.js";import{C as y}from"./checkbox-DVJcwUt1.js";import{T as se}from"./textarea-6fq0R6VV.js";import{P as te,a as le,b as ne}from"./popover-CzaQYEEP.js";function re({value:t,onChange:s,onBlur:u,readOnly:m,className:l,...a}){const[n,r]=j.useState(!1),p=j.useRef(void 0);j.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const v=j.useCallback(g=>{const N=g.target.value,f=E(N,"leading");s(f),N!==f&&N.length>0?(r(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(()=>r(!1),2e3)):r(!1)},[s]),C=j.useCallback(()=>{const g=E(t,"all");g!==t&&s(g),u?.()},[t,s,u]);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(x,{value:t,onChange:v,onBlur:C,disabled:m,"aria-invalid":n||void 0,autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:F("font-mono",l),...a}),n&&e.jsx("p",{className:"text-xs text-destructive",children:"Must start with a letter. Only lowercase letters, numbers, hyphens, and underscores."})]})}function ce({type:t,options:s,onChange:u}){const m=J();function l(a,n){u({...s,[a]:n})}return e.jsxs("div",{className:"space-y-3",children:[!["boolean","blocks","array","container"].includes(t)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-required",checked:!!s.required,onCheckedChange:a=>l("required",!!a)}),e.jsx(o,{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(o,{className:"text-xs",children:"Placeholder"}),e.jsx(x,{value:s.placeholder??"",onChange:a=>l("placeholder",a.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Length"}),e.jsx(x,{type:"number",value:s.maxLength??"",onChange:a=>l("maxLength",a.target.value?Number(a.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(o,{className:"text-xs",children:"Min"}),e.jsx(x,{type:"number",value:s.min??"",onChange:a=>l("min",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max"}),e.jsx(x,{type:"number",value:s.max??"",onChange:a=>l("max",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Step"}),e.jsx(x,{type:"number",value:s.step??"",onChange:a=>l("step",a.target.value?Number(a.target.value):void 0),className:"h-8 text-sm"})]})]}),t==="select"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Choices (one per line)"}),e.jsx(se,{value:(s.choices??[]).join(`
2
2
  `),onChange:a=>l("choices",a.target.value.split(`
3
- `).map(n=>n.trim()).filter(Boolean)),rows:4,className:"text-sm"})]}),t==="media"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Types (e.g., image/*, video/*)"}),e.jsx(x,{value:(s.allowedTypes??[]).join(", "),onChange:a=>l("allowedTypes",a.target.value.split(",").map(n=>n.trim()).filter(Boolean)),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Folder"}),e.jsx(x,{value:s.folder??"",onChange:a=>l("folder",a.target.value||void 0),placeholder:"e.g., submissions/photos",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Accept (MIME filter)"}),e.jsx(x,{value:s.accept??"",onChange:a=>l("accept",a.target.value||void 0),placeholder:"e.g., image/*",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Size (bytes)"}),e.jsx(x,{type:"number",value:s.maxSize??"",onChange:a=>l("maxSize",a.target.value?Number(a.target.value):void 0),placeholder:"5242880 (5MB)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-media-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-media-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="content"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Collections"}),m&&m.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:m.collections.map(a=>{const n=s.collections??[],r=n.includes(a.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(y,{id:`col-${a.name}`,checked:r,onCheckedChange:p=>{p?l("collections",[...n,a.name]):l("collections",n.filter(v=>v!==a.name))}}),e.jsx(o,{htmlFor:`col-${a.name}`,className:"text-xs font-normal",children:a.label||a.name})]},a.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(x,{value:(s.collections??[]).join(", "),onChange:a=>l("collections",a.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(y,{id:"opt-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="container"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Fields"}),e.jsx(I,{fields:s.fields??[],onChange:a=>l("fields",a),excludeTypes:["container","blocks"]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Item Fields"}),e.jsx(I,{fields:s.itemFields??[],onChange:a=>l("itemFields",a),excludeTypes:["array","container"]})]})]})}const w=[{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"},{value:"container",label:"Container"}];function ie({id:t,field:s,onChange:u,onRemove:m,excludeTypes:l,readOnlyName:a,defaultExpanded:n}){const[r,p]=j.useState(n??!1),[v,C]=j.useState(!!s.label),{attributes:g,listeners:N,setNodeRef:f,transform:k,transition:c}=$({id:t}),d=l?w.filter(i=>!l.includes(i.value)):w,h={transform:z.Transform.toString(k),transition:c};function b(i){u({...s,...i})}return e.jsx("div",{ref:f,style:h,className:"rounded-md border bg-card",children:e.jsxs(X,{open:r,onOpenChange:p,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",...g,...N,children:e.jsx(K,{className:"h-4 w-4"})}),e.jsx(ee,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(W,{className:F("h-4 w-4 transition-transform",r&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:m,className:"text-destructive",children:e.jsx(Y,{className:"h-3 w-3"})})]}),e.jsx(ae,{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(re,{value:s.name,onChange:i=>b({name:i}),onBlur:()=>{s.name&&!v&&b({label:Q(s.name)})},readOnly:a,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(x,{value:s.label,onChange:i=>{b({label:i.target.value}),C(!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(P,{value:s.type,onValueChange:i=>b({type:i,options:{}}),children:[e.jsx(B,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsx(O,{children:d.map(i=>e.jsx(D,{value:i.value,children:i.label},i.value))})]})]})]}),e.jsx(ce,{type:s.type,options:s.options??{},onChange:i=>b({options:i})})]})})]})})}function I({fields:t,onChange:s,excludeTypes:u,existingFieldNames:m}){const l=A(R(U)),a=t.map((c,d)=>`field-${d}`),[n,r]=j.useState("text"),[p,v]=j.useState(null),C=u?w.filter(c=>!u.includes(c.value)):w;function g(){v(t.length),s([...t,{name:"",label:"",type:n,options:{}}])}function N(c,d){const h=[...t];h[c]=d,s(h)}function f(c){s(t.filter((d,h)=>h!==c))}function k(c){const{active:d,over:h}=c;if(h&&d.id!==h.id){const b=a.indexOf(String(d.id)),i=a.indexOf(String(h.id));s(_(t,b,i))}}return e.jsx(q,{sensors:l,collisionDetection:V,onDragEnd:k,children:e.jsx(G,{items:a,strategy:H,children:e.jsxs("div",{className:"space-y-2",children:[t.map((c,d)=>e.jsx(ie,{id:`field-${d}`,field:c,onChange:h=>N(d,h),onRemove:()=>f(d),excludeTypes:u,readOnlyName:!!(m?.has(c.name)&&c.name),defaultExpanded:d===p},`field-${d}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{value:n,onValueChange:r,children:[e.jsx(B,{className:"h-8 w-[130px] text-sm",children:e.jsx(M,{})}),e.jsx(O,{children:C.map(c=>e.jsx(D,{value:c.value,children:c.label},c.value))})]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(Z,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}const oe=["Newspaper","FileText","BookOpen","PenLine","Edit","Image","Camera","Video","Music","Mic","ShoppingCart","Store","Package","Tag","Gift","Users","User","UserPlus","Contact","Building","Calendar","Clock","Timer","CalendarDays","CalendarCheck","Star","Heart","ThumbsUp","Award","Trophy","Map","MapPin","Globe","Compass","Navigation","MessageSquare","Mail","Send","Phone","Bell","Folder","FolderOpen","Archive","Database","HardDrive","Settings","Wrench","Cog","Sliders","SlidersHorizontal","BarChart","PieChart","TrendingUp","Activity","LineChart","Code","Terminal","Braces","Bug","Puzzle","Home","Layout","Grid","List","Layers","Lightbulb","Zap","Flame","Sun","Moon","Link","ExternalLink","Share","Download","Upload","Lock","Unlock","Shield","Key","Eye"];function fe({value:t,onChange:s}){const[u,m]=j.useState(!1),[l,a]=j.useState(""),n=l?Object.keys(T).filter(r=>r.toLowerCase().includes(l.toLowerCase())).slice(0,120):[...oe];return e.jsxs(te,{open:u,onOpenChange:m,children:[e.jsx(le,{asChild:!0,children:e.jsx(S,{variant:"outline",className:"gap-2 w-full justify-start",children:t?e.jsxs(e.Fragment,{children:[e.jsx(L,{name:t,className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:t})]}):e.jsx("span",{className:"text-muted-foreground",children:"Select icon..."})})}),e.jsxs(ne,{className:"w-72 p-2",align:"start",children:[e.jsx(x,{placeholder:"Search icons...",value:l,onChange:r=>a(r.target.value),className:"mb-2",autoFocus:!0}),e.jsxs("div",{className:"grid grid-cols-6 gap-1 max-h-48 overflow-y-auto",children:[n.map(r=>r in T?e.jsx("button",{type:"button",title:r,className:F("flex items-center justify-center rounded-md p-2 hover:bg-accent transition-colors",t===r&&"bg-accent ring-1 ring-primary"),onClick:()=>{s(r),m(!1),a("")},children:e.jsx(L,{name:r,className:"h-4 w-4"})},r):null),n.length===0&&e.jsx("p",{className:"col-span-6 text-center text-sm text-muted-foreground py-4",children:"No matching icons"})]}),t&&e.jsx("div",{className:"border-t mt-2 pt-2",children:e.jsx(S,{variant:"ghost",size:"sm",className:"w-full",onClick:()=>{s(""),m(!1),a("")},children:"Clear icon"})})]})]})}export{I as F,re as I,fe as a};
3
+ `).map(n=>n.trim()).filter(Boolean)),rows:4,className:"text-sm"})]}),t==="media"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Types (e.g., image/*, video/*)"}),e.jsx(x,{value:(s.allowedTypes??[]).join(", "),onChange:a=>l("allowedTypes",a.target.value.split(",").map(n=>n.trim()).filter(Boolean)),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Folder"}),e.jsx(x,{value:s.folder??"",onChange:a=>l("folder",a.target.value||void 0),placeholder:"e.g., submissions/photos",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Accept (MIME filter)"}),e.jsx(x,{value:s.accept??"",onChange:a=>l("accept",a.target.value||void 0),placeholder:"e.g., image/*",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Max Size (bytes)"}),e.jsx(x,{type:"number",value:s.maxSize??"",onChange:a=>l("maxSize",a.target.value?Number(a.target.value):void 0),placeholder:"5242880 (5MB)",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{id:"opt-media-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-media-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="content"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Allowed Collections"}),m&&m.collections.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:m.collections.map(a=>{const n=s.collections??[],r=n.includes(a.name);return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(y,{id:`col-${a.name}`,checked:r,onCheckedChange:p=>{p?l("collections",[...n,a.name]):l("collections",n.filter(v=>v!==a.name))}}),e.jsx(o,{htmlFor:`col-${a.name}`,className:"text-xs font-normal",children:a.label||a.name})]},a.name)})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave all unchecked to allow any collection"})]}):e.jsx(x,{value:(s.collections??[]).join(", "),onChange:a=>l("collections",a.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(y,{id:"opt-multiple",checked:!!s.multiple,onCheckedChange:a=>l("multiple",!!a)}),e.jsx(o,{htmlFor:"opt-multiple",className:"text-sm",children:"Allow multiple"})]})]}),t==="container"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Fields"}),e.jsx(I,{fields:s.fields??[],onChange:a=>l("fields",a),excludeTypes:["container","blocks"]})]}),t==="array"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(o,{className:"text-xs",children:"Item Fields"}),e.jsx(I,{fields:s.itemFields??[],onChange:a=>l("itemFields",a),excludeTypes:["array","container"]})]})]})}const w=[{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:"datetime",label:"Date & Time"},{value:"media",label:"Media"},{value:"content",label:"Content"},{value:"blocks",label:"Blocks"},{value:"array",label:"Array"},{value:"container",label:"Container"}];function ie({id:t,field:s,onChange:u,onRemove:m,excludeTypes:l,readOnlyName:a,defaultExpanded:n}){const[r,p]=j.useState(n??!1),[v,C]=j.useState(!!s.label),{attributes:g,listeners:N,setNodeRef:f,transform:k,transition:c}=$({id:t}),d=l?w.filter(i=>!l.includes(i.value)):w,h={transform:z.Transform.toString(k),transition:c};function b(i){u({...s,...i})}return e.jsx("div",{ref:f,style:h,className:"rounded-md border bg-card",children:e.jsxs(X,{open:r,onOpenChange:p,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",...g,...N,children:e.jsx(K,{className:"h-4 w-4"})}),e.jsx(ee,{asChild:!0,children:e.jsx("button",{type:"button",className:"flex items-center",children:e.jsx(W,{className:F("h-4 w-4 transition-transform",r&&"rotate-90")})})}),e.jsx("span",{className:"min-w-[80px] text-sm font-mono",children:s.name||"unnamed"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.type}),e.jsx("span",{className:"flex-1 truncate text-sm text-muted-foreground",children:s.label}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:m,className:"text-destructive",children:e.jsx(Y,{className:"h-3 w-3"})})]}),e.jsx(ae,{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(re,{value:s.name,onChange:i=>b({name:i}),onBlur:()=>{s.name&&!v&&b({label:Q(s.name)})},readOnly:a,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(x,{value:s.label,onChange:i=>{b({label:i.target.value}),C(!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(P,{value:s.type,onValueChange:i=>b({type:i,options:{}}),children:[e.jsx(B,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsx(D,{children:d.map(i=>e.jsx(O,{value:i.value,children:i.label},i.value))})]})]})]}),e.jsx(ce,{type:s.type,options:s.options??{},onChange:i=>b({options:i})})]})})]})})}function I({fields:t,onChange:s,excludeTypes:u,existingFieldNames:m}){const l=A(R(U)),a=t.map((c,d)=>`field-${d}`),[n,r]=j.useState("text"),[p,v]=j.useState(null),C=u?w.filter(c=>!u.includes(c.value)):w;function g(){v(t.length),s([...t,{name:"",label:"",type:n,options:{}}])}function N(c,d){const h=[...t];h[c]=d,s(h)}function f(c){s(t.filter((d,h)=>h!==c))}function k(c){const{active:d,over:h}=c;if(h&&d.id!==h.id){const b=a.indexOf(String(d.id)),i=a.indexOf(String(h.id));s(_(t,b,i))}}return e.jsx(q,{sensors:l,collisionDetection:V,onDragEnd:k,children:e.jsx(G,{items:a,strategy:H,children:e.jsxs("div",{className:"space-y-2",children:[t.map((c,d)=>e.jsx(ie,{id:`field-${d}`,field:c,onChange:h=>N(d,h),onRemove:()=>f(d),excludeTypes:u,readOnlyName:!!(m?.has(c.name)&&c.name),defaultExpanded:d===p},`field-${d}`)),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{value:n,onValueChange:r,children:[e.jsx(B,{className:"h-8 w-[130px] text-sm",children:e.jsx(M,{})}),e.jsx(D,{children:C.map(c=>e.jsx(O,{value:c.value,children:c.label},c.value))})]}),e.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:g,children:[e.jsx(Z,{className:"mr-2 h-3 w-3"})," Add Field"]})]})]})})})}const oe=["Newspaper","FileText","BookOpen","PenLine","Edit","Image","Camera","Video","Music","Mic","ShoppingCart","Store","Package","Tag","Gift","Users","User","UserPlus","Contact","Building","Calendar","Clock","Timer","CalendarDays","CalendarCheck","Star","Heart","ThumbsUp","Award","Trophy","Map","MapPin","Globe","Compass","Navigation","MessageSquare","Mail","Send","Phone","Bell","Folder","FolderOpen","Archive","Database","HardDrive","Settings","Wrench","Cog","Sliders","SlidersHorizontal","BarChart","PieChart","TrendingUp","Activity","LineChart","Code","Terminal","Braces","Bug","Puzzle","Home","Layout","Grid","List","Layers","Lightbulb","Zap","Flame","Sun","Moon","Link","ExternalLink","Share","Download","Upload","Lock","Unlock","Shield","Key","Eye"];function fe({value:t,onChange:s}){const[u,m]=j.useState(!1),[l,a]=j.useState(""),n=l?Object.keys(T).filter(r=>r.toLowerCase().includes(l.toLowerCase())).slice(0,120):[...oe];return e.jsxs(te,{open:u,onOpenChange:m,children:[e.jsx(le,{asChild:!0,children:e.jsx(S,{variant:"outline",className:"gap-2 w-full justify-start",children:t?e.jsxs(e.Fragment,{children:[e.jsx(L,{name:t,className:"h-4 w-4"}),e.jsx("span",{className:"truncate",children:t})]}):e.jsx("span",{className:"text-muted-foreground",children:"Select icon..."})})}),e.jsxs(ne,{className:"w-72 p-2",align:"start",children:[e.jsx(x,{placeholder:"Search icons...",value:l,onChange:r=>a(r.target.value),className:"mb-2",autoFocus:!0}),e.jsxs("div",{className:"grid grid-cols-6 gap-1 max-h-48 overflow-y-auto",children:[n.map(r=>r in T?e.jsx("button",{type:"button",title:r,className:F("flex items-center justify-center rounded-md p-2 hover:bg-accent transition-colors",t===r&&"bg-accent ring-1 ring-primary"),onClick:()=>{s(r),m(!1),a("")},children:e.jsx(L,{name:r,className:"h-4 w-4"})},r):null),n.length===0&&e.jsx("p",{className:"col-span-6 text-center text-sm text-muted-foreground py-4",children:"No matching icons"})]}),t&&e.jsx("div",{className:"border-t mt-2 pt-2",children:e.jsx(S,{variant:"ghost",size:"sm",className:"w-full",onClick:()=>{s(""),m(!1),a("")},children:"Clear icon"})})]})]})}export{I as F,re as I,fe as a};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as o,N as Y}from"./react-vendor-C2CvUxFh.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-BA3y7HJs.js";import{C as J,a as X,b as Z,c as $}from"./card-CZTHR2Qa.js";import"./radix-C5ZmWuuL.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as o,N as Y}from"./react-vendor-C2CvUxFh.js";import{u as z,L as c,I as d,B as m,a as x,f as _,c as G}from"./index-Ce5pmRMj.js";import{C as J,a as X,b as Z,c as $}from"./card-C9hfyHXf.js";import"./radix-C5ZmWuuL.js";function oe(){const{status:T,login:D,completeNewPassword:L,respondToMfaChallenge:O}=z(),[g,W]=o.useState(""),[j,I]=o.useState(""),[N,q]=o.useState(""),[v,E]=o.useState(""),[i,a]=o.useState(""),[n,r]=o.useState(!1),[l,y]=o.useState(null),[u,f]=o.useState("login"),[h,C]=o.useState(""),[S,P]=o.useState(""),[w,b]=o.useState(""),[F,R]=o.useState("");if(T==="authenticated")return e.jsx(Y,{to:"/sites",replace:!0});async function M(t){t.preventDefault(),a(""),r(!0);try{const s=await D(g,j);s.challenge==="NEW_PASSWORD_REQUIRED"&&s.cognitoUser?y({type:"NEW_PASSWORD_REQUIRED",user:s.cognitoUser}):s.challenge==="SOFTWARE_TOKEN_MFA"&&s.cognitoUser&&y({type:"SOFTWARE_TOKEN_MFA",user:s.cognitoUser})}catch(s){a(s instanceof Error?s.message:"Login failed")}finally{r(!1)}}async function U(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await L(l.user,N)}catch(s){a(s instanceof Error?s.message:"Password change failed")}finally{r(!1)}}}async function k(t){if(t.preventDefault(),!!l){a(""),r(!0);try{await O(l.user,v)}catch(s){s&&typeof s=="object"&&"name"in s&&s.name==="NotAuthorizedException"?(a("Your session has expired. Please sign in again."),y(null),E("")):a(s instanceof Error?s.message:"Invalid code")}finally{r(!1)}}}async function B(t){t.preventDefault(),a(""),r(!0);try{await _(h),f("forgot-confirm")}catch(s){(s&&typeof s=="object"&&"name"in s?s.name:"")==="LimitExceededException"?a("Too many attempts. Please try again later."):f("forgot-confirm")}finally{r(!1)}}async function K(){a(""),r(!0);try{await _(h)}catch{}finally{r(!1)}}async function Q(t){if(t.preventDefault(),a(""),w.length<12){a("Password must be at least 12 characters.");return}if(w!==F){a("Passwords do not match.");return}r(!0);try{await G(h,S,w),f("forgot-success")}catch(s){const p=s&&typeof s=="object"&&"name"in s?s.name:"";a(p==="CodeMismatchException"?"Invalid verification code.":p==="ExpiredCodeException"?"Verification code has expired. Please request a new one.":p==="InvalidPasswordException"?"New password does not meet requirements (min 12 chars, uppercase, lowercase, number, symbol).":p==="LimitExceededException"?"Too many attempts. Please try again later.":s instanceof Error?s.message:"Password reset failed")}finally{r(!1)}}function A(){f("login"),a(""),P(""),b(""),R("")}function V(){return u==="forgot-email"?e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter your email and we'll send a code to reset your password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"forgot-email",children:"Email"}),e.jsx(d,{id:"forgot-email",type:"email",value:h,onChange:t=>C(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Send Reset Code"]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground w-full text-center text-sm underline",onClick:A,children:"Back to sign in"})]}):u==="forgot-confirm"?e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the code sent to your email and choose a new password."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-code",children:"Verification Code"}),e.jsx(d,{id:"reset-code",type:"text",value:S,onChange:t=>P(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-password",children:"New Password"}),e.jsx(d,{id:"reset-password",type:"password",value:w,onChange:t=>b(t.target.value),required:!0,autoComplete:"new-password"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"reset-confirm-password",children:"Confirm Password"}),e.jsx(d,{id:"reset-confirm-password",type:"password",value:F,onChange:t=>R(t.target.value),required:!0,autoComplete:"new-password"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Reset Password"]}),e.jsxs("p",{className:"text-muted-foreground text-center text-sm",children:["Didn't receive a code?"," ",e.jsx("button",{type:"button",className:"text-foreground underline",onClick:K,disabled:n,children:"Resend code"})]})]}):u==="forgot-success"?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your password has been reset successfully."}),e.jsx(m,{className:"w-full",onClick:A,children:"Sign In"})]}):l?.type==="SOFTWARE_TOKEN_MFA"?e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Enter the 6-digit code from your authenticator app."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mfa-code",children:"Authentication Code"}),e.jsx(d,{id:"mfa-code",type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:v,onChange:t=>E(t.target.value),required:!0,autoFocus:!0,autoComplete:"one-time-code"})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Verify"]})]}):l?.type==="NEW_PASSWORD_REQUIRED"?e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Please set a new password to continue."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"new-password",children:"New Password"}),e.jsx(d,{id:"new-password",type:"password",value:N,onChange:t=>q(t.target.value),required:!0,minLength:12,autoFocus:!0})]}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Set Password"]})]}):e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",children:"Email"}),e.jsx(d,{id:"email",type:"email",value:g,onChange:t=>W(t.target.value),required:!0,autoFocus:!0,autoComplete:"email"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"password",children:"Password"}),e.jsx(d,{id:"password",type:"password",value:j,onChange:t=>I(t.target.value),required:!0,autoComplete:"current-password"})]}),e.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground text-sm underline",onClick:()=>{f("forgot-email"),C(g),a("")},children:"Forgot password?"}),i&&e.jsx("p",{className:"text-destructive text-sm",children:i}),e.jsxs(m,{type:"submit",className:"w-full",disabled:n,children:[n&&e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Sign In"]})]})}function H(){return u==="forgot-email"||u==="forgot-confirm"?"Reset Password":u==="forgot-success"?"Password Reset":l?.type==="SOFTWARE_TOKEN_MFA"?"Two-Factor Authentication":l?.type==="NEW_PASSWORD_REQUIRED"?"Set New Password":"Sign in to Headroom"}return e.jsx("div",{className:"flex h-dvh items-center justify-center",children:e.jsxs(J,{className:"w-full max-w-sm",children:[e.jsx(X,{children:e.jsx(Z,{className:"text-center text-xl",children:H()})}),e.jsx($,{children:V()})]})})}export{oe as LoginPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as F,r as f}from"./react-vendor-C2CvUxFh.js";import{D as R,k as $,l as q,m as B,n as E,I,B as g,a as k,an as O,a1 as L,ah as D,v as V,X as H,L as M}from"./index-BA3y7HJs.js";import{h as X,i as G,d as J,m as K,n as Q}from"./useMedia-Cu5N4rY8.js";import{S as Y,a as Z,b as ee,c as ae,d as _}from"./select-dX9e6VDt.js";import{C as se}from"./card-CZTHR2Qa.js";import{m as P}from"./media-url-DIg_vSyf.js";function te({open:i,onSelect:l,onClose:r,allowedTypes:n}){const{host:c}=F(),[d,m]=f.useState(""),[u,j]=f.useState("__all__"),t=f.useRef(null),N=X(c),o=G(c),{data:v}=J(c),h=v?.items??[],y=u==="__all__"?void 0:u==="__unfiled__"?"":u,{data:w,fetchNextPage:s,hasNextPage:C,isFetchingNextPage:b}=K(c,{folderId:y}),[S,T]=f.useState(!1),U=(w?.pages.flatMap(a=>a.items)??[]).filter(a=>n&&!n.some(x=>x.endsWith("/*")?a.mimeType.startsWith(x.slice(0,-1)):a.mimeType===x)?!1:d?a.filename.toLowerCase().includes(d.toLowerCase())||a.alt?.toLowerCase().includes(d.toLowerCase()):!0);async function A(a){T(!0);try{const{uploadUrl:p,mediaId:x}=await N.mutateAsync({filename:a.name,contentType:a.type,size:a.size});await fetch(p,{method:"PUT",body:a,headers:{"Content-Type":a.type}});const z=await o.mutateAsync({mediaId:x,filename:a.name});l(z),r()}catch(p){V.error("Upload failed",{description:p instanceof Error?p.message:void 0})}finally{T(!1)}}function W(a){return a.startsWith("image/")}return e.jsx(R,{open:i,onOpenChange:()=>r(),children:e.jsxs($,{className:"max-w-3xl",children:[e.jsxs(q,{children:[e.jsx(B,{children:"Select Media"}),e.jsx(E,{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(I,{placeholder:"Search by filename...",value:d,onChange:a=>m(a.target.value),className:"max-w-xs"}),h.length>0&&e.jsxs(Y,{value:u,onValueChange:j,children:[e.jsx(Z,{className:"w-[150px]",children:e.jsx(ee,{})}),e.jsxs(ae,{children:[e.jsx(_,{value:"__all__",children:"All folders"}),h.map(a=>e.jsx(_,{value:a.folderId,children:a.name},a.folderId)),e.jsx(_,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:t,type:"file",className:"hidden",accept:n?.join(",")??void 0,onChange:a=>a.target.files?.[0]&&A(a.target.files[0])}),e.jsxs(g,{variant:"outline",onClick:()=>t.current?.click(),disabled:S,children:[S?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(O,{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:U.map(a=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{l(a),r()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:W(a.mimeType)?e.jsx("img",{src:P(a.urls?.thumb_md??a.url),alt:a.alt??a.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[a.mimeType.startsWith("image/")?e.jsx(L,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(D,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:a.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:a.filename})})]},a.mediaId))}),U.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),C&&e.jsxs(g,{variant:"ghost",className:"mt-2 w-full",onClick:()=>s(),disabled:b,children:[b?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function le(i){if(!i)return null;if(typeof i=="string")return{id:i,url:""};const l=i,r=l.id??l.mediaId??"";return r?{id:r,url:l.url??"",mimeType:l.mimeType,width:l.width,height:l.height,alt:l.alt,caption:l.caption,filename:l.filename}:null}function ie(i){return i?i.startsWith("image/"):!0}function pe({field:i,value:l,onChange:r,disabled:n}){const{host:c}=F(),[d,m]=f.useState(!1),j=i.options?.allowedTypes,t=le(l),N=t?.id??"",{data:o}=Q(c,N),v=t?.mimeType??o?.mimeType,h=ie(v),y=s=>{t&&r({...t,alt:s})},w=s=>{t&&r({...t,caption:s})};return e.jsxs("div",{children:[t?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!n&&m(!0),children:[h&&o?.url?e.jsx("img",{src:P(o.urls?.thumb_sm??o.url),alt:t.alt??o?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}):e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded bg-muted","aria-label":"File",children:e.jsx(D,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.filename??o?.filename??"Loading..."}),!n&&e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:s=>{s.stopPropagation(),r("")},children:e.jsx(H,{className:"h-3 w-3"})})]}),!n&&h&&e.jsxs("div",{className:"grid grid-cols-1 gap-3 pl-1 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-alt`,className:"text-xs font-normal text-muted-foreground",children:"Alt text"}),e.jsx(I,{id:`${t.id}-alt`,type:"text","aria-label":"Alt text",value:t.alt??"",onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-caption`,className:"text-xs font-normal text-muted-foreground",children:"Caption"}),e.jsx(I,{id:`${t.id}-caption`,type:"text","aria-label":"Caption",value:t.caption??"",onChange:s=>w(s.target.value)})]})]})]}):e.jsxs(g,{type:"button",variant:"outline",onClick:()=>m(!0),disabled:n,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!n&&e.jsx(te,{open:d,onClose:()=>m(!1),onSelect:s=>{const C={id:s.mediaId,url:s.url,mimeType:s.mimeType,width:s.width,height:s.height,alt:s.alt??"",caption:s.caption??"",filename:s.filename};r(C),m(!1)},allowedTypes:j})]})}export{te as M,pe as a};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as F,r as f}from"./react-vendor-C2CvUxFh.js";import{D as R,k as $,l as q,m as B,n as E,I,B as g,a as k,an as O,a1 as L,ah as D,v as V,X as H,L as M}from"./index-Ce5pmRMj.js";import{h as X,i as G,d as J,m as K,n as Q}from"./useMedia-ae3s_ajC.js";import{S as Y,a as Z,b as ee,c as ae,d as _}from"./select-CrRhFGIi.js";import{C as se}from"./card-C9hfyHXf.js";import{m as P}from"./media-url-DdCoIedP.js";function te({open:i,onSelect:l,onClose:r,allowedTypes:n}){const{host:c}=F(),[d,m]=f.useState(""),[u,j]=f.useState("__all__"),t=f.useRef(null),N=X(c),o=G(c),{data:v}=J(c),h=v?.items??[],y=u==="__all__"?void 0:u==="__unfiled__"?"":u,{data:w,fetchNextPage:s,hasNextPage:C,isFetchingNextPage:b}=K(c,{folderId:y}),[S,T]=f.useState(!1),U=(w?.pages.flatMap(a=>a.items)??[]).filter(a=>n&&!n.some(x=>x.endsWith("/*")?a.mimeType.startsWith(x.slice(0,-1)):a.mimeType===x)?!1:d?a.filename.toLowerCase().includes(d.toLowerCase())||a.alt?.toLowerCase().includes(d.toLowerCase()):!0);async function A(a){T(!0);try{const{uploadUrl:p,mediaId:x}=await N.mutateAsync({filename:a.name,contentType:a.type,size:a.size});await fetch(p,{method:"PUT",body:a,headers:{"Content-Type":a.type}});const z=await o.mutateAsync({mediaId:x,filename:a.name});l(z),r()}catch(p){V.error("Upload failed",{description:p instanceof Error?p.message:void 0})}finally{T(!1)}}function W(a){return a.startsWith("image/")}return e.jsx(R,{open:i,onOpenChange:()=>r(),children:e.jsxs($,{className:"max-w-3xl",children:[e.jsxs(q,{children:[e.jsx(B,{children:"Select Media"}),e.jsx(E,{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(I,{placeholder:"Search by filename...",value:d,onChange:a=>m(a.target.value),className:"max-w-xs"}),h.length>0&&e.jsxs(Y,{value:u,onValueChange:j,children:[e.jsx(Z,{className:"w-[150px]",children:e.jsx(ee,{})}),e.jsxs(ae,{children:[e.jsx(_,{value:"__all__",children:"All folders"}),h.map(a=>e.jsx(_,{value:a.folderId,children:a.name},a.folderId)),e.jsx(_,{value:"__unfiled__",children:"Unfiled"})]})]})]}),e.jsxs("div",{children:[e.jsx("input",{ref:t,type:"file",className:"hidden",accept:n?.join(",")??void 0,onChange:a=>a.target.files?.[0]&&A(a.target.files[0])}),e.jsxs(g,{variant:"outline",onClick:()=>t.current?.click(),disabled:S,children:[S?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(O,{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:U.map(a=>e.jsxs(se,{className:"cursor-pointer overflow-hidden hover:ring-2 hover:ring-primary",onClick:()=>{l(a),r()},children:[e.jsx("div",{className:"flex aspect-square items-center justify-center bg-muted",children:W(a.mimeType)?e.jsx("img",{src:P(a.urls?.thumb_md??a.url),alt:a.alt??a.filename,className:"h-full w-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 p-2",children:[a.mimeType.startsWith("image/")?e.jsx(L,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(D,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("span",{className:"max-w-full truncate text-xs text-muted-foreground",children:a.filename})]})}),e.jsx("div",{className:"p-1.5",children:e.jsx("p",{className:"truncate text-xs",children:a.filename})})]},a.mediaId))}),U.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No media found."}),C&&e.jsxs(g,{variant:"ghost",className:"mt-2 w-full",onClick:()=>s(),disabled:b,children:[b?e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Load More"]})]})})}function le(i){if(!i)return null;if(typeof i=="string")return{id:i,url:""};const l=i,r=l.id??l.mediaId??"";return r?{id:r,url:l.url??"",mimeType:l.mimeType,width:l.width,height:l.height,alt:l.alt,caption:l.caption,filename:l.filename}:null}function ie(i){return i?i.startsWith("image/"):!0}function pe({field:i,value:l,onChange:r,disabled:n}){const{host:c}=F(),[d,m]=f.useState(!1),j=i.options?.allowedTypes,t=le(l),N=t?.id??"",{data:o}=Q(c,N),v=t?.mimeType??o?.mimeType,h=ie(v),y=s=>{t&&r({...t,alt:s})},w=s=>{t&&r({...t,caption:s})};return e.jsxs("div",{children:[t?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>!n&&m(!0),children:[h&&o?.url?e.jsx("img",{src:P(o.urls?.thumb_sm??o.url),alt:t.alt??o?.filename??"",className:"h-10 w-10 rounded object-cover bg-muted"}):e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded bg-muted","aria-label":"File",children:e.jsx(D,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.filename??o?.filename??"Loading..."}),!n&&e.jsx(g,{type:"button",variant:"ghost",size:"sm",onClick:s=>{s.stopPropagation(),r("")},children:e.jsx(H,{className:"h-3 w-3"})})]}),!n&&h&&e.jsxs("div",{className:"grid grid-cols-1 gap-3 pl-1 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-alt`,className:"text-xs font-normal text-muted-foreground",children:"Alt text"}),e.jsx(I,{id:`${t.id}-alt`,type:"text","aria-label":"Alt text",value:t.alt??"",onChange:s=>y(s.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{htmlFor:`${t.id}-caption`,className:"text-xs font-normal text-muted-foreground",children:"Caption"}),e.jsx(I,{id:`${t.id}-caption`,type:"text","aria-label":"Caption",value:t.caption??"",onChange:s=>w(s.target.value)})]})]})]}):e.jsxs(g,{type:"button",variant:"outline",onClick:()=>m(!0),disabled:n,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Select Media"]}),!n&&e.jsx(te,{open:d,onClose:()=>m(!1),onSelect:s=>{const C={id:s.mediaId,url:s.url,mimeType:s.mimeType,width:s.width,height:s.height,alt:s.alt??"",caption:s.caption??"",filename:s.filename};r(C),m(!1)},allowedTypes:j})]})}export{te as M,pe as a};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as g,R as T,L as Dt,u as kt}from"./react-vendor-C2CvUxFh.js";import{u as St}from"./useFilterParams-DYdEuWPE.js";import{u as Tt,a as It,b as Mt,c as Rt,d as ct,e as _t,f as At,g as Et,h as Ft,i as zt,j as $t,k as Pt,l as Ot}from"./useMedia-Cu5N4rY8.js";import{ad as dt,y as P,ae as Ut,af as Lt,ag as Ht,ah as Xt,ai as Yt,aj as Ne,Y as De,Z as ke,_ as Se,B as D,ak as Oe,v as I,D as oe,k as ce,l as de,m as he,n as ue,L,I as K,o as me,a as J,al as Bt,j as Ue,T as Kt,X as ge,P as Wt,am as ee,a6 as Vt,a7 as qt,ab as Qt,a9 as Gt,aa as nt,an as pe,ao as Zt,ap as Jt,a2 as es,aq as ts,ar as ss,a0 as as,x as ns,J as rs,K as is,N as ls,z as rt,as as os,at as cs,au as ds,S as hs,av as us}from"./index-BA3y7HJs.js";import{C as ms,c as xs}from"./card-CZTHR2Qa.js";import{C as Ie}from"./checkbox-DEgzM8H9.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-dX9e6VDt.js";import{u as ht,a as ps,b as gs,c as fs,D as ws,d as js,P as vs}from"./core.esm-DdQHdRkd.js";import{b as ye,a as Le,f as He}from"./format-C88SDH8g.js";import{m as W}from"./media-url-DIg_vSyf.js";import{T as ys,a as bs,b as ut,c as X,d as Cs,e as Y}from"./table-Dk7eeOt2.js";import{T as Pe,A as Xe,h as Ns,a as Ye,b as Be,c as Ke,d as We,e as Ve,g as qe,f as Qe}from"./TagInput-d-Hw1fkL.js";import{u as Ds}from"./usePageTitle-DYvuJQp6.js";import"./radix-C5ZmWuuL.js";function Me({mimeType:a,className:t}){return a==="application/pdf"?e.jsx(dt,{className:P("text-blue-500",t)}):a.startsWith("video/")?e.jsx(Ut,{className:P("text-purple-500",t)}):a.startsWith("audio/")?e.jsx(Lt,{className:P("text-green-500",t)}):a==="image/svg+xml"?e.jsx(Ht,{className:P("text-orange-500",t)}):e.jsx(Xt,{className:P("text-muted-foreground",t)})}function ks(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 Ss({item:a,selected:t,onToggle:s,onSelect:l,onLightbox:n,folderName:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";return e.jsxs(ut,{ref:o,className:P("cursor-pointer",r&&"opacity-50"),onClick:l,children:[e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsx(Y,{className:"w-6 p-1 hidden md:table-cell",children:e.jsx("div",{className:"cursor-grab text-muted-foreground",...d,...h,children:e.jsx(Yt,{className:"h-4 w-4"})})}),e.jsx(Y,{className:"p-1",children:x?e.jsx("img",{src:W(a.urls?.thumb_sm??a.url),alt:a.alt||a.filename,className:P("h-8 w-8 rounded object-cover",n&&"cursor-zoom-in"),onClick:n?p=>{p.stopPropagation(),n()}:void 0}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-5 w-5"})})}),e.jsxs(Y,{className:"max-w-[200px]",children:[i&&e.jsx("span",{className:"text-muted-foreground block truncate text-xs",children:i}),e.jsx("span",{className:"block truncate text-sm font-medium",children:a.filename})]}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ks(a.mimeType)})}),e.jsx(Y,{className:"text-right",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)})}),e.jsx(Y,{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(Y,{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(p=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]",children:p},p)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})}),e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")},children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})})]})}function Ts({items:a,host:t,onSelect:s,selectedIds:l,onToggle:n,onToggleAll:i,allSelected:d,onLightbox:h,folderMap:o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ys,{children:[e.jsx(bs,{children:e.jsxs(ut,{children:[e.jsx(X,{className:"w-10",children:e.jsx(Ie,{checked:d,onCheckedChange:i,"aria-label":"Select all"})}),e.jsx(X,{className:"w-6 hidden md:table-cell"}),e.jsx(X,{className:"w-12"}),e.jsx(X,{children:"Filename"}),e.jsx(X,{className:"w-20 hidden md:table-cell",children:"Type"}),e.jsx(X,{className:"w-24 text-right",children:"Size"}),e.jsx(X,{className:"w-28 hidden lg:table-cell",children:"Dimensions"}),e.jsx(X,{className:"w-40 hidden lg:table-cell",children:"Tags"}),e.jsx(X,{className:"w-32 hidden md:table-cell",children:"Uploaded"}),e.jsx(X,{className:"w-10"})]})}),e.jsx(Cs,{children:a.map(r=>e.jsx(Ss,{item:r,host:t,selected:l.has(r.mediaId),onToggle:()=>n(r.mediaId),onSelect:()=>s(r),folderName:o?.get(r.folderId??""),onLightbox:h&&r.mimeType.startsWith("image/")&&r.mimeType!=="image/svg+xml"?()=>h(r):void 0},r.mediaId))})]})})}var Is=Object.defineProperty,Ms=(a,t,s)=>t in a?Is(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>Ms(a,typeof t!="symbol"?t+"":t,s);const Te={x:0,y:0,width:0,height:0,unit:"px"},re=(a,t,s)=>Math.min(Math.max(a,t),s),Rs=(...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 ie(a,t,s){return a.unit==="%"?{...Te,...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"?{...Te,...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}:{...Te,...a,unit:"px"}}function lt(a,t,s,l,n,i=0,d=0,h=l,o=n){const r={...a};let x=Math.min(i,l),p=Math.min(d,n),f=Math.min(h,l),c=Math.min(o,n);t&&(t>1?(x=d?d*t:x,p=x/t,f=h*t):(p=i?i/t:p,x=p*t,c=o/t)),r.y<0&&(r.height=Math.max(r.height+r.y,p),r.y=0),r.x<0&&(r.width=Math.max(r.width+r.x,x),r.x=0);const b=l-(r.x+r.width);b<0&&(r.x=Math.min(r.x,l-x),r.width+=b);const m=n-(r.y+r.height);if(m<0&&(r.y=Math.min(r.y,n-p),r.height+=m),r.width<x&&((s==="sw"||s=="nw")&&(r.x-=x-r.width),r.width=x),r.height<p&&((s==="nw"||s=="ne")&&(r.y-=p-r.height),r.height=p),r.width>f&&((s==="sw"||s=="nw")&&(r.x-=f-r.width),r.width=f),r.height>c&&((s==="nw"||s=="ne")&&(r.y-=c-r.height),r.height=c),t){const N=r.width/r.height;if(N<t){const w=Math.max(r.width/t,p);(s==="nw"||s=="ne")&&(r.y-=w-r.height),r.height=w}else if(N>t){const w=Math.max(r.height*t,x);(s==="sw"||s=="nw")&&(r.x-=w-r.width),r.width=w}}return r}function _s(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 le={capture:!0,passive:!1};let As=0;const Z=class U extends g.PureComponent{constructor(){super(...arguments),_(this,"docMoveBound",!1),_(this,"mouseDownOnCrop",!1),_(this,"dragStarted",!1),_(this,"evData",{startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0}),_(this,"componentRef",g.createRef()),_(this,"mediaRef",g.createRef()),_(this,"resizeObserver"),_(this,"initChangeCalled",!1),_(this,"instanceId",`rc-${As++}`),_(this,"state",{cropIsActive:!1,newCropIsBeingDrawn:!1}),_(this,"onCropPointerDown",t=>{const{crop:s,disabled:l}=this.props,n=this.getBox();if(!s)return;const i=G(s,n.width,n.height);if(l)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const d=t.target.dataset.ord,h=!!d;let o=t.clientX,r=t.clientY,x=i.x,p=i.y;if(d){const f=t.clientX-n.x,c=t.clientY-n.y;let b=0,m=0;d==="ne"||d=="e"?(b=f-(i.x+i.width),m=c-i.y,x=i.x,p=i.y+i.height):d==="se"||d==="s"?(b=f-(i.x+i.width),m=c-(i.y+i.height),x=i.x,p=i.y):d==="sw"||d=="w"?(b=f-i.x,m=c-(i.y+i.height),x=i.x+i.width,p=i.y):(d==="nw"||d=="n")&&(b=f-i.x,m=c-i.y,x=i.x+i.width,p=i.y+i.height),o=x+n.x+b,r=p+n.y+m}this.evData={startClientX:o,startClientY:r,startCropX:x,startCropY:p,clientX:t.clientX,clientY:t.clientY,isResize:h,ord:d},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})}),_(this,"onComponentPointerDown",t=>{const{crop:s,disabled:l,locked:n,keepSelection:i,onChange:d}=this.props,h=this.getBox();if(l||n||i&&s)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const o=t.clientX-h.x,r=t.clientY-h.y,x={unit:"px",x:o,y:r,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:o,startCropY:r,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,d(G(x,h.width,h.height),ie(x,h.width,h.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})}),_(this,"onDocPointerMove",t=>{const{crop:s,disabled:l,onChange:n,onDragStart:i}=this.props,d=this.getBox();if(l||!s||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,i&&i(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,d.width,d.height),ie(o,d.width,d.height))}),_(this,"onComponentKeyDown",t=>{const{crop:s,disabled:l,onChange:n,onComplete:i}=this.props;if(l)return;const d=t.key;let h=!1;if(!s)return;const o=this.getBox(),r=this.makePixelCrop(o),x=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep;if(d==="ArrowLeft"?(r.x-=x,h=!0):d==="ArrowRight"?(r.x+=x,h=!0):d==="ArrowUp"?(r.y-=x,h=!0):d==="ArrowDown"&&(r.y+=x,h=!0),h){t.cancelable&&t.preventDefault(),r.x=re(r.x,0,o.width-r.width),r.y=re(r.y,0,o.height-r.height);const p=G(r,o.width,o.height),f=ie(r,o.width,o.height);n(p,f),i&&i(p,f)}}),_(this,"onHandlerKeyDown",(t,s)=>{const{aspect:l=0,crop:n,disabled:i,minWidth:d=0,minHeight:h=0,maxWidth:o,maxHeight:r,onChange:x,onComplete:p}=this.props,f=this.getBox();if(i||!n)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const c=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep,b=G(n,f.width,f.height),m=_s(b,t.key,c,s),N=lt(m,l,s,f.width,f.height,d,h,o,r);if(!it(n,N)){const w=ie(N,f.width,f.height);x(N,w),p&&p(N,w)}}),_(this,"onDocPointerDone",t=>{const{crop:s,disabled:l,onComplete:n,onDragEnd:i}=this.props,d=this.getBox();this.unbindDocMove(),!(l||!s)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,i&&i(t),n&&n(G(s,d.width,d.height),ie(s,d.width,d.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))}),_(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:i}=t.getBoundingClientRect();return{x:s,y:l,width:n,height:i}}componentDidUpdate(t){const{crop:s,onComplete:l}=this.props;if(l&&!t.crop&&s){const{width:n,height:i}=this.getBox();n&&i&&l(G(s,n,i),ie(s,n,i))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,le),this.document.addEventListener("pointerup",this.onDocPointerDone,le),this.document.addEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,le),this.document.removeEventListener("pointerup",this.onDocPointerDone,le),this.document.removeEventListener("pointercancel",this.onDocPointerDone,le),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,i=t.clientY-t.startClientY;return l.x=re(t.startCropX+n,0,s.width-l.width),l.y=re(t.startCropY+i,0,s.height-l.height),l}getPointRegion(t,s,l,n){const{evData:i}=this,d=i.clientX-t.x,h=i.clientY-t.y;let o;n&&s?o=s==="nw"||s==="n"||s==="ne":o=h<i.startCropY;let r;return l&&s?r=s==="nw"||s==="w"||s==="sw":r=d<i.startCropX,r?o?"nw":"sw":o?"ne":"se"}resolveMinDimensions(t,s,l=0,n=0){const i=Math.min(l,t.width),d=Math.min(n,t.height);return!s||!i&&!d?[i,d]:s>1?i?[i,i/s]:[d*s,d]:d?[d*s,d]:[i,i/s]}resizeCrop(){const{evData:t}=this,{aspect:s=0,maxWidth:l,maxHeight:n}=this.props,i=this.getBox(),[d,h]=this.resolveMinDimensions(i,s,this.props.minWidth,this.props.minHeight);let o=this.makePixelCrop(i);const r=this.getPointRegion(i,t.ord,d,h),x=t.ord||r;let p=t.clientX-t.startClientX,f=t.clientY-t.startClientY;(d&&x==="nw"||x==="w"||x==="sw")&&(p=Math.min(p,-d)),(h&&x==="nw"||x==="n"||x==="ne")&&(f=Math.min(f,-h));const c={unit:"px",x:0,y:0,width:0,height:0};r==="ne"?(c.x=t.startCropX,c.width=p,s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY-c.height)):r==="se"?(c.x=t.startCropX,c.y=t.startCropY,c.width=p,s?c.height=c.width/s:c.height=f):r==="sw"?(c.x=t.startCropX+p,c.y=t.startCropY,c.width=Math.abs(p),s?c.height=c.width/s:c.height=f):r==="nw"&&(c.x=t.startCropX+p,c.width=Math.abs(p),s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY+f));const b=lt(c,s,r,i.width,i.height,d,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=re(o.x,0,i.width-o.width),o.y=re(o.y,0,i.height-o.height),o}renderCropSelection(){const{ariaLabels:t=U.defaultProps.ariaLabels,disabled:s,locked:l,renderSelectionAddon:n,ruleOfThirds:i,crop:d}=this.props,h=this.getCropStyle();if(d)return T.createElement("div",{style:h,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!s&&!l&&T.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},T.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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&&T.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:o=>o.stopPropagation()},n(this.state)),i&&T.createElement(T.Fragment,null,T.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),T.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const s={...Te,...this.props.crop||{}};return G(s,t.width,t.height)}render(){const{aspect:t,children:s,circularCrop:l,className:n,crop:i,disabled:d,locked:h,style:o,ruleOfThirds:r}=this.props,{cropIsActive:x,newCropIsBeingDrawn:p}=this.state,f=i?this.renderCropSelection():null,c=Rs("ReactCrop",n,x&&"ReactCrop--active",d&&"ReactCrop--disabled",h&&"ReactCrop--locked",p&&"ReactCrop--new-crop",i&&t&&"ReactCrop--fixed-aspect",i&&l&&"ReactCrop--circular-crop",i&&r&&"ReactCrop--rule-of-thirds",!this.dragStarted&&i&&!i.width&&!i.height&&"ReactCrop--invisible-crop",l&&"ReactCrop--no-animate");return T.createElement("div",{ref:this.componentRef,className:c,style:o},T.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},s),i?T.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},T.createElement("defs",null,T.createElement("mask",{id:`hole-${this.instanceId}`},T.createElement("rect",{width:"100%",height:"100%",fill:"white"}),l?T.createElement("ellipse",{cx:`${i.x+i.width/2}${i.unit}`,cy:`${i.y+i.height/2}${i.unit}`,rx:`${i.width/2}${i.unit}`,ry:`${i.height/2}${i.unit}`,fill:"black"}):T.createElement("rect",{x:`${i.x}${i.unit}`,y:`${i.y}${i.unit}`,width:`${i.width}${i.unit}`,height:`${i.height}${i.unit}`,fill:"black"}))),T.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,f)}};_(Z,"xOrds",["e","w"]),_(Z,"yOrds",["n","s"]),_(Z,"xyOrds",["nw","ne","se","sw"]),_(Z,"nudgeStep",1),_(Z,"nudgeStepMedium",10),_(Z,"nudgeStepLarge",100),_(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 Es=Z;const Fs=[{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"}],mt=[{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"}],zs={"image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/tiff":".tiff"};function ze(a,t){return a?mt.find(s=>s.value===a)?.ext||`.${a}`:zs[t]||".jpg"}function $s(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ps({host:a,media:t,onClose:s,onSaved:l}){const n=g.useRef(null),[i,d]=g.useState(),[h,o]=g.useState(),[r,x]=g.useState(""),[p,f]=g.useState(""),[c,b]=g.useState(""),[m,N]=g.useState(""),[w,S]=g.useState("80"),[R,A]=g.useState(()=>{const y=ze("",t.mimeType),M=t.filename.lastIndexOf(".");return`${M>0?t.filename.substring(0,M):t.filename}-transformed${y}`});function F(y){const M=y==="__original__"?"":y;N(M);const q=ze(M,t.mimeType);A(ae=>$s(ae,q))}const z=Tt(a,t.mediaId),[j,v]=g.useState(null),$=g.useCallback(()=>{if(!h||!j)return null;const y=(t.width??j.width)/j.width,M=(t.height??j.height)/j.height;return{cropX:Math.round(h.x*y),cropY:Math.round(h.y*M),cropW:Math.round(h.width*y),cropH:Math.round(h.height*M)}},[h,t.width,t.height,j]),B=g.useMemo(()=>$(),[$]);async function se(){const y=B,M=p?parseInt(p):void 0,q=c?parseInt(c):void 0;if(!y&&!M&&!q&&!m){I.error("Please specify a crop, resize, or format change");return}if(!R.trim()){I.error("Filename is required");return}const ae=ze(m,t.mimeType);if(!R.trim().toLowerCase().endsWith(ae)){I.error(`Filename must end with ${ae} to match the output format`);return}try{const ne=await z.mutateAsync({...y??{},...M?{width:M}:{},...q?{height:q}:{},...m?{format:m}:{},...w?{quality:parseInt(w)}:{},filename:R.trim()});I.success("Transform saved as new media"),l?.(ne),s()}catch(ne){I.error("Transform failed",{description:ne instanceof Error?ne.message:void 0})}}function xe(y){x(y==="__free__"?"":y),d(void 0),o(void 0)}function V(y){if(!y)return;const M=y.split("/");return M.length===2?Number(M[0])/Number(M[1]):Number(y)||void 0}const Ge=V(r);return e.jsx(oe,{open:!0,onOpenChange:()=>s(),children:e.jsxs(ce,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(de,{children:[e.jsx(he,{children:"Transform Image"}),e.jsx(ue,{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(Es,{crop:i,onChange:y=>d(y),onComplete:y=>o(y),aspect:Ge,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:y=>{const M=y.currentTarget;v({width:M.naturalWidth,height:M.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(L,{children:"Crop aspect ratio"}),e.jsxs(fe,{value:r||"__free__",onValueChange:xe,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Free"})}),e.jsx(ve,{children:Fs.map(y=>e.jsx(te,{value:y.value||"__free__",children:y.label},y.value||"__free__"))})]}),h&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Crop: ",B?.cropW,"×",B?.cropH," at (",B?.cropX,", ",B?.cropY,")"]}),h&&e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{d(void 0),o(void 0)},children:"Clear crop"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Resize (optional)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Width",value:p,onChange:y=>f(y.target.value),min:1,max:2048})}),e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Height",value:c,onChange:y=>b(y.target.value),min:1,max:2048})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Output format"}),e.jsxs(fe,{value:m||"__original__",onValueChange:F,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Original"})}),e.jsx(ve,{children:mt.map(y=>e.jsx(te,{value:y.value||"__original__",children:y.label},y.value||"__original__"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Quality (1-100)"}),e.jsx(K,{type:"number",value:w,onChange:y=>S(y.target.value),min:1,max:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Save as filename"}),e.jsx(K,{value:R,onChange:y=>A(y.target.value)})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs(D,{onClick:se,disabled:z.isPending,children:[z.isPending&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save as New Image"]})]})]})})}const Os=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Us({host:a,media:t,onClose:s,onDeleted:l,folders:n,tagSuggestions:i}){const[d,h]=g.useState(t.alt??""),[o,r]=g.useState(t.caption??""),[x,p]=g.useState(t.userTags??[]),[f,c]=g.useState(t.folderId||"__none__"),[b,m]=g.useState(!1),N=Os.has(t.mimeType),w=It(a,t.mediaId),S=Mt(a,t.mediaId),{data:R,isLoading:A}=Rt(a,t.mediaId),F=t.tags.filter(v=>!t.userTags?.includes(v));async function z(){try{await w.mutateAsync({alt:d,caption:o,userTags:x,folderId:f==="__none__"?"":f}),I.success("Media updated"),s()}catch(v){I.error("Failed to update",{description:v instanceof Error?v.message:void 0})}}async function j(){try{await S.mutateAsync(),I.success("Media deleted"),l?.(t.mediaId),s()}catch(v){I.error("Failed to delete",{description:v instanceof Error?v.message:void 0})}}return e.jsxs(oe,{open:!0,onOpenChange:()=>s(),children:[e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(he,{children:t.filename}),e.jsx(ue,{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," · ",ye(t.size),t.width&&t.height&&` · ${t.width}×${t.height}`," · ",He(t.uploadedAt)]}),e.jsxs("div",{className:"flex gap-2",children:[N&&e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Transform"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(W(t.url)),I.success("URL copied to clipboard")},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),"Copy URL"]})]})]}),F.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Auto-detected tags"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:F.map(v=>e.jsx(Ue,{variant:"outline",className:"text-xs",children:v},v))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Tags"}),e.jsx(Pe,{tags:x,onChange:p,placeholder:"Add tags...",suggestions:i})]}),n&&n.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Folder"}),e.jsxs(fe,{value:f,onValueChange:c,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"No folder"})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__none__",children:"No folder"}),n.map(v=>e.jsx(te,{value:v.folderId,children:v.name},v.folderId))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"alt",children:"Alt text"}),e.jsx(K,{id:"alt",value:d,onChange:v=>h(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"caption",children:"Caption"}),e.jsx(K,{id:"caption",value:o,onChange:v=>r(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Used in"}),A?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}),"Checking usage..."]}):R?.references.length?e.jsxs("div",{className:"space-y-1",children:[R.references.map(v=>e.jsxs(Dt,{to:`/sites/${a}/content/${v.collection}/${v.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:v.title||v.contentId}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",v.collection,")"]})]},v.contentId)),R.note&&e.jsx("p",{className:"text-muted-foreground text-xs italic",children:R.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(Xe,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(D,{variant:"destructive",size:"sm",children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete media?"}),e.jsxs(We,{children:["This will permanently delete “",t.filename,"”. This action cannot be undone."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(D,{onClick:z,children:"Save"})]})]})]}),b&&e.jsx(Ps,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ls({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(Ue,{variant:t===l?"default":"secondary",className:"cursor-pointer select-none",onClick:()=>s(t===l?void 0:l),children:l},l)),t&&e.jsxs(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s(void 0),children:[e.jsx(ge,{className:"mr-1 h-3 w-3"}),"Clear"]})]})}function $e({id:a,children:t}){const{setNodeRef:s,isOver:l}=ps({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=_t(a),i=At(a),d=Et(a),[h,o]=g.useState(!1),[r,x]=g.useState(""),[p,f]=g.useState(null),[c,b]=g.useState(""),[m,N]=g.useState(null),w=g.useRef(null),S=g.useRef(null),R=l?.items??[];g.useEffect(()=>{h&&w.current?.focus()},[h]),g.useEffect(()=>{p&&S.current?.focus()},[p]);async function A(){const j=r.trim();if(!j){o(!1),x("");return}try{await n.mutateAsync(j),I.success("Folder created")}catch(v){I.error("Failed to create folder",{description:v instanceof Error?v.message:void 0})}o(!1),x("")}async function F(j){const v=c.trim();if(!v){f(null);return}try{await i.mutateAsync({folderId:j,name:v}),I.success("Folder renamed")}catch($){I.error("Failed to rename folder",{description:$ instanceof Error?$.message:void 0})}f(null)}async function z(){if(m){try{await d.mutateAsync(m.folderId),I.success("Folder deleted"),t===m.folderId&&s(null)}catch(j){I.error("Failed to delete folder",{description:j instanceof Error?j.message:void 0})}N(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(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>o(!0),children:e.jsx(Wt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[e.jsx($e,{id:"all-media",children:j=>e.jsx("button",{className:P("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",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s(null),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"All Media"]})})}),R.map(j=>e.jsx($e,{id:j.folderId,children:v=>e.jsx("div",{className:P("group flex w-full items-center justify-between px-3 py-1.5 text-sm hover:bg-accent/50",t===j.folderId&&"bg-accent font-medium",v&&"ring-2 ring-primary bg-primary/10"),children:p===j.folderId?e.jsx(K,{ref:S,value:c,onChange:$=>b($.target.value),onKeyDown:$=>{$.key==="Enter"&&F(j.folderId),$.key==="Escape"&&f(null)},onBlur:()=>F(j.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(j.folderId),children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:j.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:j.count}),e.jsxs(Vt,{children:[e.jsx(qt,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100",children:e.jsx(Qt,{className:"h-3.5 w-3.5"})})}),e.jsxs(Gt,{align:"end",children:[e.jsx(nt,{onClick:()=>{f(j.folderId),b(j.name)},children:"Rename"}),e.jsx(nt,{disabled:j.count>0,onClick:()=>N(j),children:"Delete"})]})]})]})]})})},j.folderId)),e.jsx($e,{id:"unfiled",children:j=>e.jsx("button",{className:P("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",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s("unfiled"),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Unfiled"]})})}),h&&e.jsx("div",{className:"px-3 py-1.5",children:e.jsx(K,{ref:w,value:r,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&A(),j.key==="Escape"&&(o(!1),x(""))},onBlur:A,placeholder:"Folder name...",className:"h-7 text-sm"})})]}),e.jsx(Xe,{open:!!m,onOpenChange:()=>N(null),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete folder?"}),e.jsxs(We,{children:["This will delete the folder “",m?.name,"”. Media items in this folder will become unfiled."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:z,children:"Delete"})]})]})})]})}function Hs({selectedCount:a,folders:t,onDelete:s,onMove:l,onAddTags:n,onRemoveTags:i,onClear:d,isPending:h}){const[o,r]=g.useState(null),[x,p]=g.useState(""),[f,c]=g.useState([]);function b(){r(null),p(""),c([])}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(D,{size:"sm",variant:"ghost",onClick:d,disabled:h,children:e.jsx(ge,{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(D,{size:"sm",variant:"destructive",onClick:()=>r("delete"),disabled:h,className:"shrink-0",children:"Delete"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("move"),disabled:h,className:"shrink-0",children:"Move to…"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("addTags"),disabled:h,className:"shrink-0",children:"Add tags"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("removeTags"),disabled:h,className:"shrink-0",children:"Remove tags"})]})]}),e.jsx(oe,{open:o==="delete",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Delete ",a," item",a!==1?"s":"","?"]}),e.jsx(ue,{children:"This action cannot be undone. The selected media items will be permanently deleted."})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{variant:"destructive",onClick:async()=>{b(),await s()},disabled:h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})}),e.jsx(oe,{open:o==="move",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Move ",a," item",a!==1?"s":""]}),e.jsx(ue,{children:"Choose a destination folder."})]}),e.jsxs(fe,{value:x,onValueChange:p,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Select folder..."})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__unfiled__",children:"Unfiled"}),t.map(m=>e.jsx(te,{value:m.folderId,children:m.name},m.folderId))]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=x==="__unfiled__"?"":x;b(),await l(m)},disabled:!x||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Move"]})]})]})}),e.jsx(oe,{open:o==="addTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Add tags to ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to add to the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Add tags..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await n(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Add"]})]})]})}),e.jsx(oe,{open:o==="removeTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Remove tags from ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to remove from the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Tags to remove..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await i(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Remove"]})]})]})})]})}function Xs({onFiles:a,children:t}){const[s,l]=g.useState(!1),n=g.useRef(0),i=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.types.includes("Files")&&(n.current++,l(!0))},[]),d=g.useCallback(r=>{r.preventDefault(),n.current--,n.current===0&&l(!1)},[]),h=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.dropEffect="copy"},[]),o=g.useCallback(r=>{r.preventDefault(),n.current=0,l(!1);const x=Array.from(r.dataTransfer.files);x.length>0&&a(x)},[a]);return e.jsxs("div",{className:"relative flex-1",onDragEnter:i,onDragLeave:d,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(pe,{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 Ys({queue:a}){const{items:t,retry:s,dismiss:l,clearCompleted:n}=a,[i,d]=g.useState(!1),h=t.filter(c=>c.status==="uploading").length,o=t.filter(c=>c.status==="pending").length,r=t.filter(c=>c.status==="complete").length,x=t.filter(c=>c.status==="error").length,p=h===0&&o===0;if(g.useEffect(()=>{if(p&&t.length>0){const c=setTimeout(()=>d(!0),2e3);return()=>clearTimeout(c)}},[p,t.length]),t.length===0)return null;const f=p?`${r} 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:f}),e.jsxs("div",{className:"flex items-center gap-1",children:[p&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:n,children:"Clear"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(!i),children:i?e.jsx(Zt,{className:"h-4 w-4"}):e.jsx(Jt,{className:"h-4 w-4"})})]})]}),!i&&e.jsx("div",{className:"max-h-60 overflow-y-auto",children:t.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-sm",children:[c.status==="uploading"&&e.jsx(J,{className:"h-4 w-4 shrink-0 animate-spin"}),c.status==="complete"&&e.jsx(es,{className:"h-4 w-4 shrink-0 text-green-500"}),c.status==="error"&&e.jsx(ge,{className:"h-4 w-4 shrink-0 text-destructive"}),c.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:c.file.name}),c.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:`${c.progress}%`}})}),c.status==="error"&&e.jsx("p",{className:"text-destructive truncate text-xs",children:c.error})]}),c.status==="error"&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>s(c.id),children:e.jsx(ts,{className:"h-3 w-3"})}),(c.status==="complete"||c.status==="error")&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>l(c.id),children:e.jsx(ge,{className:"h-3 w-3"})})]},c.id))})]})}const Bs=3;let Ks=0;function Ws(a,t){const[s,l]=g.useState([]),n=Ft(a),i=zt(a),d=g.useRef(0),h=g.useRef(s);h.current=s;const o=g.useRef(new Map),r=g.useCallback(async m=>{d.current++,l(N=>N.map(w=>w.id===m.id?{...w,status:"uploading",progress:0}:w));try{const{uploadUrl:N,mediaId:w}=await n.mutateAsync({filename:m.file.name,contentType:m.file.type,size:m.file.size});await new Promise((S,R)=>{const A=new XMLHttpRequest;o.current.set(m.id,A),A.upload.onprogress=F=>{if(F.lengthComputable){const z=Math.round(F.loaded/F.total*100);l(j=>j.map(v=>v.id===m.id?{...v,progress:z}:v))}},A.onload=()=>{o.current.delete(m.id),A.status>=200&&A.status<300?S():R(new Error(`Upload failed: ${A.status}`))},A.onerror=()=>{o.current.delete(m.id),R(new Error("Network error"))},A.onabort=()=>{o.current.delete(m.id),R(new Error("Upload aborted"))},A.open("PUT",N),A.setRequestHeader("Content-Type",m.file.type),A.send(m.file)}),await i.mutateAsync({mediaId:w,filename:m.file.name,folderId:m.folderId}),l(S=>S.map(R=>R.id===m.id?{...R,status:"complete",progress:100}:R))}catch(N){l(w=>w.map(S=>S.id===m.id?{...S,status:"error",error:N instanceof Error?N.message:"Upload failed"}:S))}finally{d.current--}},[n,i]),x=g.useRef(r);x.current=r,g.useEffect(()=>{const m=s.filter(w=>w.status==="pending"),N=Bs-d.current;for(let w=0;w<Math.min(m.length,N);w++)x.current(m[w])},[s]),g.useEffect(()=>{const m=o.current;return()=>{m.forEach(N=>N.abort())}},[]);const p=g.useCallback(m=>{const N=Array.from(m).map(w=>({id:`upload-${Ks++}`,file:w,folderId:t||void 0,status:"pending",progress:0}));l(w=>[...w,...N])},[t]),f=g.useCallback(m=>{l(N=>N.map(w=>w.id===m?{...w,status:"pending",progress:0,error:void 0}:w))},[]),c=g.useCallback(m=>{l(N=>N.filter(w=>w.id!==m))},[]),b=g.useCallback(()=>{l(m=>m.filter(N=>N.status!=="complete"&&N.status!=="error"))},[]);return{items:s,addFiles:p,retry:f,dismiss:c,clearCompleted:b}}function Vs({items:a,currentIndex:t,onClose:s,onNavigate:l}){const n=a[t],i=t>0,d=t<a.length-1,h=g.useRef(null),o=g.useCallback(r=>{r.key==="Escape"?s():r.key==="ArrowLeft"&&i?l(t-1):r.key==="ArrowRight"&&d&&l(t+1)},[s,l,t,i,d]);return g.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 pt-[max(0.75rem,env(safe-area-inset-top,0px))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))] text-white",onClick:r=>r.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} · `,ye(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(D,{variant:"ghost",size:"icon",className:"text-white hover:bg-white/20",onClick:s,children:e.jsx(ge,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center px-4 md:px-16",onClick:r=>r.stopPropagation(),onTouchStart:r=>{h.current=r.touches[0].clientX},onTouchEnd:r=>{if(h.current===null)return;const x=r.changedTouches[0].clientX-h.current;h.current=null,x>50&&i?l(t-1):x<-50&&d&&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"}),i&&e.jsx(D,{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(ss,{className:"h-8 w-8"})}),d&&e.jsx(D,{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(as,{className:"h-8 w-8"})})]})]}):null}function qs({open:a,duplicates:t,fileCount:s,onContinue:l,onCancel:n}){return e.jsx(Xe,{open:a,onOpenChange:i=>!i&&n(),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Possible duplicates found"}),e.jsx(We,{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(i=>e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[i.mimeType.startsWith("image/")&&i.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(i.urls?.thumb_sm??i.url),alt:i.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(Me,{mimeType:i.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:i.filename}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[ye(i.size)," ·"," ",Le(i.uploadedAt)]})]})]},i.mediaId))}),e.jsxs(Ve,{children:[e.jsx(qe,{onClick:n,children:"Cancel"}),e.jsx(Qe,{onClick:l,children:"Upload Anyway"})]})]})})}const Qs=({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},Gs=[{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 Zs({item:a,selected:t,onToggle:s,onClick:l,folderName:n,onLightbox:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";function p(f){f.stopPropagation(),navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")}return e.jsx(ms,{ref:o,...d,...h,className:P("group relative cursor-pointer overflow-hidden",r&&"opacity-50",t&&"ring-2 ring-primary"),onClick:l,children:e.jsxs(xs,{className:"p-0",children:[e.jsx("div",{className:P("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:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:e.jsx(Ie,{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:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:[e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:p,children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"Copy URL"})]})}),x&&i&&e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:f=>{f.stopPropagation(),i()},children:e.jsx(us,{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(Me,{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(ee,{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:ye(a.size)}),e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})]}),a.tags.length>0&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(f=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]",children:f},f)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})]})]})})}function xa(){const{host:a}=kt(),t=ns(),[s,l]=St([{key:"tag",defaultValue:""},{key:"folder",defaultValue:""},{key:"q",defaultValue:""},{key:"sort",defaultValue:"date_desc"},{key:"view",defaultValue:"grid"}]),n=s.view,i=u=>l({view:u}),d=s.sort,h=u=>l({sort:u}),o=s.tag||void 0,r=s.folder===""?null:s.folder,x=u=>l({folder:u??""}),[p,f]=g.useState(s.q),[c,b]=g.useState(s.q),[m,N]=g.useState(null),[w,S]=g.useState(new Set),[R,A]=g.useState(null),[F,z]=g.useState(null),[j,v]=g.useState(null),[$,B]=g.useState([]),[se,xe]=g.useState(!1),V=g.useRef(null);Ds({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Ws(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=gs(fs(vs,{activationConstraint:{distance:t?1e5:8}}));g.useEffect(()=>{const u=setTimeout(()=>{b(C=>{const k=p;return C!==k&&(S(new Set),l({q:k})),k})},300);return()=>clearTimeout(u)},[p,l]);const ne=r===null?void 0:r==="unfiled"?"":r,{data:O,isLoading:xt}=Ot(a,{sort:d,q:c||void 0,folderId:ne,tag:o}),{data:Ze}=ct(a),be=g.useMemo(()=>Ze?.items??[],[Ze?.items]),Re=g.useMemo(()=>{const u=new Map;for(const C of be)u.set(C.folderId,C.name);return u},[be]),Ce=g.useMemo(()=>(O?.items??[]).filter(u=>u.mimeType.startsWith("image/")&&u.mimeType!=="image/svg+xml"),[O?.items]),_e=g.useMemo(()=>{const u=new Map;return Ce.forEach((C,k)=>u.set(C.mediaId,k)),u},[Ce]),{allTags:pt,allUserTags:gt}=g.useMemo(()=>{const u=O?.items??[],C=new Set,k=new Set;for(const E of u){for(const H of E.tags)C.add(H);for(const H of E.userTags??[])k.add(H)}return{allTags:Array.from(C).sort(),allUserTags:Array.from(k).sort()}},[O?.items]),Ae=O?.items.map(u=>u.mediaId)??[],Ee=Ae.length>0&&Ae.every(u=>w.has(u));function Je(u){S(C=>{const k=new Set(C);return k.has(u)?k.delete(u):k.add(u),k})}function et(){S(Ee?new Set:new Set(Ae))}async function ft(){const u=[...w],k=(await M.mutateAsync({mediaIds:u,action:"delete"})).failed.length;k?I.error(`${k} of ${u.length} failed to delete`):I.success(`${u.length} item(s) deleted`),S(new Set)}async function wt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"move",folderId:u})).failed.length;E?I.error(`${E} of ${C.length} failed to move`):I.success(`${C.length} item(s) moved`),S(new Set)}async function jt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"addTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags added to ${C.length} item(s)`),S(new Set)}async function vt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"removeTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags removed from ${C.length} item(s)`),S(new Set)}async function tt(u){const C=Array.from(u),k=C.slice(0,5),E=[];for(const H of k)try{const Fe=await q.mutateAsync({filename:H.name,size:H.size});E.push(...Fe.duplicates)}catch{}E.length>0?(v(C),B(E)):y.addFiles(C)}function yt(u){u.target.files&&tt(u.target.files),V.current&&(V.current.value="")}function bt(u){A(String(u.active.id))}function Ct(u){A(null);const{active:C,over:k}=u;if(!k||k.data.current?.type!=="folder")return;const E=k.id==="unfiled"||k.id==="all-media"?"":String(k.id),H=w.has(String(C.id))?[...w]:[String(C.id)];M.mutateAsync({mediaIds:H,action:"move",folderId:E}).then(Fe=>{const at=Fe.failed.length;at?I.error(`${at} of ${H.length} failed to move`):I.success(`${H.length} item(s) moved`)})}function Nt(){A(null)}const Q=R?O?.items.find(u=>u.mediaId===R):null,st=R&&w.has(R)?w.size:1;return e.jsxs(ws,{sensors:ae,modifiers:[Qs],onDragStart:bt,onDragEnd:Ct,onDragCancel:Nt,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:r,onSelect:u=>{x(u),S(new Set)}})}),e.jsx(rs,{open:se,onOpenChange:xe,children:e.jsxs(is,{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(ls,{className:"sr-only",children:"Folders"}),e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set),xe(!1)}})]})}),e.jsxs(Xs,{onFiles:u=>tt(u),children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-2 md:p-6",children:[!t&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Media"}),e.jsx("div",{children:e.jsxs(D,{onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})})]}),e.jsx("input",{ref:V,type:"file",multiple:!0,className:"hidden",onChange:yt}),w.size>0?e.jsx(Hs,{selectedCount:w.size,folders:be,onDelete:ft,onMove:wt,onAddTags:jt,onRemoveTags:vt,onClear:()=>S(new Set),isPending:M.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(K,{placeholder:"Search media...",value:p,onChange:u=>f(u.target.value),className:"pl-9"})]}),e.jsxs(fe,{value:d,onValueChange:h,children:[e.jsx(we,{className:"w-[160px]",children:e.jsx(je,{})}),e.jsx(ve,{children:Gs.map(u=>e.jsx(te,{value:u.value,children:u.label},u.value))})]}),e.jsx(D,{variant:se?"secondary":"ghost",size:"sm",className:"md:hidden px-2",onClick:()=>xe(!se),"aria-label":"Toggle folders",children:e.jsx(os,{className:"h-4 w-4"})}),!se&&r!==null&&t&&e.jsxs(Ue,{variant:"secondary",className:"gap-1 md:hidden",children:[e.jsx(ee,{className:"h-3 w-3"}),r==="unfiled"?"Unfiled":Re.get(r)??"All Media"]}),e.jsxs("div",{className:"flex rounded-md border",children:[e.jsx(D,{variant:n==="grid"?"secondary":"ghost",size:"sm",className:"rounded-r-none px-2",onClick:()=>i("grid"),children:e.jsx(cs,{className:"h-4 w-4"})}),e.jsx(D,{variant:n==="list"?"secondary":"ghost",size:"sm",className:"rounded-l-none px-2",onClick:()=>i("list"),children:e.jsx(ds,{className:"h-4 w-4"})})]})]}),e.jsx(Ls,{tags:pt,activeTag:o,onTagChange:u=>{l({tag:u??""}),S(new Set)}}),n==="grid"&&(O?.items.length??0)>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Ie,{checked:Ee,onCheckedChange:et,"aria-label":"Select all"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:w.size>0?`${w.size} of ${O.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 xl:grid-cols-5 2xl:grid-cols-6",children:Array.from({length:8}).map((u,C)=>e.jsx(hs,{className:"aspect-square"},C))}):O?.items.length?n==="list"?e.jsx(Ts,{items:O.items,host:a,onSelect:N,selectedIds:w,onToggle:Je,onToggleAll:et,allSelected:Ee,folderMap:r===null?Re:void 0,onLightbox:u=>{const C=_e.get(u.mediaId);C!==void 0&&z(C)}}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:O.items.map(u=>e.jsx(Zs,{item:u,selected:w.has(u.mediaId),onToggle:()=>Je(u.mediaId),onClick:()=>N(u),folderName:r===null?Re.get(u.folderId??""):void 0,onLightbox:_e.has(u.mediaId)?()=>z(_e.get(u.mediaId)):void 0},u.mediaId))}):e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:c||o?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."})]}):r==="unfiled"?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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."})]}):r?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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(pe,{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(D,{className:"mt-4",onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})]})}),m&&e.jsx(Us,{host:a,media:m,onClose:()=>N(null),onDeleted:u=>{S(C=>{if(!C.has(u))return C;const k=new Set(C);return k.delete(u),k})},folders:be,tagSuggestions:gt})]}),e.jsx(Ys,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(Vs,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(qs,{open:$.length>0,host:a,duplicates:$,fileCount:j?Array.from(j).length:0,onContinue:()=>{j&&y.addFiles(j),v(null),B([])},onCancel:()=>{v(null),B([])}}),e.jsx(js,{children:R&&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(Me,{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{xa as MediaPage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as g,R as T,L as Dt,u as kt}from"./react-vendor-C2CvUxFh.js";import{u as St}from"./useFilterParams-DYdEuWPE.js";import{u as Tt,a as It,b as Mt,c as Rt,d as ct,e as _t,f as At,g as Et,h as Ft,i as zt,j as $t,k as Pt,l as Ot}from"./useMedia-ae3s_ajC.js";import{ad as dt,y as P,ae as Ut,af as Lt,ag as Ht,ah as Xt,ai as Yt,aj as Ne,Y as De,Z as ke,_ as Se,B as D,ak as Oe,v as I,D as oe,k as ce,l as de,m as he,n as ue,L,I as K,o as me,a as J,al as Bt,j as Ue,T as Kt,X as ge,P as Wt,am as ee,a6 as Vt,a7 as qt,ab as Qt,a9 as Gt,aa as nt,an as pe,ao as Zt,ap as Jt,a2 as es,aq as ts,ar as ss,a0 as as,x as ns,J as rs,K as is,N as ls,z as rt,as as os,at as cs,au as ds,S as hs,av as us}from"./index-Ce5pmRMj.js";import{C as ms,c as xs}from"./card-C9hfyHXf.js";import{C as Ie}from"./checkbox-DVJcwUt1.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-CrRhFGIi.js";import{u as ht,a as ps,b as gs,c as fs,D as ws,d as js,P as vs}from"./core.esm-DdQHdRkd.js";import{b as ye,a as Le,f as He}from"./format-C88SDH8g.js";import{m as W}from"./media-url-DdCoIedP.js";import{T as ys,a as bs,b as ut,c as X,d as Cs,e as Y}from"./table-_3bMY0_z.js";import{T as Pe,A as Xe,h as Ns,a as Ye,b as Be,c as Ke,d as We,e as Ve,f as qe,g as Qe}from"./TagInput-57c4DG1w.js";import{u as Ds}from"./usePageTitle-C1r1-C00.js";import"./radix-C5ZmWuuL.js";function Me({mimeType:a,className:t}){return a==="application/pdf"?e.jsx(dt,{className:P("text-blue-500",t)}):a.startsWith("video/")?e.jsx(Ut,{className:P("text-purple-500",t)}):a.startsWith("audio/")?e.jsx(Lt,{className:P("text-green-500",t)}):a==="image/svg+xml"?e.jsx(Ht,{className:P("text-orange-500",t)}):e.jsx(Xt,{className:P("text-muted-foreground",t)})}function ks(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 Ss({item:a,selected:t,onToggle:s,onSelect:l,onLightbox:n,folderName:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";return e.jsxs(ut,{ref:o,className:P("cursor-pointer",r&&"opacity-50"),onClick:l,children:[e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(Ie,{checked:t,onCheckedChange:s,"aria-label":`Select ${a.filename}`})}),e.jsx(Y,{className:"w-6 p-1 hidden md:table-cell",children:e.jsx("div",{className:"cursor-grab text-muted-foreground",...d,...h,children:e.jsx(Yt,{className:"h-4 w-4"})})}),e.jsx(Y,{className:"p-1",children:x?e.jsx("img",{src:W(a.urls?.thumb_sm??a.url),alt:a.alt||a.filename,className:P("h-8 w-8 rounded object-cover",n&&"cursor-zoom-in"),onClick:n?p=>{p.stopPropagation(),n()}:void 0}):e.jsx("div",{className:"flex h-8 w-8 items-center justify-center",children:e.jsx(Me,{mimeType:a.mimeType,className:"h-5 w-5"})})}),e.jsxs(Y,{className:"max-w-[200px]",children:[i&&e.jsx("span",{className:"text-muted-foreground block truncate text-xs",children:i}),e.jsx("span",{className:"block truncate text-sm font-medium",children:a.filename})]}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ks(a.mimeType)})}),e.jsx(Y,{className:"text-right",children:e.jsx("span",{className:"text-muted-foreground text-xs",children:ye(a.size)})}),e.jsx(Y,{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(Y,{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(p=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]",children:p},p)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})}),e.jsx(Y,{className:"hidden md:table-cell",children:e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})}),e.jsx(Y,{onPointerDown:p=>p.stopPropagation(),onClick:p=>p.stopPropagation(),children:e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")},children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})})]})}function Ts({items:a,host:t,onSelect:s,selectedIds:l,onToggle:n,onToggleAll:i,allSelected:d,onLightbox:h,folderMap:o}){return e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ys,{children:[e.jsx(bs,{children:e.jsxs(ut,{children:[e.jsx(X,{className:"w-10",children:e.jsx(Ie,{checked:d,onCheckedChange:i,"aria-label":"Select all"})}),e.jsx(X,{className:"w-6 hidden md:table-cell"}),e.jsx(X,{className:"w-12"}),e.jsx(X,{children:"Filename"}),e.jsx(X,{className:"w-20 hidden md:table-cell",children:"Type"}),e.jsx(X,{className:"w-24 text-right",children:"Size"}),e.jsx(X,{className:"w-28 hidden lg:table-cell",children:"Dimensions"}),e.jsx(X,{className:"w-40 hidden lg:table-cell",children:"Tags"}),e.jsx(X,{className:"w-32 hidden md:table-cell",children:"Uploaded"}),e.jsx(X,{className:"w-10"})]})}),e.jsx(Cs,{children:a.map(r=>e.jsx(Ss,{item:r,host:t,selected:l.has(r.mediaId),onToggle:()=>n(r.mediaId),onSelect:()=>s(r),folderName:o?.get(r.folderId??""),onLightbox:h&&r.mimeType.startsWith("image/")&&r.mimeType!=="image/svg+xml"?()=>h(r):void 0},r.mediaId))})]})})}var Is=Object.defineProperty,Ms=(a,t,s)=>t in a?Is(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>Ms(a,typeof t!="symbol"?t+"":t,s);const Te={x:0,y:0,width:0,height:0,unit:"px"},re=(a,t,s)=>Math.min(Math.max(a,t),s),Rs=(...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 ie(a,t,s){return a.unit==="%"?{...Te,...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"?{...Te,...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}:{...Te,...a,unit:"px"}}function lt(a,t,s,l,n,i=0,d=0,h=l,o=n){const r={...a};let x=Math.min(i,l),p=Math.min(d,n),f=Math.min(h,l),c=Math.min(o,n);t&&(t>1?(x=d?d*t:x,p=x/t,f=h*t):(p=i?i/t:p,x=p*t,c=o/t)),r.y<0&&(r.height=Math.max(r.height+r.y,p),r.y=0),r.x<0&&(r.width=Math.max(r.width+r.x,x),r.x=0);const b=l-(r.x+r.width);b<0&&(r.x=Math.min(r.x,l-x),r.width+=b);const m=n-(r.y+r.height);if(m<0&&(r.y=Math.min(r.y,n-p),r.height+=m),r.width<x&&((s==="sw"||s=="nw")&&(r.x-=x-r.width),r.width=x),r.height<p&&((s==="nw"||s=="ne")&&(r.y-=p-r.height),r.height=p),r.width>f&&((s==="sw"||s=="nw")&&(r.x-=f-r.width),r.width=f),r.height>c&&((s==="nw"||s=="ne")&&(r.y-=c-r.height),r.height=c),t){const N=r.width/r.height;if(N<t){const w=Math.max(r.width/t,p);(s==="nw"||s=="ne")&&(r.y-=w-r.height),r.height=w}else if(N>t){const w=Math.max(r.height*t,x);(s==="sw"||s=="nw")&&(r.x-=w-r.width),r.width=w}}return r}function _s(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 le={capture:!0,passive:!1};let As=0;const Z=class U extends g.PureComponent{constructor(){super(...arguments),_(this,"docMoveBound",!1),_(this,"mouseDownOnCrop",!1),_(this,"dragStarted",!1),_(this,"evData",{startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0}),_(this,"componentRef",g.createRef()),_(this,"mediaRef",g.createRef()),_(this,"resizeObserver"),_(this,"initChangeCalled",!1),_(this,"instanceId",`rc-${As++}`),_(this,"state",{cropIsActive:!1,newCropIsBeingDrawn:!1}),_(this,"onCropPointerDown",t=>{const{crop:s,disabled:l}=this.props,n=this.getBox();if(!s)return;const i=G(s,n.width,n.height);if(l)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const d=t.target.dataset.ord,h=!!d;let o=t.clientX,r=t.clientY,x=i.x,p=i.y;if(d){const f=t.clientX-n.x,c=t.clientY-n.y;let b=0,m=0;d==="ne"||d=="e"?(b=f-(i.x+i.width),m=c-i.y,x=i.x,p=i.y+i.height):d==="se"||d==="s"?(b=f-(i.x+i.width),m=c-(i.y+i.height),x=i.x,p=i.y):d==="sw"||d=="w"?(b=f-i.x,m=c-(i.y+i.height),x=i.x+i.width,p=i.y):(d==="nw"||d=="n")&&(b=f-i.x,m=c-i.y,x=i.x+i.width,p=i.y+i.height),o=x+n.x+b,r=p+n.y+m}this.evData={startClientX:o,startClientY:r,startCropX:x,startCropY:p,clientX:t.clientX,clientY:t.clientY,isResize:h,ord:d},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})}),_(this,"onComponentPointerDown",t=>{const{crop:s,disabled:l,locked:n,keepSelection:i,onChange:d}=this.props,h=this.getBox();if(l||n||i&&s)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const o=t.clientX-h.x,r=t.clientY-h.y,x={unit:"px",x:o,y:r,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:o,startCropY:r,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,d(G(x,h.width,h.height),ie(x,h.width,h.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})}),_(this,"onDocPointerMove",t=>{const{crop:s,disabled:l,onChange:n,onDragStart:i}=this.props,d=this.getBox();if(l||!s||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,i&&i(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,d.width,d.height),ie(o,d.width,d.height))}),_(this,"onComponentKeyDown",t=>{const{crop:s,disabled:l,onChange:n,onComplete:i}=this.props;if(l)return;const d=t.key;let h=!1;if(!s)return;const o=this.getBox(),r=this.makePixelCrop(o),x=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep;if(d==="ArrowLeft"?(r.x-=x,h=!0):d==="ArrowRight"?(r.x+=x,h=!0):d==="ArrowUp"?(r.y-=x,h=!0):d==="ArrowDown"&&(r.y+=x,h=!0),h){t.cancelable&&t.preventDefault(),r.x=re(r.x,0,o.width-r.width),r.y=re(r.y,0,o.height-r.height);const p=G(r,o.width,o.height),f=ie(r,o.width,o.height);n(p,f),i&&i(p,f)}}),_(this,"onHandlerKeyDown",(t,s)=>{const{aspect:l=0,crop:n,disabled:i,minWidth:d=0,minHeight:h=0,maxWidth:o,maxHeight:r,onChange:x,onComplete:p}=this.props,f=this.getBox();if(i||!n)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const c=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?U.nudgeStepLarge:t.shiftKey?U.nudgeStepMedium:U.nudgeStep,b=G(n,f.width,f.height),m=_s(b,t.key,c,s),N=lt(m,l,s,f.width,f.height,d,h,o,r);if(!it(n,N)){const w=ie(N,f.width,f.height);x(N,w),p&&p(N,w)}}),_(this,"onDocPointerDone",t=>{const{crop:s,disabled:l,onComplete:n,onDragEnd:i}=this.props,d=this.getBox();this.unbindDocMove(),!(l||!s)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,i&&i(t),n&&n(G(s,d.width,d.height),ie(s,d.width,d.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))}),_(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:i}=t.getBoundingClientRect();return{x:s,y:l,width:n,height:i}}componentDidUpdate(t){const{crop:s,onComplete:l}=this.props;if(l&&!t.crop&&s){const{width:n,height:i}=this.getBox();n&&i&&l(G(s,n,i),ie(s,n,i))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,le),this.document.addEventListener("pointerup",this.onDocPointerDone,le),this.document.addEventListener("pointercancel",this.onDocPointerDone,le),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,le),this.document.removeEventListener("pointerup",this.onDocPointerDone,le),this.document.removeEventListener("pointercancel",this.onDocPointerDone,le),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,i=t.clientY-t.startClientY;return l.x=re(t.startCropX+n,0,s.width-l.width),l.y=re(t.startCropY+i,0,s.height-l.height),l}getPointRegion(t,s,l,n){const{evData:i}=this,d=i.clientX-t.x,h=i.clientY-t.y;let o;n&&s?o=s==="nw"||s==="n"||s==="ne":o=h<i.startCropY;let r;return l&&s?r=s==="nw"||s==="w"||s==="sw":r=d<i.startCropX,r?o?"nw":"sw":o?"ne":"se"}resolveMinDimensions(t,s,l=0,n=0){const i=Math.min(l,t.width),d=Math.min(n,t.height);return!s||!i&&!d?[i,d]:s>1?i?[i,i/s]:[d*s,d]:d?[d*s,d]:[i,i/s]}resizeCrop(){const{evData:t}=this,{aspect:s=0,maxWidth:l,maxHeight:n}=this.props,i=this.getBox(),[d,h]=this.resolveMinDimensions(i,s,this.props.minWidth,this.props.minHeight);let o=this.makePixelCrop(i);const r=this.getPointRegion(i,t.ord,d,h),x=t.ord||r;let p=t.clientX-t.startClientX,f=t.clientY-t.startClientY;(d&&x==="nw"||x==="w"||x==="sw")&&(p=Math.min(p,-d)),(h&&x==="nw"||x==="n"||x==="ne")&&(f=Math.min(f,-h));const c={unit:"px",x:0,y:0,width:0,height:0};r==="ne"?(c.x=t.startCropX,c.width=p,s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY-c.height)):r==="se"?(c.x=t.startCropX,c.y=t.startCropY,c.width=p,s?c.height=c.width/s:c.height=f):r==="sw"?(c.x=t.startCropX+p,c.y=t.startCropY,c.width=Math.abs(p),s?c.height=c.width/s:c.height=f):r==="nw"&&(c.x=t.startCropX+p,c.width=Math.abs(p),s?(c.height=c.width/s,c.y=t.startCropY-c.height):(c.height=Math.abs(f),c.y=t.startCropY+f));const b=lt(c,s,r,i.width,i.height,d,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=re(o.x,0,i.width-o.width),o.y=re(o.y,0,i.height-o.height),o}renderCropSelection(){const{ariaLabels:t=U.defaultProps.ariaLabels,disabled:s,locked:l,renderSelectionAddon:n,ruleOfThirds:i,crop:d}=this.props,h=this.getCropStyle();if(d)return T.createElement("div",{style:h,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!s&&!l&&T.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},T.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),T.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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"}),T.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&&T.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:o=>o.stopPropagation()},n(this.state)),i&&T.createElement(T.Fragment,null,T.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),T.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const s={...Te,...this.props.crop||{}};return G(s,t.width,t.height)}render(){const{aspect:t,children:s,circularCrop:l,className:n,crop:i,disabled:d,locked:h,style:o,ruleOfThirds:r}=this.props,{cropIsActive:x,newCropIsBeingDrawn:p}=this.state,f=i?this.renderCropSelection():null,c=Rs("ReactCrop",n,x&&"ReactCrop--active",d&&"ReactCrop--disabled",h&&"ReactCrop--locked",p&&"ReactCrop--new-crop",i&&t&&"ReactCrop--fixed-aspect",i&&l&&"ReactCrop--circular-crop",i&&r&&"ReactCrop--rule-of-thirds",!this.dragStarted&&i&&!i.width&&!i.height&&"ReactCrop--invisible-crop",l&&"ReactCrop--no-animate");return T.createElement("div",{ref:this.componentRef,className:c,style:o},T.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},s),i?T.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},T.createElement("defs",null,T.createElement("mask",{id:`hole-${this.instanceId}`},T.createElement("rect",{width:"100%",height:"100%",fill:"white"}),l?T.createElement("ellipse",{cx:`${i.x+i.width/2}${i.unit}`,cy:`${i.y+i.height/2}${i.unit}`,rx:`${i.width/2}${i.unit}`,ry:`${i.height/2}${i.unit}`,fill:"black"}):T.createElement("rect",{x:`${i.x}${i.unit}`,y:`${i.y}${i.unit}`,width:`${i.width}${i.unit}`,height:`${i.height}${i.unit}`,fill:"black"}))),T.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,f)}};_(Z,"xOrds",["e","w"]),_(Z,"yOrds",["n","s"]),_(Z,"xyOrds",["nw","ne","se","sw"]),_(Z,"nudgeStep",1),_(Z,"nudgeStepMedium",10),_(Z,"nudgeStepLarge",100),_(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 Es=Z;const Fs=[{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"}],mt=[{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"}],zs={"image/jpeg":".jpg","image/png":".png","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/tiff":".tiff"};function ze(a,t){return a?mt.find(s=>s.value===a)?.ext||`.${a}`:zs[t]||".jpg"}function $s(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ps({host:a,media:t,onClose:s,onSaved:l}){const n=g.useRef(null),[i,d]=g.useState(),[h,o]=g.useState(),[r,x]=g.useState(""),[p,f]=g.useState(""),[c,b]=g.useState(""),[m,N]=g.useState(""),[w,S]=g.useState("80"),[R,A]=g.useState(()=>{const y=ze("",t.mimeType),M=t.filename.lastIndexOf(".");return`${M>0?t.filename.substring(0,M):t.filename}-transformed${y}`});function F(y){const M=y==="__original__"?"":y;N(M);const q=ze(M,t.mimeType);A(ae=>$s(ae,q))}const z=Tt(a,t.mediaId),[j,v]=g.useState(null),$=g.useCallback(()=>{if(!h||!j)return null;const y=(t.width??j.width)/j.width,M=(t.height??j.height)/j.height;return{cropX:Math.round(h.x*y),cropY:Math.round(h.y*M),cropW:Math.round(h.width*y),cropH:Math.round(h.height*M)}},[h,t.width,t.height,j]),B=g.useMemo(()=>$(),[$]);async function se(){const y=B,M=p?parseInt(p):void 0,q=c?parseInt(c):void 0;if(!y&&!M&&!q&&!m){I.error("Please specify a crop, resize, or format change");return}if(!R.trim()){I.error("Filename is required");return}const ae=ze(m,t.mimeType);if(!R.trim().toLowerCase().endsWith(ae)){I.error(`Filename must end with ${ae} to match the output format`);return}try{const ne=await z.mutateAsync({...y??{},...M?{width:M}:{},...q?{height:q}:{},...m?{format:m}:{},...w?{quality:parseInt(w)}:{},filename:R.trim()});I.success("Transform saved as new media"),l?.(ne),s()}catch(ne){I.error("Transform failed",{description:ne instanceof Error?ne.message:void 0})}}function xe(y){x(y==="__free__"?"":y),d(void 0),o(void 0)}function V(y){if(!y)return;const M=y.split("/");return M.length===2?Number(M[0])/Number(M[1]):Number(y)||void 0}const Ge=V(r);return e.jsx(oe,{open:!0,onOpenChange:()=>s(),children:e.jsxs(ce,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(de,{children:[e.jsx(he,{children:"Transform Image"}),e.jsx(ue,{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(Es,{crop:i,onChange:y=>d(y),onComplete:y=>o(y),aspect:Ge,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:y=>{const M=y.currentTarget;v({width:M.naturalWidth,height:M.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(L,{children:"Crop aspect ratio"}),e.jsxs(fe,{value:r||"__free__",onValueChange:xe,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Free"})}),e.jsx(ve,{children:Fs.map(y=>e.jsx(te,{value:y.value||"__free__",children:y.label},y.value||"__free__"))})]}),h&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Crop: ",B?.cropW,"×",B?.cropH," at (",B?.cropX,", ",B?.cropY,")"]}),h&&e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{d(void 0),o(void 0)},children:"Clear crop"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Resize (optional)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Width",value:p,onChange:y=>f(y.target.value),min:1,max:2048})}),e.jsx("div",{children:e.jsx(K,{type:"number",placeholder:"Height",value:c,onChange:y=>b(y.target.value),min:1,max:2048})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Output format"}),e.jsxs(fe,{value:m||"__original__",onValueChange:F,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Original"})}),e.jsx(ve,{children:mt.map(y=>e.jsx(te,{value:y.value||"__original__",children:y.label},y.value||"__original__"))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Quality (1-100)"}),e.jsx(K,{type:"number",value:w,onChange:y=>S(y.target.value),min:1,max:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Save as filename"}),e.jsx(K,{value:R,onChange:y=>A(y.target.value)})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsxs(D,{onClick:se,disabled:z.isPending,children:[z.isPending&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Save as New Image"]})]})]})})}const Os=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Us({host:a,media:t,onClose:s,onDeleted:l,folders:n,tagSuggestions:i}){const[d,h]=g.useState(t.alt??""),[o,r]=g.useState(t.caption??""),[x,p]=g.useState(t.userTags??[]),[f,c]=g.useState(t.folderId||"__none__"),[b,m]=g.useState(!1),N=Os.has(t.mimeType),w=It(a,t.mediaId),S=Mt(a,t.mediaId),{data:R,isLoading:A}=Rt(a,t.mediaId),F=t.tags.filter(v=>!t.userTags?.includes(v));async function z(){try{await w.mutateAsync({alt:d,caption:o,userTags:x,folderId:f==="__none__"?"":f}),I.success("Media updated"),s()}catch(v){I.error("Failed to update",{description:v instanceof Error?v.message:void 0})}}async function j(){try{await S.mutateAsync(),I.success("Media deleted"),l?.(t.mediaId),s()}catch(v){I.error("Failed to delete",{description:v instanceof Error?v.message:void 0})}}return e.jsxs(oe,{open:!0,onOpenChange:()=>s(),children:[e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(he,{children:t.filename}),e.jsx(ue,{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," · ",ye(t.size),t.width&&t.height&&` · ${t.width}×${t.height}`," · ",He(t.uploadedAt)]}),e.jsxs("div",{className:"flex gap-2",children:[N&&e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Bt,{className:"mr-1.5 h-3.5 w-3.5"}),"Transform"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(W(t.url)),I.success("URL copied to clipboard")},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),"Copy URL"]})]})]}),F.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Auto-detected tags"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:F.map(v=>e.jsx(Ue,{variant:"outline",className:"text-xs",children:v},v))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Tags"}),e.jsx(Pe,{tags:x,onChange:p,placeholder:"Add tags...",suggestions:i})]}),n&&n.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Folder"}),e.jsxs(fe,{value:f,onValueChange:c,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"No folder"})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__none__",children:"No folder"}),n.map(v=>e.jsx(te,{value:v.folderId,children:v.name},v.folderId))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"alt",children:"Alt text"}),e.jsx(K,{id:"alt",value:d,onChange:v=>h(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"caption",children:"Caption"}),e.jsx(K,{id:"caption",value:o,onChange:v=>r(v.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{className:"text-xs text-muted-foreground",children:"Used in"}),A?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(J,{className:"h-3.5 w-3.5 animate-spin"}),"Checking usage..."]}):R?.references.length?e.jsxs("div",{className:"space-y-1",children:[R.references.map(v=>e.jsxs(Dt,{to:`/sites/${a}/content/${v.collection}/${v.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:v.title||v.contentId}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",v.collection,")"]})]},v.contentId)),R.note&&e.jsx("p",{className:"text-muted-foreground text-xs italic",children:R.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(Xe,{children:[e.jsx(Ns,{asChild:!0,children:e.jsxs(D,{variant:"destructive",size:"sm",children:[e.jsx(Kt,{className:"mr-2 h-4 w-4"}),"Delete"]})}),e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete media?"}),e.jsxs(We,{children:["This will permanently delete “",t.filename,"”. This action cannot be undone."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"outline",onClick:s,children:"Cancel"}),e.jsx(D,{onClick:z,children:"Save"})]})]})]}),b&&e.jsx(Ps,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ls({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(Ue,{variant:t===l?"default":"secondary",className:"cursor-pointer select-none",onClick:()=>s(t===l?void 0:l),children:l},l)),t&&e.jsxs(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>s(void 0),children:[e.jsx(ge,{className:"mr-1 h-3 w-3"}),"Clear"]})]})}function $e({id:a,children:t}){const{setNodeRef:s,isOver:l}=ps({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=_t(a),i=At(a),d=Et(a),[h,o]=g.useState(!1),[r,x]=g.useState(""),[p,f]=g.useState(null),[c,b]=g.useState(""),[m,N]=g.useState(null),w=g.useRef(null),S=g.useRef(null),R=l?.items??[];g.useEffect(()=>{h&&w.current?.focus()},[h]),g.useEffect(()=>{p&&S.current?.focus()},[p]);async function A(){const j=r.trim();if(!j){o(!1),x("");return}try{await n.mutateAsync(j),I.success("Folder created")}catch(v){I.error("Failed to create folder",{description:v instanceof Error?v.message:void 0})}o(!1),x("")}async function F(j){const v=c.trim();if(!v){f(null);return}try{await i.mutateAsync({folderId:j,name:v}),I.success("Folder renamed")}catch($){I.error("Failed to rename folder",{description:$ instanceof Error?$.message:void 0})}f(null)}async function z(){if(m){try{await d.mutateAsync(m.folderId),I.success("Folder deleted"),t===m.folderId&&s(null)}catch(j){I.error("Failed to delete folder",{description:j instanceof Error?j.message:void 0})}N(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(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>o(!0),children:e.jsx(Wt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[e.jsx($e,{id:"all-media",children:j=>e.jsx("button",{className:P("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",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s(null),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"All Media"]})})}),R.map(j=>e.jsx($e,{id:j.folderId,children:v=>e.jsx("div",{className:P("group flex w-full items-center justify-between px-3 py-1.5 text-sm hover:bg-accent/50",t===j.folderId&&"bg-accent font-medium",v&&"ring-2 ring-primary bg-primary/10"),children:p===j.folderId?e.jsx(K,{ref:S,value:c,onChange:$=>b($.target.value),onKeyDown:$=>{$.key==="Enter"&&F(j.folderId),$.key==="Escape"&&f(null)},onBlur:()=>F(j.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(j.folderId),children:[e.jsx(ee,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:j.name})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:j.count}),e.jsxs(Vt,{children:[e.jsx(qt,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 group-hover:opacity-100",children:e.jsx(Qt,{className:"h-3.5 w-3.5"})})}),e.jsxs(Gt,{align:"end",children:[e.jsx(nt,{onClick:()=>{f(j.folderId),b(j.name)},children:"Rename"}),e.jsx(nt,{disabled:j.count>0,onClick:()=>N(j),children:"Delete"})]})]})]})]})})},j.folderId)),e.jsx($e,{id:"unfiled",children:j=>e.jsx("button",{className:P("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",j&&"ring-2 ring-primary bg-primary/10"),onClick:()=>s("unfiled"),children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Unfiled"]})})}),h&&e.jsx("div",{className:"px-3 py-1.5",children:e.jsx(K,{ref:w,value:r,onChange:j=>x(j.target.value),onKeyDown:j=>{j.key==="Enter"&&A(),j.key==="Escape"&&(o(!1),x(""))},onBlur:A,placeholder:"Folder name...",className:"h-7 text-sm"})})]}),e.jsx(Xe,{open:!!m,onOpenChange:()=>N(null),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Delete folder?"}),e.jsxs(We,{children:["This will delete the folder “",m?.name,"”. Media items in this folder will become unfiled."]})]}),e.jsxs(Ve,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Qe,{onClick:z,children:"Delete"})]})]})})]})}function Hs({selectedCount:a,folders:t,onDelete:s,onMove:l,onAddTags:n,onRemoveTags:i,onClear:d,isPending:h}){const[o,r]=g.useState(null),[x,p]=g.useState(""),[f,c]=g.useState([]);function b(){r(null),p(""),c([])}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(D,{size:"sm",variant:"ghost",onClick:d,disabled:h,children:e.jsx(ge,{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(D,{size:"sm",variant:"destructive",onClick:()=>r("delete"),disabled:h,className:"shrink-0",children:"Delete"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("move"),disabled:h,className:"shrink-0",children:"Move to…"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("addTags"),disabled:h,className:"shrink-0",children:"Add tags"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>r("removeTags"),disabled:h,className:"shrink-0",children:"Remove tags"})]})]}),e.jsx(oe,{open:o==="delete",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Delete ",a," item",a!==1?"s":"","?"]}),e.jsx(ue,{children:"This action cannot be undone. The selected media items will be permanently deleted."})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{variant:"destructive",onClick:async()=>{b(),await s()},disabled:h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Delete"]})]})]})}),e.jsx(oe,{open:o==="move",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Move ",a," item",a!==1?"s":""]}),e.jsx(ue,{children:"Choose a destination folder."})]}),e.jsxs(fe,{value:x,onValueChange:p,children:[e.jsx(we,{children:e.jsx(je,{placeholder:"Select folder..."})}),e.jsxs(ve,{children:[e.jsx(te,{value:"__unfiled__",children:"Unfiled"}),t.map(m=>e.jsx(te,{value:m.folderId,children:m.name},m.folderId))]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=x==="__unfiled__"?"":x;b(),await l(m)},disabled:!x||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Move"]})]})]})}),e.jsx(oe,{open:o==="addTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Add tags to ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to add to the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Add tags..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await n(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Add"]})]})]})}),e.jsx(oe,{open:o==="removeTags",onOpenChange:m=>!m&&b(),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsxs(he,{children:["Remove tags from ",a," item",a!==1?"s":""]}),e.jsx(ue,{className:"sr-only",children:"Select tags to remove from the selected items"})]}),e.jsx(Pe,{tags:f,onChange:c,placeholder:"Tags to remove..."}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(D,{onClick:async()=>{const m=[...f];b(),await i(m)},disabled:f.length===0||h,children:[h&&e.jsx(J,{className:"mr-1 h-3 w-3 animate-spin"}),"Remove"]})]})]})})]})}function Xs({onFiles:a,children:t}){const[s,l]=g.useState(!1),n=g.useRef(0),i=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.types.includes("Files")&&(n.current++,l(!0))},[]),d=g.useCallback(r=>{r.preventDefault(),n.current--,n.current===0&&l(!1)},[]),h=g.useCallback(r=>{r.preventDefault(),r.dataTransfer.dropEffect="copy"},[]),o=g.useCallback(r=>{r.preventDefault(),n.current=0,l(!1);const x=Array.from(r.dataTransfer.files);x.length>0&&a(x)},[a]);return e.jsxs("div",{className:"relative flex-1",onDragEnter:i,onDragLeave:d,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(pe,{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 Ys({queue:a}){const{items:t,retry:s,dismiss:l,clearCompleted:n}=a,[i,d]=g.useState(!1),h=t.filter(c=>c.status==="uploading").length,o=t.filter(c=>c.status==="pending").length,r=t.filter(c=>c.status==="complete").length,x=t.filter(c=>c.status==="error").length,p=h===0&&o===0;if(g.useEffect(()=>{if(p&&t.length>0){const c=setTimeout(()=>d(!0),2e3);return()=>clearTimeout(c)}},[p,t.length]),t.length===0)return null;const f=p?`${r} 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:f}),e.jsxs("div",{className:"flex items-center gap-1",children:[p&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:n,children:"Clear"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(!i),children:i?e.jsx(Zt,{className:"h-4 w-4"}):e.jsx(Jt,{className:"h-4 w-4"})})]})]}),!i&&e.jsx("div",{className:"max-h-60 overflow-y-auto",children:t.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-sm",children:[c.status==="uploading"&&e.jsx(J,{className:"h-4 w-4 shrink-0 animate-spin"}),c.status==="complete"&&e.jsx(es,{className:"h-4 w-4 shrink-0 text-green-500"}),c.status==="error"&&e.jsx(ge,{className:"h-4 w-4 shrink-0 text-destructive"}),c.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:c.file.name}),c.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:`${c.progress}%`}})}),c.status==="error"&&e.jsx("p",{className:"text-destructive truncate text-xs",children:c.error})]}),c.status==="error"&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>s(c.id),children:e.jsx(ts,{className:"h-3 w-3"})}),(c.status==="complete"||c.status==="error")&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 shrink-0 p-0",onClick:()=>l(c.id),children:e.jsx(ge,{className:"h-3 w-3"})})]},c.id))})]})}const Bs=3;let Ks=0;function Ws(a,t){const[s,l]=g.useState([]),n=Ft(a),i=zt(a),d=g.useRef(0),h=g.useRef(s);h.current=s;const o=g.useRef(new Map),r=g.useCallback(async m=>{d.current++,l(N=>N.map(w=>w.id===m.id?{...w,status:"uploading",progress:0}:w));try{const{uploadUrl:N,mediaId:w}=await n.mutateAsync({filename:m.file.name,contentType:m.file.type,size:m.file.size});await new Promise((S,R)=>{const A=new XMLHttpRequest;o.current.set(m.id,A),A.upload.onprogress=F=>{if(F.lengthComputable){const z=Math.round(F.loaded/F.total*100);l(j=>j.map(v=>v.id===m.id?{...v,progress:z}:v))}},A.onload=()=>{o.current.delete(m.id),A.status>=200&&A.status<300?S():R(new Error(`Upload failed: ${A.status}`))},A.onerror=()=>{o.current.delete(m.id),R(new Error("Network error"))},A.onabort=()=>{o.current.delete(m.id),R(new Error("Upload aborted"))},A.open("PUT",N),A.setRequestHeader("Content-Type",m.file.type),A.send(m.file)}),await i.mutateAsync({mediaId:w,filename:m.file.name,folderId:m.folderId}),l(S=>S.map(R=>R.id===m.id?{...R,status:"complete",progress:100}:R))}catch(N){l(w=>w.map(S=>S.id===m.id?{...S,status:"error",error:N instanceof Error?N.message:"Upload failed"}:S))}finally{d.current--}},[n,i]),x=g.useRef(r);x.current=r,g.useEffect(()=>{const m=s.filter(w=>w.status==="pending"),N=Bs-d.current;for(let w=0;w<Math.min(m.length,N);w++)x.current(m[w])},[s]),g.useEffect(()=>{const m=o.current;return()=>{m.forEach(N=>N.abort())}},[]);const p=g.useCallback(m=>{const N=Array.from(m).map(w=>({id:`upload-${Ks++}`,file:w,folderId:t||void 0,status:"pending",progress:0}));l(w=>[...w,...N])},[t]),f=g.useCallback(m=>{l(N=>N.map(w=>w.id===m?{...w,status:"pending",progress:0,error:void 0}:w))},[]),c=g.useCallback(m=>{l(N=>N.filter(w=>w.id!==m))},[]),b=g.useCallback(()=>{l(m=>m.filter(N=>N.status!=="complete"&&N.status!=="error"))},[]);return{items:s,addFiles:p,retry:f,dismiss:c,clearCompleted:b}}function Vs({items:a,currentIndex:t,onClose:s,onNavigate:l}){const n=a[t],i=t>0,d=t<a.length-1,h=g.useRef(null),o=g.useCallback(r=>{r.key==="Escape"?s():r.key==="ArrowLeft"&&i?l(t-1):r.key==="ArrowRight"&&d&&l(t+1)},[s,l,t,i,d]);return g.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 pt-[max(0.75rem,env(safe-area-inset-top,0px))] pl-[max(1rem,env(safe-area-inset-left,0px))] pr-[max(1rem,env(safe-area-inset-right,0px))] text-white",onClick:r=>r.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} · `,ye(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(D,{variant:"ghost",size:"icon",className:"text-white hover:bg-white/20",onClick:s,children:e.jsx(ge,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center px-4 md:px-16",onClick:r=>r.stopPropagation(),onTouchStart:r=>{h.current=r.touches[0].clientX},onTouchEnd:r=>{if(h.current===null)return;const x=r.changedTouches[0].clientX-h.current;h.current=null,x>50&&i?l(t-1):x<-50&&d&&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"}),i&&e.jsx(D,{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(ss,{className:"h-8 w-8"})}),d&&e.jsx(D,{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(as,{className:"h-8 w-8"})})]})]}):null}function qs({open:a,duplicates:t,fileCount:s,onContinue:l,onCancel:n}){return e.jsx(Xe,{open:a,onOpenChange:i=>!i&&n(),children:e.jsxs(Ye,{children:[e.jsxs(Be,{children:[e.jsx(Ke,{children:"Possible duplicates found"}),e.jsx(We,{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(i=>e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[i.mimeType.startsWith("image/")&&i.mimeType!=="image/svg+xml"?e.jsx("img",{src:W(i.urls?.thumb_sm??i.url),alt:i.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(Me,{mimeType:i.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:i.filename}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[ye(i.size)," ·"," ",Le(i.uploadedAt)]})]})]},i.mediaId))}),e.jsxs(Ve,{children:[e.jsx(qe,{onClick:n,children:"Cancel"}),e.jsx(Qe,{onClick:l,children:"Upload Anyway"})]})]})})}const Qs=({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},Gs=[{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 Zs({item:a,selected:t,onToggle:s,onClick:l,folderName:n,onLightbox:i}){const{attributes:d,listeners:h,setNodeRef:o,isDragging:r}=ht({id:a.mediaId,data:{type:"media",mediaId:a.mediaId}}),x=a.mimeType.startsWith("image/")&&a.mimeType!=="image/svg+xml";function p(f){f.stopPropagation(),navigator.clipboard.writeText(W(a.url)),I.success("URL copied to clipboard")}return e.jsx(ms,{ref:o,...d,...h,className:P("group relative cursor-pointer overflow-hidden",r&&"opacity-50",t&&"ring-2 ring-primary"),onClick:l,children:e.jsxs(xs,{className:"p-0",children:[e.jsx("div",{className:P("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:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:e.jsx(Ie,{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:f=>f.stopPropagation(),onClick:f=>f.stopPropagation(),children:[e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:p,children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})}),e.jsx(Se,{children:"Copy URL"})]})}),x&&i&&e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{className:"rounded bg-black/50 p-1 text-white hover:bg-black/70",onClick:f=>{f.stopPropagation(),i()},children:e.jsx(us,{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(Me,{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(ee,{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:ye(a.size)}),e.jsx(Ne,{children:e.jsxs(De,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("span",{className:"text-muted-foreground text-xs",children:Le(a.uploadedAt)})}),e.jsx(Se,{children:He(a.uploadedAt)})]})})]}),a.tags.length>0&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[a.tags.slice(0,3).map(f=>e.jsx("span",{className:"bg-muted text-muted-foreground rounded px-1 py-0.5 text-[10px]",children:f},f)),a.tags.length>3&&e.jsxs("span",{className:"text-muted-foreground text-[10px]",children:["+",a.tags.length-3]})]})]})]})})}function xa(){const{host:a}=kt(),t=ns(),[s,l]=St([{key:"tag",defaultValue:""},{key:"folder",defaultValue:""},{key:"q",defaultValue:""},{key:"sort",defaultValue:"date_desc"},{key:"view",defaultValue:"grid"}]),n=s.view,i=u=>l({view:u}),d=s.sort,h=u=>l({sort:u}),o=s.tag||void 0,r=s.folder===""?null:s.folder,x=u=>l({folder:u??""}),[p,f]=g.useState(s.q),[c,b]=g.useState(s.q),[m,N]=g.useState(null),[w,S]=g.useState(new Set),[R,A]=g.useState(null),[F,z]=g.useState(null),[j,v]=g.useState(null),[$,B]=g.useState([]),[se,xe]=g.useState(!1),V=g.useRef(null);Ds({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Ws(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=gs(fs(vs,{activationConstraint:{distance:t?1e5:8}}));g.useEffect(()=>{const u=setTimeout(()=>{b(C=>{const k=p;return C!==k&&(S(new Set),l({q:k})),k})},300);return()=>clearTimeout(u)},[p,l]);const ne=r===null?void 0:r==="unfiled"?"":r,{data:O,isLoading:xt}=Ot(a,{sort:d,q:c||void 0,folderId:ne,tag:o}),{data:Ze}=ct(a),be=g.useMemo(()=>Ze?.items??[],[Ze?.items]),Re=g.useMemo(()=>{const u=new Map;for(const C of be)u.set(C.folderId,C.name);return u},[be]),Ce=g.useMemo(()=>(O?.items??[]).filter(u=>u.mimeType.startsWith("image/")&&u.mimeType!=="image/svg+xml"),[O?.items]),_e=g.useMemo(()=>{const u=new Map;return Ce.forEach((C,k)=>u.set(C.mediaId,k)),u},[Ce]),{allTags:pt,allUserTags:gt}=g.useMemo(()=>{const u=O?.items??[],C=new Set,k=new Set;for(const E of u){for(const H of E.tags)C.add(H);for(const H of E.userTags??[])k.add(H)}return{allTags:Array.from(C).sort(),allUserTags:Array.from(k).sort()}},[O?.items]),Ae=O?.items.map(u=>u.mediaId)??[],Ee=Ae.length>0&&Ae.every(u=>w.has(u));function Je(u){S(C=>{const k=new Set(C);return k.has(u)?k.delete(u):k.add(u),k})}function et(){S(Ee?new Set:new Set(Ae))}async function ft(){const u=[...w],k=(await M.mutateAsync({mediaIds:u,action:"delete"})).failed.length;k?I.error(`${k} of ${u.length} failed to delete`):I.success(`${u.length} item(s) deleted`),S(new Set)}async function wt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"move",folderId:u})).failed.length;E?I.error(`${E} of ${C.length} failed to move`):I.success(`${C.length} item(s) moved`),S(new Set)}async function jt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"addTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags added to ${C.length} item(s)`),S(new Set)}async function vt(u){const C=[...w],E=(await M.mutateAsync({mediaIds:C,action:"removeTags",tags:u})).failed.length;E?I.error(`${E} of ${C.length} failed`):I.success(`Tags removed from ${C.length} item(s)`),S(new Set)}async function tt(u){const C=Array.from(u),k=C.slice(0,5),E=[];for(const H of k)try{const Fe=await q.mutateAsync({filename:H.name,size:H.size});E.push(...Fe.duplicates)}catch{}E.length>0?(v(C),B(E)):y.addFiles(C)}function yt(u){u.target.files&&tt(u.target.files),V.current&&(V.current.value="")}function bt(u){A(String(u.active.id))}function Ct(u){A(null);const{active:C,over:k}=u;if(!k||k.data.current?.type!=="folder")return;const E=k.id==="unfiled"||k.id==="all-media"?"":String(k.id),H=w.has(String(C.id))?[...w]:[String(C.id)];M.mutateAsync({mediaIds:H,action:"move",folderId:E}).then(Fe=>{const at=Fe.failed.length;at?I.error(`${at} of ${H.length} failed to move`):I.success(`${H.length} item(s) moved`)})}function Nt(){A(null)}const Q=R?O?.items.find(u=>u.mediaId===R):null,st=R&&w.has(R)?w.size:1;return e.jsxs(ws,{sensors:ae,modifiers:[Qs],onDragStart:bt,onDragEnd:Ct,onDragCancel:Nt,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:r,onSelect:u=>{x(u),S(new Set)}})}),e.jsx(rs,{open:se,onOpenChange:xe,children:e.jsxs(is,{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(ls,{className:"sr-only",children:"Folders"}),e.jsx(ot,{host:a,selectedFolderId:r,onSelect:u=>{x(u),S(new Set),xe(!1)}})]})}),e.jsxs(Xs,{onFiles:u=>tt(u),children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-2 md:p-6",children:[!t&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Media"}),e.jsx("div",{children:e.jsxs(D,{onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})})]}),e.jsx("input",{ref:V,type:"file",multiple:!0,className:"hidden",onChange:yt}),w.size>0?e.jsx(Hs,{selectedCount:w.size,folders:be,onDelete:ft,onMove:wt,onAddTags:jt,onRemoveTags:vt,onClear:()=>S(new Set),isPending:M.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(K,{placeholder:"Search media...",value:p,onChange:u=>f(u.target.value),className:"pl-9"})]}),e.jsxs(fe,{value:d,onValueChange:h,children:[e.jsx(we,{className:"w-[160px]",children:e.jsx(je,{})}),e.jsx(ve,{children:Gs.map(u=>e.jsx(te,{value:u.value,children:u.label},u.value))})]}),e.jsx(D,{variant:se?"secondary":"ghost",size:"sm",className:"md:hidden px-2",onClick:()=>xe(!se),"aria-label":"Toggle folders",children:e.jsx(os,{className:"h-4 w-4"})}),!se&&r!==null&&t&&e.jsxs(Ue,{variant:"secondary",className:"gap-1 md:hidden",children:[e.jsx(ee,{className:"h-3 w-3"}),r==="unfiled"?"Unfiled":Re.get(r)??"All Media"]}),e.jsxs("div",{className:"flex rounded-md border",children:[e.jsx(D,{variant:n==="grid"?"secondary":"ghost",size:"sm",className:"rounded-r-none px-2",onClick:()=>i("grid"),children:e.jsx(cs,{className:"h-4 w-4"})}),e.jsx(D,{variant:n==="list"?"secondary":"ghost",size:"sm",className:"rounded-l-none px-2",onClick:()=>i("list"),children:e.jsx(ds,{className:"h-4 w-4"})})]})]}),e.jsx(Ls,{tags:pt,activeTag:o,onTagChange:u=>{l({tag:u??""}),S(new Set)}}),n==="grid"&&(O?.items.length??0)>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Ie,{checked:Ee,onCheckedChange:et,"aria-label":"Select all"}),e.jsx("span",{className:"text-muted-foreground text-sm",children:w.size>0?`${w.size} of ${O.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 xl:grid-cols-5 2xl:grid-cols-6",children:Array.from({length:8}).map((u,C)=>e.jsx(hs,{className:"aspect-square"},C))}):O?.items.length?n==="list"?e.jsx(Ts,{items:O.items,host:a,onSelect:N,selectedIds:w,onToggle:Je,onToggleAll:et,allSelected:Ee,folderMap:r===null?Re:void 0,onLightbox:u=>{const C=_e.get(u.mediaId);C!==void 0&&z(C)}}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6",children:O.items.map(u=>e.jsx(Zs,{item:u,selected:w.has(u.mediaId),onToggle:()=>Je(u.mediaId),onClick:()=>N(u),folderName:r===null?Re.get(u.folderId??""):void 0,onLightbox:_e.has(u.mediaId)?()=>z(_e.get(u.mediaId)):void 0},u.mediaId))}):e.jsx("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:c||o?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."})]}):r==="unfiled"?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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."})]}):r?e.jsxs(e.Fragment,{children:[e.jsx(ee,{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(pe,{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(D,{className:"mt-4",onClick:()=>V.current?.click(),children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Upload"]})]})}),m&&e.jsx(Us,{host:a,media:m,onClose:()=>N(null),onDeleted:u=>{S(C=>{if(!C.has(u))return C;const k=new Set(C);return k.delete(u),k})},folders:be,tagSuggestions:gt})]}),e.jsx(Ys,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(Vs,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(qs,{open:$.length>0,host:a,duplicates:$,fileCount:j?Array.from(j).length:0,onContinue:()=>{j&&y.addFiles(j),v(null),B([])},onCancel:()=>{v(null),B([])}}),e.jsx(js,{children:R&&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(Me,{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{xa as MediaPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{B as a,ar as m,a0 as o}from"./index-BA3y7HJs.js";import{S as x,a as g,b as h,c as u,d as j}from"./select-dX9e6VDt.js";const p=[10,20,50,100];function S({page:t,hasNext:i,hasPrevious:r,onNext:n,onPrevious:l,perPage:c,onPerPageChange:d}){return e.jsxs("div",{className:"mt-4 flex items-center justify-between","data-testid":"pagination",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Rows per page:"}),e.jsxs(x,{value:String(c),onValueChange:s=>d(Number(s)),children:[e.jsx(g,{className:"w-[70px] h-8","data-testid":"per-page-select",children:e.jsx(h,{})}),e.jsx(u,{children:p.map(s=>e.jsx(j,{value:String(s),children:s},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a,{variant:"outline",size:"sm",onClick:l,disabled:!r,"aria-label":"Previous page",children:[e.jsx(m,{className:"h-4 w-4"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"page-indicator",children:["Page ",t]}),e.jsxs(a,{variant:"outline",size:"sm",onClick:n,disabled:!i,"aria-label":"Next page",children:["Next",e.jsx(o,{className:"h-4 w-4"})]})]})]})}export{S as P};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{B as a,ar as m,a0 as o}from"./index-Ce5pmRMj.js";import{S as x,a as g,b as h,c as u,d as j}from"./select-CrRhFGIi.js";const p=[10,20,50,100];function S({page:t,hasNext:i,hasPrevious:r,onNext:n,onPrevious:l,perPage:c,onPerPageChange:d}){return e.jsxs("div",{className:"mt-4 flex items-center justify-between","data-testid":"pagination",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Rows per page:"}),e.jsxs(x,{value:String(c),onValueChange:s=>d(Number(s)),children:[e.jsx(g,{className:"w-[70px] h-8","data-testid":"per-page-select",children:e.jsx(h,{})}),e.jsx(u,{children:p.map(s=>e.jsx(j,{value:String(s),children:s},s))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a,{variant:"outline",size:"sm",onClick:l,disabled:!r,"aria-label":"Previous page",children:[e.jsx(m,{className:"h-4 w-4"}),"Previous"]}),e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"page-indicator",children:["Page ",t]}),e.jsxs(a,{variant:"outline",size:"sm",onClick:n,disabled:!i,"aria-label":"Next page",children:["Next",e.jsx(o,{className:"h-4 w-4"})]})]})]})}export{S as P};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as f}from"./react-vendor-C2CvUxFh.js";import{b as N,c as y,P as v,D as R,e as P}from"./core.esm-DdQHdRkd.js";import{S as k,v as w,a as D}from"./sortable.esm-qVEMoaTg.js";import{B as p,P as O,ad as h,j as E,X as z}from"./index-BA3y7HJs.js";import{C as B,a as F,b as M,c as T}from"./card-CZTHR2Qa.js";import{S as A,a as b}from"./ContentField-D04Uo1Ov.js";function U({relationships:a,values:s,onChange:c,host:o}){return e.jsxs(B,{children:[e.jsx(F,{children:e.jsx(M,{children:"Relationships"})}),e.jsx(T,{className:"space-y-4",children:a.map(n=>n.multiple?e.jsx(L,{rel:n,items:s[n.name]??[],host:o,onChange:i=>c({...s,[n.name]:i})},n.name):e.jsx(H,{rel:n,value:s[n.name]?.[0]??null,host:o,onChange:i=>c({...s,[n.name]:i?[i]:[]})},n.name))})]})}function H({rel:a,value:s,host:c,onChange:o}){const[n,i]=f.useState(!1),r=s?[s.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:a.label}),s?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:s.title}),e.jsx(E,{variant:"secondary",children:s.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(z,{className:"h-3 w-3"})})]}):e.jsx(b,{host:c,collections:[a.targetCollection],selectedIds:r,open:n,onOpenChange:i,onSelect:d=>{o(d),i(!1)},status:"published",trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(h,{className:"mr-2 h-4 w-4"}),"Select ",a.label]})})]})}function L({rel:a,items:s,host:c,onChange:o}){const n=N(y(v)),[i,r]=f.useState(!1),d=s.map(t=>t.contentId),g=s.map(t=>t.contentId);function S(t){o([...s,t]),r(!1)}function I(t){o(s.filter((m,l)=>l!==t))}function C(t){const{active:m,over:l}=t;if(l&&m.id!==l.id){const j=s.findIndex(x=>x.contentId===String(m.id)),u=s.findIndex(x=>x.contentId===String(l.id));j!==-1&&u!==-1&&o(D(s,j,u))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:a.label}),e.jsx(R,{sensors:n,collisionDetection:P,onDragEnd:C,children:e.jsx(k,{items:d,strategy:w,children:e.jsxs("div",{className:"space-y-2",children:[s.map(t=>e.jsx(A,{id:t.contentId,contentRef:t,onRemove:()=>I(s.indexOf(t))},t.contentId)),e.jsx(b,{host:c,collections:[a.targetCollection],selectedIds:g,open:i,onOpenChange:r,onSelect:S,status:"published",trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(O,{className:"mr-2 h-3 w-3"}),"Add ",a.label]})})]})})})]})}export{U as R};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as f}from"./react-vendor-C2CvUxFh.js";import{b as N,c as y,P as v,D as R,e as P}from"./core.esm-DdQHdRkd.js";import{S as k,v as w,a as D}from"./sortable.esm-qVEMoaTg.js";import{B as p,P as O,ad as h,j as E,X as z}from"./index-Ce5pmRMj.js";import{C as B,a as F,b as M,c as T}from"./card-C9hfyHXf.js";import{S as A,a as b}from"./ContentField-pilCbdnA.js";function U({relationships:a,values:s,onChange:c,host:o}){return e.jsxs(B,{children:[e.jsx(F,{children:e.jsx(M,{children:"Relationships"})}),e.jsx(T,{className:"space-y-4",children:a.map(n=>n.multiple?e.jsx(L,{rel:n,items:s[n.name]??[],host:o,onChange:i=>c({...s,[n.name]:i})},n.name):e.jsx(H,{rel:n,value:s[n.name]?.[0]??null,host:o,onChange:i=>c({...s,[n.name]:i?[i]:[]})},n.name))})]})}function H({rel:a,value:s,host:c,onChange:o}){const[n,i]=f.useState(!1),r=s?[s.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:a.label}),s?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(h,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:s.title}),e.jsx(E,{variant:"secondary",children:s.collection}),e.jsx(p,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(z,{className:"h-3 w-3"})})]}):e.jsx(b,{host:c,collections:[a.targetCollection],selectedIds:r,open:n,onOpenChange:i,onSelect:d=>{o(d),i(!1)},status:"published",trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(h,{className:"mr-2 h-4 w-4"}),"Select ",a.label]})})]})}function L({rel:a,items:s,host:c,onChange:o}){const n=N(y(v)),[i,r]=f.useState(!1),d=s.map(t=>t.contentId),g=s.map(t=>t.contentId);function S(t){o([...s,t]),r(!1)}function I(t){o(s.filter((m,l)=>l!==t))}function C(t){const{active:m,over:l}=t;if(l&&m.id!==l.id){const j=s.findIndex(x=>x.contentId===String(m.id)),u=s.findIndex(x=>x.contentId===String(l.id));j!==-1&&u!==-1&&o(D(s,j,u))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:a.label}),e.jsx(R,{sensors:n,collisionDetection:P,onDragEnd:C,children:e.jsx(k,{items:d,strategy:w,children:e.jsxs("div",{className:"space-y-2",children:[s.map(t=>e.jsx(A,{id:t.contentId,contentRef:t,onRemove:()=>I(s.indexOf(t))},t.contentId)),e.jsx(b,{host:c,collections:[a.targetCollection],selectedIds:g,open:i,onOpenChange:r,onSelect:S,status:"published",trigger:e.jsxs(p,{type:"button",variant:"outline",size:"sm",children:[e.jsx(O,{className:"mr-2 h-3 w-3"}),"Add ",a.label]})})]})})})]})}export{U as R};