headroom-cms 0.1.7 → 0.1.8

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 (73) hide show
  1. package/README.md +9 -82
  2. package/admin/assets/{AdminsPage-BqfhR4Zc.js → AdminsPage-Bt_ekZen.js} +1 -1
  3. package/admin/assets/AllContentPage-CFqEMAl9.js +1 -0
  4. package/admin/assets/{ApiKeysPage-DJjOSLoR.js → ApiKeysPage-BfWCxGhC.js} +1 -1
  5. package/admin/assets/AuditPage-BE0XIUl2.js +1 -0
  6. package/admin/assets/{BlockEditor-DDsml97y.js → BlockEditor-6wqsThJ7.js} +40 -40
  7. package/admin/assets/{BlockTypeEditPage-Cg7BifaZ.js → BlockTypeEditPage-CuNJfZw0.js} +1 -1
  8. package/admin/assets/{BlockTypesPage-BDFj8TSL.js → BlockTypesPage-BIMBVxBs.js} +1 -1
  9. package/admin/assets/{BulkActionBar-CastJGEP.js → BulkActionBar-TRiXXLQd.js} +1 -1
  10. package/admin/assets/{CollectionEditPage-DGW4iMfo.js → CollectionEditPage-BqX_0cC2.js} +1 -1
  11. package/admin/assets/{CollectionsPage-C8XNxRda.js → CollectionsPage-ClplrxNn.js} +1 -1
  12. package/admin/assets/{ContentCreatePage-CX4aOzTR.js → ContentCreatePage-DfYcEH1u.js} +1 -1
  13. package/admin/assets/ContentEditPage-D3Rvlktk.js +2 -0
  14. package/admin/assets/ContentListPage-zmO8Is4d.js +1 -0
  15. package/admin/assets/{CustomBlockPreview-DfDOcbmR.js → CustomBlockPreview-C6HqS4xv.js} +1 -1
  16. package/admin/assets/{FieldBuilder-8VVLG_j0.js → FieldBuilder-36tfpSyM.js} +1 -1
  17. package/admin/assets/{FilterBar-JCp03kkK.js → FilterBar-DhRwTqFv.js} +1 -1
  18. package/admin/assets/{LoginPage-gPNC9XRN.js → LoginPage-DutieANA.js} +1 -1
  19. package/admin/assets/MediaField-J2TLG_fu.js +1 -0
  20. package/admin/assets/{MediaPage-D9763lEk.js → MediaPage-DZZKMGF4.js} +1 -1
  21. package/admin/assets/{RelationshipPicker-D7dFI43Q.js → RelationshipPicker-CDFs4TMW.js} +1 -1
  22. package/admin/assets/SiteSettingsPage-BtCC3RKc.js +1 -0
  23. package/admin/assets/SiteUserEditPage-ClHmp0T-.js +1 -0
  24. package/admin/assets/SiteUsersPage-AyJvcVM7.js +1 -0
  25. package/admin/assets/{SitesPage-BFIZ3Y5K.js → SitesPage-Bw_WBN6v.js} +1 -1
  26. package/admin/assets/SubmissionDetailPage-DS08LGxd.js +1 -0
  27. package/admin/assets/{SubmissionEditPage-PgowJuvq.js → SubmissionEditPage-Brf-DK2X.js} +1 -1
  28. package/admin/assets/{SubmissionListPage-HFDQxPhn.js → SubmissionListPage-DNMzQZHS.js} +1 -1
  29. package/admin/assets/{TagInput-CDkKZboX.js → TagInput-BILCaC9b.js} +1 -1
  30. package/admin/assets/{TagsPage-BW15-W4H.js → TagsPage-DdeZokow.js} +1 -1
  31. package/admin/assets/{UsersPage-C-zlDeTy.js → UsersPage-B0vLxjrg.js} +1 -1
  32. package/admin/assets/{WebhookEditPage-cPPALIbH.js → WebhookEditPage-SlJE4d3z.js} +1 -1
  33. package/admin/assets/{WebhooksPage-vkPC4m9a.js → WebhooksPage-C6lGZLpr.js} +1 -1
  34. package/admin/assets/{card-10FqkZPA.js → card-hXVtlM0q.js} +1 -1
  35. package/admin/assets/{checkbox-fC1QPb_4.js → checkbox-WGrS3sUr.js} +1 -1
  36. package/admin/assets/{command-BeacdV75.js → command-fvBFHye4.js} +1 -1
  37. package/admin/assets/{index-wYNPRVrc.js → index-Cir9tY_P.js} +5 -5
  38. package/admin/assets/index-DACBYsKM.css +1 -0
  39. package/admin/assets/{popover-BJDj8C6y.js → popover-D5_HjjUC.js} +1 -1
  40. package/admin/assets/{select-BV3jemT6.js → select-_uJYxzeZ.js} +1 -1
  41. package/admin/assets/serializeToText-DR_WnxiI.js +2 -0
  42. package/admin/assets/{table-WkEcC9MH.js → table-DLoIbCQ5.js} +1 -1
  43. package/admin/assets/{textarea-CHQ9tT69.js → textarea-vSXNxwTe.js} +1 -1
  44. package/admin/assets/useAdminResolver-D-LlmquD.js +1 -0
  45. package/admin/assets/useContent-e8beBIuq.js +1 -0
  46. package/admin/assets/{useContentSearch-B-_p0_QX.js → useContentSearch-DOjveB9t.js} +1 -1
  47. package/admin/assets/{useMedia-m6zKB__r.js → useMedia-e3sqWm_t.js} +1 -1
  48. package/admin/assets/{usePageTitle-Bwf-MpTD.js → usePageTitle-BNSba9_L.js} +1 -1
  49. package/admin/assets/useSiteUsers-BdnvuM2E.js +1 -0
  50. package/admin/assets/{useTags-CLPWVUB3.js → useTags-f7AVSLuj.js} +1 -1
  51. package/admin/assets/{useWebhooks-no0l3-mF.js → useWebhooks-BH_r8-Mo.js} +1 -1
  52. package/admin/index.html +2 -2
  53. package/admin/sw.js +1 -1
  54. package/dist/cdn.d.ts.map +1 -1
  55. package/dist/cdn.js +179 -19
  56. package/dist/cdn.js.map +1 -1
  57. package/lambda/api/bootstrap +0 -0
  58. package/lambda/webhook-worker/bootstrap +0 -0
  59. package/package.json +1 -1
  60. package/src/cdn.ts +184 -19
  61. package/admin/assets/AllContentPage-C11eeRMt.js +0 -1
  62. package/admin/assets/AuditPage-DJNk7IaW.js +0 -1
  63. package/admin/assets/ContentEditPage-Dj3RK2BF.js +0 -2
  64. package/admin/assets/ContentListPage-CoDanHrR.js +0 -1
  65. package/admin/assets/MediaField-Du7_gRse.js +0 -1
  66. package/admin/assets/SiteSettingsPage-Tfiex2yn.js +0 -1
  67. package/admin/assets/SiteUsersPage-CSV8syR3.js +0 -1
  68. package/admin/assets/SubmissionDetailPage-8vtUQsLd.js +0 -1
  69. package/admin/assets/index-Do_SK4Zl.css +0 -1
  70. package/admin/assets/serializeToText-BJy0Ms5I.js +0 -2
  71. package/admin/assets/useAdminResolver-CpZj93vH.js +0 -1
  72. package/admin/assets/useContent-D8yDRTTy.js +0 -1
  73. package/admin/assets/useSiteUsers-QbiItSH1.js +0 -1
@@ -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{a as Tt,b as It,c as Mt,d as Rt,e as ct,f as _t,g as At,h as Et,i as Ft,j as zt,k as $t,l as Pt,m as Ot}from"./useMedia-m6zKB__r.js";import{y as P,aa as dt,ab as Ut,ac as Lt,ad as Ht,ae as Xt,R as Yt,B as D,af 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,ag as Bt,j as Ue,T as Kt,X as ge,P as Wt,ah as ee,a2 as Vt,a3 as qt,a7 as Qt,a5 as Gt,a6 as nt,ai as pe,aj as Zt,ak as Jt,Z as es,al as ts,am as ss,W as as,x as ns,F as rs,G as is,K as ls,z as rt,an as os,ao as cs,ap as ds,S as hs,aq as us}from"./index-wYNPRVrc.js";import{C as ms,c as xs}from"./card-10FqkZPA.js";import{C as Ie}from"./checkbox-fC1QPb_4.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-BV3jemT6.js";import{s as ps,t as gs,u as fs,v as ws,w as js,A as vs}from"./radix-C1kb_NqW.js";import{b as ht,d as ys,u as bs,a as Cs,D as Ns,e as Ds,P as ks}from"./core.esm-B_kcYf6n.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 Ss,a as Ts,b as ut,c as X,d as Is,e as Y}from"./table-WkEcC9MH.js";import{T as Pe,A as Xe,h as Ms,a as Ye,b as Be,c as Ke,d as We,e as Ve,f as qe,g as Qe}from"./TagInput-CDkKZboX.js";import{u as Rs}from"./usePageTitle-Bwf-MpTD.js";function Ne({delayDuration:a=0,...t}){return e.jsx(ps,{"data-slot":"tooltip-provider",delayDuration:a,...t})}function De({...a}){return e.jsx(gs,{"data-slot":"tooltip",...a})}function ke({...a}){return e.jsx(fs,{"data-slot":"tooltip-trigger",...a})}function Se({className:a,sideOffset:t=0,children:s,...l}){return e.jsx(ws,{children:e.jsxs(js,{"data-slot":"tooltip-content",sideOffset:t,className:P("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...l,children:[s,e.jsx(vs,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}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 _s(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 As({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:_s(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 Es({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(Ss,{children:[e.jsx(Ts,{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(Is,{children:a.map(r=>e.jsx(As,{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 Fs=Object.defineProperty,zs=(a,t,s)=>t in a?Fs(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>zs(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),$s=(...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 Ps(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 Os=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-${Os++}`),_(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=Ps(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=$s("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 Us=Z;const Ls=[{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"}],Hs={"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}`:Hs[t]||".jpg"}function Xs(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ys({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=>Xs(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(Us,{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:Ls.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 Bs=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Ks({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=Bs.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(Ms,{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(Ys,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ws({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}=ys({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 Vs({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 qs({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 Qs({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 Gs=3;let Zs=0;function Js(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=Gs-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-${Zs++}`,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 ea({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 ta({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 sa=({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},aa=[{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 na({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 va(){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);Rs({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Js(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=bs(Cs(ks,{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(Ns,{sensors:ae,modifiers:[sa],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(qs,{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(Vs,{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:aa.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(Ws,{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(Es,{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(na,{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(Ks,{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(Qs,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(ea,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(ta,{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(Ds,{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{va 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-e3sqWm_t.js";import{y as P,aa as dt,ab as Ut,ac as Lt,ad as Ht,ae as Xt,R as Yt,B as D,af 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,ag as Bt,j as Ue,T as Kt,X as ge,P as Wt,ah as ee,a2 as Vt,a3 as qt,a7 as Qt,a5 as Gt,a6 as nt,ai as pe,aj as Zt,ak as Jt,Z as es,al as ts,am as ss,W as as,x as ns,F as rs,G as is,K as ls,z as rt,an as os,ao as cs,ap as ds,S as hs,aq as us}from"./index-Cir9tY_P.js";import{C as ms,c as xs}from"./card-hXVtlM0q.js";import{C as Ie}from"./checkbox-WGrS3sUr.js";import{S as fe,a as we,b as je,c as ve,d as te}from"./select-_uJYxzeZ.js";import{s as ps,t as gs,u as fs,v as ws,w as js,A as vs}from"./radix-C1kb_NqW.js";import{b as ht,d as ys,u as bs,a as Cs,D as Ns,e as Ds,P as ks}from"./core.esm-B_kcYf6n.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 Ss,a as Ts,b as ut,c as X,d as Is,e as Y}from"./table-DLoIbCQ5.js";import{T as Pe,A as Xe,h as Ms,a as Ye,b as Be,c as Ke,d as We,e as Ve,f as qe,g as Qe}from"./TagInput-BILCaC9b.js";import{u as Rs}from"./usePageTitle-BNSba9_L.js";function Ne({delayDuration:a=0,...t}){return e.jsx(ps,{"data-slot":"tooltip-provider",delayDuration:a,...t})}function De({...a}){return e.jsx(gs,{"data-slot":"tooltip",...a})}function ke({...a}){return e.jsx(fs,{"data-slot":"tooltip-trigger",...a})}function Se({className:a,sideOffset:t=0,children:s,...l}){return e.jsx(ws,{children:e.jsxs(js,{"data-slot":"tooltip-content",sideOffset:t,className:P("bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",a),...l,children:[s,e.jsx(vs,{className:"bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]"})]})})}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 _s(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 As({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:_s(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 Es({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(Ss,{children:[e.jsx(Ts,{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(Is,{children:a.map(r=>e.jsx(As,{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 Fs=Object.defineProperty,zs=(a,t,s)=>t in a?Fs(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s,_=(a,t,s)=>zs(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),$s=(...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 Ps(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 Os=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-${Os++}`),_(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=Ps(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=$s("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 Us=Z;const Ls=[{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"}],Hs={"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}`:Hs[t]||".jpg"}function Xs(a,t){const s=a.lastIndexOf(".");return(s>0?a.substring(0,s):a)+t}function Ys({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=>Xs(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(Us,{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:Ls.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 Bs=new Set(["image/jpeg","image/png","image/gif","image/webp","image/avif","image/tiff"]);function Ks({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=Bs.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(Ms,{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(Ys,{host:a,media:t,onClose:()=>m(!1),onSaved:()=>s()})]})}function Ws({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}=ys({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 Vs({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 qs({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 Qs({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 Gs=3;let Zs=0;function Js(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=Gs-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-${Zs++}`,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 ea({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 ta({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 sa=({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},aa=[{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 na({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 va(){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);Rs({title:"Media",actions:e.jsx(D,{size:"sm",onClick:()=>V.current?.click(),children:e.jsx(pe,{className:"h-4 w-4"})})});const y=Js(a,r&&r!=="unfiled"?r:void 0),M=$t(a),q=Pt(a),ae=bs(Cs(ks,{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(Ns,{sensors:ae,modifiers:[sa],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(qs,{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(Vs,{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:aa.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(Ws,{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(Es,{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(na,{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(Ks,{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(Qs,{queue:y})]})]}),F!==null&&Ce.length>0&&e.jsx(ea,{items:Ce,currentIndex:F,host:a,onClose:()=>z(null),onNavigate:z}),e.jsx(ta,{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(Ds,{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{va as MediaPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as b,u as B}from"./react-vendor-C2CvUxFh.js";import{C as L,u as w,a as P,P as R,D as k,c as O}from"./core.esm-B_kcYf6n.js";import{u as M,S as D,v as F,a as E}from"./sortable.esm-QyXA6fio.js";import{R as V,aa as f,j as C,B as h,X as y,P as z}from"./index-wYNPRVrc.js";import{C as A,a as G,b as Q,c as _}from"./card-10FqkZPA.js";import{P as q,a as H,b as X}from"./popover-BJDj8C6y.js";import{C as J,a as K,b as U,c as W,d as Y,e as Z}from"./command-BeacdV75.js";import{u as $}from"./useContentSearch-B-_p0_QX.js";import{u as ee}from"./useDebouncedValue-C-cQUcLG.js";function pe({field:i,value:t,onChange:a}){const{host:o}=B(),s=i.options,c=!!s?.multiple,d=s?.collections;return c?e.jsx(ne,{host:o,collections:d,value:t??[],onChange:a}):e.jsx(te,{host:o,collections:d,value:t,onChange:a})}function te({host:i,collections:t,value:a,onChange:o}){const[s,c]=b.useState(!1),d=a?[a.contentId]:[];function r(x){o(x),c(!1)}return e.jsx("div",{children:a?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:a.title}),e.jsx(C,{variant:"secondary",children:a.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:i,collections:t,selectedIds:d,open:s,onOpenChange:c,onSelect:r,trigger:e.jsxs(h,{type:"button",variant:"outline",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function ne({host:i,collections:t,value:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=a??[],x=r.map(n=>n.contentId),g=r.map(n=>n.contentId);function p(n){o([...r,n]),d(!1)}function I(n){o(r.filter((m,u)=>u!==n))}function l(n){const{active:m,over:u}=n;if(u&&m.id!==u.id){const S=r.findIndex(v=>v.contentId===String(m.id)),j=r.findIndex(v=>v.contentId===String(u.id));S!==-1&&j!==-1&&o(E(r,S,j))}}return e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:l,children:e.jsx(D,{items:x,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[r.map(n=>e.jsx(T,{id:n.contentId,contentRef:n,onRemove:()=>I(r.indexOf(n))},n.contentId)),e.jsx(N,{host:i,collections:t,selectedIds:g,open:c,onOpenChange:d,onSelect:p,trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function T({id:i,contentRef:t,onRemove:a}){const{attributes:o,listeners:s,setNodeRef:c,transform:d,transition:r}=M({id:i}),x={transform:L.Transform.toString(d),transition:r};return e.jsxs("div",{ref:c,style:x,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...o,...s,children:e.jsx(V,{className:"h-4 w-4"})}),e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:a,className:"text-destructive",children:e.jsx(y,{className:"h-3 w-3"})})]})}function N({host:i,collections:t,selectedIds:a,open:o,onOpenChange:s,onSelect:c,trigger:d,status:r}){const[x,g]=b.useState(""),p=ee(x,300),{data:I,isLoading:l}=$(i,p,t,r);return e.jsxs(q,{open:o,onOpenChange:s,children:[e.jsx(H,{asChild:!0,children:d}),e.jsx(X,{className:"w-80 p-0",align:"start",children:e.jsxs(J,{shouldFilter:!1,children:[e.jsx(K,{placeholder:"Search content...",value:x,onValueChange:g}),e.jsx(U,{children:l?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(W,{children:"No content found."}),e.jsx(Y,{heading:p.length===0?"Recent":void 0,children:I?.items.map(n=>{const m=a.includes(n.contentId);return e.jsxs(Z,{value:n.contentId,disabled:m,onSelect:()=>c({contentId:n.contentId,collection:n.collection,slug:n.slug??"",title:n.title}),children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:n.title}),e.jsx(C,{variant:"outline",className:"text-xs",children:n.collection})]},n.contentId)})})]})})]})})]})}function je({relationships:i,values:t,onChange:a,host:o}){return e.jsxs(A,{children:[e.jsx(G,{children:e.jsx(Q,{children:"Relationships"})}),e.jsx(_,{className:"space-y-4",children:i.map(s=>s.multiple?e.jsx(oe,{rel:s,items:t[s.name]??[],host:o,onChange:c=>a({...t,[s.name]:c})},s.name):e.jsx(se,{rel:s,value:t[s.name]?.[0]??null,host:o,onChange:c=>a({...t,[s.name]:c?[c]:[]})},s.name))})]})}function se({rel:i,value:t,host:a,onChange:o}){const[s,c]=b.useState(!1),d=t?[t.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),t?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:d,open:s,onOpenChange:c,onSelect:r=>{o(r),c(!1)},status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select ",i.label]})})]})}function oe({rel:i,items:t,host:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=t.map(l=>l.contentId),x=t.map(l=>l.contentId);function g(l){o([...t,l]),d(!1)}function p(l){o(t.filter((n,m)=>m!==l))}function I(l){const{active:n,over:m}=l;if(m&&n.id!==m.id){const u=t.findIndex(j=>j.contentId===String(n.id)),S=t.findIndex(j=>j.contentId===String(m.id));u!==-1&&S!==-1&&o(E(t,u,S))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:I,children:e.jsx(D,{items:r,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[t.map(l=>e.jsx(T,{id:l.contentId,contentRef:l,onRemove:()=>p(t.indexOf(l))},l.contentId)),e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:x,open:c,onOpenChange:d,onSelect:g,status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add ",i.label]})})]})})})]})}export{pe as C,je as R,N as a};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as b,u as B}from"./react-vendor-C2CvUxFh.js";import{C as L,u as w,a as P,P as R,D as k,c as O}from"./core.esm-B_kcYf6n.js";import{u as M,S as D,v as F,a as E}from"./sortable.esm-QyXA6fio.js";import{R as V,aa as f,j as C,B as h,X as y,P as z}from"./index-Cir9tY_P.js";import{C as A,a as G,b as Q,c as _}from"./card-hXVtlM0q.js";import{P as q,a as H,b as X}from"./popover-D5_HjjUC.js";import{C as J,a as K,b as U,c as W,d as Y,e as Z}from"./command-fvBFHye4.js";import{u as $}from"./useContentSearch-DOjveB9t.js";import{u as ee}from"./useDebouncedValue-C-cQUcLG.js";function pe({field:i,value:t,onChange:a}){const{host:o}=B(),s=i.options,c=!!s?.multiple,d=s?.collections;return c?e.jsx(ne,{host:o,collections:d,value:t??[],onChange:a}):e.jsx(te,{host:o,collections:d,value:t,onChange:a})}function te({host:i,collections:t,value:a,onChange:o}){const[s,c]=b.useState(!1),d=a?[a.contentId]:[];function r(x){o(x),c(!1)}return e.jsx("div",{children:a?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:a.title}),e.jsx(C,{variant:"secondary",children:a.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:i,collections:t,selectedIds:d,open:s,onOpenChange:c,onSelect:r,trigger:e.jsxs(h,{type:"button",variant:"outline",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select Content"]})})})}function ne({host:i,collections:t,value:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=a??[],x=r.map(n=>n.contentId),g=r.map(n=>n.contentId);function p(n){o([...r,n]),d(!1)}function I(n){o(r.filter((m,u)=>u!==n))}function l(n){const{active:m,over:u}=n;if(u&&m.id!==u.id){const S=r.findIndex(v=>v.contentId===String(m.id)),j=r.findIndex(v=>v.contentId===String(u.id));S!==-1&&j!==-1&&o(E(r,S,j))}}return e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:l,children:e.jsx(D,{items:x,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[r.map(n=>e.jsx(T,{id:n.contentId,contentRef:n,onRemove:()=>I(r.indexOf(n))},n.contentId)),e.jsx(N,{host:i,collections:t,selectedIds:g,open:c,onOpenChange:d,onSelect:p,trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add Content"]})})]})})})}function T({id:i,contentRef:t,onRemove:a}){const{attributes:o,listeners:s,setNodeRef:c,transform:d,transition:r}=M({id:i}),x={transform:L.Transform.toString(d),transition:r};return e.jsxs("div",{ref:c,style:x,className:"flex items-center gap-2 rounded-md border p-2",children:[e.jsx("button",{type:"button",className:"cursor-grab touch-none text-muted-foreground hover:text-foreground",...o,...s,children:e.jsx(V,{className:"h-4 w-4"})}),e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:a,className:"text-destructive",children:e.jsx(y,{className:"h-3 w-3"})})]})}function N({host:i,collections:t,selectedIds:a,open:o,onOpenChange:s,onSelect:c,trigger:d,status:r}){const[x,g]=b.useState(""),p=ee(x,300),{data:I,isLoading:l}=$(i,p,t,r);return e.jsxs(q,{open:o,onOpenChange:s,children:[e.jsx(H,{asChild:!0,children:d}),e.jsx(X,{className:"w-80 p-0",align:"start",children:e.jsxs(J,{shouldFilter:!1,children:[e.jsx(K,{placeholder:"Search content...",value:x,onValueChange:g}),e.jsx(U,{children:l?e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"Searching..."}):e.jsxs(e.Fragment,{children:[e.jsx(W,{children:"No content found."}),e.jsx(Y,{heading:p.length===0?"Recent":void 0,children:I?.items.map(n=>{const m=a.includes(n.contentId);return e.jsxs(Z,{value:n.contentId,disabled:m,onSelect:()=>c({contentId:n.contentId,collection:n.collection,slug:n.slug??"",title:n.title}),children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1 truncate",children:n.title}),e.jsx(C,{variant:"outline",className:"text-xs",children:n.collection})]},n.contentId)})})]})})]})})]})}function je({relationships:i,values:t,onChange:a,host:o}){return e.jsxs(A,{children:[e.jsx(G,{children:e.jsx(Q,{children:"Relationships"})}),e.jsx(_,{className:"space-y-4",children:i.map(s=>s.multiple?e.jsx(oe,{rel:s,items:t[s.name]??[],host:o,onChange:c=>a({...t,[s.name]:c})},s.name):e.jsx(se,{rel:s,value:t[s.name]?.[0]??null,host:o,onChange:c=>a({...t,[s.name]:c?[c]:[]})},s.name))})]})}function se({rel:i,value:t,host:a,onChange:o}){const[s,c]=b.useState(!1),d=t?[t.contentId]:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),t?e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-2",children:[e.jsx(f,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-sm",children:t.title}),e.jsx(C,{variant:"secondary",children:t.collection}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",onClick:()=>o(null),children:e.jsx(y,{className:"h-3 w-3"})})]}):e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:d,open:s,onOpenChange:c,onSelect:r=>{o(r),c(!1)},status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(f,{className:"mr-2 h-4 w-4"}),"Select ",i.label]})})]})}function oe({rel:i,items:t,host:a,onChange:o}){const s=w(P(R)),[c,d]=b.useState(!1),r=t.map(l=>l.contentId),x=t.map(l=>l.contentId);function g(l){o([...t,l]),d(!1)}function p(l){o(t.filter((n,m)=>m!==l))}function I(l){const{active:n,over:m}=l;if(m&&n.id!==m.id){const u=t.findIndex(j=>j.contentId===String(n.id)),S=t.findIndex(j=>j.contentId===String(m.id));u!==-1&&S!==-1&&o(E(t,u,S))}}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",children:i.label}),e.jsx(k,{sensors:s,collisionDetection:O,onDragEnd:I,children:e.jsx(D,{items:r,strategy:F,children:e.jsxs("div",{className:"space-y-2",children:[t.map(l=>e.jsx(T,{id:l.contentId,contentRef:l,onRemove:()=>p(t.indexOf(l))},l.contentId)),e.jsx(N,{host:a,collections:[i.targetCollection],selectedIds:x,open:c,onOpenChange:d,onSelect:g,status:"published",trigger:e.jsxs(h,{type:"button",variant:"outline",size:"sm",children:[e.jsx(z,{className:"mr-2 h-3 w-3"}),"Add ",i.label]})})]})})})]})}export{pe as C,je as R,N as a};
@@ -0,0 +1 @@
1
+ import{j as e,a as V}from"./tanstack-Bs3zYPPV.js";import{r as u,u as Z,f as z}from"./react-vendor-C2CvUxFh.js";import{L as r,I as m,B as c,v as n,aG as J,S as L,a$ as W,b0 as X,b1 as ee,aF as se,x as te,j as ae,a as C,aQ as ie,D as M,k as I,l as B,m as U,n as q,o as _}from"./index-Cir9tY_P.js";import{C as T,a as w,b as F,d as re,c as k}from"./card-hXVtlM0q.js";import{f as ne}from"./format-C88SDH8g.js";import{u as le}from"./usePageTitle-BNSba9_L.js";import{u as oe,a as de,b as ce,c as me}from"./useSiteUsers-BdnvuM2E.js";import{C as H}from"./checkbox-WGrS3sUr.js";import{T as R}from"./textarea-vSXNxwTe.js";import"./radix-C1kb_NqW.js";function he({host:t}){const{data:h,isLoading:l}=oe(t),p=de(t),j=ce(t),v=me(t),[i,d]=u.useState({}),[x,f]=u.useState(""),[g,y]=u.useState("");u.useEffect(()=>{h&&d(h)},[h]);async function P(){try{await p.mutateAsync(i),n.success("Auth settings saved")}catch(s){n.error("Failed to save",{description:s instanceof Error?s.message:void 0})}}async function b(){if(x)try{await j.mutateAsync(x),n.success("Test email sent")}catch(s){n.error("Failed to send test email",{description:s instanceof Error?s.message:void 0})}}async function A(){if(g)try{const s=await v.mutateAsync(g);n.success(`OTP code: ${s.code}`,{description:`For ${s.email} — valid until ${new Date(s.expiresAt*1e3).toLocaleTimeString()}`,duration:15e3})}catch(s){n.error("Failed to fetch OTP",{description:s instanceof Error?s.message:void 0})}}if(l||!h)return null;const o=(i.mode??"test")!=="production";function S(s){d({...i,mode:s})}return e.jsxs(T,{children:[e.jsxs(w,{children:[e.jsx(F,{children:"Site Authentication"}),e.jsx(re,{children:"Enable email OTP authentication for site visitors."})]}),e.jsxs(k,{className:"space-y-6",children:[i.enabled&&e.jsx("div",{role:"status",className:o?"rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-200":"rounded-md border border-emerald-300 bg-emerald-50 p-3 text-sm text-emerald-900 dark:border-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:o?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Test Mode:"})," OTP codes are not currently sent via email. Retrieve the latest code for a user from the admin API or CLI (",e.jsx("code",{children:"headroom auth latest-otp"}),")."]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Production Mode:"})," Auth is live. OTP codes are delivered to users via email using the templates below."]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{id:"auth-enabled",checked:i.enabled??!1,onCheckedChange:s=>d({...i,enabled:s})}),e.jsx(r,{htmlFor:"auth-enabled",children:"Enable site auth"})]}),i.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Mode"}),e.jsxs("div",{className:"inline-flex rounded-md border p-0.5",role:"radiogroup","aria-label":"Auth mode",children:[e.jsx("button",{type:"button",role:"radio","aria-checked":o,onClick:()=>S("test"),className:"rounded px-3 py-1 text-sm transition-colors "+(o?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"),children:"Test"}),e.jsx("button",{type:"button",role:"radio","aria-checked":!o,onClick:()=>S("production"),className:"rounded px-3 py-1 text-sm transition-colors "+(o?"text-muted-foreground hover:text-foreground":"bg-primary text-primary-foreground"),children:"Production"})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:o?"OTP codes are generated and stored but not emailed. Use the admin API or CLI to fetch the latest code for a user. Safe for development and automated testing.":"OTP codes are delivered via email using your configured templates. Only switch to Production when you're ready to accept real user logins."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(H,{id:"allow-signup",checked:i.allowSignup??!1,onCheckedChange:s=>d({...i,allowSignup:s})}),e.jsx(r,{htmlFor:"allow-signup",children:"Allow self-registration"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"session-ttl",children:"Session duration (days)"}),e.jsx(m,{id:"session-ttl",type:"number",min:1,value:Math.round((i.sessionTtl??2592e3)/86400),onChange:s=>d({...i,sessionTtl:parseInt(s.target.value)*86400})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-subject",children:"Email subject (Liquid)"}),e.jsx(m,{id:"email-subject",placeholder:"Your login code for {{ site_name }}",value:i.emailSubject??"",onChange:s=>d({...i,emailSubject:s.target.value})}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:["Variables: ","{{ code }}",", ","{{ site_name }}",", ","{{ user_email }}",", ","{{ user_name }}",", ","{{ expires_minutes }}"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-body",children:"Email HTML body (Liquid)"}),e.jsx(R,{id:"email-body",rows:5,placeholder:"<p>Your code: <strong>{{ code }}</strong></p>",value:i.emailBody??"",onChange:s=>d({...i,emailBody:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"email-text",children:"Email text body (Liquid)"}),e.jsx(R,{id:"email-text",rows:3,placeholder:"Your code: {{ code }}",value:i.emailTextBody??"",onChange:s=>d({...i,emailTextBody:s.target.value})})]}),e.jsx("div",{className:"border-t pt-4",children:e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(r,{htmlFor:"test-email",children:"Send test email"}),e.jsx(m,{id:"test-email",type:"email",placeholder:"admin@example.com",value:x,onChange:s=>f(s.target.value)})]}),e.jsx(c,{variant:"outline",onClick:b,disabled:j.isPending||!x,children:"Send"})]})}),o&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(r,{htmlFor:"otp-lookup-email",children:"Fetch latest OTP code"}),e.jsx(m,{id:"otp-lookup-email",type:"email",placeholder:"user@example.com",value:g,onChange:s=>y(s.target.value)})]}),e.jsx(c,{variant:"outline",onClick:A,disabled:v.isPending||!g,children:"Fetch"})]}),e.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:"Returns the latest unexpired OTP for the given email. Only works in test mode."})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(c,{onClick:P,disabled:p.isPending,children:"Save"})})]})]})}function Ce(){const{host:t}=Z(),{data:h,isLoading:l}=J(t);return l?e.jsxs("div",{className:"space-y-4",children:[e.jsx(L,{className:"h-8 w-64"}),e.jsx(L,{className:"h-48 w-full"})]}):h?e.jsx(ue,{site:h},h.host):e.jsx("p",{className:"text-muted-foreground",children:"Site not found."})}function ue({site:t}){const h=V(),l=W(t.host),p=X(t.host),j=ee(t.host),v=z(),d=se()==="admin",x=t.status==="archived",[f,g]=u.useState(t.name),[y,P]=u.useState(t.fromEmail??""),[b,A]=u.useState(t.fromName??""),[E,o]=u.useState(!1),[S,s]=u.useState(!1),[D,N]=u.useState(""),$=te();le({title:"Configuration"});async function Q(a){a.preventDefault();try{await l.mutateAsync({name:f,fromEmail:y,fromName:b}),n.success("Site updated")}catch(O){n.error("Failed to update site",{description:O instanceof Error?O.message:void 0})}}async function Y(){try{await l.mutateAsync({status:"archived"}),n.success("Site archived"),o(!1),v("/sites")}catch(a){n.error("Failed to archive site",{description:a instanceof Error?a.message:void 0})}}async function G(){try{await l.mutateAsync({status:"active"}),n.success("Site unarchived")}catch(a){n.error("Failed to unarchive site",{description:a instanceof Error?a.message:void 0})}}async function K(){try{await p.mutateAsync(),await j.mutateAsync(),await h.invalidateQueries({queryKey:["sites"]}),n.success("Site deleted"),s(!1),N(""),v("/sites")}catch(a){n.error("Failed to delete site",{description:a instanceof Error?a.message:void 0})}}return e.jsxs("div",{className:"mx-auto max-w-2xl",children:[!$&&e.jsx("h1",{className:"mb-6 text-2xl font-semibold",children:"Site Settings"}),e.jsxs(T,{children:[e.jsx(w,{children:e.jsx(F,{children:"General"})}),e.jsx(k,{children:e.jsxs("form",{onSubmit:Q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"name",children:"Site Name"}),e.jsx(m,{id:"name",value:f,onChange:a=>g(a.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"fromEmail",children:"Sender email (optional)"}),e.jsx(m,{id:"fromEmail",type:"email",placeholder:"Uses global default",value:y,onChange:a=>P(a.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'"From" address for emails sent by this site. Must be verified in SES.'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{htmlFor:"fromName",children:"Sender name (optional)"}),e.jsx(m,{id:"fromName",placeholder:"My Site",value:b,onChange:a=>A(a.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display name shown alongside the sender email address."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Host"}),e.jsx(m,{value:t.host,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Status"}),e.jsx("div",{className:"flex items-center gap-2",children:x?e.jsx(ae,{variant:"outline",children:"Archived"}):e.jsx(m,{value:t.status,disabled:!0})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(r,{children:"Created"}),e.jsx(m,{value:ne(t.createdAt),disabled:!0})]}),e.jsxs(c,{type:"submit",disabled:l.isPending,children:[l.isPending&&e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})]})})]}),d&&e.jsxs(T,{className:"mt-6",children:[e.jsx(w,{children:e.jsx(F,{children:"Site Status"})}),e.jsx(k,{className:"space-y-4",children:x?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"This site is archived. Unarchive it to allow content changes."}),e.jsxs(c,{variant:"outline",onClick:G,disabled:l.isPending,children:[l.isPending&&e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}),"Unarchive Site"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Archiving a site makes it read-only. Content cannot be created or modified while archived."}),e.jsxs(c,{variant:"outline",onClick:()=>o(!0),children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Archive Site"]}),e.jsx(M,{open:E,onOpenChange:o,children:e.jsxs(I,{children:[e.jsxs(B,{children:[e.jsx(U,{children:"Archive Site"}),e.jsxs(q,{children:["Are you sure you want to archive ",e.jsx("strong",{children:t.host}),"? The site will become read-only."]})]}),e.jsxs(_,{children:[e.jsx(c,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsxs(c,{onClick:Y,disabled:l.isPending,children:[l.isPending&&e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}),"Archive"]})]})]})})]})})]}),d&&e.jsx("div",{className:"mt-6",children:e.jsx(he,{host:t.host})}),d&&x&&e.jsxs(T,{className:"border-destructive mt-6",children:[e.jsx(w,{children:e.jsx(F,{className:"text-destructive",children:"Danger Zone"})}),e.jsxs(k,{className:"space-y-4",children:[e.jsx("p",{className:"text-muted-foreground text-sm",children:"Permanently delete this site and all its content, media, collections, and block types. This action cannot be undone."}),e.jsx(c,{variant:"destructive",onClick:()=>s(!0),children:"Delete Site"}),e.jsx(M,{open:S,onOpenChange:a=>{s(a),a||N("")},children:e.jsxs(I,{children:[e.jsxs(B,{children:[e.jsx(U,{children:"Delete Site"}),e.jsxs(q,{children:["This will permanently delete this site and all its content. Type ",e.jsx("strong",{children:t.host})," to confirm."]})]}),e.jsx(m,{placeholder:t.host,value:D,onChange:a=>N(a.target.value)}),e.jsxs(_,{children:[e.jsx(c,{variant:"outline",onClick:()=>{s(!1),N("")},children:"Cancel"}),e.jsxs(c,{variant:"destructive",onClick:K,disabled:D!==t.host||p.isPending||j.isPending,children:[(p.isPending||j.isPending)&&e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}),"Delete Everything"]})]})]})})]})]})]})}export{Ce as SiteSettingsPage};
@@ -0,0 +1 @@
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as R,f as V,r as n}from"./react-vendor-C2CvUxFh.js";import{g as $,h as q,i as z,f as X}from"./useSiteUsers-BdnvuM2E.js";import{S as T,x as G,L as u,I as j,j as p,X as J,B as r,a as I,D as Q,i as W,T as Y,k as Z,l as _,m as ee,n as se,o as ae,v as l}from"./index-Cir9tY_P.js";import{C as f,a as g,b as v,c as N}from"./card-hXVtlM0q.js";import{f as k}from"./format-C88SDH8g.js";import{u as te}from"./usePageTitle-BNSba9_L.js";import"./radix-C1kb_NqW.js";function xe(){const{host:t,userId:a}=R(),{data:c,isLoading:d}=$(t,a);return d?e.jsxs("div",{className:"space-y-4",children:[e.jsx(T,{className:"h-8 w-64"}),e.jsx(T,{className:"h-64 w-full"})]}):c?e.jsx(ie,{host:t,user:c},c.userId):e.jsx("p",{className:"text-muted-foreground",children:"User not found."})}function ie({host:t,user:a}){const c=V(),d=q(t),x=z(t),y=X(t),A=G(),[b,L]=n.useState(a.name??""),[h,C]=n.useState(a.status),[o,D]=n.useState(a.tags??[]),[w,S]=n.useState(""),[m,P]=n.useState(a.email),[F,U]=n.useState(!1);te({title:a.name||a.email,showBack:!0,backTo:`/sites/${t}/settings/site-users`});async function B(s){s.preventDefault();try{await d.mutateAsync({userId:a.userId,name:b,status:h,tags:o}),l.success("User updated")}catch(i){l.error("Failed to update user",{description:i instanceof Error?i.message:void 0})}}async function O(s){if(s.preventDefault(),m!==a.email)try{await x.mutateAsync({userId:a.userId,email:m}),l.success("Email updated")}catch(i){l.error("Failed to change email",{description:i instanceof Error?i.message:void 0})}}async function H(){try{await y.mutateAsync(a.userId),l.success("User deleted"),c(`/sites/${t}/settings/site-users`)}catch(s){l.error("Failed to delete user",{description:s instanceof Error?s.message:void 0})}}function E(){const s=w.trim();s&&!o.includes(s)&&D([...o,s]),S("")}function K(s){D(o.filter(i=>i!==s))}function M(s){s.key==="Enter"&&(s.preventDefault(),E())}return e.jsxs("div",{className:"mx-auto max-w-2xl space-y-6",children:[!A&&e.jsx("h1",{className:"text-2xl font-semibold",children:"Edit User"}),e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(v,{children:"User Details"})}),e.jsx(N,{children:e.jsxs("form",{onSubmit:B,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"name",children:"Name"}),e.jsx(j,{id:"name",value:b,onChange:s=>L(s.target.value),placeholder:"User name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Status"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:h==="active"?"default":"outline",className:"cursor-pointer",onClick:()=>C("active"),children:"active"}),e.jsx(p,{variant:h==="disabled"?"default":"outline",className:"cursor-pointer",onClick:()=>C("disabled"),children:"disabled"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-2",children:o.map(s=>e.jsxs(p,{variant:"secondary",className:"gap-1",children:[s,e.jsx("button",{type:"button",onClick:()=>K(s),className:"hover:text-destructive",children:e.jsx(J,{className:"h-3 w-3"})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{value:w,onChange:s=>S(s.target.value),onKeyDown:M,placeholder:"Add tag...",className:"max-w-xs"}),e.jsx(r,{type:"button",variant:"outline",size:"sm",onClick:E,children:"Add"})]})]}),e.jsxs(r,{type:"submit",disabled:d.isPending,children:[d.isPending&&e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}),"Save"]})]})})]}),e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(v,{children:"Email"})}),e.jsx(N,{children:e.jsxs("form",{onSubmit:O,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"email",children:"Email Address"}),e.jsx(j,{id:"email",type:"email",value:m,onChange:s=>P(s.target.value),required:!0})]}),e.jsxs(r,{type:"submit",variant:"outline",disabled:x.isPending||m===a.email,children:[x.isPending&&e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}),"Change Email"]})]})})]}),e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(v,{children:"Info"})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"User ID"}),e.jsx("span",{className:"font-mono",children:a.userId})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Created"}),e.jsx("span",{children:k(a.createdAt)})]}),a.lastLogin&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last Login"}),e.jsx("span",{children:k(a.lastLogin)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Session Version"}),e.jsx("span",{children:a.sessionVersion})]})]})]}),e.jsxs(Q,{open:F,onOpenChange:U,children:[e.jsx(W,{asChild:!0,children:e.jsxs(r,{variant:"destructive",children:[e.jsx(Y,{className:"mr-2 h-4 w-4"}),"Delete User"]})}),e.jsxs(Z,{children:[e.jsxs(_,{children:[e.jsx(ee,{children:"Delete user?"}),e.jsx(se,{children:"This will permanently delete this user and all their identities. This action cannot be undone."})]}),e.jsxs(ae,{children:[e.jsx(r,{variant:"outline",onClick:()=>U(!1),children:"Cancel"}),e.jsx(r,{variant:"destructive",onClick:H,disabled:y.isPending,children:"Delete"})]})]})]})]})}export{xe as SiteUserEditPage};
@@ -0,0 +1 @@
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{u as q,f as z,r as i}from"./react-vendor-C2CvUxFh.js";import{d as G,e as J,f as K}from"./useSiteUsers-BdnvuM2E.js";import{x as Q,B as a,P as b,I as x,S as V,j as C,D as S,k as D,l as w,m as T,n as U,L as P,o as F,v as d}from"./index-Cir9tY_P.js";import{T as W,a as X,b as k,c as l,d as Y,e as n}from"./table-DLoIbCQ5.js";import{f as Z}from"./format-C88SDH8g.js";import{u as _}from"./usePageTitle-BNSba9_L.js";import"./radix-C1kb_NqW.js";function ce(){const{host:r}=q(),E=z(),[u,I]=i.useState(""),{data:A,isLoading:L,hasNextPage:M,fetchNextPage:B,isFetchingNextPage:j}=G(r,{tag:u||void 0}),p=J(r),g=K(r),[O,c]=i.useState(!1),[o,f]=i.useState(""),[v,N]=i.useState(""),[m,h]=i.useState(null),H=Q();_({title:"Site Users",actions:e.jsx(a,{size:"sm",onClick:()=>c(!0),children:e.jsx(b,{className:"h-4 w-4"})})});async function R(s){s.preventDefault();try{await p.mutateAsync({email:o,name:v||void 0}),c(!1),f(""),N(""),d.success("User created")}catch(t){d.error("Failed to create user",{description:t instanceof Error?t.message:void 0})}}async function $(){if(m)try{await g.mutateAsync(m),h(null),d.success("User deleted")}catch(s){d.error("Failed to delete user",{description:s instanceof Error?s.message:void 0})}}const y=A?.pages.flatMap(s=>s.items)??[];return e.jsxs("div",{children:[!H&&e.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Site Users"}),e.jsxs(a,{onClick:()=>c(!0),children:[e.jsx(b,{className:"mr-2 h-4 w-4"}),"Add User"]})]}),e.jsx("div",{className:"mb-4",children:e.jsx(x,{placeholder:"Filter by tag...",value:u,onChange:s=>I(s.target.value),className:"max-w-xs"})}),L?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx(V,{className:"h-12 w-full"},s))}):y.length===0?e.jsx("p",{className:"text-muted-foreground py-8 text-center",children:"No site users yet"}):e.jsxs(W,{children:[e.jsx(X,{children:e.jsxs(k,{children:[e.jsx(l,{children:"Email"}),e.jsx(l,{children:"Name"}),e.jsx(l,{children:"Status"}),e.jsx(l,{children:"Tags"}),e.jsx(l,{children:"Created"})]})}),e.jsx(Y,{children:y.map(s=>e.jsxs(k,{className:"cursor-pointer",onClick:()=>E(`/sites/${r}/settings/site-users/${s.userId}`),children:[e.jsx(n,{className:"font-medium",children:s.email}),e.jsx(n,{children:s.name||"—"}),e.jsx(n,{children:e.jsx(C,{variant:s.status==="active"?"default":"secondary",children:s.status})}),e.jsx(n,{children:s.tags?.map(t=>e.jsx(C,{variant:"outline",className:"mr-1",children:t},t))}),e.jsx(n,{children:Z(s.createdAt)})]},s.userId))})]}),M&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(a,{variant:"outline",onClick:()=>B(),disabled:j,children:j?"Loading...":"Load more"})}),e.jsx(S,{open:O,onOpenChange:c,children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(T,{children:"Add Site User"}),e.jsx(U,{children:"Create a new user for this site."})]}),e.jsxs("form",{onSubmit:R,children:[e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"email",children:"Email"}),e.jsx(x,{id:"email",type:"email",value:o,onChange:s=>f(s.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"name",children:"Name (optional)"}),e.jsx(x,{id:"name",value:v,onChange:s=>N(s.target.value)})]})]}),e.jsx(F,{children:e.jsx(a,{type:"submit",disabled:p.isPending||!o,children:"Create"})})]})]})}),e.jsx(S,{open:!!m,onOpenChange:()=>h(null),children:e.jsxs(D,{children:[e.jsxs(w,{children:[e.jsx(T,{children:"Delete User"}),e.jsx(U,{children:"This will permanently delete this user and all their identities."})]}),e.jsxs(F,{children:[e.jsx(a,{variant:"outline",onClick:()=>h(null),children:"Cancel"}),e.jsx(a,{variant:"destructive",onClick:$,disabled:g.isPending,children:"Delete"})]})]})})]})}export{ce as SiteUsersPage};
@@ -1 +1 @@
1
- import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as u,f as V}from"./react-vendor-C2CvUxFh.js";import{b as X,u as Z,d as ee,e as te,g as se,h as ae,H as U,D as G,i as J,B as k,P as R,U as ne,j as oe,k as ie,l as le,m as re,n as ce,L as W,I as Y,o as de}from"./index-wYNPRVrc.js";import{C as me,a as he,b as ue,d as ge}from"./card-10FqkZPA.js";import{C as b}from"./checkbox-fC1QPb_4.js";import"./radix-C1kb_NqW.js";const pe={name:"pages",label:"Pages",labelSingular:"Page",slug:"pages",singleton:!1,fields:[{name:"content",label:"Content",type:"blocks",options:{}}]},xe={name:"posts",label:"Blog Posts",labelSingular:"Blog Post",slug:"/blog",singleton:!1,fields:[{name:"author",label:"Author",type:"text",options:{}},{name:"content",label:"Content",type:"blocks",options:{}}]},fe={name:"site-settings",label:"Site Settings",labelSingular:"Site Settings",slug:"site-settings",singleton:!0,fields:[{name:"siteName",label:"Site Name",type:"text",options:{}},{name:"tagline",label:"Tagline",type:"text",options:{}},{name:"footerText",label:"Footer Text",type:"text",options:{}},{name:"menuItems",label:"Menu Items",type:"array",options:{itemFields:[{name:"label",label:"Label",type:"text",options:{}},{name:"href",label:"URL",type:"text",options:{}}]}}]};function C(s,o){return{id:o,type:"paragraph",props:{textColor:"default",backgroundColor:"default",textAlignment:"left"},content:[{type:"text",text:s}],children:[]}}function $(s,o,d){return{id:d,type:"heading",props:{textColor:"default",backgroundColor:"default",textAlignment:"left",level:o},content:[{type:"text",text:s}],children:[]}}const z=[{title:"Home",slug:"home",body:{content:[$("Welcome to Headroom",1,"home-h1"),C("This is your new site powered by Headroom CMS. Edit this page to add your own content.","home-p1"),$("Getting Started",2,"home-h2"),C("Head over to the admin panel to manage your content, collections, and media.","home-p2")]}},{title:"About",slug:"about",body:{content:[$("About Us",1,"about-h1"),C("Tell your visitors about your company, team, or project. This is a great place to share your story.","about-p1")]}},{title:"Contact",slug:"contact",body:{content:[$("Contact",1,"contact-h1"),C("Get in touch with us. Replace this with your contact information or a contact form.","contact-p1")]}}],K=[{title:"Welcome to Headroom",slug:"welcome-to-headroom",body:{author:"Admin",content:[C("This is your first blog post. You can edit or delete it and start writing your own content.","post-p1"),C("Headroom makes it easy to create and manage your content with a powerful block editor, media library, and flexible collections.","post-p2")]}}],Se={siteName:"Headroom Site",tagline:"A site powered by Headroom CMS",footerText:"© 2026 Headroom Site. Built with Headroom CMS.",menuItems:[{label:"Home",href:"/"},{label:"About",href:"/about"},{label:"Blog",href:"/blog"},{label:"Contact",href:"/contact"}]};function Q(s){const d=[s.createPages,s.createPosts,s.createSettings].filter(Boolean).length;if(!s.addSampleContent)return d;let g=0;return s.createPages&&(g+=z.length*2),s.createPosts&&(g+=K.length*2),s.createSettings&&(g+=3),d+g}async function be(s,o,d,g){const r={collectionsCreated:[],contentCreated:[],errors:[]},x=Q(d);let a=0;const m=t=>{g?.({completed:a,total:x,label:t})},y=[{key:"pages",enabled:d.createPages,schema:pe},{key:"posts",enabled:d.createPosts,schema:xe},{key:"site-settings",enabled:d.createSettings,schema:fe}],p=new Set;for(const{key:t,enabled:n,schema:f}of y)if(n){m(`Creating ${t} collection...`);try{await s.apiFetch(`/v1/admin/sites/${o}/collections`,{method:"POST",body:JSON.stringify(f)}),r.collectionsCreated.push(t),p.add(t)}catch(h){r.errors.push(`Failed to create ${t} collection: ${h instanceof Error?h.message:String(h)}`)}a++}if(!d.addSampleContent)return m("Done"),r;if(p.has("pages"))for(const t of z){m(`Creating page "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"pages",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing page "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`pages/${t.slug}`)}catch(n){r.errors.push(`Failed to create page "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("posts"))for(const t of K){m(`Creating post "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"posts",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing post "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`posts/${t.slug}`)}catch(n){r.errors.push(`Failed to create post "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("site-settings")){m("Configuring settings...");try{const t=await s.apiFetch(`/v1/admin/sites/${o}/collections/site-settings`);a++,t.singletonContentId?(m("Saving settings draft..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/draft`,{method:"PUT",body:JSON.stringify({title:"Site Settings",slug:"site-settings",body:Se})}),a++,m("Publishing settings..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/publish`,{method:"POST"}),a++,r.contentCreated.push("site-settings")):a+=2}catch(t){r.errors.push(`Failed to populate settings: ${t instanceof Error?t.message:String(t)}`),a+=3}}return m("Done"),r}function Pe(){const[s,o]=u.useState(!1),{data:d,isLoading:g}=X(s),r=V(),x=u.useMemo(()=>[...d?.items??[]].sort((l,A)=>(l.name||l.host).localeCompare(A.name||A.host)),[d]),{user:a}=Z(),{data:m}=ee(),y=a?(m?.superAdminIds??[]).includes(a.sub):!1,p=te(),t=se(),[n,f]=u.useState(!1),[h,j]=u.useState(""),[S,c]=u.useState(""),[N,i]=u.useState(!0),[v,D]=u.useState(!0),[w,O]=u.useState(!0),[P,E]=u.useState(!0),[F,L]=u.useState(!1),[H,T]=u.useState(null),I=()=>{j(""),c(""),i(!0),D(!0),O(!0),E(!0),L(!1),T(null)},B=l=>{f(l),l||I()};if(g)return e.jsx(ae,{});const _=async()=>{if(h.trim())try{await t.mutateAsync({host:h.trim(),name:S.trim()||h.trim()});const l={createPages:v,createPosts:w,createSettings:P,addSampleContent:F};if(N&&(v||w||P)){const A=Q(l);T({completed:0,total:A,label:"Setting up collections..."});const M=await be(p,h.trim(),l,T);M.errors.length>0&&console.warn("Scaffold warnings:",M.errors)}f(!1),I()}catch{T(null)}};return x.length===0?e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"No sites available."}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Create Site"]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]}):e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex-1 p-4 sm:p-8",children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Select a site"}),y&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:s,onCheckedChange:l=>o(l===!0)}),"Show archived sites"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{variant:"outline",onClick:()=>r("/users"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"All Users"})]}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Create Site"})]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]})]}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:x.map(l=>e.jsx(me,{className:"cursor-pointer transition-shadow hover:shadow-md",onClick:()=>r(`/sites/${l.host}/content`),children:e.jsxs(he,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{children:l.name||l.host}),l.status==="archived"&&e.jsx(oe,{variant:"outline",children:"Archived"})]}),e.jsx(ge,{children:l.host})]})},l.host))})]})]})}function q({newHost:s,setNewHost:o,newName:d,setNewName:g,createDefaults:r,setCreateDefaults:x,createPages:a,setCreatePages:m,createPosts:y,setCreatePosts:p,createSettings:t,setCreateSettings:n,addSampleContent:f,setAddSampleContent:h,onSubmit:j,isPending:S,scaffoldProgress:c}){const N=S||!!c;return e.jsxs(ie,{children:[e.jsxs(le,{children:[e.jsx(re,{children:"Create Site"}),e.jsx(ce,{className:"sr-only",children:"Enter details for the new site"})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"host",children:"Host"}),e.jsx(Y,{id:"host",placeholder:"example.com",value:s,onChange:i=>o(i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"name",children:"Display Name"}),e.jsx(Y,{id:"name",placeholder:"My Site",value:d,onChange:i=>g(i.target.value)})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(b,{checked:r,onCheckedChange:i=>x(i===!0)}),"Create Default Collections"]}),r&&e.jsxs("div",{className:"ml-6 mt-3 space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:a,onCheckedChange:i=>m(i===!0)}),"Pages"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:y,onCheckedChange:i=>p(i===!0)}),"Posts"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:t,onCheckedChange:i=>n(i===!0)}),"Site Settings"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(b,{checked:f,onCheckedChange:i=>h(i===!0)}),"Add Sample Content"]})]})]})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300",style:{width:`${c.total>0?c.completed/c.total*100:0}%`},role:"progressbar","aria-valuenow":c.completed,"aria-valuemin":0,"aria-valuemax":c.total})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.label," ","(",c.completed,"/",c.total,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please wait while your site is being set up. Do not close this tab."})]}),e.jsx(de,{children:e.jsx(k,{onClick:j,disabled:!s.trim()||N,children:c?c.label:S?"Creating...":"Create"})})]})}export{Pe as SitesPage};
1
+ import{j as e}from"./tanstack-Bs3zYPPV.js";import{r as u,f as V}from"./react-vendor-C2CvUxFh.js";import{b as X,u as Z,d as ee,e as te,g as se,h as ae,H as U,D as G,i as J,B as k,P as R,U as ne,j as oe,k as ie,l as le,m as re,n as ce,L as W,I as Y,o as de}from"./index-Cir9tY_P.js";import{C as me,a as he,b as ue,d as ge}from"./card-hXVtlM0q.js";import{C as b}from"./checkbox-WGrS3sUr.js";import"./radix-C1kb_NqW.js";const pe={name:"pages",label:"Pages",labelSingular:"Page",slug:"pages",singleton:!1,fields:[{name:"content",label:"Content",type:"blocks",options:{}}]},xe={name:"posts",label:"Blog Posts",labelSingular:"Blog Post",slug:"/blog",singleton:!1,fields:[{name:"author",label:"Author",type:"text",options:{}},{name:"content",label:"Content",type:"blocks",options:{}}]},fe={name:"site-settings",label:"Site Settings",labelSingular:"Site Settings",slug:"site-settings",singleton:!0,fields:[{name:"siteName",label:"Site Name",type:"text",options:{}},{name:"tagline",label:"Tagline",type:"text",options:{}},{name:"footerText",label:"Footer Text",type:"text",options:{}},{name:"menuItems",label:"Menu Items",type:"array",options:{itemFields:[{name:"label",label:"Label",type:"text",options:{}},{name:"href",label:"URL",type:"text",options:{}}]}}]};function C(s,o){return{id:o,type:"paragraph",props:{textColor:"default",backgroundColor:"default",textAlignment:"left"},content:[{type:"text",text:s}],children:[]}}function $(s,o,d){return{id:d,type:"heading",props:{textColor:"default",backgroundColor:"default",textAlignment:"left",level:o},content:[{type:"text",text:s}],children:[]}}const z=[{title:"Home",slug:"home",body:{content:[$("Welcome to Headroom",1,"home-h1"),C("This is your new site powered by Headroom CMS. Edit this page to add your own content.","home-p1"),$("Getting Started",2,"home-h2"),C("Head over to the admin panel to manage your content, collections, and media.","home-p2")]}},{title:"About",slug:"about",body:{content:[$("About Us",1,"about-h1"),C("Tell your visitors about your company, team, or project. This is a great place to share your story.","about-p1")]}},{title:"Contact",slug:"contact",body:{content:[$("Contact",1,"contact-h1"),C("Get in touch with us. Replace this with your contact information or a contact form.","contact-p1")]}}],K=[{title:"Welcome to Headroom",slug:"welcome-to-headroom",body:{author:"Admin",content:[C("This is your first blog post. You can edit or delete it and start writing your own content.","post-p1"),C("Headroom makes it easy to create and manage your content with a powerful block editor, media library, and flexible collections.","post-p2")]}}],Se={siteName:"Headroom Site",tagline:"A site powered by Headroom CMS",footerText:"© 2026 Headroom Site. Built with Headroom CMS.",menuItems:[{label:"Home",href:"/"},{label:"About",href:"/about"},{label:"Blog",href:"/blog"},{label:"Contact",href:"/contact"}]};function Q(s){const d=[s.createPages,s.createPosts,s.createSettings].filter(Boolean).length;if(!s.addSampleContent)return d;let g=0;return s.createPages&&(g+=z.length*2),s.createPosts&&(g+=K.length*2),s.createSettings&&(g+=3),d+g}async function be(s,o,d,g){const r={collectionsCreated:[],contentCreated:[],errors:[]},x=Q(d);let a=0;const m=t=>{g?.({completed:a,total:x,label:t})},y=[{key:"pages",enabled:d.createPages,schema:pe},{key:"posts",enabled:d.createPosts,schema:xe},{key:"site-settings",enabled:d.createSettings,schema:fe}],p=new Set;for(const{key:t,enabled:n,schema:f}of y)if(n){m(`Creating ${t} collection...`);try{await s.apiFetch(`/v1/admin/sites/${o}/collections`,{method:"POST",body:JSON.stringify(f)}),r.collectionsCreated.push(t),p.add(t)}catch(h){r.errors.push(`Failed to create ${t} collection: ${h instanceof Error?h.message:String(h)}`)}a++}if(!d.addSampleContent)return m("Done"),r;if(p.has("pages"))for(const t of z){m(`Creating page "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"pages",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing page "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`pages/${t.slug}`)}catch(n){r.errors.push(`Failed to create page "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("posts"))for(const t of K){m(`Creating post "${t.title}"...`);try{const n=await s.apiFetch(`/v1/admin/sites/${o}/content`,{method:"POST",body:JSON.stringify({collection:"posts",params:{title:t.title,slug:t.slug,body:t.body}})});a++,m(`Publishing post "${t.title}"...`),await s.apiFetch(`/v1/admin/sites/${o}/content/${n.contentId}/publish`,{method:"POST"}),a++,r.contentCreated.push(`posts/${t.slug}`)}catch(n){r.errors.push(`Failed to create post "${t.title}": ${n instanceof Error?n.message:String(n)}`),a+=2}}if(p.has("site-settings")){m("Configuring settings...");try{const t=await s.apiFetch(`/v1/admin/sites/${o}/collections/site-settings`);a++,t.singletonContentId?(m("Saving settings draft..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/draft`,{method:"PUT",body:JSON.stringify({title:"Site Settings",slug:"site-settings",body:Se})}),a++,m("Publishing settings..."),await s.apiFetch(`/v1/admin/sites/${o}/content/${t.singletonContentId}/publish`,{method:"POST"}),a++,r.contentCreated.push("site-settings")):a+=2}catch(t){r.errors.push(`Failed to populate settings: ${t instanceof Error?t.message:String(t)}`),a+=3}}return m("Done"),r}function Pe(){const[s,o]=u.useState(!1),{data:d,isLoading:g}=X(s),r=V(),x=u.useMemo(()=>[...d?.items??[]].sort((l,A)=>(l.name||l.host).localeCompare(A.name||A.host)),[d]),{user:a}=Z(),{data:m}=ee(),y=a?(m?.superAdminIds??[]).includes(a.sub):!1,p=te(),t=se(),[n,f]=u.useState(!1),[h,j]=u.useState(""),[S,c]=u.useState(""),[N,i]=u.useState(!0),[v,D]=u.useState(!0),[w,O]=u.useState(!0),[P,E]=u.useState(!0),[F,L]=u.useState(!1),[H,T]=u.useState(null),I=()=>{j(""),c(""),i(!0),D(!0),O(!0),E(!0),L(!1),T(null)},B=l=>{f(l),l||I()};if(g)return e.jsx(ae,{});const _=async()=>{if(h.trim())try{await t.mutateAsync({host:h.trim(),name:S.trim()||h.trim()});const l={createPages:v,createPosts:w,createSettings:P,addSampleContent:F};if(N&&(v||w||P)){const A=Q(l);T({completed:0,total:A,label:"Setting up collections..."});const M=await be(p,h.trim(),l,T);M.errors.length>0&&console.warn("Scaffold warnings:",M.errors)}f(!1),I()}catch{T(null)}};return x.length===0?e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"No sites available."}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),"Create Site"]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]}):e.jsxs("div",{className:"flex h-dvh flex-col",children:[e.jsx(U,{}),e.jsxs("div",{className:"flex-1 p-4 sm:p-8",children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Select a site"}),y&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:s,onCheckedChange:l=>o(l===!0)}),"Show archived sites"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{variant:"outline",onClick:()=>r("/users"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"All Users"})]}),e.jsxs(G,{open:n,onOpenChange:B,children:[e.jsx(J,{asChild:!0,children:e.jsxs(k,{children:[e.jsx(R,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Create Site"})]})}),e.jsx(q,{newHost:h,setNewHost:j,newName:S,setNewName:c,createDefaults:N,setCreateDefaults:i,createPages:v,setCreatePages:D,createPosts:w,setCreatePosts:O,createSettings:P,setCreateSettings:E,addSampleContent:F,setAddSampleContent:L,onSubmit:_,isPending:t.isPending,scaffoldProgress:H})]})]})]})]}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:x.map(l=>e.jsx(me,{className:"cursor-pointer transition-shadow hover:shadow-md",onClick:()=>r(`/sites/${l.host}/content`),children:e.jsxs(he,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{children:l.name||l.host}),l.status==="archived"&&e.jsx(oe,{variant:"outline",children:"Archived"})]}),e.jsx(ge,{children:l.host})]})},l.host))})]})]})}function q({newHost:s,setNewHost:o,newName:d,setNewName:g,createDefaults:r,setCreateDefaults:x,createPages:a,setCreatePages:m,createPosts:y,setCreatePosts:p,createSettings:t,setCreateSettings:n,addSampleContent:f,setAddSampleContent:h,onSubmit:j,isPending:S,scaffoldProgress:c}){const N=S||!!c;return e.jsxs(ie,{children:[e.jsxs(le,{children:[e.jsx(re,{children:"Create Site"}),e.jsx(ce,{className:"sr-only",children:"Enter details for the new site"})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"host",children:"Host"}),e.jsx(Y,{id:"host",placeholder:"example.com",value:s,onChange:i=>o(i.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"name",children:"Display Name"}),e.jsx(Y,{id:"name",placeholder:"My Site",value:d,onChange:i=>g(i.target.value)})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(b,{checked:r,onCheckedChange:i=>x(i===!0)}),"Create Default Collections"]}),r&&e.jsxs("div",{className:"ml-6 mt-3 space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:a,onCheckedChange:i=>m(i===!0)}),"Pages"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:y,onCheckedChange:i=>p(i===!0)}),"Posts"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(b,{checked:t,onCheckedChange:i=>n(i===!0)}),"Site Settings"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(b,{checked:f,onCheckedChange:i=>h(i===!0)}),"Add Sample Content"]})]})]})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all duration-300",style:{width:`${c.total>0?c.completed/c.total*100:0}%`},role:"progressbar","aria-valuenow":c.completed,"aria-valuemin":0,"aria-valuemax":c.total})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.label," ","(",c.completed,"/",c.total,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please wait while your site is being set up. Do not close this tab."})]}),e.jsx(de,{children:e.jsx(k,{onClick:j,disabled:!s.trim()||N,children:c?c.label:S?"Creating...":"Create"})})]})}export{Pe as SitesPage};
@@ -0,0 +1 @@
1
+ import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as F,f as B,r as L,L as C}from"./react-vendor-C2CvUxFh.js";import{j as S,m as O}from"./useContent-e8beBIuq.js";import{x as E,w as M,S as b,B as r,b3 as P,$ as U,a9 as z,D as H,i as V,T as Y,k as _,l as q,m as G,n as J,o as K,aa as Q,j as W,v as g}from"./index-Cir9tY_P.js";import{u as X}from"./usePageTitle-BNSba9_L.js";import{C as y,a as v,b as D,c as w}from"./card-hXVtlM0q.js";import{f as Z}from"./format-C88SDH8g.js";import{M as ss}from"./MediaField-J2TLG_fu.js";import"./radix-C1kb_NqW.js";import"./useMedia-e3sqWm_t.js";import"./select-_uJYxzeZ.js";import"./media-url-DIg_vSyf.js";function es({host:i,ref:t}){const c=!t.title&&!!t.contentId,{data:o}=S(i,c?t.contentId:""),d=c&&o?.content?o.content:null,u=t.title||d?.title||t.contentId,a=t.collection||d?.collection||"";return s.jsxs(C,{to:`/sites/${i}/content/${a}/${t.contentId}`,className:"flex items-center gap-3 rounded-md border p-2 transition-colors hover:bg-muted",children:[s.jsx(Q,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"flex-1 truncate text-sm",children:u}),a&&s.jsx(W,{variant:"secondary",children:a})]})}function us(){const{host:i,collection:t,id:c}=F(),o=B(),d=E(),{collections:u}=M(),{data:a,isLoading:$}=S(i,c),k=O(i,c),[T,p]=L.useState(!1),m=u.find(e=>e.name===t),f=m?.relationships??[];if(X({title:"Submission Detail",showBack:!0,backTo:`/sites/${i}/submissions/${t}`}),$)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(b,{className:"h-8 w-64"}),s.jsx(b,{className:"h-64 w-full"})]});if(!a?.content)return s.jsx("p",{className:"text-muted-foreground",children:"Submission not found."});const l=a.content,x=a.body??l.body,h=l.siteUser,j=l.relationships;function I(e,n){return n==null?"—":typeof n=="boolean"?n?"Yes":"No":Array.isArray(n)?n.join(", "):String(n)}async function R(){try{await k.mutateAsync(),g.success("Submission deleted"),o(`/sites/${i}/submissions/${t}`)}catch(e){g.error("Failed to delete",{description:e instanceof Error?e.message:void 0})}}const A=f.length>0&&j&&Object.keys(j).length>0;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!d&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>o(`/sites/${i}/submissions/${t}`),children:[s.jsx(P,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:"Submission Detail"}),s.jsx("div",{className:"ml-auto",children:s.jsxs(r,{variant:"outline",size:"sm",onClick:()=>o(`/sites/${i}/submissions/${t}/${c}/edit`),children:[s.jsx(U,{className:"mr-1.5 h-4 w-4"}),"Edit"]})})]}),s.jsxs(y,{children:[s.jsx(v,{children:s.jsx(D,{children:l.title||"Untitled"})}),s.jsxs(w,{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2 text-sm",children:[s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"ID"}),s.jsx("span",{className:"font-mono text-xs",children:l.contentId})]}),!!l.publishedAt&&s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Submitted"}),s.jsx("span",{children:Z(l.publishedAt)})]}),h&&s.jsxs("div",{className:"flex justify-between",children:[s.jsx("span",{className:"text-muted-foreground",children:"Submitted by"}),s.jsx(C,{to:`/sites/${i}/settings/site-users/${h.userId}`,className:"text-primary hover:underline",children:h.name||h.email})]})]}),s.jsx(z,{}),s.jsxs("div",{className:"space-y-3",children:[m?.fields?.map(e=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:e.label||e.name}),e.type==="media"?s.jsx(ss,{field:e,value:x?.[e.name],onChange:()=>{},disabled:!0}):s.jsx("p",{className:"text-sm whitespace-pre-wrap",children:I(e,x?.[e.name])})]},e.name)),(!m?.fields||m.fields.length===0)&&x&&s.jsx("div",{className:"space-y-3",children:Object.entries(x).map(([e,n])=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:e}),s.jsx("p",{className:"text-sm whitespace-pre-wrap",children:n==null?"—":String(n)})]},e))})]})]})]}),A&&s.jsxs(y,{className:"mt-6",children:[s.jsx(v,{children:s.jsx(D,{children:"Relationships"})}),s.jsx(w,{className:"space-y-4",children:f.map(e=>{const n=j?.[e.name]??[];return n.length===0?null:s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-sm font-medium",children:e.label}),s.jsx("div",{className:"space-y-2",children:n.map(N=>s.jsx(es,{host:i,ref:N},N.contentId))})]},e.name)})})]}),s.jsx("div",{className:"mt-6",children:s.jsxs(H,{open:T,onOpenChange:p,children:[s.jsx(V,{asChild:!0,children:s.jsxs(r,{variant:"destructive",children:[s.jsx(Y,{className:"mr-2 h-4 w-4"}),"Delete Submission"]})}),s.jsxs(_,{children:[s.jsxs(q,{children:[s.jsx(G,{children:"Delete submission?"}),s.jsx(J,{children:"This will permanently delete this submission."})]}),s.jsxs(K,{children:[s.jsx(r,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),s.jsx(r,{variant:"destructive",onClick:R,children:"Delete"})]})]})]})})]})}export{us as SubmissionDetailPage};
@@ -1 +1 @@
1
- import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as O,f as z,r as u}from"./react-vendor-C2CvUxFh.js";import{x as U,w as V,e as D,S as E,B as P,a$ as H,L as q,b0 as G,I as x,v as j}from"./index-wYNPRVrc.js";import{j as J,s as K,t as Q}from"./useContent-D8yDRTTy.js";import{u as W}from"./usePageTitle-Bwf-MpTD.js";import{T as X}from"./textarea-CHQ9tT69.js";import{C as Y}from"./checkbox-fC1QPb_4.js";import{S as Z,a as _,b as ee,c as se,d as te}from"./select-BV3jemT6.js";import{C as ae,a as ne,b as ie,c as oe}from"./card-10FqkZPA.js";import{M as re}from"./MediaField-Du7_gRse.js";import{R as ce}from"./RelationshipPicker-D7dFI43Q.js";import"./radix-C1kb_NqW.js";import"./useMedia-m6zKB__r.js";import"./media-url-DIg_vSyf.js";import"./core.esm-B_kcYf6n.js";import"./sortable.esm-QyXA6fio.js";import"./popover-BJDj8C6y.js";import"./command-BeacdV75.js";import"./useContentSearch-B-_p0_QX.js";import"./useDebouncedValue-C-cQUcLG.js";function Fe(){const{host:i,collection:c,id:m}=O(),b=z(),R=U(),{collections:A}=V(),o=!!m,d=A.find(t=>t.name===c),v=u.useMemo(()=>d?.relationships??[],[d?.relationships]),h=v.length>0,{data:p,isLoading:T}=J(i,m??""),S=D(),C=K(i),f=Q(i,m??""),[$,y]=u.useState({}),[w,N]=u.useState({}),[k,L]=u.useState(!o);W({title:o?"Edit Submission":"New Submission",showBack:!0,backTo:o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`});const I=u.useCallback(async t=>{const a={};for(const[e,n]of Object.entries(t))a[e]=await Promise.all(n.map(async r=>{if(r.title)return r;try{const g=await S.apiFetch(`/v1/admin/sites/${i}/content/${r.contentId}`);return{contentId:r.contentId,collection:g.content.collection??r.collection??"",slug:g.content.slug??r.slug??"",title:g.content.title??r.contentId}}catch{return r}}));return a},[S,i]);if(u.useEffect(()=>{if(o&&p&&!k){const t=p.body;t&&y({...t});const e=p.content?.relationships;e&&Object.keys(e).length>0&&I(e).then(N),L(!0)}},[o,p,k,I]),o&&T)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(E,{className:"h-8 w-64"}),s.jsx(E,{className:"h-64 w-full"})]});function l(t,a){y(e=>({...e,[t]:a}))}function M(t){const a=$[t.name];switch(t.type){case"text":return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)});case"textarea":return s.jsx(X,{value:a??"",onChange:e=>l(t.name,e.target.value),rows:4});case"number":return s.jsx(x,{type:"number",value:a!=null?String(a):"",onChange:e=>l(t.name,e.target.value===""?void 0:Number(e.target.value))});case"boolean":return s.jsx(Y,{checked:!!a,onCheckedChange:e=>l(t.name,!!e)});case"select":{const e=t.options?.choices??[];return s.jsxs(Z,{value:a??"",onValueChange:n=>l(t.name,n),children:[s.jsx(_,{children:s.jsx(ee,{placeholder:"Select..."})}),s.jsx(se,{children:e.map(n=>s.jsx(te,{value:n,children:n},n))})]})}case"array":return s.jsx(x,{value:Array.isArray(a)?a.join(", "):a??"",onChange:e=>l(t.name,e.target.value?e.target.value.split(",").map(n=>n.trim()):[]),placeholder:"Comma-separated values"});case"media":return s.jsx(re,{field:t,value:a,onChange:()=>{},disabled:!0});default:return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)})}}async function B(){const t={};for(const[e,n]of Object.entries($))n!==void 0&&n!==""&&(t[e]=n);const a={};if(h)for(const[e,n]of Object.entries(w))a[e]=n.map(r=>({contentId:r.contentId}));try{if(o)await f.mutateAsync({fields:t,...h?{relationships:a}:{}}),j.success("Submission updated"),b(`/sites/${i}/submissions/${c}/${m}`);else{const e=await C.mutateAsync({collection:c,fields:t,...h?{relationships:a}:{}});j.success("Submission created"),b(`/sites/${i}/submissions/${c}/${e.contentId}`)}}catch(e){const n=e instanceof Error?e.message:typeof e=="object"&&e!==null&&"message"in e?String(e.message):String(e);j.error(o?"Failed to update":"Failed to create",{description:n})}}const F=C.isPending||f.isPending;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!R&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>b(o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`),children:[s.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:o?"Edit Submission":"New Submission"})]}),s.jsxs(ae,{children:[s.jsx(ne,{children:s.jsx(ie,{children:d?.label??c})}),s.jsxs(oe,{className:"space-y-4",children:[d?.fields?.map(t=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(q,{htmlFor:`field-${t.name}`,children:t.label||t.name}),s.jsx("div",{id:`field-${t.name}`,children:M(t)})]},t.name)),s.jsx("div",{className:"pt-4",children:s.jsxs(P,{onClick:B,disabled:F,children:[s.jsx(G,{className:"mr-1.5 h-4 w-4"}),F?"Saving...":o?"Update":"Create"]})})]})]}),h&&s.jsx("div",{className:"mt-6",children:s.jsx(ce,{relationships:v,values:w,onChange:N,host:i})})]})}export{Fe as SubmissionEditPage};
1
+ import{j as s}from"./tanstack-Bs3zYPPV.js";import{u as O,f as z,r as u}from"./react-vendor-C2CvUxFh.js";import{x as U,w as V,e as D,S as E,B as P,b3 as H,L as q,b4 as G,I as x,v as j}from"./index-Cir9tY_P.js";import{j as J,s as K,t as Q}from"./useContent-e8beBIuq.js";import{u as W}from"./usePageTitle-BNSba9_L.js";import{T as X}from"./textarea-vSXNxwTe.js";import{C as Y}from"./checkbox-WGrS3sUr.js";import{S as Z,a as _,b as ee,c as se,d as te}from"./select-_uJYxzeZ.js";import{C as ae,a as ne,b as ie,c as oe}from"./card-hXVtlM0q.js";import{M as re}from"./MediaField-J2TLG_fu.js";import{R as ce}from"./RelationshipPicker-CDFs4TMW.js";import"./radix-C1kb_NqW.js";import"./useMedia-e3sqWm_t.js";import"./media-url-DIg_vSyf.js";import"./core.esm-B_kcYf6n.js";import"./sortable.esm-QyXA6fio.js";import"./popover-D5_HjjUC.js";import"./command-fvBFHye4.js";import"./useContentSearch-DOjveB9t.js";import"./useDebouncedValue-C-cQUcLG.js";function Fe(){const{host:i,collection:c,id:m}=O(),b=z(),R=U(),{collections:A}=V(),o=!!m,d=A.find(t=>t.name===c),v=u.useMemo(()=>d?.relationships??[],[d?.relationships]),h=v.length>0,{data:p,isLoading:T}=J(i,m??""),S=D(),C=K(i),f=Q(i,m??""),[y,$]=u.useState({}),[w,N]=u.useState({}),[k,L]=u.useState(!o);W({title:o?"Edit Submission":"New Submission",showBack:!0,backTo:o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`});const I=u.useCallback(async t=>{const a={};for(const[e,n]of Object.entries(t))a[e]=await Promise.all(n.map(async r=>{if(r.title)return r;try{const g=await S.apiFetch(`/v1/admin/sites/${i}/content/${r.contentId}`);return{contentId:r.contentId,collection:g.content.collection??r.collection??"",slug:g.content.slug??r.slug??"",title:g.content.title??r.contentId}}catch{return r}}));return a},[S,i]);if(u.useEffect(()=>{if(o&&p&&!k){const t=p.body;t&&$({...t});const e=p.content?.relationships;e&&Object.keys(e).length>0&&I(e).then(N),L(!0)}},[o,p,k,I]),o&&T)return s.jsxs("div",{className:"space-y-4",children:[s.jsx(E,{className:"h-8 w-64"}),s.jsx(E,{className:"h-64 w-full"})]});function l(t,a){$(e=>({...e,[t]:a}))}function M(t){const a=y[t.name];switch(t.type){case"text":return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)});case"textarea":return s.jsx(X,{value:a??"",onChange:e=>l(t.name,e.target.value),rows:4});case"number":return s.jsx(x,{type:"number",value:a!=null?String(a):"",onChange:e=>l(t.name,e.target.value===""?void 0:Number(e.target.value))});case"boolean":return s.jsx(Y,{checked:!!a,onCheckedChange:e=>l(t.name,!!e)});case"select":{const e=t.options?.choices??[];return s.jsxs(Z,{value:a??"",onValueChange:n=>l(t.name,n),children:[s.jsx(_,{children:s.jsx(ee,{placeholder:"Select..."})}),s.jsx(se,{children:e.map(n=>s.jsx(te,{value:n,children:n},n))})]})}case"array":return s.jsx(x,{value:Array.isArray(a)?a.join(", "):a??"",onChange:e=>l(t.name,e.target.value?e.target.value.split(",").map(n=>n.trim()):[]),placeholder:"Comma-separated values"});case"media":return s.jsx(re,{field:t,value:a,onChange:()=>{},disabled:!0});default:return s.jsx(x,{value:a??"",onChange:e=>l(t.name,e.target.value)})}}async function B(){const t={};for(const[e,n]of Object.entries(y))n!==void 0&&n!==""&&(t[e]=n);const a={};if(h)for(const[e,n]of Object.entries(w))a[e]=n.map(r=>({contentId:r.contentId}));try{if(o)await f.mutateAsync({fields:t,...h?{relationships:a}:{}}),j.success("Submission updated"),b(`/sites/${i}/submissions/${c}/${m}`);else{const e=await C.mutateAsync({collection:c,fields:t,...h?{relationships:a}:{}});j.success("Submission created"),b(`/sites/${i}/submissions/${c}/${e.contentId}`)}}catch(e){const n=e instanceof Error?e.message:typeof e=="object"&&e!==null&&"message"in e?String(e.message):String(e);j.error(o?"Failed to update":"Failed to create",{description:n})}}const F=C.isPending||f.isPending;return s.jsxs("div",{className:"mx-auto max-w-2xl",children:[!R&&s.jsxs("div",{className:"mb-6 flex items-center gap-4",children:[s.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>b(o?`/sites/${i}/submissions/${c}/${m}`:`/sites/${i}/submissions/${c}`),children:[s.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Back"]}),s.jsx("h1",{className:"text-2xl font-semibold",children:o?"Edit Submission":"New Submission"})]}),s.jsxs(ae,{children:[s.jsx(ne,{children:s.jsx(ie,{children:d?.label??c})}),s.jsxs(oe,{className:"space-y-4",children:[d?.fields?.map(t=>s.jsxs("div",{className:"space-y-2",children:[s.jsx(q,{htmlFor:`field-${t.name}`,children:t.label||t.name}),s.jsx("div",{id:`field-${t.name}`,children:M(t)})]},t.name)),s.jsx("div",{className:"pt-4",children:s.jsxs(P,{onClick:B,disabled:F,children:[s.jsx(G,{className:"mr-1.5 h-4 w-4"}),F?"Saving...":o?"Update":"Create"]})})]})]}),h&&s.jsx("div",{className:"mt-6",children:s.jsx(ce,{relationships:v,values:w,onChange:N,host:i})})]})}export{Fe as SubmissionEditPage};