1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8805],{688:(e,t,a)=>{"use strict";a.d(t,{s:()=>n});var i=a(7778);function n(e){let{className:t,color:a}=e,n=a||"#A1A1AA",r="#000000"===n.toLowerCase()?{className:"fill-black dark:fill-white"}:{fill:n};return(0,i.jsxs)("svg",{viewBox:"0 0 24 24",className:t,xmlns:"http://www.w3.org/2000/svg",children:[(0,i.jsx)("path",{d:"M4 4 C2.89543 4 2 4.89543 2 6 V18 C2 19.1046 2.89543 20 4 20 H20 C21.1046 20 22 19.1046 22 18 V8 C22 6.89543 21.1046 6 20 6 H12 L10.4142 4.41421 C10.0391 4.03914 9.53043 4 9 4 H4 Z",...r}),(0,i.jsx)("path",{d:"M 3.5 8.5 A 1 1 0 0 1 4.5 7.5 H 19.5 A 1 1 0 0 1 20.5 8.5 V 17.5 A 1 1 0 0 1 19.5 18.5 H 4.5 A 1 1 0 0 1 3.5 17.5 Z",...r})]})}a(85418)},3611:(e,t,a)=>{"use strict";a.r(t),a.d(t,{CreatePostDialog:()=>i.CreatePostDialog});var i=a(19958)},9463:(e,t,a)=>{"use strict";a.d(t,{d:()=>n});var i=a(28067);let n=(0,i.createServerReference)("709f411fd923fa47861a7929497cc1649eae031860",i.callServer,void 0,i.findSourceMapURL,"completeMultipartUpload")},9716:(e,t,a)=>{"use strict";a.d(t,{W:()=>n});var i=a(28067);let n=(0,i.createServerReference)("601ca48289080c4d51a1b0c1c45636ecb113476d71",i.callServer,void 0,i.findSourceMapURL,"abortMultipartUpload")},11759:(e,t,a)=>{"use strict";a.d(t,{BL:()=>m,BP:()=>h,D1:()=>p});var i=a(7778);a(85418);var n=a(11576),r=a(66467),l=a(25065),s=a(3295),o=a(29140),d=a(4327);let c={FACEBOOK:"bg-[#1877F2]",INSTAGRAM:"bg-gradient-to-r from-purple-500 to-pink-500",INSTAGRAM_DIRECT:"bg-gradient-to-r from-purple-500 to-pink-500",LINKEDIN:"bg-[#0077B5]",LINKEDIN_ORGANIZATION:"bg-[#0077B5]",X:"bg-black",THREADS:"bg-black",MASTODON:"bg-[#6364FF]",BLUESKY:"bg-[#0085FF]",PINTEREST:"bg-[#E60023]",YOUTUBE:"bg-[#FF0000]",TIKTOK:"bg-black",TELEGRAM:"bg-[#229ED9]",GOOGLE_BUSINESS:"bg-white"},u={FACEBOOK:s.iY,INSTAGRAM:s.ao,INSTAGRAM_DIRECT:s.ao,LINKEDIN:s.QE,LINKEDIN_ORGANIZATION:s.QE,X:s.TC,THREADS:d.qX,MASTODON:s.hH,BLUESKY:d.o4,PINTEREST:s.oC,YOUTUBE:s.Vk,TIKTOK:s.kk,TELEGRAM:s.hF,GOOGLE_BUSINESS:o.$};function m(e){let{platform:t,className:a,iconClassName:n}=e,s=u[t];return(0,i.jsx)("span",{className:(0,l.cn)("flex h-8 w-8 shrink-0 items-center justify-center rounded-full",t===r.SocialPlatform.GOOGLE_BUSINESS?"text-[#4285F4] ring-1 ring-border":"text-white",c[t],a),children:(0,i.jsx)(s,{className:(0,l.cn)("h-4 w-4",n)})})}function h(e){let{platform:t,className:a,size:n="default"}=e,s=u[t];return(0,i.jsx)("span",{className:(0,l.cn)("flex shrink-0 items-center justify-center rounded-full",t===r.SocialPlatform.GOOGLE_BUSINESS?"text-[#4285F4] ring-1 ring-border":"text-white","sm"===n?"h-7 w-7":"h-9 w-9",c[t],a),children:(0,i.jsx)(s,{className:"sm"===n?"h-4 w-4":"h-5 w-5"})})}function p(e,t,a){var r;let l="h-".concat(4," w-").concat(4),d=t?"".concat(l," ").concat(t):l,c={facebook:(0,i.jsx)(n.F.facebook,{className:d}),instagram:(0,i.jsx)(n.F.instagram,{className:d}),instagram_direct:(0,i.jsx)(n.F.instagram,{className:d}),linkedin:(0,i.jsx)(n.F.linkedin,{className:d}),linkedin_organization:(0,i.jsx)(n.F.linkedin,{className:d}),x:(0,i.jsx)(n.F.twitter,{className:d}),twitter:(0,i.jsx)(n.F.twitter,{className:d}),threads:(0,i.jsx)(n.F.threads,{className:d}),mastodon:(0,i.jsx)(n.F.mastodon,{className:d}),bluesky:(0,i.jsx)(n.F.bluesky,{className:d}),pinterest:(0,i.jsx)(n.F.pinterest,{className:d}),youtube:(0,i.jsx)(n.F.youtube,{className:d}),tiktok:(0,i.jsx)(n.F.tiktok,{className:d}),telegram:(0,i.jsx)(s.hF,{className:d}),google_business:(0,i.jsx)(o.$,{className:d}),other:(0,i.jsx)(n.F.helpCircle,{className:d})};return c[null==e||null==(r=e.toLowerCase)?void 0:r.call(e)]||c.other}},15033:(e,t,a)=>{"use strict";a.d(t,{Ks:()=>c,NS:()=>l,Z0:()=>d,eN:()=>i,hT:()=>r,kh:()=>n});let i=new Set(["image/jpeg","image/jpg","image/png","image/gif","video/mp4","video/quicktime"]),n=Array.from(i),r=0x3200000,l=524288e3,s=["image/jpeg","image/png"],o=["video/mp4","video/quicktime"];function d(e,t){let a=null==e?void 0:e.trim();if(a&&"application/octet-stream"!==a)return a;let i=(t||"").toLowerCase();return i.endsWith(".mov")||i.includes(".mov?")?"video/quicktime":i.endsWith(".mp4")||i.includes(".mp4?")?"video/mp4":i.endsWith(".gif")?"image/gif":i.endsWith(".png")?"image/png":i.endsWith(".jpg")||i.endsWith(".jpeg")?"image/jpeg":a||"application/octet-stream"}function c(e){return e.startsWith("image/")?s:e.startsWith("video/")?o:[]}[...s,...o]},18962:(e,t,a)=>{"use strict";a.d(t,{J:()=>tw});var i=a(7778),n=a(85418),r=a(20389),l=a(94340),s=a(27169),o=a(50330),d=a(42749),c=a(52766),u=a(50749),m=a(12882),h=a(3575),p=a(62374),f=a(85191),x=a(16323),g=a(7120),v=a(12777),b=a(6478),y=a(13078),w=a(3100),j=a(15055),C=a(51157),N=(a(6328),a(25065));let S=n.forwardRef((e,t)=>
1{let{...a}=e;return(0,i.jsx)("nav",{ref:t,"aria-label":"breadcrumb",...a})});S.displayName="Breadcrumb";let k=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)("ol",{ref:t,className:(0,N.cn)("flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground",a),...n})});k.displayName="BreadcrumbList";let T=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)("li",{ref:t,className:(0,N.cn)("inline-flex items-center gap-1.5",a),...n})});T.displayName="BreadcrumbItem",n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)("a",{ref:t,className:(0,N.cn)("hover:text-foreground transition-colors",a),...n})}).displayName="BreadcrumbLink",n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)("span",{ref:t,role:"link","aria-disabled":"true","aria-current":"page",className:(0,N.cn)("font-normal text-foreground",a),...n})}).displayName="BreadcrumbPage";let E=n.forwardRef((e,t)=>{let{children:a,className:n,...r}=e;return(0,i.jsx)("span",{ref:t,role:"presentation","aria-hidden":"true",className:(0,N.cn)("[&>svg]:size-3.5",n),...r,children:null!=a?a:(0,i.jsx)(C.A,{})})});E.displayName="BreadcrumbSeparator";var I=a(44367),A=a(28863),P=a(19873),M=a(55754),D=a(3854),R=a(31194),F=a(79536),O=a(688);let z=[{name:"Theme Default",value:"bg-gradient-to-br from-black to-white",hex:"#000000"},{name:"Blue",value:"bg-blue-200",hex:"#bfdbfe"},{name:"Green",value:"bg-green-200",hex:"#bbf7d0"},{name:"Yellow",value:"bg-yellow-200",hex:"#fef08a"},{name:"Red",value:"bg-red-200",hex:"#fecdd3"},{name:"Purple",value:"bg-purple-200",hex:"#e9d5ff"},{name:"Pink",value:"bg-pink-200",hex:"#fbcfe8"},{name:"Indigo",value:"bg-indigo-200",hex:"#c7d2fe"}];function L(e){let{open:t,onOpenChange:a,onFolderCreated:l,folderHierarchy:d,initialFolderId:c}=e,u=(0,r.useTranslations)("Media"),m=(0,s.useSearchParams)(),[h,p]=(0,n.useState)(""),[f,x]=(0,n.useState)(z[0]),[g,v]=(0,n.useState)(c||m.get("folderId")||null),[b,y]=(0,n.useState)(!1),[w,j]=(0,n.useState)(null),C=(0,n.useRef)(null);(0,n.useEffect)(()=>{t?(p(""),x(z[0]),v(c||m.get("folderId")||null),j(null)):y(!1)},[t,m,c]);let S=async e=>{if(e.preventDefault(),!h.trim())return void j(u("validation.folderNameRequired"));y(!0),j(null);try{let e=await (0,R.Lf)({name:h.trim(),parentId:g||void 0,color:f.hex});e.error?(console.error("[CreateFolderDialog] Failed createFolderViaApi:",e.error),j(e.error)):e.data?(l(e.data),a(!1)):(console.error("[CreateFolderDialog] createFolderViaApi succeeded but returned no data."),j(u("errors.unknownError")||"An unknown error occurred."))}catch(e){console.error("[CreateFolderDialog] Exception calling createFolderViaApi:",e),j(e instanceof Error?e.message:u("errors.folderCreationFailed")||"Failed to create folder")}finally{y(!1)}};return(0,i.jsx)(D.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(D.Cf,{className:"sm:max-w-[500px]",onOpenAutoFocus:e=>{var t;e.preventDefault(),null==(t=C.current)||t.focus()},children:[(0,i.jsx)(D.c7,{children:(0,i.jsx)(D.L3,{children:u("createFolderTitle")})}),(0,i.jsxs)("form",{onSubmit:S,children:[(0,i.jsxs)("div",{className:"grid gap-6 py-6",children:[(0,i.jsxs)("div",{className:"grid gap-2",children:[(0,i.jsx)(F.J,{htmlFor:"name",children:u("nameLabel")}),(0,i.jsx)(M.p,{id:"name",ref:C,value:h,onChange:e=>p(e.target.value),placeholder:u("folderNamePlaceholder")||"Folder Name",required:!0})]}),(0,i.jsxs)("div",{className:"grid gap-2",children:[(0,i.jsx)(F.J,{htmlFor:"parentFolder",children:u("folderLocationLabel")}),(0,i.jsx)(P.D,{value:g,onChange:v,folderHierarchy:d})]}),(0,i.jsxs)("div",{className:"grid gap-3",children:[(0,i.jsx)(F.J,{children:u("colorLabel")}),(0,i.jsx)("div",{className:"grid grid-cols-4 gap-3 sm:grid-cols-8",children:z.map(e=>(0,i.jsxs)(o.$,{type:"button",variant:"ghost",size:"icon",className:(0,N.cn)("h-12 w-12 p-1.5",f.value===e.value?"ring-2 ring-primary":"hover:bg-accent"),onClick:()=>x(e),children:[(0,i.jsx)(O.s,{className:"h-full w-full",color:e.hex}),(0,i.jsx)("span",{className:"sr-only",children:e.name})]},e.name))})]}),w&&(0,i.jsx)("div",{className:"text-destructive text-sm",children:w})]}),(0,i.jsxs)(D.Es,{children:[(0,i.jsx)(o.$,{variant:"outline",type:"button",onClick:()=>a(!1),disabled:b,children:u("cancel")}),(0,i.jsx)(o.$,{type:"submit",disabled:b||!h.trim(),children:b?u("creating")||"Creating...":u("create")})]})]})]})})}var U=a(57783),_=a(95609),B=a(20362);function K(e){var t;let{onClick:a,onUpgradeClick:l,disabled:s}=e,d=(0,r.useTranslations)("Media"),{canUploadMedia:c,usage:u,limits:m,isLoading:h}
1=(0,_.Q)(),[p,f]=(0,n.useState)(!1),x=(null==u?void 0:u.mediaStorageMB)||0,g=(null==m||null==(t=m.media_storage)?void 0:t.max)||null,v=g&&x>=g;return(0,n.useEffect)(()=>{if(p&&!h){if(f(!1),v){l&&l();return}c?a():l&&l()}},[p,h,v,c,a,l]),(0,i.jsxs)(i.Fragment,{children:[p&&(0,i.jsx)(B.W,{withBlur:!0}),(0,i.jsxs)(o.$,{variant:"outline",onClick:()=>{if(h)return void f(!0);if(v){l&&l();return}c?a():l&&l()},disabled:s||p,children:[(0,i.jsxs)("svg",{className:"h-5 w-8",viewBox:"75 342.6 434 139.1",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"canva-gradient",gradientUnits:"userSpaceOnUse",x1:"75.6711",y1:"412.9916",x2:"493.0198",y2:"407.3517",children:[(0,i.jsx)("stop",{offset:"0",stopColor:"#04BDCD"}),(0,i.jsx)("stop",{offset:"6.735983e-002",stopColor:"#10A9D3"}),(0,i.jsx)("stop",{offset:"0.172",stopColor:"#2883DE"}),(0,i.jsx)("stop",{offset:"0.5026",stopColor:"#2D7BE1"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#7D2AE7"})]})}),(0,i.jsx)("path",{fill:"url(#canva-gradient)",d:"M505.8,437.8c-0.7,0-1.4,0.5-1.7,1.4c-4.4,12.7-10.5,20.2-15.4,20.2c-2.8,0-4-3.2-4-8.2 c0-12.4,7.4-38.7,11.2-50.8c0.4-1.4,0.7-2.7,0.7-3.8c0-3.5-1.9-5.2-6.7-5.2c-5.1,0-10.6,2-15.9,11.3c-1.8-8.2-7.4-11.9-15.2-11.9 c-9,0-17.7,5.8-24.9,15.2c-7.2,9.4-15.5,12.5-21.9,10.9c4.6-11.1,6.2-19.4,6.2-25.7c0-9.7-4.8-15.5-12.5-15.5 c-11.8,0-18.6,11.2-18.6,23.1c0,9.1,4.1,18.5,13.2,23.1c-7.7,17.3-18.8,32.9-23,32.9c-5.5,0-7.1-26.7-6.8-45.8 c0.2-11,1.1-11.6,1.1-14.9c0-1.9-1.2-3.2-6.2-3.2c-11.6,0-15.2,9.8-15.7,21c-0.1,4.3-0.9,8.5-2,12.7C343,441.9,333,455,326.5,455 c-3,0-3.8-3-3.8-6.9c0-12.4,6.9-28,6.9-41.2c0-9.8-4.3-15.9-12.3-15.9c-9.5,0-22,11.3-33.9,32.4c3.9-16.2,5.5-31.8-6.1-31.8 c-2.5,0.1-5,0.7-7.2,1.9c-1.5,0.7-2.5,2.2-2.3,4c1.1,17.2-13.9,61.3-28,61.3c-2.6,0-3.8-2.8-3.8-7.3c0-12.4,7.4-38.7,11.1-50.7 c0.5-1.6,0.7-2.9,0.7-4c0-3.3-2-5-6.7-5c-5.1,0-10.6,2-15.9,11.3c-1.9-8.2-7.4-11.9-15.3-11.9c-12.8,0-27,13.5-33.3,31.1 c-8.4,23.5-25.3,46.2-48.1,46.2c-20.7,0-31.6-17.2-31.6-44.4c0-39.3,28.8-71.3,50.2-71.3c10.2,0,15.1,6.5,15.1,16.5 c0,12.1-6.7,17.7-6.7,22.3c0,1.4,1.2,2.8,3.5,2.8c9.3,0,20.2-10.9,20.2-25.8c0-14.9-12.1-25.7-33.5-25.7c-35.3,0-70.8,35.5-70.8,81 c0,36.2,17.9,58.1,48.8,58.1c21.1,0,39.5-16.4,49.4-35.5c1.2,15.8,8.3,24.1,19.3,24.1c9.8,0,17.6-5.8,23.7-16 c2.3,10.7,8.5,15.9,16.5,15.9c9.2,0,16.8-5.8,24.1-16.6c-0.1,8.5,1.8,16.5,9.2,16.5c3.5,0,7.6-0.8,8.3-3.8 c7.7-32,26.9-58.1,32.7-58.1c1.7,0,2.2,1.7,2.2,3.6c0,8.7-6.1,26.5-6.1,37.9c0,12.3,5.2,20.5,16,20.5c12,0,24.1-14.7,32.2-36.1 c2.5,20,8,36.1,16.6,36.1c10.6,0,29.3-22.2,40.6-45.7c4.4,0.6,11.1,0.4,17.6-4.1c-2.7,6.9-4.3,14.5-4.3,22 c0,21.8,10.4,27.9,19.4,27.9c9.8,0,17.6-5.8,23.7-16c2,9.3,7.1,15.9,16.5,15.9c14.7,0,27.4-15,27.4-27.3 C508.8,439.7,507.4,437.8,505.8,437.8z M201.5,458.3c-5.9,0-8.2-6-8.2-14.8c0-15.5,10.6-41.2,21.8-41.2c4.8,0,6.7,5.7,6.7,12.8 C221.8,430.7,211.7,458.3,201.5,458.3z M404.3,412.3c-3.5-4.2-4.8-9.9-4.8-15c0-6.3,2.3-11.6,5.1-11.6s3.6,2.7,3.6,6.5 C408.1,398.4,405.9,407.6,404.3,412.3z M450.2,458.3c-5.9,0-8.2-6.9-8.2-14.8c0-14.9,10.6-41.2,21.8-41.2c4.9,0,6.6,5.7,6.6,12.8 C470.4,430.7,460.5,458.3,450.2,458.3z"})]}),(0,i.jsx)("span",{className:"sr-only sm:not-sr-only sm:whitespace-nowrap",children:d("canva.import")})]})]})}var G=a(73367),W=a(39427),V=a(18545),q=a(73431),H=a(95258),$=a(93832),Y=a(43945),X=a(72374),Z=a(36088),J=a(19348),Q=a(11357),ee=a(42128),et=a(96116);async function ea(e){if(e.type.startsWith("video/")||e.name.toLowerCase().endsWith(".mov")||e.name.toLowerCase().endsWith(".mp4"))return new Promise(t=>{let a=document.createElement("video");a.preload="metadata",a.onloadedmetadata=()=>{let e=Math.round(a.duration);URL.revokeObjectURL(a.src);try{a.src="",a.load(),a.onloadedmetadata=null,a.onerror=null}catch(e){}t(e)},a.onerror=()=>{URL.revokeObjectURL(a.src);try{a.src="",a.load(),a.onloadedmetadata=null,a.onerror=null}catch(e){}t(void 0)},a.src=URL.createObjectURL(e)})}async function ei(e){return e.type.startsWith("video/")||e.name.toLowerCase().endsWith(".mov")||e.name.toLowerCase().endsWith(".mp4")?new Promise(t=>{let a=document.createElement("video");a.preload="metadata",a.onloadedmetadata=()=>{let e=a.videoWidth||void 0,i=a.videoHeight||void 0;URL.revokeObjectURL(a.src);try{a.src="",a.load(),a.onloadedmetadata=null,a.onerror=null}catch(e){}t({width:e,height:i})},a.onerror=()=>{URL.revokeObjectURL(a.src);try{a.src="",a.load(),a.onloadedmetadata=null,a.onerror=null}catch(e){}t({})},a.src=URL.createObjectURL(e)}):{}}async function en(e){return e.type.startsWith("image/")?new Promise(t=>{let a=document.createElement("img");a.onload=()=>
1{let e=a.naturalWidth||void 0,i=a.naturalHeight||void 0;URL.revokeObjectURL(a.src);try{a.src="",a.onload=null,a.onerror=null}catch(e){}t({width:e,height:i})},a.onerror=()=>{URL.revokeObjectURL(a.src);try{a.src="",a.onload=null,a.onerror=null}catch(e){}t({})},a.src=URL.createObjectURL(e)}):{}}async function er(e,t){let a=await fetch(e);if(!a.ok)throw Error("Failed to download file: ".concat(a.status," ").concat(a.statusText));let i=await a.blob(),n=a.headers.get("content-type")||i.type||"application/octet-stream";return new File([i],t,{type:n})}async function el(e,t,a){let i=await (0,ee.X)(t,e.type);if(i.error||!i.data)throw Error(i.error||"Failed to get presigned URL");let n=await fetch(i.data.url,{method:"PUT",body:e,headers:{"Content-Type":e.type}});if(!n.ok)throw Error("Failed to upload to R2: ".concat(n.status," ").concat(n.statusText));let r="https://".concat("media.dopost.co","/").concat(i.data.key);return{key:i.data.key,url:r}}async function es(e,t,a,i,n,r,l){let s,o,d,c,u;null==l||l(0,"Downloading files...");let m=t?t.replace(/[^a-zA-Z0-9\s-]/g,"").replace(/\s+/g,"-").toLowerCase().substring(0,100):"canva-design",h=e.includes(".mp4")?"mp4":e.includes(".jpg")||e.includes(".jpeg")?"jpg":"png",p=i>1?"".concat(a,"-").concat(m,".").concat(h):"".concat(m,".").concat(h),f=await er(e,p);if(null==l||l(25,"Downloading files..."),f.type.startsWith("video/")){let e=await ei(f);s=e.width,o=e.height,d=await ea(f)}else if(f.type.startsWith("image/")){let e=await en(f);s=e.width,o=e.height}null==l||l(50,"Processing and saving to gallery...");let{key:x,url:g}=await el(f,p,n);null==l||l(75,"Processing and saving to gallery...");try{let e=await (0,et.Gn)(f);if(e.success&&e.blob){let t=await (0,et.Jm)(e.blob,x,ee.X);t.success&&t.thumbnailUrl&&t.thumbnailKey&&(c=t.thumbnailUrl,u=t.thumbnailKey)}}catch(e){}return null==l||l(100,"Finalizing import..."),{name:p,url:g,type:f.type,folderId:r,storageKey:x,sizeInBytes:f.size,width:s,height:o,durationSeconds:d,thumbnailUrl:c,thumbnailStorageKey:u}}var eo=a(28067);let ed=(0,eo.createServerReference)("406cb96a5c557554b6acfe2fb8d45db119fd4e2b12",eo.callServer,void 0,eo.findSourceMapURL,"createBatchMediaRecords");var ec=a(92919),eu=a(30605),em=a(56354),eh=a(36311),ep=a(88697);function ef(e){let{onLogoutSuccess:t,align:a="start"}=e,l=(0,r.useTranslations)("Media"),[s,d]=(0,n.useState)(null),[c,u]=(0,n.use
1State)(!0),[m,h]=(0,n.useState)(!1),p=(0,n.useCallback)(async()=>{try{u(!0);let t=await fetch("/api/canva/me");if(t.ok){let a=await t.json(),i={id:"me"};if(a.profile){var e;i={id:(null==(e=a.team_user)?void 0:e.user_id)||"me",display_name:a.profile.display_name}}else a.user?i={...a.user}:a.id?i={...a}:a.team_user&&(i={id:a.team_user.user_id,display_name:"Connected"});d(i)}}catch(e){console.error("Error fetching Canva user:",e)}finally{u(!1)}},[]);(0,n.useEffect)(()=>{p()},[p]);let f=async()=>{h(!1);try{let e=await fetch("/api/canva/logout",{method:"POST",headers:{"Content-Type":"application/json"}});if(e.ok)d(null),H.oR.success(l("canva.logoutSuccess")||"Logged out from Canva"),t();else{let t=(await e.json().catch(()=>({}))).error||"Failed to disconnect Canva account";H.oR.error(t)}}catch(e){H.oR.error("Failed to disconnect Canva account")}};return(0,i.jsxs)(ec.rI,{children:[(0,i.jsx)(ec.ty,{asChild:!0,children:(0,i.jsxs)(o.$,{variant:"ghost",size:"sm",className:"flex items-center gap-2 px-2 h-8 hover:bg-background rounded-full border border-border/40 transition-all group shrink-0",children:[(0,i.jsx)("div",{className:"h-5 w-5 rounded-full overflow-hidden flex items-center justify-center shrink-0 shadow-sm",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#pill_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#pill_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#pill_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#pill_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"pill_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"pill_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"pill_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"pill_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),c?(0,i.jsx)(eh.E,{className:"h-3 w-16 rounded flex-shrink-0"}):(0,i.jsx)("span",{className:"text-[10px] font-bold text-foreground leading-none truncate max-w-[100px] uppercase tracking-tight",children:(null==s?void 0:s.display_name)||l("canva.connected")||"Connected"}),(0,i.jsx)(eu.A,{className:"h-3 w-3 text-muted-foreground shrink-0"})]})}),(0,i.jsxs)(ec.SQ,{align:a,className:"w-[200px]",children:[(0,i.jsxs)("div",{className:"px-2 py-2 border-b border-border/40 mb-1",children:[(0,i.jsx)("div",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider mb-0.5",children:"Canva Account"}),c?(0,i.jsx)(eh.E,{className:"h-4 w-16 rounded"}):(0,i.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:(null==s?void 0:s.display_name)||"Connected"})]}),(0,i.jsxs)(ec._2,{onClick:()=>h(!0),className:"text-destructive focus:text-destructive cursor-pointer py-2",children:[(0,i.jsx)(em.A,{className:"h-4 w-4 mr-2"}),(0,i.jsx)("span",{className:"font-medium text-xs",children:l("canva.logout")})]})]}),(0,i.jsx)(ep.Lt,{open:m,onOpenChange:h,children:(0,i.jsxs)(ep.EO,{children:[(0,i.jsxs)(ep.wd,{children:[(0,i.jsx)(ep.r7,{children:l("canva.logoutConfirm.title")}),(0,i.jsx)(ep.$v,{children:l("canva.logoutConfirm.description")})]}),(0,i.jsxs)(ep.ck,{children:[(0,i.jsx)(ep.Zr,{onClick:()=>h(!1),children:l("canva.logoutConfirm.cancel")}),(0,i.jsx)(ep.Rx,{onClick:f,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:l("canva.logoutConfirm.confirm")})]})]})})]})}let ex=()=>(0,i.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,i.jsx)("div",{className:"aspect-square w-full rounded-lg bg-skeleton animate-pulse"}),(0,i.jsx)("div",{className:"px-1",children:(0,i.jsx)("div",{className:"h-3 w-full bg-skeleton animate-pulse rounded"})})]});function eg(e){var t,a;let{open:s,onOpenChange:c,onImportComplete:u,folderId:m,folderHierarchy:h=[]}
1=e,p=(0,r.useTranslations)("Media"),[x,g]=(0,n.useState)([]),[v,b]=(0,n.useState)([]),[y,w]=(0,n.useState)(!1),[j,S]=(0,n.useState)(!1),[k,T]=(0,n.useState)(null),[E,I]=(0,n.useState)(!1),[A,R]=(0,n.useState)(0),[F,O]=(0,n.useState)(null),[z,L]=(0,n.useState)(null),[U,B]=(0,n.useState)(m||null),[K,ee]=(0,n.useState)("PNG"),[et,ea]=(0,n.useState)(""),[ei,en]=(0,n.useState)(""),[er,el]=(0,n.useState)(null),[eo,ec]=(0,n.useState)([]),[eu,em]=(0,n.useState)(""),[eh,ep]=(0,n.useState)(null),eg=(0,Z.d)(eu,900),ev=(0,n.useRef)(null),eb=(0,n.useRef)(!1),ey=e=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},{workspace:ew}=(0,Q.k)(),ej=(null==ew?void 0:ew.id)||"",{usage:eC,limits:eN,isLoading:eS}=(0,_.Q)(),{onMediaUploaded:ek}=(0,J.f)(),eT=(null==eC?void 0:eC.mediaStorageMB)||0,eE=(null==eN||null==(t=eN.media_storage)?void 0:t.max)||null,eI=eE&&eE>0?eT/eE*100:0;(0,n.useEffect)(()=>{if(k)if(k.isVideo){ee("MP4");let e=k.thumbnail;(null==e?void 0:e.width)&&(null==e?void 0:e.height)?ea(e.width>=e.height?"horizontal_1080p":"vertical_1080p"):ea("horizontal_1080p")}else ee("PNG"),ea("")},[k]),(0,n.useEffect)(()=>{if("MP4"===K&&!et&&k){let e=k.thumbnail;(null==e?void 0:e.width)&&(null==e?void 0:e.height)?ea(e.width>=e.height?"horizontal_1080p":"vertical_1080p"):ea("horizontal_1080p")}else"MP4"!==K&&ea("")},[K,et,k]),(0,n.useEffect)(()=>{void 0!==m&&B(m)},[m]);let eA=(0,n.useCallback)(async function(){let{mode:e="replace",continuationToken:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a="append"===e;a?S(!0):w(!0),O(null);try{let e="";e=eg?"/api/canva/designs?query=".concat(encodeURIComponent(eg),"&limit=").concat(12):er?"/api/canva/folders/".concat(er,"/items?limit=").concat(12):"/api/canva/designs?limit=".concat(12),a&&t&&(e+=(e.includes("?")?"&":"?")+"continuation=".concat(t));let i=await fetch(e);if(!i.ok){if(401===i.status)return void L(!1);let e=await i.json().catch(()=>({}));throw Error(e.error||"Failed to load designs")}let n=await i.json(),r=[],l=[],s=null;if(eg||!er){let e=n.items||n.designs||[];r=Array.isArray(e)?e:[],s=n.continuation||null}else{let e=n.items||[];r=e.filter(e=>"design"===e.type).map(e=>e.design).filter(Boolean),l=e.filter(e=>"folder"===e.type).map(e=>
1e.folder).filter(Boolean),s=n.continuation||null}a?(g(e=>ey([...e,...r])),b(e=>ey([...e,...l]))):(g(r),b(l)),ep(s)}catch(e){console.error("Error loading designs:",e),O(e instanceof Error?e.message:"Failed to load designs")}finally{w(!1),S(!1)}},[er,eg,12]);(0,n.useEffect)(()=>{z&&s&&eA({mode:"replace"})},[eg,er,z,s,eA]),(0,n.useEffect)(()=>{if(!y&&eb.current&&ev.current&&eu){let e=setTimeout(()=>{var e;null==(e=ev.current)||e.focus()},0);return()=>clearTimeout(e)}},[y,eu]);let eP=(0,n.useCallback)(async()=>{w(!0),O(null);try{let e=await fetch("/api/canva/designs?limit=1");e.ok?L(!0):(401===e.status?L(!1):O("Failed to check Canva session"),w(!1))}catch(e){console.error("Error checking session:",e),L(!1),w(!1)}},[]);(0,n.useEffect)(()=>{s&&!z&&eP()},[s,z,eP]);let eM=async()=>{if(!k||!ej)return;I(!0),R(0),O(null),en(p("canva.exportingFromCanva"));let e=null;try{let t=k.page_count||1;for(let e=0;e<=15;e++)R(e),await new Promise(e=>setTimeout(e,40));let a=Date.now();e=setInterval(()=>{let e,t=Date.now()-a;e=t<25e3?15+t/25e3*40:55+5*(1-Math.exp(-(t-25e3)/3e4)),R(Math.floor(e))},100);let i=await fetch("/api/canva/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({designId:k.id,exportFormat:K,quality:et||void 0,pageCount:t})});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error||"Failed to create export job")}let n=await i.json();if(!n.success||!n.urls||0===n.urls.length)throw Error("No export URLs received from Canva");e&&clearInterval(e),R(60);let r=n.urls;en(p("canva.downloadingFilesCount",{count:r.length}));let l=Array(r.length).fill(0),s=await Promise.all(r.map(async(e,t)=>es(e,k.title,t+1,r.length,ej,U,(e,a)=>{l[t]=e;let i=l.reduce((e,t)=>e+t,0)/r.length;R(Math.floor(60+i/100*35));let n="Downloading files..."===a?p("canva.downloadingFiles"):"Processing and saving to gallery..."===a?p("canva.processingAndSaving"):"Finalizing import..."===a?p("canva.finalizingImport"):a;en(n)})));en(p("canva.finalizingImport")),R(95);let o=await ed({files:s});if(o.error)throw Error(o.error);let d=o.data||[],m=d.length,h=s.reduce((e,t)=>e+t.sizeInBytes/1048576,0);h>0&&await ek(h),u&&d.forEach(e=>{u(e)}),en(p("canva.importComplete")),R(100),H.oR.success(1===m?p("canva.importSuccessSingle",{title:k.title}):p("canva.importSuccessMultiple",{count:m,title:k.title}),{duration:3e3}),await new Promise(e=>setTimeout(e,500)),T(null),R(0),en(""),c(!1)}catch(t){e&&clearInterval(e),console.error("Error importing design:",t),O(t instanceof Error?t.message:p("canva.importError")),R(0),en(""),H.oR.error(t instanceof Error?t.message:p("canva.importError"))}finally{I(!1)}};return(0,i.jsx)(D.lG,{open:s,onOpenChange:c,children:(0,i.jsxs)(D.Cf,{className:"sm:max-w-[800px] max-h-[90vh] p-0 min-h-[500px] overflow-hidden flex flex-col",children:[(0,i.jsx)(D.c7,{className:"px-6 py-4 flex-row items-center justify-between space-y-0",children:(0,i.jsxs)(D.L3,{className:"flex items-center gap-2.5",children:[(0,i.jsxs)("svg",{className:"h-9 w-9",viewBox:"75 342.6 434 139.1",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"canva-gradient-dialog",gradientUnits:"userSpaceOnUse",x1:"75.6711",y1:"412.9916",x2:"493.0198",y2:"407.3517",children:[(0,i.jsx)("stop",{offset:"0",stopColor:"#04BDCD"}),(0,i.jsx)("stop",{offset:"6.735983e-002",stopColor:"#10A9D3"}),(0,i.jsx)("stop",{offset:"0.172",stopColor:"#2883DE"}),(0,i.jsx)("stop",{offset:"0.5026",stopColor:"#2D7BE1"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#7D2AE7"})]})}),(0,i.jsx)("path",{fill:"url(#canva-gradient-dialog)",d:"M505.8,437.8c-0.7,0-1.4,0.5-1.7,1.4c-4.4,12.7-10.5,20.2-15.4,20.2c-2.8,0-4-3.2-4-8.2 c0-12.4,7.4-38.7,11.2-50.8c0.4-1.4,0.7-2.7,0.7-3.8c0-3.5-1.9-5.2-6.7-5.2c-5.1,0-10.6,2-15.9,11.3c-1.8-8.2-7.4-11.9-15.2-11.9 c-9,0-17.7,5.8-24.9,15.2c-7.2,9.4-15.5,12.5-21.9,10.9c4.6-11.1,6.2-19.4,6.2-25.7c0-9.7-4.8-15.5-12.5-15.5 c-11.8,0-18.6,11.2-18.6,23.1c0,9.1,4.1,18.5,13.2,23.1c-7.7,17.3-18.8,32.9-23,32.9c-5.5,0-7.1-26.7-6.8-45.8 c0.2-11,1.1-11.6,1.1-14.9c0-1.9-1.2-3.2-6.2-3.2c-11.6,0-15.2,9.8-15.7,21c-0.1,4.3-0.9,8.5-2,12.7C343,441.9,333,455,326.5,455 c-3,0-3.8-3-3.8-6.9c0-12.4,6.9-28,6.9-41.2c0-9.8-4.3-15.9-12.3-15.9c-9.5,0-22,11.3-33.9,32.4c3.9-16.2,5.5-31.8-6.1-31.8 c-2.5,0.1-5,0.7-7.2,1.9c-1.5,0.7-2.5,2.2-2.3,4c1.1,17.2-13.9,61.3-28,61.3c-2.6,0-3.8-2.8-3.8-7.3c0-12.4,7.4-38.7,11.1-50.7 c0.5-1.6,0.7-2.9,0.7-4c0-3.3-2-5-6.7-5c-5.1,0-10.6,2-15.9,11.3c-1.9-8.2-7.4-11.9-15.3-11.9c-12.8,0-27,13.5-33.3,31.1 c-8.4,23.5-25.3,46.2-48.1,46.2c-20.7,0-31.6-17.2-31.6-44.4c0-39.3,28.8-71.3,50.2-71.3c10.2,0,15.1,6.5,15.1,16.5 c0,12.1-6.7,17.7-6.7,22.3c0,1.4,1.2,2.8,3.5,2.8c9.3,0,20.2-10.9,20.2-25.8c0-14.9-12.1-25.7-33.5-25.7c-35.3,0-70.8,35.5-70.8,81 c0,36.2,17.9,58.1,48.8,58.1c21.1,0,39.5-16.4,49.4-35.5c1.2,15.8,8.3,24.1,19.3,24.1c9.8,0,17.6-5.8,23.7-16 c2.3,10.7,8.5,15.9,16.5,15.9c9.2,0,16.8-5.8,24.1-16.6c-0.1,8.5,1.8,16.5,9.2,16.5c3.5,0,7.6-0.8,8.3-3.8 c7.7-32,26.9-58.1,32.7-58.1c1.7,0,2.2,1.7,2.2,3.6c0,8.7-6.1,26.5-6.1,37.9c0,12.3,5.2,20.5,16,20.5c12,0,24.1-14.7,32.2-36.1 c2.5,20,8,36.1,16.6,36.1c10.6,0,29.3-22.2,40.6-45.7c4.4,0.6,11.1,0.4,17.6-4.1c-2.7,6.9-4.3,14.5-4.3,22 c0,21.8,10.4,27.9,19.4,27.9c9.8,0,17.6-5.8,23.7-16c2,9.3,7.1,15.9,16.5,15.9c14.7,0,27.4-15,27.4-27.3 C508.8,439.7,507.4,437.8,505.8,437.8z M201.5,458.3c-5.9,0-8.2-6-8.2-14.8c0-15.5,10.6-41.2,21.8-41.2c4.8,0,6.7,5.7,6.7,12.8 C221.8,43
10.7,211.7,458.3,201.5,458.3z M404.3,412.3c-3.5-4.2-4.8-9.9-4.8-15c0-6.3,2.3-11.6,5.1-11.6s3.6,2.7,3.6,6.5 C408.1,398.4,405.9,407.6,404.3,412.3z M450.2,458.3c-5.9,0-8.2-6.9-8.2-14.8c0-14.9,10.6-41.2,21.8-41.2c4.9,0,6.6,5.7,6.6,12.8 C470.4,430.7,460.5,458.3,450.2,458.3z"})]}),(0,i.jsx)("span",{className:"text-xl font-bold tracking-tight",children:p("canva.import")})]})}),!E&&!1!==z&&(0,i.jsx)("div",{className:"px-4 py-2",children:(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)(G.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,i.jsx)(M.p,{ref:ev,placeholder:p("canva.searchPlaceholder"),className:"pl-9 h-9 text-sm bg-muted/20 border-none focus-visible:ring-1 focus-visible:ring-primary/20 transition-all",value:eu,onChange:e=>{em(e.target.value),ep(null),eb.current=!0},onFocus:()=>{eb.current=!0},onBlur:()=>{eb.current=!1},disabled:y&&!j})]})}),(0,i.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col relative min-h-0 min-w-0",children:(0,i.jsx)($.N,{mode:"wait",children:E?(0,i.jsxs)(Y.P.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:1.05},transition:{duration:.3,ease:"easeOut"},className:"flex-1 flex flex-col items-center justify-center p-6 space-y-8",children:[(null==k||null==(a=k.thumbnail)?void 0:a.url)&&(0,i.jsxs)(Y.P.div,{initial:{y:10,opacity:0},animate:{y:0,opacity:1},transition:{delay:.1,duration:.4},className:"relative w-32 h-32 rounded-lg overflow-hidden border shadow-lg",children:[(0,i.jsx)(l.default,{src:k.thumbnail.url,alt:"",fill:!0,className:"object-cover"}),k.isVideo&&(0,i.jsx)("div",{className:"absolute bottom-1.5 right-1.5 bg-black/70 rounded p-1 z-10",children:(0,i.jsx)(d.A,{className:"h-3 w-3 text-white fill-white"})})]}
1),(0,i.jsxs)("div",{className:"w-full max-w-md space-y-4",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between text-sm gap-4",children:[(0,i.jsx)("span",{className:"font-medium text-foreground truncate min-w-0",children:p("canva.importingDesign",{title:(null==k?void 0:k.title)||""})}),(0,i.jsxs)("span",{className:"text-muted-foreground font-mono shrink-0",children:[Math.round(A),"%"]})]}),(0,i.jsxs)("div",{className:"relative h-2.5 w-full bg-primary/20 rounded-full overflow-hidden",children:[(0,i.jsx)(Y.P.div,{className:"absolute inset-y-0 left-0 bg-primary rounded-full",initial:{width:0},animate:{width:"".concat(A,"%")},transition:{type:"spring",bounce:0,duration:.5}}),(0,i.jsx)(Y.P.div,{className:"absolute inset-0 bg-primary/10 blur-sm rounded-full -z-10",animate:{opacity:[.3,.6,.3]},transition:{duration:2,repeat:1/0}})]}),(0,i.jsx)("p",{className:"text-xs text-muted-foreground text-center animate-pulse",children:ei||(A<60?p("canva.exportingFromCanva"):A<85?p("canva.downloadingFiles"):A<95?p("canva.processingAndSaving"):p("canva.finalizingImport"))})]})]},"importing"):(0,i.jsx)(Y.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"flex-1 overflow-hidden flex flex-col",children:!1===z?(0,i.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center space-y-4",children:[(0,i.jsx)("p",{className:"text-center text-muted-foreground",children:p("canva.authenticateMessage")}),(0,i.jsxs)(o.$,{onClick:()=>{window.location.href="/api/canva/authorize"},className:"gap-2",children:[(0,i.jsx)("div",{className:"h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_import_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_import_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_import_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_import_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"btn_import_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_import_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_import_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_import_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),p("canva.connectToCanva")]})]}):(0,i.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-4 min-h-0",children:[!eg&&eo.length>0&&(0,i.jsx)("div",{className:"flex items-center gap-1 mb-4 text-xs text-muted-foreground overflow-x-auto whitespace-nowrap pb-1",children:eo.map((e,t)=>(0,i.jsxs)(n.Fragment,{children:[t>0&&(0,i.jsx)(C.A,{className:"h-3 w-3 shrink-0"}),(0,i.jsx)("button",{onClick:()=>(e=>{let t=eo.slice(0,e+1);ec(t),el(t[t.length-1].id),ep(null),T(null)})(t),className:(0,N.cn)("hover:text-foreground transition-colors",t===eo.length-1&&"font-semibold text-foreground"),children:e.name})]},e.id))}),y||null===z?(0,i.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4",children:[...Array(8)].map((e,t)=>(0,i.jsx)(ex,{},"skeleton-".concat(t)))}):F?(0,i.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center py-12 space-y-4",children:[(0,i.jsx)("p",{className:"text-center text-destructive",children:F}),(0,i.jsx)(o.$,{variant:"outline",onClick:()=>eA({mode:"replace"}),children:p("canva.retry")})]}):0===x.length&&0===v.length?(0,i.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center py-12 space-y-4",children:[(0,i.jsx)("p",{className:"text-center text-muted-foreground",children:eg?p("canva.noDesignsFoundForQuery",{query:eg}):p("canva.noDesignsOrFoldersFound")}),(0,i.jsx)(o.$,{variant:"outline",onClick:()=>eA({mode:"replace"}),children:p("canva.refresh")})]}):(0,i.jsxs)("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4",children:[!eg&&v.map(e=>(0,i.jsxs)("div",{className:"flex flex-col cursor-pointer group",onClick:()=>{var t,a;return t=e.id,a=e.name,void(el(t),ep(null),null===t?ec([]):a&&ec(e=>[...e,{id:t,name:a}]),T(null))},children:[(0,i.jsx)("div",{className:"aspect-square rounded-lg border bg-muted flex items-center justify-center group-hover:border-primary transition-all",children:(0,i.jsx)(W.A,{className:"h-10 w-10 text-muted-foreground group-hover:text-primary transition-colors"})}),(0,i.jsx)("div",{className:"mt-2 px-1",children:(0,i.jsx)("p",{className:"text-xs font-medium truncate",children:e.name})})]},e.id)),x.map(e=>{var t;let a=(null==k?void 0:k.id)===e.id;return(0,i.jsxs)("div",{className:"flex flex-col",onClick:()=>T(e),children:[(0,i.jsxs)("div",{className:"\n group relative aspect-square rounded-lg overflow-hidden border bg-muted cursor-pointer transition-all\n ".concat(a?"border-primary ring-2 ring-primary shadow-md":"hover:border-primary","\n "),children:[(null==(t=e.thumbnail)?void 0:t.url)?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l.default,{src:e.thumbnail.url,alt:"",fill:!0,className:"object-cover",sizes:"(max-width: 640px) 50vw, (max-width: 768px) 33vw, 25vw"}),e.isVideo&&(0,i.jsx)("div",{className:"absolute bottom-1.5 right-1.5 bg-black/70 rounded p-1 z-10",children:(0,i.jsx)(d.A,{className:"h-3 w-3 text-white fill-white"})})]}):(0,i.jsx)("div",{className:"w-full h-full flex items-center justify-center bg-muted",children:(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:p("canva.noThumbnail")})}),a&&(0,i.jsx)("div",{className:"absolute top-2 right-2 bg-primary text-primary-foreground rounded-full p-1 z-20 shadow-sm animate-in zoom-in duration-200",children:(0,i.jsx)(V.A,{className:"h-4 w-4"})})]}),(0,i.jsxs)("div",{className:"mt-2 px-1",children:[(0,i.jsx)("p",{className:"text-xs font-medium truncate",children:e.title}),e.page_count&&e.page_count>1&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:p("canva.pages",{count:e.page_count})})]})]},e.id)}),j&&[void 0,void 0,void 0,void 0].map((e,t)=>(0,i.jsx)(ex,{},"skeleton-more-".concat(t)))]}),eh&&!y&&!j&&(0,i.jsx)("div",{className:"flex justify-center py-6",children:(0,i.jsx)(o.$,{variant:"outline",size:"sm",onClick:()=>eA({mode:"append",continuationToken:eh}),className:"gap-2",children:p("canva.loadMore")})})]})},"grid")})}),!1!==z&&!E&&(0,i.jsxs)("div",{className:"space-y-3 px-3 pb-3 pt-3 bg-muted/30 shrink-0",children:[(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsxs)("div",{className:"flex-1",children:[(0,i.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:p("canva.formatLabel")}),(0,i.jsxs)(X.Select,{value:K,onValueChange:ee,disabled:!k,children:[(0,i.jsx)(X.SelectTrigger,{className:"h-8",children:(0,i.jsx)(X.SelectValue,{})}),(0,i.jsxs)(X.SelectContent,{children:[(0,i.jsx)(X.SelectItem,{value:"PNG",children:"PNG"}),(0,i.jsx)(X.SelectItem,{value:"JPG",children:"JPG"}),(0,i.jsx)(X.SelectItem,{value:"MP4",children:"MP4"})]})]})]}),"MP4"===K&&(0,i.jsxs)("div",{className:"flex-1",children:[(0,i.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:p("canva.qual
1ityLabel")}),(0,i.jsxs)(X.Select,{value:et,onValueChange:ea,disabled:!k,children:[(0,i.jsx)(X.SelectTrigger,{className:"h-8",children:(0,i.jsx)(X.SelectValue,{placeholder:p("canva.selectQuality")})}),(0,i.jsxs)(X.SelectContent,{children:[(0,i.jsx)(X.SelectItem,{value:"horizontal_1080p",children:p("canva.quality1080pHorizontal")}),(0,i.jsx)(X.SelectItem,{value:"vertical_1080p",children:p("canva.quality1080pVertical")}),(0,i.jsx)(X.SelectItem,{value:"horizontal_4k",children:p("canva.quality4kHorizontal")}),(0,i.jsx)(X.SelectItem,{value:"vertical_4k",children:p("canva.quality4kVertical")})]})]})]})]}),(0,i.jsxs)("div",{className:"flex-1",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,i.jsx)("div",{className:"text-xs font-semibold text-muted-foreground",children:p("folderLabel")}),(0,i.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[(0,i.jsxs)("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground min-w-[60px] justify-end",children:[(0,i.jsx)(q.A,{className:"h-3 w-3 shrink-0"}),eS?(0,i.jsx)(f.A,{className:"h-3 w-3 animate-spin inline-block"}):(0,i.jsxs)("span",{className:"whitespace-nowrap",children:[(0,N.s8)(eT),eE?"/".concat((0,N.s8)(eE)):""]})]}),(0,i.jsx)("div",{className:"min-w-[20px] flex justify-end",children:eS?(0,i.jsx)("div",{className:"h-4 w-8 rounded bg-skeleton animate-pulse"}):eE?(0,i.jsxs)("span",{className:(0,N.cn)("text-[10px] px-1 rounded font-medium whitespace-nowrap",eI>=100?"bg-red-100 text-red-800":eI>=90?"bg-orange-100 text-orange-800":"bg-green-100 text-green-700"),children:[Math.round(eI),"%"]}):null})]})]}),(0,i.jsx)(P.D,{value:U,onChange:B,folderHierarchy:h})]})]}),(0,i.jsxs)("div",{className:"flex items-center justify-between pt-2",children:[(0,i.jsxs)("div",{className:"flex items-center gap-3 flex-1 min-w-0 pr-4",children:[(!0===z||null===z)&&!E&&(0,i.jsx)(ef,{onLogoutSuccess:()=>{L(!1),g([]),b([]),ec([]),el(null),T(null)},align:"start"}),(0,i.jsxs)("div",{className:"min-w-0",children:[k&&k.page_count&&k.page_count>1&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:p("canva.pagesWillBeImported",{count:k.page_count})}),!k&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:p("canva.selectDesignToImport")})]})]}),(0,i.jsxs)("div",{className:"flex gap-2",children:[k&&(0,i.jsx)(o.$,{variant:"outline",onClick:()=>T(null),disabled:E,children:p("canva.cancel")}),(0,i.jsx)(o.$,{onClick:eM,disabled:!k||E||"MP4"===K&&!et,children:p("canva.import")})]})]})]})]})})}var ev=a(21735);function eb(e){let{open:t,onOpenChange:a,media:s}=e,d=(0,r.useTranslations)("Media"),{workspace:c}=(0,Q.k)(),u=(null==c?void 0:c.id)||"",[m,h]=(0,n.useState)(!1),[p,x]=(0,n.useState)(0),[g,v]=(0,n.useState)(null),[,b]=(0,n.useState)(null),[y,w]=(0,n.useState)(null),[j,C]=(0,n.useState)(!1),[N,S]=(0,n.useState)(null),k=async()=>{try{let e=await fetch("/api/canva/designs?limit=1");w(e.ok)}catch(e){w(!1)}};(0,n.useEffect)(()=>{t&&s&&(null===y&&k(),(async()=>{try{let e=await fetch("/api/canva/get-edit-url?mediaId=".concat(s.id));if(e.ok){let t=await e.json();t.editUrl?(v(t.editUrl),S(null),C(!0)):(C(!1),v(null),S(null))}else C(!1),v(null),S(null)}catch(e){console.error("[CanvaEditDialog] Failed to check edit URL:",e),C(!1),v(null),S(null)}})())},[t,y,s]);let T=async()=>{if(!s)return;h(!0),x(0),b(null),v(null);let e=setInterval(()=>{x(t=>t>=90?(clearInterval(e),90):t+5)},1e3);try{let t=await fetch("/api/canva/import-design",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaId:s.id})});if(clearInterval(e),!t.ok){let e=await t.json();if(e.requiresReauth){b(e.error||d("canva.uploadError")),w(!1),H.oR.error(e.error||d("canva.uploadError"));return}if(e.unsupportedFormat){let t=e.error||d("canva.unsupportedFormat");b(t),H.oR.error(t),h(!1);return}throw Error(e.error||d("canva.uploadError"))}let{editUrl:a}=await t.json();v(a),x(100),H.oR.success(d("canva.uploadComplete"))}catch(a){clearInterval(e);let t=a instanceof Error?a.message:d("canva.uploadError");b(t),H.oR.error(t),h(!1)}},E=async()=>
1{if(!g||!s)return;let e=btoa(unescape(encodeURIComponent(JSON.stringify({mediaId:s.id,folderId:s.folderId||null,workspaceId:u,replaceMode:!0})))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),t=new URL(g);t.searchParams.set("correlation_state",e);let a=t.toString();window.location.href=a},I=()=>{h(!1),x(0),v(null),b(null)};return((0,n.useEffect)(()=>{t||setTimeout(I,300)},[t]),s)?(0,i.jsx)(D.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(D.Cf,{className:"p-4 sm:max-w-[450px]",children:[(0,i.jsx)(D.c7,{children:(0,i.jsxs)(D.L3,{className:"flex items-center gap-2",children:[(0,i.jsxs)("svg",{className:"h-6 w-11",viewBox:"75 342.6 434 139.1",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"canva-gradient-edit",gradientUnits:"userSpaceOnUse",x1:"75.6711",y1:"412.9916",x2:"493.0198",y2:"407.3517",children:[(0,i.jsx)("stop",{offset:"0",stopColor:"#04BDCD"}),(0,i.jsx)("stop",{offset:"6.735983e-002",stopColor:"#10A9D3"}),(0,i.jsx)("stop",{offset:"0.172",stopColor:"#2883DE"}),(0,i.jsx)("stop",{offset:"0.5026",stopColor:"#2D7BE1"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#7D2AE7"})]})}),(0,i.jsx)("path",{fill:"url(#canva-gradient-edit)",d:"M505.8,437.8c-0.7,0-1.4,0.5-1.7,1.4c-4.4,12.7-10.5,20.2-15.4,20.2c-2.8,0-4-3.2-4-8.2 c0-12.4,7.4-38.7,11.2-50.8c0.4-1.4,0.7-2.7,0.7-3.8c0-3.5-1.9-5.2-6.7-5.2c-5.1,0-10.6,2-15.9,11.3c-1.8-8.2-7.4-11.9-15.2-11.9 c-9,0-17.7,5.8-24.9,15.2c-7.2,9.4-15.5,12.5-21.9,10.9c4.6-11.1,6.2-19.4,6.2-25.7c0-9.7-4.8-15.5-12.5-15.5 c-11.8,0-18.6,11.2-18.6,23.1c0,9.1,4.1,18.5,13.2,23.1c-7.7,17.3-18.8,32.9-23,32.9c-5.5,0-7.1-26.7-6.8-45.8 c0.2-11,1.1-11.6,1.1-14.9c0-1.9-1.2-3.2-6.2-3.2c-11.6,0-15.2,9.8-15.7,21c-0.1,4.3-0.9,8.5-2,12.7C343,441.9,333,455,326.5,455 c-3,0-3.8-3-3.8-6.9c0-12.4,6.9-28,6.9-41.2c0-9.8-4.3-15.9-12.3-15.9c-9.5,0-22,11.3-33.9,32.4c3.9-16.2,5.5-31.8-6.1-31.8 c-2.5,0.1-5,0.7-7.2,1.9c-1.5,0.7-2.5,2.2-2.3,4c1.1,17.2-13.9,61.3-28,61.3c-2.6,0-3.8-2.8-3.8-7.3c0-12.4,7.4-38.7,11.1-50.7 c0.5-1.
16,0.7-2.9,0.7-4c0-3.3-2-5-6.7-5c-5.1,0-10.6,2-15.9,11.3c-1.9-8.2-7.4-11.9-15.3-11.9c-12.8,0-27,13.5-33.3,31.1 c-8.4,23.5-25.3,46.2-48.1,46.2c-20.7,0-31.6-17.2-31.6-44.4c0-39.3,28.8-71.3,50.2-71.3c10.2,0,15.1,6.5,15.1,16.5 c0,12.1-6.7,17.7-6.7,22.3c0,1.4,1.2,2.8,3.5,2.8c9.3,0,20.2-10.9,20.2-25.8c0-14.9-12.1-25.7-33.5-25.7c-35.3,0-70.8,35.5-70.8,81 c0,36.2,17.9,58.1,48.8,58.1c21.1,0,39.5-16.4,49.4-35.5c1.2,15.8,8.3,24.1,19.3,24.1c9.8,0,17.6-5.8,23.7-16 c2.3,10.7,8.5,15.9,16.5,15.9c9.2,0,16.8-5.8,24.1-16.6c-0.1,8.5,1.8,16.5,9.2,16.5c3.5,0,7.6-0.8,8.3-3.8 c7.7-32,26.9-58.1,32.7-58.1c1.7,0,2.2,1.7,2.2,3.6c0,8.7-6.1,26.5-6.1,37.9c0,12.3,5.2,20.5,16,20.5c12,0,24.1-14.7,32.2-36.1 c2.5,20,8,36.1,16.6,36.1c10.6,0,29.3-22.2,40.6-45.7c4.4,0.6,11.1,0.4,17.6-4.1c-2.7,6.9-4.3,14.5-4.3,22 c0,21.8,10.4,27.9,19.4,27.9c9.8,0,17.6-5.8,23.7-16c2,9.3,7.1,15.9,16.5,15.9c14.7,0,27.4-15,27.4-27.3 C508.8,439.7,507.4,437.8,505.8,437.8z M201.5,458.3c-5.9,0-8.2-6-8.2-14.8c0-15.5,10.6-41.2,21.8-41.2c4.8,0,6.7,5.7,6.7,12.8 C221.8,430.7,211.7,458.3,201.5,458.3z M404.3,412.3c-3.5-4.2-4.8-9.9-4.8-15c0-6.3,2.3-11.6,5.1-11.6s3.6,2.7,3.6,6.5 C408.1,398.4,405.9,407.6,404.3,412.3z M450.2,458.3c-5.9,0-8.2-6.9-8.2-14.8c0-14.9,10.6-41.2,21.8-41.2c4.9,0,6.6,5.7,6.6,12.8 C470.4,430.7,460.5,458.3,450.2,458.3z"})]}),d("canva.edit")]})}),(0,i.jsxs)("div",{className:"flex flex-col items-center gap-4 w-full min-w-0",children:[(0,i.jsx)("div",{className:"relative w-full flex justify-center overflow-hidden rounded-lg",children:s.width&&s.height?(0,i.jsx)("div",{className:"relative w-full max-w-[300px]",style:{aspectRatio:"".concat(s.width," / ").concat(s.height)},children:(0,i.jsx)(l.default,{src:s.thumbnailUrl||s.url,alt:s.name,fill:!0,className:"object-contain rounded-lg",sizes:"(max-width: 768px) 100vw, 300px"})}):(0,i.jsx)("div",{className:"relative aspect-video w-full max-w-[300px]",children:(0,i.jsx)(l.default,{src:s.thumbnailUrl||s.url,alt:s.name,fill:!0,className:"object-contain rounded-lg",sizes:"(max-width: 768px) 100vw, 300px"})})}),(0,i.jsx)("div",{className:"w-full px-10 overflow-hidden text-center",style:{maxWidth:"100%"},children:(0,i.jsx)("p",{className:"text-sm font-medium truncate block w-full",title:s.name,children:s.name})}),(0,i.jsx)("div",{className:"w-full mt-2",children:(0,i.jsx)($.N,{mode:"wait",children:!1===y?(0,i.jsxs)(Y.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"w-full flex flex-col items-center justify-center space-y-4 py-4",children:[(0,i.jsx)("p",{className:"text-center text-muted-foreground",children:d("canva.authenticateEditMessage")}),(0,i.jsxs)(o.$,{onClick:()=>{let e=s?"/api/canva/authorize?mediaId=".concat(s.id):"/api/canva/authorize";window.location.href=e},className:"gap-2",children:[(0,i.jsx)("div",{className:"h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_edit_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_edit_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_edit_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#btn_edit_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"btn_edit_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_edit_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_edit_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"btn_edit_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),d("canva.connectToCanva")]})]},"auth"):m?(0,i.jsxs)(Y.P.div,{initial:{opacity:0,y:10}
1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"w-full space-y-4",children:[(0,i.jsxs)("div",{className:"space-y-2 w-full",children:[(0,i.jsxs)("div",{className:"flex justify-between text-xs text-muted-foreground",children:[(0,i.jsx)("span",{children:100===p?d("canva.uploadComplete"):d("canva.uploadingToCanva")}),(0,i.jsxs)("span",{children:[p,"%"]})]}),(0,i.jsx)("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:(0,i.jsx)(Y.P.div,{className:"h-full bg-primary",initial:{width:0},animate:{width:"".concat(p,"%")},transition:{duration:.3}})})]}),(0,i.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,i.jsx)("div",{className:"flex-1",children:(0,i.jsx)(ef,{onLogoutSuccess:()=>w(!1),align:"start"})}),(0,i.jsx)("div",{className:"flex justify-end",children:100===p?(0,i.jsxs)(o.$,{className:"gap-2",onClick:E,children:[(0,i.jsx)(ev.A,{className:"h-4 w-4"}),d("canva.editInCanva")]}):(0,i.jsxs)(o.$,{disabled:!0,className:"gap-2",children:[(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}),d("canva.uploadingToCanva")]})})]})]},"uploading"):j&&g?(0,i.jsxs)(Y.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"w-full space-y-4",children:[N&&(0,i.jsx)("div",{className:"text-sm text-destructive text-center p-2 bg-destructive/10 rounded",children:N}),(0,i.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,i.jsx)("div",{className:"flex-1 min-w-0 pr-4",children:(0,i.jsx)(ef,{onLogoutSuccess:()=>w(!1),align:"start"})}),(0,i.jsx)("div",{className:"flex-1 flex justify-end",children:(0,i.jsxs)(o.$,{className:"gap-2",onClick:E,disabled:!y,children:[(0,i.jsx)(ev.A,{className:"h-4 w-4"}),d("canva.editInCanva")]})})]}),N&&(0,i.jsx)("div",{className:"flex justify-center",children:(0,i.jsx)(o.$,{variant:"outline",className:"gap-2",onClick:()=>{S(null),C(!1),v(null)},children:d("canva.uploadToCanva")})})]},"stored-url"):(0,i.jsxs)("div",{className:"w-full space-y-4",children:[N&&(0,i.jsx)("div",{className:"text-sm text-destructive text-center p-2 bg-destructive/10 rounded",children:N}),(0,i.jsxs)("div",{className:"flex items-center justify-between w-full pt-2",children:[(0,i.jsx)("div",{className:"flex-1 min-w-0 pr-4",children:(0,i.jsx)(ef,{onLogoutSuccess:()=>w(!1),align:"start"})}),(0,i.jsx)("div",{className:"flex-1 flex justify-end",children:(0,i.jsx)(Y.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"flex justify-end",children:(0,i.jsx)(o.$,{className:"gap-2",onClick:T,disabled:null===y,children:null===y?(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}):d("canva.uploadToCanva")})},"idle")})]})]})})})]})]})}):null}var ey=a(37606),ew=a(36451);function ej(e){let{open:t,onOpenChange:a,mediaId:s,designId:d,token:c,onComplete:u,onRefreshCache:m}=e,h=(0,r.useTranslations)("Media"),{onMediaUploaded:p}=(0,J.f)(),[g,v]=(0,n.useState)(!1),[b,y]=(0,n.useState)(null),[w,j]=(0,n.useState)([]),[C,S]=(0,n.useState)(null),[k,T]=(0,n.use
1State)(!1),[E,I]=(0,n.useState)(!0),[A,P]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&s&&c&&!k&&M()},[t,s,c,k]);let M=async()=>{try{S(null);let e=await fetch("/api/queries/media?mediaId=".concat(s));if(e.ok){let t=await e.json();y(t.data)}R(),T(!0)}catch(t){console.error("[CanvaReturnDialog] Failed to fetch data:",t);let e=t instanceof Error?t.message:"Failed to load data";S(e),H.oR.error(e)}},R=async()=>{let e=0,t=async()=>{try{let e=await fetch("/api/canva/get-cached-data?token=".concat(c));if(e.ok){let t=await e.json();if(t.data&&Array.isArray(t.data)&&t.data.length>0)return j(t.data),I(!1),!0}}catch(e){console.warn("Polling error:",e)}return!1};for(;e<30;){if(await t())return;e++,await new Promise(e=>setTimeout(e,1e3))}S("Timeout waiting for design to process. Please try again."),I(!1)},F=async e=>{if(!c)return void H.oR.error("Missing token");v(!0),P(e),S(null);try{let i=await fetch("/api/canva/replace-media",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mediaId:s,designId:d,token:c,action:e})});if(!i.ok){let e=await i.json();throw Error(e.error||"Failed to process request")}let n=await i.json();m&&await m(e,n.mediaId||s);try{if("replace"===e){var t;let e=(null==b?void 0:b.sizeInBytes)?(0,N.LI)(b.sizeInBytes)/1048576:0,a=((null==(t=w[0])?void 0:t.sizeInBytes)?w[0].sizeInBytes/1048576:0)-e;Math.abs(a)>.001&&await p(Math.abs(a))}else{let e=w.reduce((e,t)=>e+(t.sizeInBytes?t.sizeInBytes/1048576:0),0);e>0&&await p(e)}}catch(e){console.warn("[CanvaReturnDialog] Failed to refresh usage tracker:",e)}v(!1),P(null),a(!1),u&&u(),"replace"===e?H.oR.success(h("canva.replaceSuccess")||"Media replaced successfully"):H.oR.success(h("canva.importSuccess")||"New media created successfully")}catch(t){let e=t instanceof Error?t.message:"An error occurred";S(e),H.oR.error(e),v(!1),P(null)}},O=async e=>{if(!e&&c&&!g)try{await fetch("/api/media-cache/cleanup?token=".concat(c),{method:"DELETE"})}catch(e){console.error("[CanvaReturnDialog] Failed to cleanup cache:",e)}a(e)};return t?(0,i.jsx)(D.lG,{open:t,onOpenChange:O,children:(0,i.jsxs)(D.Cf,{className:"p-4 sm:max-w-[500px]",children:[(0,i.jsxs)(D.c7,{children:[(0,i.jsxs)(D.L3,{className:"flex items-center gap-2",children:[(0,i.jsxs)("svg",{className:"h-6 w-11",viewBox:"75 342.6 434 139.1",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"canva-gradient-return",gradientUnits:"userSpaceOnUse",x1:"75.6711",y1:"412.9916",x2:"493.0198",y2:"407.3517",children:[(0,i.jsx)("stop",{offset:"0",stopColor:"#04BDCD"}),(0,i.jsx)("stop",{offset:"6.735983e-002",stopColor:"#10A9D3"}),(0,i.jsx)("stop",{offset:"0.172",stopColor:"#2883DE"}),(0,i.jsx)("stop",{offset:"0.5026",stopColor:"#2D7BE1"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#7D2AE7"})]})}),(0,i.jsx)("path",{fill:"url(#canva-gradient-return)",d:"M505.8,437.8c-0.7,0-1.4,0.5-1.7,1.4c-4.4,12.7-10.5,20.2-15.4,20.2c-2.8,0-4-3.2-4-8.2 c0-12.4,7.4-38.7,11.2-50.8c0.4-1.4,0.7-2.7,0.7-3.8c0-3.5-1.9-5.2-6.7-5.2c-5.1,0-10.6,2-15.9,11.3c-1.8-8.2-7.4-11.9-15.2-11.9 c-9,0-17.7,5.8-24.9,15.2c-7.2,9.4-15.5,12.5-21.9,10.9c4.6-11.1,6.2-19.4,6.2-25.7c0-9.7-4.8-15.5-12.5-15.5 c-11.8,0-18.6,11.2-18.6,23.1c0,9.1,4.1,18.5,13.2,23.1c-7.7,17.3-18.8,32.9-23,32.9c-5.5,0-7.1-26.7-6.8-45.8 c0.2-11,1.1-11.6,1.1-14.9c0-1.9-1.2-3.2-6.2-3.2c-11.6,0-15.2,9.8-15.7,21c-0.1,4.3-0.9,8.5-2,12.7C343,441.9,333,455,326.5,455 c-3,0-3.8-3-3.8-6.9c0-12.4,6.9-28,6.9-41.2c0-9.8-4.3-15.9-12.3-15.9c-9.5,0-22,11.3-33.9,32.4c3.9-16.2,5.5-31.8-6.1-31.8 c-2.5,0.1-5,0.7-7.2,1.9c-1.5,0.7-2.5,2.2-2.3,4c1.1,17.2-13.9,61.3-28,61.3c-2.6,0-3.8-2.8-3.8-7.3c0-12.4,7.4-38.7,11.1-50.7 c0.5-1.
16,0.7-2.9,0.7-4c0-3.3-2-5-6.7-5c-5.1,0-10.6,2-15.9,11.3c-1.9-8.2-7.4-11.9-15.3-11.9c-12.8,0-27,13.5-33.3,31.1 c-8.4,23.5-25.3,46.2-48.1,46.2c-20.7,0-31.6-17.2-31.6-44.4c0-39.3,28.8-71.3,50.2-71.3c10.2,0,15.1,6.5,15.1,16.5 c0,12.1-6.7,17.7-6.7,22.3c0,1.4,1.2,2.8,3.5,2.8c9.3,0,20.2-10.9,20.2-25.8c0-14.9-12.1-25.7-33.5-25.7c-35.3,0-70.8,35.5-70.8,81 c0,36.2,17.9,58.1,48.8,58.1c21.1,0,39.5-16.4,49.4-35.5c1.2,15.8,8.3,24.1,19.3,24.1c9.8,0,17.6-5.8,23.7-16 c2.3,10.7,8.5,15.9,16.5,15.9c9.2,0,16.8-5.8,24.1-16.6c-0.1,8.5,1.8,16.5,9.2,16.5c3.5,0,7.6-0.8,8.3-3.8 c7.7-32,26.9-58.1,32.7-58.1c1.7,0,2.2,1.7,2.2,3.6c0,8.7-6.1,26.5-6.1,37.9c0,12.3,5.2,20.5,16,20.5c12,0,24.1-14.7,32.2-36.1 c2.5,20,8,36.1,16.6,36.1c10.6,0,29.3-22.2,40.6-45.7c4.4,0.6,11.1,0.4,17.6-4.1c-2.7,6.9-4.3,14.5-4.3,22 c0,21.8,10.4,27.9,19.4,27.9c9.8,0,17.6-5.8,23.7-16c2,9.3,7.1,15.9,16.5,15.9c14.7,0,27.4-15,27.4-27.3 C508.8,439.7,507.4,437.8,505.8,437.8z M201.5,458.3c-5.9,0-8.2-6-8.2-14.8c0-15.5,10.6-41.2,21.8-41.2c4.8,0,6.7,5.7,6.7,12.8 C221.8,430.7,211.7,458.3,201.5,458.3z M404.3,412.3c-3.5-4.2-4.8-9.9-4.8-15c0-6.3,2.3-11.6,5.1-11.6s3.6,2.7,3.6,6.5 C408.1,398.4,405.9,407.6,404.3,412.3z M450.2,458.3c-5.9,0-8.2-6.9-8.2-14.8c0-14.9,10.6-41.2,21.8-41.2c4.9,0,6.6,5.7,6.6,12.8 C470.4,430.7,460.5,458.3,450.2,458.3z"})]}),h("canva.returnFromCanva")||"Return from Canva"]}),(0,i.jsx)(D.rr,{children:h("canva.returnDescription")||"Choose how to handle the edited design"})]}),(0,i.jsxs)("div",{className:"flex flex-col gap-6 w-full",children:[C&&(0,i.jsx)("div",{className:"text-sm text-destructive bg-destructive/10 p-3 rounded",children:C}),(0,i.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("h4",{className:"text-sm font-medium text-muted-foreground",children:h("canva.original")||"Original"}),(0,i.jsx)("div",{className:"relative w-full rounded-lg overflow-hidden bg-muted",style:{aspectRatio:(null==b?void 0:b.width)&&(null==b?void 0:b.height)?"".concat(b.width," / ").concat(b.height):"1 / 1"},children:b?(0,i.jsx)(l.default,{src:b.thumbnailUrl||b.url,alt:"",fill:!0,className:"object-contain",sizes:"(max-width: 768px) 50vw, 200px"}):(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,i.jsx)(f.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}),b&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:b.name,children:b.name})]}),(0,i.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,i.jsx)("h4",{className:"text-sm font-medium text-muted-foreground",children:h("canva.edited")||"Edited"}),(0,i.jsxs)("div",{className:"relative w-full rounded-lg overflow-hidden bg-muted transition-all duration-300",style:{aspectRatio:(null==b?void 0:b.width)&&(null==b?void 0:b.height)?"".concat(b.width," / ").concat(b.height):"1 / 1"},children:[(0,i.jsx)("div",{className:"absolute inset-0 transition-opacity duration-500 ".concat(E?"opacity-100":"opacity-0 pointer-events-none"),children:(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,i.jsx)(f.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}),w.length>0&&(0,i.jsx)("div",{className:"absolute inset-0 transition-opacity duration-500 ".concat(E?"opacity-0":"opacity-100"),children:(0,i.jsx)(l.default,{src:w[0].thumbnailUrl||w[0].url,alt:"",fill:!0,className:"object-contain",sizes:"(max-width: 768px) 50vw, 200px"})})]}),w.length>0&&!E&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground animate-in fade-in duration-500 truncate",title:w[0].name,children:w[0].name})]})]}),(0,i.jsxs)("div",{className:"flex gap-3",children:[(0,i.jsxs)(o.$,{onClick:()=>F("replace"),disabled:E||0===w.length||g,className:"flex-1 gap-2",children:["replace"===A?(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(ew.A,{className:"h-4 w-4"}),h("canva.replaceOriginal")||"Replace Original"]}),(0,i.jsxs)(o.$,{onClick:()=>F("create_new"),disabled:E||0===w.length||g,variant:"outline",className:"flex-1 gap-2",children:["create_new"===A?(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(x.A,{className:"h-4 w-4"}),h("canva.createAsNew")||"Create as New File"]})]})]})]})}):null}var eC=a(68663),eN=a(97237),eS=a(70576),ek=a(82253),eT=a(63557),eE=a(15087);
1let eI=eT.bL,eA=eT.l9;eT.YJ,eT.ZL,eT.Pb,eT.z6,n.forwardRef((e,t)=>{let{className:a,inset:n,children:r,...l}=e;return(0,i.jsxs)(eT.ZP,{ref:t,className:(0,N.cn)("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",n&&"pl-8",a),...l,children:[r,(0,i.jsx)(C.A,{className:"ml-auto h-4 w-4"})]})}).displayName=eT.ZP.displayName,n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)(eT.G5,{ref:t,className:(0,N.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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",a),...n})}).displayName=eT.G5.displayName;let eP=n.forwardRef((e,t)=>{let{className:a,...n}=e,r=e=>{e.preventDefault(),e.stopPropagation()};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(eT.ZL,{children:(0,i.jsx)("div",{className:"fixed inset-0 z-[49]","aria-hidden":"true",onClick:r,onMouseDown:r,onMouseUp:r,onPointerDown:r,onPointerUp:r,onContextMenu:r})}),(0,i.jsx)(eT.ZL,{children:(0,i.jsx)(eT.UC,{ref:t,className:(0,N.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-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",a),...n})})]})});eP.displayName=eT.UC.displayName;let eM=n.forwardRef((e,t)=>{let{className:a,inset:n,...r}=e;return(0,i.jsx)(eT.q7,{ref:t,className:(0,N.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n&&"pl-8",a),...r})});eM.displayName=eT.q7.displayName,n.forwardRef((e,t)=>{let{className:a,children:n,checked:r,...l}=e;return(0,i.jsxs)(eT.H_,{ref:t,className:(0,N.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),checked:r,...l,children:[(0,i.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,i.jsx)(eT.VF,{children:(0,i.jsx)(V.A,{className:"h-4 w-4"})})}),n]})}).displayName=eT.H_.displayName,n.forwardRef((e,t)=>{let{className:a,children:n,...r}=e;return(0,i.jsxs)(eT.hN,{ref:t,className:(0,N.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...r,children:[(0,i.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,i.jsx)(eT.VF,{children:(0,i.jsx)(eE.A,{className:"h-2 w-2 fill-current"})})}),n]})}).displayName=eT.hN.displayName,n.forwardRef((e,t)=>{let{className:a,inset:n,...r}=e;return(0,i.jsx)(eT.JU,{ref:t,className:(0,N.cn)("px-2 py-1.5 text-sm font-semibold text-foreground",n&&"pl-8",a),...r})}).displayName=eT.JU.displayName;let eD=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)(eT.wv,{ref:t,className:(0,N.cn)("-mx-1 my-1 h-px bg-border",a),...n})});eD.displayName=eT.wv.displayName;let eR=e=>{let{className:t,...a}=e;return(0,i.jsx)("span",{className:(0,N.cn)("ml-auto text-xs tracking-widest text-muted-foreground",t),...a})};eR.displayName="ContextMenuShortcut";let eF=(0,n.memo)(e=>{var t;let{folder:a,isSelected:l,isPreSelected:s=!1,onSelect:o,onItemClick:d,activeId:c,selectedItems:u,itemSize:m="default",enableFolderSelection:h=!1,hideName:p=!1,isInDragOverlay:f=!1,onContextMenuEdit:x,onContextMenuMove:g,onContextMenuDelete:v,onMenuInteraction:C,onPreserveSelection:S}
1=e,k=(0,r.useTranslations)("Media"),[T,E]=(0,n.useState)(!1),I=(0,n.useRef)(!1),A=(0,n.useRef)(0),P=(0,ek.a)(),M=(0,j.fF)(),D=null!==M.active,R=(null==(t=M.active)?void 0:t.id)===a.id,F=(0,n.useRef)(a.id),z=(0,n.useRef)(a.name),L=(0,n.useRef)(a.color);(0,n.useEffect)(()=>{F.current=a.id,z.current=a.name,L.current=a.color},[a]);let U=!P&&h,{attributes:_,listeners:B,setNodeRef:K,isDragging:G,transform:W}=(0,j.PM)({id:a.id,data:{type:"folder",folder:a,viewMode:"grid"},disabled:!U}),{isOver:V,setNodeRef:q}=(0,j.zM)({id:a.id,data:{type:"folder",folder:a,isRoot:!1}}),H=(0,n.useCallback)(e=>{K(e),q(e)},[K,q]),$=D&&c&&(null==u?void 0:u.has(c))&&(null==u?void 0:u.has(a.id)),Y=G||$,X={...W&&!Y?{transform:"translate3d(".concat(W.x,"px, ").concat(W.y,"px, 0)"),willChange:G?"transform":"auto"}:{},opacity:+!Y,transition:Y?"opacity 0.2s ease-out":void 0,pointerEvents:D&&!R?"none":"auto",touchAction:U?"none":"auto"},Z=(0,n.useCallback)(()=>{h&&o(F.current,"folder")},[h,o]),J=(0,n.useCallback)(e=>{if(D||Date.now()-A.current<300||I.current){e&&(e.preventDefault(),e.stopPropagation());return}e&&(P||e.preventDefault(),e.stopPropagation()),I.current=!0,d&&d(F.current,"folder"),setTimeout(()=>{I.current=!1},500)},[d,D,P]);(0,n.useEffect)(()=>()=>{I.current=!1},[]);let Q={sm:{card:"",iconContainer:"w-12 h-12 mb-1",text:"text-[11px]",checkboxTop:"top-[3px] left-1.5",contentPadding:"p-1 pt-6"},default:{card:"",iconContainer:"w-16 h-16 mb-2",text:"text-xs",checkboxTop:"top-[7px] left-2",contentPadding:"p-2 pt-8"},lg:{card:"",iconContainer:"w-20 h-20 mb-2",text:"text-sm",checkboxTop:"top-[7px] left-2.5",contentPadding:"p-3 pt-10"}}[m],ee=(0,n.useCallback)(()=>{!P&&(G||E(!0))},[G,P]),et=(0,n.useCallback)(()=>{P||E(!1)},[P]),ea=(0,n.useCallback)(e=>{e.stopPropagation()},[]),ei=(0,n.useCallback)(e=>{C&&C(),e?(A.current=Date.now(),o(a.id,"folder",!0)):A.current=Date.now()},[a.id,o,C]);return(0,i.jsxs)(eI,{onOpenChange:ei,children:[(0,i.jsx)(eA,{asChild:!0,disabled:P,children:(0,i.jsxs)(eS.Zp,{ref:H,style:{...X,...f?{cursor:"inherit"}:{cursor:G?"grabbing":U?"grab":"pointer"}},"data-is-folder":"true","data-folder-id":a.id,className:(0,N.cn)("group relative w-full h-full shadow-none transition-all duration-300 select-none",Q.card,"border border-border",l&&h?"ring-2 ring-primary bg-accent":"",!l&&s&&h&&"ring-2 ring-primary/40 bg-primary/5",l&&s&&h&&"ring-2 ring-destructive/40 bg-destructive/5",!P&&!G&&!l&&!s&&"hover:ring-2 hover:ring-primary/20",G&&!Y&&"shadow-lg scale-105 z-50",V&&!G&&"ring-2 ring-primary/30 bg-accent/30",f?"!cursor-inherit":G?"!cursor-grabbing":U?"!cursor-grab":"cursor-pointer"),onMouseEnter:ee,onMouseLeave:et,onPointerDown:e=>{Date.now()-A.current<300&&(e.preventDefault(),e.stopPropagation())},onClick:J,...U?_:{},children:[h&&(0,i.jsx)("div",{className:(0,N.cn)("absolute z-10 checkbox-container flex items-center justify-center",Q.checkboxTop,"cursor-default"),style:{opacity:(T||l)&&!G?1:0,transition:"opacity 150ms ease-out",pointerEvents:(T||l)&&!G?"auto":"none",willChange:"opacity",contain:"layout style paint",minWidth:"20px",minHeight:"20px"},onClick:ea,children:(0,i.jsx)(eN.S,{checked:l,"aria-label":"Select ".concat(a.name),tabIndex:-1,onCheckedChange:Z,className:"cursor-pointer bg-white shrink-0"})}),(0,i.jsx)("div",{...U?B:{},style:{...f?{cursor:"inherit"}:{cursor:G?"grabbing":U?"grab":"pointer"}},className:(0,N.cn)("focus:outline-none h-full w-full flex flex-col","sm"===m?"p-1":"p-2"),"aria-label":"Folder ".concat(a.name),children:(0,i.jsxs)("div",{className:(0,N.cn)("aspect-square w-full flex flex-col items-center justify-center rounded-sm"),children:[(0,i.jsx)("div",{className:(0,N.cn)("flex items-center justify-center",Q.iconContainer),children:(0,i.jsx)(O.s,{className:"w-full h-full",color:a.color})}),!p&&(0,i.jsx)("div",{className:(0,N.cn)("pointer-events-none absolute inset-x-0 bottom-[7px] px-2"),children:(0,i.jsx)("p",{className:(0,N.cn)("font-medium truncate text-center w-full",Q.text),title:a.name,children:a.name})})]})})]})}),(0,i.jsxs)(eP,{className:"w-52",children:[x&&u&&1===u.size&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{C&&C(),A.current=Date.now(),x()},0)},children:[(0,i.jsx)(b.A,{className:"mr-2 h-4 w-4"}),k("editButton"),(0,i.jsx)(eR,{children:"E"})]}),(0,i.jsx)(eD,{}),g&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{C&&C(),A.current=Date.now(),g()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),k("moveButton"),(0,i.jsx)(eR,{children:"M"})]}),v&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{C&&C(),A.current=Date.now(),v()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),k("delete"),(0,i.jsx)(eR,{children:"Del"})]})]})]})},(e,t)=>{var a,i;return e.folder.id===t.folder.id&&e.folder.name===t.folder.name&&e.folder.color===t.folder.color&&e.isSelected===t.isSelected&&e.isPreSelected===t.isPreSelected&&e.isDragging===t.isDragging&&e.activeId===t.activeId&&e.itemSize===t.itemSize&&e.enableFolderSelection===t.enableFolderSelection&&(!e.activeId&&!t.activeId||(null==(a=e.selectedItems)?void 0:a.has(e.folder.id))===(null==(i=t.selectedItems)?void 0:i.has(t.folder.id)))});var eO=a(83734),ez=a(13480),eL=a(11688),eU=a(84045),e_=a(93846),eB=a(80683);function eK(e){var t;let{item:a,isHovered:r,isError:s,onError:o,priority:c=!1,imageKey:u,videoRef:m,playIconClassName:h="absolute top-1.5 right-1.5 bg-black/70 rounded p-1",sizes:p="(max-width: 768px) 33vw, (max-width: 1200px) 20vw, 15vw",isProcessing:f=!1}=e,x=(0,n.useRef)(null),g=a.type.startsWith("video/"),v=(0,e_.x)(a.type,a.url,a.name),b=!0===(0,eB.F)(a.url,v),y=b&&r&&!f,w=r&&!f?"object-contain":"object-cover",j=a.type.startsWith("image/")?a.url:null!=(t=a.thumbnailUrl)?t:null;return f&&j?(0,i.jsx)(l.default,{src:j,alt:a.name,className:w,fill:!0,loading:c?"eager":"lazy",priority:c,sizes:p,onError:o,placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"},unoptimized:!0},"".concat(u,"-processing")):s?(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-destructive/10",children:(0,i.jsx)(eL.A,{className:"h-1/2 w-1/2 text-muted-foreground opacity-50"})}):g?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("video",{ref:null!=m?m:x,src:a.url,className:"h-full w-full ".concat(w),preload:c?"auto":"metadata",muted:!0,playsInl
1ine:!0,poster:a.thumbnailUrl||void 0,onError:o,draggable:!1,style:{cursor:"inherit",pointerEvents:"none"}},u),(0,i.jsx)("div",{className:h,children:(0,i.jsx)(d.A,{className:"h-3 w-3 text-white fill-white"})})]}):v&&b?(0,i.jsxs)(i.Fragment,{children:[y?(0,i.jsx)("img",{src:a.url,alt:a.name,className:"absolute inset-0 h-full w-full ".concat(w),draggable:!1,style:{cursor:"inherit",pointerEvents:"none"}},"".concat(u,"-animated")):(0,i.jsx)(l.default,{src:a.thumbnailUrl||a.url,alt:a.name,className:w,fill:!0,loading:c?"eager":"lazy",priority:c,sizes:p,onError:o,placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"},unoptimized:!0},u),(0,i.jsx)("div",{className:h,children:(0,i.jsx)(d.A,{className:"h-3 w-3 text-white fill-white"})})]}):a.type.startsWith("image/")?(0,i.jsx)(l.default,{src:a.thumbnailUrl||a.url,alt:a.name,className:w,fill:!0,loading:c?"eager":"lazy",priority:c,sizes:p,onError:o,placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"},unoptimized:!!(a.thumbnailUrl&&a.thumbnailStorageKey)||v},u):(0,i.jsx)(eU.A,{className:"h-1/2 w-1/2 text-muted-foreground"})}function eG(e){let{item:t,isHovered:a,videoRef:r}=e,s=(0,n.useRef)(null),o=t.type.startsWith("video/"),c=(0,e_.x)(t.type,t.url,t.name),u=!0===(0,eB.F)(t.url,c);return t.type.startsWith("image/")?c&&u?(0,i.jsxs)(i.Fragment,{children:[u&&a?(0,i.jsx)("img",{src:t.url,alt:t.name,className:"h-full w-full object-cover",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"}}):(0,i.jsx)(l.default,{src:t.thumbnailUrl||t.url,alt:t.name,className:"object-cover",fill:!0,sizes:"80px",placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"},unoptimized:!0}),(0,i.jsx)("div",{className:"absolute top-1 right-1 bg-black/70 rounded p-0.5",children:(0,i.jsx)(d.A,{className:"h-2.5 w-2.5 text-white fill-white"})})]}):(0,i.jsx)(l.default,{src:t.thumbnailUrl||t.url,alt:t.name,className:"object-cover",fill:!0,sizes:"80px",placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E",draggable:!1,style:{cursor:"inherit",pointerEvents:"none"},unoptimized:!!(t.thumbnailUrl&&t.thumbnailStorageKey)||c}):o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("video",{ref:null!=r?r:s,src:t.url,className:"h-full w-full object-cover",preload:"metadata",muted:!0,playsInline:!0,poster:t.thumbnailUrl||void 0,draggable:!1,style:{cursor:"inherit",pointerEvents:"none"}}),(0,i.jsx)("div",{className:"absolute top-1 right-1 bg-black/70 rounded p-0.5",children:(0,i.jsx)(d.A,{className:"h-2.5 w-2.5 text-white fill-white"})})]}):(0,i.jsx)(eU.A,{className:"h-1/2 w-1/2 text-muted-foreground"})}var eW=a(18552),eV=a(50366);let eq=(0,n.memo)(e=>{var t;let{item:a,isSelected:l,isPreSelected:s=!1,onSelect:d,onItemClick:c,minimal:u=!1,itemSize:m="default",activeId:h,selectedItems:p,hideCheckbox:C=!1,hideName:S=!1,priority:k=!1,isInDragOverlay:T=!1,onMediaHover:E,onMediaHoverEnd:I,onContextMenuCreatePost:A,onContextMenuPreview:P,onContextMenuEdit:M,onContextMenuEditWithCanva:D,onContextMenuConvert:R,onContextMenuMove:F,onContextMenuDelete:O,onlyMediaSelected:z=!1,hideCreatePostButton:L=!1,isSelectionContext:U=!1,onMenuInteraction:_,onPreserveSelection:B,onCancelConversion:K,isCancellingConversion:G=!1}=e,W=(0,r.useTranslations)("Media"),V=(0,r.useTranslations)("Media.convert"),[q,H]=(0,n.useState)(!1),$=(0,eO.S)(a),Y=!$&&"CONVERTING"===a.status,X=$||Y||G,Z=$&&(0,eO.o)(a);(0,n.useEffect)(()=>{X&&H(!1)},[X,a.id]);
1let[J,Q]=(0,n.useState)(!1),[ee,et]=(0,n.useState)(!1),ea=(0,n.useRef)(null),ei=(0,n.useRef)(null),en=(0,n.useRef)(null),er=(0,n.useRef)(null),el=(0,n.useRef)(0),es=(0,j.fF)(),eo=null!==es.active,ed=(null==(t=es.active)?void 0:t.id)===a.id,ec=(0,ek.a)(),eu=!ec,{attributes:em,listeners:eh,setNodeRef:ep,transform:ef,isDragging:ex}=(0,j.PM)({id:a.id,data:{type:"media",item:a,folderId:a.folderId,viewMode:"grid"},disabled:!eu||X}),eg=(0,n.useCallback)(e=>{en.current=e,ep(e)},[ep]),ev=(0,n.useCallback)(e=>{!X&&(e&&e.stopPropagation(),eo||d(a.id,"media"))},[eo,X,a.id,d]),eb=(0,n.useCallback)(e=>{if(!X){if(Date.now()-el.current<300){e&&(e.preventDefault(),e.stopPropagation());return}eo||(c?c(a.id,"media"):d(a.id,"media"))}},[eo,X,a.id,c,d]),ey=(0,n.useCallback)(()=>{if(!ec&&(et(!0),E&&E(a.id),a.type.startsWith("video/")&&!X&&!("ontouchstart"in window))){let e=ea.current||ei.current;e&&e.play().catch(()=>{})}},[a.type,a.id,E,ec,X]),ew=(0,n.useCallback)(()=>{if(!ec&&(et(!1),I&&I(),a.type.startsWith("video/"))){let e=ea.current||ei.current;e&&(e.pause(),e.currentTime=0)}},[a.type,I,ec]),ej=(0,n.useCallback)(e=>{let t=Date.now();_&&_(),el.current=t,e&&!X&&d(a.id,"media",!0)},[a.id,X,d,_]);(0,n.useEffect)(()=>{Q(!0)},[]);let eC=(0,n.useMemo)(()=>"img-".concat(a.id),[a.id]),eT=eo&&h&&(null==p?void 0:p.has(h))&&(null==p?void 0:p.has(a.id)),eE=ex||eT,eF={...ef&&!eE?{transform:eW.Ks.Translate.toString(ef),willChange:"transform"}:{},opacity:+!eE,transition:eE?"opacity 0.2s ease-out":void 0,pointerEvents:eo&&!ed?"none":"auto",touchAction:eu?"none":"auto"};if(!J)return null;let eL={sm:{card:"",checkboxTop:"top-1.5 left-1.5",contentPadding:"p-0",imageContainer:"",text:"text-[11px]"},default:{card:"",checkboxTop:"top-1.5 left-1.5",contentPadding:"p-0",imageContainer:"",text:"text-xs"},lg:{card:"",checkboxTop:"top-1.5 left-1.5",contentPadding:"p-0",imageContainer:"",text:"text-sm"}}[m];if(u)return(0,i.jsx)("div",{className:"aspect-square w-full h-full overflow-hidden rounded-sm relative bg-muted flex items-center justify-center select-none",style:{cursor:ex?"grabbing":eu?"grab":"pointer"},children:(0,i.jsx)(eG,{item:a,isHovered:!1,videoRef:ei})});let eU=a.type.startsWith("image/"),e_=a.type.startsWith("video/"),eB=p&&p.size>1,eq=p&&1===p.size;return(0,i.jsxs)(eI,{onOpenChange:ej,children:[(0,i.jsx)(eA,{asChild:!0,disabled:ec,children:(0,i.jsxs)(eS.Zp,{ref:eg,style:{...eF,overflow:"visible",...T?{cursor:"inherit"}:{}},...eu&&!X?em:{},className:(0,N.cn)("group relative w-full h-full shadow-none will-change-transform select-none",eL.card,"transition-all duration-300","border-0",X&&"cursor-default",l&&!X?"ring-2 ring-primary bg-accent":"",!l&&s&&!X&&"ring-2 ring-primary/40 bg-primary/5",l&&s&&!X&&"ring-2 ring-destructive/40 bg-destructive/5",!ec&&!ex&&!l&&!s&&!X&&"hover:ring-2 hover:ring-primary/20",!ec&&!ex&&!X&&"hover:bg-accent/50",ex&&!eE&&"shadow-lg scale-105 z-50","overflow-visible",T&&"!cursor-inherit"),onPointerDown:e=>{Date.now()-el.current<300&&(e.preventDefault(),e.stopPropagation())},onClick:eb,onMouseEnter:ey,onMouseLeave:ew,children:[X&&(0,i.jsx)("div",{className:(0,N.cn)("absolute inset-0 bg-background/50 flex items-center justify-center z-[55] rounded-lg",Y&&K&&!G?"pointer-events-auto":"pointer-events-none"),children:G?(0,i.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,i.jsx)(f.A,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:V("canceling")})]}):Y&&K&&(ee||ec)?(0,i.jsx)(o.$,{type:"button",variant:"secondary",size:"sm",className:"h-7 px-2 text-xs",onClick:e=>{e.stopPropagation(),K(a.id)},children:V("cancel")}):(0,i.jsx)(eV.X,{})}),Z&&(0,i.jsx)("div",{className:"absolute top-2 right-2 z-[55] pointer-events-none",children:(0,i.jsx)(ez.A,{className:"h-4 w-4 text-destructive"})}),!C&&!X&&(0,i.jsx)("div",{ref:er,className:(0,N.cn)("absolute z-20 checkbox-container flex items-center justify-center",eL.checkboxTop,eo&&!ed&&"!opacity-0","cursor-default"),style:{opacity:ee||l?1:0,transition:"opacity 150ms ease-out",pointerEvents:ee||l?"auto":"none",willChange:"opacity",contain:"layout style paint",minWidth:"20px",minHeight:"20px"},onClick:e=>e.stopPropagation(),children:(0,i.jsx)(eN.S,{checked:l,"aria-label":"Select ".concat(a.name),tabIndex:-1,onCheckedChange:()=>ev(),className:"cursor-pointer bg-white shrink-0"})}),(0,i.jsx)(eS.Wu,{className:(0,N.cn)("p-0 flex flex-col rounded-[inherit]",eL.contentPadding,"overflow-visible"),...eu&&!X?eh:{}
1,style:{...T?{cursor:"inherit"}:{cursor:X?"default":ex?"grabbing":eu?"grab":"pointer"}},children:(0,i.jsxs)("div",{className:(0,N.cn)("aspect-square w-full relative overflow-hidden rounded-[inherit] bg-muted flex items-center justify-center",eL.imageContainer),children:[(0,i.jsx)(eK,{item:a,isHovered:ee,isError:q,onError:()=>{en.current&&H(!0)},priority:k,imageKey:eC,videoRef:ea,isProcessing:X,sizes:k?"160px":"(max-width: 768px) 33vw, (max-width: 1200px) 20vw, 15vw"}),!S&&(0,i.jsx)("p",{className:(0,N.cn)("pointer-events-none absolute inset-x-0 bottom-0 z-10 before:absolute before:inset-x-0 before:top-0 before:-bottom-px before:bg-gradient-to-t before:from-black/80 before:to-transparent before:content-[''] px-2 pb-2 pt-6 font-medium text-center text-xs text-white transition-opacity [@media(hover:hover)]:opacity-0 [@media(hover:hover)]:group-hover:opacity-100 [@media(hover:hover)]:group-has-[:focus-visible]:opacity-100",eL.text),title:a.name,style:{cursor:"inherit"},children:(0,i.jsx)("span",{className:"relative block truncate",children:a.name})})]})})]})}),(0,i.jsx)(eP,{className:"w-52",children:eB?(0,i.jsxs)(i.Fragment,{children:[A&&z&&!U&&!L&&(0,i.jsxs)(eM,{onSelect:()=>{B&&B(),setTimeout(()=>{let e=Date.now();_&&_(),el.current=e,A()},0)},children:[(0,i.jsx)(x.A,{className:"mr-2 h-4 w-4"}),W("createPostButton"),(0,i.jsx)(eR,{children:"P"})]}),F&&!U&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),F()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),W("moveButton"),(0,i.jsx)(eR,{children:"M"})]}),O&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),O()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),W("delete"),(0,i.jsx)(eR,{children:"Del"})]})]}):(0,i.jsxs)(i.Fragment,{children:[A&&z&&!U&&!L&&(0,i.jsxs)(eM,{onSelect:()=>{B&&B(),setTimeout(()=>{let e=Date.now();_&&_(),el.current=e,A()},0)},children:[(0,i.jsx)(x.A,{className:"mr-2 h-4 w-4"}),W("createPostButton"),(0,i.jsx)(eR,{children:"P"})]}),P&&eq&&z&&!U&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),P()},0)},children:[(0,i.jsx)(g.A,{className:"mr-2 h-4 w-4"}),W("previewButton"),(0,i.jsx)(eR,{children:"Space"})]}),M&&eq&&!U&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),M()},0)},children:[(0,i.jsx)(b.A,{className:"mr-2 h-4 w-4"}),W("editButton"),(0,i.jsx)(eR,{children:"E"})]}),D&&eq&&z&&!U&&eU&&!e_&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),D()},0)},children:[(0,i.jsx)("div",{className:"mr-2 h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"canva_edit_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),W("canva.editWithCanva")]}),R&&eq&&z&&!U&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),R()},0)},children:[(0,i.jsx)(v.A,{className:"mr-2 h-4 w-4"}),W("convertButton")]}),(0,i.jsx)(eD,{}),F&&!U&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),F()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),W("moveButton"),(0,i.jsx)(eR,{children:"M"})]}),O&&!Y&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{_&&_(),el.current=Date.now(),O()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),W("delete"),(0,i.jsx)(eR,{children:"Del"})]})]})})]})},(e,t)=>{let a=e.item.id!==t.item.id,i=e.isSelected!==t.isSelected,n=e.isPreSelected!==t.isPreSelected,r=e.itemSize!==t.itemSize,l=e.activeId!==t.activeId,s=e.item.url!==t.item.url,o=e.item.thumbnailUrl!==t.item.thumbnailUrl,d=e.item.name!==t.item.name,c=!(0,eO.S)(e.item)&&!(0,eO.S)(t.item)&&e.item.status!==t.item.status,u=e.isCancellingConversion!==t.isCancellingConversion;return!(a||i||n||r||l||s||o||d||c||u)});var eH=a(93949);function e$(e){let{folders:t,media:a,selectedItems:l,onSelect:s,onItemClick:d,activeId:u,itemSize:h="default",enableFolderSelection:p=!1,onMediaHover:f,onMediaHoverEnd:x,onContextMenuCreatePost:g,onContextMenuPreview:v,onContextMenuEdit:b,onContextMenuEditWithCanva:y,onContextMenuConvert:w,onContextMenuMove:j,onContextMenuDelete:C,onContextMenuCreateFolder:S,onContextMenuUpload:k,onContextMenuCanvaImport:T,onlyMediaSelected:E=!1,isSelectedMediaVideo:I=!1,hideCreatePostButton:A=!1,isSelectionContext:P=!1,onClearSelection:M,onBatchToggleSelection:D,onMenuInteraction:R,onPreserveSelection:F,onCancelC
1onversion:O,isCancellingConversion:z}=e,L=(0,r.useTranslations)("Media"),[U,_]=(0,n.useState)(!1),B=(0,n.useRef)(null),K=(0,n.useRef)(null),[G,W]=(0,n.useState)(!1),[V,q]=(0,n.useState)(null),[H,$]=(0,n.useState)(null),[Y,X]=(0,n.useState)(!1),Z=(0,n.useRef)(0),J=(0,n.useRef)(new Map),Q=(0,n.useRef)(!1),ee=(0,n.useRef)(!1),et=(0,n.useRef)(0),ea=(0,ek.a)(),ei=(0,n.useCallback)((e,t)=>{let a=Date.now();ee.current||a-et.current<500||(ee.current=!0,et.current=a,d&&d(e,t),setTimeout(()=>{ee.current=!1},500))},[d]);(0,n.useEffect)(()=>{_(!0);let e=()=>{Z.current=Date.now()};return window.addEventListener("dopost-menu-interaction",e),()=>{window.removeEventListener("dopost-menu-interaction",e),ee.current&&(ee.current=!1)}},[]);let{uniqueFolders:en,uniqueMedia:er}=(0,n.useMemo)(()=>({uniqueFolders:t.filter((e,t,a)=>t===a.findIndex(t=>t.id===e.id)),uniqueMedia:a.filter((e,t,a)=>t===a.findIndex(t=>t.id===e.id))}),[t,a]),el=(0,n.useMemo)(()=>[...en.map(e=>({type:"folder",data:e})),...er.map(e=>({type:"media",data:e}))],[en,er]),es=(0,n.useCallback)(e=>{if(!(0!==e.button||ea||Y||Date.now()-Z.current<300)&&!e.target.closest("[data-media-item], [data-folder-item]")&&K.current){let t=K.current.getBoundingClientRect(),a=e.clientX-t.left,i=e.clientY-t.top;q({x:a,y:i}),$({x:a,y:i})}},[Y]),eo=(0,n.useCallback)(e=>{if(G||Q.current||Date.now()-Z.current<300||document.querySelector('[data-radix-menu-content], [role="menu"]'))return;let t=e.target;if(!t.closest('[data-media-item], [data-folder-item], [role="checkbox"], button, a, input, textarea')&&M&&K.current){let e=t===K.current,a=K.current.contains(t)&&!t.closest("[data-media-item], [data-folder-item]");(e||a)&&M()}},[G,M]),ed=(0,n.useCallback)(e=>{if(!V||!K.current)return;let t=K.current.getBoundingClientRect(),a=e.clientX-t.left,i=e.clientY-t.top;!G&&(Math.abs(a-V.x)>3||Math.abs(i-V.y)>3)&&W(!0),G&&$({x:a,y:i})},[G,V]);(0,n.useCallback)(()=>{W(!1),q(null),$(null)},[]);let ec=(0,n.useCallback)(e=>{X(e&&!ea),Z.current=Date.now(),R&&R(),e&&(0,eC.flushSync)(()=>{W(!1),q(null),$(null)})},[R,ea]);(0,n.useEffect)(()=>{if(!V)return;let e=e=>{let a=Date.now()-Z.current;if(Y||a<500)return void t();if(G&&V&&H&&K.current){let e=Math.min(V.x,H.x),t=Math.max(V.x,H.x),a=Math.min(V.y,H.y),i=Math.max(V.y,H.y),n=[];J.current.forEach((r,l)=>{let s=r.getBoundingClientRect(),o=K.current.getBoundingClientRect(),d=s.left-o.left,c=s.right-o.left,u=s.top-o.top,m=s.bottom-o.top;c<e||d>t||m<a||u>i||n.push(l)}),n.length>0&&(D?D(n):n.forEach(e=>{let t=en.some(t=>t.id===e);s(e,t?"folder":"media")}))}G&&(Q.current=!0,setTimeout(()=>{Q.current=!1},100)),t()},t=()=>{(0,eC.flushSync)(()=>{W(!1),q(null),$(null)})};return window.addEventListener("mouseup",e,{capture:!0,once:!0}),()=>{window.removeEventListener("mouseup",e,{capture:!0})}},[V,H,G,Y,en,s,D]);let eu=(0,n.useMemo)(()=>{if(!G||!V||!H||!K.current)return new Set;let e=Math.min(V.x,H.x),t=Math.max(V.x,H.x),a=Math.min(V.y,H.y),i=Math.max(V.y,H.y),n=new Set;return J.current.forEach((r,l)=>{let s=r.getBoundingClientRect(),o=K.current.getBoundingClientRect(),d=s.left-o.left,c=s.right-o.left,u=s.top-o.top,m=s.bottom-o.top;c<e||d>t||m<a||u>i||n.add(l)}),n},[G,V,H]);if((0,n.useEffect)(()=>{if(G&&V&&K.current){let e=e=>{let t=K.current.getBoundingClientRect();$({x:e.clientX-t.left,y:e.clientY-t.top})};return window.addEventListener("mousemove",e),()=>{window.removeEventListener("mousemove",e)}}},[G,V]),!U)return null;let em=el.length>0,eh=V&&H&&(Math.abs(H.x-V.x)>2||Math.abs(H.y-V.y)>2)?{left:Math.min(V.x,H.x),top:Math.min(V.y,H.y),width:Math.abs(H.x-V.x),height:Math.abs(H.y-V.y)}:null;return(0,i.jsx)("div",{ref:B,className:"w-full h-full",children:em?(0,i.jsxs)(eI,{onOpenChange:ec,children:[(0,i.jsx)(eA,{asChild:!0,disabled:ea,children:(0,i.jsxs)("div",{ref:K,className:(0,N.cn)("".concat({sm:"grid gap-4",default:"grid gap-4",lg:"grid gap-4"}[h]),"relative min-h-full pb-32"),style:{gridTemplateColumns:"repeat(auto-fill, minmax(160px, 1fr))",gridAutoRows:"min-content",alignContent:"start",maxWidth:"100%"},onMouseDown:es,onMouseMove:ed,onClick:eo,children:[en.map(e=>(0,i.jsx)("div",{className:"max-w-[200px] w-full","data-folder-item":!0,ref:t=>{t?J.current.set(e.id,t):J.current.delete(e.id)},children:(0,i.jsx)(eF,{folder:e,isSelected:l.has(e.id),isPreSelected:eu.has(e.id),onSelect:s,onItemClick:ei,isDragging:u===e.id,activeId:u,selectedItems:l,itemSize:h,enableFolderSelection:p,onContextMenuEdit:b,onContextMenuMove:j,onContextMenuDelete:C,onMenuInteraction:R,onPreserveSelection:F})},e.id)),er.map(e=>{var t;return(0,i.jsx)("div",{className:"max-w-[200px] w-full","data-media-item":!0,ref:t=>{t?J.current.set(e.id,t):J.current.delete(e.id)},children:(0,i.jsx)(eq,{item:e,isSelected:l.has(e.id),isPreSelected:eu.has(e.id),onSelect:s,onItemClick:d,itemSize:h,activeId:u,selectedItems:l,onMediaHover:f,onMediaHoverEnd:x,onContextMenuCreatePost:g,onContextMenuPreview:v,onContextMenuEdit:b,onContextMenuEditWithCanva:y,onContextMenuConvert:w,onContextMenuMove:j,onContextMenuDelete:C,onlyMediaSelected:E,isSelectedMediaVideo:I,hideCreatePostButton:A,isSelectionContext:P,onMenuInteraction:R,onPreserveSelection:F,onCancelC
1onversion:O,isCancellingConversion:null!=(t=null==z?void 0:z(e.id))&&t})},e.id)}),eh&&G&&(0,i.jsx)("div",{className:"absolute border-2 border-primary bg-primary/10 pointer-events-none z-50",style:{left:"".concat(eh.left,"px"),top:"".concat(eh.top,"px"),width:"".concat(eh.width,"px"),height:"".concat(eh.height,"px")}})]})}),!ea&&(0,i.jsxs)(eP,{className:"w-52",children:[S&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),S()},0)},children:[(0,i.jsx)(m.A,{className:"mr-2 h-4 w-4"}),"New Folder"]}),k&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),k()},0)},children:[(0,i.jsx)(c.A,{className:"mr-2 h-4 w-4"}),L("upload")]}),T&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),T()},0)},children:[(0,i.jsx)("div",{className:"mr-2 h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_context_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_context_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_context_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_context_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"canva_context_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_context_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_context_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_context_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),L("canva.import")]})]})]}):(0,i.jsxs)(eI,{onOpenChange:ec,children:[(0,i.jsx)(eA,{asChild:!0,disabled:ea,children:(0,i.jsx)(eH.p,{surface:"panel",className:"min-h-[200px]",title:L("emptyFolder"),description:L("emptyFolderDe
1scription"),actions:(0,i.jsxs)(i.Fragment,{children:[k?(0,i.jsxs)(o.$,{onClick:k,children:[(0,i.jsx)(c.A,{className:"h-4 w-4"}),L("upload")]}):null,S?(0,i.jsxs)(o.$,{variant:"outline",onClick:S,children:[(0,i.jsx)(m.A,{className:"h-4 w-4"}),L("newFolder")]}):null]})})}),!ea&&(0,i.jsxs)(eP,{className:"w-52",children:[S&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),S()},0)},children:[(0,i.jsx)(m.A,{className:"mr-2 h-4 w-4"}),"New Folder"]}),k&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),k()},0)},children:[(0,i.jsx)(c.A,{className:"mr-2 h-4 w-4"}),L("upload")]}),T&&(0,i.jsxs)(eM,{onSelect:()=>{setTimeout(()=>{Z.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction")),T()},0)},children:[(0,i.jsx)("div",{className:"mr-2 h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_empty_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_empty_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_empty_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_empty_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"canva_empty_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_empty_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_empty_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_empty_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),L("canva.import")]})]})]})})}var eY=a(7505),eX=a(14552),eZ=a(67910);
1function eJ(){let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{t(!0)},[]),e}var eQ=a(14668);function e0(e){var t,a,s,o,d,c,u,m;let{virtualRow:h,itemData:p,isSelected:C,activeId:S,selectedItems:k,onSelect:T,onItemClick:E,gridTemplateColumns:I,isFirst:A,isLast:P,totalItems:M,onMediaHover:D,onMediaHoverEnd:R,onContextMenuCreatePost:F,onContextMenuPreview:z,onContextMenuEdit:L,onContextMenuEditWithCanva:U,onContextMenuConvert:_,onContextMenuMove:B,onContextMenuDelete:K,onlyMediaSelected:G,isSelectedMediaVideo:W,hideCreatePostButton:V,isSelectionContext:q,onMenuInteraction:H,onPreserveSelection:$}=e,{type:Y,data:X}=p,Z="folder"===Y,J=eJ(),Q=(0,r.useTranslations)(),ee=(0,n.useRef)(!1),et=(0,n.useRef)(0),ea=null!==(0,j.fF)().active,ei=(0,ek.a)(),en=!ei,er=!Z&&"CONVERTING"===X.status,{attributes:el,listeners:es,setNodeRef:eo,isDragging:ed}=(0,j.PM)({id:X.id,data:{...p,viewMode:"list"},disabled:!en||er}),{isOver:ec,setNodeRef:eu}=(0,j.zM)({id:X.id,data:{...p},disabled:!Z}),em=(0,n.useCallback)(e=>{eo(e),Z&&eu(e)},[eo,eu,Z]),eh=e=>{er||(null==e||e.stopPropagation(),T(X.id,Y))},ep=(0,n.useCallback)(e=>{if(!(er||e.target.closest(".checkbox-cell"))&&!(Date.now()-et.current<300)){if(Z&&ee.current){e.preventDefault(),e.stopPropagation();return}E?Z?(T(X.id,Y),ee.current=!0,setTimeout(()=>{E(X.id,Y),setTimeout(()=>{ee.current=!1},300)},10)):E(X.id,Y):T(X.id,Y)}},[E,T,X.id,Y,Z,er]),ef=(0,n.useCallback)(e=>{H&&H(),et.current=Date.now(),e&&!er&&T(X.id,Y,!0)},[X.id,Y,er,T,H]);(0,n.useEffect)(()=>()=>{ee.current=!1},[]);let ex=ea&&null!==S&&k.has(S),eg=ex&&k.has(X.id),ev={position:"absolute",top:0,left:0,width:"100%",height:"".concat(h.size,"px"),transform:"translateY(".concat(h.start,"px)"),opacity:ed||eg?.3:1,transition:"opacity 0.2s ease-out",boxSizing:"border-box",cursor:er?"default":ed?"grabbing":en?"grab":"default"},eb="border-x ";1===M?eb+="border-t rounded-b-md":A?eb+="border-t":P?eb+="border-t border-b rounded-b-md":eb+="border-t";let ey=(0,N.cn)(eb,"transition-colors box-border",C&&!ex?"bg-accent shadow-sm":"",ei||C?"":"hover:bg-muted/50",ec&&Z&&!ed&&"bg-muted"),ew=J&&en&&!er?el:{},ej=J&&en&&!er?es:{},eC=k&&k.size>1,eS=k&&1===k.size,eT=null!=(s=null==(t=X.type)?void 0:t.startsWith("image/"))&&s,eE=null!=(o=null==(a=X.type)?void 0:a.startsWith("video/"))&&o,eF=Z?null:eT?X.url:null!=(d=X.thumbnailUrl)?d:null;return(0,i.jsxs)(eI,{onOpenChange:ef,children:[(0,i.jsx)(eA,{asChild:!0,disabled:ei,children:(0,i.jsxs)("div",{ref:em,"data-index":h.index,style:{...ev,display:"grid",gridTemplateColumns:I,alignContent:"stretch",alignItems:"stretch"},className:(0,N.cn)(ey,"text-sm"),...ew,...en&&!ei?ej:{},"data-is-folder":Z?"true":void 0,"data-folder-id":Z?X.id:void 0,onPointerDown:e=>{Date.now()-et.current<300&&(e.preventDefault(),e.stopPropagation())},onClick:ep,onMouseEnter:()=>{!Z&&D&&D(X.id)},onMouseLeave:()=>{!Z&&R&&R()},children:[(0,i.jsx)("div",{className:(0,N.cn)("flex items-center justify-center checkbox-cell pl-0 pr-0 py-3 min-h-full self-stretch box-border",er&&"pointer-events-none opacity-50"),onClick:e=>{e.stopPropagation(),eh()},children:(0,i.jsx)(eN.S,{checked:C,disabled:er,onCheckedChange:()=>eh(),"aria-label":Q("Media.list.ariaLabels.selectItem",{itemName:X.name}),onClick:e=>e.stopPropagation()})}),(0,i.jsx)("div",{className:"px-1 py-3 flex items-center justify-center min-h-full self-stretch box-border",children:Z?(0,i.jsx)(O.s,{className:"h-7 w-7 flex-shrink-0",color:X.color}):er&&eF?(0,i.jsxs)("div",{className:"relative h-7 w-7 flex-shrink-0 rounded-sm overflow-hidden bg-muted",children:[(0,i.jsx)(l.default,{src:eF,alt:X.name,width:28,height:28,className:"h-full w-full object-cover",unoptimized:!0}),(0,i.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-background/50",children:(0,i.jsx)(f.A,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})})]}):(null==(c=X.type)?void 0:c.startsWith("image/"))?(0,i.jsx)("div",{className:"h-7 w-7 flex-shrink-0 rounded-sm overflow-hidden bg-muted",children:(0,i.jsx)(l.default,{src:X.url,alt:X.name,width:28,height:28,className:"h-full w-full object-cover"})}):(null==(u=X.type)?void 0:u.startsWith("video/"))?(0,i.jsx)("div",{className:"h-7 w-7 flex-shrink-0 rounded-sm overflow-hidden bg-muted",children:(0,i.jsx)("video",{src:"".concat(X.url,"#t=0.1"),muted:!0,preload:"metadata",poster:null!=(m=X.thumbnailUrl)?m:void 0,className:"h-full w-full object-cover"})}):(0,i.jsx)(eU.A,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"})}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium flex items-center gap-3 overflow-hidden min-w-0 pl-4 pr-1 sm:px-4 py-3 min-h-full self
1-stretch box-border"),children:(0,i.jsxs)("div",{className:"flex items-center gap-2 w-full overflow-hidden",...!ei&&!er?ej:{},style:{cursor:er?"default":ed?"grabbing":en?"grab":"default"},children:[(0,i.jsx)("span",{className:"truncate",children:X.name}),er&&(0,i.jsxs)("span",{className:"shrink-0 text-[10px] text-muted-foreground flex items-center gap-1",children:[(0,i.jsx)(f.A,{className:"h-3 w-3 animate-spin"}),Q("Media.processing")]})]})}),(0,i.jsx)("div",{className:(0,N.cn)("truncate whitespace-nowrap pl-1 pr-0 sm:px-2 py-3 text-right flex items-center justify-end gap-1 sm:gap-2 min-h-full self-stretch box-border"),children:Z?(0,i.jsx)("span",{className:"text-xs sm:text-sm",children:Q("Media.list.types.folder")}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{className:"uppercase text-xs sm:text-sm",children:function(e){let t=e.lastIndexOf(".");return -1===t||t===e.length-1?"":e.slice(t+1).toLowerCase()}(X.name)}),function(e){let t="h-3 w-3 sm:h-4 sm:w-4 text-muted-foreground flex-shrink-0";if("string"!=typeof e)return(0,i.jsx)(eU.A,{className:t});let a=e.toLowerCase();return a.startsWith("image/")||a.match(/\.png$|\.jpg$|\.jpeg$|\.webp$|\.gif$/)?(0,i.jsx)(eX.A,{className:t}):a.startsWith("video/")||a.match(/\.mp4$|\.webm$|\.mov$|\.mkv$/)?(0,i.jsx)(eZ.A,{className:t}):(0,i.jsx)(eU.A,{className:t})}(X.type||X.name)]})}),(0,i.jsx)("div",{className:(0,N.cn)("truncate whitespace-nowrap pl-2 pr-2 sm:px-4 py-3 text-right text-xs sm:text-sm flex items-center justify-end min-h-full self-stretch box-border"),children:Z?Q("Media.list.fileSize.unknown"):function(e,t){if(!e||e<=0)return t("Media.list.fileSize.unknown");let a=[t("Media.list.fileSize.units.bytes"),t("Media.list.fileSize.units.kilobytes"),t("Media.list.fileSize.units.megabytes"),t("Media.list.fileSize.units.gigabytes")],i="bigint"==typeof e?Number(e):e,n=0;for(;i>=1024&&n<a.length-1;)i/=1024,n++;return"".concat(i.toFixed(+(0!==n))," ").concat(a[n])}(X.sizeInBytes,Q)}),(0,i.jsx)("div",{className:(0,N.cn)("truncate whitespace-nowrap px-4 py-3 text-right hidden sm:flex items-center justify-end min-h-full self-stretch box-border"),children:(0,eY.GP)(new Date(X.createdAt),"PP")})]},h.key)}),(0,i.jsx)(eP,{className:"w-52",children:Z?(0,i.jsxs)(i.Fragment,{children:[L&&eS&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),L()},0)},children:[(0,i.jsx)(b.A,{className:"mr-2 h-4 w-4"}),Q("Media.editButton"),(0,i.jsx)(eR,{children:"E"})]}),(0,i.jsx)(eD,{}),B&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),B()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),Q("Media.moveButton"),(0,i.jsx)(eR,{children:"M"})]}),K&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),K()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),Q("Media.delete"),(0,i.jsx)(eR,{children:"Del"})]})]}):eC?(0,i.jsxs)(i.Fragment,{children:[F&&G&&!q&&!V&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),F()},0)},children:[(0,i.jsx)(x.A,{className:"mr-2 h-4 w-4"}),Q("Media.createPostButton"),(0,i.jsx)(eR,{children:"P"})]}),B&&!q&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),B()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),Q("Media.moveButton"),(0,i.jsx)(eR,{children:"M"})]}),K&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),K()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),Q("Media.delete"),(0,i.jsx)(eR,{children:"Del"})]})]}):(0,i.jsxs)(i.Fragment,{children:[F&&G&&!q&&!V&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),F()},0)},children:[(0,i.jsx)(x.A,{className:"mr-2 h-4 w-4"}),Q("Media.createPostButton"),(0,i.jsx)(eR,{children:"P"})]}),z&&eS&&G&&!q&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),z()},0)},children:[(0,i.jsx)(g.A,{className:"mr-2 h-4 w-4"}),Q("Media.previewButton"),(0,i.jsx)(eR,{children:"Space"})]}),L&&eS&&!q&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),L()},0)},children:[(0,i.jsx)(b.A,{className:"mr-2 h-4 w-4"}),Q("Media.editButton"),(0,i.jsx)(eR,{children:"E"})]}),U&&eS&&G&&!q&&eT&&!eE&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),U()},0)}
1,children:[(0,i.jsx)("div",{className:"mr-2 h-4 w-4 rounded-full overflow-hidden flex items-center justify-center shrink-0",children:(0,i.jsxs)("svg",{viewBox:"0 0 64 64",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"h-full w-full",children:[(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"#7D2AE7"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint0_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint1_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint2_radial)"}),(0,i.jsx)("path",{d:"M32 64C49.6731 64 64 49.6731 64 32C64 14.3269 49.6731 0 32 0C14.3269 0 0 14.3269 0 32C0 49.6731 14.3269 64 32 64Z",fill:"url(#canva_edit_paint3_radial)"}),(0,i.jsx)("path",{d:"M45.8152 38.5644C45.5511 38.5644 45.3187 38.7874 45.0769 39.2745C42.3458 44.8125 37.6286 48.731 32.17 48.731C25.8582 48.731 21.9495 43.0333 21.9495 35.1619C21.9495 21.8286 29.3785 14.1195 35.9037 14.1195C38.9527 14.1195 40.8148 16.0357 40.8148 19.0849C40.8148 22.7039 38.7587 24.62 38.7587 25.8964C38.7587 26.4693 39.1151 26.8162 39.8218 26.8162C42.661 26.8162 45.9934 23.5538 45.9934 18.9449C45.9934 14.476 42.1039 11.1912 35.5789 11.1912C24.7951 11.1912 15.2113 21.1888 15.2113 35.0218C15.2113 45.7294 21.3257 52.8051 30.7599 52.8051C40.7734 52.8051 46.5634 42.8423 46.5634 39.6086C46.5634 38.8925 46.1972 38.5644 45.8152 38.5644Z",fill:"white"}),(0,i.jsxs)("defs",{children:[(0,i.jsxs)("radialGradient",{id:"canva_edit_paint0_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-49.4156) scale(49.4986)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint1_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(16.9432 7.27579) rotate(54.7035) scale(55.8188)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint2_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(12.3621 56.7242) rotate(-45.1954) scale(48.8994 22.4895)",children:[(0,i.jsx)("stop",{stopColor:"#6420FF"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#6420FF",stopOpacity:"0"})]}),(0,i.jsxs)("radialGradient",{id:"canva_edit_paint3_radial",cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:"translate(26.1726 8.62316) rotate(66.5198) scale(50.3869 84.4093)",children:[(0,i.jsx)("stop",{stopColor:"#00C4CC",stopOpacity:"0.725916"}),(0,i.jsx)("stop",{offset:"0.0001",stopColor:"#00C4CC"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#00C4CC",stopOpacity:"0"})]})]})]})}),Q("Media.canva.editWithCanva")]}),_&&eS&&G&&!q&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),_()},0)},children:[(0,i.jsx)(v.A,{className:"mr-2 h-4 w-4"}),Q("Media.convertButton")]}),(0,i.jsx)(eD,{}),B&&!q&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),B()},0)},children:[(0,i.jsx)(y.A,{className:"mr-2 h-4 w-4"}),Q("Media.moveButton"),(0,i.jsx)(eR,{children:"M"})]}),K&&!er&&(0,i.jsxs)(eM,{onSelect:()=>{$&&$(),setTimeout(()=>{H&&H(),et.current=Date.now(),K()},0)},className:"text-destructive focus:text-destructive",children:[(0,i.jsx)(w.A,{className:"mr-2 h-4 w-4"}),Q("Media.delete"),(0,i.jsx)(eR,{children:"Del"})]})]})})]})}function e1(e){let{folders:t,media:a,selectedItems:l,onSelect:s,onItemClick:d,activeId:u,setListCollisionDetection:h,scrollElementRef:p,onMediaHover:f,onMediaHoverEnd:x,onMenuInteraction:g,onContextMenuCreatePost:v,onContextMenuPreview:b,onContextMenuEdit:y,onContextMenuEditWithCanva:w,onContextMenuConvert:j,onContextMenuMove:C,onContextMenuDelete:S,onContextMenuCreateFolder:k,onContextMenuUpload:T,onContextMenuCanvaImport:E,onlyMediaSelected:I,isSelectedMediaVideo:A,hideCreatePostButton:P,isSelectionContext:M,onPreserveSelection:D}=e,R=(0,n.useRef)(null),F=eJ(),O=(0,ek.a)(),z=(0,r.useTranslations)(),L=(0,n.useCallback)(()=>
1{if(!R.current)return null;let e=R.current.parentElement;for(;e;){let t=window.getComputedStyle(e),a=t.overflowY||t.overflow;if("auto"===a||"scroll"===a)return e;e=e.parentElement}return null},[]),U=(0,n.useMemo)(()=>[...t.map(e=>({type:"folder",data:e})),...a.map(e=>({type:"media",data:e}))],[t,a]),_=O?"50px 40px minmax(120px,2fr) 60px 80px var(--date-col-width,0px)":"50px 40px minmax(0,1fr) 120px 100px var(--date-col-width,100px)",B=(0,eQ.Te)({count:U.length,getScrollElement:()=>(null==p?void 0:p.current)||L(),estimateSize:()=>49,overscan:5}),K=(0,n.useCallback)(e=>{let{pointerCoordinates:t,droppableContainers:a}=e,i=(null==p?void 0:p.current)||L(),n=R.current;if(!t||!i||!B||!n)return[];let r=n.getBoundingClientRect(),l=t.y-r.top-48+i.scrollTop,s=-1;for(let e of B.getVirtualItems())if(l>=e.start&&l<e.start+e.size){s=e.index;break}if(s<0||s>=U.length)return[];let o=U[s];if("folder"!==o.type)return[];let d=o.data.id,c=a.find(e=>e.id===d);return c?[{id:c.id,data:{droppableContainer:c,...o.data}}]:[]},[B,U,p,L]);if((0,n.useEffect)(()=>(B&&U.length>0?h(()=>K):h(null),()=>h(null)),[h,K,B,U]),!F)return null;let G=U.length>0;return(0,i.jsxs)("div",{ref:R,className:"h-full flex flex-col",children:[G&&(0,i.jsxs)("div",{className:"grid items-center border-x border-t rounded-t-md bg-background h-12 flex-shrink-0 text-sm [--date-col-width:0px] sm:[--date-col-width:120px]",style:{gridTemplateColumns:O?"50px 40px minmax(120px,2fr) 60px 80px var(--date-col-width,0px)":"50px 40px minmax(0,1fr) 120px 100px var(--date-col-width,160px)"},children:[(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground pl-0 pr-0"),children:(0,i.jsx)("span",{className:"sr-only",children:z("Media.list.headers.select")})}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground px-1")}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground min-w-0 px-4"),children:z("Media.list.headers.name")}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground whitespace-nowrap pl-1 pr-0 sm:px-2 text-right"),children:z("Media.list.headers.type")}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground whitespace-nowrap pl-2 pr-2 sm:px-4 text-right"),children:z("Media.list.headers.size")}),(0,i.jsx)("div",{className:(0,N.cn)("font-medium text-muted-foreground whitespace-nowrap px-4 text-right hidden sm:flex sm:items-center sm:justify-end"),children:z("Media.list.headers.dateCreated")})]}),(0,i.jsx)("div",{className:"flex-grow relative",children:G?(0,i.jsx)("div",{className:"[--date-col-width:0px] sm:[--date-col-width:120px]",style:{height:"".concat(B.getTotalSize(),"px"),width:"100%",position:"relative"},children:B.getVirtualItems().map(e=>{let t=U[e.index],a=t.data,n=l.has(a.id),r=0===e.index,o=e.index===U.length-1;return(0,i.jsx)(e0,{virtualRow:e,itemData:t,isSelected:n,activeId:u,selectedItems:l,onSelect:s,onItemClick:d,gridTemplateColumns:_,isFirst:r,isLast:o,totalItems:U.length,onMediaHover:f,onMediaHoverEnd:x,onContextMenuCreatePost:v,onContextMenuPreview:b,onContextMenuEdit:y,onContextMenuEditWithCanva:w,onContextMenuConvert:j,onContextMenuMove:C,onContextMenuDelete:S,onlyMediaSelected:I,isSelectedMediaVideo:A,hideCreatePostButton:P,isSelectionContext:M,onMenuInteraction:g,onPreserveSelection:D},e.key)})}):(0,i.jsx)(eH.p,{size:"compact",className:"min-h-[200px] rounded-md border",title:z("Media.emptyFolder"),description:z("Media.emptyFolderDescription"),actions:(0,i.jsxs)(i.Fragment,{children:[T?(0,i.jsxs)(o.$,{size:"sm",onClick:T,children:[(0,i.jsx)(c.A,{className:"h-4 w-4"}),z("Media.upload")]}):null,k?(0,i.jsxs)(o.$,{size:"sm",variant:"outline",onClick:k,children:[(0,i.jsx)(m.A,{className:"h-4 w-4"}),z("Media.newFolder")]}):null]})})})]})}function e2(e){let{open:t,onOpenChange:a,itemCount:n,onConfirm:l,selectedItems:s,folders:d=[],media:c=[],isLoading:u=!1}=e,m=(0,r.useTranslations)("Media"),h=d.filter(e=>null==s?void 0:s.has(e.id)),p=c.filter(e=>null==s?void 0:s.has(e.id)),x=h.length>0;return(0,i.jsx)(D.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(D.Cf,{children:[(0,i.jsxs)(D.c7,{children:[(0,i.jsx)(D.L3,{className:"flex items-center gap-2",children:m("deleteConfirmTitle")}),(0,i.jsx)(D.rr,{className:"text-left",children:(()=>
1{if(1===n&&1===p.length)return m("deleteConfirmDescription");if(1===n&&1===h.length)return m("deleteFolderDescription",{folderName:h[0].name});let e=[];if(p.length>0){let t=1===p.length?m("mediaFileCount",{count:p.length}):m("mediaFilesCount",{count:p.length});e.push(t)}if(h.length>0){let t=1===h.length?m("folderCount",{count:h.length}):m("foldersCount",{count:h.length});e.push(t)}let t=m("deleteMultipleItemsDescription",{items:e.join(" and ")});return x&&(t+=" "+m("deleteMultipleItemsWithFolders")),t+=" "+m("actionCannotBeUndone")})()})]}),(0,i.jsxs)(D.Es,{children:[(0,i.jsx)(D.HM,{asChild:!0,children:(0,i.jsx)(o.$,{variant:"outline",children:m("cancel")})}),(0,i.jsx)(o.$,{variant:"destructive",onClick:()=>{l()},disabled:u,children:u?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(f.A,{className:"mr-2 h-4 w-4 animate-spin"}),m("deleting")]}):m("delete")})]})]})})}var e4=a(90633);function e3(e){let{node:t,level:a,selectedTargetFolder:n,onSelectFolder:r,currentFolderId:l,foldersToMove:s,invalidFolderIds:o}=e,d=n===t.id,c=t.id===l,u=(null==o?void 0:o.has(t.id))||!1,m=c||u;return(0,i.jsxs)("li",{className:"relative pl-[1.25rem] list-none before:absolute before:left-[0.5rem] before:top-0 before:bottom-0 before:w-px before:bg-border last:before:h-5",children:[(0,i.jsxs)("div",{className:(0,N.cn)("flex items-center justify-between w-full text-left h-10 pl-2 pr-1 rounded-sm relative","after:absolute after:left-[-0.75rem] after:top-1/2 after:-translate-y-1/2 after:w-3 after:h-px after:bg-border",d?"bg-accent text-accent-foreground":"",m?"opacity-50 cursor-not-allowed":"cursor-pointer hover:bg-muted"),onClick:()=>!m&&r(t.id),role:"button",tabIndex:m?-1:0,onKeyDown:e=>{m||"Enter"!==e.key&&" "!==e.key||r(t.id)},"aria-disabled":m,title:m?c?"Cannot move to the same folder":"Cannot move a folder into itself or its children":void 0,children:[(0,i.jsxs)("div",{className:"flex items-center gap-2 overflow-hidden",children:[(0,i.jsx)(O.s,{className:"h-6 w-6 flex-shrink-0",color:t.color}),(0,i.jsx)("span",{className:"truncate text-sm font-medium",children:t.name})]}),(0,i.jsx)(C.A,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground mr-1"})]}),t.children.length>0&&(0,i.jsx)("ul",{className:"list-none p-0 m-0 pt-1",children:t.children.map(e=>(0,i.jsx)(e3,{node:e,level:a+1,selectedTargetFolder:n,onSelectFolder:r,currentFolderId:l,foldersToMove:s,invalidFolderIds:o},e.id))})]})}function e5(e){let{open:t,onOpenChange:a,itemsToMove:l,itemType:s="media",folderIds:d=[],mediaIds:c=[],currentFolderId:m,onItemsMoved:h}=e,p=(0,r.useTranslations)("Media"),{toast:x}=(0,e4.d)(),{data:g,error:v,isLoading:b}=(0,R.b)(),[y,w]=(0,n.useState)(void 0),[j,C]=(0,n.useState)(!1),[S,k]=(0,n.useState)(null),T=(0,n.useMemo)(()=>{if("media"===s)return[];let e=new Set(d);return l.filter(t=>e.has(t))},[l,d,s]),E=(0,n.useMemo)(()=>{if(!g){let e=new Set;return m&&e.add(m),e}let e=new Set;return m&&e.add(m),0===T.length||T.forEach(t=>{e.add(t);let a=function e(t,a){for(let i of t){if(i.id===a)return i;let t=e(i.children,a);if(t)return t}return null}(g,t);a&&(function(e){let t=new Set;return!function e(a){a.children.forEach(a=>{t.add(a.id),e(a)})}(e),t})(a).forEach(t=>e.add(t))}),e},[g,T,m]);(0,n.useEffect)(()=>{t&&(w(void 0),k(null))},[t]),(0,n.useEffect)(()=>{v&&k(v.message||"Failed to load folder structure.")},[v]);let I=e=>{w(e)},A=async()=>{if(void 0!==y){if(null!==y&&E.has(y))return void k("Cannot move to this folder. Please select a different destination.");C(!0),k(null);try{if("mixed"===s){let e=new Set(d),t=new Set(c),a=l.filter(t=>e.has(t)),i=l.filter(e=>t.has(e));a.length>0&&await (0,R.Kg)({itemIds:a,itemType:"folder",destinationFolderId:null!=y?y:void 0}),i.length>0&&await (0,R.Kg)({itemIds:i,itemType:"media",destinationFolderId:null!=y?y:void 0})}else await (0,R.Kg)({itemIds:l,itemType:"folder"===s?"folder":"media",destinationFolderId:null!=y?y:void 0});x({title:p("moveSuccess"),description:1===l.length?p("moveSuccessDescriptionSingle"):p("moveSuccessDescriptionMultiple",{count:l.length})}),h(),a(!1)}catch(e){console.error("Failed to move items:",e),k(p("moveError")||"Failed to move items. Please try again.")}finally{C(!1)}}};return(0,i.jsx)(D.lG,{open:t,onOpenChange:e=>{e||(w(void 0),k(null)),a(e)},children:(0,i.jsxs)(D.Cf,{className:"sm:max-w-lg",children:[(0,i.jsx)(D.c7,{children:(0,i.jsx)(D.L3,{children:(()=>{let e=l.length;return 1===e?p("moveItemTitleSingular")||"Move 1 item to...":p("moveItemsTitlePlural",{c
1ount:e})||"Move ".concat(e," items to...")})()})}),(0,i.jsx)("div",{className:"py-2 max-h-[50vh] overflow-y-auto",children:b?(0,i.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,i.jsx)(f.A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):g&&0!==g.length?(0,i.jsxs)("ul",{className:"list-none p-0 m-0",children:[(0,i.jsx)("li",{className:"relative list-none",children:(0,i.jsx)("div",{className:(0,N.cn)("flex items-center justify-between w-full text-left h-10 pl-3 pr-1 cursor-pointer rounded-sm relative","hover:bg-muted",null===y?"bg-accent text-accent-foreground":""),onClick:()=>w(null),role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&w(null)},children:(0,i.jsxs)("div",{className:"flex items-center gap-2 overflow-hidden",children:[(0,i.jsx)(u.A,{className:"h-5 w-5 flex-shrink-0"}),(0,i.jsx)("span",{className:"truncate text-sm font-medium",children:p("home")})]})})}),g.map(e=>(0,i.jsx)(e3,{node:e,level:0,selectedTargetFolder:y,onSelectFolder:I,currentFolderId:m,foldersToMove:T,invalidFolderIds:E},e.id))]}):(0,i.jsx)(eH.p,{size:"compact",title:p("noOtherFolders"),description:p("noOtherFoldersDescription")})}),S&&(0,i.jsx)("p",{className:"text-sm text-destructive px-1 text-center -mt-2 mb-2",children:S}),(0,i.jsxs)(D.Es,{children:[(0,i.jsx)(D.HM,{asChild:!0,children:(0,i.jsx)(o.$,{variant:"outline",disabled:j,children:p("cancel")})}),(0,i.jsxs)(o.$,{onClick:A,disabled:j||b||void 0===y,children:[j&&(0,i.jsx)(f.A,{className:"mr-2 h-4 w-4 animate-spin"}),p("moveButton")]})]})]})})}var e6=a(46368),e8=a(3611),e9=a(55594),e7=a(21352),te=a(6278);let tt=te.Ik({name:te.Yj().min(1,"Name cannot be empty").max(100,"Name too long"),color:te.Yj().optional()});function ta(e){let{open:t,onOpenChange:a,item:l,onUpdateComplete:s}=e,d=(0,r.useTranslations)("Media"),{toast:c}=(0,e4.d)(),[u,m]=(0,n.useState)(!1),[h,p]=(0,n.useState)(void 0),x=(0,n.useMemo)(()=>l&&"color"in l,[l]),g=z[0].hex,{register:v,handleSubmit:b,reset:y,setValue:w,formState:{errors:j,isDirty:C}}=(0,e9.mN)({resolver:(0,e7.u)(tt),defaultValues:{name:""}});(0,n.useEffect)(()=>{if(t&&l){var e;let t=x?null!=(e=l.color)?e:g:void 0;y({name:l.name,color:t}),p(t)}else t||(y({name:"",color:void 0}),p(void 0),m(!1))},[l,t,y,x,g]);let S=async e=>{var t;if(!l)return;m(!0);let i=l.name,n=x?null!=(t=l.color)?t:g:void 0,r=e.name!==i,o=x&&e.color!==n;if(!r&&!o){c({title:d("noChangesTitle")||"No Changes Detected",description:d("noChangesDescription")||"The name and color are the same as before."}),m(!1),a(!1);return}try{await (0,R.xV)({itemId:l.id,itemType:x?"folder":"media",newName:r?e.name:void 0,color:x&&o?e.color:void 0}),c({title:d("successTitle")||"Update Successful",description:d("successDescription",{itemName:e.name})||"".concat(x?"Folder":"Item"," updated successfully.")});let t={...l,name:e.name,...x&&e.color?{color:e.color}:{}};s(t),a(!1)}catch(e){console.error("Exception calling update action:",e),c({title:d("errorTitle")||"Update Failed",description:e instanceof Error?e.message:d("errorDescription")||"An unexpected error occurred.",variant:"destructive"})}finally{m(!1)}};if(!l)return null;let k=x?d("titleFolder")||"Edit Folder":d("titleMedia")||"Edit Media Item";return(0,i.jsx)(D.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(D.Cf,{className:"sm:max-w-[425px]",children:[(0,i.jsx)(D.c7,{children:(0,i.jsx)(D.L3,{children:k})}),(0,i.jsxs)("form",{onSubmit:b(S),className:"grid gap-4 py-4",children:[" ",(0,i.jsxs)("div",{className:"grid gap-2",children:[(0,i.jsx)(F.J,{htmlFor:"name",className:"text-left",children:d("nameLabel")||"Name"}),(0,i.jsx)(M.p,{id:"name",...v("name"),className:"w-full",disabled:u}),j.name&&(0,i.jsx)("p",{className:"col-span-4 text-right text-xs text-destructive",children:j.name.message})]}),x&&(0,i.jsxs)("div",{className:"grid grid-1 gap-3",children:[(0,i.jsx)(F.J,{className:"text-left",children:d("colorLabel")||"Color"}),(0,i.jsx)("div",{className:"grid grid-cols-4 gap-3 sm:grid-cols-8",children:z.map(e=>(0,i.jsxs)(o.$,{type:"button",variant:"ghost",size:"icon",className:(0,N.cn)("h-10 w-10 p-1.5 rounded-md",h===e.hex?"ring-2 ring-primary ring-offset-2 ring-offset-background":"hover:bg-accent"),onClick:()=>{var t;p(t=e.hex),w("color",t,{shouldValidate:!0,shouldDirty:!0})},disabled:u,"aria-label":e.name,children:[(0,i.jsx)(O.s,{className:"h-full w-full",color:e.hex}),(0,i.jsx)("span",{className:"sr-only",children:e.name})]},e.name))}),j.color&&(0,i.jsx)("p",{className:"col-span-4 text-right text-xs text-destructive",children:j.color.message})]}),(0,i.jsxs)(D.Es,{children:[(0,i.jsx)(o.$,{type:"button",variant:"outline",onClick:()=>a(!1),disabled:u,children:d("cancelButton")||"Cancel"}),(0,i.jsx)(o.$,{type:"submit",disabled:!C||u,children:u?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}),d("savingButton")]}):d("saveButton")||"Save Changes"})]})]})]})})}var ti=a(36407),tn=a(94745),tr=a(31724),tl=a(53623),ts=a(52076);let to="flex size-11 shrink-0 items-center justify-center rounded-full text-white/70 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70 disabled:pointer-events-none disabled:opacity-20 motion-reduce:transition-none";function td(e){let{open:t,onOpenChange:a,media:s,mediaItems:o=[],onMediaChange:d}=e,c=(0,r.useTranslations)("Media.preview"),u=(0,n.useRef)(null),m=(0,n.useRef)(null),h=o.findIndex(e=>e.id===(null==s?void 0:s.id)),p=h>=0&&o.length>1&&!!d,f=p&&h>0,x=p&&h<o.length-1,g=null==s?void 0:s.type.startsWith("image/"),v=null==s?void 0:s.type.startsWith("video/"),b=e=>{if(-1===e?!f:!x)return;let t=o[h+e];t&&(null==d||d(t))};if(!s)return null;let y=Number(s.sizeInBytes),w=y?y<1024?"".concat(y," B"):y<1048576?"".concat((y/1024).toFixed(1)," KB"):"".concat((y/1048576).toFixed(1)," MB"):c("unknownSize");return(0,i.jsx)(ts.bL,{open:t,onOpenChange:a,children:(0,i.jsxs)(ts.ZL,{children:[(0,i.jsx)(ts.hJ,{className:"fixed inset-0 z-50 bg-black/95 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 duration-200 motion-reduce:animate-none"}),(0,i.jsxs)(ts.UC,{"aria-describedby":void 0,className:"fixed inset-0 z-50 grid h-dvh grid-rows-[auto_minmax(0,1fr)_auto] bg-transparent text-white outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 duration-200 motion-reduce:animate-none",onOpenAutoFocus:e=>{var t;
1e.preventDefault(),null==(t=u.current)||t.focus()},onKeyDown:e=>{e.target.closest("video, input, textarea, [contenteditable=true]")||("ArrowLeft"===e.key||"ArrowRight"===e.key)&&(e.preventDefault(),e.stopPropagation(),b("ArrowLeft"===e.key?-1:1))},children:[(0,i.jsxs)(ts.hE,{className:"sr-only",children:[c("title"),": ",s.name]}),(0,i.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 sm:px-6 sm:py-3",children:[(0,i.jsx)("span",{"aria-live":"polite","aria-atomic":"true",className:"px-2 text-xs tabular-nums text-white/50",children:h>=0?c("counter",{current:h+1,total:o.length}):null}),(0,i.jsxs)("div",{className:"flex items-center gap-1",children:[(0,i.jsx)("a",{href:"/api/media/download/".concat(s.id),download:s.name,className:to,"aria-label":c("download"),title:c("download"),children:(0,i.jsx)(ti.A,{className:"size-[18px]","aria-hidden":"true"})}),(0,i.jsx)(ts.bm,{ref:u,className:to,"aria-label":c("close"),title:c("close"),children:(0,i.jsx)(tn.A,{className:"size-5","aria-hidden":"true"})})]})]}),(0,i.jsxs)("div",{className:"relative flex min-h-0 items-center justify-center px-4 sm:px-16",onClick:e=>{e.target===e.currentTarget&&a(!1)},onTouchStart:e=>{if(!g||1!==e.touches.length){m.current=null;return}m.current={x:e.touches[0].clientX,y:e.touches[0].clientY}},onTouchCancel:()=>{m.current=null},onTouchEnd:e=>{let t=m.current;if(m.current=null,!t||e.touches.length)return;let i=e.changedTouches[0],n=i.clientX-t.x,r=i.clientY-t.y;Math.abs(n)>60&&Math.abs(n)>1.5*Math.abs(r)?b(n<0?1:-1):r>100&&r>1.5*Math.abs(n)&&a(!1)},children:[p&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("button",{type:"button",onClick:()=>b(-1),disabled:!f,"aria-label":c("previous"),className:"".concat(to," absolute left-1 top-1/2 z-10 -translate-y-1/2 bg-black/20 sm:left-4"),children:(0,i.jsx)(tr.A,{className:"size-5","aria-hidden":"true"})}),(0,i.jsx)("button",{type:"button",onClick:()=>b(1),disabled:!x,"aria-label":c("next"),className:"".concat(to," absolute right-1 top-1/2 z-10 -translate-y-1/2 bg-black/20 sm:right-4"),children:(0,i.jsx)(C.A,{className:"size-5","aria-hidden":"true"})})]}),g&&(0,i.jsx)(l.default,{src:s.url,alt:s.name,width:s.width||1200,height:s.height||800,className:"h-auto max-h-full w-auto max-w-full rounded-md object-contain animate-in fade-in-0 duration-200 motion-reduce:animate-none",unoptimized:!0,priority:!0,draggable:!1},s.id),v&&(0,i.jsx)("video",{src:s.url,controls:!0,autoPlay:!0,className:"max-h-full max-w-full rounded-md object-contain",poster:s.thumbnailUrl||void 0,preload:"metadata"},s.id),!g&&!v&&(0,i.jsxs)("div",{className:"px-6 text-center",children:[(0,i.jsx)(tl.A,{className:"mx-auto mb-4 size-10 text-white/40","aria-hidden":"true"}),(0,i.jsx)("p",{className:"text-sm text-white/80",children:c("notAvailable")}),(0,i.jsx)("p",{className:"mt-2 text-xs text-white/40",children:c("downloadToView")})]})]}),(0,i.jsxs)("div",{className:"mx-auto w-full max-w-xl px-6 pb-[max(1.5rem,env(safe-area-inset-bottom))] pt-5 text-center",children:[(0,i.jsx)("p",{className:"truncate text-sm font-medium text-white/80",title:s.name,children:s.name}),(0,i.jsxs)("p",{className:"mt-1 text-xs text-white/40",children:[s.width&&s.height?"".concat(s.width," \xd7 ").concat(s.height," \xb7 "):"",w]})]})]})]})})}function tc(e){let{count:t,embedded:a,children:n}=e,l=(0,r.useTranslations)("Media");return(0,i.jsx)("div",{className:(0,N.cn)("pointer-events-none z-20 mt-4 flex shrink-0 justify-center",a?"absolute inset-x-4 bottom-16":"sticky bottom-[calc(4rem+var(--dashboard-bottom-nav-space,0px))] lg:bottom-16"),children:(0,i.jsxs)("div",{role:"group","aria-label":l("selectionActions",{count:t}),className:"pointer-events-auto flex max-w-full items-center gap-1 overflow-x-auto overscroll-x-contain rounded-2xl border border-border/60 bg-popover/60 p-1.5 text-popover-foreground shadow-lg backdrop-blur-xl animate-in fade-in-0 slide-in-from-bottom-2 duration-150 motion-reduce:animate-none [&>button]:h-9 [&>button]:shrink-0 [&>button]:rounded-xl [&>button]:px-3 [&>button:focus-visible]:ring-2",children:[(0,i.jsx)("span",{"aria-hidden":"true",className:"mx-1 flex size-7 shrink-0 items-center justify-center rounded-lg bg-muted text-xs font-medium tabular-nums text-muted-foreground",children:t}),n]})})}var tu=a(45528),tm=a(16698);let th=(0,eo.createServerReference)("4047360cfad0d5c63f8f8a9edff40779388c66351f",eo.callServer,void 0,eo.findSourceMapURL,"cancelConversionJobAction");var tp=a(41013),tf=a(70508),tx=a(20836),tg=a(49493);let tv=n.memo(function(e){let{folderId:t,onClick:a,children:r}=e,l=(0,n.useCallback)(()=>{a(t)},[t,a]);return(0,i.jsx)("button",{type:"button",onClick:l,className:"text-sm font-medium text-foreground hover:text-muted-foreground cursor-pointer bg-transparent border-none p-0",children:r})});function tb(e){let{itemData:t}=e,a="folder"===t.type,n=a?t.data:null,r=a?null:t.data;return(0,i.jsxs)("div",{className:"bg-card rounded-lg shadow-md border p-3 flex items-center gap-2 cursor-grabbing",children:[a&&n?(0,i.jsx)("div",{className:"flex-shrink-0 h-10 w-10 flex items-center justify-center",children:(0,i.jsx)(O.s,{className:"h-7 w-7",color:n.color})}):r?(0,i.jsx)("div",{className:"flex-shrink-0 h-10 w-10 rounded overflow-hidden bg-muted relative",children:r.type.startsWith("image/")?(0,i.jsx)(l.default,{src:r.thumbnailUrl||r.url,alt:r.name,className:"object-cover",fill:!0,loading:"eager",priority:!0,sizes:"40px",placeholder:"blur",blurDataURL:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Crect width='100%25' height='100%25' fill='%23f1f5f9'/%3E%3C/svg%3E"}):r.type.startsWith("video/")?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("video",{src:r.url,className:"h-full w-full object-cover",preload:"auto",muted:!0,playsInl
1ine:!0,poster:r.thumbnailUrl||void 0}),(0,i.jsx)("div",{className:"absolute bottom-0.5 right-0.5 bg-black/70 rounded p-0.5",children:(0,i.jsx)(d.A,{className:"h-2 w-2 text-white fill-white"})})]}):(0,i.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,i.jsx)(c.A,{className:"h-4 w-4 text-muted-foreground"})})}):null,(0,i.jsx)("span",{className:"text-sm font-medium truncate",children:t.data.name})]})}function ty(e){let{activeItemData:t,selectedItems:a,activeId:n,folderItems:r,mediaItems:l}=e,s=Array.from(a).filter(e=>e!==n).map(e=>{let t=r.find(t=>t.id===e);if(t)return{type:"folder",data:t,id:t.id};let a=l.find(t=>t.id===e);return a?{type:"media",data:a,id:a.id}:null}).filter(e=>null!==e).slice(0,3);return(0,i.jsxs)("div",{className:"relative !cursor-grabbing",style:{width:"160px",height:"160px",cursor:"grabbing"},children:[(0,i.jsx)("div",{className:"relative w-full h-full",style:{zIndex:10,opacity:.8},children:"folder"===t.type?(0,i.jsx)(eF,{folder:t.data,isSelected:!1,onSelect:()=>{},enableFolderSelection:!1,itemSize:"sm",hideName:!0,isInDragOverlay:!0}):(0,i.jsx)(eq,{item:t.data,isSelected:!1,onSelect:()=>{},hideCheckbox:!0,itemSize:"sm",hideName:!0,priority:!0,isInDragOverlay:!0})}),s.length>0&&(0,i.jsx)(i.Fragment,{children:s.map((e,t)=>(0,i.jsx)("div",{className:"absolute w-16 h-16 rounded-md border bg-card shadow-md p-1 pointer-events-none",style:{top:"0px",right:"".concat(8*t,"px"),opacity:.8,zIndex:11+t},children:"folder"===e.type?(0,i.jsx)(eF,{folder:e.data,isSelected:!1,onSelect:()=>{},itemSize:"sm",enableFolderSelection:!1,hideName:!0,isInDragOverlay:!0}):(0,i.jsx)(eq,{item:e.data,isSelected:!1,onSelect:()=>{},minimal:!0,itemSize:"sm",hideCheckbox:!0,hideName:!0,priority:!0,isInDragOverlay:!0})},e.id))}),a.size>1&&(0,i.jsx)("div",{className:"absolute bg-primary text-primary-foreground rounded-full text-xs font-semibold shadow-lg border-2 border-primary-foreground flex items-center justify-center pointer-events-none",style:{top:"-8px",right:"-8px",width:"28px",height:"28px",zIndex:50},children:a.size})]})}function tw(e){var t,a;let{initialContents:l,initialHierarchy:d,initialFolderPath:C,onMediaSelectConfirm:M,selectionMode:D="multiple",enableFolderSelection:F=!1,initialSelectedItems:O=[],maxSelectionCount:z,onSelectionChange:G,hideHeader:W=!1,hideCreateFolder:V=!1,hideUpload:q=!1,preferInitialContents:$=!1,fitParentHeight:Y=!1,itemSize:X="default",hideCreatePostButton:Z=!1,onConfirmMultiSelect:J,multiSelectConfirmText:ee,onNavigateRequest:et,internalFolderId:ea,onFolderCreated:ei,onUploadComplete:en,onMoveComplete:er,onRefreshContentsAndHierarchy:el,onRefreshByOperation:es,mutate:eo,isLoading:ed,skeletonComponent:ec}=e,eu=(0,n.useRef)(0),em=(0,n.useRef)(void 0),eh=(0,r.useTranslations)("Media"),{canUploadMedia:ep,planTier:ef,trialEligible:ex,subscriptionOwnership:ev,isLoading:ew,refreshInBackground:eC}=(0,_.Q)(),{socialConnections:eN,isLoading:eS}=(0,tp.W)(),{socialGroups:ek}=(0,tf.n)(),eT=eN.length>
10,[eE,eI]=(0,n.useState)(!1),[eA]=(0,n.useState)(!1);(0,n.useEffect)(()=>{eu.current+=1,em.current!==ea&&(em.current=ea)},[ea]);let[eP,eM]=(0,n.useTransition)(),[eD,eR]=(0,n.useState)(!1),[eO,ez]=(0,n.useState)("grid"),[eL,eU]=(0,n.useState)(new Set(O)),[e_,eB]=(0,n.useState)(!1),[eK,eG]=(0,n.useState)(!1),[eW,eV]=(0,n.useState)(!1),[eH,eY]=(0,n.useState)(!1),[eX,eZ]=(0,n.useState)(!1),[eJ,eQ]=(0,n.useState)(!1),[e0,e4]=(0,n.useState)(!1),[e3,e9]=(0,n.useState)(void 0),[e7,te]=(0,n.useState)(null),[tt,ti]=(0,n.useState)(null),[tn,tr]=(0,n.useState)(!1),[tl,ts]=(0,n.useState)(()=>O.length>0?l.media.filter(e=>O.includes(e.id)):[]),[to,tw]=(0,n.useState)(!1),[tj,tC]=(0,n.useState)(null),[tN,tS]=(0,n.useState)(!1),[tk,tT]=(0,n.useState)(null),[tE,tI]=(0,n.useState)(null),[tA,tP]=(0,n.useState)(null),[tM,tD]=(0,n.useState)(!1),[tR,tF]=(0,n.useState)(null),[tO,tz]=(0,n.useState)(null),[tL,tU]=(0,n.useState)(!1),[t_,tB]=(0,n.useState)(null),[tK,tG]=(0,n.useState)(null),[tW,tV]=(0,n.useState)(null),tq=(0,n.useRef)(0),tH=(0,n.useRef)(null),t$=(0,n.useCallback)(()=>{tq.current=Date.now(),window.dispatchEvent(new CustomEvent("dopost-menu-interaction"))},[]),tY=(0,n.useCallback)(()=>{tH.current={items:new Set(eL),media:[...tl]}},[eL,tl]),tX=(0,s.useRouter)(),tZ=(0,s.useSearchParams)(),{data:tJ,mutate:tQ}=(0,R.cs)(ea),t0=eo||tQ,{workspace:t1}=(0,Q.k)(),{registerConversionJob:t2}=(0,tu.o)(),[t4,t3]=(0,n.useState)(()=>new Set),t5=(0,n.useCallback)(async e=>{t3(t=>new Set(t).add(e)),await t0(t=>{var a,i;if(!(null==t||null==(a=t.data)?void 0:a.media))return t;let n=t.data.media.find(t=>t.id===e);if(!n||(null==(i=n.storageKey)?void 0:i.startsWith("pending-conversion/")))return t;let r=t.data.media.map(t=>t.id===e?{...t,status:"READY"}:t);return{...t,data:{...t.data,media:r}}},{revalidate:!1});try{let t=await th(e);if(t.error){H.oR.error(t.error),await t0();return}(null==t1?void 0:t1.id)&&await (0,tm.A)(t1.id),await t0()}finally{t3(t=>{let a=new Set(t);return a.delete(e),a})}},[t0,null==t1?void 0:t1.id]),t6=(0,n.useCallback)(e=>t4.has(e),[t4]),t8=(0,n.useMemo)(()=>$?(null==l?void 0:l.media)||[]:(null==tJ?void 0:tJ.media)||(null==l?void 0:l.media)||[],[tJ,l,$]),t9=(0,n.useMemo)(()=>$?(null==l?void 0:l.folders)||[]:(null==tJ?void 0:tJ.folders)||(null==l?void 0:l.folders)||[],[tJ,l,$]),t7=(0,n.useRef)(t8);(0,n.useEffect)(()=>{t7.current=t8},[t8]),(0,n.useEffect)(()=>{if("success"===tZ.get("canva_auth")){let e=tZ.get("canva_media_id"),t=new URLSearchParams(tZ.toString());t.delete("canva_auth"),t.delete("canva_media_id");let a="".concat(window.location.pathname).concat(t.toString()?"?".concat(t.toString()):"");tX.replace(a),e?tz(e):eV(!0)}},[tZ,tX]),(0,n.useEffect)(()=>{if(tO){let e=t8.find(e=>e.id===tO);e&&(tI(e),eY(!0),tz(null))}},[tO,t8]),(0,n.useEffect)(()=>{if("replace"===tZ.get("canva_return")){let e=tZ.get("mediaId"),t=tZ.get("designId"),a=tZ.get("token");if(e&&t&&a){tB(e),tG(t),tV(a),tU(!0);let i=new URLSearchParams(tZ.toString());i.delete("canva_return"),i.delete("mediaId"),i.delete("designId"),i.delete("token");let n="".concat(window.location.pathname).concat(i.toString()?"?".concat(i.toString()):"");tX.replace(n)}}},[tZ,tX]);let ae=(0,n.useMemo)(()=>{if(!ea||!d)return C||[];let e=function(t,a){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];for(let n of t){let t=[...i,n];if(n.id===a)return t;if(n.children.length>0){let i=e(n.children,a,t);if(i)return i}}return null},t=e(d,ea);return t?t.map(e=>({id:e.id,name:e.name,color:e.color,parentId:e.parentId,workspaceId:"",createdAt:new Date,updatedAt:new Date})):C||[]},[ea,d,C]);(0,n.useEffect)(()=>{ae&&ae.length>0?e9(ae[ae.length-1]):e9(void 0)},[ae]);let[at,aa]=(0,n.useState)(null),[ai,an]=(0,n.useState)(!1),ar=(0,n.useRef)(null);(0,n.useEffect)(()=>{G&&G(tl)},[tl,G]);let al=(0,n.useCallback)(async(e,t)=>{es?await es(e,t):el?await el():t0()},[es,el,t0]);(0,n.useEffect)(()=>{if("success"===tZ.get("canva_replace")||"success"===tZ.get("canva_import")){al("upload");let e=new URLSearchParams(tZ.toString());e.delete("canva_replace"),e.delete("canva_import");let t="".concat(window.location.pathname).concat(e.toString()?"?".concat(e.toString()):"");tX.replace(t)}},[tZ,tX,al]),(0,n.useEffect)(()=>{eU(new Set)},[ea]);let as=(0,n.useCallback)(function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=Date.now()-tq.current;if((a||!(i<300))&&("folder"!==t||F||!M)){if(M&&"media"===t&&"single"===D){let t=t7.current.find(t=>
1t.id===e);t&&M(t);return}eU(t=>{let i=new Set(t);if(t.has(e),"single"===D&&i.clear(),a)i.has(e)||(i.clear(),i.add(e));else{if(z&&"multiple"===D&&!i.has(e)&&i.size>=z)return H.oR.error("You can only select up to ".concat(z," items.")),t;i.has(e)?i.delete(e):i.add(e)}i.has(e);let n=Array.from(i).map(e=>t7.current.find(t=>t.id===e)).filter(Boolean);return ts(n),G&&G(n),i})}},[F,M,D,z,G]),ao=(0,n.useCallback)(()=>{!(Date.now()-tq.current<300)&&(eU(new Set),ts([]),G&&G([]))},[G]),ad=(0,n.useCallback)(e=>{Date.now()-tq.current<300||0!==e.length&&eU(t=>{let a=new Set(t),i=a.size,n=e.filter(e=>!a.has(e)),r=e.filter(e=>a.has(e));if(z&&"multiple"===D)if(i-r.length+n.length>z&&n.length>0){let e=z-(i-r.length);e>0&&n.slice(0,e).forEach(e=>a.add(e)),r.forEach(e=>a.delete(e))}else e.forEach(e=>{a.has(e)?a.delete(e):a.add(e)});else e.forEach(e=>{a.has(e)?a.delete(e):a.add(e)});let l=Array.from(a).map(e=>t7.current.find(t=>t.id===e)).filter(Boolean);return ts(l),G&&G(l),a})},[D,z,G]),ac=(0,n.useRef)(!1),au=(0,n.useRef)(null),am=(0,n.useCallback)(e=>{ac.current||(ac.current=!0,au.current&&clearTimeout(au.current),et&&et(e),au.current=setTimeout(()=>{ac.current=!1},300))},[et]);(0,n.useEffect)(()=>()=>{au.current&&clearTimeout(au.current)},[]);let ah=(0,n.useCallback)((e,t)=>{"folder"===t?e!==ea&&(eU(new Set),et&&et(e)):(eU(t=>{let a=new Set(t);if("single"===D&&a.clear(),!t.has(e)&&z&&"multiple"===D&&a.size>=z)return H.oR.error("You can only select up to ".concat(z," items.")),t;t.has(e)?a.delete(e):a.add(e);let i=Array.from(a).map(e=>t8.find(t=>t.id===e)).filter(Boolean);return ts(i),G&&G(i),a}),te(e))},[et,D,ea,t8,z,G]),ap=async()=>{if(0!==eL.size){eR(!0);try{var e,t,a;let i=t8.filter(e=>eL.has(e.id)),n=t9.filter(e=>eL.has(e.id)),r=[...i.map(e=>({itemId:e.id,itemType:"media"})),...n.map(e=>({itemId:e.id,itemType:"folder",deleteContents:!0}))],l=await (0,R.mx)({items:r});(null==(e=l.data)?void 0:e.failureCount)>0?H.oR.error(eh("bulkDeleteErrorTitle")):H.oR.success(eh("bulkDeleteSuccessTitle",{count:(null==(a=l.data)?void 0:a.successCount)||0})),(null==(t=l.data)?void 0:t.successCount)>0&&eC(),eU(new Set),await t0()}catch(e){H.oR.error("Delete Failed")}finally{eR(!1),eZ(!1)}}},af=()=>{eL.size>0&&e4(!0)},ax=()=>{eL.size>0&&eZ(!0)},ag=()=>{V||eB(!0)},av=()=>{q||(ep?eG(!0):eQ(!0))},ab=()=>{q||eV(!0)},ay=(0,n.useCallback)(async e=>{es?await es("upload"):el?await el():await t0(),en&&en(e)},[en,es,el,t0]),aw=(0,n.useCallback)(()=>{er&&er()},[er]),aj=(0,n.useMemo)(()=>({activationConstraint:{distance:5}}),[]),aC=(0,j.MS)(j.AN,aj),aN=(0,j.MS)(j.uN),aS=(0,j.FR)(aC,aN),ak=async e=>{let{active:t,over:a}=e;if(te(null),!a||!e7||!t||t.id!==e7||t.id===a.id)return;let i=a.data.current,n=(null==i?void 0:i.type)==="folder",r=n?a.id:void 0;if(!n||r===ea)return;let l=eL.has(e7)?Array.from(eL):[e7],s=new Set(t9.map(e=>e.id)),o=l.some(e=>s.has(e)),d=l.some(e=>!s.has(e));if(o&&d){let e=l.filter(e=>s.has(e)),t=l.filter(e=>!s.has(e));eM(async()=>{try{e.length>0&&await (0,R.Kg)({itemIds:e,itemType:"folder",destinationFolderId:r||void 0}),t.length>0&&await (0,R.Kg)({itemIds:t,itemType:"media",destinationFolderId:r||void 0}),H.oR.success(eh("moveItemsSuccessTitle",{count:l.length})),await new Promise(e=>setTimeout(e,100)),await al("move-items"),eU(new Set)}catch(t){let e=t instanceof Error?t.message:"Failed to move items";H.oR.error("".concat(eh("errors.moveItemsTitle"),": ").concat(e))}})}else{let e=o?"folder":"media";eM(async()=>{try{await (0,R.Kg)({itemIds:l,itemType:e,destinationFolderId:r||void 0}),H.oR.success(eh("moveItemsSuccessTitle",{count:l.length})),await new Promise(e=>setTimeout(e,100)),await al("move-items"),eU(new Set)}catch(t){let e=t instanceof Error?t.message:"Failed to move items";H.oR.error("".concat(eh("errors.moveItemsTitle"),": ").concat(e))}})}},aT=eL.size>0,aE=(0,n.useMemo)(()=>{let e=new Set(t9.map(e=>e.id));for(let t of eL)if(e.has(t))return!1;return!0},[eL,t9]),aI=(0,n.useCallback)(()=>{if(0===eL.size)return"media";let e=new Set(t9.map(e=>e.id)),t=new Set(t8.map(e=>e.id)),a=!1,i=!1;for(let n of eL)e.has(n)&&(a=!0),t.has(n)&&(i=!0);return a&&i?"mixed":a?"folder":"media"},[eL,t9,t8]),aA=(0,n.useMemo)(()=>
1{if(!e7)return null;let e=t9.find(e=>e.id===e7);if(e)return{type:"folder",data:e};let t=t8.find(e=>e.id===e7);return t?{type:"media",data:t}:null},[e7,t9,t8]);(0,n.useEffect)(()=>{if(eE&&!eS){var e,t,a;eI(!1);let i=eL.size>0?eL:(null==(e=tH.current)?void 0:e.items)||new Set,n=tl.length>0?tl:(null==(t=tH.current)?void 0:t.media)||[];tH.current=null,eT?(i.size>0&&0===eL.size&&(eU(i),ts(n)),tr(!0)):null==(a=ar.current)||a.openDialog()}},[eE,eS,eT,eL,tl]);let aP=()=>{var e,t,a;let i=eL.size>0?eL:(null==(e=tH.current)?void 0:e.items)||new Set,n=tl.length>0?tl:(null==(t=tH.current)?void 0:t.media)||[];if(eS){tH.current={items:i,media:n},eI(!0);return}if(tH.current=null,!eT){null==(a=ar.current)||a.openDialog();return}i.size>0&&0===eL.size&&(eU(i),ts(n)),tr(!0)},aM=(0,n.useCallback)(e=>{tr(e)},[]),aD=()=>{if(1!==eL.size)return;let e=Array.from(eL)[0],t=t9.find(t=>t.id===e);if(t){tC(t),tw(!0);return}let a=t8.find(t=>t.id===e);if(a){tC(a),tw(!0);return}},aR=()=>{if(1!==eL.size)return;let e=Array.from(eL)[0],t=t8.find(t=>t.id===e);t&&(tI(t),eY(!0))},aF=()=>{if(1!==eL.size)return;let e=Array.from(eL)[0],t=t8.find(t=>t.id===e);t&&(tP(t),tD(!0))},aO=()=>{if(1===eL.size){let e=Array.from(eL)[0],t=t8.find(t=>t.id===e);t&&(tT(t),tS(!0))}},az=(0,n.useCallback)(e=>{tF(e)},[]),aL=(0,n.useCallback)(()=>{tF(null)},[]),aU="function"==typeof M||"function"==typeof J,a_=ee||eh("addMedia"),aB=(0,n.useMemo)(()=>{if(1===eL.size&&aE){let e=Array.from(eL)[0];return t8.find(t=>t.id===e)}return null},[eL,aE,t8]),aK=null!=(a=null==aB||null==(t=aB.type)?void 0:t.startsWith("video/"))&&a,aG="list"===eO&&at?at:j.TT,[aW,aV]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{aW&&!ew&&(aV(!1),ep?eG(!0):eQ(!0))},[aW,ew,ep]),(0,n.useEffect)(()=>{an(!0)},[]),(0,n.useEffect)(()=>{let e=e=>{if(tN)return;let t=document.activeElement;if((null==t?void 0:t.tagName)!=="INPUT"&&(null==t?void 0:t.tagName)!=="TEXTAREA"&&(null==t?void 0:t.getAttribute("contenteditable"))!=="true"&&(null==t?void 0:t.closest('[role="menu"]'))===null&&(null==t?void 0:t.closest('[role="combobox"]'))===null&&(null==t?void 0:t.closest("[data-radix-menu-content]"))===null&&(null==t?void 0:t.closest("[data-radix-dropdown-menu-content]"))===null&&(null==t?void 0:t.getAttribute("aria-haspopup"))!=="menu"){if(("p"===e.key||"P"===e.key)&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&aE&&!aU&&!Z&&eL.size>0){e.preventDefault(),e.stopPropagation(),aP();return}if("Space"===e.code||" "===e.key){let t=null;if(1===eL.size&&aE){let e=Array.from(eL)[0];t=t8.find(t=>t.id===e)||null}else 0===eL.size&&tR&&(t=t8.find(e=>e.id===tR)||null);t&&(e.preventDefault(),e.stopPropagation(),setTimeout(()=>{tT(t),tS(!0)},0));return}if(("r"===e.key||"R"===e.key)&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===eL.size&&!aU){e.preventDefault(),e.stopPropagation(),aD();return}if(("m"===e.key||"M"===e.key)&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&eL.size>0&&!aU){e.preventDefault(),e.stopPropagation(),af();return}if(("Delete"===e.key||"Del"===e.key)&&eL.size>0&&(!aU||"multiple"===D)){e.preventDefault(),e.stopPropagation(),ax();return}}};return window.addEventListener("keydown",e,!0),()=>{window.removeEventListener("keydown",e,!0)}},[eL,aE,t8,tR,tN,aU,Z,D,aP,aD,af,ax]),(0,i.jsxs)("div",{className:"relative flex min-h-0 min-w-0 flex-col h-full w-full max-lg:isolate max-lg:overflow-hidden",children:[!W&&(0,i.jsx)(I.X,{title:eh("title")}),(0,i.jsxs)(j.Mp,{sensors:aS,collisionDetection:aG,onDragStart:e=>{var t;let a=e.active.id;te(a),ti((null==(t=e.active.data.current)?void 0:t.viewMode)||null),eL.has(a)||eU(e=>{let t=new Set(e);return t.add(a),G&&G(t8.filter(e=>t.has(e.id))),t})},onDragEnd:ak,children:[(0,i.jsxs)(A.R,{noHeaderMode:W,contentClassName:(0,N.cn)("min-w-0",!Y&&"flex-none min-h-full"),className:(0,N.cn)("flex min-w-0 flex-col flex-1 md:no-header-mode mt-0 max-lg:overscroll-y-none",Y&&"min-h-0 max-h-none"),children:[(0,i.jsxs)("div",{className:"sticky top-0 z-10 min-w-0 max-w-full overflow-x-auto overscroll-x-contain md:overflow-x-visible bg-white dark:bg-[#1a1a1b] -mt-6 pt-4 pb-4 md:pt-6 flex flex-row items-center justify-between gap-2 md:gap-4",children:[(0,i.jsx)("div",{className:"w-40 shrink-0 md:hidden",children:(0,i.jsx)(P.D,{value:null!=ea?ea:null,onChange:e=>am("home"===e||null===e?void 0:e||void 0),folderHierarchy:d||[]},"folder-select-".concat(ea||"home","-").concat((null==d?void 0:d.length)||0))}),(0,i.jsx)(S,{className:"hidden md:flex overflow-hidden flex-shrink min-w-0 items-center",children:(0,i.jsxs)(k,{className:"flex-nowrap",children:[(0,i.jsx)(T,{children:(0,i.jsx)(tv,{onClick:am,children:(0,i.jsx)(u.A,{className:"h-4 w-4 mr-1.5"})})}),ae.map(e=>(0,i.jsxs)(n.Fragment,{children:[(0,i.jsx)(E,{}),(0,i.jsx)(T,{children:(0,i.jsx)(tv,{folderId:e.id,onClick:am,children:e.name})})]},e.id))]})}),(0,i.jsxs)("div",{className:"flex shrink-0 items-center gap-2 justify-end flex-nowrap [&>button]:shrink-0",children:[!V&&(0,i.jsxs)(o.$,{variant:"outline",onClick:()=>eB(!0),children:[(0,i.jsx)(m.A,{className:"h-3.5 w-3.5"}),(0,i.jsx)("span",{className:"sr-only sm:not-sr-only sm:whitespace-nowrap",children:eh("createFolder")})]}),!q&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(o.$,{variant:"outline",onClick:()=>
1{if(ew)return void aV(!0);ep?eG(!0):eQ(!0)},disabled:aW,children:[(0,i.jsx)(c.A,{className:"h-3.5 w-3.5"}),(0,i.jsx)("span",{className:"sr-only sm:not-sr-only sm:whitespace-nowrap",children:eh("upload")})]}),(0,i.jsx)(K,{onClick:()=>eV(!0),onUpgradeClick:()=>eQ(!0)})]}),(0,i.jsx)(o.$,{variant:"outline",size:"icon",onClick:()=>ez("grid"===eO?"list":"grid"),title:"grid"===eO?eh("viewModeList"):eh("viewModeGrid"),children:"grid"===eO?(0,i.jsx)(h.A,{className:"h-4 w-4"}):(0,i.jsx)(p.A,{className:"h-4 w-4"})})]})]}),(0,i.jsx)("div",{className:(0,N.cn)("flex-1 min-h-0",Y&&aT&&"pb-32",Y?"overflow-x-hidden overflow-y-auto overscroll-y-none ai-chat-scrollbar":"list"===eO&&"overflow-hidden"),children:eA||ed?ec||(0,i.jsx)("div",{className:"flex items-center justify-center h-full min-h-[400px]",children:(0,i.jsx)(f.A,{className:"h-8 w-8 animate-spin text-primary"})}):"grid"===eO?(0,i.jsx)("div",{className:(0,N.cn)("h-full",Y?"px-0.5 pt-1 pb-0.5":"pt-1 -mr-4 pr-4"),children:(0,i.jsx)(e$,{folders:t9,media:t8,selectedItems:eL,onSelect:as,onItemClick:ah,activeId:e7,itemSize:X,enableFolderSelection:F,onMediaHover:az,onMediaHoverEnd:aL,onContextMenuCreatePost:aP,onContextMenuPreview:aO,onContextMenuEdit:aD,onContextMenuEditWithCanva:aR,onContextMenuConvert:aF,onContextMenuMove:af,onContextMenuDelete:ax,onContextMenuCreateFolder:ag,onContextMenuUpload:av,onContextMenuCanvaImport:ab,onMenuInteraction:t$,onPreserveSelection:tY,onCancelConversion:t5,isCancellingConversion:t6,onlyMediaSelected:aE,isSelectedMediaVideo:aK,hideCreatePostButton:Z,isSelectionContext:aU,onClearSelection:ao,onBatchToggleSelection:ad})}):(0,i.jsx)("div",{className:"h-full pt-1",children:(0,i.jsx)(e1,{folders:t9,media:t8,selectedItems:eL,onSelect:as,onItemClick:ah,onMediaHover:az,onMediaHoverEnd:aL,activeId:e7,setListCollisionDetection:aa,onContextMenuCreatePost:aP,onContextMenuPreview:aO,onContextMenuEdit:aD,onContextMenuEditWithCanva:aR,onContextMenuConvert:aF,onContextMenuMove:af,onContextMenuDelete:ax,onContextMenuCreateFolder:ag,onContextMenuUpload:av,onContextMenuCanvaImport:ab,onMenuInteraction:t$,onPreserveSelection:tY,onlyMediaSelected:aE,isSelectedMediaVideo:aK,hideCreatePostButton:Z,isSelectionContext:aU})})}),aT&&(0,i.jsxs)(tc,{count:eL.size,embedded:Y,children:[aE&&!aU&&!Z&&(0,i.jsxs)(o.$,{variant:"ghost",title:eh("createPostButtonTitle"),onClick:aP,children:[(0,i.jsx)(x.A,{className:"h-3.5 w-3.5"}),(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("createPostButton")})]}),1===eL.size&&aE&&!aU&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:aO,title:eh("previewButtonTitle"),children:[(0,i.jsx)(g.A,{className:"h-4 w-4"})," ",(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("previewButton")})]}),1===eL.size&&aE&&!aU&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:aF,title:eh("convertButtonTitle"),children:[(0,i.jsx)(v.A,{className:"h-4 w-4"})," ",(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("convertButton")})]}),1===eL.size&&!aU&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:aD,title:eh("editButtonTitle"),children:[(0,i.jsx)(b.A,{className:"h-4 w-4"})," ",(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("editButton")})]}),1===eL.size&&aE&&!aU&&!aK&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:aR,title:eh("canva.editWithCanva"),children:[(0,i.jsxs)("svg",{className:"h-5 w-8",viewBox:"75 342.6 434 139.1",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",children:[(0,i.jsx)("defs",{children:(0,i.jsxs)("linearGradient",{id:"canva-gradient-edit-btn",gradientUnits:"userSpaceOnUse",x1:"75.6711",y1:"412.9916",x2:"493.0198",y2:"407.3517",children:[(0,i.jsx)("stop",{offset:"0",stopColor:"#04BDCD"}),(0,i.jsx)("stop",{offset:"6.735983e-002",stopColor:"#10A9D3"}),(0,i.jsx)("stop",{offset:"0.172",stopColor:"#2883DE"}),(0,i.jsx)("stop",{offset:"0.5026",stopColor:"#2D7BE1"}),(0,i.jsx)("stop",{offset:"1",stopColor:"#7D2AE7"})]})}),(0,i.jsx)("path",{fill:"url(#canva-gradient-edit-btn)",d:"M505.8,437.8c-0.7,0-1.4,0.5-1.7,1.4c-4.4,12.7-10.5,20.2-15.4,20.2c-2.8,0-4-3.2-4-8.2 c0-12.4,7.4-38.7,11.2-50.8c0.4-1.4,0.7-2.7,0.7-3.8c0-3.5-1.9-5.2-6.7-5.2c-5.1,0-10.6,2-15.9,11.3c-1.8-8.2-7.4-11.9-15.2-11.9 c-9,0-17.7,5.8-24.9,15.2c-7.2,9.4-15.5,12.5-21.9,10.9c4.6-11.1,6.2-19.4,6.2-25.7c0-9.7-4.8-15.5-12.5-15.5 c-11.8,0-18.6,11.2-18.6,23.1c0,9.1,4.1,18.5,13.2,23.1c-7.7,17.3-18.8,32.9-23,32.9c-5.5,0-7.1-26.7-6.8-45.8 c0.2-11,1.1-11.6,1.1-14.9c0-1.9-1.2-3.2-6.2-3.2c-11.6,0-15.2,9.8-15.7,21c-0.1,4.3-0.9,8.5-2,12.7C343,441.9,333,455,326.5,455 c-3,0-3.8-3-3.8-6.9c0-12.4,6.9-28,6.9-41.2c0-9.8-4.3-15.9-12.3-15.9c-9.5,0-22,11.3-33.9,32.4c3.9-16.2,5.5-31.8-6.1-31.8 c-2.5,0.1-5,0.7-7.2,1.9c-1.5,0.7-2.5,2.2-2.3,4c1.1,17.2-13.9,61.3-28,61.3c-2.6,0-3.8-2.8-3.8-7.3c0-12.4,7.4-38.7,11.1-50.7 c0.5-1.
16,0.7-2.9,0.7-4c0-3.3-2-5-6.7-5c-5.1,0-10.6,2-15.9,11.3c-1.9-8.2-7.4-11.9-15.3-11.9c-12.8,0-27,13.5-33.3,31.1 c-8.4,23.5-25.3,46.2-48.1,46.2c-20.7,0-31.6-17.2-31.6-44.4c0-39.3,28.8-71.3,50.2-71.3c10.2,0,15.1,6.5,15.1,16.5 c0,12.1-6.7,17.7-6.7,22.3c0,1.4,1.2,2.8,3.5,2.8c9.3,0,20.2-10.9,20.2-25.8c0-14.9-12.1-25.7-33.5-25.7c-35.3,0-70.8,35.5-70.8,81 c0,36.2,17.9,58.1,48.8,58.1c21.1,0,39.5-16.4,49.4-35.5c1.2,15.8,8.3,24.1,19.3,24.1c9.8,0,17.6-5.8,23.7-16 c2.3,10.7,8.5,15.9,16.5,15.9c9.2,0,16.8-5.8,24.1-16.6c-0.1,8.5,1.8,16.5,9.2,16.5c3.5,0,7.6-0.8,8.3-3.8 c7.7-32,26.9-58.1,32.7-58.1c1.7,0,2.2,1.7,2.2,3.6c0,8.7-6.1,26.5-6.1,37.9c0,12.3,5.2,20.5,16,20.5c12,0,24.1-14.7,32.2-36.1 c2.5,20,8,36.1,16.6,36.1c10.6,0,29.3-22.2,40.6-45.7c4.4,0.6,11.1,0.4,17.6-4.1c-2.7,6.9-4.3,14.5-4.3,22 c0,21.8,10.4,27.9,19.4,27.9c9.8,0,17.6-5.8,23.7-16c2,9.3,7.1,15.9,16.5,15.9c14.7,0,27.4-15,27.4-27.3 C508.8,439.7,507.4,437.8,505.8,437.8z M201.5,458.3c-5.9,0-8.2-6-8.2-14.8c0-15.5,10.6-41.2,21.8-41.2c4.8,0,6.7,5.7,6.7,12.8 C221.8,430.7,211.7,458.3,201.5,458.3z M404.3,412.3c-3.5-4.2-4.8-9.9-4.8-15c0-6.3,2.3-11.6,5.1-11.6s3.6,2.7,3.6,6.5 C408.1,398.4,405.9,407.6,404.3,412.3z M450.2,458.3c-5.9,0-8.2-6.9-8.2-14.8c0-14.9,10.6-41.2,21.8-41.2c4.9,0,6.6,5.7,6.6,12.8 C470.4,430.7,460.5,458.3,450.2,458.3z"})]}),(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("canva.edit")})]}),!aU&&aT&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:af,title:eh("moveSelected"),disabled:eP,children:[eP?(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(y.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("moveButton")})]}),(!aU||"multiple"===D)&&(0,i.jsxs)(o.$,{variant:"ghost",className:"text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>eZ(!0),disabled:eD,children:[eD?(0,i.jsx)(f.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(w.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"whitespace-nowrap",children:eh("delete")})]}),aU&&"multiple"===D&&J&&(0,i.jsxs)(o.$,{variant:"ghost",onClick:J,disabled:0===eL.size,children:[a_," ",eL.size>0?"(".concat(eL.size,")"):""]})]})]}),(0,i.jsx)(j.Hd,{dropAnimation:null,modifiers:"grid"===tt&&e7&&eL.has(e7)&&eL.size>1?[]:[e6.jw],children:e7&&aA?(()=>{let e=eL.has(e7)&&eL.size>1;if("grid"===(tt||"grid"))if(e)return(0,i.jsx)(ty,{activeItemData:aA,selectedItems:eL,activeId:e7,folderItems:t9,mediaItems:t8});else return(0,i.jsx)("div",{className:"relative !cursor-grabbing",style:{cursor:"grabbing",width:"160px",height:"160px"},children:(0,i.jsx)("div",{className:"relative w-full h-full pointer-events-none",style:{zIndex:10},children:"folder"===aA.type?(0,i.jsx)(eF,{folder:aA.data,isSelected:!1,onSelect:()=>{},itemSize:"sm",hideName:!0,isInDragOverlay:!0}):(0,i.jsx)(eq,{item:aA.data,isSelected:!1,onSelect:()=>{},itemSize:"sm",hideCheckbox:!0,hideName:!0,priority:!0,isInDragOverlay:!0})})});let t=(0,i.jsx)(tb,{itemData:aA});if(!e)return(0,i.jsx)("div",{className:"w-40",children:t});{let e=Array.from(eL).filter(e=>e!==e7).map(e=>{let t=t9.find(t=>t.id===e);if(t)return{type:"folder",data:t};let a=t8.find(t=>t.id===e);return a?{type:"media",data:a}:null}).filter(e=>null!==e).slice(0,3);return(0,i.jsxs)("div",{className:"relative",children:[e.reverse().map(e=>(0,i.jsx)("div",{className:"absolute top-0 left-1/2 transition-transform duration-150 ease-in-out pointer-events-none",style:{transform:"translateX(-50%) translateY(6px) scale(0.94)",zIndex:-1,opacity:.75},children:(0,i.jsx)("div",{className:"w-40",children:(0,i.jsx)(tb,{itemData:e})})},e.data.id)),(0,i.jsxs)("div",{className:"relative w-40 left-1/2 transform -translate-x-1/2",style:{zIndex:0},children:[t,(0,i.jsx)("div",{className:"absolute top-0 right-0 bg-primary text-primary-foreground rounded-full text-xs font-semibold shadow-lg border-2 border-background z-10 transform translate-x-1/2 -translate-y-1/2 flex items-center justify-center w-5 h-5",children:eL.size})]})]})}})():null})]}),e_&&(0,i.jsx)(L,{open:!0,onOpenChange:eB,onFolderCreated:()=>{al("create-folder"),ei&&ei()},folderHierarchy:d||[],initialFolderId:ea}),(0,i.jsx)(U.C,{open:eK,onOpenChange:eG,onUploadComplete:ay,folderHierarchy:d,initialFolderId:ea}),eW&&(0,i.jsx)(eg,{open:!0,onOpenChange:eV,onImportComplete:async e=>{await al("upload"),en&&en([e])},folderId:ea,folderHierarchy:d}),eH&&(0,i.jsx)(eb,{open:!0,onOpenChange:eY,media:tE}),tM&&(0,i.jsx)(ey.k,{isOpen:!0,onOpenChange:e=>{tD(e),e||tP(null)},media:tA,onConversionStarted:(e,t,a)=>{t2(e.conversionJobId),t0(i=>{if(!(null==i?void 0:i.data))return i;if("replace"===t)return{...i,data:{...i.data,media:i.data.media.map(e=>e.id===a.id?{...e,status:"CONVERTING"}:e)}};if(!e.targetMediaId)return i;let n=i.data.media.find(e=>e.id===a.id);if(!n)return i;let r={...n,id:e.targetMediaId,status:"CONVERTING",sizeInBytes:BigInt(0),createdAt:new Date,updatedAt:new Date};return{...i,data:{...i.data,media:[r,...i.data.media]}}},{revalidate:!0})}}),t_&&tK&&tW&&(0,i.jsx)(ej,{open:tL,onOpenChange:e=>{tU(e),e||(tB(null),tG(null),tV(null))},onRefreshCache:async(e,t)=>{if("replace"===e&&t)try{let e=await fetch("/api/queries/media?mediaId=".concat(t));if(e.ok){let a=(await e.json()).data;await t0(e=>e&&e.data&&e.data.media?{data:{media:e.data.media.map(e=>e.id===t?a:e),folders:e.data.folders}}:e,{revalidate:!1});return}}catch(e){console.error("[MediaLayout] Failed to fetch updated media:",e)}"replace"===e?await al("update-media",t):await al("upload")},mediaId:t_,designId:tK,token:tW,onComplete:()=>{al("upload")}}),eX&&(0,i.jsx)(e2,{open:eX,onOpenChange:eZ,onConfirm:ap,itemCount:eL.size,selectedItems:eL,folders:t9,media:t8,isLoading:eD}),e0&&(0,i.jsx)(e5,{open:!0,onOpenChange:e4,itemsToMove:Array.from(eL),itemType:aI(),folderIds:t9.map(e=>e.id),mediaIds:t8.map(e=>e.id),currentFolderId:ea,onItemsMoved:async()=>{await new Promise(e=>setTimeout(e,100)),await al("move-items"),eU(new Set),aw()}}),!aU&&tn&&(0,i.jsx)(e8.CreatePostDialog,{open:!0,onOpenChange:aM,initialMedia:eL.size>0?Array.from(eL).map(e=>t8.find(t=>
1t.id===e)).filter(e=>void 0!==e).map(e=>{var t,a,i,n;return{mediaId:e.id,url:e.url,type:e.type,alt:"",width:null!=(t=e.width)?t:void 0,height:null!=(a=e.height)?a:void 0,thumbnailUrl:null!=(i=e.thumbnailUrl)?i:void 0,sizeInBytes:e.sizeInBytes?Number(e.sizeInBytes):void 0,durationSeconds:null!=(n=e.durationSeconds)?n:void 0}}):void 0,preloadedSocialAccounts:(null==eN?void 0:eN.filter(e=>e.isActive))||[],preloadedSocialGroups:ek}),to&&(0,i.jsx)(ta,{open:!0,onOpenChange:tw,item:tj,onUpdateComplete:e=>{"color"in e?(t0(t=>t?{...t,data:{...t.data,folders:t.data.folders.map(t=>t.id===e.id?e:t)}}:t,!1),e.id===(null==e3?void 0:e3.id)&&e9(e)):t0(t=>t?{...t,data:{...t.data,media:t.data.media.map(t=>t.id===e.id?e:t)}}:t,!1),al("color"in e?"update-folder":"update-media",e.id),eU(new Set),ts([])}}),tN&&(0,i.jsx)(td,{open:!0,onOpenChange:tS,media:tk,mediaItems:t8,onMediaChange:e=>{tT(e)}}),ai&&(0,i.jsx)("div",{className:"hidden",children:(0,i.jsx)(tg.ConnectSocialButton,{ref:ar,onSuccess:()=>{tr(!0)}})}),eJ&&(0,i.jsx)(tx.PricingDialog,{open:!0,onOpenChange:eQ,currentPlanTier:ef,context:"media-storage",loading:!1,trialEligible:ex,subscriptionOwnership:ev}),(aW||eE)&&(0,i.jsx)(B.W,{withBlur:!0})]})}},19511:(e,t,a)=>{"use strict";function i(e,t){if(!["INSTAGRAM","INSTAGRAM_DIRECT","THREADS","PINTEREST","LINKEDIN","LINKEDIN_ORGANIZATION"].includes(e.platform))return null;if("LINKEDIN"===e.platform||"LINKEDIN_ORGANIZATION"===e.platform){try{let a={};e.metadata&&(a="string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata);let i=a.refreshTokenExpiresAt;if(i){let e=new Date(i),a=new Date,n=e.getTime()-a.getTime(),r=Math.ceil(n/864e5);if(r<0)return{status:"expired",days:Math.abs(r),text:t?t("tokenExpiration.refreshTokenExpired",{days:Math.abs(r),plural:1===Math.abs(r)?"":"s"}):"Expired ".concat(Math.abs(r)," day").concat(1===Math.abs(r)?"":"s"," ago")};if(0===r)return{status:"today",days:0,text:t?t("tokenExpiration.refreshTokenExpiresToday"):"Expires today"};if(r<=30)return{status:"warning",days:r,text:t?t("tokenExpiration.refreshTokenExpiresIn",{days:r,plural:1===r?"":"s"}):"Expires in ".concat(r," day").concat(1===r?"":"s")};else return{status:"valid",days:r,text:t?t("tokenExpiration.refreshTokenExpiresIn",{days:r,plural:1===r?"":"s"}):"Expires in ".concat(r," day").concat(1===r?"":"s")}}}catch(e){console.error("Error parsing LinkedIn metadata:",e)}return null}if(!e.expiresAt)return null;let a=new Date,i=Math.ceil((new Date(e.expiresAt).getTime()-a.getTime())/864e5);return i<0?{status:"expired",days:Math.abs(i),text:t?t("tokenExpiration.expired",{days:Math.abs(i),plural:1===Math.abs(i)?"":"s"}):"Expired ".concat(Math.abs(i)," day").concat(1===Math.abs(i)?"":"s"," ago")}:0===i?{status:"today",days:0,text:t?t("tokenExpiration.expiresToday"):"Expires today"}:i<=7?{status:"warning",days:i,text:t?t("tokenExpiration.expiresIn",{days:i,plural:1===i?"":"s"}):"Expires in ".concat(i," day").concat(1===i?"":"s")}:{status:"valid",days:i,text:t?t("tokenExpiration.expiresIn",{days:i,plural:1===i?"":"s"}):"Expires in ".concat(i," day").concat(1===i?"":"s")}}function n(e){let t=i(e);return null!==t&&"expired"===t.status}function r(e){return"RECONNECT_REQUIRED"===e.connectionStatus}a.d(t,{Ur:()=>r,XP:()=>n,po:()=>i})},19873:(e,t,a)=>{"use strict";a.d(t,{D:()=>v});var i=a(7778),n=a(85418),r=a(72488),l=a(20389),s=a(50749),o=a(28482),d=a(85191),c=a(50330),u=a(92919),m=a(25065),h=a(99889),p=a(688),f=a(51157);function x(e){let{node:t,level:a,isSelected:n,onSelect:r,selectedValue:l}=e;return(0,i.jsxs)("li",{className:"relative pl-[1.25rem] list-none before:absolute before:left-[0.5rem] before:top-0 before:bottom-0 before:w-px before:bg-border last:before:h-5",children:[(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center justify-between w-full text-left h-10 pl-2 pr-1 rounded-sm relative","after:absolute after:left-[-0.75rem] after:top-1/2 after:-translate-y-1/2 after:w-3 after:h-px after:bg-border","hover:bg-muted","cursor-pointer",n?"bg-accent text-accent-foreground":""),onClick:()=>r(t.id),role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&r(t.id)},style:{cursor:"pointer"},children:[(0,i.jsxs)("div",{className:"flex items-center gap-2 overflow-hidden",children:[(0,i.jsx)(p.s,{className:"h-6 w-6 flex-shrink-0",color:t.color}),(0,i.jsx)("span",{className:"truncate text-sm font-medium",children:t.name})]}),t.children.length>0&&(0,i.jsx)(f.A,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground mr-1"})]}),t.children.length>0&&(0,i.jsx)("ul",{className:"list-none p-0 m-0 pt-1",children:t.children.map(e=>(0,i.jsx)(x,{node:e,level:a+1,isSelected:l===e.id,onSelect:r,selectedValue:l},e.id))})]})}let g=(e,t)=>{for(let a of e){if(a.id===t)return a;let e=g(a.children,t);
1if(e)return e}return null};function v(e){let{fieldLabel:t,value:a,onChange:f,defaultValue:v,onOpenChange:b,folderHierarchy:y,initialFolderError:w}=e,j=(0,l.useTranslations)("Media"),[C,N]=(0,n.useState)(y),[S]=(0,n.useState)(!1),[k]=(0,n.useState)(w||null),[T,E]=(0,n.useState)(!1);(0,n.useEffect)(()=>{N(y)},[y]),(0,n.useEffect)(()=>{void 0!==v&&f(v)},[v,f]);let I=e=>{f(e),E(!1),null==b||b(!1)},A=null===a||"home"===a?{id:"home",name:j("home")}:g(C,a);return(0,i.jsxs)(u.rI,{open:T,onOpenChange:e=>{E(e),null==b||b(e)},children:[(0,i.jsx)(u.ty,{asChild:!0,children:(0,i.jsxs)(c.$,{variant:"outline",role:"combobox","aria-expanded":T,className:(0,m.cn)("w-full min-w-0 justify-between",t&&"gap-2 px-3 py-0"),disabled:S,children:[(0,i.jsxs)("div",{className:"flex h-full min-w-0 flex-1 items-center gap-2 text-left",children:[t&&(0,i.jsx)(r.m,{children:t}),S?(0,i.jsx)("span",{className:"text-muted-foreground",children:j("loadingFolders")}):A?(0,i.jsxs)("span",{className:"flex min-w-0 items-center gap-2",children:["home"===A.id?(0,i.jsx)(s.A,{className:"h-4 w-4 shrink-0"}):(0,i.jsx)(p.s,{className:"h-4 w-4 shrink-0",color:A.color}),(0,i.jsx)("span",{className:"truncate",children:A.name})]}):(0,i.jsx)("span",{className:"text-muted-foreground",children:j("selectFolder")})]}),(0,i.jsx)(o.A,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),(0,i.jsx)(u.SQ,{align:"start",className:"w-[--radix-dropdown-menu-trigger-width] p-0",children:(0,i.jsx)(h.F,{className:"h-[250px] overflow-y-auto",children:(0,i.jsx)("div",{className:"p-2",children:S?(0,i.jsx)("div",{className:"flex items-center justify-center p-4",children:(0,i.jsx)(d.A,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):k?(0,i.jsx)("p",{className:"px-4 py-2 text-sm text-destructive text-center",children:k}):C&&0!==C.length?(0,i.jsxs)("ul",{className:"list-none p-0 m-0",children:[(0,i.jsx)("li",{className:"relative list-none",children:(0,i.jsx)("div",{className:(0,m.cn)("flex items-center justify-between w-full text-left h-10 pl-3 pr-1 cursor-pointer rounded-sm relative","hover:bg-muted",null===a||"home"===a?"bg-accent text-accent-foreground":""),onClick:()=>I(null),role:"button",tabIndex:0,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&I(null)},children:(0,i.jsxs)("div",{className:"flex items-center gap-2 overflow-hidden",children:[(0,i.jsx)(s.A,{className:"h-5 w-5 flex-shrink-0"}),(0,i.jsx)("span",{className:"truncate text-sm font-medium",children:j("home")})]})})}),C.map(e=>(0,i.jsx)(x,{node:e,level:0,isSelected:a===e.id,onSelect:I,selectedValue:a},e.id))]}):(0,i.jsx)("p",{className:"px-4 py-2 text-sm text-muted-foreground text-center",children:j("noFoldersFound")})})})})]})}},19958:(e,t,a)=>{"use strict";a.r(t),a.d(t,{CreatePostDialog:()=>i6});var i=a(7778),n=a(3854),r=a(66379),l=a(68663),s=a(11576),o=a(20389),d=a(85418),c=a(66467),u=a(34089),m=a(25065),h=a(20581);function p(e){return"number"==typeof e&&Number.isFinite(e)?e:"bigint"==typeof e?Number(e):void 0}function f(e){return[..."string"==typeof e.mediaId?["id:".concat(e.mediaId)]:[],"url:".concat(e.url)]}function x(e){var t,a;return{duration:null!=(t=p(e.duration))?t:p(e.durationSeconds),fileSize:null!=(a=p(e.fileSize))?a:p(e.sizeInBytes),width:p(e.width),height:p(e.height),thumbnailUrl:"string"==typeof e.thumbnailUrl?e.thumbnailUrl:void 0}}function g(e){var t,a,i,n,r;let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{duration:null!=(t=e.duration)?t:l.duration,fileSize:null!=(a=e.fileSize)?a:l.fileSize,width:null!=(i=e.width)?i:l.width,height:null!=(n=e.height)?n:l.height,thumbnailUrl:null!=(r=e.thumbnailUrl)?r:l.thumbnailUrl}}function v(e,t){return!(t.length<2)&&new Set(t.map(t=>{var a,i;return null!=(i=null==(a=e[t])?void 0:a.content)?i:""})).size>1}function b(e,t,a,i,n){if(!n)return{...e,[a]:{...e[a],content:i}};let r={...e},l=!1;for(let n of t)n.id===a&&(l=!0),r[n.id]={...e[n.id],content:function(e,t){return t===c.SocialPlatform.LINKEDIN||t===c.SocialPlatform.LINKEDIN_ORGANIZATION?e:(0,m.QP)(e)}(i,n.platform)};return l||(r[a]={...e[a],content:i}),r}function y(e,t){return t>1?"carousel":"feed"===e||"story"===e||"reel"===e||"carousel"===e?e:"feed"}function w(e,t){var a,i,n;let r=y(e,t.length);if(t.length>1)return"carousel";let l=1===t.length&&null!=(n=null==(i=t[0])||null==(a=i.type)?void 0:a.startsWith("video/"))&&n;return"carousel"===r?l?"reel":"feed":l&&"feed"===r?"reel":1!==t.length||l||"reel"!==r?r:"feed"}let j=["image/jpeg","image/jpg","image/png","image/gif"];function C(e){return"string"==typeof e&&e.length>0?e:void 0}function N(e){return"bigint"==typeof e?Number(e):"number"==typeof e&&Number.isFinite(e)?e:void 0}function S(e){var t,a;let i=[],n=[],r=[],l=null==(t=e.type)?void 0:t.toLowerCase(),s=N(null!=(a=e.sizeInBytes)?a:e.fileSize);return(null==l?void 0:l.startsWith("image/"))?j.includes(l)||(i.push("unsupportedType"),n.push("Thumbnail formats: JPG, PNG, GIF only")):(i.push("notImage"),n.push("Thumbnail must be an image file")),void 0===s?(i.push("unknownFileSize"),n.push("Thumbnail file size could not be verified")):s>2097152&&(i.push("fileTooLarge"),n.push("Thumbnail file size must be under 2MB")),null==e.width?(i.push("unknownWidth"),n.push("Thumbnail width could not be verified")):e.width<640&&(i.push("widthTooSmall"),n.push("Thumbnail minimum width: 640 pixels required")),e.width&&e.height&&Math.abs(e.width/e.height-16/9)>.2&&r.push("Recommended aspect ratio: 16:9 (e.g., 1280\xd7720) for best results"),{isValid:0===n.length,errorCodes:i,errors:n,warnings:r}}function k(e,t){var a;return e!==c.SocialPlatform.INSTAGRAM&&e!==c.SocialPlatform.INSTAGRAM_DIRECT?t:{...t,postType:w(t.postType,null!=(a=t.media)?a:[])}}let T=(0,d.createContext)(void 0);function E(e){var t;let{children:a,allSocialAccounts:n,initialPostGroup:r,initialMedia:l,initialScheduledDate:s,initialPublishAction:o,initialContent:p,hashtagCollections:b=null,textSnippetCollections:y=null,isLoadingHashtagsAndSnippets:w=!1,duplicateMode:j=!1,initialCaptionSyncEnabled:S=!1}=e,E=(0,d.useMemo)(()=>{var e;return j?null:(null==r?void 0:r.groupPostsId)||(null==r||null==(e=r.posts[0])?void 0:e.id)||null},[r,j]),I=(0,d.useMemo)(()=>(null==r?void 0:r.socialAccounts)?n.filter(e=>r.socialAccounts.some(t=>t.id===e.id)):[],[r,n]),M=(0,d.useMemo)(()=>
1{if((E||j)&&(null==r?void 0:r.posts)){let e={},t=function(e){let t=new Map;for(let i of e.flat()){let e=x(i);for(let n of f(i)){var a;t.set(n,g(null!=(a=t.get(n))?a:{},e))}}return t}(r.posts.map(e=>{let t=e.platformPayload;return Array.isArray(null==t?void 0:t.media)?t.media.filter(e=>"string"==typeof(null==e?void 0:e.url)):[]}));return r.posts.forEach(a=>{if(a.socialAccountId){var i,n,r,l,s,o,d,u,m,h,p,v,b,y,w,j,S,T,E,I,A,P,M;let D=a.platformPayload,R=a.mediaExpiredAt?[]:null==D?void 0:D.media,F=(null==(i=a.socialAccount)?void 0:i.platform)===c.SocialPlatform.PINTEREST?"pin":(null==(n=a.socialAccount)?void 0:n.platform)===c.SocialPlatform.LINKEDIN||(null==(r=a.socialAccount)?void 0:r.platform)===c.SocialPlatform.LINKEDIN_ORGANIZATION?"feed":(null==(l=a.socialAccount)?void 0:l.platform)===c.SocialPlatform.MASTODON?"post":null==D?void 0:D.postType,O={content:(null==D?void 0:D.content)||(null==D?void 0:D.message)||"",media:Array.isArray(R)?R.filter(e=>"string"==typeof(null==e?void 0:e.url)).map((e,a)=>(function(e,t,a){let i=g(x(e),function(e,t){for(let a of f(e)){let e=t.get(a);if(e)return e}return{}}(e,a)),n="string"==typeof e.type&&e.type.includes("/")?e.type:function(e){let t=e.toLowerCase();return t.includes(".mp4")?"video/mp4":t.includes(".mov")?"video/quicktime":t.includes(".webm")?"video/webm":t.includes(".png")?"image/png":t.includes(".gif")?"image/gif":t.includes(".jpg")||t.includes(".jpeg")?"image/jpeg":"application/octet-stream"}(e.url);return{id:t,mediaId:"string"==typeof e.mediaId?e.mediaId:void 0,url:e.url,type:n,alt:"string"==typeof e.alt?e.alt:void 0,duration:i.duration,fileSize:i.fileSize,width:i.width,height:i.height,aspectRatio:i.width&&i.height?i.width/i.height:void 0,thumbnailUrl:i.thumbnailUrl}})(e,"db-media-".concat(Date.now(),"-").concat(a),t)):[],postType:F};if((null==(s=a.socialAccount)?void 0:s.platform)===c.SocialPlatform.PINTEREST&&(O.pinterest={link:null==D||null==(S=D.settings)?void 0:S.link,title:null==D||null==(T=D.settings)?void 0:T.title,board:null==D||null==(E=D.settings)?void 0:E.board,section:null==D||null==(I=D.settings)?void 0:I.section}),(null==(o=a.socialAccount)?void 0:o.platform)===c.SocialPlatform.INSTAGRAM){let e,t=null==D?void 0:D.userTags,a=null==D?void 0:D.locationId,i=null==D?void 0:D.locationName,n=null==D?void 0:D.firstComment,r=null==D?void 0:D.collaborators,l=null==D?void 0:D.shareToFeed;if(t&&"object"==typeof t&&!Array.isArray(t)){let a=O.media,i={},n=Object.keys(t);if(n.length>0&&/^\d+$/.test(n[0]))for(let[e,n]of Object.entries(t)){let t=a[parseInt(e,10)];t&&Array.isArray(n)&&n.length>0&&(i[t.id]=n)}else for(let[e,n]of Object.entries(t)){let t=a.find(t=>t.url===e);t&&Array.isArray(n)&&n.length>0&&(i[t.id]=n)}Object.keys(i).length>0&&(e=i)}else if(Array.isArray(t)&&t.length>0){let a=null==(P=O.media)||null==(A=P[0])?void 0:A.id;a&&(e={[a]:t})}(e||a||n||(null==r?void 0:r.length)||void 0!==l)&&(O.instagram={...void 0!==l&&{shareToFeed:l},...e&&{userTags:e},...a&&{locationId:a,locationName:i},...n&&{firstComment:n},...(null==r?void 0:r.length)&&{collaborators:r}})}if((null==(d=a.socialAccount)?void 0:d.platform)===c.SocialPlatform.INSTAGRAM_DIRECT){let e=null==D?void 0:D.shareToFeed,t=null==D?void 0:D.firstComment;(void 0!==e||t)&&(O.instagram={...void 0!==e&&{shareToFeed:e},...t&&{firstComment:t}})}if((null==(u=a.socialAccount)?void 0:u.platform)===c.SocialPlatform.X&&(O.x={communityId:"string"==typeof(null==D?void 0:D.communityId)?D.communityId:void 0,communityName:"string"==typeof(null==D?void 0:D.communityName)?D.communityName:void 0,communityThumbnailUrl:"string"==typeof(null==D?void 0:D.communityThumbnailUrl)?D.communityThumbnailUrl:void 0,shareWithFollowers:"boolean"==typeof(null==D?void 0:D.shareWithFollowers)?D.shareWithFollowers:null!=D&&!!D.communityId||void 0,threadComments:Array.isArray(null==D?void 0:D.threadComments)?D.threadComments.map(e=>({id:e.id||"comment-".concat(Date.now(),"-").concat(Math.random()),content:e.content||"",media:Array.isArray(e.media)?e.media.map((e,t)=>({id:"comment-media-".concat(Date.now(),"-").concat(t),url:e.url,type:e.type||"image/jpeg",alt:e.alt||""})):[]})):[]}),(null==(m=a.socialAccount)?void 0:m.platform)===c.SocialPlatform.LINKEDIN||(null==(h=a.socialAccount)?void 0:h.platform)===c.SocialPlatform.LINKEDIN_ORGANIZATION){let e=null==D||null==(M=D.linkedin)?void 0:M.comment;e&&(O.linkedin={comment:{id:e.id||"comment-".concat(Date.now(),"-").concat(Math.random()),content:e.content||"",media:Array.isArray(e.media)?e.media.map((e,t)=>({id:"comment-media-".concat(Date.now(),"-").concat(t),url:e.url,type:e.type||"image/jpeg",alt:e.alt||""})):[]}})}(null==(p=a.socialAccount)?void 0:p.platform)===c.SocialPlatform.YOUTUBE&&(O.youtube={title:"string"==typeof(null==D?void 0:D.title)?D.title:"",description:"string"==typeof(null==D?void 0:D.description)?D.description:(null==D?void 0:D.content)||(null==D?void 0:D.message)||"",tags:Array.isArray(null==D?void 0:D.tags)?D.tags:[],categoryId:"string"==typeof(null==D?void 0:D.categoryId)?D.categoryId:void 0,customThumbnail:function(e,t){if(e&&"object"==typeof e&&!Array.isArray(e)){let t=C(e.url);if(t){let a=C(e.mediaId),i=C(e.type),n=C(e.thumbnailUrl),r=N(e.fileSize),l=N(e.width),s=N(e.height);return{url:t,...a?{mediaId:a}:{},...i?{type:i}:{},...n?{thumbnailUrl:n}:{},...void 0!==r?{fileSize:r}:{},...void 0!==l?{width:l}:{},...void 0!==s?{height:s}:{}}}}let a=C(t);return a?{url:a}:void 0}(null==D?void 0:D.customThumbnail,null==D?void 0:D.thumbnailMediaId),privacyStatus:(null==D?void 0:D.privacyStatus)==="public"||(null==D?void 0:D.privacyStatus)==="private"||(null==D?void 0:D.privacyStatus)==="unlisted"?D.privacyStatus:"private"},O.content="string"==typeof(null==D?void 0:D.description)?D.description:(null==D?void 0:D.content)||(null==D?void 0:D.message)||""),(null==(v=a.socialAccount)?void 0:v.platform)===c.SocialPlatform.TIKTOK&&(O.tiktok={privacyLevel:"string"==typeof(null==D?void 0:D.privacyLevel)?D.privacyLevel:"PUBLIC_TO_EVERYONE",disableDuet:"boolean"==typeof(null==D?void 0:D.disableDuet)&&D.disableDuet,disableStitch:"boolean"==typeof(null==D?void 0:D.disableStitch)&&D.disableStitch,disableComment:"boolean"==typeof(null==D?void 0:D.disableComment)&&D.disableComment,discloseContent:"boolean"==typeof(null==D?void 0:D.discloseContent)&&D.discloseContent,isYourBrand:"boolean"==typeof(null==D?void 0:D.isYourBrand)&&D.isYourBrand,isBrandedContent:"boolean"==typeof(null==D?void 0:D.isBrandedContent)&&D.isBrandedContent}),(null==(b=a.socialAccount)?void 0:b.platform)===c.SocialPlatform.TELEGRAM&&(O.telegram={pin:"boolean"==typeof(null==D?void 0:D.pin)&&D.pin}),(null==(y=a.socialAccount)?void 0:y.platform)===c.SocialPlatform.THREADS&&(O.content="string"==typeof(null==D?void 0:D.text)?D.text:"",O.threads={threadComments:Array.isArray(null==D?void 0:D.threadComments)?D.threadComments.map(e=>({id:e.id||"comment-".concat(Date.now(),"-").concat(Math.random()),content:e.content||"",media:Array.isArray(e.media)?e.media.map((e,t)=>({id:"comment-media-".concat(Date.now(),"-").concat(t),url:e.url,type:e.type||"image/jpeg",alt:e.alt||""})):[]})):[]}),(null==(w=a.socialAccount)?void 0:w.platform)===c.SocialPlatform.MASTODON&&(O.mastodon={threadComments:Array.isArray(null==D?void 0:D.threadComments)?D.threadComments.map(e=>({id:e.id||"comment-".concat(Date.now(),"-").concat(Math.random()),content:e.content||"",media:Array.isArray(e.media)?e.media.map((e,t)=>({id:"comment-media-".concat(Date.now(),"-").concat(t),url:e.url,type:e.type||"image/jpeg",alt:e.alt||""})):[]})):[]}),e[a.socialAccountId]=k(null==(j=a.socialAccount)?void 0:j.platform,O)}}),e}if(I.length>0&&p){let e={};return I.forEach(t=>{let a=u.C[t.platform],i=Object.keys((null==a?void 0:a.postTypes)||{})[0],n=l&&l.length>0?l.map((e,a)=>({id:"initial-media-".concat(Date.now(),"-").concat(a,"-").concat(t.id),mediaId:e.mediaId,url:e.url,alt:e.alt||"",type:e.type,width:e.width,height:e.height,thumbnailUrl:e.thumbnailUrl,fileSize:e.sizeInBytes,duration:e.durationSeconds,aspectRatio:"number"==typeof e.width&&"number"==typeof e.height&&0!==e.height?e.width/e.height:void 0})):void 0;e[t.id]=k(t.platform,{content:p,media:n,...i&&{postType:i}})}),e}return{}},[E,j,r,l,I,p]),D=(0,d.useMemo)(()=>
1{if(p)return p;if((null==r?void 0:r.posts)&&r.posts.length>0){let e=r.posts[0].platformPayload;return(null==e?void 0:e.content)||(null==e?void 0:e.message)||""}return""},[r,p]),R=(0,d.useMemo)(()=>{var e,t;return e=!!(E||j),t=I.map(e=>e.id),!!S&&(!e||!v(M,t))},[j,E,S,M,I]),F=(0,d.useMemo)(()=>l&&l.length>0?l.map(e=>e.url):[],[l]),O=(0,d.useRef)(new Map(null!=(t=null==l?void 0:l.map(e=>[e.url,e]))?t:[]));(0,d.useEffect)(()=>{var e;O.current=new Map(null!=(e=null==l?void 0:l.map(e=>[e.url,e]))?e:[])},[l]);let z=(0,d.useMemo)(()=>{if(s||(null==r?void 0:r.scheduledFor))return(0,h.OG)(null!=s?s:null==r?void 0:r.scheduledFor);if(!r){let e=new Date;return e.setHours(e.getHours()+1),e}return null},[s,r]),L=(0,d.useMemo)(()=>{if(o)return o;if(!(null==r?void 0:r.posts)||0===r.posts.length)return"schedule";let e=r.posts.some(e=>"DRAFT"===e.status),t=r.posts.some(e=>"PENDING"===e.status),a=r.posts.some(e=>"PUBLISHED"===e.status),i=r.posts.some(e=>"FAILED"===e.status);if(e)return"draft";if(t);else if(a||i)return"publish";return"schedule"},[r,o]),[U,_]=(0,d.useReducer)(A,{...P,selectedAccounts:I,payloads:M,commonContent:D,captionSyncEnabled:R,commonImages:F,publishAction:L,scheduleFor:z,editingGroupId:E}),[B,K]=(0,d.useState)(()=>{var e;return(null==(e=I[0])?void 0:e.id)||(n&&n.length>0?n[0].id:null)}),G=(0,d.useRef)(null);(0,d.useEffect)(()=>{G.current=B},[B]),(0,d.useEffect)(()=>{n&&n.length>0&&!B&&K(n[0].id)},[]);let W=(0,d.useMemo)(()=>n?null===U.currentGroupId?n:n.filter(e=>Array.isArray(e.socialGroups)&&e.socialGroups.some(e=>e.id===U.currentGroupId)):[],[n,U.currentGroupId]),V=(0,d.useCallback)(e=>{let t=U.selectedAccounts.some(t=>t.id===e.id),a=t?U.selectedAccounts.filter(t=>t.id!==e.id):[...U.selectedAccounts,e];if(_({type:"SET_SELECTED_ACCOUNTS",payload:a}),!t&&!U.payloads[e.id]){let t=u.C[e.platform],a=Object.keys((null==t?void 0:t.postTypes)||{})[0],i=U.commonImages&&U.commonImages.length>0?U.commonImages.map((e,t)=>{let a=O.current.get(e),i=(null==a?void 0:a.type)||"image/jpeg";return!(null==a?void 0:a.type)&&(e.includes(".mp4")?i="video/mp4":e.includes(".mov")?i="video/quicktime":e.includes(".webm")?i="video/webm":e.includes(".png")?i="image/png":e.includes(".gif")?i="image/gif":(e.includes(".jpg")||e.includes(".jpeg"))&&(i="image/jpeg")),{id:"initial-media-".concat(Date.now(),"-").concat(t),mediaId:null==a?void 0:a.mediaId,url:e,alt:(null==a?void 0:a.alt)||"",type:i,width:null==a?void 0:a.width,height:null==a?void 0:a.height,thumbnailUrl:null==a?void 0:a.thumbnailUrl,fileSize:null==a?void 0:a.sizeInBytes,duration:null==a?void 0:a.durationSeconds,aspectRatio:"number"==typeof(null==a?void 0:a.width)&&"number"==typeof(null==a?void 0:a.height)&&0!==a.height?a.width/a.height:void 0}}):[],n=U.commonContent;e.platform!==c.SocialPlatform.LINKEDIN&&e.platform!==c.SocialPlatform.LINKEDIN_ORGANIZATION&&n&&(n=(0,m.QP)(n)),_({type:"UPDATE_PAYLOAD",payload:{accountId:e.id,data:{content:n,media:i.length>0?i:void 0,...a&&{postType:a}}}})}let i=B;if(t){if(0===a.length)i=null;else if(B===e.id){var n,r;i=null!=(r=null==(n=a[0])?void 0:n.id)?r:null}}else 1===a.length?i=a[0].id:null===G.current&&i!==e.id&&(i=e.id);i!==B&&K(i)},[U.selectedAccounts,U.payloads,U.commonContent,U.commonImages,B,K]),q=(0,d.useCallback)((e,t)=>{if(Object.prototype.hasOwnProperty.call(t,"content")){var a;_({type:"UPDATE_CAPTION",payload:{accountId:e,content:null!=(a=t.content)?a:""}});let{content:i,...n}=t;Object.keys(n).length>0&&_({type:"UPDATE_PAYLOAD",payload:{accountId:e,data:n}});return}_({type:"UPDATE_PAYLOAD",payload:{accountId:e,data:t}})},[]),H=(0,d.useCallback)((e,t)=>{_({type:"SET_CAPTION_SYNC_ENABLED",payload:{enabled:e,sourceAccountId:t}})},[]),$=(0,d.useCallback)(e=>{_({type:"SET_SCHEDULE_FOR",payload:e})},[]),Y=(0,d.useCallback)(e=>{_({type:"SET_PUBLISH_ACTION",payload:e})},[]),X=(0,d.useCallback)(e=>{_({type:"SET_COMMON_CONTENT",payload:e})},[]),Z=(0,d.useCallback)(e=>{_({type:"SET_COMMON_IMAGES",payload:e})},[]),J=(0,d.useCallback)(e=>{if(_({type:"SET_CURRENT_GROUP_ID",payload:e}),null!==e&&n){var t,a;let i=n.filter(t=>Array.isArray(t.socialGroups)&&t.socialGroups.some(t=>t.id===e));_({type:"SET_SELECTED_ACCOUNTS",payload:i}
1),i.forEach(e=>{if(!U.payloads[e.id]){let t=u.C[e.platform],a=Object.keys((null==t?void 0:t.postTypes)||{})[0],i=U.commonImages&&U.commonImages.length>0?U.commonImages.map((t,a)=>{let i=O.current.get(t),n=(null==i?void 0:i.type)||"image/jpeg";return!(null==i?void 0:i.type)&&(t.includes(".mp4")?n="video/mp4":t.includes(".mov")?n="video/quicktime":t.includes(".webm")?n="video/webm":t.includes(".png")?n="image/png":t.includes(".gif")?n="image/gif":(t.includes(".jpg")||t.includes(".jpeg"))&&(n="image/jpeg")),{id:"initial-media-".concat(Date.now(),"-").concat(a,"-").concat(e.id),mediaId:null==i?void 0:i.mediaId,url:t,alt:(null==i?void 0:i.alt)||"",type:n,width:null==i?void 0:i.width,height:null==i?void 0:i.height,thumbnailUrl:null==i?void 0:i.thumbnailUrl,fileSize:null==i?void 0:i.sizeInBytes,duration:null==i?void 0:i.durationSeconds,aspectRatio:"number"==typeof(null==i?void 0:i.width)&&"number"==typeof(null==i?void 0:i.height)&&0!==i.height?i.width/i.height:void 0}}):[],n=U.commonContent;e.platform!==c.SocialPlatform.LINKEDIN&&e.platform!==c.SocialPlatform.LINKEDIN_ORGANIZATION&&n&&(n=(0,m.QP)(n)),_({type:"UPDATE_PAYLOAD",payload:{accountId:e.id,data:{content:n,media:i.length>0?i:void 0,...a&&{postType:a}}}})}}),K(null!=(a=null==(t=i[0])?void 0:t.id)?a:null)}},[n,U.payloads,U.commonContent,U.commonImages]),Q=(0,d.useCallback)(e=>{var t,a;_({type:"SET_SELECTED_ACCOUNTS",payload:e}),K(null!=(a=null==(t=e[0])?void 0:t.id)?a:null)},[K]),ee=(0,d.useCallback)((e,t)=>{let a=U.payloads[e];if(!a)return;let i=a[t];if("pinterest"===t){if(!i||"object"==typeof i&&0===Object.keys(i).length)return void console.warn("Cannot copy empty or undefined 'pinterest' field from account ".concat(e,"."))}else if("content"===t&&(!i||""===String(i).trim())||"media"===t&&(!i||!Array.isArray(i)||0===i.length))return void console.warn("Cannot copy empty field '".concat(String(t),"' from account ").concat(e,"."));U.selectedAccounts.forEach(a=>{if(a.id===e)return;let n=i;"content"===t&&"string"==typeof i&&a.platform!==c.SocialPlatform.LINKEDIN&&a.platform!==c.SocialPlatform.LINKEDIN_ORGANIZATION&&(n=(0,m.QP)(i)),_({type:"UPDATE_PAYLOAD",payload:{accountId:a.id,data:{[t]:n}}})})},[U.payloads,U.selectedAccounts]),et=(0,d.useCallback)((e,t,a,i)=>{},[]),ea=(0,d.useMemo)(()=>({selectedAccounts:U.selectedAccounts,payloads:U.payloads,scheduleFor:U.scheduleFor,publishAction:U.publishAction,commonContent:U.commonContent,captionSyncEnabled:U.captionSyncEnabled,commonImages:U.commonImages,currentGroupId:U.currentGroupId,openCardId:B,editingGroupId:U.editingGroupId,filteredAccounts:W,toggleAccountSelection:V,updatePayload:q,setScheduleFor:$,setPublishAction:Y,setCommonContent:X,setCaptionSyncEnabled:H,setCommonImages:Z,setCurrentGroupId:J,setSelectedAccounts:Q,onCopyField:ee,setOpenCardId:K,updatePlatformSpecificField:et,initialPostGroup:r,hashtagCollections:b,textSnippetCollections:y,isLoadingHashtagsAndSnippets:w,duplicateMode:j}),[U.selectedAccounts,U.payloads,U.scheduleFor,U.publishAction,U.commonContent,U.captionSyncEnabled,U.commonImages,U.currentGroupId,B,W,V,q,$,Y,X,H,Z,J,Q,ee,K,et,U.editingGroupId,r,b,y,w,j]);return(0,i.jsx)(T.Provider,{value:ea,children:a})}function I(){let e=(0,d.useContext)(T);if(void 0===e)throw Error("usePostContext must be used within a PostProvider");return e}function A(e,t){switch(t.type){case"SET_SELECTED_ACCOUNTS":{let a={...e.payloads};for(let e of t.payload){let t=a[e.id];t&&(a[e.id]=k(e.platform,t))}return{...e,selectedAccounts:t.payload,payloads:a}}case"UPDATE_PAYLOAD":{let a=e.payloads[t.payload.accountId],i=e.selectedAccounts.find(e=>e.id===t.payload.accountId),n=Object.prototype.hasOwnProperty.call(t.payload.data,"media"),r={...a,...t.payload.data},l=n?k(null==i?void 0:i.platform,r):r;return{...e,payloads:{...e.payloads,[t.payload.accountId]:l}}}case"UPDATE_CAPTION":return{...e,payloads:b(e.payloads,e.selectedAccounts,t.payload.accountId,t.payload.content,e.captionSyncEnabled),commonContent:e.captionSyncEnabled?t.payload.content:e.commonContent};case"SET_CAPTION_SYNC_ENABLED":{var a,i,n,r;let l=null!=(n=t.payload.sourceAccountId)?n:null==(a=e.selectedAccounts[0])?void 0:a.id;if(!t.payload.enabled||!l)return{...e,captionSyncEnabled:t.payload.enabled};let s=null!=(r=null==(i=e.payloads[l])?void 0:i.content)?r:"";return{...e,captionSyncEnabled:!0,commonContent:s,payloads:b(e.payloads,e.selectedAccounts,l,s,!0)}}case"SET_SCHEDULE_FOR":return{...e,scheduleFor:t.payload};case"SET_PUBLISH_ACTION":return{...e,publishAction:t.payload};case"SET_COMMON_CONTENT":return{...e,commonContent:t.payload};case"SET_COMMON_IMAGES":return{...e,commonImages:t.payload};case"SET_CURRENT_GROUP_ID":return{...e,currentGroupId:t.payload};case"SET_OPEN_CARD_ID":return{...e,openCardId:t.payload};case"SET_EDITING_GROUP_ID":return{...e,editingGroupId:t.payload};default:return e}}let P={selectedAccounts:[],payloads:{},scheduleFor:null,publishAction:"schedule",commonContent:"",captionSyncEnabled:!1,commonImages:[],currentGroupId:null,openCardId:null,editingGroupId:null};var M=a(68380),D=a(50330),R=a(5853),F=a(38035),O=a(17987),z=a(19511);function L(e){let{filteredAccounts:t,selectedAccounts:a,toggleAccountSelection:n,selectedGroup:r=null,onShowAllAccounts:l}=e,s=(0,o.useTranslations)("CreatePost"),c=(0,o.useTranslations)("CreatePost.header"),u=(0,d.useRef)(null),[h,p]=(0,d.useState)(!1),[f,x]=(0,d.useState)(0),[g,v]=(0,d.useState)(0),[b,y]=(0,d.useState)(!1);return(0,d.useEffect)(()=>{let e=()=>{if(u.current){let{scrollWidth:e,clientWidth:t}=u.current;y(e>t)}};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[t]),(0,i.jsx)(O.TooltipProvider,{children:(0,i.jsxs)("div",{className:"relative flex-1 min-w-0",children:[(0,i.jsxs)("div",{ref:u,className:(0,m.cn)("flex items-center gap-2 overflow-x-auto scrollbar-none py-1 -my-1 select-none",b&&(h?"cursor-grabbing":"cursor-grab")),onMouseDown:e=>{u.current&&(p(!0),x(e.pageX-u.current.offsetLeft),v(u.current.scrollLeft))},onMouseMove:e=>{if(!h||!u.current)return;e.preventDefault();let t=e.pageX-u.current.offsetLeft;u.current.scrollLeft=g-(t-f)*2},onMouseUp:()=>{p(!1)},onMouseLeave:()=>{p(!1)},children:[t.map(e=>{let t=(0,z.po)(e),r=(null==t?void 0:t.status)==="expired",l="RECONNECT_REQUIRED"===e.connectionStatus,o=e.platformUsername;try{if(e.metadata){let t="string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata;
1t&&(o=t.displayName||t.name||o)}}catch(e){}return(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(D.$,{variant:a.some(t=>t.id===e.id)?"outline":"ghost",size:"icon",className:(0,m.cn)("rounded-full h-10 w-10 p-0 border-2 flex-shrink-0 pointer-events-auto",a.some(t=>t.id===e.id)?"border-primary":"border-transparent","hover:border-primary/50 transition-colors"),onClick:()=>{h||n(e)},onMouseDown:e=>e.stopPropagation(),"aria-label":"Select ".concat(o),children:(0,i.jsx)(R.u,{account:e,size:"sm",disableTooltip:!0,isSelected:a.some(t=>t.id===e.id)})})}),(0,i.jsx)(O.TooltipContent,{className:"pb-2",children:(0,i.jsxs)("div",{className:"flex flex-col items-center gap-1.5",children:[(0,i.jsx)("p",{className:"font-medium",children:o}),e.isActive?l?(0,i.jsx)(F.Badge,{variant:"destructive",className:"text-[10px]",children:s("reconnect",{defaultValue:"Reconnect required"})}):r?(0,i.jsx)(F.Badge,{variant:"destructive",className:"text-[10px]",children:s("expired",{defaultValue:"Expired"})}):null:(0,i.jsx)(F.Badge,{variant:"secondary",className:"text-[10px]",children:s("inactive",{defaultValue:"Inactive"})})]})})]},e.id)}),null!=r&&null!=l&&(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)("button",{type:"button",onClick:l,onMouseDown:e=>e.stopPropagation(),"aria-label":c("allAccounts"),className:(0,m.cn)("flex-shrink-0 flex items-center h-7 px-2 rounded-full","border border-muted-foreground/40 bg-muted/30 hover:bg-muted/60 hover:border-primary/50","text-[11px] font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer"),children:c("showAll")})}),(0,i.jsx)(O.TooltipContent,{children:(0,i.jsx)("p",{children:c("allAccounts")})})]})]}),t.length>3&&(0,i.jsx)("div",{className:"absolute top-0 right-0 h-full w-6 bg-gradient-to-l from-background to-transparent pointer-events-none"})]})})}var U=a(30605),_=a(16323),B=a(95258),K=a(23860),G=a(76609),W=a(16698),V=a(92919),q=a(11357),H=a(82253);function $(e){var t,a;let{selectedGroup:n,onGroupSelect:r,availableAccounts:l,onGroupCreated:s,preloadedSocialGroups:c}=e,{workspace:u}=(0,q.k)(),[h,p]=(0,d.useState)([]),[f,x]=(0,d.useState)(!0),[g,v]=(0,d.useState)(null),b=(0,o.useTranslations)("CreatePost.header"),y=(0,o.useTranslations)("SocialGroupsManager"),[w,j]=(0,d.useState)(!1),[C,N]=(0,d.useState)(!1),[S,k]=(0,d.useState)(!1),T=(0,H.a)();(0,d.useEffect)(()=>{if(null!=c){p(c.filter(e=>!!e.socialAccounts&&0!==e.socialAccounts.length&&e.socialAccounts.some(e=>e.isActive))),x(!1),v(null);return}(async()=>{if(null==u?void 0:u.id){x(!0),v(null);try{let e=await fetch("/api/queries/social-groups?workspaceId=".concat(u.id));if(!e.ok)throw Error("Failed to fetch social groups");let t=await e.json();if(t.success){let e=(t.data||[]).filter(e=>!!e.socialAccounts&&0!==e.socialAccounts.length&&e.socialAccounts.some(e=>e.isActive));p(e)}else console.error("Error fetching groups:",t.error),v("Failed to load groups."),p([])}catch(e){console.error("Exception fetching groups:",e),v("Failed to load groups."),p([])}finally{x(!1)}}})()},[c]);let E=async(e,t,a)=>{if(!S&&(null==u?void 0:u.id)){k(!0);try{let i=await fetch("/api/social-groups",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({operation:"create",input:{name:e.trim(),socialAccountIds:t,isDefault:a}})}),n=await i.json();if(!i.ok||!n.success||!n.data)throw Error(n.error||y("toasts.failedToCreate"));let r=n.data;p(e=>[...e.map(e=>r.isDefault?{...e,isDefault:!1}:e),...r.socialAccounts.some(e=>e.isActive)?[r]:[]]),s(r),N(!1),B.oR.success(y("toasts.groupCreated")),(0,M.p)(),(0,W.dR)(u.id),(0,W.yw)(u.id),(0,K.j)("/api/queries/sidebar?workspaceId=".concat(u.id))}catch(e){B.oR.error(e instanceof Error?e.message:y("toasts.failedToCreate"))}finally{k(!1)}}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(V.rI,{open:w,onOpenChange:j,children:[(0,i.jsx)(V.ty,{asChild:!0,children:(0,i.jsxs)(D.$,{variant:"outline",className:(0,m.cn)("justify-between",T?"w-[130px] min-w-0 px-2":"min-w-[150px]"),disabled:f||!!g,children:[(0,i.jsx)("span",{className:"truncate",children:f?"Loading...":g?"Error loading groups":null===n?b("allAccounts"):null!=(a=null==(t=h.find(e=>e.id===n))?void 0:t.name)?a:b(T?"group":"selectGroupPlaceholder")}),(0,i.jsx)(U.A,{className:"h-4 w-4 shrink-0 opacity-50"})]})}),(0,i.jsxs)(V.SQ,{align:"end",side:"top",className:"w-[var(--radix-dropdown-menu-trigger-width)] min-w-0 bg-card dark:bg-card",children:[(0,i.jsx)(V._2,{onSelect:()=>r(null),disabled:f||!!g,children:b("allAccounts")}),(0,i.jsx)(V.mB,{}),!f&&!g&&0===h.length&&(0,i.jsx)(V._2,{disabled:!0,children:"No groups foun
1d"}),!f&&!g&&h.map(e=>(0,i.jsx)(V._2,{onSelect:()=>r(e.id),children:(0,i.jsx)("span",{className:"truncate",children:e.name})},e.id)),(0,i.jsx)("div",{className:"pt-2 mt-2",children:(0,i.jsx)(V._2,{asChild:!0,className:"p-0",onSelect:()=>{j(!1),N(!0)},children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",className:"w-full justify-center font-medium !bg-transparent !text-sm",children:[(0,i.jsx)(_.A,{className:"size-3.5 shrink-0"}),(0,i.jsx)("span",{className:"truncate",children:y("createGroup")})]})})})]})]}),(0,i.jsx)(G.Y,{isOpen:C,onOpenChange:e=>{S||N(e)},accounts:l,onSubmit:E,isLoading:S})]})}var Y=a(61814),X=a(12688);function Z(e){let{filteredAccounts:t,selectedAccounts:a,toggleAccountSelection:r,selectedGroup:l,onGroupSelect:s,availableAccounts:d,onGroupCreated:c,preloadedSocialGroups:u,captionSyncEnabled:m,onCaptionSyncChange:h,onClose:p}=e,f=(0,o.useTranslations)("CreatePost.captionSync"),x=(0,o.useTranslations)("CreatePost.header");return(0,i.jsx)("div",{className:"relative rounded-t-[inherit] px-3 pb-3 pt-[max(0.75rem,env(safe-area-inset-top))] before:pointer-events-none before:absolute before:inset-x-0 before:-top-2 before:bottom-0 before:rounded-t-[inherit] before:bg-background/60 before:backdrop-blur-xl before:content-[''] md:py-3",children:(0,i.jsxs)("div",{className:"relative z-10 grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-2 gap-y-2 md:flex md:gap-4",children:[(0,i.jsxs)("div",{className:"flex min-w-0 items-center md:hidden",children:[(0,i.jsx)(D.$,{type:"button",variant:"ghost",size:"icon",onClick:p,"aria-label":x("title"),className:"-ml-2 h-8 w-8 shrink-0",children:(0,i.jsx)(Y.A,{className:"h-5 w-5"})}),(0,i.jsx)(n.L3,{className:"min-w-0 truncate text-left text-sm font-semibold",children:x("title")})]}),(0,i.jsx)("div",{className:"order-3 col-span-2 min-w-0 md:order-none md:flex-1",children:(0,i.jsx)(L,{filteredAccounts:t,selectedAccounts:a,toggleAccountSelection:r,selectedGroup:l,onShowAllAccounts:null!=l?()=>s(null):void 0})}),(0,i.jsxs)("div",{className:"order-2 ml-auto flex min-w-0 items-center gap-2 md:order-none md:shrink-0",children:[(0,i.jsx)($,{selectedGroup:l,onGroupSelect:s,availableAccounts:d,onGroupCreated:c,preloadedSocialGroups:u}),(0,i.jsx)(O.TooltipProvider,{children:(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(D.$,{type:"button",variant:"outline",size:"icon",onClick:()=>h(!m),"aria-label":f(m?"activeLabel":"label"),"aria-pressed":m,className:m?"flex-shrink-0 border-primary/40 bg-primary/10 text-primary hover:bg-primary/15 hover:text-primary":"flex-shrink-0",children:(0,i.jsx)(X.A,{className:m?"h-4 w-4 text-green-600 dark:text-green-400":"h-4 w-4"})})}),(0,i.jsx)(O.TooltipContent,{side:"bottom",children:(0,i.jsx)("p",{children:f(m?"activeLabel":"label")})})]})})]})]})})}var J=a(3100),Q=a(7120),ee=a(76080),et=a(95609),ea=a(20836),ei=a(20362);function en(e){let{isLoading:t,publishAction:a,onActionSelect:n,onFinalAction:r,getButtonLabel:l,isActionDisabled:s,fixedAction:c=!1,recurrenceEnabled:u=!1}=e,h=(0,o.useTranslations)("CreatePost.actions"),{canCreatePost:p,planTier:f,trialEligible:x,subscriptionOwnership:g,isLoading:v}=(0,et.Q)(),[b,y]=(0,d.useState)(!1),[w,j]=(0,d.useState)(!1),C=(0,d.useRef)(null);(0,d.useEffect)(()=>{if(w&&!v&&C.current){j(!1);let e=C.current;C.current=null,p?n(e):y(!0)}},[w,v,p,n]);let N=(0,d.useCallback)(async e=>{if(!t)if("schedule"===e||"publish"===e){if(v){C.current=e,j(!0);return}if(!p)return void y(!0);n(e)}else n(e)},[n,p,t,v]),S=(0,d.useCallback)(async()=>{t||await r()},[r,t]);return(0,i.jsxs)(i.Fragment,{children:[w&&(0,i.jsx)(ei.W,{withBlur:!0}),(0,i.jsxs)("div",{className:"brand-gradient-outline flex items-center gap-0 rounded-md","data-gradient-available":!t&&!s,children:[(0,i.jsx)(D.$,{onClick:S,disabled:t||s,variant:"ghost",className:c?void 0:"rounded-r-none",children:t?h("processing"):l()}),c?null:(0,i.jsxs)(V.rI,{children:[(0,i.jsx)(V.ty,{asChild:!0,children:(0,i.jsxs)(D.$,{size:"icon",variant:"ghost",className:(0,m.cn)("rounded-l-none border-l border-border/50 p-0"),disabled:t,children:[(0,i.jsx)(ee.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"sr-only",children:h("publishOptions")})]})}),(0,i.jsxs)(V.SQ,{align:"end",children:[(0,i.jsx)(V._2,{onSelect:()=>N("publish"),disabled:t||"publish"===a,children:h("publishNow")}),(0,i.jsx)(V._2,{onSelect:()=>N("schedule"),disabled:t||"schedule"===a,children:h("schedule")}),(0,i.jsx)(V._2,{onSelect:()=>N("draft"),disabled:t||"draft"===a,children:h("saveDraft")}),u?(0,i.jsx)("p",{className:"max-w-64 px-2 py-2 text-xs text-muted-foreground",children:h("recurringSingleActionNotice")}):null]})]})]}),(0,i.jsx)(ea.PricingDialog,{open:b,onOpenChange:y,currentPlanT
1ier:f,context:"scheduled-posts",trialEligible:x,subscriptionOwnership:g})]})}var er=a(53580),el=a(75468),es=a(18947),eo=a(64435),ed=a(36322),ec=a(72488),eu=a(77247),em=a(7505),eh=a(44003),ep=a(47051),ef=a(48122),ex=a(94985),eg=a(52888),ev=a(89017);function eb(e){let{value:t,inline:a=!1,minDate:n,label:r,onChange:l}=e,[s,c]=(0,d.useState)(!1),u=(0,o.useLocale)().toLowerCase().startsWith("es"),h=u?ep.es:ef.c,p=t?(0,er.H)(t):void 0,f=p&&(0,el.f)(p)?p:void 0,x=(0,eu.o)(n);return(0,i.jsxs)(ev.AM,{open:s,onOpenChange:c,children:[(0,i.jsx)(ev.Wv,{asChild:!0,children:(0,i.jsxs)(D.$,{variant:"outline",className:(0,m.cn)("w-full justify-start gap-2 bg-transparent font-normal",a&&"h-full w-auto shrink-0 rounded-l-none border-0 border-l border-input px-2 focus-visible:ring-0"),"aria-label":r,children:[a?null:(0,i.jsx)(ex.A,{className:"h-4 w-4 shrink-0"}),f?(0,em.GP)(f,a?u?"d MMM yyyy":"MMM d, yyyy":"PPP",{locale:h}):r]})}),(0,i.jsx)(ev.hl,{align:"start",className:"z-[90] w-auto p-0",children:(0,i.jsx)(eg.V,{mode:"single",locale:h,weekStartsOn:1,selected:f,defaultMonth:null!=f?f:x,fromMonth:(0,eh.w)(x),disabled:{before:x},onSelect:e=>{e&&(l((0,em.GP)(e,"yyyy-MM-dd")),c(!1))},initialFocus:!0})})]})}var ey=a(79536),ew=a(72374),ej=a(5898),eC=a(75727),eN=a(66442),eS=a(35223),ek=a(34190),eT=a(99889);let eE=Array.from({length:60},(e,t)=>t);function eI(e){let{value:t,onChange:a,preloadedTimeSlots:n,inline:r=!1}=e,{timeSlots:l=[]}=(0,eS.m)(),s=null!=n?n:l,{workspaceTimezone:c,isLoading:u}=(0,ek.C)(),p=(0,o.useLocale)(),f=(0,o.useTranslations)("RecurringPosts.schedule"),[x,g]=(0,d.useState)([]),[v,b]=(0,d.useState)(null),[y,w]=(0,d.useState)(!1),j=(0,d.useRef)(!1);(0,d.useEffect)(()=>{j.current=y},[y]);let C=(0,d.useMemo)(()=>t?new Date(t):null,[t]),N=(0,d.useMemo)(()=>{if(!C)return null;let e=(null==c?void 0:c.country)||Intl.DateTimeFormat().resolvedOptions().timeZone;return h.FL.getWorkspaceDateParts(C,e)},[C,null==c?void 0:c.country]),S="es"===p?ep.es:ef.c,[k,T]=(0,d.useState)(null),E=(0,d.useRef)({}),I=(0,d.useRef)({}),A=(0,eh.w)(new Date),P=new Date;P.setMonth(P.getMonth()+10);let M=(0,eh.w)(P);(0,d.useEffect)(()=>{let e=()=>{u||b((()=>{let e=new Date;if(!(null==c?void 0:c.country))return e;let t=h.FL.getDynamicUtcOffset(c.country);return new Date(e.getTime()+6e4*e.getTimezoneOffset()+36e5*t)})())};e();let t=setInterval(e,6e4);return()=>clearInterval(t)},[null==c?void 0:c.country,u]),(0,d.useEffect)(()=>()=>{j.current&&w(!1)},[]);let R=(e,t,a)=>{if(!C||!v||!(0,eN.r)(a,v))return!1;let i=new Date(v);return i.setHours(e,t,0,0),i<=v};(0,d.useEffect)(()=>{var e;s&&s.length>0&&(null==(e=s[0])?void 0:e.hours)&&g(s[0].hours.map(e=>{let[t,a]=e.split(":");return{hour:parseInt(t,10),minute:parseInt(a,10)}}).sort((e,t)=>e.hour===t.hour?e.minute-t.minute:e.hour-t.hour).filter((e,t,a)=>t===a.findIndex(t=>t.hour===e.hour&&t.minute===e.minute)))},[s]);let F=(0,d.useCallback)(e=>{e?T(x.find(t=>t.hour===e.hours&&t.minute===e.minutes)||null):T(null)},[x,T]);function O(e,t){let i,n,r,l,s;if(C&&N)i=N.year,n=N.month,r=N.day,l=N.hours,s=N.minutes;else{let e=v||new Date;i=e.getFullYear(),n=e.getMonth(),r=e.getDate(),l=e.getHours(),s=e.getMinutes()}"hour"===e?l=parseInt(t,10):"minute"===e&&(s=parseInt(t,10));let o=(null==c?void 0:c.country)||Intl.DateTimeFormat().resolvedOptions().timeZone;a(h.FL.createDateFromWorkspaceTime(i,n,r,l,s,o))}(0,d.useEffect)(()=>{F(N)},[N,F]),(0,d.useEffect)(()=>{let e=null==N?void 0:N.hours,t=null==N?void 0:N.minutes;setTimeout(()=>{if(void 0!==e){let t=E.current[e];null==t||t.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}if(void 0!==t){let e=I.current[t];null==e||e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},0)},[N]);let z=Array.from({length:24},(e,t)=>t),L=(0,d.useCallback)(e=>{w(e),j.current=e},[]),U=(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("div",{className:"border-b p-3",children:(null==c?void 0:c.country)?(0,i.jsxs)("div",{className:"text-xs space-y-1",children:[(0,i.jsxs)("div",{children:[c.country," (UTC",(()=>{let e=h.FL.getDynamicUtcOffset(c.country);return"".concat(e>=0?"+":"").concat(e)})(),")"]}),(0,i.jsx)("div",{className:"text-muted-foreground",children:v?(0,i.jsx)(i.Fragment,{children:f("currentTime",{time:(0,em.GP)(v,"HH:mm")}
1)}):(0,i.jsx)(i.Fragment,{children:f("loadingCurrentTime")})})]}):u?(0,i.jsx)("div",{className:"text-sm text-muted-foreground",children:f("loadingTimezone")}):(0,i.jsx)("div",{className:"text-sm text-muted-foreground",children:"No country timezone selected in settings, browser location timezone will be used as default"})}),(0,i.jsxs)("div",{className:"flex",children:[(0,i.jsx)(eg.V,{mode:"single",className:"h-full",selected:null!=C?C:void 0,onSelect:function(e){if(!e){a(null),T(null);return}let t=N?N.hours:v?v.getHours():0,i=N?N.minutes:v?v.getMinutes():0,n=(null==c?void 0:c.country)||Intl.DateTimeFormat().resolvedOptions().timeZone;a(h.FL.createDateFromWorkspaceTime(e.getFullYear(),e.getMonth(),e.getDate(),t,i,n))},disabled:e=>{if(!v)return!1;let t=new Date(v);return t.setHours(0,0,0,0),e<t},fromMonth:A,weekStartsOn:1,toMonth:M,locale:S}),(0,i.jsxs)("div",{className:"flex shrink-0 flex-row divide-x border-l",children:[(0,i.jsxs)(eT.F,{className:"h-[325px] w-12 shrink-0 py-2",children:[(0,i.jsx)("div",{className:"flex flex-col p-2",children:z.map(e=>{let t=!!C&&R(e,C.getUTCMinutes(),C);return(0,i.jsx)(D.$,{ref:t=>{E.current[e]=t},size:"icon",variant:(null==N?void 0:N.hours)===e?"default":"ghost",className:(0,m.cn)("aspect-square h-8 w-8 shrink-0 text-xs",t&&"cursor-not-allowed opacity-50"),disabled:t,onClick:()=>O("hour",e.toString()),children:e.toString().padStart(2,"0")},"hour-".concat(e))})}),(0,i.jsx)(eT.$,{orientation:"horizontal",className:"sm:hidden"})]}),(0,i.jsxs)(eT.F,{className:"h-[325px] w-12 shrink-0 py-2",children:[(0,i.jsx)("div",{className:"flex flex-col p-2",children:eE.map(e=>{let t=!!C&&!!N&&R(N.hours,e,C);return(0,i.jsx)(D.$,{ref:t=>{I.current[e]=t},size:"icon",variant:(null==N?void 0:N.minutes)===e?"default":"ghost",className:(0,m.cn)("aspect-square h-8 w-8 shrink-0 text-xs",t&&"cursor-not-allowed opacity-50"),disabled:t,onClick:()=>O("minute",e.toString()),children:e.toString().padStart(2,"0")},"minute-".concat(e))})}),(0,i.jsx)(eT.$,{orientation:"horizontal",className:"sm:hidden"})]})]})]}),x.length>0?(0,i.jsx)("div",{className:"border-t px-1",children:(0,i.jsx)("div",{className:"flex items-center gap-2 overflow-x-auto rounded-sm px-1 py-2",children:x.map(e=>{let t=!!C&&!!N&&R(e.hour,e.minute,C);return(0,i.jsx)(D.$,{variant:(null==k?void 0:k.hour)===e.hour&&(null==k?void 0:k.minute)===e.minute?"default":"outline",size:"sm",disabled:t,onClick:()=>(function(e){let t,i,n,r=(null==c?void 0:c.country)||Intl.DateTimeFormat().resolvedOptions().timeZone;if(C&&N)t=N.year,i=N.month,n=N.day;else{let e=v||new Date;t=e.getFullYear(),i=e.getMonth(),n=e.getDate()}a(h.FL.createDateFromWorkspaceTime(t,i,n,e.hour,e.minute,r)),T(e)})(e),className:(0,m.cn)("text-xs",t&&"cursor-not-allowed opacity-50"),children:"".concat(e.hour.toString().padStart(2,"0"),":").concat(e.minute.toString().padStart(2,"0"))},"pref-".concat(e.hour,"-").concat(e.minute))})})}):null]});return r?(0,i.jsx)("div",{className:"w-full overflow-x-auto rounded-md border",children:U}):(0,i.jsxs)(ev.AM,{modal:!1,open:y,onOpenChange:L,children:[(0,i.jsx)(ev.Wv,{asChild:!0,children:(0,i.jsxs)(D.$,{variant:"outline",className:(0,m.cn)("flex h-8 w-[124px] items-center gap-2 whitespace-nowrap px-2 text-left font-normal",!C&&"text-muted-foreground"),children:[C&&N?"".concat((0,em.GP)(C,"dd/MM")," ").concat(N.hours.toString().padStart(2,"0"),":").concat(N.minutes.toString().padStart(2,"0")):C?(0,em.GP)(C,"dd/MM HH:mm"):(0,i.jsx)("span",{children:"Pick date"}),(0,i.jsx)(eC.O4,{className:"ml-auto h-4 w-4 opacity-50"})]})}),(0,i.jsx)(ev.hl,{className:"pointer-events-auto z-[60] w-[350px] p-0",onOpenAutoFocus:e=>e.preventDefault(),children:U})]})}var eA=a(87546);let eP=[{value:1,key:"monday"},{value:2,key:"tuesday"},{value:3,key:"wednesday"},{value:4,key:"thursday"},{value:5,key:"friday"},{value:6,key:"saturday"},{value:0,key:"sunday"}],eM=eP.map(e=>e.value);function eD(e,t){return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(new Intl.DateTimeFormat("en-US",{timeZone:t,weekday:"short"}).format(e))}function eR(e){var t,a;
1let{scheduleFor:n,onScheduleChange:r,recurrence:l,onRecurrenceChange:s,timezone:c,preloadedTimeSlots:u,disabled:m=!1,repeatReadOnlyLabel:p,recurrenceRequired:f=!1}=e,x=(0,o.useTranslations)("RecurringPosts.schedule"),g=(0,o.useLocale)(),[v,b]=(0,d.useState)(!1),[y,w]=(0,d.useState)("datetime"),j=(0,d.useMemo)(()=>(function(e){if((0,h.bd)(e))return e;let t=Intl.DateTimeFormat().resolvedOptions().timeZone;return(0,h.bd)(t)?t:"UTC"})(c),[c]),C=(0,d.useMemo)(()=>(0,h.OG)(n),[n]),N=(0,d.useMemo)(()=>null!=C?C:new Date(Date.now()+36e5),[C]),S=(0,d.useMemo)(()=>null!=l?l:{...eA.lU,weekdays:[eD(N,j)]},[N,l,j]),k=e=>s({...S,...e}),T=(0,d.useMemo)(()=>(0,eA.Q8)({...S,startsAt:N,timezone:j},3),[N,S,j]),E=C?new Intl.DateTimeFormat(g,{timeZone:j,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(C):x("pickDate"),I=C?new Intl.DateTimeFormat(g,{timeZone:j,month:"short",day:"numeric"}).format(C):null,A=C?new Intl.DateTimeFormat(g,{timeZone:j,hour:"numeric",minute:"2-digit"}).format(C):null,P=null!=p?p:l&&C?(0,eA.Rr)({...l,startsAt:C,timezone:j},g):E,M=e=>new Intl.DateTimeFormat(g,{timeZone:j,month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}).format(e),R=(0,eA.Rr)({...S,startsAt:N,timezone:j},g),F=S.endDate?(0,er.H)(S.endDate):null,O="ON_DATE"===S.endType&&F&&(0,el.f)(F)?x("summaryUntil",{cadence:R,date:new Intl.DateTimeFormat(g,{month:"short",day:"numeric",year:"numeric"}).format(F)}):"AFTER_OCCURRENCES"===S.endType?x("summaryCount",{cadence:R,count:null!=(t=S.occurrenceCount)?t:10}):x("summaryNever",{cadence:R});return(0,i.jsxs)(ev.AM,{open:v,onOpenChange:b,children:[(0,i.jsx)(ev.Wv,{asChild:!0,children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",disabled:m,title:P,"aria-label":E,className:"h-8 max-w-[180px] gap-1.5 px-2 sm:gap-2 sm:px-3",children:[l||p?(0,i.jsx)(es.A,{className:"h-4 w-4 shrink-0 text-primary"}):(0,i.jsx)(eo.A,{className:"h-4 w-4 shrink-0"}),C?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("span",{"aria-hidden":"true",className:"flex min-w-0 flex-col text-left text-[10px] leading-3 sm:hidden",children:[(0,i.jsx)("span",{className:"truncate",children:I}),(0,i.jsx)("span",{className:"truncate",children:A})]}),(0,i.jsx)("span",{"aria-hidden":"true",className:"hidden truncate sm:inline",children:E})]}):(0,i.jsx)("span",{className:"truncate",children:E})]})}),(0,i.jsx)(ev.hl,{align:"end",side:"top",className:"z-[70] w-[380px] max-w-[calc(100vw-2rem)] p-3",children:(0,i.jsxs)(ej.tU,{value:y,onValueChange:w,children:[(0,i.jsxs)(ej.j7,{className:"grid w-full grid-cols-2",children:[(0,i.jsx)(ej.Xi,{value:"datetime",children:x("dateTime")}),(0,i.jsx)(ej.Xi,{value:"repeat",children:x("repeat")})]}),(0,i.jsxs)(ej.av,{value:"datetime",className:"mt-4 h-[440px] max-h-[calc(100vh-8rem)] space-y-3 overflow-hidden",children:[p?(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:x("nextRunHelp")}):null,(0,i.jsx)(eI,{value:C,onChange:r,preloadedTimeSlots:u,inline:!0})]}),(0,i.jsx)(ej.av,{value:"repeat",className:"mt-4 h-[440px] max-h-[calc(100vh-8rem)] space-y-3 overflow-y-auto [&_.border-r]:w-16",children:p?(0,i.jsxs)("div",{className:"rounded-md border p-3",children:[(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:x("repeatReadOnly")}),(0,i.jsx)("p",{className:"mt-1 text-sm font-medium",children:p})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"flex items-center justify-between rounded-md border p-3",children:[(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"text-sm font-medium",children:x("repeatThisPost")}),l?null:(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:x("selectedDateHelp")})]}),(0,i.jsx)(ed.d,{checked:!!l,disabled:f,"aria-label":x("repeatThisPost"),onCheckedChange:e=>s(e?S:null)})]}),l?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"flex items-start justify-between gap-2 rounded-md border border-input p-3",children:[(0,i.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:x("firstRun")}),(0,i.jsx)("p",{className:"text-sm",children:C?M(C):x("pickDate")}),(0,i.jsx)("p",{className:"break-words text-xs text-muted-foreground",children:j})]}),(0,i.jsx)(D.$,{variant:"ghost",size:"xs",onClick:()=>w("datetime"),children:x("editFirstRun")})]}),(0,i.jsxs)("div",{className:"flex h-8 items-center gap-2 rounded-md border border-input pl-3",children:[(0,i.jsx)(ec.m,{children:x("every")}),(0,i.jsxs)("div",{className:"flex h-full min-w-0 flex-1 items-center",children:[(0,i.jsxs)(ew.Select,{value:String(S.interval),onValueChange:e=>k({interval:Number(e)}),children:[(0,i.jsx)(ew.SelectTrigger,{"aria-label":x("repeatEvery"),className:"h-full w-20 shrink-0 rounded-none border-0 bg-transparent px-2 focus:ring-0 focus-visible:ring-0",children:(0,i.jsx)(ew.SelectValue,{})}),(0,i.jsx)(ew.SelectContent,{className:"z-[80] [&_[role=option]]:text-sm",children:Array.from({length:365},(e,t)=>t+1).map(e=>(0,i.jsx)(ew.SelectItem,{value:String(e),children:e},e))})]}),(0,i.jsxs)(ew.Select,{value:S.frequency,onValueChange:e=>k({frequency:e,weekdays:"WEEKLY"===e&&0===S.weekdays.length?[eD(N,j)]:S.weekdays}),children:[(0,i.jsx)(ew.SelectTrigger,{className:"h-full min-w-0 flex-1 border-0 border-l border-input rounded-l-none bg-transparent shadow-none focus:ring-0 focus-visible:ring-0","aria-label":x("frequency"),children:(0,i.jsx)(ew.SelectValue,{})}),(0,i.jsxs)(ew.SelectContent,{className:"z-[80] [&_[role=option]]:text-sm",children:[(0,i.jsx)(ew.SelectItem,{value:"DAILY",children:x("days",{count:S.interval})}),(0,i.jsx)(ew.SelectItem,{value:"WEEKLY",children:x("weeks",{count:S.interval})}),(0,i.jsx)(ew.SelectItem,{value:"MONTHLY",children:x("months",{count:S.interval})})]})]})]})]}),"WEEKLY"===S.frequency?(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsx)(ey.J,{children:x("onDays")}),(0,i.jsx)("div",{className:"flex justify-between gap-1",children:eP.map(e=>(0,i.jsx)(D.$,{type:"button",variant:"outline",size:"icon",className:"h-8 min-w-0 flex-1 rounded-md bg-transparent px-0 text-xs aria-pressed:border-foreground aria-pressed:font-semibold",onClick:()=>(e=>{let t=S.weekdays.includes(e)?S.weekdays.filter(t=>t!==e):[...S.weekdays,e].sort((e,t)=>
1eM.indexOf(e)-eM.indexOf(t));t.length>0&&k({weekdays:t})})(e.value),"aria-label":x("weekdays.".concat(e.key,".long")),"aria-pressed":S.weekdays.includes(e.value),children:x("weekdays.".concat(e.key,".short"))},e.value))})]}):null,(0,i.jsxs)("div",{className:"flex h-8 items-center gap-2 rounded-md border border-input pl-3",children:[(0,i.jsx)(ec.m,{children:x("ends")}),(0,i.jsxs)("div",{className:"flex h-full min-w-0 flex-1 items-center",children:[(0,i.jsxs)(ew.Select,{value:S.endType,onValueChange:e=>{var t;return k({endType:e,occurrenceCount:"AFTER_OCCURRENCES"===e?null!=(t=S.occurrenceCount)?t:10:S.occurrenceCount})},children:[(0,i.jsx)(ew.SelectTrigger,{className:"h-full min-w-0 flex-1 border-0 bg-transparent px-2 focus:ring-0 focus-visible:ring-0","aria-label":x("ends"),children:(0,i.jsx)(ew.SelectValue,{children:"AFTER_OCCURRENCES"===S.endType?x("afterPostsShort"):"ON_DATE"===S.endType?x("onDate"):x("never")})}),(0,i.jsxs)(ew.SelectContent,{className:"[&_[role=option]]:text-sm z-[80]",children:[(0,i.jsx)(ew.SelectItem,{value:"NEVER",children:x("never")}),(0,i.jsx)(ew.SelectItem,{value:"ON_DATE",children:x("onDate")}),(0,i.jsx)(ew.SelectItem,{value:"AFTER_OCCURRENCES",children:x("afterPosts")})]})]}),"ON_DATE"===S.endType?(0,i.jsx)(eb,{inline:!0,value:S.endDate,minDate:N,label:x("onDate"),onChange:e=>k({endDate:e})}):null,"AFTER_OCCURRENCES"===S.endType?(0,i.jsxs)(ew.Select,{value:String(null!=(a=S.occurrenceCount)?a:10),onValueChange:e=>k({occurrenceCount:Number(e)}),children:[(0,i.jsx)(ew.SelectTrigger,{"aria-label":x("afterPosts"),className:"h-full w-20 shrink-0 rounded-l-none border-0 border-l border-input bg-transparent px-2 focus:ring-0 focus-visible:ring-0",children:(0,i.jsx)(ew.SelectValue,{})}),(0,i.jsx)(ew.SelectContent,{className:"z-[80] [&_[role=option]]:text-sm",children:Array.from({length:499},(e,t)=>t+2).map(e=>(0,i.jsx)(ew.SelectItem,{value:String(e),children:e},e))})]}):null]})]}),(0,i.jsxs)("div",{className:"space-y-3 rounded-md border border-input p-3","aria-live":"polite",children:[(0,i.jsx)("p",{className:"text-sm leading-relaxed",children:T.length>0&&C?O:x("invalid")}),T.length>0&&C?(0,i.jsxs)("div",{className:"space-y-1.5",children:[(0,i.jsx)("p",{className:"text-xs font-medium text-muted-foreground",children:x("nextPosts")}),(0,i.jsx)("ul",{className:"space-y-1 text-xs text-muted-foreground",children:T.map(e=>(0,i.jsx)("li",{children:M(e)},e.toISOString()))})]}):null]})]}):null]})})]})})]})}function eF(e){let{scheduleFor:t,onScheduleChange:a,preloadedTimeSlots:n,recurrence:r,onRecurrenceChange:l,timezone:s,disabled:o,repeatReadOnlyLabel:d,recurrenceRequired:c}=e;return(0,i.jsx)("div",{className:"flex items-center",children:(0,i.jsx)(eR,{scheduleFor:t,onScheduleChange:a,preloadedTimeSlots:n,recurrence:r,onRecurrenceChange:l,timezone:s,disabled:o,repeatReadOnlyLabel:d,recurrenceRequired:c})})}function eO(e,t,a,i){if(!(null==e?void 0:e.translate))return a;try{return e.translate(t,i)}catch(e){return a}}var ez=a(77712),eL=a(4531);function eU(e,t,a){let i="".concat(e,"-").concat(t,"-").concat(a||"global"),n=0;for(let e=0;e<i.length;e++)n=(n<<5)-n+i.charCodeAt(e),n&=n;return Math.abs(n).toString(36)}function e_(e,t){return{description:"Facebook videos must be between ".concat(e," and ").concat(t," seconds"),check:(a,i,n)=>a.flatMap((a,i)=>{var r;if(!(null==(r=a.type)?void 0:r.startsWith("video/"))||void 0===a.duration||a.duration>=e&&a.duration<=t)return[];let l=eO(n,"restrictions.facebookVideoDurationRange","Video ".concat(i+1," must be between ").concat(e," and ").concat(t," seconds (current: ").concat(a.duration,"s)."),{index:i+1,min:e,max:t,duration:a.duration});return[{id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.FACEBOOK}]})}}function eB(e,t){return{description:"Facebook media file size limit",check:(a,i,n)=>a.flatMap((a,i)=>{var r,l,s,o;let d=null==(r=a.type)?void 0:r.startsWith("video/"),u=d?t:(null==(l=a.type)?void 0:l.startsWith("image/"))?e:null;if(null===u||void 0===a.fileSize||Number(a.fileSize)<=1024*u*1024)return[];let h=(0,m.s8)(Number(a.fileSize)/1048576),p=d?null==n||null==(s=n.videoFileSizeExceeded)?void 0:s.call(n,{index:i+1,maxSize:"".concat(u,"MB"),currentSize:h}):null==n||null==(o=n.imageFileSizeExceeded)?void 0:o.call(n,{index:i+1,maxSize:"".concat(u,"MB"),currentSize:h}),f="".concat(d?"Video":"Image"," ").concat(i+1," exceeds ").concat(u,"MB limit (").concat(h,").");return[{id:eU("media",p||f),field:"media",message:p||f,type:"error",severity:"blocking",platform:c.SocialPlatform.FACEBOOK}]})}}class eK{async getCreatorInfo(e){let t=this.cache.get(e),a=Date.now();if(t){let e=a-t.timestamp;if(t.hasPostingCapError?e<this.POSTING_CAP_CHECK_INTERVAL:e<this.CACHE_DURATION)return t}try{var i,n,r,l,s,o;let d=await fetch("/api/queries/tiktok/creator-info?accountId=".concat(encodeURIComponent(e)),{method:"GET",headers:{"Content-Type":"application/json"}});if(!d.ok)throw Error("API request failed: ".concat(d.status));let c=await d.json();if(!c.success&&c.isPostingCapError){let l={maxDurationSec:(null==t?void 0:t.maxDurationSec)||600,maxDurationMinutes:(null==t?void 0:t.maxDurationMinutes)||10,privacyLevelOptions:(null==t?void 0:t.privacyLevelOptions)||[],defaultAllowComment:null==(i=null==t?void 0:t.defaultAllowComment)||i,defaultAllowDuet:null==(n=null==t?void 0:t.defaultAllowDuet)||n,defaultAllowStitch:null==(r=null==t?void 0:t.defaultAllowStitch)||r,username:null==t?void 0:t.username,nickname:null==t?void 0:t.nickname,avatarUrl:null==t?void 0:t.avatarUrl,hasPostingCapError:!0,postingCapErrorCode:c.errorCode,postingCapErrorMessage:c.error,timestamp:a};return this.cache.set(e,l),l}if(!c.success||!c.data)throw Error("API request failed: ".concat(c.error||"No data received"));let u=c.data,m={maxDurationSec:u.maxVideoDurationSec||600,maxDurationMinutes:u.maxDurationMinutes||10,privacyLevelOptions:u.privacyLevelOptions||[],defaultAllowComment:null==(l=u.defaultAllowComment)||l,defaultAllowDuet:null==(s=u.defaultAllowDuet)||s,defaultAllowStitch:null==(o=u.defaultAllowStitch)||o,username:u.username,nickname:u.nickname,avatarUrl:u.avatarUrl,hasPostingCapError:!1,timestamp:a};return this.cache.set(e,m),m}catch(e){if(console.warn("[TikTok Validation Cache] Failed to fetch creator info:",e),t)return t;return null}}async getMaxVideoDuration(e){let t=await this.getCreatorInfo(e);return(null==t?void 0:t.maxDurationSec)||null}clearCache(e){e?this.cache.delete(e):this.cache.clear()}constructor(){this.cache=new Map,this.CACHE_DURATION=3e5,this.PO
1STING_CAP_CHECK_INTERVAL=6e4}}let eG=new eK,eW={"facebook-feed-media-size":eB(30,500),"facebook-reel-video-size":eB(null,500),"facebook-story-video-size":eB(30,100),"facebook-story-video-duration":e_(3,60),"facebook-feed-video-duration":e_(1,900),"facebook-reel-video-duration":e_(3,900),"no-mixed-media":{description:"Cannot mix images and videos in the same post",check:(e,t,a)=>{let i=e.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("image/")}),n=e.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")});if(i&&n){let e=eO(a,"restrictions.noMixedMediaFacebook","Facebook does not support mixing images and videos in the same post. Please create separate posts.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.FACEBOOK}]}return[]}},"single-video-max":{description:"Maximum 1 video per post",check:(e,t,a)=>{if(e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}).length>1){let e=eO(a,"restrictions.singleVideoMaxFacebook","Facebook feed posts support only one video per post.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.FACEBOOK}]}return[]}},"video-only":{description:"Only video content allowed",check:(e,t,a)=>{if(e.filter(e=>{var t;return!(null==(t=e.type)?void 0:t.startsWith("video/"))}).length>0){let e=eO(a,"restrictions.videoOnly","This post type only supports video content.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"}]}return[]}},"image-only":{description:"Only image content allowed",check:(e,t,a)=>{if(e.filter(e=>{var t;return!(null==(t=e.type)?void 0:t.startsWith("image/"))}).length>0){let e=eO(a,"restrictions.imageOnly","This post type only supports image content.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"}]}return[]}},"instagram-standalone-video-specs":{description:"Meta Reel specifications for standalone Instagram videos",check:(e,t,a)=>e.flatMap((e,t)=>{var i;return(null==(i=e.type)?void 0:i.startsWith("video/"))?(0,eL.n)(e).map(e=>{let i=eO(a,"restrictions.instagramStandaloneVideo.".concat(e.code),e.message,{index:t+1});return{id:eU("media",i),field:"media",message:i,type:e.severity,severity:"error"===e.severity?"blocking":"non-blocking"}}):[]})},"duration-max-60s":{description:"Video duration must be 60 seconds or less",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration&&e.duration>60){let n=eO(a,"restrictions.videoDurationMax60s","Video ".concat(t+1," duration must be 60 seconds or less (current: ").concat(e.duration,"s)."),{index:t+1,duration:e.duration});i.push({id:eU("media",n),field:"media",message:n,type:"error",severity:"blocking"})}}),i}},"facebook-story-duration-max-60s":{description:"Facebook Story video duration must be 60 seconds or less",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration&&e.duration>60){let t=eO(a,"restrictions.facebookStoryDurationMax60s","Facebook Story video duration must be 60 seconds or less (current: ".concat(e.duration,"s)."),{duration:e.duration});i.push({id:eU("media",t),field:"media",message:t,type:"error",severity:"blocking"})}}),i}},"instagram-story-duration-max-60s":{description:"Instagram Story video duration must be 60 seconds or less",check:(e,t,a)=>{let i=[];return e.forEach(e=>{var t;if((null==(t=e.type)?void 0:t.startsWith("video/"))&&void 0!==e.duration&&e.duration>60){let t=eO(a,"restrictions.instagramStoryDurationMax60s","Instagram Story video duration must be 60 seconds or less (current: ".concat(e.duration,"s)."),{duration:e.duration});i.push({id:eU("media",t),field:"media",message:t,type:"error",severity:"blocking"})}}),i}},"mixed-media-special":{description:"TikTok special rule: 35 images OR 1 video",check:(e,t,a)=>{let i=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}),n=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("image/")});if(i.length>0&&n.length>0){let e=eO(a,"restrictions.tiktokNoMixedMedia","TikTok posts can have either multiple images OR one video, not both.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"}]}if(i.length>1){let e=eO(a,"restrictions.tiktokMaxOneVideo","TikTok allows maximum 1 video per post.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"}]}if(n.length>35){let e=eO(a,"restrictions.tiktokMaxImages","TikTok allows maximum 35 images per post.");return[{id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"}]}return[]}},"vertical-required":{description:"Content must be vertical (9:16 aspect ratio)",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(void 0!==e.aspectRatio&&e.aspectRatio>.8){let e=eO(a,"restrictions.verticalRequired","Media ".concat(t+1," must be vertical (9:16 ratio) for this post type."),{index:t+1});i.push({id:eU("media",e),field:"media",message:e,type:"error",severity:"blocking"})}}),i}},"vertical-preferred":{description:"Vertical content performs better",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(void 0!==e.aspectRatio&&e.aspectRatio>.8){let e=eO(a,"restrictions.verticalPreferred","Media ".concat(t+1," would perform better in vertical format (9:16 ratio)."),{index:t+1});i.push({id:eU("media",e),field:"media",message:e,type:"warning",severity:"non-blocking"})}}),i}},"square-preferred":{description:"Square content performs better",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(void 0!==e.aspectRatio&&Math.abs(e.aspectRatio-1)>.2){let e=eO(a,"restrictions.squarePreferred","Media ".concat(t+1," would perform better in square format (1:1 ratio)."),{index:t+1});i.push({id:eU("media",e),field:"media",message:e,type:"warning",severity:"non-blocking"})}}),i}},"max-file-size-100mb":{description:"File size must be under 100MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(e.fileSize&&e.fileSize>0x6400000){var n;let r=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(n=a.fileSizeExceeded)?void 0:n.call(a,{index:t+1,maxSize:"100MB",currentSize:r}))||"Media ".concat(t+1," exceeds 100MB limit (").concat(r,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking"})}}),i}},"max-file-size-5mb":{description:"File size must be under 5MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(e.fileSize&&e.fileSize>5242880){var n;let r=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(n=a.fileSizeExceeded)?void 0:n.call(a,{index:t+1,maxSize:"5MB",currentSize:r}))||"Media ".concat(t+1," exceeds 5MB limit (").concat(r,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking"})}}),i}},"max-file-size-1mb":{description:"File size must be under 1MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(e.fileSize&&e.fileSize>1048576){var n;let r=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(n=a.fileSizeExceeded)?void 0:n.call(a,{index:t+1,maxSize:"1MB",currentSize:r}))||"Media ".concat(t+1," exceeds 1MB limit (").concat(r,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking"})}}),i}},"max-file-size-40mb":{description:"File size must be under 40MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(e.fileSize&&e.fileSize>0x2800000){var n;let r=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(n=a.fileSizeExceeded)?void 0:n.call(a,{index:t+1,maxSize:"40MB",currentSize:r}))||"Media ".concat(t+1," exceeds 40MB limit (").concat(r,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking"})}}),i}},"video-duration-10m-max":{description:"TikTok videos must be 10 minutes or less",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration&&e.duration>600){let n=eO(a,"restrictions.tiktokVideoTooLong","Video ".concat(t+1," is too long. TikTok videos must be 10 minutes or less (current: ").concat(Math.round(e.duration/60),"m ").concat(e.duration%60,"s)."),{index:t+1,minutes:Math.round(e.duration/60),seconds:e.duration%60});i.push({id:eU("media",n),field:"media",message:n,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK})}}),i}},"x-video-duration-max":{description:"X/Twitter videos must be between 0.5 seconds and 2 minutes 20 seconds",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r,l;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration){if(e.duration<.5){let n=(null==a||null==(r=a.xVideoTooShort)?void 0:r.call(a,{index:t+1,duration:e.duration}))||"Video ".concat(t+1," is too short. X/Twitter videos must be at least 0.5 seconds (current: ").concat(e.duration,"s).");i.push({id:eU("media",n),field:"media",message:n,type:"error",severity:"blocking",platform:c.SocialPlatform.X})}else if(e.duration>140){let n=Math.floor(e.duration/60),r=e.duration%60,s=(null==a||null==(l=a.xVideoTooLong)?void 0:l.call(a,{index:t+1,minutes:n,seconds:r}))||"Video ".concat(t+1," is too long. X/Twitter videos must be 2 minutes 20 seconds or less (current: ").concat(n,"m ").concat(r,"s).");i.push({id:eU("media",s),field:"media",message:s,type:"error",severity:"blocking",platform:c.SocialPlatform.X})}}}),i}},"x-media-policy":{description:"X requires text or media and supports four images, one GIF, or one video",check:(e,t)=>{var a,i;let n=[],r="string"==typeof t.content?t.content:"",l=e=>({id:eU("media",e,c.SocialPlatform.X),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.X});r.trim()||0!==e.length||n.push(l("An X Post requires text or media."));let s=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}),o=e.filter(e=>"image/gif"===e.type);return(s.length>1||o.length>1||(s.length||o.length)&&e.length>1)&&n.push(l("X supports up to four images, one GIF, or one video per Post.")),(null!=(i=null==(a=r.match(/(^|\s)\$[A-Za-z][A-Za-z0-9_]{0,14}\b/g))?void 0:a.length)?i:0)>1&&n.push(l("X self-serve access allows one cashtag per Post.")),e.forEach((e,t)=>{var a;let i="bigint"==typeof e.fileSize?Number(e.fileSize):e.fileSize,r=(null==(a=e.type)?void 0:a.startsWith("video/"))?0x20000000:"image/gif"===e.type?0xf00000:5242880;void 0!==i&&i>r&&n.push(l("Media ".concat(t+1," exceeds X's file-size limit."))),e.alt&&"image/jpeg"!==e.type&&"image/png"!==e.type&&"image/webp"!==e.type?n.push(l("Media ".concat(t+1," cannot use alt text because X supports alt text only for images."))):e.alt&&e.alt.length>1e3&&n.push(l("Media ".concat(t+1," alt text must be 1,000 characters or fewer.")))}),n}},"telegram-media-policy":{description:"Telegram requires text or media and enforces Bot API media limits",check:(e,t,a)=>{let i=[],n="string"==typeof t.content?t.content:"",r=e=>({id:eU("media",e,c.SocialPlatform.TELEGRAM),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.TELEGRAM}),l=(e,t,i)=>eO(a,"restrictions.telegram.".concat(e),t,i);
1return n.trim()||0!==e.length||i.push(r(l("content-required","Add a caption or at least one media item for Telegram."))),e.forEach((e,t)=>{var a;let n=t+1,s="bigint"==typeof e.fileSize?e.fileSize>BigInt(Number.MAX_SAFE_INTEGER)?Number.MAX_SAFE_INTEGER:Number(e.fileSize):e.fileSize,o=null==(a=e.type)?void 0:a.startsWith("image/");"number"==typeof s&&s>(o?0xa00000:0x3200000)&&i.push(r(l(o?"photo-size":"video-size","Media ".concat(n," exceeds Telegram's ").concat(o?"10 MB photo":"50 MB video"," limit."),{index:n}))),o&&e.width&&e.height&&(e.width+e.height>1e4&&i.push(r(l("photo-dimensions","Photo ".concat(n," width and height cannot exceed 10,000 in total."),{index:n}))),Math.max(e.width,e.height)/Math.min(e.width,e.height)>20&&i.push(r(l("photo-aspect-ratio","Photo ".concat(n," aspect ratio cannot exceed 20:1."),{index:n}))))}),i}},"tiktok-api-validation-hint":{description:"Indicates TikTok API validation is needed for accurate duration limits",check:e=>[]},"professional-content":{description:"Content should be professional and appropriate for LinkedIn",check:()=>[]},"image-preferred":{description:"Images perform better than videos on Pinterest",check:(e,t,a)=>{let i=[];return e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}).length>0&&i.push({id:eU("media","Images typically perform better than videos on Pinterest."),field:"media",message:eO(a,"restrictions.pinterestImagePreferred","Images typically perform better than videos on Pinterest."),type:"warning",severity:"non-blocking"}),i}},"linkedin-video-duration":{description:"LinkedIn videos must be between 3 seconds and 15 minutes",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;(null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration&&(e.duration<3?i.push({id:eU("media",eO(a,"restrictions.linkedinVideoTooShort","Video ".concat(t+1," is too short. LinkedIn videos must be at least 3 seconds (current: ").concat(e.duration,"s)."),{index:t+1,duration:e.duration})),field:"media",message:eO(a,"restrictions.linkedinVideoTooShort","Video ".concat(t+1," is too short. LinkedIn videos must be at least 3 seconds (current: ").concat(e.duration,"s)."),{index:t+1,duration:e.duration}),type:"error",severity:"blocking",platform:c.SocialPlatform.LINKEDIN}):e.duration>900&&i.push({id:eU("media",eO(a,"restrictions.linkedinVideoTooLong","Video ".concat(t+1," is too long. LinkedIn videos must be 15 minutes or less (current: ").concat(Math.round(e.duration/60),"m ").concat(e.duration%60,"s)."),{index:t+1,minutes:Math.round(e.duration/60),seconds:e.duration%60})),field:"media",message:eO(a,"restrictions.linkedinVideoTooLong","Video ".concat(t+1," is too long. LinkedIn videos must be 15 minutes or less (current: ").concat(Math.round(e.duration/60),"m ").concat(e.duration%60,"s)."),{index:t+1,minutes:Math.round(e.duration/60),seconds:e.duration%60}),type:"error",severity:"blocking",platform:c.SocialPlatform.LINKEDIN}))}),i}},"linkedin-video-file-size":{description:"LinkedIn videos must be under 5GB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&e.fileSize&&e.fileSize>0x140000000){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.videoFileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"5GB",currentSize:n}))||"Video ".concat(t+1," exceeds 5GB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.LINKEDIN})}}),i}},"linkedin-image-file-size":{description:"LinkedIn images must be under 5MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("image/"))&&e.fileSize&&e.fileSize>5242880){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.imageFileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"5MB",currentSize:n}))||"Image ".concat(t+1," exceeds 5MB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.LINKEDIN})}}),i}},"linkedin-carousel-limit":{description:"LinkedIn supports up to 9 media items in a carousel",check:(e,t,a)=>e.length>9?[{id:eU("media",eO(a,"restrictions.linkedinCarouselLimit","LinkedIn supports maximum 9 media items per post (current: ".concat(e.length,"). Consider creating multiple posts."),{count:e.length})),field:"media",message:eO(a,"restrictions.linkedinCarouselLimit","LinkedIn supports maximum 9 media items per post (current: ".concat(e.length,"). Consider creating multiple posts."),{count:e.length}),type:"error",severity:"blocking",platform:c.SocialPlatform.LINKEDIN}]:[]},"linkedin-video-resolution":{description:"LinkedIn video resolution should be between 256x144 and 4096x2304",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r,l,s,o,d,u,m,h;(null==(n=e.type)?void 0:n.startsWith("video/"))&&e.width&&e.height&&(e.width<256||e.height<144?i.push({id:eU("media",eO(a,"restrictions.linkedinVideoResolutionLow","Video ".concat(t+1," resolution is below recommended minimum (").concat(e.width,"x").concat(e.height,"). LinkedIn recommends at least 256x144."),{index:t+1,width:null!=(r=e.width)?r:0,height:null!=(l=e.height)?l:0}
1)),field:"media",message:eO(a,"restrictions.linkedinVideoResolutionLow","Video ".concat(t+1," resolution is below recommended minimum (").concat(e.width,"x").concat(e.height,"). LinkedIn recommends at least 256x144."),{index:t+1,width:null!=(s=e.width)?s:0,height:null!=(o=e.height)?o:0}),type:"warning",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN}):(e.width>4096||e.height>2304)&&i.push({id:eU("media",eO(a,"restrictions.linkedinVideoResolutionHigh","Video ".concat(t+1," resolution is very high (").concat(e.width,"x").concat(e.height,"). Consider reducing to 1920x1080 for better compatibility."),{index:t+1,width:null!=(d=e.width)?d:0,height:null!=(u=e.height)?u:0})),field:"media",message:eO(a,"restrictions.linkedinVideoResolutionHigh","Video ".concat(t+1," resolution is very high (").concat(e.width,"x").concat(e.height,"). Consider reducing to 1920x1080 for better compatibility."),{index:t+1,width:null!=(m=e.width)?m:0,height:null!=(h=e.height)?h:0}),type:"warning",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN}))}),i}},"linkedin-image-dimensions":{description:"LinkedIn images should be at least 552x276 pixels",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r,l,s,o;(null==(n=e.type)?void 0:n.startsWith("image/"))&&e.width&&e.height&&(e.width<552||e.height<276)&&i.push({id:eU("media",eO(a,"restrictions.linkedinImageTooSmall","Image ".concat(t+1," is smaller than recommended size (").concat(e.width,"x").concat(e.height,"). LinkedIn recommends at least 552x276 for better display."),{index:t+1,width:null!=(r=e.width)?r:0,height:null!=(l=e.height)?l:0})),field:"media",message:eO(a,"restrictions.linkedinImageTooSmall","Image ".concat(t+1," is smaller than recommended size (").concat(e.width,"x").concat(e.height,"). LinkedIn recommends at least 552x276 for better display."),{index:t+1,width:null!=(s=e.width)?s:0,height:null!=(o=e.height)?o:0}),type:"warning",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN})}),i}},"linkedin-aspect-ratio-optimal":{description:"Optimal aspect ratios for LinkedIn engagement",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(void 0!==e.aspectRatio){let n=e.aspectRatio;n>1.5&&Math.abs(n-1.78)>.1?i.push({id:eU("media",eO(a,"restrictions.linkedinAspectLandscape","Media ".concat(t+1," would perform better in 16:9 landscape format for LinkedIn."),{index:t+1})),field:"media",message:eO(a,"restrictions.linkedinAspectLandscape","Media ".concat(t+1," would perform better in 16:9 landscape format for LinkedIn."),{index:t+1}),type:"info",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN}):n>=.8&&n<=1.2&&Math.abs(n-1)>.1&&i.push({id:eU("media",eO(a,"restrictions.linkedinAspectSquare","Media ".concat(t+1," would look better as perfect square (1:1) for LinkedIn."),{index:t+1})),field:"media",message:eO(a,"restrictions.linkedinAspectSquare","Media ".concat(t+1," would look better as perfect square (1:1) for LinkedIn."),{index:t+1}),type:"info",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN})}}),i}},"linkedin-video-format":{description:"LinkedIn works best with MP4 videos",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r,l;(null==(n=e.type)?void 0:n.startsWith("video/"))&&"video/mp4"!==e.type&&i.push({id:eU("media",eO(a,"restrictions.linkedinVideoFormat","Video ".concat(t+1," format (").concat(e.type,") may have compatibility issues. MP4 is recommended for LinkedIn."),{index:t+1,type:null!=(r=e.type)?r:""})),field:"media",message:eO(a,"restrictions.linkedinVideoFormat","Video ".concat(t+1," format (").concat(e.type,") may have compatibility issues. MP4 is recommended for LinkedIn."),{index:t+1,type:null!=(l=e.type)?l:""}),type:"warning",severity:"non-blocking",platform:c.SocialPlatform.LINKEDIN})}),i}},"mastodon-no-mixed-media":{description:"Mastodon cannot mix images and videos in the same post",check:(e,t,a)=>{let i=e.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("image/")}),n=e.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")});return i&&n?[{id:eU("media","Mastodon does not support mixing images and videos in the same post. Please use only images or only videos."),field:"media",message:eO(a,"restrictions.mastodonNoMixedMedia","Mastodon does not support mixing images and videos in the same post. Please use only images or only videos."),type:"error",severity:"blocking",platform:c.SocialPlatform.MASTODON}]:[]}}
1,"bluesky-image-file-size":{description:"Bluesky image file size limit (1MB)",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("image/"))&&e.fileSize&&e.fileSize>1048576){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.fileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"1MB",currentSize:n}))||"Image ".concat(t+1," exceeds 1MB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.BLUESKY})}}),i}},"bluesky-video-file-size":{description:"Bluesky video file size limit (50MB)",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&e.fileSize&&e.fileSize>0x3200000){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.fileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"50MB",currentSize:n}))||"Video ".concat(t+1," exceeds 50MB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.BLUESKY})}}),i}},"pinterest-image-file-size":{description:"Pinterest images must be under 20MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("image/"))&&e.fileSize&&e.fileSize>0x1400000){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.imageFileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"20MB",currentSize:n}))||"Image ".concat(t+1," exceeds 20MB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST})}}),i}},"pinterest-video-file-size":{description:"Pinterest videos must be under 100MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n,r;if((null==(n=e.type)?void 0:n.startsWith("video/"))&&e.fileSize&&e.fileSize>0x6400000){let n=(0,m.s8)("bigint"==typeof e.fileSize?Number(e.fileSize)/1048576:(e.fileSize||0)/1048576),l=(null==a||null==(r=a.videoFileSizeExceeded)?void 0:r.call(a,{index:t+1,maxSize:"100MB",currentSize:n}))||"Video ".concat(t+1," exceeds 100MB limit (").concat(n,").");i.push({id:eU("media",l),field:"media",message:l,type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST})}}),i}},"pinterest-video-duration":{description:"Pinterest videos must be between 1 and 60 seconds",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;(null==(n=e.type)?void 0:n.startsWith("video/"))&&void 0!==e.duration&&(e.duration<1?i.push({id:eU("media",eO(a,"restrictions.pinterestVideoTooShort","Video ".concat(t+1," is too short. Pinterest videos must be at least 1 second (current: ").concat(e.duration,"s)."),{index:t+1,duration:e.duration})),field:"media",message:eO(a,"restrictions.pinterestVideoTooShort","Video ".concat(t+1," is too short. Pinterest videos must be at least 1 second (current: ").concat(e.duration,"s)."),{index:t+1,duration:e.duration}),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST}):e.duration>60&&i.push({id:eU("media",eO(a,"restrictions.pinterestVideoTooLong","Video ".concat(t+1," is too long. Pinterest videos must be 60 seconds or less (current: ").concat(Math.round(e.duration),"s)."),{index:t+1,duration:Math.round(e.duration)})),field:"media",message:eO(a,"restrictions.pinterestVideoTooLong","Video ".concat(t+1," is too long. Pinterest videos must be 60 seconds or less (current: ").concat(Math.round(e.duration),"s)."),{index:t+1,duration:Math.round(e.duration)}),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST}))}),i}},"pinterest-no-mixed-media":{description:"Pinterest does not support mixing images and videos in the same pin",check:(e,t,a)=>{let i=[],n=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("image/")}),r=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")});return n.length>0&&r.length>0&&i.push({id:eU("media","Pinterest does not support mixing images and videos in the same pin."),field:"media",message:eO(a,"restrictions.pinterestNoMixedMedia","Pinterest does not support mixing images and videos in the same pin."),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST}),r.length>
11&&i.push({id:eU("media","Pinterest supports only 1 video per pin."),field:"media",message:eO(a,"restrictions.pinterestOneVideo","Pinterest supports only 1 video per pin."),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST}),i}},"pinterest-aspect-ratio-consistency":{description:"Pinterest carousel pins require all images to have the same aspect ratio",check:(e,t,a)=>{let i=[],n=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("image/")});if(n.length>1){let e=[];if(n.forEach((t,n)=>{if(t.width&&t.height&&t.width>0&&t.height>0){let a=t.width/t.height;e.push(a)}else i.push({id:eU("media",eO(a,"restrictions.pinterestCarouselMissingDimensions","Image ".concat(n+1," dimensions are missing. Pinterest requires all carousel images to share the same aspect ratio. Please use images with known width and height (e.g., 1000x1500 for 2:3)."),{index:n+1})),field:"media",message:eO(a,"restrictions.pinterestCarouselMissingDimensions","Image ".concat(n+1," dimensions are missing. Pinterest requires all carousel images to share the same aspect ratio. Please use images with known width and height (e.g., 1000x1500 for 2:3)."),{index:n+1}),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST})}),e.length>1){let t=e[0];if(e.some((e,a)=>Math.abs(e-t)/t>.05)){let e=n.map((e,t)=>{if(e.width&&e.height&&e.width>0&&e.height>0){let a=(e.width/e.height).toFixed(2);return"- Image ".concat(t+1,": ").concat(a,":1 (").concat(e.width,"x").concat(e.height,")")}return"- Image ".concat(t+1,": unknown (missing dimensions)")}).join("\n");i.push({id:eU("media","Pinterest requires all carousel images to have the same aspect ratio."),field:"media",message:eO(a,"restrictions.pinterestCarouselAspectMismatch","Pinterest requires all carousel images to have the same aspect ratio.\n".concat(e,"\nPinterest recommends 2:3 (e.g., 1000x1500). Ensure all images share the same ratio."),{bulletLines:e}),type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST})}}}return i}},"max-resolution-1080x1920":{description:"Media resolution must not exceed 1080x1920 pixels for reels and stories",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{if(e.width&&e.height&&(e.width>1080||e.height>1920)){var n,r,l,s;i.push({id:eU("media",eO(a,"restrictions.maxResolution1080x1920","Media ".concat(t+1," resolution (").concat(e.width,"x").concat(e.height,") exceeds maximum 1080x1920 pixels for reels and stories."),{index:t+1,width:null!=(n=e.width)?n:0,height:null!=(r=e.height)?r:0})),field:"media",message:eO(a,"restrictions.maxResolution1080x1920","Media ".concat(t+1," resolution (").concat(e.width,"x").concat(e.height,") exceeds maximum 1080x1920 pixels for reels and stories."),{index:t+1,width:null!=(l=e.width)?l:0,height:null!=(s=e.height)?s:0}),type:"error",severity:"blocking"})}}),i}},"instagram-image-file-size-8mb":{description:"Instagram images must not exceed 8 MB",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;if(!(null==(n=e.type)?void 0:n.startsWith("image/"))||!e.fileSize)return;let r="bigint"==typeof e.fileSize?Number(e.fileSize):e.fileSize;if(r>ez.Av.maxFileSizeBytes){let e=(0,m.s8)(r/1048576),n=(null==a?void 0:a.imageFileSizeExceeded({index:t+1,maxSize:"8MB",currentSize:e}))||"Image ".concat(t+1," exceeds Instagram's 8MB limit (").concat(e,").");i.push({id:eU("media",n),field:"media",message:n,type:"error",severity:"blocking"})}}),i}},"instagram-feed-image-aspect-ratio":{description:"Instagram feed and carousel images must have an aspect ratio between 4:5 and 1.91:1",check:(e,t,a)=>{let i=[];return e.forEach((e,t)=>{var n;if(!(null==(n=e.type)?void 0:n.startsWith("image/")))return;let r=(0,ez.DN)(e.width,e.height,e.aspectRatio);if(void 0===r||(0,ez.pF)(r))return;let l=e.width&&e.height?" (".concat(e.width,"x").concat(e.height,")"):"",s=eO(a,"restrictions.instagramFeedAspectRatio","Image ".concat(t+1).concat(l," has an unsupported aspect ratio of ").concat(r.toFixed(2),":1 for Instagram Feed and Carousel posts. Use a ratio between 4:5 and 1.91:1, or switch to Story or Reel."),{index:t+1,dimensions:l,aspectRatio:r.toFixed(2)});i.push({id:eU("media",s),field:"media",message:s,type:"error",severity:"blocking"})}),i}}
1,"instagram-feed-video-published-as-reel":{description:"Instagram publishes feed videos as Reels shared to the Feed",check:(e,t,a)=>{if(!e.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}))return[];let i=eO(a,"restrictions.instagramFeedVideoPublishedAsReel","Instagram publishes videos as Reels. This video will also appear in the Feed.");return[{id:eU("media",i),field:"media",message:i,type:"warning",severity:"non-blocking"}]}}};var eV=a(30789);function eq(e,t,a){let i=u.C[e];if(!i)return null;let n=i.postTypes[t];if(!n)return null;let r={};return i.text&&(r.content={maxLength:e===c.SocialPlatform.X&&a&&i.text.premium?i.text.premium.maxLength:i.text.maxLength,required:i.text.required||!1,field:i.text.field}),i.title&&(r.title={maxLength:i.title.maxLength,required:i.title.required}),r.media={maxCount:n.maxMediaCount,required:n.requiresMedia||!1,restrictions:n.restrictions,supportedTypes:n.supportedTypes},n.thumbnail&&(r.thumbnail={maxCount:n.thumbnail.maxCount,required:n.thumbnail.required,restrictions:n.thumbnail.restrictions,supportedTypes:n.thumbnail.supportedTypes}),r}let eH={captionRequired:"Caption is required.",descriptionRequired:"Description is required.",titleRequired:"Title is required.",captionTooLong:e=>{let{maxLength:t,currentLength:a}=e;return"Caption is too long (".concat(a,"/").concat(t," characters).")},descriptionTooLong:e=>{let{maxLength:t,currentLength:a}=e;return"Description is too long (".concat(a,"/").concat(t," characters).")},titleTooLong:e=>{let{maxLength:t,currentLength:a}=e;return"Title is too long (".concat(a,"/").concat(t," characters).")},mediaRequired:"At least one media item is required.",tooManyMedia:e=>{let{maxCount:t,currentCount:a}=e;return"Too many media items. Maximum ".concat(t," allowed (current: ").concat(a,").")},unsupportedMediaFormat:e=>{let{index:t,supportedTypes:a}=e;return"Media ".concat(t," has unsupported format. Supported: ").concat(a,".")},unsupportedPostType:e=>{let{postType:t,platform:a}=e;return'Post type "'.concat(t,'" is not supported for ').concat(a,".")},xVideoTooShort:e=>{let{index:t,duration:a}=e;return"Video ".concat(t," is too short. X/Twitter videos must be at least 0.5 seconds (current: ").concat(a,"s).")},xVideoTooLong:e=>{let{index:t,minutes:a,seconds:i}=e;return"Video ".concat(t," is too long. X/Twitter videos must be 2 minutes 20 seconds or less (current: ").concat(a,"m ").concat(i,"s).")},fileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return"Media ".concat(t," exceeds ").concat(a," limit (").concat(i,")")},videoFileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return"Video ".concat(t," exceeds ").concat(a," limit (").concat(i,")")},imageFileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return"Image ".concat(t," exceeds ").concat(a," limit (").concat(i,")")},threadCommentTooLong:e=>{let{commentNumber:t,maxLength:a,currentLength:i}=e;return"Thread ".concat(t," exceeds ").concat(a," characters (").concat(i,"/").concat(a,")")},threadCommentEmpty:e=>{let{commentNumber:t}=e;return"Thread ".concat(t," cannot be empty")},expiredAccount:"This account's token has expired. Please reconnect to continue posting.",reconnectAccount:"Facebook must be reconnected before publishing.",pinterestBoardRequired:"Pinterest board is required.",tiktokVisibilityRequired:"Visibility level is required for TikTok posts.",tiktokDiscloseRequired:"You need to indicate if your content promotes yourself, a third party, or both."};function e$(e){if(void 0===e)return;if("number"==typeof e)return e;let t=Number.MAX_SAFE_INTEGER;return e>BigInt(t)?(console.warn("BigInt value exceeds safe integer limit: ".concat(e)),t):Number(e)}class eY{static generateErrorId(e,t,a){let i="".concat(e,"-").concat(t,"-").concat(a||"global"),n=0;for(let e=0;e<i.length;e++)n=(n<<5)-n+i.charCodeAt(e),n&=n;return Math.abs(n).toString(36)}static async validatePayload(e,t,a,i,n){let r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:eH,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"en",s=this.generateCacheKey(e,t,a,l);if(n&&(0,z.Ur)(n))return{isValid:!1,hasWarnings:!1,errors:[{id:this.generateErrorId("account","Account reconnect required",e),field:"account",message:r.reconnectAccount||"Facebook must be reconnected before publishing.",type:"error",severity:"blocking",platform:e,postType:t.postType||this.getDefaultPostType(e)}],warnings:[],canPublish:!1,canSaveDraft:!0};if(n&&(0,z.XP)(n))return{isValid:!1,hasWarnings:!1,errors:[{id:this.generateErrorId("account","Account token expired",e),field:"account",message:r.expiredAccount||"This account's token has expired. Please reconnect to continue posting.",type:"error",severity:"blocking",platform:e,postType:t.postType||this.getDefaultPostType(e)}],warnings:[],canPublish:!1,canSaveDraft:!0};if(this.cache.has(s))return this.cache.get(s);let o=await this.performPlatformValidation(e,t,a,i,r);if(this.cache.size>=this.CACHE_SIZE_LIMIT){let e=this.cache.keys().next().value;e&&this.cache.delete(e)}return this.cache.set(s,o),o}static validatePayloadSync(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:eH,i=arguments.length>3?arguments[3]:void 0,n=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0,l=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"en";if(n&&(0,z.Ur)(n))return{isValid:!1,hasWarnings:!1,errors:[{id:this.generateErrorId("account","Account reconnect required",e),field:"account",message:a.reconnectAccount||"Facebook must be reconnected before publishing.",type:"error",severity:"blocking",platform:e,postType:t.postType||this.getDefaultPostType(e)}],warnings:[],canPublish:!1,canSaveDraft:!0};if(n&&(0,z.XP)(n))return{isValid:!1,hasWarnings:!1,errors:[{id:this.generateErrorId("account","Account token expired",e),field:"account",message:a.expiredAccount||"This account's token has expired. Please reconnect to continue posting.",type:"error",severity:"blocking",platform:e,postType:t.postType||this.getDefaultPostType(e)}],warnings:[],canPublish:!1,canSaveDraft:!0};let s=this.generateCacheKey(e,t,r,l);if(this.cache.has(s))return this.cache.get(s);let o=this.performPlatformValidationSync(e,t,a,i);if(this.cache.size>=this.CACHE_SIZE_LIMIT){let e=this.cache.keys().next().value;e&&this.cache.delete(e)}return this.cache.set(s,o),o}static validateField(e,t,a,i){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:eH,r=arguments.length>5?arguments[5]:void 0,l=i.postType||this.getDefaultPostType(e),s=eq(e,l,r||!1);if(!s)return[];switch(t){case"content":var o,d;return s.content?this.validateContent(i,e===c.SocialPlatform.TELEGRAM&&(null!=(d=null==(o=i.media)?void 0:o.length)?d:0)>0?{...s.content,maxLength:1024}:s.content,e,n):[];case"title":return s.title?this.validateTitle(i,s.title,e,n):[];case"media":return s.media?this.validateMedia(i.media||[],s.media,i,e,n):[];default:return[]}}static async performPlatformValidation(e,t,a,i){var n,r,l,s,o,d,u,m,h,p;let f=arguments.length>4&&void 0!==arguments[4]?arguments[4]:eH,x=[],g=[],v=t.postType||this.getDefaultPostType(e),b=eq(e,v,i||!1);if(!b)return x.push({id:this.generateErrorId("postType","Unsupported post type: ".concat(v," for ").concat(e)),field:"postType",message:f.unsupportedPostType({postType:v,platform:e}),type:"error",severity:"blocking",platform:e,postType:v}),{isValid:!1,hasWarnings:!1,errors:x,warnings:g,canPublish:!1,canSaveDraft:!0};let y=e===c.SocialPlatform.X&&(null==(n=t.x)?void 0:n.threadComments)&&t.x.threadComments.length>0||e===c.SocialPlatform.THREADS&&(null==(r=t.threads)?void 0:r.threadComments)&&t.threads.threadComments.length>0||e===c.SocialPlatform.MASTODON&&(null==(l=t.mastodon)?void 0:l.threadComments)&&t.mastodon.threadComments.length>0;if(b.content){let a=e===c.SocialPlatform.TELEGRAM&&(null!=(h=null==(m=t.media)?void 0:m.length)?h:0)>0?{...b.content,maxLength:1024}:b.content,i=this.validateContent(t,a,e,f),n=y?i.map(e=>({...e,message:e.message.replace(/Caption/gi,"Thread 1 caption").replace(/Description/gi,"Thread 1 caption")})):i;x.push(...n.filter(e=>"error"===e.type)),g.push(...n.filter(e=>"warning"===e.type))}if(b.title){let a=this.validateTitle(t,b.title,e,f);x.push(...a.filter(e=>"error"===e.type)),g.push(...a.filter(e=>"warning"===e.type))}if(b.media){let a=this.validateMedia(t.media||[],b.media,t,e,f);x.push(...a.filter(e=>"error"===e.type)),g.push(...a.filter(e=>"warning"===e.type))}if(null==(s=b.media)?void 0:s.restrictions){let i=b.media.restrictions;if(e===c.SocialPlatform.TIKTOK&&a)try{let e=await eG.getCreatorInfo(a);null!==e&&e.maxDurationSec>600&&(i=i.filter(e=>"video-duration-10m-max"!==e))}catch(e){console.warn("[TikTok Validation] API check failed, using default restrictions:",e)}let n=this.validateRestrictions(t.media||[],i,t,f);x.push(...n.filter(e=>"error"===e.type)),g.push(...n.filter(e=>"warning"===e.type))}if(e===c.SocialPlatform.X&&(null==(o=t.x)?void 0:o.threadComments)&&t.x.threadComments.length>0){let a=this.validateThreadComments(t.x.threadComments,b,e,f);x.push(...a.filter(e=>"error"===e.type)),g.push(...a.filter(e=>"warning"===e.type))}else if(e===c.SocialPlatform.THREADS&&(null==(d=t.threads)?void 0:d.threadComments)&&t.threads.threadComments.length>0){let a=this.validateThreadComments(t.threads.threadComments,b,e,f);x.push(...a.filter(e=>"error"===e.type)),g.push(...a.filter(e=>"warning"===e.type))}else if(e===c.SocialPlatform.MASTODON&&(null==(u=t.mastodon)?void 0:u.threadComments)&&t.mastodon.threadComments.length>0){let a=this.validateThreadComments(t.mastodon.threadComments,b,e,f);x.push(...a.filter(e=>"error"===e.type)),g.push(...a.filter(e=>"warning"===e.type))}if(e===c.SocialPlatform.TIKTOK&&a){let e=await this.validateTikTokAPI(t.media||[],a,f);x.push(...e.filter(e=>"error"===e.type)),g.push(...e.filter(e=>"warning"===e.type))}if(e===c.SocialPlatform.TIKTOK){let e=this.validateTikTokSettings(t,f);x.push(...e.filter(e=>"error"===e.type)),g.push(...e.filter(e=>"warning"===e.type))}return e===c.SocialPlatform.PINTEREST&&((null==(p=t.pinterest)?void 0:p.board)||x.push({id:this.generateErrorId("pinterest-board","Pinterest board is required.",c.SocialPlatform.PINTEREST),field:"pinterest-board",message:f.pinterestBoardRequired||"Pinterest board is required.",type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST,postType:v})),{isValid:0===x.length,hasWarnings:g.length>0,errors:x,warnings:g,canPublish:0===x.length,canSaveDraft:!0}}static performPlatformValidationSync(e,t){var a,i,n,r,l,s,o,d,u,m;let h=arguments.length>2&&void 0!==arguments[2]?arguments[2]:eH,p=arguments.length>3?arguments[3]:void 0,f=[],x=[],g=t.postType||this.getDefaultPostType(e),v=eq(e,g,p||!1);if(!v)return f.push({id:this.generateErrorId("postType","Unsupported post type: ".concat(g," for ").concat(e)),field:"postType",message:h.unsupportedPostType({postType:g,platform:e}),type:"error",severity:"blocking",platform:e,postType:g}),{isValid:!1,hasWarnings:!1,errors:f,warnings:x,canPublish:!1,canSaveDraft:!0};let b=e===c.SocialPlatform.X&&(null==(a=t.x)?void 0:a.threadComments)&&t.x.threadComments.length>0||e===c.SocialPlatform.THREADS&&(null==(i=t.threads)?void 0:i.threadComments)&&t.threads.threadComments.length>0||e===c.SocialPlatform.MASTODON&&(null==(n=t.mastodon)?void 0:n.threadComments)&&t.mastodon.threadComments.length>0;if(v.content){let a=e===c.SocialPlatform.TELEGRAM&&(null!=(u=null==(d=t.media)?void 0:d.length)?u:0)>0?{...v.content,maxLength:1024}:v.content,i=this.validateContent(t,a,e,h),n=b?i.map(e=>({...e,message:e.message.replace(/Caption/gi,"Thread 1 caption").replace(/Description/gi,"Thread 1 caption")})):i;f.push(...n.filter(e=>"error"===e.type)),x.push(...n.filter(e=>"warning"===e.type))}if(v.title){let a=this.validateTitle(t,v.title,e,h);f.push(...a.filter(e=>"error"===e.type)),x.push(...a.filter(e=>"warning"===e.type))}if(v.media){let a=this.validateMedia(t.media||[],v.media,t,e,h);f.push(...a.filter(e=>"error"===e.type)),x.push(...a.filter(e=>"warning"===e.type))}if(e===c.SocialPlatform.X&&(null==(r=t.x)?void 0:r.threadComments)&&t.x.threadComments.length>0){let a=this.validateThreadComments(t.x.threadComments,v,e,h);f.push(...a.filter(e=>"error"===e.type)),x.push(...a.filter(e=>"warning"===e.type))}else if(e===c.SocialPlatform.THREADS&&(null==(l=t.threads)?void 0:l.threadComments)&&t.threads.threadComments.length>0){let a=this.validateThreadComments(t.threads.threadComments,v,e,h);f.push(...a.filter(e=>"error"===e.type)),x.push(...a.filter(e=>"warning"===e.type))}else if(e===c.SocialPlatform.MASTODON&&(null==(s=t.mastodon)?void 0:s.threadComments)&&t.mastodon.threadComments.length>0){let a=this.validateThreadComments(t.mastodon.threadComments,v,e,h);f.push(...a.filter(e=>"error"===e.type)),x.push(...a.filter(e=>"warning"===e.type))}if(null==(o=v.media)?void 0:o.restrictions){let e=this.validateRestrictions(t.media||[],v.media.restrictions,t,h);f.push(...e.filter(e=>"error"===e.type)),x.push(...e.filter(e=>"warning"===e.type))}if(e===c.SocialPlatform.TIKTOK){let e=this.validateTikTokSettings(t,h);f.push(...e.filter(e=>"error"===e.type)),x.push(...e.filter(e=>"warning"===e.type))}return e===c.SocialPlatform.PINTEREST&&((null==(m=t.pinterest)?void 0:m.board)||f.push({id:this.generateErrorId("pinterest-board","Pinterest board is required.",c.SocialPlatform.PINTEREST),field:"pinterest-board",message:h.pinterestBoardRequired||"Pinterest board is required.",type:"error",severity:"blocking",platform:c.SocialPlatform.PINTEREST,postType:g})),{isValid:0===f.length,hasWarnings:x.length>0,errors:f,warnings:x,canPublish:0===f.length,canSaveDraft:!0}}static validateContent(e,t,a){var i;let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:eH,r=[],l="description"===t.field?(null==(i=e.youtube)?void 0:i.description)||"":e.content||"";
1if(t.required&&!l.trim()){let e="description"===t.field?"descriptionRequired":"captionRequired";r.push({id:this.generateErrorId("content","".concat("description"===t.field?"Description":"Caption"," is required."),a),field:t.field||"content",message:n[e],type:"error",severity:"blocking",platform:a})}let s=a===c.SocialPlatform.X?eV.A.parseTweet(l.normalize("NFC")).weightedLength:l.length;if(s>t.maxLength){let e="description"===t.field?"descriptionTooLong":"captionTooLong";r.push({id:this.generateErrorId("content","".concat("description"===t.field?"Description":"Caption"," exceeds ").concat(t.maxLength," characters (").concat(s,"/").concat(t.maxLength,")."),a),field:t.field||"content",message:n[e]({maxLength:t.maxLength,currentLength:s}),type:"error",severity:"blocking",platform:a})}return r}static validateThreadComments(e,t,a){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:eH,n=[];return e.forEach((e,r)=>{var l;let s=r+2;if(t.content){let r={content:e.content,media:e.media||[]};this.validateContent(r,t.content,a,i).forEach(t=>{n.push({...t,id:"".concat(t.id,"-thread-").concat(e.id),field:"threadComment-".concat(e.id),message:t.message.replace(/Caption/gi,"Thread ".concat(s," caption")).replace(/Description/gi,"Thread ".concat(s," caption"))})})}if(e.media&&e.media.length>0&&t.media){let r={content:e.content,media:e.media};this.validateMedia(e.media,t.media,r,a,i).forEach(t=>{n.push({...t,id:"".concat(t.id,"-thread-").concat(e.id),field:"threadComment-".concat(e.id,"-media"),message:t.message.replace("Media ","Thread comment ".concat(s," media ")).replace("media item","thread comment ".concat(s," media item"))})}),t.media.restrictions&&this.validateRestrictions(e.media,t.media.restrictions,r,i).forEach(t=>{n.push({...t,id:"".concat(t.id,"-thread-").concat(e.id),field:"threadComment-".concat(e.id,"-media"),message:t.message.replace("Media ","Thread comment ".concat(s," media ")).replace("media item","thread comment ".concat(s," media item"))})})}else if(null==(l=t.media)?void 0:l.restrictions){let a={content:e.content,media:[]};this.validateRestrictions([],t.media.restrictions,a,i).forEach(t=>{n.push({...t,id:"".concat(t.id,"-thread-").concat(e.id),field:"threadComment-".concat(e.id,"-media"),message:t.message.replace("An X Post","Thread ".concat(s))})})}}),n}static validateTitle(e,t,a){var i;let n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:eH,r=[],l=(null==(i=e.youtube)?void 0:i.title)||"";return t.required&&!l.trim()&&r.push({id:this.generateErrorId("title","Title is required.",a),field:"title",message:n.titleRequired,type:"error",severity:"blocking",platform:a}),l.length>t.maxLength&&r.push({id:this.generateErrorId("title","Title exceeds ".concat(t.maxLength," characters (").concat(l.length,"/").concat(t.maxLength,")."),a),field:"title",message:n.titleTooLong({maxLength:t.maxLength,currentLength:l.length}),type:"error",severity:"blocking",platform:a}),r}static validateMedia(e,t,a,i){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:eH,r=[];return t.required&&0===e.length&&r.push({id:this.generateErrorId("media","At least one media item is required.",i),field:"media",message:n.mediaRequired,type:"error",severity:"blocking",platform:i}),e.length>t.maxCount&&r.push({id:this.generateErrorId("media","Too many media items. Maximum ".concat(t.maxCount," allowed (current: ").concat(e.length,")."),i),field:"media",message:n.tooManyMedia({maxCount:t.maxCount,currentCount:e.length}),type:"error",severity:"blocking",platform:i}),t.supportedTypes&&e.forEach((e,a)=>{this.isMediaTypeSupported(e,t.supportedTypes)||r.push({id:this.generateErrorId("media","Media ".concat(a+1," has unsupported format. Supported: ").concat(this.getSupportedTypesString(t.supportedTypes),"."),i),field:"media",message:n.unsupportedMediaFormat({index:a+1,supportedTypes:this.getSupportedTypesString(t.supportedTypes)}),type:"error",severity:"blocking",platform:i})}),r}static validateRestrictions(e,t,a){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:eH,n=[];return t.forEach(t=>{let r=eW[t];if(r){let t=r.check(e,a,i);n.push(...t)}}),n}static validateTikTokSettings(e){var t,a;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:eH,n=[];if(!(null==(t=e.tiktok)?void 0:t.privacyLevel)){let e=i.tiktokVisibilityRequired||"Visibility level is required for TikTok posts.";n.push({id:this.generateErrorId("tiktok-visibility",e,c.SocialPlatform.TIKTOK),field:"tiktok-visibility",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK})}if(null==(a=e.tiktok)?void 0:a.discloseContent){let t=!0===e.tiktok.isYourBrand,a=!0===e.tiktok.isBrandedContent;if(!t&&!a){let e=i.tiktokDiscloseRequired||"You need to indicate if your content promotes yourself, a third party, or both.";n.push({id:this.generateErrorId("tiktok-disclose",e,c.SocialPlatform.TIKTOK),field:"tiktok-disclose",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK})}}return n}static async validateTikTokAPI(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:eH,i=[];try{let n=await eG.getCreatorInfo(t);if(!n)return console.warn("[TikTok API Validation] No creator info available, using fallback validation"),e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}
1).forEach((e,t)=>{if(e.duration&&e.duration>600){var n;let e=(null==(n=a.translate)?void 0:n.call(a,"restrictions.tiktokVideoExceedsDefaultDuration",{index:t+1}))||"Video ".concat(t+1," exceeds TikTok's default maximum duration of 10 minutes");i.push({id:this.generateErrorId("media",e,c.SocialPlatform.TIKTOK),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK})}}),i;if(n.hasPostingCapError){let e={id:this.generateErrorId("posting-cap",n.postingCapErrorMessage||"Posting cap reached",c.SocialPlatform.TIKTOK),field:"posting-cap",message:this.getPostingCapErrorMessage(n.postingCapErrorCode||n.postingCapErrorMessage||"unknown",a),type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK};return i.push(e),i}let r=e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")});r.length>0&&n.maxDurationSec>0&&r.forEach((e,t)=>{if(e.duration&&e.duration>n.maxDurationSec){var r;let l=Math.floor(n.maxDurationSec/60),s=Math.floor(e.duration/60),o=e.duration%60,d=(null==(r=a.translate)?void 0:r.call(a,"restrictions.tiktokVideoExceedsMaxDuration",{index:t+1,maxMinutes:l,providedMinutes:s,providedSeconds:o.toString().padStart(2,"0")}))||"Video ".concat(t+1," exceeds TikTok's maximum duration of ").concat(l," minutes (").concat(s,"m ").concat(o.toString().padStart(2,"0"),"s provided)"),u={id:this.generateErrorId("media",d,c.SocialPlatform.TIKTOK),field:"media",message:d,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK};i.push(u)}})}catch(t){console.error("[TikTok API Validation] Unexpected error:",t),e.filter(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}).forEach((e,t)=>{if(e.duration&&e.duration>600){var n;let e=(null==(n=a.translate)?void 0:n.call(a,"restrictions.tiktokVideoExceedsDefaultDuration",{index:t+1}))||"Video ".concat(t+1," exceeds TikTok's default maximum duration of 10 minutes");i.push({id:this.generateErrorId("media",e,c.SocialPlatform.TIKTOK),field:"media",message:e,type:"error",severity:"blocking",platform:c.SocialPlatform.TIKTOK})}})}return i}static getPostingCapErrorMessage(e){var t,a,i,n;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:eH;switch(e){case"spam_risk_too_many_posts":return(null==(t=r.translate)?void 0:t.call(r,"restrictions.tiktokDailyPostingLimit"))||"Daily posting limit reached for your TikTok account. Try again tomorrow.";case"spam_risk_user_banned_from_posting":return(null==(a=r.translate)?void 0:a.call(r,"restrictions.tiktokTemporarilyBanned"))||"Your TikTok account is temporarily banned from posting. Contact TikTok support for assistance.";case"reached_active_user_cap":return(null==(i=r.translate)?void 0:i.call(r,"restrictions.tiktokActiveUserCap"))||"Daily quota for active users reached. Try again later.";default:if(e.includes("posting")||e.includes("limit")||e.includes("cap"))return e;return(null==(n=r.translate)?void 0:n.call(r,"restrictions.tiktokUnableToPost"))||"Unable to post to TikTok at this time. Please try again later."}}static isMediaTypeSupported(e,t){var a,i;return!!e.type&&!!t&&(e.type.startsWith("image/")?(null==(a=t.images)?void 0:a.includes(e.type))||!1:!!e.type.startsWith("video/")&&((null==(i=t.videos)?void 0:i.includes(e.type))||!1))}static getSupportedTypesString(e){let t=[];return(null==e?void 0:e.images)&&t.push(...e.images),(null==e?void 0:e.videos)&&t.push(...e.videos),t.join(", ")}static getDefaultPostType(e){return({[c.SocialPlatform.FACEBOOK]:"feed",[c.SocialPlatform.INSTAGRAM]:"feed",[c.SocialPlatform.INSTAGRAM_DIRECT]:"feed",[c.SocialPlatform.X]:"tweet",[c.SocialPlatform.YOUTUBE]:"video",[c.SocialPlatform.TIKTOK]:"post",[c.SocialPlatform.LINKEDIN]:"feed",[c.SocialPlatform.LINKEDIN_ORGANIZATION]:"feed",[c.SocialPlatform.PINTEREST]:"pin",[c.SocialPlatform.THREADS]:"post",[c.SocialPlatform.MASTODON]:"post",[c.SocialPlatform.BLUESKY]:"post",[c.SocialPlatform.TELEGRAM]:"post",[c.SocialPlatform.GOOGLE_BUSINESS]:"standard"})[e]||"post"}static generateCacheKey(e,t,a){var i,n,r,l,s,o,d,c,u,m,h,p,f,x,g,v,b,y,w,j,C,N,S,k,T,E,I,A,P,M,D,R,F,O,z,L,U,_,B,K,G;let W=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"en";return JSON.stringify({platform:e,locale:W,content:t.content,mediaCount:(null==(i=t.media)?void 0:i.length)||0,mediaTypes:null==(n=t.media)?void 0:n.map(e=>e.type),mediaDurations:null==(r=t.media)?void 0:r.map(e=>e.duration),mediaDimensions:null==(l=t.media)?void 0:l.map(e=>[e.width,e.height,e.aspectRatio]),mediaFrameRates:null==(s=t.media)?void 0:s.map(e=>e.frameRate),mediaBitrates:null==(o=t.media)?void 0:o.map(e=>e.bitrate),mediaVideoCodecs:null==(d=t.media)?void 0:d.map(e=>e.videoCodec),mediaAudioCodecs:null==(c=t.media)?void 0:c.map(e=>e.audioCodec),mediaAudioSampleRates:null==(u=t.media)?void 0:u.map(e=>e.audioSampleRateHz),mediaFileSizes:null==(m=t.media)?void 0:m.map(e=>e$(e.fileSize)),mediaUrls:null==(h=t.media)?void 0:h.map(e=>e.url),postType:t.postType,instagramShareToFeed:null==(p=t.instagram)?void 0:p.shareToFeed,youtubeTitle:null==(f=t.youtube)?void 0:f.title,youtubeDescription:null==(x=t.youtube)?void 0:x.description,pinterestLink:null==(g=t.pinterest)?void 0:g.link,pinterestBoard:null==(v=t.pinterest)?void 0:v.board,tiktokPrivacyLevel:null==(b=t.tiktok)?void 0:b.privacyLevel,tiktokDiscloseContent:null==(y=t.tiktok)?void 0:y.discloseContent,tiktokIsYourBrand:null==(w=t.tiktok)?void 0:w.isYourBrand,tiktokIsBrandedContent:null==(j=t.tiktok)?void 0:j.isBrandedContent,tiktokDisableComment:null==(C=t.tiktok)?void 0:C.disableComment,tiktokDisableDuet:null==(N=t.tiktok)?void 0:N.disableDuet,tiktokDisableStitch:null==(S=t.tiktok)?void 0:S.disableStitch,xThreadCommentsCount:(null==(T=t.x)||null==(k=T.threadComments)?void 0:k.length)||0,xThreadCommentsContent:(null==(I=t.x)||null==(E=I.threadComments)?void 0:E.map(e=>e.content).join("|"))||"",xThreadCommentsMediaCount:(null==(P=t.x)||null==(A=P.threadComments)?void 0:A.map(e=>{var t;return(null==(t=e.media)?void 0:t.length)||0}).join("|"))||"",threadsThreadCommentsCount:(null==(D=t.threads)||null==(M=D.threadComments)?void 0:M.length)||0,threadsThreadCommentsContent:(null==(F=t.threads)||null==(R=F.threadComments)?void 0:R.map(e=>e.content).join("|"))||"",threadsThreadCommentsMediaCount:(null==(z=t.threads)||null==(O=z.threadComments)?void 0:O.map(e=>{var t;return(null==(t=e.media)?void 0:t.length)||0}).join("|"))||"",mastodonThreadCommentsCount:(null==(U=t.mastodon)||null==(L=U.threadComments)?void 0:L.length)||0,mastodonThreadCommentsContent:(null==(B=t.mastodon)||null==(_=B.threadComments)?void 0:_.map(e=>e.content).join("|"))||"",mastodonThreadCommentsMediaCount:(null==(G=t.mastodon)||null==(K=G.threadComments)?void 0:K.map(e=>{var t;return(null==(t=e.media)?void 0:t.length)||0}).join("|"))||"",accountId:a},(e,t)=>"bigint"==typeof t?e$(t):t)}static clearCache(){this.cache.clear()}static clearCacheForAccount(e){let t=[];for(let[a]of this.cache.entries())try{JSON.parse(a).accountId===e&&t.push(a)}catch(e){}
1t.forEach(e=>this.cache.delete(e))}}eY.cache=new Map,eY.CACHE_SIZE_LIMIT=100;class eX{static updateAccountValidation(e,t){this.accountValidations.set(e,t),this.notifyListeners()}static removeAccountValidation(e){this.accountValidations.delete(e),this.notifyListeners()}static getGlobalState(){let e=Array.from(this.accountValidations.values());return{canPublish:e.length>0&&e.every(e=>e.canPublish),canSchedule:e.length>0&&e.every(e=>e.canPublish),canSaveDraft:!0,hasErrors:e.some(e=>!e.isValid),hasWarnings:e.some(e=>e.hasWarnings),totalErrors:e.reduce((e,t)=>e+t.errors.length,0),totalWarnings:e.reduce((e,t)=>e+t.warnings.length,0),accountStates:Object.fromEntries(this.accountValidations)}}static subscribe(e){return this.listeners.add(e),e(this.getGlobalState()),()=>this.listeners.delete(e)}static getAccountValidation(e){return this.accountValidations.get(e)}static clearAll(){this.accountValidations.clear(),this.notifyListeners()}static notifyListeners(){let e=this.getGlobalState();this.listeners.forEach(t=>{try{t(e)}catch(e){console.error("Error in validation state listener:",e)}})}}function eZ(){let[e,t]=(0,d.useState)(()=>eX.getGlobalState());return(0,d.useEffect)(()=>eX.subscribe(t),[]),{...e,isPublishDisabled:!e.canPublish,isScheduleDisabled:!e.canSchedule,hasAnyIssues:e.hasErrors||e.hasWarnings,issuesSummary:{errors:e.totalErrors,warnings:e.totalWarnings,accounts:Object.keys(e.accountStates).length}}}eX.accountValidations=new Map,eX.listeners=new Set;var eJ=a(13480),eQ=a(10052),e0=a(17739);function e1(e){let{error:t,className:a}=e,n=(0,o.useTranslations)("CreatePost"),r="pinterest-board"===t.field?n("validation.pinterestBoardRequired"):t.message;return(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center gap-1.5 text-xs",(()=>{switch(t.type){case"error":default:return"text-red-600";case"warning":return"text-amber-600";case"info":return"text-blue-600"}})(),a),children:[(()=>{switch(t.type){case"error":default:return(0,i.jsx)(eJ.A,{className:"h-3.5 w-3.5"});case"warning":return(0,i.jsx)(eQ.A,{className:"h-3.5 w-3.5"});case"info":return(0,i.jsx)(e0.A,{className:"h-3.5 w-3.5"})}})(),(0,i.jsx)("span",{className:"whitespace-pre-line",children:r})]})}function e2(e){let{errors:t,warnings:a,className:n,showErrorsOnly:r=!1}=e,l=t.length>0,s=a.length>0;return l||s&&!r?(0,i.jsxs)("div",{className:n,children:[t.map(e=>(0,i.jsx)(e1,{error:e,className:"mb-1 last:mb-0"},"error-".concat(e.id))),!r&&a.map(e=>(0,i.jsx)(e1,{error:e,className:"mb-1 last:mb-0"},"warning-".concat(e.id)))]}):null}var e4=a(8832),e3=a(11759);function e5(){let[e,t]=(0,d.useState)(!1),a=eZ(),{selectedAccounts:n}=I(),r=(0,o.useTranslations)("CreatePost.errorSummary");if(!a.hasErrors)return null;let l=n.reduce((e,t)=>(e[t.id]=t,e),{}),s=a.totalErrors;return(0,i.jsxs)(ev.AM,{open:e,onOpenChange:t,children:[(0,i.jsx)(ev.Wv,{asChild:!0,children:(0,i.jsxs)(D.$,{variant:"outline",size:"sm",className:"relative border-destructive/50 text-destructive hover:bg-destructive/10 px-2 sm:px-3 h-8 flex items-center",children:[(0,i.jsx)(F.Badge,{variant:"destructive",className:"h-3.5 w-3.5 text-[9px] px-0 py-0 flex items-center justify-center sm:mr-2",children:s}),(0,i.jsx)("span",{className:"hidden sm:inline",children:1===s?r("issue"):r("issues")})]})}),(0,i.jsx)(ev.hl,{className:"w-64 p-3 z-50",align:"end",side:"top",sideOffset:8,children:(0,i.jsx)("div",{className:"space-y-3",children:(0,i.jsx)("div",{className:"space-y-2",children:Object.entries(a.accountStates).filter(e=>{let[,t]=e;return t.errors.length>0}).map(e=>{let[t,a]=e,n=l[t];return(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsxs)("div",{className:"flex items-center gap-1.5",children:[n&&(0,i.jsxs)(i.Fragment,{children:[(0,e3.D1)(n.platform,"w-3.5 h-3.5 text-gray-500"),(0,i.jsx)("span",{className:"text-xs font-medium text-gray-700",children:n.platformUsername})]}),!n&&(0,i.jsx)("span",{className:"text-xs text-gray-600",children:r("accountLabel",{id:t})})]}),(0,i.jsx)("div",{className:"space-y-2",children:a.errors.map(e=>(0,i.jsx)("div",{className:"text-xs text-red-600",children:e.message},e.id))})]},t)})})})})]})}function e6(e){let{isLoading:t,isDeleting:a=!1,publishAction:n,onActionSelect:r,onFinalAction:l,getButtonLabel:d,scheduleFor:c,onScheduleChange:u,onCancelClick:m,selectedAccountsCount:h,isEditing:p=!1,onDeleteClick:f,preloadedT
1imeSlots:x,onPreviewClick:g,isPreviewActive:v=!1,isPreviewDisabled:b=!1,recurrence:y,onRecurrenceChange:w,timezone:j,recurringEditMode:C=!1,isMediaProcessing:N=!1}=e,S=(0,o.useTranslations)("CreatePost.actions"),k=eZ(),T=N||0===h||"draft"!==n&&k.isPublishDisabled||C&&(!c||c<=new Date)||!C&&"schedule"===n&&(!c||c<=new Date);return(0,i.jsx)("div",{className:"relative z-30 shrink-0 rounded-b-[inherit] px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-3 before:pointer-events-none before:absolute before:inset-x-0 before:top-0 before:-bottom-2 before:rounded-b-[inherit] before:bg-background/60 before:backdrop-blur-xl before:content-[''] md:py-3",children:(0,i.jsxs)("div",{className:"relative z-10 flex justify-between items-center",children:[(0,i.jsxs)("div",{className:"flex gap-2 items-center".concat(p&&f?" mr-2 md:mr-0":""),children:[(0,i.jsx)(D.$,{variant:"outline",size:"sm",onClick:m,disabled:t,className:"max-md:hidden",children:S("cancel")}),p&&f&&(0,i.jsxs)(D.$,{variant:"outline",size:"sm",onClick:f,disabled:t||a,className:"text-destructive hover:text-destructive/80",children:[a?(0,i.jsx)(s.F.spinner,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(J.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"hidden sm:inline",children:S(a?"processing":"delete")})]})]}),(0,i.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2 md:flex-none",children:[(0,i.jsxs)("div",{className:"mr-auto flex items-center gap-2 md:mr-0",children:[(0,i.jsxs)(D.$,{variant:"outline",size:"sm",onClick:g,disabled:t||b,"aria-label":"Toggle preview",className:"w-8 shrink-0 px-0 sm:w-auto sm:px-3".concat(v?" bg-muted":""),children:[(0,i.jsx)(Q.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"hidden sm:inline",children:S("preview")})]}),(0,i.jsx)(e5,{})]}),C?(0,i.jsx)(eF,{scheduleFor:c,onScheduleChange:u,preloadedTimeSlots:x,recurrence:y,onRecurrenceChange:w,timezone:j,disabled:t||N,recurrenceRequired:!0}):"schedule"===n&&(0,i.jsx)(i.Fragment,{children:(0,i.jsx)(eF,{scheduleFor:c,onScheduleChange:u,preloadedTimeSlots:x,recurrence:y,onRecurrenceChange:w,timezone:j,disabled:t||N})}),(0,i.jsx)(en,{isLoading:t,publishAction:n,onActionSelect:r,onFinalAction:l,getButtonLabel:d,isActionDisabled:T,fixedAction:C,recurrenceEnabled:!!y})]})]})})}var e8=a(38667),e9=a(18962),e7=a(31194),te=a(62403);let tt={en:"Showing only YouTube-compatible thumbnails: JPG, PNG, or GIF images at least 640 px wide and n
1o larger than 2 MB.",es:"Mostrando solo miniaturas compatibles con YouTube: im\xe1genes JPG, PNG o GIF de al menos 640 px de ancho y un m\xe1ximo de 2 MB."};function ta(e){var t;let{isOpen:a,open:n,onOpenChange:l,children:s,onSelect:c,selectionMode:u="multiple",maxSelectionCount:m,multiSelectConfirmText:h="Add Media",youTubeThumbnailMode:p=!1}=e,f=(0,o.useTranslations)("CreatePost.youtube.thumbnail"),x=(0,o.useLocale)(),g=f.has("compatibilityNotice")?f("compatibilityNotice"):tt[x.startsWith("es")?"es":"en"],v=null!=(t=null!=n?n:a)&&t,b=(0,d.useRef)(null),[y,w]=(0,d.useState)([]),[j,C]=(0,d.useState)(void 0),N=(0,e7.x9)(j),k=(0,e7.jt)(j),T=p?k.data:N.contents,E=N.hierarchy,I=N.refreshTargeted,A=p?k.isLoading:N.isLoading,P=(0,d.useMemo)(()=>{let e=T||{media:[],folders:[]};return p?{...e,media:e.media.filter(e=>S(e).isValid)}:e},[T,p]),M=(0,d.useCallback)(e=>{C(e||void 0)},[]),D=(0,d.useCallback)(e=>{w(e)},[]);(0,d.useEffect)(()=>{v||w([])},[v]);let R=(0,d.useCallback)(e=>{e||w([]),l(e)},[l]),F=(0,d.useCallback)(e=>{e&&c&&c(e),R(!1)},[c,R]),O=(0,d.useCallback)(()=>{if(p&&1===y.length){let e=S(y[0]).errorCodes[0];if(e)return void B.oR.error(f("errors.".concat(e)))}c&&y.length>0&&c(y),R(!1)},[p,y,c,R,f]);return(0,i.jsxs)(e8.cj,{open:v,onOpenChange:R,children:[s&&(0,i.jsx)(e8.CG,{asChild:!0,children:s}),(0,i.jsxs)(e8.h,{ref:b,tabIndex:-1,onOpenAutoFocus:e=>{var t;e.preventDefault(),null==(t=b.current)||t.focus({preventScroll:!0})},side:"right",className:"w-full sm:max-w-2xl md:max-w-3xl lg:max-w-4xl xl:max-w-5xl p-0 flex flex-col outline-none [&>button]:z-20 [&>button]:inline-flex [&>button]:size-8 [&>button]:items-center [&>button]:justify-center [&>button]:bg-background [&>button:focus:not(:focus-visible)]:ring-0 [&>button:focus:not(:focus-visible)]:ring-offset-0","aria-describedby":"media-drawer-description",children:[(0,i.jsx)(r.s6,{children:(0,i.jsx)(e8.qp,{children:"Select Media"})}),(0,i.jsx)("div",{id:"media-drawer-description",className:"sr-only",children:"Media selection drawer"}),(0,i.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[p&&(0,i.jsx)("div",{className:"mx-4 mt-4 rounded-md border bg-muted/40 px-3 py-2 text-sm text-muted-foreground md:mx-6",role:"note",children:g}),(0,i.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden",children:(0,i.jsx)(e9.J,{initialContents:P,initialHierarchy:E||[],initialFolderPath:[],enableFolderSelection:!0,selectionMode:u,internalFolderId:j,onNavigateRequest:M,onMediaSelectConfirm:"single"===u?F:void 0,onConfirmMultiSelect:"multiple"===u?O:void 0,onSelectionChange:D,maxSelectionCount:m,multiSelectConfirmText:p?f("useThumbnail"):h,preferInitialContents:p,fitParentHeight:!0,hideHeader:!0,hideCreateFolder:!1,hideUpload:!1,hideCreatePostButton:!0,itemSize:"sm",onRefreshContentsAndHierarchy:I.contentsAndHierarchy,onRefreshByOperation:I.byOperation,mutate:p?k.mutate:N.mutateContents,skeletonComponent:(0,i.jsx)(te.Q6,{itemSize:"sm"}),isLoading:A})})]})]})]})}var ti=a(57783);async function tn(e,t){if(!e||!t)throw Error("Missing post group or workspace for publishing");let a=await fetch("/api/qstash/schedule-group-publish",{method:"POST",keepalive:!0,headers:{"Content-Type":"application/json"},body:JSON.stringify({groupPostsId:e,workspaceId:t})}),i=await a.json().catch(()=>null);if(!a.ok||!i||i.error||!1===i.success)throw Error((null==i?void 0:i.error)||"Failed to schedule background publishing")}let tr=(0,d.createContext)(void 0);function tl(e){let{children:t}=e,[a,n]=(0,d.useState)([]),r=(0,d.useRef)(new Map),l=(0,d.useCallback)(e=>{let t=r.current.get(e);t&&(clearTimeout(t),r.current.delete(e)),n(t=>t.filter(t=>t.id!==e))},[]),s=(0,d.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"error";if(!e||""===e.trim())return;let a=Math.random().toString(36).substring(7);n(i=>[...i,{id:a,message:e,type:t}]);let i=setTimeout(()=>{r.current.delete(a),n(e=>e.filter(e=>e.id!==a))},4e3);r.current.set(a,i)},[]),o=(0,d.useCallback)(()=>{for(let e of r.current.values())clearTimeout(e);r.current.clear(),n([])},[]);return(0,d.useEffect)(()=>()=>{for(let e of r.current.values())clearTimeout(e);r.current.clear()},[]),(0,i.jsxs)(tr.Provider,{value:{errors:a,addError:s,removeError:l,clearErrors:o},children:[t,a.length>0&&(0,i.jsx)("div",{className:"pointer-events-none absolute inset-x-0 top-[72px] z-50 flex flex-col items-center gap-2 px-4",children:a.map(e=>(0,i.jsxs)("div",{role:"status",className:(0,m.cn)("pointer-events-auto flex max-w-md items-center gap-3 rounded-xl border px-4 py-3 text-center text-sm shadow-lg backdrop-blur-md animate-in fade-in-0 zoom-in-95 duration-200","error"===e.type?"border-destructive/20 bg-destructive/15 text-destructive":"border-amber-500/20 bg-amber-500/15 text-amber-700 dark:text-amber-300"),children:[(0,i.jsx)("span",{className:"min-w-0 flex-1 text-center leading-snug",children:e.message}),(0,i.jsx)("button",{type:"button",onClick:()=>l(e.id),className:"shrink-0 rounded-md px-1 text-base leading-none opacity-70 transition-opacity hover:opacity-100","aria-label":"Dismiss",children:"\xd7"})]},e.id))})]})}function ts(){let e=(0,d.useContext)(tr);if(void 0===e)throw Error("useError must be used within an ErrorProvider");return e}var to=a(13010);let td=["#FAFAFA"],tc=["#171717"];var tu=a(57943),tm=a(19348),th=a(69452),tp=a(28067);let tf=(0,tp.createServerReference)("78059e44755e948fd1653a2c52b7f4058049584fda",tp.callServer,void 0,tp.findSourceMapURL,"updateRecurringPostSeries");var tx=a(70576),tg=a(96838),tv=a(94340),tb=a(80594);function ty(e){let{account:t,isOpen:a,payload:n,selectedPostTypeLabel:r,truncateText:l,validation:s,isExpired:d=!1,requiresReconnect:c=!1}=e,u=(0,o.useTranslations)("CreatePost"),h=(0,o.useTranslations)("Connections.accounts"),p=!!s&&s.visibleErrors.length>0,f=d?(0,z.po)(t,h):null,x=(null==f?void 0:f.text)||u("expired",{defaultValue:"Expired"}),g=d||c,v=c?u("reconnectRequired",{defaultValue:"Reconnect required"}):x,b=c?u("reconnectRequiredDescription",{defaultValue:"This account needs to be reconnected before you can publish."}):u("expiredDescription",{defaultValue:"This account has expired. Reconnect it to continue publishing."}),y=(0,i.jsxs)(tx.aR,{className:(0,m.cn)("flex flex-row items-center justify-between px-4 py-2 transition-colors","!space-y-0",g?"cursor-not-allowed opacity-75":"cursor-pointer md:[@media(hover:hover)_and_(pointer:fine)]:hover:bg-muted/40"),style:{padding:"0.5rem 1rem"},children:[(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,i.jsx)(R.u,{account:t,size:"sm"}),a&&(0,i.jsx)(tx.ZB,{className:"text-sm leading-none text-foreground",children:t.platformUsername}),!a&&!g&&(0,i.jsxs)("div",{className:"flex items-center min-w-0 gap-2 overflow-hidden flex-nowrap whitespace-nowrap my-0",children:[n.media&&n.media.length>0&&(0,i.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[n.media.slice(0,5).map((e,t)=>{var a;let n=null==(a=e.type)?void 0:a.startsWith("video/"),r=encodeURI(e.thumbnailUrl||e.url);return(0,i.jsx)("div",{className:"relative w-5 h-5 rounded overflow-hidden border border-border/50 bg-black",children:n&&!e.thumbnailUrl?(0,i.jsx)("video",{src:"".concat(r,"#t=0.1"),muted:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-cover"}):(0,i.jsx)(tv.default,{src:r,alt:"Thumb ".concat(t+1),fill:!0,sizes:"20px",className:"object-cover"})},t)}),n.media.length>5&&(0,i.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",n.media.length-5]})]}),n.content&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:l((0,m.QP)(n.content),30)})]})]}),(0,i.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0 my-0 ml-3",children:[!a&&g&&(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)("span",{className:(0,m.cn)("text-xs px-2 py-1 rounded-full flex items-center my-0",c||(null==f?void 0:f.status)==="expired"||(null==f?void 0:f.status)==="today"?"bg-destructive/10 text-destructive":"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/20 dark:text-yellow-400"),children:v})}),(0,i.jsx)(O.TooltipContent,{children:(0,i.jsx)("p",{children:b})})]}),!a&&g&&(0,i.jsx)(tb.M,{account:t}),!a&&g&&(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)("span",{tabIndex:0,"aria-label":v,className:"inline-flex",children:(0,i.jsx)(eJ.A,{className:"w-3.5 h-3.5 text-destructive"})})}),(0,i.jsx)(O.TooltipContent,{hideArrow:!0,sideOffset:8,className:"w-64 border bg-popover p-3 text-popover-foreground shadow-md text-left",children:(0,i.jsx)("p",{className:"text-xs text-destructive",children:b})})]}),!g&&r&&(0,i.jsx)(F.Badge,{variant:"outline",className:"text-xs px-1.5 py-0.5 rounded-lg text-muted-foreground",children:r}),!g&&p&&(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)("span",{tabIndex:0,"aria-label":u("errorSummary.issues"),className:"inline-flex",children:(0,i.jsx)(eJ.A,{className:"w-3.5 h-3.5 text-destructive"})})}),(0,i.jsx)(O.TooltipContent,{hideArrow:!0,sideOffset:8,className:"w-64 border bg-popover p-3 text-popover-foreground shadow-md text-left",children:(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e3.D1)(t.platform,"w-3.5 h-3.5 text-muted-foreground"),(0,i.jsx)("span",{className:"text-xs font-medium text-foreground",children:t.platformUsername})]}),(0,i.jsx)("div",{className:"space-y-2",children:null==s?void 0:s.visibleErrors.map(e=>(0,i.jsx)("div",{className:"text-xs text-destructive whitespace-pre-line",children:e.message},e.id))})]})})]}),!g&&(0,i.jsx)("div",{children:a?(0,i.jsx)(ee.A,{className:"w-4 h-4 text-muted-foreground"}):(0,i.jsx)(U.A,{className:"w-4 h-4 text-muted-foreground"})})]})]});return g?(0,i.jsx)("div",{className:"w-full",children:y}):(0,i.jsx)(tg.R6,{asChild:!0,disabled:g,children:(0,i.jsx)("div",{className:"w-full",children:y})})}var tw=a(11688),tj=a(42749),tC=a(10743),tN=a(80769),tS=a(42830),tk=a(59898),tT=a(85191),tE=a(71904),tI=a(72755),tA=a(94745),tP=a(6187),tM=a(5890),tD=a(18131),tR=a(36451),tF=a(12777),tO=a(14552),tz=a(84542),tL=a(37606),tU=a(93846),t_=a(80683),tB=a(15055),tK=a(13168),tG=a(18552),tW=a(50366);let tV=new Set,tq=e=>{let{item:t,alt:a,onError:n,isThumbnail:r=!1,objectFit:l="cover",isProcessing:s=!1}=e,c=(0,o.useTranslations)("CreatePost"),[u,h]=(0,d.useState)(!1),[p,f]=(0,d.useState)(!1),x=t.type.startsWith("video/"),g=(0,tU.x)(t.type,t.url),v=!0===(0,t_.F)(t.url,g),b=(0,d.useRef)(null),y=(0,H.a)(),w=t.thumbnailUrl||t.url,j=encodeURI(w),C=x&&!t.thumbnailUrl?"".concat(j,"#t=0.1"):j,N=t.alt||a||"Media item",S=()=>{h(!0),n(t.url)},k=(0,d.useCallback)(()=>{!y&&!r&&(f(!0),x&&b.current&&b.current.play().catch(()=>{}))},[y,x,r]),T=(0,d.useCallback)(()=>{!y&&!r&&(f(!1),x&&b.current&&(b.current.pause(),b.current.currentTime=0))},[y,x,r]);return((0,d.useEffect)(()=>{h(!1)},[w]),u)?(0,i.jsx)("div",{className:(0,m.cn)("relative w-full h-full group/imageitem overflow-hidden bg-muted-foreground
1/10 flex items-center justify-center",r?"rounded-md":"rounded-lg"),children:(0,i.jsxs)("div",{className:"text-center p-2",children:[(0,i.jsx)(tw.A,{className:"h-6 w-6 mx-auto mb-1 text-muted-foreground"}),(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:c("mediaSection.unavailable")})]})}):(0,i.jsxs)("div",{className:(0,m.cn)("relative w-full h-full group/imageitem overflow-hidden",r?"rounded-md":"rounded-lg"),onMouseEnter:k,onMouseLeave:T,children:[x?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("video",{ref:b,src:t.url,muted:!0,playsInline:!0,preload:"metadata",poster:t.thumbnailUrl||void 0,className:(0,m.cn)("relative h-full w-full z-10","contain"===l?"object-contain":"object-cover"),onError:S,children:"Your browser does not support the video tag."},w),r&&(0,i.jsx)("div",{className:"absolute bottom-0.5 right-0.5 p-0.5 bg-black/70 rounded z-20",children:(0,i.jsx)(tj.A,{className:"h-2 w-2 text-white fill-white"})})]}):g&&v?(0,i.jsxs)(i.Fragment,{children:[v&&p?(0,i.jsx)("img",{src:t.url,alt:N,className:(0,m.cn)("relative h-full w-full z-10","contain"===l?"object-contain":"object-cover")},"".concat(t.id,"-animated")):(0,i.jsx)(tv.default,{src:C,alt:N,fill:!0,className:(0,m.cn)("contain"===l?"object-contain":"object-cover","z-10"),onError:S,unoptimized:!0},C),r&&(0,i.jsx)("div",{className:"absolute bottom-0.5 right-0.5 p-0.5 bg-black/70 rounded z-20",children:(0,i.jsx)(tj.A,{className:"h-2 w-2 text-white fill-white"})})]}):(0,i.jsx)(tv.default,{src:C,alt:N,fill:!0,className:(0,m.cn)("contain"===l?"object-contain":"object-cover","z-10"),onError:S,unoptimized:g||C.endsWith(".gif")},C),!r&&(0,i.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-2 z-20 flex justify-center px-2 opacity-0 transition-opacity group-hover/imageitem:opacity-100",children:(0,i.jsxs)("p",{className:"flex max-w-full flex-wrap items-center justify-center gap-3 rounded-md bg-black/70 px-2 py-1 text-center text-xs font-medium leading-tight text-white",children:[(0,i.jsxs)("span",{className:"flex items-center gap-0.5",children:[x?(0,i.jsx)(tC.A,{className:"h-3 w-3 opacity-70"}):(0,i.jsx)(tN.A,{className:"h-3 w-3 opacity-70"}),function(e){var t;return(null!=(t=e.split("/")[1])?t:e).replace("jpeg","JPG").replace("quicktime","MOV").toUpperCase()}(t.type)]}),t.width&&t.height?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,i.jsx)(tS.A,{className:"h-3 w-3 opacity-70"}),t.width," \xd7 ",t.height]}),(0,i.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,i.jsx)(tk.A,{className:"h-3 w-3 opacity-70"}),function(e,t){let a=[[1,1],[4,5],[5,4],[16,9],[9,16],[4,3],[3,4],[3,2],[2,3],[2,1],[1,2],[5,3],[3,5],[7,4],[4,7]],i=e/t,n=a[0],r=1/0;for(let e of a){let t=Math.abs(i-e[0]/e[1]);t<r&&(r=t,n=e)}if(r/i<.05)return"".concat(n[0],":").concat(n[1]);let l=(e,t)=>0===t?e:l(t,e%t),s=l(e,t);return"".concat(e/s,":").concat(t/s)}(t.width,t.height)]})]}):null,x&&t.duration?(0,i.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,i.jsx)(eo.A,{className:"h-3 w-3 opacity-70"}),function(e){let t=Math.floor(e/60),a=Math.floor(e%60);return"".concat(t,":").concat(a.toString().padStart(2,"0"))}(t.duration)]}):null]})}),s&&(0,i.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-[55] rounded-lg pointer-events-none",children:r?(0,i.jsx)(tT.A,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}):(0,i.jsx)(tW.X,{})})]})},tH=e=>{let{item:t,index:a,isActive:n,onFocusClick:r,renderItem:l,isProcessing:s}=e,[o,c]=(0,d.useState)(!1),{attributes:u,listeners:h,setNodeRef:p,transform:f,transition:x,isDragging:g}=(0,tK.gl)({id:t.id,disabled:s}),v={transform:tG.Ks.Transform.toString(f),transition:x,opacity:g?.5:1,zIndex:g?10:void 0};return(0,i.jsxs)("div",{ref:p,style:v,className:(0,m.cn)("relative h-full aspect-square rounded-lg overflow-hidden border cursor-pointer touch-manipulation",n?"border-primary border-2":"border-border/50"),onClick:()=>r(a),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),...u,...!s?h:{},children:[l(t,!0),(0,i.jsx)("div",{className:(0,m.cn)("pointer-events-none absolute inset-0 flex items-center justify-center transition-opacity duration-150 bg-black/40",o?"opacity-100":"opacity-0"),children:(0,i.jsx)(tE.A,{className:"h-5 w-5 text-white drop-shadow-[0_1px_3px_rgba(0,0,0,1)]"})})]})};function t$(e){var t;let{images:a,defaultAlt:n,hasError:r,errorMessage:l,defaultLayout:s="focus",onCopy:c,onRemove:u,onRemoveImage:h,onError:p,onSelect:f,onUpdateImageAlt:x,onReorderImages:g,onCropComplete:v,onConversionStarted:b,processingItemIds:y=tV,isCropSaving:w,onChangeMedia:j,platform:C,postType:N,isUploading:S,hideAddButton:k,showTikTokThumbnailButton:T,onTikTokThumbnailClick:E,showYouTubeThumbn
1ailButton:I,onYouTubeThumbnailClick:A,youTubeThumbnailUrl:P,youTubeThumbnailSelected:M,selectedAccountsCount:R=1,onUserTagClick:F,userTagCount:z,onActiveImageChange:L}=e,U=(0,o.useTranslations)("CreatePost"),B=(0,o.useTranslations)("Media"),K=null!=(t=null==a?void 0:a.length)?t:0,G=a&&K>0?a[0]:null,[W,V]=(0,d.useState)(!1),[q,H]=(0,d.useState)(s),[$,Y]=(0,d.useState)(0),[X,Z]=(0,d.useState)(0),[J,Q]=(0,d.useState)(!1),ee=(0,d.useRef)(K),et=Math.min($,K-1),ea=Math.min(X,K-1),ei=1===K?null==a?void 0:a[0]:"carousel"===q?null==a?void 0:a[et]:null==a?void 0:a[ea],en=!!ei&&y.has(ei.id);(0,d.useEffect)(()=>{V(!1),0===ee.current&&K>0&&(Y(0),Z(0),H(s)),0===K&&(Y(0),Z(0)),ee.current=K},[K,s]),(0,d.useEffect)(()=>{$>=K&&K>0&&Y(Math.max(0,K-1)),X>=K&&K>0&&Z(Math.max(0,K-1))},[K,$,X]),(0,d.useEffect)(()=>{0===K&&J&&Q(!1)},[K,J]);let er=e=>{console.warn("Media failed to load (this is handled gracefully):",e),p(e)},el=r||W,es=(0,tB.FR)((0,tB.MS)(tB.AN,{activationConstraint:{distance:5}})),eo=e=>{e>=0&&e<K&&(Z(e),(null==a?void 0:a[e])&&(null==L||L(a[e].id)))},ed=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t?"cover":"contain";return e?(0,i.jsx)(tq,{item:e,alt:e.alt||n||" ",onError:er,isThumbnail:t,objectFit:a,isProcessing:y.has(e.id)}):(0,i.jsx)("div",{className:"w-full h-full bg-muted-foreground/20 flex items-center justify-center",children:(0,i.jsx)("span",{className:"text-muted-foreground text-xs",children:"Missing media"})})};return 0!==K||el?(0,i.jsxs)("div",{className:"flex w-full flex-1 items-center justify-start gap-2 md:flex-col md:items-stretch md:gap-0",children:[(0,i.jsxs)("div",{"data-media-preview":!0,"data-gradient-available":!S,className:(0,m.cn)("brand-gradient-outline group flex items-center justify-center relative isolate",0===K?"rounded-lg flex-1 w-full md:w-auto md:cursor-pointer md:hover:bg-muted md:transition-colors":"min-w-0 flex-1 rounded-xl w-full max-w-[240px] min-h-[150px] md:mx-auto md:flex-none md:max-w-none",K>=1&&!(K>1&&"focus"===q)&&"aspect-square",!(K>1&&"focus"===q)&&"overflow-hidden"),onClick:0!==K||S?void 0:e=>{e.stopPropagation(),f()},children:[!G&&!el&&(0,i.jsx)("div",{className:"flex items-center justify-center p-2 px-3 h-full w-full pointer-events-none md:pointer-events-auto",children:S?(0,i.jsx)(i.Fragment,{children:(0,i.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-2 border-primary border-t-transparent"})}):(0,i.jsx)(i.Fragment,{children:(0,i.jsx)("div",{className:"flex gap-1 flex-row px-0.5 md:flex-col items-center md:items-center md:justify-center",children:(0,i.jsx)(tI.A,{className:"h-5 w-5 text-muted-foreground group-hover:text-foreground transition-colors"})})})}),el&&(0,i.jsxs)("div",{className:"flex flex-col items-center text-center p-4",children:[(0,i.jsx)(tw.A,{className:"h-8 w-8 mb-2 text-destructive"}),(0,i.jsx)("p",{className:"text-xs text-destructive mb-2",children:l||U("mediaSection.loadingError")}),(0,i.jsx)(D.$,{variant:"outline",size:"sm",onClick:()=>{null==u||u(),f()},children:U("mediaSection.selectMedia")})]}),G&&!el&&(0,i.jsxs)(i.Fragment,{children:[K>1&&"grid"===q&&(0,i.jsxs)("div",{className:"absolute bottom-1 right-1 bg-black/70 text-white text-xs font-semibold px-1.5 py-0.5 rounded z-10",children:[K," images"]}),1===K?(0,i.jsxs)("div",{className:"absolute inset-0 w-full h-full p-1 z-[1]",children:[ed("carousel"===q&&a?a[et]:"focus"===q&&a?a[ea]:G,!1,"contain"),(0,i.jsx)("button",{className:"absolute top-2 right-2 z-[60] rounded-full bg-black/50 hover:bg-black/70 text-white p-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),h(("carousel"===q&&a?a[et]:"focus"===q&&a?a[ea]:G).id)},children:(0,i.jsx)(tA.A,{className:"h-3.5 w-3.5"})}),F&&(0,i.jsxs)("button",{className:"absolute bottom-2 right-2 z-20 rounded-full bg-black/60 hover:bg-black/80 text-white p-1.5 transition-colors cursor-pointer",onClick:e=>{e.stopPropagation(),F()},children:[(0,i.jsx)(tP.A,{className:"h-4 w-4"}),(null!=z?z:0)>0&&(0,i.jsx)("span",{className:"absolute -top-1 -right-1 bg-primary text-primary-foreground text-[10px] font-bold rounded-full w-4 h-4 flex items-center justify-center",children:z})]})]}):(0,i.jsxs)(i.Fragment,{children:["grid"===q&&a&&(0,i.jsx)("div",{className:"absolute inset-0 w-full h-full p-1 z-[1]",children:(0,i.jsx)("div",{className:"grid grid-cols-2 grid-rows-2 gap-0.5 w-full h-full rounded-lg overflow-hidden",children:a.slice(0,4).map((e,t)=>{let a=3===t&&K>4;return(0,i.jsxs)("div",{className:(0,m.cn)("relative w-full h-full bg-muted-foreground
1/10 rounded overflow-hidden group/imageitem",a&&"cursor-pointer",a&&"opacity-60"),onClick:a?()=>{}:void 0,children:[ed(e,!0),a&&(0,i.jsx)("div",{className:"absolute inset-0 bg-black/40 flex items-center justify-center z-10 rounded-md",children:(0,i.jsxs)("span",{className:"text-white font-bold text-lg",children:["+",K-4]})})]},e.id)})})}),"carousel"===q&&a&&(0,i.jsxs)("div",{className:"absolute inset-0 w-full h-full p-1 z-[1]",children:[(0,i.jsx)("div",{className:"relative w-full h-full rounded-lg overflow-hidden",children:ed(a[et])}),K>1&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"absolute top-1/2 left-1 transform -translate-y-1/2 rounded bg-black/30 hover:bg-black/60 text-white opacity-0 group-hover:opacity-100 transition-opacity z-10",onClick:e=>{if(e.stopPropagation(),!a||0===K)return;let t=(et-1+K)%K;Y(t),null==L||L(a[t].id)},"aria-label":"Previous image",children:(0,i.jsx)(tM.A,{size:16})}),(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"absolute top-1/2 right-1 transform -translate-y-1/2 rounded bg-black/30 hover:bg-black/60 text-white opacity-0 group-hover:opacity-100 transition-opacity z-10",onClick:e=>{if(e.stopPropagation(),!a||0===K)return;let t=(et+1)%K;Y(t),null==L||L(a[t].id)},"aria-label":"Next image",children:(0,i.jsx)(tD.A,{size:16})})]}),(0,i.jsxs)("div",{className:"absolute bottom-1 right-1 bg-black/70 text-white text-xs font-semibold px-1.5 py-0.5 rounded z-10",children:[et+1," / ",K]})]}),"focus"===q&&a&&(0,i.jsxs)("div",{className:"w-full z-[1] flex flex-col p-1 gap-1",children:[(0,i.jsxs)("div",{className:"relative h-[180px] w-full flex-shrink-0 rounded-lg overflow-hidden md:h-auto md:aspect-square",children:[a.map((e,t)=>(0,i.jsx)("div",{className:"absolute inset-0 w-full h-full",style:{visibility:t===ea?"visible":"hidden"},children:ed(e,!1,"contain")},e.id)),(0,i.jsx)("button",{className:"absolute top-2 right-2 z-[60] rounded-full bg-black/50 hover:bg-black/70 text-white p-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),h(a[ea].id)},children:(0,i.jsx)(tA.A,{className:"h-3.5 w-3.5"})}),F&&(0,i.jsxs)("button",{className:"absolute bottom-2 right-2 z-20 rounded-full bg-black/60 hover:bg-black/80 text-white p-1.5 transition-colors cursor-pointer",onClick:e=>{e.stopPropagation(),F()},children:[(0,i.jsx)(tP.A,{className:"h-4 w-4"}),(null!=z?z:0)>0&&(0,i.jsx)("span",{className:"absolute -top-1 -right-1 bg-primary text-primary-foreground text-[10px] font-bold rounded-full w-4 h-4 flex items-center justify-center",children:z})]})]}),(0,i.jsx)("div",{className:"flex-shrink-0 h-12 overflow-x-auto overflow-y-hidden",children:(0,i.jsx)(tB.Mp,{sensors:es,collisionDetection:tB.fp,onDragEnd:e=>{let{active:t,over:i}=e;if(!i||t.id===i.id||!a||y.has(String(t.id))||y.has(String(i.id)))return;let n=a.map(e=>e.id),r=n.indexOf(t.id),l=n.indexOf(i.id);g((0,tK.be)(a,r,l))},children:(0,i.jsx)(tK.gB,{items:a.map(e=>e.id),strategy:tK.m$,children:(0,i.jsx)("div",{className:"flex gap-1 h-full w-max",children:a.map((e,t)=>(0,i.jsx)(tH,{item:e,index:t,isActive:t===ea,onFocusClick:eo,renderItem:ed,isProcessing:y.has(e.id)},e.id))})})})})]})]})]})]}),K>0&&(0,i.jsx)("div",{role:"group","aria-label":U("mediaSection.selectMedia"),className:"flex w-fit max-w-[130px] shrink-0 flex-col items-stretch gap-0.5 md:mx-auto md:mt-3 md:max-w-full md:flex-row md:items-center overflow-x-auto overscroll-x-contain rounded-md border border-input bg-popover/95 p-0.5 text-muted-foreground backdrop-blur-xl [&_button]:h-6 [&_button]:justify-start md:[&_button]:justify-center [&_button]:text-sm [&_button]:shrink-0 [&_button]:rounded-sm [&_button]:focus-visible:ring-2",children:(0,i.jsxs)(i.Fragment,{children:[!k&&(0,i.jsxs)(D.$,{variant:"ghost",size:"xs",onClick:f,"aria-label":"Add more images",children:[(0,i.jsx)(_.A,{className:"h-3 w-3"}),U("mediaSection.add")]}),j&&K>0&&(0,i.jsxs)(D.$,{variant:"ghost",size:"xs",disabled:en,onClick:()=>{ei&&j(ei.id)},"aria-label":"Change media",children:[(0,i.jsx)(tR.A,{className:"h-3 w-3"}),U("mediaSection.change")]}),(()=>{let e=!!(null==ei?void 0:ei.mediaId)&&!en;return(0,i.jsxs)(D.$,{variant:"ghost",size:"xs",onClick:()=>Q(!0),disabled:!e,title:(null==ei?void 0:ei.mediaId)?void 0:U("mediaSection.convertUnavailable"),"aria-label":B("convertButton"),children:[(0,i.jsx)(tF.A,{className:"h-3 w-3"}),B("convertButton")]})})(),T&&(0,i.jsxs)(D.$,{variant:"ghost",size:"xs",onClick:E,"aria-label":"Select video thumbnail",children:[(0,i.jsx)(tO.A,{className:"h-3 w-3"}),"Thumbnail"]}),c&&R>=2&&(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsxs)(D.$,{variant:"ghost",size:"xs",onClick:c,"aria-label":U("mediaSection.copyToAllTooltip"),children:[(0,i.jsx)(tz.A,{className:"h-3 w-3"}),U("mediaSection.copyToAll")]})}),(0,i.jsx)(O.TooltipContent,{side:"bottom",children:(0,i.jsx)("p",{children:U("mediaSection.copyToAllTooltip")})})]}),I&&(0,i.jsx)(D.$,{variant:"ghost",size:"xs",className:(0,m.cn)(M&&"bg-muted text-foreground"),onClick:A,"aria-label":M?U("youtube.thumbnail.changeAria"):U("youtube.thumbnail.selectAria"),children:P?(0,i.jsxs)("div",{className:"flex items-center gap-1",children:[(0,i.jsx)("img",{src:P,alt:U("youtube.thumbnail.previewAlt"),className:"w-4 h-2.5 object-cover rounded-sm border",style:{aspectRatio:"16/9"}}),(0,i.jsx)("span",{className:"text-xs",children:U("youtube.thumbnail.label")})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(tO.A,{className:"h-3 w-3"}),U("youtube.thumbnail.label")]})})]})}),G&&a&&((null==ei?void 0:ei.mediaId)&&!en?(0,i.jsx)(tL.k,{isOpen:J,onOpenChange:Q,preferredPlatform:C,preferredPostType:N,media:{id:ei.mediaId,url:ei.url,type:ei.type,name:ei.alt,width:ei.width,height:ei.height,thumbnailUrl:ei.thumbnailUrl},onConversionStarted:(e,t)=>{null==b||b(ei.id,e,t),Q(!1)}}):null)]}):(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(D.$,{type:"button",variant:"brand",size:"icon",className:"!bg-transparent",onClick:f,disabled:S,"aria-label":U("mediaSection.selectMedia"),children:S?(0,i.jsx)(tT.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(tI.A,{className:"h-4 w-4"})})}),(0,i.jsx)(O.TooltipContent,{children:U("mediaSection.selectMedia")})]})}function tY(e){let{videoUrl:t,videoDuration:a,currentTimestamp:n,onTimestampChange:r,className:l}=e,[s,o]=(0,d.useState)(n/1e3),c=(0,d.useRef)(null);(0,d.useEffect)(()=>{o(n/1e3)},[n]);let u=e=>{let t=Math.floor(e/60),a=Math.floor(e%60);return"".concat(t,":").concat(a.toString().padStart(2,"0"))};return(0,i.jsx)("div",{className:(0,m.cn)("w-full",l),children:(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsx)("div",{className:"relative aspect-video bg-black rounded-lg overflow-hidden",children:(0,i.jsx)("video",{ref:c,src:t,className:"w-full h-full object-contain",onTimeUpdate:()=>{c.current&&o(c.current.currentTime)}
1,muted:!0,playsInline:!0})}),(0,i.jsxs)("div",{className:"space-y-3",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(eo.A,{className:"h-4 w-4 text-muted-foreground"}),(0,i.jsx)("span",{className:"text-muted-foreground",children:"Thumbnail at:"}),(0,i.jsx)("span",{className:"font-medium",children:u(n/1e3)})]}),(0,i.jsxs)("span",{className:"text-muted-foreground",children:[u(s)," / ",u(a)]})]}),(0,i.jsx)("div",{className:"w-full",children:(0,i.jsx)("input",{type:"range",min:"0",max:a,step:"0.1",value:s,onChange:e=>{let t=parseFloat(e.target.value);o(t),c.current&&(c.current.currentTime=t),r(Math.round(1e3*t))},className:"w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer slider",style:{background:"linear-gradient(to right, #3b82f6 0%, #3b82f6 ".concat(s/a*100,"%, #e5e7eb ").concat(s/a*100,"%, #e5e7eb 100%)")}})})]})]})})}var tX=a(15982),tZ=a(90633);function tJ(e){let{isOpen:t,onOpenChange:a,onRemoveThumbnail:r,onReplaceThumbnail:l,currentThumbnailUrl:s}=e,{toast:d}=(0,tZ.d)(),c=(0,o.useTranslations)("CreatePost.youtube.thumbnail");return(0,i.jsx)(n.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(n.Cf,{className:"max-w-md max-h-[80vh] flex flex-col",children:[(0,i.jsx)(n.c7,{children:(0,i.jsx)(n.L3,{children:c("optionsTitle")})}),(0,i.jsx)("div",{className:"flex-1 overflow-y-auto space-y-4",children:s&&(0,i.jsx)("div",{className:"space-y-2",children:(0,i.jsx)("div",{className:"flex justify-center",children:(0,i.jsx)("img",{src:s,alt:c("previewAlt"),className:"max-w-full max-h-[40vh] h-auto object-contain rounded-lg"})})})}),(0,i.jsxs)(n.Es,{className:"mt-4 flex-row items-center justify-between gap-2 sm:justify-between",children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(D.$,{variant:"outline",onClick:()=>a(!1),children:c("cancel")}),(0,i.jsxs)(D.$,{onClick:()=>{r(),a(!1),d({title:c("removedTitle"),description:c("removedDescription"),variant:"default"})},variant:"destructive",children:[(0,i.jsx)(J.A,{className:"h-4 w-4"}),c("remove")]})]}),(0,i.jsxs)(D.$,{onClick:()=>{l&&(a(!1),l())},variant:"default",children:[(0,i.jsx)(tX.A,{className:"h-4 w-4"}),c("replace")]})]})]})})}var tQ=a(36704),t0=a(55754),t1=a(74112);function t2(e){let{x:t,y:a,username:n,onRemove:r}=e;return(0,i.jsx)("div",{className:"absolute z-20",style:{left:"".concat(100*t,"%"),top:"".concat(100*a,"%"),transform:"translateX(".concat(t<.2?"0%":t>.8?"-100%":"-50%",") translateY(").concat(a>.75?"calc(-100% - 14px)":"8px",")")},children:(0,i.jsxs)("div",{className:"flex items-center gap-0.5 bg-black/75 text-white text-[10px] rounded-full px-2 py-0.5 shadow-md whitespace-nowrap",children:[(0,i.jsxs)("span",{children:["@",n]}),(0,i.jsx)("button",{type:"button",className:"ml-0.5 hover:bg-white/20 rounded-full p-0.5",onClick:e=>{e.stopPropagation(),r(n)},children:(0,i.jsx)(tA.A,{className:"h-2.5 w-2.5"})})]})})}function t4(e){var t,a;let{accountId:r,payload:l,updatePayload:s,activeMediaId:c,open:u,onOpenChange:h}=e,p=(0,o.useTranslations)("CreatePost.instagram.userTags"),[f,x]=(0,d.useState)(!1),g=void 0!==u,v=g&&null!=h?h:x,[b,y]=(0,d.useState)(null),[w,j]=(0,d.useState)(null),[C,N]=(0,d.useState)(""),[S,k]=(0,d.useState)(""),T=(0,d.useRef)(null),E=(0,d.useRef)(null),I="story"===l.postType,A=(0,d.useMemo)(()=>{var e,t,a;return null!=(a=null==(t=l.instagram)||null==(e=t.userTags)?void 0:e[c])?a:[]},[null==(t=l.instagram)?void 0:t.userTags,c]),P=(0,d.useMemo)(()=>{var e;return null==(e=l.media)?void 0:e.find(e=>e.id===c)},[l.media,c]),M=null==P||null==(a=P.type)?void 0:a.startsWith("video/"),R=(0,d.useMemo)(()=>{let e=e=>{if("number"==typeof e)return Number.isFinite(e)?e:null;if("bigint"==typeof e)return Number.isFinite(Number(e))?Number(e):null;if("string"==typeof e){let t=Number(e);return Number.isFinite(t)?t:null}return null},t=e(null==P?void 0:P.width),a=e(null==P?void 0:P.height);return t&&a&&t>0&&a>0?"".concat(t," / ").concat(a):"1 / 1"},[P]);(0,d.useLayoutEffect)(()=>{if(!b)return void j(null);let e=T.current,t=E.current;if(!e||!t)return;let a=()=>{let a=e.offsetWidth,i=e.offsetHeight,n=t.offsetWidth,r=t.offsetHeight;if(0===a||0===i)return;let l=b.x*a,s=b.y*i,o=s+12;o+r>i-8&&(o=s-12-r),o=Math.max(8,Math.min(i-8-r,o));let d=l-n/2;j({left:d=Math.max(8,Math.min(a-8-n,d)),top:o})};a(),window.addEventListener("resize",a);let i=new ResizeObserver(a);return i.observe(e),()=>{window.removeEventListener("resize",a),i.disconnect()}},[b,C,S]);let O=(0,d.useCallback)(e=>{var t;let a={...null==(t=l.instagram)?void 0:t.userTags};e.length>0?a[c]=e:delete a[c],s(r,{instagram:{...l.instagram,userTags:Object.keys(a).length>0?a:void 0}})},[r,c,l.instagram,s]),z=(0,d.useCallback)((e,t,a)=>{let i=e.replace(/^@+/,"").trim().toLowerCase();return!!i&&(/^[a-zA-Z0-9._]{1,30}$/.test(i)?A.some(e=>e.username===i)?(k(p("duplicate")),!1):A.length>=20?(k(p("maxReached",{max:20})),!1):(k(""),O([...A,{username:i,x:t,y:a}]),!0):(k(p("invalidUsername")),!1))},[A,O,p]),L=(0,d.useCallback)(e=>{O(A.filter(t=>t.username!==e))},[A,O]),U=(0,d.useCallback)(e=>{let t=e.currentTarget.getBoundingClientRect();y({x:Math.max(0,Math.min(1,Math.round((e.clientX-t.left)/t.width*100)/100)),y:Math.max(0,Math.min(1,Math.round((e.clientY-t.top)/t.height*100)/100))}),N(""),k("")},[]),_=(0,d.useCallback)(()=>{b&&C.trim()&&z(C,b.x,b.y)&&(y(null),N(""))},[b,C,z]),B=(0,d.useCallback)(()=>{C.trim()&&z(C,.5,.5)&&N("")},[C,z]);return(0,i.jsxs)(i.Fragment,{children:[!g&&(0,i.jsxs)("div",{className:"shrink-0",children:[(0,i.jsx)(ey.J,{className:"text-muted-foreground",children:p("label")}),(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",className:"mt-1 h-8 text-xs gap-1.5 shrink-0 whitespace-nowrap w-full",onClick:()=>{(I||P)&&v(!0)},disabled:!I&&!P,children:[(0,i.jsx)(tP.A,{className:"h-3.5 w-3.5"}),p("label"),A.length>0&&(0,i.jsx)(F.Badge,{variant:"secondary",size:"sm",className:"ml-1 px-1.5 py-0 text-[10px]",children:A.length})]})]}),(0,i.jsx)(n.lG,{open:g?u:f,onOpenChange:v,children:(0,i.jsxs)(n.Cf,{className:(0,m.cn)("p-0 overflow-hidden",I?"sm:max-w-sm":"sm:max-w-lg"),children:[(0,i.jsxs)(n.c7,{className:"px-4 pt-4 pb-2",children:[(0,i.jsxs)(n.L3,{className:"text-base flex items-center gap-2",children:[(0,i.jsx)(t1.A,{className:"h-4 w-4"}),p("dialogTitle")]}),(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:I?p("storyDescription"):p("dialogDescription")})]}),I&&(0,i.jsxs)("div",{className:"px-4",children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center border rounded-md bg-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 flex-1",S&&"border-destructive"),children:[(0,i.jsx)("span",{className:"pl-2.5 text-sm text-muted-foreground select-none",children:"@"}),(0,i.jsx)(t0.p,{type:"text",autoFocus:!0,placeholder:p("inputPlaceholder"),value:C,onChange:e=>{N(e.target.value.replace(/@/g,"")),S&&k("")},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),B())},className:"h-8 !text-sm placeholder:!text-sm border-0 focus-visible:ring-0 focus-visible:ring-offset-0 pl-0.5"})]}),(0,i.jsx)(D.$,{type:"button",size:"sm",className:"h-8 px-3 text-xs shrink-0",onClick:B,disabled:!C.trim(),children:p("add")})]}),S&&(0,i.jsx)("p",{className:"text-xs text-destructive mt-1",children:S}),A.length>0&&(0,i.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:A.map(e=>(0,i.jsxs)(F.Badge,{variant:"secondary",size:"sm",className:"gap-1 pr-1 cursor-default",children:[(0,i.jsxs)("span",{children:["@",e.username]}),(0,i.jsx)("button",{type:"button",onClick:()=>L(e.username),className:"ml-0.5 rounded-full hover:bg-muted-foreground
1/20 p-0.5",children:(0,i.jsx)(tA.A,{className:"h-3 w-3"})})]},e.username))})]}),!I&&P&&(0,i.jsx)("div",{className:"px-4",children:(0,i.jsxs)("div",{ref:T,className:"relative w-full max-w-[500px] mx-auto cursor-crosshair rounded-md overflow-hidden border border-border bg-black/5 dark:bg-white/5",style:{aspectRatio:R},onClick:U,children:[(0,i.jsx)(tv.default,{src:encodeURI(M&&P.thumbnailUrl?P.thumbnailUrl:P.url),alt:"Tag users",fill:!0,sizes:"(max-width: 480px) 100vw, 480px",className:"object-cover pointer-events-none"}),A.map(e=>(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{className:"absolute z-10 -translate-x-1/2 -translate-y-1/2 pointer-events-none",style:{left:"".concat(100*e.x,"%"),top:"".concat(100*e.y,"%")},children:(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)("div",{className:"h-3 w-3 rounded-full bg-white shadow-sm"}),(0,i.jsx)("div",{className:"absolute inset-0 rounded-full ring-2 ring-black/60"})]})}),(0,i.jsx)(t2,{x:e.x,y:e.y,username:e.username,onRemove:L})]},e.username)),b&&(0,i.jsx)("div",{className:"absolute z-10 -translate-x-1/2 -translate-y-1/2 pointer-events-none",style:{left:"".concat(100*b.x,"%"),top:"".concat(100*b.y,"%")},children:(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)("div",{className:"h-3 w-3 rounded-full bg-white shadow-sm"}),(0,i.jsx)("div",{className:"absolute inset-0 rounded-full ring-2 ring-black/60"})]})}),b&&(0,i.jsxs)("div",{ref:E,className:"absolute z-20",style:w?{left:w.left,top:w.top}:{left:"".concat(100*b.x,"%"),top:"".concat(100*b.y,"%"),transform:"translate(-50%, 12px)"},onClick:e=>e.stopPropagation(),children:[(0,i.jsxs)("div",{className:"flex items-center gap-1 bg-white dark:bg-zinc-900 border border-border rounded-lg shadow-xl px-2 py-1",children:[(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center border rounded-md bg-background",S&&"border-destructive"),children:[(0,i.jsx)("span",{className:"pl-1.5 text-xs text-muted-foreground select-none",children:"@"}),(0,i.jsx)(t0.p,{type:"text",autoFocus:!0,placeholder:p("inputPlaceholder"),value:C,onChange:e=>{N(e.target.value.replace(/@/g,"")),S&&k("")},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),_()),"Escape"===e.key&&y(null)},className:"h-6 w-28 !text-xs placeholder:!text-xs pl-0.5 pr-1.5 border-0 focus-visible:ring-0 focus-visible:ring-offset-0"})]}),(0,i.jsx)(D.$,{type:"button",size:"sm",className:"h-6 px-2 text-xs",onClick:_,disabled:!C.trim(),children:p("add")}),(0,i.jsx)("button",{type:"button",className:"p-0.5 hover:bg-muted rounded",onClick:()=>y(null),children:(0,i.jsx)(tA.A,{className:"h-3 w-3 text-muted-foreground"})})]}),S&&(0,i.jsx)("p",{className:"text-[10px] text-destructive mt-0.5 bg-white dark:bg-zinc-900 rounded px-2 py-0.5 shadow",children:S})]})]})}),(0,i.jsxs)("div",{className:"mx-4 mb-4 flex items-start gap-2 rounded-md bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800/50 px-3 py-2",children:[(0,i.jsx)(e0.A,{className:"h-3.5 w-3.5 text-amber-600 dark:text-amber-500 mt-0.5 shrink-0"}),(0,i.jsx)("p",{className:"text-[11px] leading-snug text-amber-700 dark:text-amber-400",children:p("followNotice")})]})]})})]})}function t3(e){var t,a,r,l,s,u,m,h,p,f,x,g,v,b,y,w,j;let{accountId:C,platform:N,payload:S,updatePayload:k,onSelectImageClick:T,onCopyField:E,onUploadFromPC:I,isUploading:A,selectedAccountsCount:P=1,processingItemIds:M,onConversionStarted:R}=e,{imageError:F,mediaError:O,handleRemoveImage:z,handleImageError:L}=function(e){let{updatePayload:t,accountId:a,payload:i}=e,n=(0,o.useTranslations)("CreatePost.mediaSection"),[r,l]=(0,d.useState)(!1),[s,c]=(0,d.useState)(null),u=(0,d.useCallback)(()=>{t(a,{media:[]}),l(!1),c(null),eY.clearCacheForAccount(a)},[a,t]),m=(0,d.useCallback)(e=>{console.warn("Media failed to load (handled gracefully): ".concat(e)),l(!0),c(n("failedToLoad"))},[n]);return(0,d.useEffect)(()=>
1{l(!1),c(null)},[i.media]),{imageError:r,mediaError:s,handleRemoveImage:u,handleImageError:m}}({updatePayload:k,accountId:C,payload:S,platform:N}),[U,_]=(0,d.useState)(!1),[B,K]=(0,d.useState)(!1),[G,W]=(0,d.useState)(!1),[V,q]=(0,d.useState)(!1),[H,$]=(0,d.useState)(null),Y=N===c.SocialPlatform.INSTAGRAM,X=null!=(v=null==(a=S.media)||null==(t=a[0])?void 0:t.id)?v:null,Z=null!=H?H:X,J=Z&&null!=(b=null==(s=S.instagram)||null==(l=s.userTags)||null==(r=l[Z])?void 0:r.length)?b:0;Object.values(null!=(y=null==(u=S.instagram)?void 0:u.userTags)?y:{}).reduce((e,t)=>e+t.length,0),(0,d.useEffect)(()=>{var e,t,a;if(!Y||!H)return;let i=null!=(t=null==(e=S.media)?void 0:e.map(e=>e.id))?t:[];if(0===i.length)return void $(null);i.includes(H)||$(null!=(a=i[0])?a:null)},[Y,H,S.media]);let Q=(0,d.useRef)(null),ee=E?()=>{E(C,"media")}:void 0,et=(j=S.media)?j.map(e=>({id:e.id||(0,tQ.A)(),mediaId:e.mediaId,url:e.url,type:e.type||(e.url.includes(".mp4")||e.url.includes(".mov")?"video/mp4":"image/jpeg"),alt:e.alt,thumbnailUrl:e.thumbnailUrl,fileSize:e.fileSize,width:e.width,height:e.height,duration:e.duration})):[],ea=N===c.SocialPlatform.TIKTOK&&(null==(m=S.media)?void 0:m.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}))===!0,ei=N===c.SocialPlatform.YOUTUBE&&(null==(h=S.media)?void 0:h.some(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}))===!0,en=null==(p=S.media)?void 0:p.find(e=>{var t;return null==(t=e.type)?void 0:t.startsWith("video/")}),er=e=>{var t,a,i;k(C,{youtube:{...S.youtube,customThumbnail:e?{mediaId:e.id,url:e.url,type:e.type,thumbnailUrl:null!=(t=e.thumbnailUrl)?t:void 0,fileSize:null!=e.sizeInBytes?Number(e.sizeInBytes):void 0,width:null!=(a=e.width)?a:void 0,height:null!=(i=e.height)?i:void 0}:void 0,thumbnailMediaId:void 0}})},el=()=>{var e,t,a,i;return a=null==(e=S.youtube)?void 0:e.customThumbnail,i=null==(t=S.youtube)?void 0:t.thumbnailMediaId,(null==a?void 0:a.thumbnailUrl)||(null==a?void 0:a.url)||i},es=el(),eo=!!((null==(f=S.youtube)?void 0:f.customThumbnail)||(null==(x=S.youtube)?void 0:x.thumbnailMediaId));return(0,d.useEffect)(()=>{let e=Q.current;if(!e||!S.media)return;let{targetId:t,knownIds:a}=e,i=S.media.filter(e=>!a.has(e.id));if(0===i.length)return;Q.current=null;let n=S.media.filter(e=>a.has(e.id)),r=n.findIndex(e=>e.id===t),l=n.filter(e=>e.id!==t),s=r>=0?r:l.length,o=[...l.slice(0,s),...i,...l.slice(s)];eY.clearCacheForAccount(C),k(C,{media:o})},[S.media,C,k]),(0,i.jsxs)("div",{className:"flex flex-col gap-4 w-full",children:[(0,i.jsx)(t$,{images:et,defaultAlt:"Post image for ".concat(C),hasError:F,errorMessage:O,onError:L,onRemove:z,onRemoveImage:e=>{var t;let a=(S.media||[]).filter(t=>t.id!==e);eY.clearCacheForAccount(C);let i=null==(t=S.instagram)?void 0:t.userTags,n=i?(()=>{let{[e]:t,...a}=i;return Object.keys(a).length>0?a:void 0})():void 0;k(C,{media:a.length>0?a:[],...i&&{instagram:{...S.instagram,userTags:n}}})},onSelect:()=>{T(C)},onCopy:ee,onUpdateImageAlt:(e,t)=>{k(C,{media:(S.media||[]).map(a=>a.id===e?{...a,alt:t}:a)})},onReorderImages:e=>{let t=new Map((S.media||[]).map(e=>[e.id,e])),a=e.map(e=>{let a=t.get(e.id);return a?{...a,id:e.id}:{id:e.id,url:e.url,type:e.type,alt:e.alt,thumbnailUrl:e.thumbnailUrl,fileSize:e.fileSize?Number(e.fileSize):void 0,width:e.width,height:e.height,duration:e.duration}});eY.clearCacheForAccount(C),k(C,{media:a})},onConversionStarted:(e,t,a)=>null==R?void 0:R(C,e,t,a),processingItemIds:M,onChangeMedia:e=>{Q.current={targetId:e,knownIds:new Set((S.media||[]).map(e=>e.id))},T(C)},platform:N,postType:null!=(w=S.postType)?w:N===c.SocialPlatform.YOUTUBE?"video":"feed",isUploading:A,hideAddButton:ea||ei,showTikTokThumbnailButton:ea&&!!en,onTikTokThumbnailClick:()=>_(!0),showYouTubeThumbnailButton:ei,onYouTubeThumbnailClick:()=>{var e,t;(null==(e=S.youtube)?void 0:e.customThumbnail)||(null==(t=S.youtube)?void 0:t.thumbnailMediaId)?K(!0):W(!0)},youTubeThumbnailUrl:es,youTubeThumbnailSelected:eo,selectedAccountsCount:P,onUserTagClick:Y?()=>q(!0):void 0,userTagCount:Y?J:void 0,onActiveImageChange:Y?$:void 0}),Y&&Z&&(0,i.jsx)(t4,{accountId:C,payload:S,updatePayload:k,activeMediaId:Z,open:V,onOpenChange:q}),ea&&en&&(0,i.jsx)(n.lG,{open:U,onOpenChange:_,children:(0,i.jsxs)(n.Cf,{className:"max-w-2xl",children:[(0,i.jsx)(n.c7,{children:(0,i.jsx)(n.L3,{children:"Select Video Thumbnail"})}),(0,i.jsx)(tY,{videoUrl:en.url,videoDuration:en.duration||60,currentTimestamp:(null==(g=S.tiktok)?void 0:g.videoCoverTimestampMs)||0,onTimestampChange:e=>{k(C,{tiktok:{...S.tiktok,videoCoverTimestampMs:e}})}}),(0,i.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,i.jsx)(D.$,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),(0,i.jsx)(D.$,{onClick:()=>_(!1),children:"Save"})]})]})}
1),ei&&(0,i.jsx)(tJ,{isOpen:B,onOpenChange:K,onRemoveThumbnail:()=>er(null),onReplaceThumbnail:()=>W(!0),currentThumbnailUrl:el()}),ei&&(0,i.jsx)(ta,{isOpen:G,onOpenChange:W,onSelect:e=>{let t=Array.isArray(e)?e[0]:e;t&&(er(t),W(!1))},selectionMode:"multiple",maxSelectionCount:1,youTubeThumbnailMode:!0})]})}var t5=a(47589),t6=a(11738),t8=a(29358);function t9(e,t){let a=(0,d.useMemo)(()=>(0,e4.en)(e,t),[e,t]),i=(0,d.useMemo)(()=>{let t={};return(0,e4.ix)(e).forEach(i=>{let n=a.postTypes[i];n&&(t[i]={value:i,label:i.charAt(0).toUpperCase()+i.slice(1),requiresMedia:(0,e4.er)(e,i),maxMediaCount:n.maxMediaCount,supportedImageTypes:a.image.formats,supportedVideoTypes:["video/mp4"],videoSpecs:(0,e4.wm)(e,i),aspectRatio:(0,e4.KD)(e,i)})}),t},[e,a]),n=(0,d.useMemo)(()=>Object.keys(i).length>1,[i]);return{postTypes:i,validateContent:a=>(0,e4.uA)(a,e,t),validateMedia:(t,a)=>(0,e4.e4)(t,e,a),maxTextLength:a.text.maxLength,shouldShowPostTypeSelector:n}}let t7=(0,tp.createServerReference)("407ea9ca4a10c4daaf2fc36d8062cc1c6c1d07e935",tp.callServer,void 0,tp.findSourceMapURL,"getPinterestBoards"),ae={},at=(0,tp.createServerReference)("6024b93ecf4fcc55173b014aacd3378f16a060da87",tp.callServer,void 0,tp.findSourceMapURL,"createPinterestBoard");function aa(e){let{accountId:t,onChange:a,value:r,className:l,showLabel:s=!0}=e,{boards:c,isLoading:u,error:m,refetch:h}=function(e){let[t,a]=(0,d.useState)([]),[i,n]=(0,d.useState)(!1),[r,l]=(0,d.useState)(null),s=(0,d.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!e)return;let i=ae[e],r=Date.now();if(!t&&i&&r-i.timestamp<3e5){a(i.boards),l(i.error||null),n(!1);return}try{n(!0),l(null);let t=await t7(e);if(t.error)throw Error(t.error);let i=t.data||[];ae[e]={boards:i,timestamp:r},a(i)}catch(a){let t="Failed to load boards";ae[e]={boards:[],timestamp:r,error:t},l(t),console.error("Error fetching Pinterest boards:",a)}finally{n(!1)}},[e]);return(0,d.useEffect)(()=>{s()},[s]),{boards:t,isLoading:i,error:r,refetch:(0,d.useCallback)(()=>s(!0),[s])}}(t),p=(0,o.useTranslations)("CreatePost.pinterest"),[f,x]=(0,d.useTransition)(),[g,v]=(0,d.useState)(""),[b,y]=(0,d.useState)(""),[w,j]=(0,d.useState)(null),[C,N]=(0,d.useState)(!1);return((0,d.useEffect)(()=>{!r&&c.length>0&&a(c[0].id)},[r,c,a]),u)?(0,i.jsx)("div",{className:"space-y-2 mb-2",children:(0,i.jsx)(ew.Select,{value:void 0,disabled:!0,children:(0,i.jsx)(ew.SelectTrigger,{fieldLabel:s?p("boardInlineLabel"):void 0,disabled:!0,className:l||"w-full bg-transparent border-input focus:ring-0 focus:ring-offset-0 focus:outline-none",children:(0,i.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,i.jsx)(tT.A,{className:"h-4 w-4 animate-spin"}),(0,i.jsx)(ew.SelectValue,{placeholder:p("loadingBoards")})]})})})}):m?(0,i.jsxs)("div",{className:"flex items-center text-sm text-destructive",children:[(0,i.jsx)(eJ.A,{className:"w-4 h-4 mr-2"}),m]}):0===c.length?(0,i.jsxs)("div",{className:"space-y-3 mb-2",children:[(0,i.jsx)("p",{className:"text-amber-500 text-sm",children:p("noBoards")}),(0,i.jsxs)(n.lG,{open:C,onOpenChange:e=>{N(e),e&&j(null)},children:[(0,i.jsx)(n.zM,{asChild:!0,children:(0,i.jsx)(D.$,{size:"sm",children:p("createBoardCta")})}),(0,i.jsxs)(n.Cf,{children:[(0,i.jsx)(n.c7,{children:(0,i.jsx)(n.L3,{children:p("createBoardTitle")})}),(0,i.jsxs)("form",{className:"space-y-3 mt-2",onSubmit:e=>{e.preventDefault(),g.trim()&&!f&&(j(null),x(async()=>{try{let e=await at(t,{name:g.trim(),description:b.trim()||void 0});if(!e||e.error){let t=(null==e?void 0:e.error)||p("createError");j("string"==typeof t?t:p("createError"));return}let i=e.data;await h(),(null==i?void 0:i.id)&&a(i.id),v(""),y(""),N(!1)}catch(e){console.error("Error creating Pinterest board:",e),j(p("createError"))}}))},children:[(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsx)(ey.J,{htmlFor:"pinterest-board-name",className:"text-xs",children:p("nameLabel")}),(0,i.jsx)(t0.p,{id:"pinterest-board-name",value:g,onChange:e=>v(e.target.value),placeholder:p("namePlaceholder"),className:"h-8 text-xs"})]}),(0,i.jsxs)("div",{className:"space-y-1",children:[(0,i.jsx)(ey.J,{htmlFor:"pinterest-board-description",className:"text-xs",children:p("descriptionLabel")}),(0,i.jsx)(t0.p,{id:"pinterest-board-description",value:b,onChange:e=>y(e.target.value),placeholder:"",className:"h-8 text-xs"})]}),w&&(0,i.jsx)("p",{className:"text-xs text-destructive",children:w}),(0,i.jsx)("div",{className:"flex justify-end pt-2",children:(0,i.jsxs)(D.$,{type:"submit",size:"sm",disabled:f||!g.trim(),children:[f&&(0,i.jsx)(tT.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),f?p("creating"):p("submit")]})})]})]})]})]}):(0,i.jsx)("div",{className:"space-y-2 mb-2",children:(0,i.jsxs)(ew.Select,{value:r,onValueChange:a,children:[(0,i.jsx)(ew.SelectTrigger,{fieldLabel:s?p("boardInlineLabel"):void 0,className:l||"w-full bg-transparent border-input focus:ring-0 focus:ring-offset-0 focus:outline-none",children:(0,i.jsx)(ew.SelectValue,{placeholder:p("selectPlaceholder")})}),(0,i.jsx)(ew.SelectContent,{className:"[&_[role=option]]:text-sm",children:(0,i.jsx)(ew.s3,{children:c.map(e=>(0,i.jsx)(ew.SelectItem,{value:e.id,className:"data-[state=checked]:bg-transparent data-[state=checked]:text-foreground focus-visible:ring-0 focus-visible:ring-offset-0 outline-none focus:outline-none",children:e.name},e.id))})})]})})}let ai=(0,tp.createServerReference)("60643735f16c1baaea2de066f14cf68eb6686cf724",tp.callServer,void 0,tp.findSourceMapURL,"getPinterestBoardSections"),an={};function ar(e){let{accountId:t,boardId:a,value:n,onChange:r,className:l}=e,s=(0,o.useTranslations)("CreatePost.pinterest"),{sections:c,isLoading:u}=function(e,t){let[a,i]=(0,d.useState)([]),[n,r]=(0,d.useState)(!1),[l,s]=(0,d.useState)(null),o=t?"".concat(e,":").concat(t):"",c=(0,d.useCallback)(async function(){let a=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!e||!t)return;let n=Date.now(),l=an[o];if(!a&&l&&n-l.timestamp<3e5){i(l.sections),s(l.error||null),r(!1);return}try{r(!0),s(null);let a=await ai(e,t);if(a.error)throw Error(a.error);let l=a.data||[];an[o]={sections:l,timestamp:n},i(l)}catch(t){let e="Failed to load board sections";an[o]={sections:[],timestamp:n,error:e},s(e),console.error("Error fetching Pinterest board sections:",t)}finally{r(!1)}},[e,t,o]);return(0,d.useEffect)(()=>
1{if(!t){i([]),s(null),r(!1);return}i([]),s(null),c(!0)},[c,t]),{sections:a,isLoading:n,error:l,refetch:(0,d.useCallback)(()=>c(!0),[c])}}(t,a);return a&&0!==c.length?(0,i.jsx)("div",{className:"space-y-2 mb-2",children:(0,i.jsxs)(ew.Select,{value:null!=n?n:"__root__",onValueChange:e=>r("__root__"===e?"":e),disabled:u,children:[(0,i.jsx)(ew.SelectTrigger,{fieldLabel:s("sectionInlineLabel"),className:l||"w-full bg-transparent border-input focus:ring-0 focus:ring-offset-0 focus:outline-none",children:(0,i.jsx)(ew.SelectValue,{placeholder:s("sectionSelectPlaceholder")})}),(0,i.jsx)(ew.SelectContent,{className:"[&_[role=option]]:text-sm",children:(0,i.jsxs)(ew.s3,{children:[(0,i.jsx)(ew.SelectItem,{value:"__root__",children:s("sectionNone")}),c.map(e=>(0,i.jsx)(ew.SelectItem,{value:e.id,children:e.name},e.id))]})})]})}):null}function al(e){var t,a,n,r;let{accountId:l,pinLink:s}=e,{payloads:o,updatePayload:c}=I(),u=(null==(a=o[l])||null==(t=a.pinterest)?void 0:t.board)||"",m=(null==(r=o[l])||null==(n=r.pinterest)?void 0:n.section)||"",h=(0,d.useCallback)(e=>{var t;c(l,{postType:"pin",pinterest:{...null==(t=o[l])?void 0:t.pinterest,board:e,section:void 0},platformPayload:{settings:{board:e,section:void 0}}})},[l,c,o]),p=(0,d.useCallback)(e=>{var t;let a=e||void 0;c(l,{pinterest:{...null==(t=o[l])?void 0:t.pinterest,section:a},platformPayload:{settings:{board:u,...a&&{section:a}}}})},[l,u,c,o]);return(0,i.jsxs)("div",{className:s?"grid grid-cols-1 gap-2 md:grid-cols-2 md:items-end md:gap-x-3":"flex flex-col gap-2 md:flex-row md:items-end md:gap-3",children:[(0,i.jsx)("div",{className:"min-w-0 flex-1",children:(0,i.jsx)(aa,{accountId:l,value:u,onChange:h})}),s,(0,i.jsx)(ar,{accountId:l,boardId:u,value:m,onChange:p})]})}let as={feed:tO.A,reel:t5.A,story:t6.A,carousel:t8.A,post:tO.A,article:t8.A,shorts:t5.A,pin:tO.A,tweet:tO.A,video:t5.A,short:t5.A,standard:tO.A,event:t6.A,offer:t8.A,media:t5.A};function ao(e){let{platform:t,value:a,onChange:n,accountId:r,disabledTypes:l,pinterestPinLink:s}=e,d=(0,o.useTranslations)("CreatePost.postType"),{postTypes:u,shouldShowPostTypeSelector:m}=t9(t);if(t===c.SocialPlatform.PINTEREST)return r?(0,i.jsx)(al,{accountId:r,pinLink:s}):(console.error("AccountId is required for Pinterest post type selector"),null);if(!m)return null;let h=Object.entries(u),p=u[a],f=as[a]||tO.A,x=e=>d(e)||e.charAt(0).toUpperCase()+e.slice(1);return(0,i.jsxs)(ew.Select,{value:a,onValueChange:n,children:[(0,i.jsx)(ew.SelectTrigger,{fieldLabel:d("inlineLabel"),className:"w-full bg-card dark:bg-card",children:(0,i.jsx)(ew.SelectValue,{children:(0,i.jsx)("div",{className:"flex min-w-0 items-center gap-2",children:p&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(f,{className:"h-4 w-4 shrink-0"}),(0,i.jsx)("span",{className:"truncate",children:x(a)})]})})})}),(0,i.jsx)(ew.SelectContent,{className:"[&_[role=option]]:text-sm bg-card dark:bg-card",children:h.map(e=>{var t;let[a,n]=e,r=as[a]||tO.A,s=null!=(t=null==l?void 0:l.includes(a))&&t;return(0,i.jsx)(ew.SelectItem,{value:a,disabled:s,children:(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,i.jsx)(r,{className:"h-4 w-4"}),(0,i.jsx)("span",{children:x(a)})]})},a)})})]})}var ad=a(81295),ac=a.n(ad),au=a(93832),am=a(43945),ah=a(64442),ap=a(48623),af=a(15410),ax=a(88146),ag=a(53623);function av(e){let{onSnippetSelect:t,isOpen:a,onOpenChange:n,isTooltipVisible:r,setTooltipVisible:l,collections:s,isLoading:c,error:u,onCreateNew:h}=e,p=(0,o.useTranslations)("CreatePost.textSnippetSelector"),[f,x]=(0,d.useState)(new Set);return(0,i.jsxs)(V.rI,{open:a,onOpenChange:n,modal:!1,children:[(0,i.jsxs)(O.Tooltip,{open:r&&!a,children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(V.ty,{asChild:!0,children:(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),"aria-label":p("addTextSnippetsAria"),children:(0,i.jsx)(ag.A,{className:"h-4 w-4"})})})}),(0,i.jsx)(O.TooltipContent,{side:"bottom",children:(0,i.jsx)("p",{children:p("addTextSnippetsTooltip")})})]}),(0,i.jsxs)(V.SQ,{className:"w-80 p-2",side:"bottom",align:"start",sideOffset:5,children:[c?(0,i.jsx)("div",{className:"flex items-center justify-center p-4",children:(0,i.jsx)(tT.A,{className:"h-4 w-4 animate-spin"})}):u?(0,i.jsx)("div",{className:"p-4 text-sm text-center text-destructive",children:u}):0===s.length?(0,i.jsx)("div",{className:"p-4 text-sm text-center text-muted-foreground",children:p("noCollectionsFound")}):(0,i.jsx)("div",{className:"max-h-[300px] overflow-hidden",children:(0,i.jsx)(eT.F,{className:"h-[300px]",children:(0,i.jsx)("div",{className:"space-y-2 pb-12",children:s.map(e=>{var a,r,l;return(0,i.jsxs)("div",{className:"space-y-2 border rounded-md p-2.5",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between",children:[(0,i.jsx)("h5",{className:"font-medium text-xs",children:e.name}),(0,i.jsx)(D.$,{variant:"outline",size:"xs",className:"font-medium",onClick:()=>{t(e.snippets),n(!1)},children:(null!=(l=null==(a=e.snippets)?void 0:a.length)?l:0)>1?p("addAll"):p("add")})]}),(0,i.jsx)("div",{className:"space-y-2",children:null==(r=e.snippets)?void 0:r.map((e,t)=>(0,i.jsx)("button",{type:"button",onClick:()=>{x(t=>{let a=new Set(t);return a.has(e)?a.delete(e):a.add(e),a})},className:(0,m.cn)("w-full text-left p-2 rounded-md text-xs transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",f.has(e)?"bg-primary text-primary-foreground hover:bg-primary/90":"bg-secondary text-secondary-foreground hover:bg-secondary/80"),children:(0,i.jsx)("span",{className:"line-clamp-2 whitespace-pre-wrap",children:e.length>60?"".concat(e.substring(0,60),"..."):e})},"".concat(e,"-").concat(t)))})]},e.id)})})})}),f.size>0?(0,i.jsx)("div",{className:(0,m.cn)("relative z-10 -mx-2 -mb-2 bg-popover/60 p-2 backdrop-blur-md",!(s.length>0)||c||u?"mt-2":"-mt-12"),children:(0,i.jsxs)("div",{className:"flex items-center justify-between",children:[(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:p("selectedCount",{count:f.size})}),(0,i.jsx)(D.$,{variant:"outline",size:"sm",className:"font-medium",onClick:()=>{0!==f.size&&(t(Array.from(f)),x(new Set),n(!1))},children:p("add")})]})}):h?(0,i.jsx)("div",{className:(0,m.cn)("relative z-10 -mx-2 -mb-2 bg-popover/60 p-2 backdrop-blur-md",!(s.length>0)||c||u?"mt-2":"-mt-12"),children:(0,i.jsxs)(D.$,{variant:"outline",size:"sm",className:"w-full font-medium !bg-transparent",onClick:()=>{h&&(h(),n(!1))},children:[(0,i.jsx)(_.A,{className:"h-3.5 w-3.5"}),p("createNew")]})}):null]})]})}function ab(e,t){let a=t.join("\n\n");return e.trim()?"".concat(e,"\n\n").concat(a):a}var ay=a(98755);function aw(e){let{isOpen:t,onOpenChange:a,searchQuery:n,searchResults:r,isSearching:l,searchError:s,onSelect:o,position:c,_accountId:u}=e,[h,p]=(0,d.useState)(-1),[f,x]=(0,d.useState)(new Set),g=(0,d.useRef)(null),v=(0,d.useRef)(null);if((0,d.useEffect)(()=>{p(-1),x(new Set)},[r]),(0,d.useEffect)(()=>{v.current&&g.current&&v.current.scrollIntoView({block:"nearest",behavior:"smooth"})},[h]),(0,d.useEffect)(()=>
1{if(!t)return;let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),p(e=>e<r.length-1?-1===e?0:e+1:e)):"ArrowUp"===e.key?(e.preventDefault(),p(e=>e>0?e-1:0)):"Enter"===e.key?(e.preventDefault(),r[h]&&o(r[h])):"Escape"===e.key&&(e.preventDefault(),a(!1))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r,h,o,a]),!t)return null;let b=e=>"organization"===e.type?e.name||e.firstName||"Unknown Organization":"".concat(e.firstName," ").concat(e.lastName).trim()||"Unknown";return(0,i.jsxs)(ev.AM,{open:t,onOpenChange:a,children:[(0,i.jsx)(ev.Wv,{asChild:!0,children:(0,i.jsx)("div",{className:"hidden"})}),(0,i.jsx)(ev.hl,{className:"w-80 p-0",style:c?{position:"fixed",top:"".concat(c.top,"px"),left:"".concat(c.left,"px"),transform:"none"}:void 0,side:c?void 0:"bottom",align:c?void 0:"start",sideOffset:5*!c,onOpenAutoFocus:e=>e.preventDefault(),children:l?(0,i.jsxs)("div",{className:"flex items-center justify-center p-4",children:[(0,i.jsx)(tT.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,i.jsx)("span",{className:"ml-2 text-sm text-muted-foreground",children:"Searching..."})]}):s?(0,i.jsxs)("div",{className:"p-4 text-sm text-center text-destructive",children:[s,s.includes("Community Management API")&&(0,i.jsx)("div",{className:"mt-2 text-xs text-muted-foreground",children:"Please request access in LinkedIn Developer Portal"})]}):!n.trim()||n.trim().length<3?(0,i.jsx)("div",{className:"p-4 text-sm text-center text-muted-foreground",children:"Type at least 3 characters to search"}):0===r.length?(0,i.jsxs)("div",{className:"p-4 text-sm text-center text-muted-foreground",children:['No results found for "',n,'"']}):(0,i.jsx)(eT.F,{className:"max-h-[300px]",ref:g,children:(0,i.jsx)("div",{className:"p-2",children:r.map((e,t)=>(0,i.jsxs)("button",{ref:t===h?v:null,type:"button",onClick:()=>{o(e),a(!1)},onMouseEnter:()=>p(t),className:(0,m.cn)("w-full grid grid-cols-[auto_1fr] gap-3 p-2 rounded-md text-left transition-colors overflow-hidden","hover:bg-accent focus:bg-accent focus:outline-none",t===h&&"bg-accent"),children:[(0,i.jsx)("div",{className:"flex-shrink-0 w-10 h-10 rounded-full overflow-hidden bg-muted flex items-center justify-center relative",children:e.photo&&e.photo.trim()&&!f.has(e.member)?(0,i.jsx)("img",{src:e.photo,alt:b(e),className:"w-full h-full object-cover",crossOrigin:"anonymous",referrerPolicy:"no-referrer",onError:()=>{x(t=>new Set(t).add(e.member))}}):(e=>{var t,a,n;let r="organization"===(t=e).type?(t.name||t.firstName||"").substring(0,2).toUpperCase()||"OR":(((null==(a=t.firstName)?void 0:a.charAt(0))||"")+((null==(n=t.lastName)?void 0:n.charAt(0))||"")).toUpperCase()||"U";return(0,i.jsx)("div",{className:"w-full h-full flex items-center justify-center text-xs font-medium text-muted-foreground bg-muted",children:r})})(e)}),(0,i.jsxs)("div",{className:"min-w-0 overflow-hidden flex flex-col justify-center",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between gap-2 w-full",children:[(0,i.jsx)("div",{className:"font-medium text-sm truncate",title:b(e),children:b(e)}),"organization"===e.type&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground px-1.5 py-0.5 rounded bg-muted/50 flex-shrink-0",children:"SCHOOL"===e.primaryOrganizationType?"School":"Company"})]}),e.headline&&(0,i.jsx)("div",{className:"text-xs text-muted-foreground truncate",title:e.headline,children:e.headline})]})]},e.member))})})})]})}var aj=a(91053),aC=a(36088);function aN(e){var t;let{accountId:a,payload:n,updatePayload:r,isAILoading:l=!1,onAIGenerate:s,onCopyField:u,platform:h,label:p,isYouTube:f=!1,isPremium:x,validation:g,onCreateHashtag:v,onCreateSnippet:b,selectedAccountsCount:y=1,onSelectMedia:w,isUploading:j=!1,noBorder:C=!1,matchMediaHeight:N=!1}=e,S=(0,d.useRef)(null),[k,T]=(0,d.useState)(0),[E,A]=(0,d.useState)(!1);(0,d.useEffect)(()=>{let e=window.matchMedia("(min-width: 768px)"),t=()=>A(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),(0,d.useEffect)(()=>{var e,t,a;if(!N)return void T(0);let i=null==(t=S.current)||null==(e=t.closest("[data-post-editor-row]"))?void 0:e.querySelector("[data-media-preview]");if(!i)return;let n=window.matchMedia("(min-width: 768px)"),r=()=>{let e=S.current;T(n.matches&&e?Math.max(0,Math.ceil(i.getBoundingClientRect().bottom-e.getBoundingClientRect().top)):0)},l=new ResizeObserver(r);return l.observe(i),(null==(a=S.current)?void 0:a.parentElement)&&l.observe(S.current.parentElement),n.addEventListener("change",r),r(),()=>{l.disconnect(),n.removeEventListener("change",r)}},[N]);let P=Math.max(200,k-2*!C),M={minHeight:P,height:E?P:void 0,maxHeight:E?P:Math.max(400,P)},R=(0,d.useRef)(null),[F,z]=(0,d.useState)(0),[L,U]=(0,d.useState)(!1),[_,B]=(0,d.useState)(!1),K=(0,ah.Y)(),[G,W]=(0,d.useState)({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V=(0,d.useRef)(""),q=h===c.SocialPlatform.LINKEDIN||h===c.SocialPlatform.LINKEDIN_ORGANIZATION,{searchMentions:H,searchResults:$,isSearching:Y,searchError:X,insertMention:Z,parseMentions:J,formatForDisplay:Q}=function(){let[e,t]=(0,d.useState)([]),[a,i]=(0,d.useState)(!1),[n,r]=(0,d.useState)(null),l=(0,d.useCallback)(e=>{let t,a=[],i=/@\[([^\]]+)\]\((urn:li:[^)]+)\)/g;for(;null!==(t=i.exec(e));){let e=t[2];a.push({name:t[1],urn:e,startIndex:t.index,endIndex:t.index+t[0].length})}return a},[]),s=(0,d.useCallback)(async(e,a)=>{if(!e||0===e.trim().length){t([]),i(!1);return}let n=e.trim();if(n.length<3){t([]),r(null),i(!1);return}i(!0),r(null);try{var l;let e="/api/queries/linkedin/mentions?keywords=".concat(encodeURIComponent(n),"&accountId=").concat(encodeURIComponent(a)),i=await fetch(e);if(!i.ok){let e="Failed to search mentions";try{let t=await i.json();e=t.error||t.message||e}catch(t){e=i.statusText||e}
1403===i.status?r("Community Management API access required. Please request access in LinkedIn Developer Portal."):404===i.status?r("Social account not found"):r(e),t([]);return}let s=(null==(l=(await i.json()).data)?void 0:l.members)||[];t(s),r(null)}catch(e){console.error("Mention search error:",e),r(e instanceof Error?e.message:"Failed to search mentions"),t([])}finally{i(!1)}},[]),o=(0,d.useCallback)(e=>{let t=l(e),a=e;return t.reverse().forEach(e=>{a=a.substring(0,e.startIndex)+"**@".concat(e.name,"**")+a.substring(e.endIndex)}),a},[l]),c=(0,d.useCallback)((e,t,a)=>{let i=e.substring(0,t).lastIndexOf("@");if(-1===i)return{newText:e,newCursorPosition:t};let n=a.name||"".concat(a.firstName," ").concat(a.lastName).trim(),r="@[".concat(n,"](").concat(a.member,")");return{newText:e.substring(0,i)+r+e.substring(t),newCursorPosition:i+r.length}},[]),u=(0,d.useCallback)(e=>{let t=l(e),a=e;return t.reverse().forEach(e=>{a=a.substring(0,e.startIndex)+e.name+a.substring(e.endIndex)}),a},[l]),m=(0,d.useCallback)((e,t)=>{let a=l(t),i=e,n=0;return a.forEach(e=>{let t=i.indexOf(e.name,n);if(-1!==t){let a=i.substring(0,t),r=i.substring(t+e.name.length);i=a+"@[".concat(e.name,"](").concat(e.urn,")")+r,n=t+"@[".concat(e.name,"](").concat(e.urn,")").length}}),i},[l]);return{searchMentions:s,searchResults:e,isSearching:a,searchError:n,parseMentions:l,formatTextForDisplay:o,insertMention:c,formatForDisplay:u,formatForStorage:m}}(),ee=(0,d.useRef)(null),et=(0,d.useRef)(!1),ea=(0,d.useCallback)((e,t)=>{let a=J(t);e.innerHTML="";let i=0;if(a.forEach(a=>{if(a.startIndex>i){let n=document.createTextNode(t.substring(i,a.startIndex));e.appendChild(n)}let n=document.createElement("span");n.className="font-bold",n.setAttribute("data-mention","@[".concat(a.name,"](").concat(a.urn,")")),n.contentEditable="false",n.textContent=a.name,e.appendChild(n),i=a.endIndex}),i<t.length){let a=document.createTextNode(t.substring(i));e.appendChild(a)}},[J]),ei=(0,d.useCallback)(e=>{let t="",a=e=>{if(e.nodeType===Node.TEXT_NODE)t+=e.textContent||"";else if(e.nodeType===Node.ELEMENT_NODE){let i=e.getAttribute("data-mention"),n=e.tagName.toUpperCase();if(i)t+=i;else if("BR"===n)t+="\n";else{for(let t=0;t<e.childNodes.length;t++)a(e.childNodes[t]);"DIV"!==n&&"P"!==n||t.endsWith("\n")||(t+="\n")}}};for(let t=0;t<e.childNodes.length;t++)a(e.childNodes[t]);return t},[]),en=(0,d.useCallback)(e=>{if(ee.current=e,e&&q){let t=ei(e),a=n.content||"";t!==a&&ea(e,a)}},[q,n.content,ei,ea]);(0,d.useEffect)(()=>{if(q&&ee.current){let e=ee.current,t=ei(e),a=n.content||"";t!==a&&ea(e,a)}},[q,n.content,ei,ea,F]);let er=(0,aC.d)(G.searchQuery,300);(0,d.useEffect)(()=>{q&&G.isActive&&er&&er.trim().length>=3&&H(er.trim(),a)},[er,G.isActive,q,a,H]);let el=(0,d.useRef)(!1);(0,d.useEffect)(()=>{el.current||(n.content&&""!==n.content.trim()&&eR.current.reset(n.content),el.current=!0)},[]);let es=t9(h,h===c.SocialPlatform.X?x:void 0),eo=(f?5e3:es.maxTextLength)-((null==(t=n.content)?void 0:t.length)||0),ed=(0,o.useTranslations)("CreatePost.captionEditor"),ec=(0,o.useTranslations)("CreatePost.mediaSection"),{hashtagCollections:eu,textSnippetCollections:em,isLoadingHashtagsAndSnippets:eh,selectedAccounts:ep,captionSyncEnabled:ef}=I(),{isEmojiPickerOpen:ex,isHashtagPopoverOpen:eg,isTextSnippetPopoverOpen:ev,isAIDropdownOpen:eb,isHashtagTooltipVisible:ew,isTextSnippetTooltipVisible:ej,isEmojiTooltipVisible:eC,isAITooltipVisible:eN,setIsHashtagTooltipVisible:eS,setIsTextSnippetTooltipVisible:ek,setIsEmojiTooltipVisible:eT,setIsAITooltipVisible:eE,handleHashtagOpenChange:eI,handleTextSnippetOpenChange:eA,handleEmojiOpenChange:eP,handleAIOpenChange:eM}=(0,aj.$)(),eD=(0,d.useRef)(l),eR=(0,d.useRef)(K);eR.current=K;let[eF,eO]=(0,d.useState)(!1),[ez,eL]=(0,d.useState)(void 0),eU=(0,d.useRef)(!1),e_=(0,d.useRef)(!1);(0,d.useEffect)(()=>{l&&!eD.current&&(eU.current=!0),!l&&eD.current&&(eR.current.addToHistory(n.content||""),z(e=>e+1),eU.current&&(eL(n.content),eO(!0),eU.current=!1,e_.current=!0)),eD.current=l},[l,n.content]);let eB=(0,d.useCallback)(e=>{if(q&&ee.current){let t,i=ee.current,n=window.getSelection();n&&n.rangeCount>0&&i.contains(n.anchorNode)?t=n.getRangeAt(0):((t=document.createRange()).selectNodeContents(i),t.collapse(!1));
1let l=document.createTextNode(e.emoji);t.insertNode(l),t.collapse(!1),n&&(n.removeAllRanges(),n.addRange(t)),r(a,{content:ei(i)});return}let t=R.current;if(!t)return;let i=t.selectionStart,n=t.selectionEnd,l=t.value||"";r(a,{content:l.substring(0,i)+e.emoji+l.substring(n)}),setTimeout(()=>{t.focus(),t.selectionStart=t.selectionEnd=i+e.emoji.length},0)},[a,r,q,ei]),eK=(0,d.useCallback)(e=>{if(q&&ee.current){let t=ee.current,i=ei(t),n=i.includes("#"),l="";if(n){let e=i.lastIndexOf("#");l=i.substring(e).includes("\n")?"\n\n":" "}else l="\n\n";i.trim()||(l="");let s=document.createTextNode(l+e.join(" "));t.appendChild(s),r(a,{content:ei(t)});return}let t=R.current;if(!t)return;let i=t.value||"",n=i;if(i.includes("#")){let t=i.lastIndexOf("#");n=i.substring(t).includes("\n")?i+"\n\n"+e.join(" "):i+" "+e.join(" ")}else n=i+"\n\n"+e.join(" ");r(a,{content:n}),setTimeout(()=>{t.focus(),t.selectionStart=t.selectionEnd=n.length},0)},[a,r,q,ei]),eG=(0,d.useCallback)(e=>{if(q&&ee.current){let t=ee.current,i=ab(ei(t),e);ea(t,i),r(a,{content:i});return}let t=R.current;if(!t)return;let i=ab(t.value||"",e);r(a,{content:i}),setTimeout(()=>{t.focus(),t.selectionStart=t.selectionEnd=i.length},0)},[a,r,q,ei,ea]),eW=(0,d.useCallback)(async(e,t,a)=>{if(s){n.content&&""!==n.content.trim()&&eR.current.addToHistory(n.content);let i="write"===e?n.content:void 0;await s(e,i,t,a)}},[s]),eV=(0,d.useCallback)(()=>{if(!n.content||""===n.content.trim())return void console.warn("Cannot copy empty content.");u&&u(a,"content")},[a,u,n.content]),eq=(0,d.useCallback)(()=>{if(q&&ee.current){let e=ee.current,t=window.getSelection();if(!t||0===t.rangeCount)return null;let a=t.getRangeAt(0).getBoundingClientRect(),i=e.getBoundingClientRect();return{top:a.bottom+5,left:Math.min(a.left,i.right-320)}}let e=R.current;if(!e)return null;try{let t=e.selectionStart,a=e.value.substring(0,t),i=a.lastIndexOf("@");if(-1===i)return null;let n=a.split("\n").length-1,r=a.lastIndexOf("\n")+1,l=a.substring(r),s=document.createElement("span");s.style.visibility="hidden",s.style.position="absolute",s.style.whiteSpace="pre-wrap",s.style.wordWrap="break-word",s.style.font=window.getComputedStyle(e).font,s.style.padding=window.getComputedStyle(e).padding,s.style.border=window.getComputedStyle(e).border,s.style.width="".concat(e.offsetWidth,"px"),s.textContent=l,document.body.appendChild(s);let o=Math.min(s.offsetWidth,e.offsetWidth-20);document.body.removeChild(s);let d=e.getBoundingClientRect(),c=e.scrollTop,u=parseInt(window.getComputedStyle(e).lineHeight)||20,m=parseInt(window.getComputedStyle(e).paddingTop)||0,h=d.top+m+(n+1)*u-c+5,p=d.left+Math.min(o+10,d.width-320);return{top:h,left:p}}catch(e){return null}},[q]),eH=(0,d.useCallback)(e=>{null==g||g.onFieldChange(f?"description":"content");let t=e.target.value;if(r(a,{content:t}),q&&G.isActive){let a=e.target.selectionStart,i=t.substring(0,a),n=i.lastIndexOf("@");if(-1!==n){let e=i.substring(n+1),t=e.indexOf("\n");-1!==t&&(e=e.substring(0,t));let a=eq();W(t=>({...t,searchQuery:e,position:a}))}else W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current=""}},[a,r,g,f,q,G.isActive,eq]),e$=(0,d.useCallback)(e=>{if(!q)return;let t=e.currentTarget,i=t.selectionStart,n=t.value.substring(0,i);if("@"===e.key||"Backspace"!==e.key&&n.endsWith("@")){let t=eq();W({isActive:!0,startIndex:i-("@"!==e.key),searchQuery:"",position:t}),V.current="@";return}if(G.isActive){if("Backspace"===e.key){let e=n.lastIndexOf("@");if(-1===e||i<=e){W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current="";return}let t=n.substring(e+1,i-1),a=eq();W(e=>({...e,searchQuery:t,position:a})),V.current=t.slice(-1)||"";return}if(" "===e.key){if(" "===V.current){e.preventDefault(),W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current="",r(a,{content:t.value.substring(0,i)+" "+t.value.substring(i)}),setTimeout(()=>{t.focus(),t.selectionStart=t.selectionEnd=i+1},0);return}V.current=" ";let l=n.lastIndexOf("@"),s=n.substring(l+1)+" ",o=eq();W(e=>({...e,searchQuery:s,position:o}));return}1!==e.key.length||e.ctrlKey||e.metaKey||e.altKey||(V.current=e.key),"Enter"===e.key&&G.isActive&&(W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current="")}},[q,G.isActive,a,r,eq]),eY=(0,d.useCallback)(e=>{if(q&&ee.current){var t;let i=ee.current,n=window.getSelection(),l=null==n?void 0:n.getRangeAt(0);if(!l)return;let s=l.startContainer,o=((null==(t=s.textContent)?void 0:t.substring(0,l.startOffset))||"").lastIndexOf("@");if(-1===o)return;let d=e.name||"".concat(e.firstName," ").concat(e.lastName).trim(),c=document.createElement("span");c.className="font-bold",c.setAttribute("data-mention","@[".concat(d,"](").concat(e.member,")")),c.textContent=d,c.contentEditable="false";let u=document.createRange();u.setStart(s,o),u.setEnd(s,l.startOffset),u.deleteContents(),u.insertN
1ode(c);let m=window.getSelection();if(m){m.removeAllRanges();let e=document.createRange();e.setStartAfter(c),e.collapse(!0),m.addRange(e)}r(a,{content:ei(i)}),W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current=""}else{let t=R.current;if(!t)return;let i=t.selectionStart,{newText:n,newCursorPosition:l}=Z(t.value,i,e);r(a,{content:n}),W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current="",setTimeout(()=>{t.focus(),t.selectionStart=t.selectionEnd=l},0)}},[a,r,Z,q,ei]),eX=(0,d.useCallback)(()=>{r(a,{content:eR.current.undo()}),setTimeout(()=>{R.current&&R.current.focus()},10)},[a,r]),eZ=(0,d.useCallback)(()=>{r(a,{content:eR.current.redo()}),setTimeout(()=>{R.current&&R.current.focus()},10)},[a,r]);return(0,i.jsxs)("div",{ref:S,className:"flex flex-col gap-2 w-full",children:[p&&(0,i.jsx)("div",{className:"flex items-center justify-between",children:(0,i.jsx)(ey.J,{htmlFor:"caption-".concat(a),children:p})}),(0,i.jsxs)("div",{className:"relative min-h-[200px] h-auto",children:[q?(0,i.jsxs)("div",{style:{minHeight:P+2*!C,height:E?P+2*!C:void 0,maxHeight:E?P+2*!C:Math.max(400,k)},className:(0,m.cn)("w-full min-h-[200px] h-full max-h-[400px] overflow-y-auto ai-chat-scrollbar roun
1ded-md transition-colors relative",!C&&(L?"border":"border border-input")),children:[(0,i.jsx)(au.N,{children:eF&&ez&&(0,i.jsx)(am.P.div,{initial:{clipPath:"polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)"},animate:{clipPath:"polygon(100% 0%, 100% 0%, 100% 100%, 100% 100%)"},exit:{clipPath:"polygon(100% 0%, 100% 0%, 100% 100%, 100% 100%)"},transition:{duration:.4,ease:"easeInOut"},className:"absolute inset-0 z-10 pointer-events-none rounded-md overflow-hidden",children:(0,i.jsx)("div",{className:"absolute inset-0 bg-clip-text text-transparent px-3 py-2 text-base md:text-sm whitespace-pre-wrap break-words bg-[linear-gradient(to_right,#fecdd3,#f5d0fe,#bae6fd,#f5d0fe,#fecdd3)] dark:bg-[linear-gradient(to_right,#9f1239,#86198f,#075985,#86198f,#9f1239)]",style:{backgroundSize:"200% auto",animation:"gradient 1.5s linear infinite"},children:Q(ez||"")})},"fade-out-previous")}),(0,i.jsx)(au.N,{initial:!1,children:(0,i.jsxs)(am.P.div,{initial:!!e_.current&&{clipPath:"polygon(0% 0%, 0% 0%, 0% 100%, 0% 100%)",opacity:1},animate:e_.current?{clipPath:"polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)",opacity:1}:{opacity:1},exit:{opacity:0,transition:{duration:0}},transition:{duration:.4,ease:"easeInOut"},className:"relative z-0 w-full h-full min-h-[200px]",onAnimationComplete:()=>eO(!1),children:[(0,i.jsx)("div",{style:M,ref:en,contentEditable:!(l||eF),suppressContentEditableWarning:!0,onInput:e=>{if(et.current)return;let t=ei(e.currentTarget);et.current=!0,r(a,{content:t}),et.current=!1,null==g||g.onFieldChange(f?"description":"content");let i=window.getSelection();if(i&&i.rangeCount>0){var n;let e=i.getRangeAt(0),t=(null==(n=e.startContainer.textContent)?void 0:n.substring(0,e.startOffset))||"",a=t.lastIndexOf("@");if(-1!==a){let e=t.substring(a+1);W({isActive:!0,startIndex:a,searchQuery:e,position:eq()})}else G.isActive&&W({isActive:!1,startIndex:-1,searchQuery:"",position:null})}},onKeyDown:e=>{if(!q)return;let t=e.currentTarget,i=window.getSelection();if(!i||0===i.rangeCount)return;let n=i.getRangeAt(0);if("Backspace"===e.key||"Delete"===e.key){var l;let i=null==(l=n.startContainer.parentElement)?void 0:l.closest("[data-mention]");if(i){e.preventDefault(),i.remove(),r(a,{content:ei(t)});return}}if("@"===e.key){let e=eq();W({isActive:!0,startIndex:n.startOffset,searchQuery:"",position:e}),V.current="@"}G.isActive&&" "===e.key&&(" "===V.current?(e.preventDefault(),W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current=""):V.current=" ")},onFocus:()=>{if(U(!0),null==g||g.onFieldFocus(f?"description":"content"),G.isActive){let e=eq();W(t=>({...t,position:e}))}},onBlur:()=>{U(!1),null==g||g.onFieldBlur(f?"description":"content")},"data-placeholder":ed("placeholder"),className:"jsx-6eb4513f3ea75287 "+((0,m.cn)("min-h-[200px] h-auto max-h-[400px] w-full resize-none bg-transparent px-3 py-2 text-base md:text-sm shadow-xs outline-none transition-[color,box-shadow] disabled:cursor-not-allowed disabled:opacity-50 whitespace-pre-wrap break-words",w?"pb-24 sm:pb-12":"pb-8",C&&"shadow-none",E&&"overflow-y-auto ai-chat-scrollbar","placeholder:text-muted-foreground","focus-visible:ring-0 focus-visible:ring-offset-0",eF||l?"text-transparent":"text-foreground",(l||eF)&&"cursor-not-allowed opacity-50")||"")}),(0,i.jsx)(ac(),{id:"6eb4513f3ea75287",children:"[contenteditable][data-placeholder]:empty:before{content:attr(data-placeholder);color:hsl(var(--muted-foreground)/.6);pointer-events:none}"}),(0,i.jsx)(au.N,{children:(l||eF)&&(0,i.jsx)(am.P.div,{className:"absolute inset-0 z-20 pointer-events-none rounded-md overflow-hidden",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{opacity:{duration:.3}},children:(0,i.jsx)("div",{style:{backgroundSize:"200% auto",animation:"gradient 1.5s linear infinite"},className:"jsx-6eb4513f3ea75287 absolute inset-0 bg-clip-text text-transparent px-3 py-2 text-base md:text-sm whitespace-pre-wrap break-words bg-[linear-gradient(to_right,#fecdd3,#f5d0fe,#bae6fd,#f5d0fe,#fecdd3)] dark:bg-[linear-gradient(to_right,#9f1239,#86198f,#075985,#86198f,#9f1239)]",children:Q(n.content||"")||" "})},"ai-overlay-".concat(l?"loading":"revealing"))})]},e_.current?F:"static")})]}):(0,i.jsx)(ap.b,{noBorder:C,style:M,ref:R,id:"caption-".concat(a),placeholder:ed("placeholder"),value:n.content||"",onChange:eH,onKeyDown:e$,onFocus:()=>{null==g||g.onFieldFocus(f?"description":"content")},onBlur:()=>{null==g||g.onFieldBlur(f?"description":"content")},className:(0,m.cn)("block min-h-[200px] h-auto max-h-[400px] overflow-y-auto ai-chat-scrollbar resize-none pr-3 text-base md:text-sm",w?"pb-24 sm:pb-12":"pb-8","border-input bg-transparent transition-[border-color,box-shadow]","placeholder:text-muted-foreground/60","focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:border-primary/20"),autoResize:!E,isLoading:l,aiContentVersion:F}),q&&(0,i.jsx)(aw,{isOpen:G.isActive,onOpenChange:e=>{e||(W({isActive:!1,startIndex:-1,searchQuery:"",position:null}),V.current="")},searchQuery:G.searchQuery,searchResults:$,isSearching:Y,searchError:X,onSelect:eY,position:G.position||void 0,_accountId:a}),(0,i.jsxs)("div",{className:(0,m.cn)("absolute bottom-1 inset-x-1 flex items-center z-20",w&&"flex-wrap items-end justify-between gap-1"),children:[w&&(0,i.jsx)("div",{className:"ml-1 mb-[3px] shrink-0 rounded-md bg-card/80 backdrop-blur-sm",children:(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(D.$,{type:"button",variant:"brand",size:"icon",className:"!bg-transparent",onClick:w,disabled:j,"aria-label":ec("selectMedia"),children:j?(0,i.jsx)(tT.A,{className:"h-4 w-4 animate-spin"}):(0,i.jsx)(tI.A,{className:"h-4 w-4"})})}),(0,i.jsx)(O.TooltipContent,{side:"bottom",children:ec("selectMedia")})]})}),(0,i.jsxs)("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-0.5 rounded-md bg-card/80 pr-1 backdrop-blur-sm",children:[u&&y>=2&&!ef&&(0,i.jsx)("div",{className:"pointer-events-auto",children:(0,i.jsxs)(O.Tooltip,{open:_,children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"",onClick:eV,onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1),"aria-label":ed("copyToAllAria"),children:(0,i.jsx)(tz.A,{className:"h-4 w-4"})})}),(0,i.jsx)(O.TooltipContent,{side:"bottom",children:(0,i.jsx)("p",{children:ed("copyToAll")})})]})}),s&&(0,i.jsx)("div",{className:"pointer-events-auto",children:(0,i.jsx)(ay.F,{onGenerate:eW,isOpen:eb,onOpenChange:eM,isTooltipVisible:eN,setTooltipVisible:eE,isLoading:l,currentContent:n.content,onUndo:eX,onRedo:eZ,canUndo:K.canUndo,canRedo:K.canRedo,selectedAccounts:ep,platform:h,isPremium:x})}),(0,i.jsx)("div",{className:"pointer-events-auto",children:(0,i.jsx)(ax.e,{onHashtagSelect:eK,isOpen:eg,onOpenChange:eI,isTooltipVisible:ew,setTooltipVisible:eS,collections:eu||[],isLoading:eh,error:null,onCreateNew:v})}),(0,i.jsx)("div",{className:"pointer-events-auto",children:(0,i.jsx)(av,{onSnippetSelect:eG,isOpen:ev,onOpenChange:eA,isTooltipVisible:ej,setTooltipVisible:ek,collections:em||[],isLoading:eh,error:null,onCreateNew:b})}),(0,i.jsx)("div",{className:"pointer-events-auto",children:(0,i.jsx)(af.p,{onEmojiSelect:eB,isOpen:ex,onOpenChange:eP,isTooltipVisible:eC,setTooltipVisible:eT})}),(0,i.jsx)("div",{className:"rounded-md bg-muted/50 py-1 px-2 ml-2 text-xs font-medium",children:(0,i.jsx)("span",{className:(0,m.cn)("transition-colors",eo<0?"text-destructive":"text-muted-foreground"),children:eo})})]})]})]})]})}var aS=a(77528),ak=a(54621),aT=a(77968),aE=a(97237);let aI={DRAFT:{value:"DRAFT",label:"Draft",description:"Save to your TikTok inbox for editing",icon:ag.A},PUBLIC_TO_EVERYONE:{value:"PUBLIC_TO_EVERYONE",label:"Public",de
1scription:"Anyone can see this post",icon:aS.A},MUTUAL_FOLLOW_FRIENDS:{value:"MUTUAL_FOLLOW_FRIENDS",label:"Friends",description:"Only friends can see this post",icon:ak.A},FOLLOWER_OF_CREATOR:{value:"FOLLOWER_OF_CREATOR",label:"Followers",description:"Only your followers can see this post",icon:ak.A},SELF_ONLY:{value:"SELF_ONLY",label:"Private",description:"Only you can see this post",icon:aT.A}};function aA(e){let{value:t,onChange:a,supportedPrivacyLevels:n=[],media:r=[]}=e,l=(0,o.useTranslations)("CreatePost.tiktokSelectors"),[s,c]=(0,d.useState)(!1),u=(0,d.useRef)(null),h="DRAFT"===t.visibilityLevel,p=(0,d.useMemo)(()=>0!==r.length&&r.every(e=>{var t;return null==(t=e.type)?void 0:t.toLowerCase().startsWith("image/")}),[r]);(0,d.useEffect)(()=>{p&&(t.allowDuet||t.allowStitch)&&a({...t,allowDuet:!1,allowStitch:!1})},[p,t,a]);let f=t.visibilityLevel?aI[t.visibilityLevel]:void 0,x=(null==f?void 0:f.icon)||aS.A;(0,d.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]);let g=e=>{a({...t,[e]:!t[e]})};return(0,i.jsxs)("div",{className:"space-y-4 mb-4",children:[(0,i.jsxs)("div",{className:(0,m.cn)("grid grid-cols-1 gap-2 md:items-end md:gap-3",!h&&"md:grid-cols-2"),children:[(0,i.jsx)("div",{children:(0,i.jsxs)(ew.Select,{value:t.visibilityLevel||"",onValueChange:e=>{if("DRAFT"===e)return void a({...t,visibilityLevel:e,discloseContent:!1,isYourBrand:void 0,isBrandedContent:void 0});let i={...t,visibilityLevel:e};t.discloseContent&&"SELF_ONLY"===e&&(i={...i,discloseContent:!1,isYourBrand:void 0,isBrandedContent:void 0}),a(i)},children:[(0,i.jsx)(ew.SelectTrigger,{fieldLabel:l("visibilityLabel"),className:"w-full bg-card dark:bg-card",children:(0,i.jsx)(ew.SelectValue,{placeholder:l("selectVisibility"),children:t.visibilityLevel?(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(x,{className:"h-4 w-4"}),(0,i.jsx)("span",{children:t.visibilityLevel?l("visibility.".concat(t.visibilityLevel,".label")):null})]}):(0,i.jsx)("span",{className:"text-muted-foreground",children:l("selectVisibility")})})}),(0,i.jsx)(ew.SelectContent,{className:"[&_[role=option]]:text-sm bg-card dark:bg-card",children:Object.entries(aI).map(e=>{let[a,r]=e,s=r.icon,o=(e=>"DRAFT"===e?t.discloseContent:"SELF_ONLY"===e?t.discloseContent&&t.isBrandedContent:!("DRAFT"===e||0===n.length||n.includes(e)))(a);return(0,i.jsx)(ew.SelectItem,{value:a,disabled:o,children:(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center gap-3",o&&"opacity-50"),children:[(0,i.jsx)(s,{className:"h-4 w-4"}),(0,i.jsxs)("div",{className:"flex flex-col",children:[(0,i.jsx)("span",{className:"font-medium",children:l("visibility.".concat(a,".label"))}),(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:o?"DRAFT"===a?l("draftUnavailable"):"SELF_ONLY"===a&&t.discloseContent&&t.isBrandedContent?l("brandedPrivate"):l("unsupported"):l("visibility.".concat(a,".description"))})]})]})},a)})})]})}),!h&&(0,i.jsx)("div",{className:"relative min-w-0",children:(0,i.jsxs)("div",{ref:u,className:"flex h-8 items-center px-3 py-0 text-sm border rounded-md cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>c(!s),children:[(0,i.jsx)(ec.m,{children:l("permissions")}),(0,i.jsxs)("div",{className:"ml-2 flex min-w-0 w-full items-center justify-between gap-2",children:[(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,i.jsx)(ak.A,{className:"h-4 w-4 shrink-0"}),(0,i.jsxs)("span",{className:"truncate text-sm",children:[void 0===t.allowComment?l("noComment"):t.allowComment?l("comment"):l("noComment"),!p&&(0,i.jsxs)(i.Fragment,{children:[","," ",void 0===t.allowDuet?l("noDuet"):t.allowDuet?"Duet":l("noDuet"),","," ",void 0===t.allowStitch?l("noStitch"):t.allowStitch?"Stitch":l("noStitch")]})]})]}),(0,i.jsx)(U.A,{className:(0,m.cn)("h-4 w-4 shrink-0 transition-transform",s&&"rotate-180")})]}),s&&(0,i.jsx)("div",{className:"absolute top-full left-0 right-0 z-50 mt-1 rounded-md border bg-background shadow-lg",children:(0,i.jsxs)("div",{className:"p-2 space-y-2",children:[(0,i.jsxs)("div",{className:"flex items-center space-x-2 px-2 py-1 hover:bg-muted rounded",children:[(0,i.jsx)(aE.S,{id:"permission-comment",checked:t.allowComment||!1,onCheckedChange:()=>g("allowComment")}),(0,i.jsx)(ey.J,{htmlFor:"permission-comment",className:"text-sm font-normal cursor-pointer",children:l("comment")})]}),!p&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"flex items-center space-x-2 px-2 py-1 hover:bg-muted rounded",children:[(0,i.jsx)(aE.S,{id:"permission-duet",checked:t.allowDuet||!1,onCheckedChange:()=>g("allowDuet")}),(0,i.jsx)(ey.J,{htmlFor:"permission-duet",className:"text-sm font-normal cursor-pointer",children:"Duet"})]}),(0,i.jsxs)("div",{className:"flex items-center space-x-2 px-2 py-1 hover:bg-muted rounded",children:[(0,i.jsx)(aE.S,{id:"permission-stitch",checked:t.allowStitch||!1,onCheckedChange:()=>g("allowStitch")}),(0,i.jsx)(ey.J,{htmlFor:"permission-stitch",className:"text-sm font-normal cursor-pointer",children:"Stitch"})]})]}),p&&(0,i.jsx)("div",{className:"px-2 py-1",children:(0,i.jsx)("div",{className:"text-xs text-muted-foreground",children:l("videoOnly")})})]})})]})})]}),!1]})}var aP=a(13760),aM=a(16639);function aD(e){var t;let{accountId:a,payload:n,updatePayload:r}=e,l=(0,o.useTranslations)("CreatePost.youtube.visibility"),s=[{value:"private",label:l("private.label"),description:l("private.description"),icon:aP.A},{value:"unlisted",label:l("unlisted.label"),description:l("unlisted.description"),icon:aM.A},{value:"public",label:l("public.label"),description:l("public.description"),icon:Q.A}],d=(null==(t=n.youtube)?void 0:t.privacyStatus)||"private",c=s.find(e=>e.value===d);return(0,i.jsx)("div",{children:(0,i.jsxs)(ew.Select,{value:d,onValueChange:e=>{r(a,{youtube:{...n.youtube,privacyStatus:e}})},children:[(0,i.jsx)(ew.SelectTrigger,{fieldLabel:l("label"),className:"bg-card dark:bg-card",children:(0,i.jsx)(ew.SelectValue,{children:c?(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,i.jsx)(c.icon,{className:"h-4 w-4 shrink-0"}),(0,i.jsx)("span",{className:"truncate",children:c.label})]}):(0,i.jsx)("span",{className:"text-muted-foreground",children:l("selectPlaceholder")})})}),(0,i.jsx)(ew.SelectContent,{className:"[&_[role=option]]:text-sm bg-card dark:bg-card",children:s.map(e=>(0,i.jsx)(ew.SelectItem,{value:e.value,children:(0,i.jsxs)("div",{className:"flex items-center gap-3 py-1",children:[(0,i.jsx)(e.icon,{className:"h-4 w-4 shrink-0"}),(0,i.jsxs)("div",{className:"flex flex-col",children:[(0,i.jsx)("span",{className:"font-medium",children:e.label}),(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:e.description})]})]})},e.value))})]})})}function aR(e){var t;let{accountId:a,payload:r,updatePayload:l}=e,s=(0,o.useTranslations)("CreatePost.instagram.collaborators"),[c,u]=(0,d.useState)(""),[m,h]=(0,d.useState)(""),[p,f]=(0,d.useState)(!1),x=(0,d.useMemo)(()=>{var e,t;return null!=(t=null==(e=r.instagram)?void 0:e.collaborators)?t:[]},[null==(t=r.instagram)?void 0:t.collaborators]),g=(0,d.useCallback)(e=>{let t=e.replace(/^@+/,"").trim().toLowerCase();if(!t)return;if(!/^[a-zA-Z0-9._]{1,30}$/.test(t))return void h(s("invalidUsername"));if(x.includes(t))return void h(s("duplicate"));if(x.length>=3)return void h(s("maxReached",{max:3}));h("");let i=[...x,t];l(a,{instagram:{...r.instagram,collaborators:i}}),u("")},[a,x,r.instagram,l,s]),v=(0,d.useCallback)(e=>{let t=x.filter(t=>t!==e);l(a,{instagram:{...r.instagram,collaborators:t.length>0?t:void 0}})},[a,x,r.instagram,l]),b=(0,d.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),g(c))},[c,g]);return(0,i.jsxs)(n.lG,{open:p,onOpenChange:f,children:[(0,i.jsx)(n.zM,{asChild:!0,children:(0,i.jsx)(D.$,{type:"button",variant:"outline",size:"sm","aria-label":x.length?s("label"):s("addCollaborator"),className:"h-8 w-full justify-start gap-2 border-input bg-card px-3 text-sm font-normal dark:bg-card hover:bg-muted/50",children:0===x.length?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(_.A,{className:"h-4 w-4 shrink-0"}),(0,i.jsx)("span",{className:"truncate",children:s("addCollaborator")})]}):(0,i.jsx)("span",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-hidden",children:x.map(e=>(0,i.jsx)(F.Badge,{variant:"secondary",className:"min-w-0 shrink px-1.5 py-0 text-xs font-normal",children:(0,i.jsxs)("span",{className:"truncate",children:["@",e]})},e))})})}),(0,i.jsxs)(n.Cf,{className:"sm:max-w-md p-0 overflow-hidden",children:[(0,i.jsx)(n.c7,{className:"px-4 pt-4 pb-2",children:(0,i.jsx)(n.L3,{className:"text-base",children:s("dialogTitle")})}),(0,i.jsxs)("div",{className:"px-4 pb-4 space-y-3",children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsxs)("div",{className:"relative flex-1",children:[(0,i.jsx)("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"@"}),(0,i.jsx)(t0.p,{value:c,onChange:e=>{u(e.target.value),h("")},onKeyDown:b,placeholder:s("placeholder"),className:"pl-6 !text-sm placeholder:!text-sm h-8",disabled:x.length>=3})]}),(0,i.jsxs)(D.$,{type:"button",size:"sm",variant:"outline",className:"h-8 shrink-0",onClick:()=>g(c),disabled:!c.trim()||x.length>=3,children:[(0,i.jsx)(_.A,{className:"h-3.5 w-3.5"}),s("add")]})]}),m&&(0,i.jsx)("p",{className:"text-xs text-destructive",children:m}),x.length>0?(0,i.jsx)("div",{className:"flex flex-wrap gap-1.5",children:x.map(e=>(0,i.jsxs)(F.Badge,{variant:"secondary",className:"text-xs gap-1 pr-1",children:["@",e,(0,i.jsx)("button",{type:"button",onClick:()=>v(e),className:"ml-0.5 hover:text-destructive transition-colors",children:(0,i.jsx)(tA.A,{className:"h-3 w-3"})})]},e))}):null,(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:s("description")})]})]})]})}var aF=a(56056),aO=a(18545),az=a(6328),aL=a(88697);let aU=(0,tp.createServerReference)("60e2bb81950ace5e99775da7a9af5ac3c6652500d7",tp.callServer,void 0,tp.findSourceMapURL,"markSavedXCommunityUsed"),a_=(0,tp.createServerReference)("60c01afcb79d4be4be03ed1935e1aacb4632f791e3",tp.callServer,void 0,tp.findSourceMapURL,"addSavedXCommunity"),aB=(0,tp.createServerReference)("6020f
168879c5b16b58d7faf065cc8e5eb665f63f94",tp.callServer,void 0,tp.findSourceMapURL,"removeSavedXCommunity");var aK=a(7523);function aG(e){var t;let{accountId:a,communityId:r,communityName:l,communityThumbnailUrl:s,shareWithFollowers:c,onChange:u}=e,h=(0,o.useTranslations)("CreatePost.xCommunities"),{communities:p,setCommunities:f,isLoading:x,error:g}=(0,aK.j)(a),[v,b]=(0,d.useState)(!1),[y,w]=(0,d.useState)(!1),[j,C]=(0,d.useState)(""),[N,S]=(0,d.useState)(null),[k,T]=(0,d.useState)(null),[E,I]=(0,d.useTransition)(),A=(0,d.useMemo)(()=>p.find(e=>e.id===r),[p,r]),P=(null==A?void 0:A.name)||l,M=r?(null==A?void 0:A.thumbnailUrl)||s:void 0,R=e=>{S(null),u({communityId:e.id,communityName:e.name,communityThumbnailUrl:e.thumbnailUrl,shareWithFollowers:e.id!==r||null==c||c}),aU(a,e.id),b(!1)};return(0,i.jsxs)("div",{className:"mt-2",children:[(0,i.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,i.jsxs)(n.lG,{open:v,onOpenChange:e=>{if(e&&!x&&0===p.length&&!g){S(null),w(!0);return}b(e),e||S(null)},children:[(0,i.jsx)(n.zM,{asChild:!0,children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",className:"h-8 max-w-[240px] gap-1.5 bg-transparent text-sm font-normal hover:bg-transparent",title:P||h("label"),disabled:x&&!r,children:[M?(0,i.jsx)(tv.default,{src:M,alt:"",width:20,height:20,className:"size-5 shrink-0 rounded object-cover"}):(0,i.jsx)(aF.A,{className:"size-3.5 shrink-0"}),(0,i.jsx)("span",{className:"truncate",children:P||h("label")})]})}),(0,i.jsxs)(n.Cf,{className:"overflow-hidden p-0 sm:max-w-md",children:[(0,i.jsxs)(n.c7,{className:"px-4 pb-2 pt-4",children:[(0,i.jsx)(n.L3,{className:"text-base",children:h("dialogTitle")}),(0,i.jsx)(n.rr,{className:"sr-only",children:h("dialogDescription")})]}),(0,i.jsxs)("div",{className:"space-y-3 px-4 pb-4",children:[N?(0,i.jsx)("p",{className:"text-xs text-destructive",children:N}):null,g?(0,i.jsx)("p",{className:"text-xs text-destructive",children:g}):null,x||p.length>0?(0,i.jsx)("div",{className:"overflow-hidden rounded-md border",children:x?(0,i.jsxs)("div",{className:"flex items-center gap-2 px-3 py-3 text-xs text-muted-foreground",children:[(0,i.jsx)(tT.A,{className:"size-3.5 animate-spin"}),h("loading")]}):p.map((e,t)=>(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center transition-colors hover:bg-muted/60",t>0&&"border-t",e.id===r&&"bg-muted/60"),children:[(0,i.jsxs)("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2.5 px-2.5 py-1.5 text-left",onClick:()=>R(e),children:[(0,i.jsxs)("span",{className:"relative size-8 shrink-0",children:[(0,i.jsx)("span",{className:"relative flex size-full overflow-hidden rounded-md bg-muted",children:e.thumbnailUrl?(0,i.jsx)(tv.default,{src:e.thumbnailUrl,alt:"",fill:!0,sizes:"32px",className:"object-cover"}):(0,i.jsx)("span",{className:"flex size-full items-center justify-center",children:(0,i.jsx)(aF.A,{className:"size-3.5 text-muted-foreground"})})}),e.id===r?(0,i.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 flex size-3.5 items-center justify-center rounded-full bg-primary text-primary-foreground ring-2 ring-background",children:(0,i.jsx)(aO.A,{className:"size-2.5"})}):null]}),(0,i.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,i.jsx)("span",{className:"block truncate text-sm font-medium",children:e.name}),e.isValid?null:(0,i.jsx)("span",{className:"block text-xs text-destructive",children:h("invalid")})]})]}),(0,i.jsxs)(V.rI,{children:[(0,i.jsx)(V.ty,{asChild:!0,children:(0,i.jsx)(D.$,{type:"button",variant:"ghost",size:"icon",className:"mr-0.5 size-8 text-muted-foreground","aria-label":h("moreActions",{name:e.name}),disabled:E,children:(0,i.jsx)(az.A,{className:"size-4"})})}),(0,i.jsx)(V.SQ,{align:"end",children:(0,i.jsxs)(V._2,{className:"text-destructive focus:bg-destructive/10 focus:text-destructive",onSelect:()=>T(e),children:[(0,i.jsx)(J.A,{className:"mr-2 size-3.5"}),h("remove")]})})]})]},e.id))}):null,(0,i.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",onClick:()=>{S(null),b(!1),w(!0)},children:[(0,i.jsx)(_.A,{className:"size-3.5"}),h("add")]}),r?(0,i.jsx)(D.$,{type:"button",variant:"ghost",size:"sm",className:"text-muted-foreground",onClick:()=>{u({}),b(!1)},children:h("clearSelection")}):null]})]})]})]}
1),r?(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(ey.J,{htmlFor:"x-share-followers-".concat(a),className:"whitespace-nowrap text-xs font-normal text-muted-foreground",children:h("shareWithFollowers")}),(0,i.jsx)(ed.d,{id:"x-share-followers-".concat(a),size:"sm",checked:null==c||c,onCheckedChange:e=>u({communityId:r,communityName:P,communityThumbnailUrl:M,shareWithFollowers:e})})]}):null]}),(0,i.jsx)(n.lG,{open:y,onOpenChange:e=>{w(e),e||(C(""),S(null))},children:(0,i.jsxs)(n.Cf,{className:"sm:max-w-md",children:[(0,i.jsxs)(n.c7,{children:[(0,i.jsx)(n.L3,{children:h("addTitle")}),(0,i.jsx)(n.rr,{children:h("addDescription")})]}),(0,i.jsxs)("form",{className:"space-y-4",onSubmit:e=>{e.preventDefault(),j.trim()&&!E&&(S(null),I(async()=>{var e;let t=await a_(a,j);if(!t.data)return void S(t.error||h("addError"));e=t.data,f(t=>[e,...t.filter(t=>t.id!==e.id)]),R(t.data),C(""),w(!1)}))},children:[(0,i.jsx)(t0.p,{value:j,onChange:e=>{C(e.target.value),S(null)},placeholder:h("inputPlaceholder"),autoComplete:"off",autoFocus:!0}),N?(0,i.jsx)("p",{className:"text-xs text-destructive",children:N}):null,(0,i.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,i.jsx)(D.$,{type:"button",variant:"outline",disabled:E,onClick:()=>w(!1),children:h("cancel")}),(0,i.jsxs)(D.$,{type:"submit",disabled:E||!j.trim(),children:[E?(0,i.jsx)(tT.A,{className:"size-3.5 animate-spin"}):(0,i.jsx)(_.A,{className:"size-3.5"}),E?h("validating"):h("add")]})]})]})]})}),(0,i.jsx)(aL.Lt,{open:null!==k,onOpenChange:e=>{e||T(null)},children:(0,i.jsxs)(aL.EO,{className:"sm:max-w-md",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:h("removeConfirmTitle")}),(0,i.jsx)(aL.$v,{children:h("removeConfirmDescription",{name:null!=(t=null==k?void 0:k.name)?t:""})})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(D.$,{type:"button",variant:"outline",disabled:E,onClick:()=>T(null),children:h("cancel")}),(0,i.jsx)(D.$,{type:"button",variant:"destructive",disabled:E,onClick:()=>{if(!k)return;let e=k.id;T(null),E||(S(null),I(async()=>{let t=await aB(a,e);if(!t.data)return void S(t.error||h("removeError"));let i=p.filter(t=>t.id!==e);f(i),e===r&&u({}),0===i.length&&(b(!1),w(!0))}))},children:h("confirmRemove")})]})]})})]})}let aW={"ai-writer":["[email protected]","[email protected]"],"post-preview":["[email protected]","[email protected]"],"first-comment":["[email protected]","[email protected]"],"x-communities":["[email protected]","[email protected]"]};function aV(e,t){var a,i;return!!t&&null!=(i=null==(a=aW[e])?void 0:a.includes(t))&&i}var aq=a(30462);function aH(e){if(!e)return"";let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let a=6e4*t.getTimezoneOffset();return new Date(t.getTime()-a).toISOString().slice(0,16)}function a$(e){var t,a,n,r,l,s,d,c,u;let{accountId:m,payload:h,updatePayload:p}=e,f=(0,o.useTranslations)("CreatePost.googleBusiness"),x=null!=(t=h.googleBusiness)?t:{},g=null!=(a=h.postType)?a:"standard",v=e=>p(m,{googleBusiness:{...x,...e}});return(0,i.jsxs)("div",{className:"mb-4 grid gap-3 rounded-md border p-3",children:["event"===g||"offer"===g?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{htmlFor:"google-business-title-".concat(m),children:f("title")}),(0,i.jsx)(t0.p,{id:"google-business-title-".concat(m),value:null!=(n=x.eventTitle)?n:"",maxLength:58,onCh
1ange:e=>v({eventTitle:e.target.value}),placeholder:f("titlePlaceholder")})]}),(0,i.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{htmlFor:"google-business-start-".concat(m),children:f("starts")}),(0,i.jsx)(t0.p,{id:"google-business-start-".concat(m),type:"datetime-local",value:aH(x.eventStart),onChange:e=>v({eventStart:e.target.value?new Date(e.target.value).toISOString():void 0})})]}),(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{htmlFor:"google-business-end-".concat(m),children:f("ends")}),(0,i.jsx)(t0.p,{id:"google-business-end-".concat(m),type:"datetime-local",value:aH(x.eventEnd),onChange:e=>v({eventEnd:e.target.value?new Date(e.target.value).toISOString():void 0})})]})]})]}):null,"offer"!==g&&"media"!==g?(0,i.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{children:f("cta")}),(0,i.jsxs)(ew.Select,{value:null!=(r=x.ctaType)?r:"none",onValueChange:e=>v({ctaType:"none"===e?void 0:e,..."none"===e||"call"===e?{ctaUrl:void 0}:{}}),children:[(0,i.jsx)(ew.SelectTrigger,{children:(0,i.jsx)(ew.SelectValue,{})}),(0,i.jsxs)(ew.SelectContent,{className:"[&_[role=option]]:text-sm",children:[(0,i.jsx)(ew.SelectItem,{value:"none",children:f("ctaTypes.none")}),(0,i.jsx)(ew.SelectItem,{value:"book",children:f("ctaTypes.book")}),(0,i.jsx)(ew.SelectItem,{value:"order",children:f("ctaTypes.order")}),(0,i.jsx)(ew.SelectItem,{value:"shop",children:f("ctaTypes.shop")}),(0,i.jsx)(ew.SelectItem,{value:"learn_more",children:f("ctaTypes.learnMore")}),(0,i.jsx)(ew.SelectItem,{value:"sign_up",children:f("ctaTypes.signUp")}),(0,i.jsx)(ew.SelectItem,{value:"call",children:f("ctaTypes.call")})]})]})]}),x.ctaType&&"call"!==x.ctaType?(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{htmlFor:"google-business-cta-".concat(m),children:f("ctaUrl")}),(0,i.jsx)(t0.p,{id:"google-business-cta-".concat(m),type:"url",value:null!=(l=x.ctaUrl)?l:"",onChange:e=>v({ctaUrl:e.target.value}),placeholder:"https://example.com"})]}):null]}):null,"offer"===g?(0,i.jsxs)("div",{className:"grid gap-3",children:[(0,i.jsx)(t0.p,{value:null!=(s=x.couponCode)?s:"",onChange:e=>v({couponCode:e.target.value}),placeholder:f("couponCode")}),(0,i.jsx)(t0.p,{type:"url",value:null!=(d=x.redeemOnlineUrl)?d:"",onChange:e=>v({redeemOnlineUrl:e.target.value}),placeholder:f("redeemUrl")}),(0,i.jsx)(t0.p,{value:null!=(c=x.termsConditions)?c:"",onChange:e=>v({termsConditions:e.target.value}),placeholder:f("terms")})]}):null,"media"===g?(0,i.jsxs)("div",{className:"grid gap-1.5",children:[(0,i.jsx)(ey.J,{children:f("mediaCategory")}),(0,i.jsxs)(ew.Select,{value:null!=(u=x.mediaCategory)?u:"ADDITIONAL",onValueChange:e=>v({mediaCategory:e}),children:[(0,i.jsx)(ew.SelectTrigger,{children:(0,i.jsx)(ew.SelectValue,{})}),(0,i.jsxs)(ew.SelectContent,{className:"[&_[role=option]]:text-sm",children:[(0,i.jsx)(ew.SelectItem,{value:"ADDITIONAL",children:f("mediaCategories.additional")}),(0,i.jsx)(ew.SelectItem,{value:"COVER",children:f("mediaCategories.cover")}),(0,i.jsx)(ew.SelectItem,{value:"PROFILE",children:f("mediaCategories.profile")}),(0,i.jsx)(ew.SelectItem,{value:"EXTERIOR",children:f("mediaCategories.exterior")}),(0,i.jsx)(ew.SelectItem,{value:"INTERIOR",children:f("mediaCategories.interior")}),(0,i.jsx)(ew.SelectItem,{value:"PRODUCT",children:f("mediaCategories.product")}),(0,i.jsx)(ew.SelectItem,{value:"AT_WORK",children:f("mediaCategories.atWork")}),(0,i.jsx)(ew.SelectItem,{value:"FOOD_AND_DRINK",children:f("mediaCategories.foodAndDrink")}),(0,i.jsx)(ew.SelectItem,{value:"MENU",children:f("mediaCategories.menu")})]})]})]}):null]})}function aY(e){var t,a,n,r,l,s,u,h,p,f,x,g,v,b,y,j,C,N,S;let{accountId:k,platform:T,payload:E,updatePayload:I,isAILoading:A,onAIGenerate:P,onCopyField:M,isPremium:D,validation:R,onSelectImageClick:F,onUploadFromPC:z,isUploading:L,getAILoadingForComponent:U,onCreateHashtag:_,onCreateSnippet:B,selectedAccountsCount:K=1}=e,G=(0,o.useTranslations)("CreatePost"),{user:W}=(0,aq.J)(),V=aV("x-communities",null==W?void 0:W.email),{shouldShowPostTypeSelector:q}=t9(T,T===c.SocialPlatform.X?D:void 0),H=(0,d.useMemo)(()=>T===c.SocialPlatform.YOUTUBE,[T]),$=(0,d.useMemo)(()=>T===c.SocialPlatform.TIKTOK,[T]),Y=R.getFieldErrors("media"),X=R.getFieldWarnings("media"),Z=e=>e.filter(e=>"media"!==e.field||"blocking"!==e.severity),J=(0,d.useMemo)(()=>$?Z([...Y,...R.allErrors.filter(e=>"media"===e.field)].filter((e,t,a)=>a.findIndex(t=>t.id===e.id)===t)):Z(Y),[$,Y,R.allErrors]),Q=(0,d.useMemo)(()=>$?[...X,...R.allWarnings.filter(e=>"media"===e.field)].filter((e,t,a)=>a.findIndex(t=>t.id===e.id)===t):X,[$,X,R.allWarnings]),ee=R.getFieldErrors("postType"),et=R.getFieldWarnings("postType"),ea=H?R.getFieldErrors("thumbnail"):[],ei=H?R.getFieldWarnings("thumbnail"):[],en=(0,d.useMemo)(()=>J.length>0||Q.length>0||ee.length>0||et.length>0||H&&(ea.length>0||ei.length>
10),[J,Q,ee,et,H,ea,ei]),er=(null==(t=E.youtube)?void 0:t.title)||"",el=(null==(a=E.pinterest)?void 0:a.link)||"",[es,eo]=(0,d.useState)({supportedPrivacyLevels:[],defaultAllowComment:!0,defaultAllowDuet:!0,defaultAllowStitch:!0,isLoading:!1}),eu=(0,d.useMemo)(()=>T!==c.SocialPlatform.TIKTOK?[]:es.supportedPrivacyLevels,[T,es.supportedPrivacyLevels]);(0,d.useEffect)(()=>{T===c.SocialPlatform.TIKTOK&&k&&!es.isLoading&&(eo(e=>({...e,isLoading:!0})),eG.getCreatorInfo(k).then(e=>{e?eo({supportedPrivacyLevels:e.privacyLevelOptions,defaultAllowComment:e.defaultAllowComment,defaultAllowDuet:e.defaultAllowDuet,defaultAllowStitch:e.defaultAllowStitch,maxVideoDurationSec:e.maxDurationSec,isLoading:!1,error:e.hasPostingCapError?e.postingCapErrorMessage:void 0}):(console.warn("Failed to fetch TikTok creator info from cache"),eo({supportedPrivacyLevels:[],defaultAllowComment:!0,defaultAllowDuet:!0,defaultAllowStitch:!0,isLoading:!1,error:"Failed to fetch creator info"}))}).catch(e=>{console.error("Error fetching TikTok creator info from cache:",e),eo({supportedPrivacyLevels:[],defaultAllowComment:!0,defaultAllowDuet:!0,defaultAllowStitch:!0,isLoading:!1,error:"Network error fetching creator info"})}))},[T,k]);let em=(0,d.useCallback)(e=>{R.onFieldChange("pinterest"),I(k,{pinterest:{...E.pinterest,link:e.target.value}})},[R,I,k,E.pinterest]),eh=(0,d.useCallback)(e=>{I(k,{tiktok:{...E.tiktok,privacyLevel:e.visibilityLevel,disableComment:void 0!==e.allowComment?!e.allowComment:void 0,disableDuet:void 0!==e.allowDuet?!e.allowDuet:void 0,disableStitch:void 0!==e.allowStitch?!e.allowStitch:void 0,discloseContent:e.discloseContent,isYourBrand:e.isYourBrand,isBrandedContent:e.isBrandedContent}})},[I,k,E.tiktok]),ep=(0,d.useCallback)(e=>{R.onFieldChange("postType"),I(k,{postType:e})},[R,I,k]);(0,d.useEffect)(()=>{var e,t;if(T!==c.SocialPlatform.INSTAGRAM&&T!==c.SocialPlatform.INSTAGRAM_DIRECT)return;let a=null!=(e=E.postType)?e:"feed",i=w(a,null!=(t=E.media)?t:[]);i!==a&&I(k,{postType:i})},[T,E.media,E.postType,k,I]);let ef=(0,d.useCallback)(e=>{R.onFieldChange("title"),I(k,{youtube:{...E.youtube,title:e.target.value}})},[R,I,k,E.youtube]),ex=(0,d.useMemo)(()=>{var e,t,a,i,n,r,l;return{visibilityLevel:null==(e=E.tiktok)?void 0:e.privacyLevel,allowComment:(null==(t=E.tiktok)?void 0:t.disableComment)!==void 0?!E.tiktok.disableComment:void 0,allowDuet:(null==(a=E.tiktok)?void 0:a.disableDuet)!==void 0?!E.tiktok.disableDuet:void 0,allowStitch:(null==(i=E.tiktok)?void 0:i.disableStitch)!==void 0?!E.tiktok.disableStitch:void 0,discloseContent:(null==(n=E.tiktok)?void 0:n.discloseContent)||!1,isYourBrand:null==(r=E.tiktok)?void 0:r.isYourBrand,isBrandedContent:null==(l=E.tiktok)?void 0:l.isBrandedContent}},[E.tiktok]);(0,d.useEffect)(()=>{$&&E.tiktok&&R.onFieldChange("tiktok-disclose")},[$,E.tiktok,null==(n=E.tiktok)?void 0:n.discloseContent,null==(r=E.tiktok)?void 0:r.isYourBrand,null==(l=E.tiktok)?void 0:l.isBrandedContent,R]);let eg=T===c.SocialPlatform.INSTAGRAM||T===c.SocialPlatform.INSTAGRAM_DIRECT,ev=null!=(C=null==(s=E.media)?void 0:s.length)?C:0,eb=eg&&1===ev&&null!=(N=null==(p=E.media)||null==(h=p[0])||null==(u=h.type)?void 0:u.startsWith("video/"))&&N,ew=eg&&ev>1?["feed","story","reel"]:eb?["feed"]:void 0,ej=(0,i.jsxs)("div",{className:"flex h-8 min-w-0 items-center rounded-md border border-input bg-card pl-3 mb-2",children:[(0,i.jsx)("div",{className:"flex h-full shrink-0 items-center gap-1.5",children:(0,i.jsxs)(ec.m,{children:[(0,i.jsx)("span",{className:"mr-1.5",children:G("pinterest.pinLinkLabel")}),(0,i.jsx)(O.TooltipProvider,{delayDuration:300,children:(0,i.jsxs)(O.Tooltip,{children:[(0,i.jsx)(O.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(e0.A,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})}),(0,i.jsx)(O.TooltipContent,{side:"top",className:"text-xs",children:(0,i.jsx)("p",{children:G("pinterest.pinLinkTooltip")})})]})})]})}),(0,i.jsx)(t0.p,{id:"pinterest-link-".concat(k),"aria-label":G("pinterest.pinLinkLabel"),type:"url",placeholder:"https://link.com",value:el,onChange:em,onFocus:()=>R.onFieldFocus("pinterest"),onBlur:()=>R.onFieldBlur("pinterest"),className:"border-0 bg-transparent dark:bg-transparent shadow-none focus-visible:ring-0 focus-visible:ring-offset-0"})]});return(0,i.jsxs)("div",{className:"min-h-full flex flex-col",children:[H?(0,i.jsxs)("div",{className:"flex flex-row gap-4 mb-2",children:[(0,i.jsx)("div",{className:"flex-1",children:(0,i.jsx)(aD,{accountId:k,payload:E,updatePayload:I})}),(0,i.jsx)("div",{className:"flex-1",children:(0,i.jsx)(ao,{platform:T,value:E.postType||(H?"video":T===c.SocialPlatform.GOOGLE_BUSINESS?"standard":"feed"),onChange:ep,accountId:k,disabledTypes:ew,pinterestPinLink:ej})})]}):(q||T===c.SocialPlatform.PINTEREST||T===c.SocialPlatform.INSTAGRAM||T===c.SocialPlatform.GOOGLE_BUSINESS)&&(0,i.jsxs)("div",{className:(0,m.cn)("mb-2",T===c.SocialPlatform.INSTAGRAM&&"story"!==E.postType&&"grid grid-cols-1 gap-2 md:grid-cols-2 md:items-end md:gap-3"),children:[(0,i.jsx)("div",{className:"min-w-0",children:(0,i.jsx)(ao,{platform:T,value:E.postType||(H?"video":T===c.SocialPlatform.GOOGLE_BUSINESS?"standard":"feed"),onChange:ep,accountId:k,disabledTypes:ew,pinterestPinLink:ej})}),T===c.SocialPlatform.INSTAGRAM&&"story"!==E.postType&&(0,i.jsx)("div",{className:"min-w-0",children:(0,i.jsx)(aR,{accountId:k,payload:E,updatePayload:I})})]}),T===c.SocialPlatform.GOOGLE_BUSINESS?(0,i.jsx)(a$,{accountId:k,payload:E,updatePayload:I}):null,T===c.SocialPlatform.TIKTOK&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(aA,{value:ex,onChange:eh,supportedPrivacyLevels:eu,media:E.media}),es.error&&(0,i.jsx)("div",{className:"mt-2 p-2 bg-yellow-50 border border-yellow-200 rounded-md",children:(0,i.jsxs)("div",{className:"text-sm text-yellow-800",children:["â ï¸ Could not load account privacy options: ",es.error]})})]}),$&&(()=>{let e=R.getFieldErrors("posting-cap");return e.length>0&&(0,i.jsx)("div",{className:"mt-2 p-3 bg-red-50 border border-red-200 rounded-md",children:(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)("div",{className:"h-5 w-5 text-red-600 flex-shrink-0",children:"\uD83D\uDEAB"}),(0,i.jsxs)("div",{className:"text-sm text-red-800",children:[(0,i.jsx)("div",{className:"font-medium mb-1",children:"Posting Blocked"}),e.map(e=>(0,i.jsx)("div",{className:"text-xs",children:e.message},e.id))]})]})})})(),$&&(0,i.jsx)(e2,{errors:R.getFieldErrors("tiktok-disclose"),warnings:R.getFieldWarnings("tiktok-disclose"),className:"mt-2"}),H&&(0,i.jsxs)("div",{className:"mb-2",children:[(0,i.jsxs)("div",{className:"flex h-8 min-w-0 items-center rounded-md border border-input bg-card pl-3",children:[(0,i.jsx)(ey.J,{htmlFor:"youtube-title-".concat(k),className:"h-full shrink-0",children:(0,i.jsx)(ec.m,{children:(0,i.jsxs)("span",{className:"inline-grid",children:[(0,i.jsx)("span",{className:"col-start-1 row-start-1",children:G("youtube.title.label")}),(0,i.jsx)("span",{"aria-hidden":"true",className:"invisible col-start-1 row-start-1",children:G("youtube.visibility.label")})]})})}
1),(0,i.jsx)(t0.p,{id:"youtube-title-".concat(k),value:er,onChange:ef,onFocus:()=>R.onFieldFocus("title"),onBlur:()=>R.onFieldBlur("title"),placeholder:G("youtube.title.placeholder"),maxLength:100,className:"h-full min-w-0 flex-1 border-0 bg-transparent px-2 text-sm shadow-none placeholder:text-muted-foreground/60 focus-visible:ring-0"}),(0,i.jsx)("div",{className:"mr-1.5 flex shrink-0 items-center rounded-md bg-muted/50 px-2 py-1",children:(0,i.jsx)("span",{className:(0,m.cn)("text-xs font-medium transition-colors",100-er.length<0?"text-destructive":"text-muted-foreground"),children:100-er.length})})]}),(0,i.jsx)(e2,{errors:er.trim()?R.getFieldErrors("title"):[],warnings:R.getFieldWarnings("title"),className:"mt-1 mb-2"})]}),T===c.SocialPlatform.X&&V?(0,i.jsx)("div",{className:"mb-2",children:(0,i.jsx)(aG,{accountId:k,communityId:null==(f=E.x)?void 0:f.communityId,communityName:null==(x=E.x)?void 0:x.communityName,communityThumbnailUrl:null==(g=E.x)?void 0:g.communityThumbnailUrl,shareWithFollowers:null==(v=E.x)?void 0:v.shareWithFollowers,onChange:e=>I(k,{x:{...E.x,communityId:e.communityId,communityName:e.communityName,communityThumbnailUrl:e.communityThumbnailUrl,shareWithFollowers:e.shareWithFollowers}})})}):null,T!==c.SocialPlatform.GOOGLE_BUSINESS||"media"!==E.postType?(0,i.jsx)(aN,{matchMediaHeight:!!(null==(b=E.media)?void 0:b.length),accountId:k,payload:E,updatePayload:I,isAILoading:A,onAIGenerate:P,onCopyField:M,error:void 0,platform:T,isYouTube:H,isPremium:T===c.SocialPlatform.X?D:void 0,validation:R,onCreateHashtag:_,onCreateSnippet:B,selectedAccountsCount:K,onSelectMedia:(null==(y=E.media)?void 0:y.length)?void 0:()=>F(k),isUploading:L}):null,(0,i.jsx)("div",{children:T===c.SocialPlatform.TELEGRAM&&(0,i.jsxs)("div",{className:"mt-2 flex items-center justify-between gap-4 rounded-md border p-3",children:[(0,i.jsx)("div",{children:(0,i.jsx)(ey.J,{htmlFor:"telegram-pin-".concat(k),className:"text-sm font-medium",children:G("telegram.pin.label")})}),(0,i.jsx)(ed.d,{id:"telegram-pin-".concat(k),checked:null!=(S=null==(j=E.telegram)?void 0:j.pin)&&S,onCheckedChange:e=>I(k,{telegram:{...E.telegram,pin:e}}),"aria-label":G("telegram.pin.label")})]})}),en&&(0,i.jsxs)("div",{className:"flex flex-col gap-2 mt-2",children:[(0,i.jsx)(e2,{errors:J,warnings:Q}),(0,i.jsx)(e2,{errors:ee,warnings:et}),H&&(0,i.jsx)(e2,{errors:ea,warnings:ei})]})]})}var aX=a(54851);function aZ(e){var t,a,n;let{accountId:r,platform:l,payload:s,updatePayload:u,onSelectImageClick:h,onCopyField:p,onUploadFromPC:f,isUploading:x,onAIGenerate:g,getAILoadingForComponent:v,validation:b,onCreateHashtag:y,onCreateSnippet:w}=e,j=(0,o.useTranslations)("CreatePost.threadComments"),C=(0,d.useMemo)(()=>{var e,t,a;switch(l){case c.SocialPlatform.X:return(null==(e=s.x)?void 0:e.threadComments)||[];case c.SocialPlatform.THREADS:return(null==(t=s.threads)?void 0:t.threadComments)||[];case c.SocialPlatform.MASTODON:return(null==(a=s.mastodon)?void 0:a.threadComments)||[];default:return[]}},[l,null==(t=s.x)?void 0:t.threadComments,null==(a=s.threads)?void 0:a.threadComments,null==(n=s.mastodon)?void 0:n.threadComments]),[N,S]=(0,d.useState)(null),k=(0,d.useCallback)(()=>{let e,t={id:(0,tQ.A)(),content:"",media:[]};switch(l){case c.SocialPlatform.X:e={...s,x:{...s.x||{},threadComments:[...C,t]}};break;case c.SocialPlatform.THREADS:e={...s,threads:{...s.threads||{},threadComments:[...C,t]}};break;case c.SocialPlatform.MASTODON:e={...s,mastodon:{...s.mastodon||{},threadComments:[...C,t]}};break;default:return}u(r,e)},[l,r,s,C,u]),T=(0,d.useCallback)(e=>{let t,a=C.filter(t=>t.id!==e);switch(l){case c.SocialPlatform.X:t={...s,x:{...s.x||{},threadComments:a}};break;case c.SocialPlatform.THREADS:t={...s,threads:{...s.threads||{},threadComments:a}};break;case c.SocialPlatform.MASTODON:t={...s,mastodon:{...s.mastodon||{},threadComments:a}};break;default:return}u(r,t),S(null)},[l,r,s,C,u]),E=(0,d.useCallback)((e,t)=>{t.content&&t.content.trim().length>0||t.media&&t.media.length>0?S(e):T(e)},[T]),I=(0,d.useCallback)((e,t)=>{let a,i=C.map(a=>a.id===e?{...a,...t}:a);switch(l){case c.SocialPlatform.X:a={...s,x:{...s.x||{},threadComments:[...i]}};break;case c.SocialPlatform.THREADS:a={...s,threads:{...s.threads||{},threadComments:[...i]}};break;case c.SocialPlatform.MASTODON:a={...s,mastodon:{...s.mastodon||{},threadComments:[...i]}};break;default:return}u(r,a)},[l,r,s,C,u]),A=(0,d.useCallback)((e,t)=>{I(e,{content:t}),(null==b?void 0:b.onFieldBlur)&&b.onFieldBlur("threadComment-".concat(e))},[I,b]),P=(0,d.useCallback)((e,t)=>{I(e,{media:t}),(null==b?void 0:b.onFieldBlur)&&b.onFieldBlur("threadComment-".concat(e,"-media"))},[I,b]),M=(0,d.useCallback)(async(e,t,a,i)=>{g&&await g(e,t,a,i)},[g]);return(0,i.jsxs)("div",{children:[0===C.length&&(0,i.jsx)("div",{className:"p-2 pt-0",children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",onClick:k,className:"w-full text-muted-foreground hover:text-foreground bg-card dark:bg-card transition-all duration-300",children:[(0,i.jsx)(_.A,{className:"w-4 h-4"}),j("startThread")]})}),C.length>0&&(0,i.jsx)("div",{className:"px-0 space-y-0 relative",children:C.map((e,t)=>{var a;let n=t===C.length-1,s=!!(null==(a=e.media)?void 0:a.length),o=!s;return(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)("div",{className:"absolute left-[20px] -top-2 h-4 w-px bg-border/60 z-0"}),!n&&(0,i.jsx)("div",{className:"absolute left-[20px] top-2 bottom-0 w-px bg-border/60 z-0"}),(0,i.jsx)("div",{className:"relative z-10 bg-transparent",children:(0,i.jsxs)(tx.Wu,{"data-post-editor-row":!0,className:(0,m.cn)("flex flex-col md:flex-row md:items-stretch gap-2 px-2 pb-2 relative"),children:[(0,i.jsx)("div",{className:"absolute left-[8px] top-2 z-20",children:(0,i.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full border bg-muted border-border text-foreground shadow-sm",children:(0,i.jsx)("span",{className:"text-[10px] font-bold",children:t+2})})}),!o&&(0,i.jsx)("div",{className:(0,m.cn)(e.media&&e.media.length>0?"md:w-[40%] flex-shrink-0 flex ml-8":"md:w-auto flex-shrink-0 flex ml-8"),children:(0,i.jsx)(t3,{accountId:r,platform:l,payload:{media:e.media||[]},updatePayload:(t,a)=>{"media"in a&&P(e.id,a.media)},onSelectImageClick:t=>
1h(t,e.id),onUploadFromPC:t=>null==f?void 0:f(t,e.id),isUploading:x})}),(0,i.jsx)("div",{className:(0,m.cn)("md:flex-1",s?"ml-10 md:ml-0":"ml-8"),children:(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)(aN,{matchMediaHeight:s,accountId:"".concat(r,"-thread-").concat(e.id),platform:l,payload:{content:e.content},updatePayload:(t,a)=>{"content"in a&&"string"==typeof a.content&&A(e.id,a.content)},isAILoading:!!v&&v("comment-".concat(e.id)),onAIGenerate:(t,a,i,n)=>M(t,e.id,i,n),onCreateHashtag:y,onCreateSnippet:w,onSelectMedia:o?()=>h(r,e.id):void 0,isUploading:x,validation:b?{...b,getFieldErrors:t=>{let a="content"===t?"threadComment-".concat(e.id):t;return b.getFieldErrors(a)},getFieldWarnings:t=>{let a="content"===t?"threadComment-".concat(e.id):t;return b.getFieldWarnings(a)},onFieldFocus:t=>{let a="content"===t?"threadComment-".concat(e.id):t;b.onFieldFocus(a)},onFieldBlur:t=>{let a="content"===t?"threadComment-".concat(e.id):t;b.onFieldBlur(a)}}:void 0}),(0,i.jsx)(D.$,{variant:"ghost",size:"sm",onClick:t=>{t.stopPropagation(),E(e.id,e)},className:"absolute top-2 right-2 h-7 w-7 p-0 text-destructive/50 hover:text-destructive hover:bg-destructive/10 transition-all z-10",children:(0,i.jsx)(aX.A,{className:"w-3.5 h-3.5"})})]})})]})})]},e.id)})}),C.length>0&&(0,i.jsx)("div",{className:"px-2 pb-2 pt-0",children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",onClick:k,className:"w-full text-muted-foreground hover:text-foreground bg-card dark:bg-card transition-all duration-300",children:[(0,i.jsx)(_.A,{className:"w-4 h-4"}),j("addThreadNumber",{number:C.length+2})]})}),(0,i.jsx)(aL.Lt,{open:null!==N,onOpenChange:e=>!e&&S(null),children:(0,i.jsxs)(aL.EO,{children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:j("deleteConfirmation.title")}),(0,i.jsx)(aL.$v,{children:j("deleteConfirmation.description")})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>S(null),children:j("deleteConfirmation.cancel")}),(0,i.jsx)(aL.Rx,{onClick:()=>N&&T(N),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:j("deleteConfirmation.confirm")})]})]})})]})}function aJ(e){var t,a;let{accountId:n,payload:r,updatePayload:l,onCopyField:s,onAIGenerate:u,getAILoadingForComponent:m,validation:h,onCreateHashtag:p,onCreateSnippet:f}=e,x=(0,o.useTranslations)("CreatePost.threadComments"),g=null==(t=r.linkedin)?void 0:t.comment,[v,b]=(0,d.useState)(!1),y=(0,d.useCallback)(()=>{let e={id:(0,tQ.A)(),content:"",media:[]};l(n,{...r,linkedin:{...r.linkedin,comment:e}}),b(!0)},[n,r,l]),w=(0,d.useCallback)(()=>{l(n,{...r,linkedin:{...r.linkedin,comment:void 0}}),b(!1)},[n,r,l]),j=(0,d.useCallback)(e=>{if(!g)return;let t={...g,...e};l(n,{...r,linkedin:{...r.linkedin,comment:t,_lastUpdated:Date.now()}})},[n,r,g,l]),C=(0,d.useCallback)(e=>{j({content:e}),(null==h?void 0:h.onFieldBlur)&&h.onFieldBlur("linkedin-comment")},[j,h]),N=(0,d.useCallback)(async(e,t,a)=>{u&&(null==g?void 0:g.id)&&await u(e,g.id,t,a)},[u,null==g?void 0:g.id]);return(0,i.jsxs)(i.Fragment,{children:[!g&&(0,i.jsx)("div",{className:"p-2 pt-0",children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",onClick:y,className:"w-full text-muted-foreground hover:text-foreground bg-card dark:bg-card transition-all duration-300",children:[(0,i.jsx)(_.A,{className:"w-4 h-4"}),x("addCommentButton")]})}),g&&(0,i.jsx)("div",{className:"p-2 pt-0",children:(0,i.jsx)(tg.Nt,{open:v,onOpenChange:b,children:(0,i.jsxs)("div",{className:"overflow-hidden border rounded-md bg-card border-border",children:[(0,i.jsx)(tg.R6,{asChild:!0,children:(0,i.jsxs)("div",{className:"flex h-[30px] items-center justify-between px-3 cursor-pointer hover:bg-muted/50 transition-colors ".concat(v?"border-b border-border/50":""),children:[(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,i.jsx)("span",{className:"shrink-0 font-medium text-sm",children:x("comment")}),!v&&(0,i.jsxs)("div",{className:"flex items-center min-w-0 gap-2 overflow-hidden flex-nowrap whitespace-nowrap",children:[g.media&&g.media.length>0&&(0,i.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[g.media.slice(0,5).map((e,t)=>{var a;let n=null==(a=e.type)?void 0:a.startsWith("video/"),r=encodeURI(e.thumbnailUrl||e.url);return(0,i.jsx)("div",{className:"relative w-5 h-5 rounded overflow-hidden border border-border/50 bg-black",children:n&&!e.thumbnailUrl?(0,i.jsx)("video",{src:"".concat(r,"#t=0.1"),muted:!0,preload:"metadata",className:"absolute inset-0 h-full w-full object-cover"}):(0,i.jsx)("img",{src:r,alt:"Thumb ".concat(t+1),className:"absolute inset-0 h-full w-full object-cover"})},t)}),g.media.length>5&&(0,i.jsxs)("span",{className:"text-xs text-muted-foreground",children:["+",g.media.length-5]})]}),g.content&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:(a=g.content,!a||a.length<=30?a||"":a.substring(0,30)+"...")})]})]}),(0,i.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:[(0,i.jsx)(D.$,{variant:"ghost",size:"sm",onClick:e=>{e.stopPropagation(),w()},className:"h-6 px-1 text-destructive hover:text-destructive hover:bg-destructive/10",children:(0,i.jsx)(aX.A,{className:"w-4 h-4"})}),(0,i.jsx)("div",{className:"text-muted-foreground",children:v?(0,i.jsx)(ee.A,{className:"w-4 h-4"}):(0,i.jsx)(U.A,{className:"w-4 h-4"})})]})]})}),(0,i.jsx)(tg.Ke,{children:(0,i.jsx)(tx.Wu,{className:"p-0",children:(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsx)(aN,{noBorder:!0,accountId:"".concat(n,"-linkedin-comment-").concat(g.id),platform:c.SocialPlatform.LINKEDIN,payload:{content:g.content},updatePayload:(e,t)=>{"content"in t&&"string"==typeof t.content&&C(t.content)},isAILoading:!!m&&m("comment-".concat(g.id)),onAIGenerate:(e,t,a,i)=>N(e,a,i),onCreateHashtag:p,onCreateSnippet:f}),h&&(0,i.jsx)(i.Fragment,{children:(0,i.jsx)(e2,{errors:h.getFieldErrors("linkedin-comment"),warnings:h.getFieldWarnings("linkedin-comment"),className:"mt-1"})})]})})})]})})})]})}function aQ(e){var t;let{accountId:a,payload:n,updatePayload:r,onAIGenerate:l,getAILoadingForComponent:s,validation:u,onCreateHashtag:m,onCreateSnippet:h}=e,p=(0,o.useTranslations)("CreatePost.instagram.firstComment"),f=null==(t=n.instagram)?void 0:t.firstComment,[x,g]=(0,d.useState)(!1),v=(0,d.useCallback)(()=>{r(a,{instagram:{...n.instagram,firstComment:""}}),g(!0)},[a,n.instagram,r]),b=(0,d.useCallback)(()=>{var e;let{firstComment:t,...i}=null!=(e=n.instagram)?e:{};r(a,{instagram:Object.keys(i).length>0?i:void 0}),g(!1)},[a,n.instagram,r]),y=(0,d.useCallback)(e=>{r(a,{instagram:{...n.instagram,firstComment:e}}),null==u||u.onFieldBlur("instagram-first-comment")},[a,n.instagram,r,u]),w=(0,d.useCallback)(async(e,t,a,i)=>{await l(e,"instagram-first-comment",a,i)},[l]);return"story"===n.postType?null:(0,i.jsxs)(i.Fragment,{children:[void 0===f&&(0,i.jsx)("div",{className:"p-2 pt-0",children:(0,i.jsxs)(D.$,{type:"button",variant:"outline",size:"sm",onClick:v,className:"w-full text-muted-foreground hover:text-foreground bg-card dark:bg-card transition-all duration-300",children:[(0,i.jsx)(_.A,{className:"w-4 h-4"}),p("addCommentButton")]})}),void 0!==f&&(0,i.jsx)("div",{className:"p-2 pt-0",children:(0,i.jsx)(tg.Nt,{open:x,onOpenChange:g,children:(0,i.jsxs)("div",{className:"overflow-hidden border rounded-md bg-card border-border",children:[(0,i.jsx)(tg.R6,{asChild:!0,children:(0,i.jsxs)("div",{className:"flex h-[30px] items-center justify-between px-3 cursor-pointer hover:bg-muted/50 transition-colors ".concat(x?"border-b border-border/50":""),children:[(0,i.jsxs)("div",{className:"flex min-w-0 items-center gap-3",children:[(0,i.jsx)("span",{className:"shrink-0 font-medium text-sm",children:p("comment")}),!x&&f&&(0,i.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:f.length<=30?f:f.substring(0,30)+"â¦"})]}),(0,i.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:[(0,i.jsx)(D.$,{variant:"ghost",size:"sm",onClick:e=>{e.stopPropagation(),b()},className:"h-6 px-1 text-destructive hover:text-destructive hover:bg-destructive/10",children:(0,i.jsx)(aX.A,{className:"w-4 h-4"})}),(0,i.jsx)("div",{className:"text-muted-foreground",children:x?(0,i.jsx)(ee.A,{className:"w-4 h-4"}):(0,i.jsx)(U.A,{className:"w-4 h-4"})})]})]})}),(0,i.jsx)(tg.Ke,{children:(0,i.jsxs)(tx.Wu,{className:"p-0",children:[(0,i.jsx)(aN,{noBorder:!0,accountId:"".concat(a,"-instagram-first-comment"),platform:c.SocialPlatform.INSTAGRAM,payload:{content:f},updatePayload:(e,t)=>{"content"in t&&"string"==typeof t.content&&y(t.content)},isAILoading:!!s&&s("instagram-first-comment"),onAIGenerate:w,onCreateHashtag:m,onCreateSnippet:h}),u&&(0,i.jsx)(e2,{errors:u.getFieldErrors("instagram-first-comment"),warnings:u.getFieldWarnings("instagram-first-comment"),className:"mt-1"})]})})]})})})]})}var a0=a(6278),a1=a(37811);a1.env.AI_MODEL;let a2=Number(a1.env.AI_MAX_TOKENS)||1e3,a4=Number(a1.env.AI_DEFAULT_TEMPERATURE)||.7;a0.Ik({prompt:a0.Yj(),mode:a0.k5(["write","rephrase","shorten","expand","fixGrammar","generateHashtags","translate","json"]),maxTokens:a0.ai().min(1).max(a2).default(a2),temperature:a0.ai().min(0).max(2).default(a4)});var a3=a(84295);function a5(e){var t,a,n,r,l,s,u,h,p,f,x,g,v,b,y,w,j,C,N,S,k,T,E,I,A,P,M,D,R,F,O,L;let{account:U,payload:_,updatePayload:B,onSelectImageClick:K,onCopyField:G,onUploadFromPC:W,isUploading:V,isLast:q,isOpen:H,onToggleOpen:$,onCreateHashtag:Y,onCreateSnippet:X,selectedAccountsCount:Z=1,processingItemIds:J,onConversionStarted:Q}=e,[ee,et]=(0,d.useState)({}),{postTypes:ea}=t9(U.platform,U.platform===c.SocialPlatform.X?U.isPremium:void 0),{addError:ei}=ts(),{onAICreditsUsed:en}=(0,tm.f)(),{user:er}=(0,aq.J)(),el=aV("first-comment",null==er?void 0:er.email),es=(0,d.useCallback)((e,t)=>{et(a=>({...a,[e]:t}))},[]),eo=(0,d.useCallback)(e=>ee[e]||!1,[ee]),ed=function(e){let{account:t,payload:a,enabled:i=!0}=e,n=t.id,r=t.platform,l="isPremium"in t?t.isPremium:void 0,s="expiresAt"in t||"metadata"in t?t:void 0,u=function(){let e=(0,d.useRef)({}),t=(0,d.useCallback)((t,a)=>{let i=e.current[t]||{hasBeenFocused:!1,hasBeenChanged:!1,hasBeenBlurred:!1,lastInteraction:0,interactionType:"focus"};
1e.current[t]={...i,hasBeenFocused:i.hasBeenFocused||"focus"===a,hasBeenChanged:i.hasBeenChanged||"change"===a,hasBeenBlurred:i.hasBeenBlurred||"blur"===a,lastInteraction:Date.now(),interactionType:a}},[]),a=(0,d.useCallback)(t=>{let a=e.current[t];if(!a)return!1;let i=a.hasBeenFocused||a.hasBeenChanged,n=a.hasBeenBlurred,r=Date.now()-a.lastInteraction,l=a.hasBeenChanged&&r>1e3;return i&&(n||l)},[]),i=(0,d.useCallback)(t=>e.current[t]||null,[]);return{trackInteraction:t,shouldShowErrors:a,getFieldState:i,resetField:(0,d.useCallback)(t=>{delete e.current[t]},[]),resetAll:(0,d.useCallback)(()=>{e.current={}},[])}}(),m=(0,o.useTranslations)("CreatePost.validation"),h=(0,o.useLocale)(),[p,f]=(0,d.useState)({isValid:!0,hasWarnings:!1,errors:[],warnings:[],canPublish:!0,canSaveDraft:!0}),[x,g]=(0,d.useState)(!1),v=(0,d.useMemo)(()=>({captionRequired:m("captionRequired"),descriptionRequired:m("descriptionRequired"),titleRequired:m("titleRequired"),captionTooLong:e=>{let{maxLength:t,currentLength:a}=e;return m("captionTooLong",{maxLength:t,currentLength:a})},descriptionTooLong:e=>{let{maxLength:t,currentLength:a}=e;return m("descriptionTooLong",{maxLength:t,currentLength:a})},titleTooLong:e=>{let{maxLength:t,currentLength:a}=e;return m("titleTooLong",{maxLength:t,currentLength:a})},mediaRequired:m("mediaRequired"),tooManyMedia:e=>{let{maxCount:t,currentCount:a}=e;return m("tooManyMedia",{maxCount:t,currentCount:a})},unsupportedMediaFormat:e=>{let{index:t,supportedTypes:a}=e;return m("unsupportedMediaFormat",{index:t,supportedTypes:a})},unsupportedPostType:e=>{let{postType:t,platform:a}=e;return m("unsupportedPostType",{postType:t,platform:a})},xVideoTooShort:e=>{let{index:t,duration:a}=e;return m("xVideoTooShort",{index:t,duration:a})},xVideoTooLong:e=>{let{index:t,minutes:a,seconds:i}=e;return m("xVideoTooLong",{index:t,minutes:a,seconds:i})},fileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return m("fileSizeExceeded",{index:t,maxSize:a,currentSize:i})},videoFileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return m("videoFileSizeExceeded",{index:t,maxSize:a,currentSize:i})},imageFileSizeExceeded:e=>{let{index:t,maxSize:a,currentSize:i}=e;return m("imageFileSizeExceeded",{index:t,maxSize:a,currentSize:i})},threadCommentTooLong:e=>{let{commentNumber:t,maxLength:a,currentLength:i}=e;return m("threadCommentTooLong",{commentNumber:t,maxLength:a,currentLength:i})},threadCommentEmpty:e=>{let{commentNumber:t}=e;return m("threadCommentEmpty",{commentNumber:t})},expiredAccount:m("expiredAccount",{defaultValue:"This account's token has expired. Please reconnect to continue posting."}),reconnectAccount:m("reconnectAccount",{defaultValue:"Facebook must be reconnected before publishing."}),pinterestBoardRequired:m("pinterestBoardRequired"),tiktokVisibilityRequired:m("tiktokVisibilityRequired"),tiktokDiscloseRequired:m("tiktokDiscloseRequired"),translate:(e,t)=>
1m(e,t)}),[m]);(0,d.useEffect)(()=>{if(!i)return void f({isValid:!0,hasWarnings:!1,errors:[],warnings:[],canPublish:!0,canSaveDraft:!0});(async()=>{g(!0);try{let e;e=r===c.SocialPlatform.TIKTOK?await eY.validatePayload(r,a,n,l,s,v,h):eY.validatePayloadSync(r,a,v,l,s,n,h),f(e)}catch(e){console.error("[useLiveValidation] Validation failed:",e),f(eY.validatePayloadSync(r,a,v,l,s,n,h))}finally{g(!1)}})()},[r,a,n,h,i,v,l,s]),(0,d.useEffect)(()=>(i?eX.updateAccountValidation(n,p):eX.removeAccountValidation(n),()=>{eX.removeAccountValidation(n)}),[n,p,i]);let b=(0,d.useCallback)((e,t)=>i?eY.validateField(r,e,t,a,v,l):[],[r,a,i,v,l]),y=(0,d.useCallback)(e=>{if(!i)return[];let t=p.errors.filter(t=>t.field===e);return"media"===e||"posting-cap"===e||"tiktok-disclose"===e||"pinterest-board"===e||e.startsWith("threadComment-")||u.shouldShowErrors("".concat(n,"-").concat(e))?t:[]},[p.errors,u,n,i]),w=(0,d.useCallback)(e=>i?p.warnings.filter(t=>t.field===e):[],[p.warnings,i]),j=(0,d.useCallback)(e=>{u.trackInteraction("".concat(n,"-").concat(e),"focus")},[u,n]),C=(0,d.useCallback)(e=>{u.trackInteraction("".concat(n,"-").concat(e),"blur")},[u,n]),N=(0,d.useCallback)(e=>{u.trackInteraction("".concat(n,"-").concat(e),"change")},[u,n]),S=(0,d.useMemo)(()=>i?p.errors.filter(e=>!!("media"===e.field||"posting-cap"===e.field||"tiktok-disclose"===e.field||"pinterest-board"===e.field||e.field.startsWith("threadComment-"))||u.shouldShowErrors("".concat(n,"-").concat(e.field))):[],[p.errors,u,n,i]),k=(0,d.useMemo)(()=>i?p.warnings:[],[p.warnings,i]),T=(0,d.useCallback)(e=>y(e).length>0,[y]),E=(0,d.useCallback)(e=>w(e).length>0,[w]),I=(0,d.useCallback)(e=>{u.resetField("".concat(n,"-").concat(e))},[u,n]),A=(0,d.useCallback)(()=>{u.resetAll()},[u]);return{validation:p,isValid:p.isValid,hasWarnings:p.hasWarnings,canPublish:p.canPublish,canSaveDraft:p.canSaveDraft,isLoading:x,visibleErrors:S,visibleWarnings:k,getFieldErrors:y,getFieldWarnings:w,hasFieldErrors:T,hasFieldWarnings:E,validateField:b,onFieldFocus:j,onFieldBlur:C,onFieldChange:N,resetFieldInteraction:I,resetAllInteractions:A,allErrors:p.errors,allWarnings:p.warnings}}({account:U,payload:_}),ec=(0,d.useCallback)((e,t)=>e?e.length<=t?e:e.substring(0,t)+"...":"",[]),eu=(0,z.XP)(U),em="RECONNECT_REQUIRED"===U.connectionStatus,eh=eu||em,ep=U.platform===c.SocialPlatform.X&&(null==(t=_.x)?void 0:t.threadComments)&&_.x.threadComments.length>0||U.platform===c.SocialPlatform.THREADS&&(null==(a=_.threads)?void 0:a.threadComments)&&_.threads.threadComments.length>0||U.platform===c.SocialPlatform.MASTODON&&(null==(n=_.mastodon)?void 0:n.threadComments)&&_.mastodon.threadComments.length>0,ef=(U.platform===c.SocialPlatform.X||U.platform===c.SocialPlatform.THREADS||U.platform===c.SocialPlatform.MASTODON)&&ep?"Thread":_.postType?null==(O=ea[_.postType])?void 0:O.label:null==(L=ea.feed)?void 0:L.label,ex=(0,d.useCallback)(async(e,t,a,i)=>{var n,r,l,s,o,d,c,u,m,h;let p,f,x,g=t&&(null==(r=_.x)||null==(n=r.threadComments)?void 0:n.some(e=>e.id===t)),v=t&&(null==(s=_.linkedin)||null==(l=s.comment)?void 0:l.id)===t;if(g){f=t,x="comment-".concat(f);let a=null==(d=_.x)||null==(o=d.threadComments)?void 0:o.find(e=>e.id===f);p="write"===e?(null==a?void 0:a.content)||"":null==a?void 0:a.content}else if(v){f=t,x="comment-".concat(f);let a=null==(c=_.linkedin)?void 0:c.comment;p="write"===e?(null==a?void 0:a.content)||"":null==a?void 0:a.content}else x="main",p="write"===e?t:_.content;if(!p)return void ei("Cannot perform AI action without content or a prompt.","error");"shorten"===e&&a&&(p="".concat(p,"\n\nImportant: The shortened text must be ").concat(a," characters or less.")),"expand"===e&&a&&(p="".concat(p,"\n\nCritical: The expanded text must be ").concat(a," characters or LESS. Expand the content while maintaining natural flow and readability, but DO NOT exceed ").concat(a," characters. This is a hard limit that cannot be exceeded.")),"translate"===e&&i&&(p="Translate to ".concat(i,":\n\n").concat(p)),es(x,!0);try{let t=await (0,a3.b)({prompt:p,mode:e,maxTokens:a2,temperature:a4},{source:"create-post-composer",socialPlatforms:[U.platform],socialAccountIds:[U.id]});if(t.error)throw Error(t.error);if(void 0!==t.data){let i=t.data;
1if(a&&("shorten"===e||"expand"===e)&&i.length>a&&(i=i.substring(0,a).trim()),g){let e=(null==(m=_.x)||null==(u=m.threadComments)?void 0:u.map(e=>e.id===f?{...e,content:i}:e))||[];B(U.id,{..._,x:{..._.x,threadComments:e}})}else if(v){let e=null==(h=_.linkedin)?void 0:h.comment;e&&B(U.id,{..._,linkedin:{..._.linkedin,comment:{...e,content:i}}})}else B(U.id,{..._,content:i});await en(1)}else throw Error("Received undefined data from AI generation.")}catch(e){console.error("Error calling generateAiText action:",e),ei(e instanceof Error?e.message:"AI generation failed.","error")}finally{es(x,!1)}},[U.id,_,B,ei,es,en]),eg=(0,d.useCallback)((e,t)=>{t&&eh||t!==H&&$(e,t)},[H,$,eh]);return(0,i.jsx)(tg.Nt,{open:!eh&&H,onOpenChange:e=>!eh&&eg(U.id,e),children:(0,i.jsxs)(tx.Zp,{className:(0,m.cn)("overflow-hidden shadow-none"),children:[(0,i.jsx)(ty,{account:U,isOpen:!eh&&H,payload:_,selectedPostTypeLabel:ef,truncateText:ec,validation:ed,isExpired:eu,requiresReconnect:em}),(0,i.jsxs)(tg.Ke,{children:[(0,i.jsxs)("div",{className:(0,m.cn)("relative",(U.platform===c.SocialPlatform.X||U.platform===c.SocialPlatform.THREADS||U.platform===c.SocialPlatform.MASTODON)&&"pl-0"),children:[(0,i.jsxs)("div",{className:"relative",children:[(U.platform===c.SocialPlatform.X&&((null==(l=_.x)||null==(r=l.threadComments)?void 0:r.length)||0)>0||U.platform===c.SocialPlatform.THREADS&&((null==(u=_.threads)||null==(s=u.threadComments)?void 0:s.length)||0)>0||U.platform===c.SocialPlatform.MASTODON&&((null==(p=_.mastodon)||null==(h=p.threadComments)?void 0:h.length)||0)>0)&&(0,i.jsx)("div",{className:"absolute left-[20px] top-8 bottom-0 w-px bg-border/60 z-0"}),(0,i.jsxs)(tx.Wu,{"data-post-editor-row":!0,className:(0,m.cn)("flex flex-col md:flex-row md:items-stretch gap-1 p-2 pt-1 relative z-10",!!(null==(f=_.media)?void 0:f.length)&&"md:gap-2"),children:[(U.platform===c.SocialPlatform.X&&((null==(g=_.x)||null==(x=g.threadComments)?void 0:x.length)||0)>0||U.platform===c.SocialPlatform.THREADS&&((null==(b=_.threads)||null==(v=b.threadComments)?void 0:v.length)||0)>0||U.platform===c.SocialPlatform.MASTODON&&((null==(w=_.mastodon)||null==(y=w.threadComments)?void 0:y.length)||0)>0)&&(0,i.jsx)("div",{className:"absolute left-[8px] top-1 z-20",children:(0,i.jsx)("div",{className:"flex items-center justify-center w-6 h-6 rounded-full bg-muted border border-border text-foreground shadow-sm",children:(0,i.jsx)("span",{className:"text-[10px] font-bold",children:"1"})})}),(!!(null==(j=_.media)?void 0:j.length)||U.platform===c.SocialPlatform.GOOGLE_BUSINESS&&"media"===_.postType)&&(0,i.jsx)("div",{className:(0,m.cn)(_.media&&_.media.length>0?"md:w-[40%] flex-shrink-0 flex":"md:w-auto flex-shrink-0 flex",(U.platform===c.SocialPlatform.X&&((null==(N=_.x)||null==(C=N.threadComments)?void 0:C.length)||0)>0||U.platform===c.SocialPlatform.THREADS&&((null==(k=_.threads)||null==(S=k.threadComments)?void 0:S.length)||0)>0||U.platform===c.SocialPlatform.MASTODON&&((null==(E=_.mastodon)||null==(T=E.threadComments)?void 0:T.length)||0)>0)&&"ml-8"),children:(0,i.jsx)(t3,{accountId:U.id,platform:U.platform,payload:_,updatePayload:B,onSelectImageClick:K,onCopyField:G,onUploadFromPC:W,isUploading:V,selectedAccountsCount:Z,processingItemIds:J,onConversionStarted:Q})}),(0,i.jsx)("div",{className:(0,m.cn)("flex-1",(U.platform===c.SocialPlatform.X&&((null==(A=_.x)||null==(I=A.threadComments)?void 0:I.length)||0)>0||U.platform===c.SocialPlatform.THREADS&&((null==(M=_.threads)||null==(P=M.threadComments)?void 0:P.length)||0)>0||U.platform===c.SocialPlatform.MASTODON&&((null==(R=_.mastodon)||null==(D=R.threadComments)?void 0:D.length)||0)>0)&&((null==(F=_.media)?void 0:F.length)?"ml-8 md:ml-0":"ml-8")),children:(0,i.jsx)(aY,{accountId:U.id,platform:U.platform,payload:_,updatePayload:B,isAILoading:eo("main"),onAIGenerate:ex,onCopyField:G,isPremium:U.platform===c.SocialPlatform.X?U.isPremium:void 0,validation:ed,onSelectImageClick:K,onUploadFromPC:W,isUploading:V,getAILoadingForComponent:eo,onCreateHashtag:Y,onCreateSnippet:X,selectedAccountsCount:Z})})]})]}),(U.platform===c.SocialPlatform.X||U.platform===c.SocialPlatform.THREADS||U.platform===c.SocialPlatform.MASTODON)&&(0,i.jsx)(aZ,{accountId:U.id,platform:U.platform,payload:_,updatePayload:B,onSelectImageClick:K,onCopyField:G,onUploadFromPC:W,isUploading:V,onAIGenerate:ex,getAILoadingForComponent:eo,validation:ed,onCreateHashtag:Y,onCreateSnippet:X})]}),(U.platform===c.SocialPlatform.INSTAGRAM||U.platform===c.SocialPlatform.INSTAGRAM_DIRECT)&&(el?(0,i.jsx)(aQ,{accountId:U.id,payload:_,updatePayload:B,onAIGenerate:ex,getAILoadingForComponent:eo,validation:{getFieldErrors:ed.getFieldErrors,getFieldWarnings:ed.getFieldWarnings,onFieldFocus:ed.onFieldFocus,onFieldBlur:ed.onFieldBlur},onCreateHashtag:Y,onCreateSnippet:X}):null),U.platform===c.SocialPlatform.LINKEDIN&&(0,i.jsx)(aJ,{accountId:U.id,payload:_,updatePayload:B,onCopyField:G,onAIGenerate:ex,getAILoadingForComponent:eo,validation:{getFieldErrors:ed.getFieldErrors,getFieldWarnings:ed.getFieldWarnings,onFieldFocus:ed.onFieldFocus,onFieldBlur:ed.onFieldBlur},onCreateHashtag:Y,onCreateSnippet:X}),U.platform===c.SocialPlatform.LINKEDIN_ORGANIZATION&&(0,i.jsx)(aJ,{accountId:U.id,payload:_,updatePayload:B,onCopyField:G,onAIGenerate:ex,getAILoadingForComponent:eo,validation:{getFieldErrors:ed.getFieldErrors,getFieldWarnings:ed.getFieldWarnings,onFieldFocus:ed.onFieldFocus,onFieldBlur:ed.onFieldBlur},onCreateHashtag:Y,onCreateSnippet:X})]})]})})}let a6=(0,tp.createServerReference)("40979e7bfa29921f6b40f0d70dbd2b2fb146476dc6",tp.callServer,void 0,tp.findSourceMapURL,"deletePostAction"),a8=(0,tp.createServerReference)("40f6398055bd1d013e548b9f96713ee00021ad88ea",tp.callServer,void 0,tp.findSourceMapURL,"cancelScheduledPostToDraftAction");var a9=a(2810),a7=a(30906),ie=a(11877),it=a(45528);function ia(e,t){var a,i,n,r;let{originalUrl:l,...s}=e,o=null!=(a=t.width)?a:e.width,d=null!=(i=t.height)?i:e.height;
1return{...s,id:e.id,mediaId:t.id,url:t.url,type:t.type,thumbnailUrl:null!=(n=t.thumbnailUrl)?n:void 0,width:o,height:d,aspectRatio:o&&d?o/d:e.aspectRatio,fileSize:null!=t.sizeInBytes?Number(t.sizeInBytes):e.fileSize,duration:null!=(r=t.durationSeconds)?r:e.duration}}var ii=a(69704),ir=a(2367),il=a(42128),is=a(57645),io=a(49553),id=a(9463),ic=a(9716);let iu=(0,tp.createServerReference)("4064744347153a95f634cb781f9066505e10216bd5",tp.callServer,void 0,tp.findSourceMapURL,"createPostOnlyMediaRecordAction");var im=a(62505),ih=a(96116),ip=a(15033),ix=a(51708),ig=a(60238);function iv(e){return e.type?e.type:e.name.toLowerCase().endsWith(".mov")?"video/quicktime":"application/octet-stream"}async function ib(e){let t,a=iv(e),i={};try{i=a.startsWith("video/")?await (0,ig.s)(e):await (0,ig.k)(e)}catch(e){}try{if((0,ih.$b)(e)){let a=await (0,ih.Gn)(e);t=a.success?a.blob:void 0}}catch(e){}return{file:e,type:a,metadata:i,thumbnailBlob:t}}async function iy(e){var t,a,i,n,r;let l=function(e,t){let a=[],i=e.slice(0,10).filter(e=>{let i=iv(e),n=ip.eN.has(i)?e.size<=0?"The file is empty.":e.size>t?"The file exceeds the ".concat(Math.round(t/1048576)," MB limit."):null:"Unsupported media type.";return n&&a.push({fileName:e.name,message:n}),!n});for(let t of e.slice(10))a.push({fileName:t.name,message:"Only 10 files can be uploaded at once."});return{accepted:i,failures:a}}(e.files,e.maxFileSize),s=l.failures,o=l.accepted;if(0===o.length)return{media:[],failures:s};let d=await Promise.all(o.map(ib));if(null==(t=e.signal)?void 0:t.aborted)return{media:[],failures:o.map(e=>({fileName:e.name,message:"Upload cancelled."}))};let c=new Map,u=new ii.A({restrictions:{maxNumberOfFiles:10,maxFileSize:e.maxFileSize,allowedFileTypes:[...ip.eN]},autoProceed:!1});u.use(ir.A,{async getUploadParameters(e){let t=await (0,il.X)(e.name||"media",e.type||"application/octet-stream");if(!t.data)throw Error(t.error||"Unable to start upload.");return c.set(e.id,t.data.key),{method:"PUT",url:t.data.url,fields:{},headers:{"Content-Type":e.type||"application/octet-stream"}}},async createMultipartUpload(e){let t=await (0,is.m)(e.name||"media",e.type||"application/octet-stream");if(!t.data)throw Error(t.error||"Unable to start multipart upload.");return c.set(e.id,t.data.key),t.data},listParts:async()=>[],async signPart(e,t){let{uploadId:a,key:i,partNumber:n}=t,r=await (0,io.M)(i,a,n);if(!r.data)throw Error(r.error||"Unable to sign upload part.");return{url:r.data.url}},async completeMultipartUpload(e,t){let{uploadId:a,key:i,parts:n}=t,r=await (0,id.d)(i,a,n.map(e=>({ETag:e.ETag,PartNumber:e.PartNumber})));if(!r.data)throw Error(r.error||"Unable to finish multipart upload.");return{location:r.data.location}},async abortMultipartUpload(e,t){let{uploadId:a,key:i}=t;i&&a&&await (0,ic.W)(i,a)},shouldUseMultipart:e=>{var t;return(null!=(t=e.size)?t:0)>0x6400000},getChunkSize:e=>{var t;return(null!=(t=e.size)?t:0)>524288e3?0x1400000:0xa00000}});let m=new Map;for(let e of d){let t=u.addFile({name:e.file.name,type:e.type,data:e.file});m.set(t,e)}u.on("progress",t=>{var a;return null==(a=e.onProgress)?void 0:a.call(e,t)});let h=()=>u.cancelAll();null==(a=e.signal)||a.addEventListener("abort",h,{once:!0});try{let t=await u.upload();for(let e of null!=(i=null==t?void 0:t.failed)?i:[])s.push({fileName:e.name||"media",message:e.error||"Upload failed."});return{media:(await Promise.all((null!=(n=null==t?void 0:t.successful)?n:[]).map(async t=>{let a,i,n=m.get(t.id),r=c.get(t.id);if(!n||!r)return s.push({fileName:t.name||"media",message:"Upload metadata was lost."}),null;if(n.thumbnailBlob)try{let e=await (0,ih.Jm)(n.thumbnailBlob,r,il.X);a=e.thumbnailUrl,i=e.thumbnailKey}catch(e){}let l={name:n.file.name,url:(0,ix.H)(r),type:n.type,storageKey:r,sizeInBytes:n.file.size,durationSeconds:n.metadata.duration,width:n.metadata.width,height:n.metadata.height,thumbnailUrl:a,thumbnailStorageKey:i,skipMediaProcessing:!0};try{let t="post-only"===e.mode?await iu(l):await (0,im.e)({...l,folderId:e.folderId});if(t.data)return t.data;s.push({fileName:n.file.name,message:t.error||"Unable to finalize upload."})}
1catch(e){s.push({fileName:n.file.name,message:e instanceof Error?e.message:"Unable to finalize upload."})}return null}))).filter(e=>null!==e),failures:s}}finally{null==(r=e.signal)||r.removeEventListener("abort",h),u.destroy()}}var iw=a(54194),ij=a(77648),iC=a(93949);function iN(e){let{selectedGroup:t}=e,a=(0,o.useTranslations)("CreatePost")(t?"emptyStateGroup":"emptyStateGeneral");return(0,i.jsx)(iC.p,{className:"min-h-full flex-1",description:a})}function iS(e){switch(e){case"INSTAGRAM":return"instagram";case"INSTAGRAM_DIRECT":return"instagramDirect";case"FACEBOOK":return"facebook";case"LINKEDIN":return"linkedin";case"LINKEDIN_ORGANIZATION":return"linkedinOrg";case"X":return"twitter";case"TIKTOK":return"tiktok";case"THREADS":return"threads";case"MASTODON":return"mastodon";case"BLUESKY":return"bluesky";case"PINTEREST":return"pinterest";case"YOUTUBE":return"youtube";case"TELEGRAM":return"telegram";default:return"generic"}}function ik(e){let{account:t,platformLabel:a,compact:n=!1}=e;return(0,i.jsxs)("div",{className:(0,m.cn)("flex min-w-0 items-center text-left",n?"gap-2":"gap-3"),children:[(0,i.jsx)(R.u,{account:t,size:n?"xsm":"md",disableTooltip:!0}),(0,i.jsxs)("div",{className:"min-w-0",children:[(0,i.jsx)("div",{className:(0,m.cn)("truncate font-medium",n?"text-xs":"text-sm"),children:function(e){try{let t="string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata;if(t&&"object"==typeof t){if("string"==typeof t.displayName)return t.displayName;if("string"==typeof t.name)return t.name}}catch(e){}return e.platformUsername}(t)}),(0,i.jsx)("div",{className:"truncate text-xs text-muted-foreground",children:a})]})]})}let iT=d.forwardRef(function(e,t){var a,n,r;let{onOpenChange:l,forceClose:u,selectedGroup:h,onGroupSelect:p,availableAccounts:f,onGroupCreated:x,activePreviewAccountId:g,setActivePreviewAccountId:b,isMediaGalleryOpen:j,setIsMediaGalleryOpen:C,handleMediaSelectConfirm:N,handleSelectImageClick:S,mediaSelectionLimit:k,initialPostGroup:T,preloadedSocialGroups:E,preloadedTimeSlots:A,recurringSeriesId:P,initialRecurrence:M}=e,R=(0,o.useTranslations)("CreatePost"),F=(0,o.useTranslations)("Connections.accounts"),{mutate:O}=(0,ie.iX)(),{onPostUnscheduled:L}=(0,tm.f)(),{selectedAccounts:U,filteredAccounts:_,toggleAccountSelection:K,payloads:G,updatePayload:V,commonContent:H,commonImages:$,scheduleFor:Y,setScheduleFor:X,onCopyField:J,openCardId:Q,setOpenCardId:ee,editingGroupId:ea,publishAction:ei,captionSyncEnabled:en,setCaptionSyncEnabled:er}=I(),[el,es]=(0,d.useState)(!1),eo=(0,d.useRef)(null),ed=(0,d.useRef)(null),ec=(0,d.useRef)(null);(0,d.useLayoutEffect)(()=>{let e=eo.current,t=ed.current,a=ec.current;if(!e||!t||!a)return;let i=()=>{e.style.setProperty("--create-post-header-height","".concat(t.getBoundingClientRect().height,"px")),e.style.setProperty("--create-post-footer-height","".concat(a.getBoundingClientRect().height,"px"))};i();let n=new ResizeObserver(i);return n.observe(t),n.observe(a),()=>n.disconnect()},[]);let[eu,em]=(0,d.useState)(!1),[eh,ep]=(0,d.useState)(!1),[ef,ex]=(0,d.useState)(!1),[eg,ev]=(0,d.useState)(!1),[eb,ey]=(0,d.useState)(!1),[ew,ej]=(0,d.useState)(null),[eC,eN]=(0,d.useState)({}),[eS,ek]=(0,d.useState)(()=>new Set),[eT,eE]=(0,d.useState)(0),[eI,eA]=(0,d.useState)(!1),[eP,eM]=(0,d.useState)(null),eD=(0,d.useRef)(null),{planTier:eR}=(0,et.Q)(),[eF,eO]=(0,d.useState)(()=>null!=M?M:null),ez=(0,d.useMemo)(()=>{var e,t;return null!=(t=null!=(e=U.find(e=>e.id===Q))?e:U[0])?t:null},[Q,U]),eL=(0,d.useCallback)(e=>{if(!e){er(!1),B.oR.info(R("captionSync.disabledToast"));return}if(v(G,U.map(e=>e.id)))return void em(!0);er(!0,null==ez?void 0:ez.id),B.oR.success(R("captionSync.enabledToast"))},[null==ez?void 0:ez.id,G,U,er,R]),eU=(0,d.useCallback)(()=>{er(!0,null==ez?void 0:ez.id),em(!1),B.oR.success(R("captionSync.enabledToast"))},[null==ez?void 0:ez.id,er,R]),e_=(0,d.useRef)(P);(0,d.useEffect)(()=>{e_.current!==P&&(e_.current=P,eO(null!=M?M:null))},[M,P]);let eB=(0,d.useRef)(null);(0,d.useEffect)(()=>{ea&&null===eB.current&&(eB.current={payloads:JSON.parse(JSON.stringify(G)),selectedAccountIds:U.map(e=>e.id)})},[ea,G,U]);let[eK,eG]=(0,d.useState)(!1),[eW,eV]=(0,d.useState)(!1),eq=(0,d.useCallback)(()=>{eG(!0)},[]),eH=(0,d.useCallback)(()=>{eV(!0)},[]),e$=null!=(n=null!=Q?Q:null==(a=U[0])?void 0:a.id)?n:null,eX=null!=(r=U.find(e=>e.id===Q))?r:U[0],eZ=!!e$&&g===e$,eJ=!e$,eQ=(0,d.useCallback)(()=>{e$&&b(g===e$?null:e$)},[g,e$,b]),{addError:e0}=ts(),{data:e1}=(0,e7.b)(),{workspace:e2}=(0,q.k)(),e4=(0,d.useRef)(G);(0,d.useEffect)(()=>{e4.current=G},[G]),(0,d.useEffect)(()=>()=>{var e;return null==(e=eD.current)?void 0:e.abort()},[]);let e3=(0,d.useCallback)(async(e,t)=>{if(0===e.length||0===t.length||eD.current)return;let a=new AbortController;
1eD.current=a,ek(new Set(t)),eE(0);try{var i,n,r,l,s;let o=await iy({files:e,mode:"post-only",maxFileSize:"FREE"===eR?ip.hT:ip.NS,signal:a.signal,onProgress:eE});if(o.media.length>0)for(let e of t){let t=e4.current[e],a=null!=(n=null==t?void 0:t.media)?n:[],r=function(e,t){return e.map(e=>{var a,i,n,r;return{id:t(),mediaId:e.id,url:e.url,type:e.type,alt:"",duration:null!=(a=e.durationSeconds)?a:void 0,fileSize:null!=e.sizeInBytes?Number(e.sizeInBytes):void 0,thumbnailUrl:null!=(i=e.thumbnailUrl)?i:void 0,width:null!=(n=e.width)?n:void 0,height:null!=(r=e.height)?r:void 0}})}(o.media,tQ.A),l=[...a,...r],d=null==(i=U.find(t=>t.id===e))?void 0:i.platform,c=d?(s=null==t?void 0:t.postType,"INSTAGRAM"===d||"INSTAGRAM_DIRECT"===d?w(s,l):s):null==t?void 0:t.postType;eY.clearCacheForAccount(e),V(e,{media:l,...c&&{postType:c}})}o.failures.length>0&&e0(R("mediaDrop.failed",{count:o.failures.length,reason:null!=(l=null==(r=o.failures[0])?void 0:r.message)?l:""}),"error")}catch(e){a.signal.aborted||e0(e instanceof Error?e.message:R("mediaDrop.uploadFailed"),"error")}finally{eD.current===a&&(eD.current=null),ek(new Set),eE(0)}},[e0,eR,U,R,V]),e5=(0,d.useCallback)((e,t)=>{var a;e.preventDefault(),e.stopPropagation(),eA(!1),eM(null);let i=(a=U.map(e=>e.id),"all"===t?[...a]:Q&&a.includes(Q)?[Q]:a.slice(0,1));e3(Array.from(e.dataTransfer.files),i)},[e3,Q,U]),e8=(0,d.useRef)({}),[e9,te]=(0,d.useState)({}),tt=(0,d.useCallback)(e=>{let t=e(e8.current);e8.current=t,te(t)},[]),tr=(0,d.useCallback)(e=>{tt(t=>{if(!t[e])return t;let{[e]:a,...i}=t;return i})},[tt]),tl=(0,d.useCallback)(async e=>{var t,a,i,n,r,l,s;let o=e8.current[e.conversionJobId];if(!o)return;if("completed"!==e.status)return void tr(e.conversionJobId);let d=e4.current;if(!("replace"===o.mode?Object.values(d).some(e=>{var t;return(null!=(t=e.media)?t:[]).some(e=>e.mediaId===o.sourceMediaId)}):(null!=(a=null==(t=d[o.accountId])?void 0:t.media)?a:[]).some(e=>e.id===o.composerItemId)))return void tr(e.conversionJobId);try{let t=new URLSearchParams({mediaId:e.mediaId,conversionJobId:e.conversionJobId}),a=await fetch("/api/queries/media?".concat(t.toString()),{cache:"no-store"});if(!a.ok)throw Error("Failed to load converted media");let d=await a.json();if(!(null==d?void 0:d.data))throw Error("Converted media was not returned");let c=e4.current;if("replace"===o.mode)for(let[e,t]of Object.entries(c)){let a=null!=(i=t.media)?i:[];a.some(e=>e.mediaId===o.sourceMediaId)&&(eY.clearCacheForAccount(e),V(e,{media:function(e,t,a){return e.map(e=>e.mediaId!==t?e:ia(e,a))}(a,o.sourceMediaId,d.data)}))}else{let e=null!=(r=null==(n=c[o.accountId])?void 0:n.media)?r:[];if(!e.some(e=>e.id===o.composerItemId))return;eY.clearCacheForAccount(o.accountId),V(o.accountId,{media:(l=o.composerItemId,s=d.data,e.map(e=>e.id!==l?e:ia(e,s)))})}}catch(e){e0(R("messages.mediaConversionLoadFailed"),"error")}finally{tr(e.conversionJobId)}},[e0,tr,R,V]),{registerConversionJob:tp}=(0,it.o)(!0,tl),tx=(0,d.useCallback)((e,t,a,i)=>{var n,r,l;let s=null==(n=(null!=(l=null==(r=e4.current[e])?void 0:r.media)?l:[]).find(e=>e.id===t))?void 0:n.mediaId;if(!s)return void e0(R("messages.mediaConversionLoadFailed"),"error");let o={conversionJobId:a.conversionJobId,accountId:e,composerItemId:t,sourceMediaId:s,mode:i};tt(e=>({...e,[a.conversionJobId]:o})),tp(a.conversionJobId)},[e0,tp,R,tt]);(0,d.useEffect)(()=>{tt(e=>{let t=Object.fromEntries(Object.entries(e).filter(e=>{let[,t]=e;if("copy"===t.mode){var a,i;return(null!=(i=null==(a=G[t.accountId])?void 0:a.media)?i:[]).some(e=>e.id===t.composerItemId)}return Object.values(G).some(e=>{var a;return(null!=(a=e.media)?a:[]).some(e=>e.mediaId===t.sourceMediaId)})}));return Object.keys(t).length===Object.keys(e).length?e:t})},[G,tt]);let tg=(0,d.useMemo)(()=>{let e=new Map;for(let a of Object.values(e9)){var t;let i=null!=(t=e.get(a.accountId))?t:new Set;i.add(a.composerItemId),e.set(a.accountId,i)}return e},[e9]),tv=Object.keys(e9).length>0,tb=eS.size>0,ty=tv||tb,tw=(0,d.useCallback)((e,t)=>{ee(t?e:null)},[ee]),tj=d.useMemo(()=>{if(!ea||!eB.current)return!1;let e=eB.current;for(let t of U.map(e=>e.id)){let a=G[t],i=e.payloads[t];if(JSON.stringify(a)!==JSON.stringify(i))return!0}return!1},[ea,U,G]),{publishAction:tC,isLoading:tN,handleActionSelect:tS,handleFinalAction:tk,getButtonLabel:tT,showResc
1heduleConfirm:tE,setShowRescheduleConfirm:tI,handleConfirmReschedule:tA}=function(e){var t;let{selectedAccounts:a,payloads:i,commonContent:n,scheduleFor:r,initialPublishAction:l="publish",initialScheduleDate:s,hasContentChanges:u=!1,recurrence:m=null,recurringSeriesId:h=null,setScheduleFor:p,setRecurrence:f,onOpenChange:x}=e,[g,v]=(0,d.useState)(l),[b,w]=(0,d.useState)(!1),j=(0,d.useRef)(!1),{addError:C,clearErrors:N}=ts(),{editingGroupId:S}=I(),{onPostScheduled:k,onPostUnscheduled:T}=(0,tm.f)(),E=(0,o.useTranslations)("CreatePost"),A=!!S&&"schedule"===l,P=!!((t={editingGroupId:S,recurringSeriesId:h,recurrence:m}).editingGroupId&&t.recurrence&&!t.recurringSeriesId),M=(()=>{if(!A||!s||!r)return!1;let e=r instanceof Date?r:new Date(r);return(s instanceof Date?s:new Date(s)).getTime()!==e.getTime()})(),D=()=>{w(!1),j.current=!1},R=async function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(b||j.current)return;j.current=!0,w(!0),N();let l=e||g;if("schedule"===l&&A&&M&&!t){O(!0),D();return}if(0===a.length){C("No social accounts selected.","warning"),D();return}let s=a.filter(e=>(0,z.XP)(e));if(s.length>0){let e=s.map(e=>e.platformUsername).join(", ");C(E("cannotPostExpired",{usernames:e,defaultValue:"Cannot post with expired accounts: ".concat(e,". Please reconnect them first.")}),"error"),D();return}let o=a.filter(e=>"RECONNECT_REQUIRED"===e.connectionStatus);if(o.length>0){let e=o.map(e=>e.platformUsername).join(", ");C("Reconnect Facebook before publishing with: ".concat(e,"."),"error"),D();return}if("schedule"===l&&!h){if(!r){B.oR.error(E("messages.scheduleRequired")),D();return}if((r instanceof Date?r:new Date(r))<=(0,th.z)(new Date,2)){B.oR.error(E("messages.pastScheduleError")),D();return}}if(h){if(!r||!m){B.oR.error(E("messages.scheduleRequired")),D();return}if((r instanceof Date?r:new Date(r))<=(0,th.z)(new Date,2)){B.oR.error(E("messages.pastScheduleError")),D();return}}let d={},u=!1;for(let e of a)try{let t=i[e.id],a=(null==t?void 0:t.content)&&""!==t.content.trim()?t.content:n,r=(null==t?void 0:t.media)&&t.media.length>0?t.media:void 0;d[e.id]=function(e,t,a,i,n){var r,l,s,o,d,u,m,h,p,f,x,g,v,b,w,j,C,N,S,k,T,E,I,A,P,M,D,R,F;let O=arguments.length>5&&void 0!==arguments[5]&&arguments[5];switch(e){case c.SocialPlatform.BLUESKY:return{platform:c.SocialPlatform.BLUESKY,message:t,media:a};case c.SocialPlatform.INSTAGRAM:let z=y(i,null!=(d=null==a?void 0:a.length)?d:0),L=(()=>{var e;let t=null==n||null==(e=n.instagram)?void 0:e.userTags;if(!t||0===Object.keys(t).length)return;let i=a||(null==n?void 0:n.media)||[],r={};for(let[e,a]of Object.entries(t)){let t=i.findIndex(t=>t.id===e);-1!==t&&a.length>0&&(r[String(t)]=a)}return Object.keys(r).length>0?r:void 0})();return{platform:c.SocialPlatform.INSTAGRAM,message:t,media:a||[],postType:z,..."reel"===z&&{shareToFeed:!0},...L&&{userTags:L},...(null==n||null==(r=n.instagram)?void 0:r.locationId)&&{locationId:n.instagram.locationId,locationName:n.instagram.locationName},...(null==n||null==(l=n.instagram)?void 0:l.firstComment)!==void 0&&{firstComment:n.instagram.firstComment},...(null==n||null==(o=n.instagram)||null==(s=o.collaborators)?void 0:s.length)&&{collaborators:n.instagram.collaborators}};case c.SocialPlatform.INSTAGRAM_DIRECT:let U=y(i,null!=(m=null==a?void 0:a.length)?m:0);return{platform:c.SocialPlatform.INSTAGRAM_DIRECT,message:t,media:a||[],postType:U,..."reel"===U&&{shareToFeed:!0},...(null==n||null==(u=n.instagram)?void 0:u.firstComment)!==void 0&&{firstComment:n.instagram.firstComment}};case c.SocialPlatform.PINTEREST:if(!(null==a?void 0:a.length)&&!O)throw Error("Pinterest requires at least one media item");let _=(null==n||null==(h=n.pinterest)?void 0:h.board)||"",B=(null==n||null==(p=n.pinterest)?void 0:p.section)||void 0;if(!_&&!O)throw Error("Pinterest requires a board selection (boardId missing).");return{platform:c.SocialPlatform.PINTEREST,message:t,media:a,settings:{board:_||"draft-placeholder",...(null==n||null==(f=n.pinterest)?void 0:f.title)&&{title:n.pinterest.title},...(null==n||null==(x=n.pinterest)?void 0:x.link)&&{link:n.pinterest.link},...B&&{section:B}}};case c.SocialPlatform.MASTODON:let K=i&&["public","unlisted","private","direct"].includes(i)?i:"public";return{platform:c.SocialPlatform.MASTODON,message:t,media:a,postType:K,threadComments:null==n||null==(v=n.mastodon)||null==(g=v.threadComments)?void 0:g.map(e=>({id:e.id,content:e.content,media:e.media}))};case c.SocialPlatform.LINKEDIN:let G={platform:c.SocialPlatform.LINKEDIN,message:t,media:a,postType:"personal"};return(null==n||null==(b=n.linkedin)?void 0:b.comment)&&(G.linkedin={comment:{id:n.linkedin.comment.id,content:n.linkedin.comment.content,media:n.linkedin.comment.media}}),G;case c.SocialPlatform.LINKEDIN_ORGANIZATION:let W={platform:c.SocialPlatform.LINKEDIN_ORGANIZATION,message:t,media:a,postType:"company"};return(null==n||null==(w=n.linkedin)?void 0:w.comment)&&(W.linkedin={comment:{id:n.linkedin.comment.id,content:n.linkedin.comment.content,media:n.linkedin.comment.media}}),W;case c.SocialPlatform.TIKTOK:if((!a||0===a.length)&&!O)throw Error("TikTok requires a video.");let V=null==n?void 0:n.tiktok;return{platform:c.SocialPlatform.TIKTOK,message:t,media:a||[],privacyLevel:(null==V?void 0:V.privacyLevel)||"PUBLIC_TO_EVERYONE",disableDuet:(null==V?void 0:V.disableDuet)||!1,disableStitch:(null==V?void 0:V.disableStitch)||!1,disableComment:(null==V?void 0:V.disableComment)||!1,discloseContent:(null==V?void 0:V.discloseContent)||!1,isYourBrand:(null==V?void 0:V.isYourBrand)||!1,isBrandedContent:(null==V?void 0:V.isBrandedContent)||!1};case c.SocialPlatform.THREADS:let q="TEXT";if(a&&a.length>0)q=1===a.length?(null==(C=a[0].type)?void 0:C.startsWith("image/"))?"IMAGE":(null==(N=a[0].type)?void 0:N.startsWith("video/"))?"VIDEO":"TEXT":"CAROUSEL";else if(!t&&!O)throw Error("Threads requires text or media.");return{platform:c.SocialPlatform.THREADS,text:t,media:a||[],media_type:q,threadComments:null==n||null==(j=n.threads)?void 0:j.threadComments};case c.SocialPlatform.X:let H=null==a?void 0:a.map(e=>({mediaId:e.mediaId,url:e.url||"",alt:e.alt,type:e.type,fileSize:e.fileSize,width:e.width,height:e.height,duration:e.duration})).filter(e=>e.url);return{platform:c.SocialPlatform.X,message:t,media:H&&H.length>0?H:void 0,postType:"tweet",...(null==n||null==(S=n.x)?void 0:S.communityId)&&{communityId:n.x.communityId,communityName:n.x.communityName,communityThumbnailUrl:n.x.communityThumbnailUrl,shareWithFollowers:null==(E=n.x.shareWithFollowers)||E},threadComments:null==n||null==(T=n.x)||null==(k=T.threadComments)?void 0:k.map(e=>{var t;return{id:e.id,content:e.content,media:null==(t=e.media)?void 0:t.map(e=>({mediaId:e.mediaId,url:e.url,alt:e.alt,type:e.type,fileSize:e.fileSize,width:e.width,height:e.height,duration:e.duration}))}})};
1case c.SocialPlatform.YOUTUBE:if((!a||0===a.length||!a[0].url)&&!O)throw Error("YouTube requires a video.");let $=null==n?void 0:n.youtube;if(!(null==$?void 0:$.title)&&!O)throw Error("YouTube requires a video title.");let Y=(null==$?void 0:$.privacyStatus)||"private";return{platform:c.SocialPlatform.YOUTUBE,title:(null==$?void 0:$.title)||"Draft Title",description:(null==$?void 0:$.description)||t,media:a||[],privacyStatus:Y,tags:null==$?void 0:$.tags,categoryId:null==$?void 0:$.categoryId,videoType:"video",customThumbnail:(null==$||null==(I=$.customThumbnail)?void 0:I.mediaId)?$.customThumbnail:void 0,thumbnailMediaId:(null==$||null==(A=$.customThumbnail)?void 0:A.mediaId)?void 0:(null==$||null==(P=$.customThumbnail)?void 0:P.url)||(null==$?void 0:$.thumbnailMediaId)};case c.SocialPlatform.FACEBOOK:let X=null==a?void 0:a.map(e=>({url:e.url,alt:e.alt,type:e.type})),Z="feed";return(null==n?void 0:n.postType)&&("reel"===n.postType||"story"===n.postType||"feed"===n.postType)?Z=n.postType:a&&1===a.length&&(null==(M=a[0].type)?void 0:M.startsWith("video/"))&&(Z="feed"),{platform:c.SocialPlatform.FACEBOOK,message:t,media:X,postType:Z,title:null==n||null==(D=n.youtube)?void 0:D.title,description:null==n||null==(R=n.youtube)?void 0:R.description};case c.SocialPlatform.TELEGRAM:return{platform:c.SocialPlatform.TELEGRAM,message:t,...(null==n||null==(F=n.telegram)?void 0:F.pin)!==void 0&&{pin:n.telegram.pin},media:a};case c.SocialPlatform.GOOGLE_BUSINESS:{let e=["standard","event","offer","media"].includes(null!=i?i:"")?i:"standard";return{platform:c.SocialPlatform.GOOGLE_BUSINESS,message:t,media:a,postType:e,...null==n?void 0:n.googleBusiness}}default:throw Error("Unsupported platform for payload creation: ".concat(e))}}(e.platform,a,r,null==t?void 0:t.postType,t,"draft"===l)}catch(t){"draft"!==l?(C("Error preparing for ".concat(e.platformUsername||e.platform,": ").concat(t instanceof Error?t.message:"Unknown error"),"error"),u=!0):console.warn("Draft validation warning for ".concat(e.platformUsername,":"),t)}if(u&&"draft"!==l)return void D();if(0===Object.keys(d).length&&a.length>0)if("draft"===l);else{C("Nothing to post. Please add content or media to at least one selected account.","warning"),D();return}try{var p;if(h){x(!1);let e=B.oR.loading(E("messages.updatingContent",{defaultValue:"Updating recurring post..."}));try{let t=await tf(h,d,r instanceof Date?r.toISOString():new Date(r).toISOString(),m);B.oR.dismiss(e),t.error?B.oR.error(t.error):(B.oR.success(E("messages.contentUpdated",{defaultValue:"Recurring post updated."})),await (0,W.xj)())}catch(t){B.oR.dismiss(e),B.oR.error(t instanceof Error?t.message:"Failed to update recurring post.")}finally{D()}return}if((p={isEditingScheduledPost:A,finalAction:l,scheduleChanged:M,editingGroupId:S,recurringConversion:P}).isEditingScheduledPost&&"schedule"===p.finalAction&&!p.scheduleChanged&&p.editingGroupId&&!p.recurringConversion){x(!1),D();let e=B.oR.loading(E("messages.updatingContent",{defaultValue:"Updating content..."})),t=JSON.stringify({groupPostsId:S,platformPayloads:d});fetch("/api/posts/content",{method:"PATCH",keepalive:t.length<=6e4,headers:{"Content-Type":"application/json"},body:t}).then(async t=>{let a=await t.json();if(t.ok||a.error||(a.error="Failed to update post content."),B.oR.dismiss(e),a.error)B.oR.error(a.error||"Failed to update post content.");else{try{await (0,W.xj)()}catch(e){console.error("Failed to refresh posts data:",e)}B.oR.success(E("messages.contentUpdated",{defaultValue:"Content updated! Post will be published at the scheduled time."}),{duration:5e3})}}).catch(t=>{B.oR.dismiss(e),B.oR.error("Failed to update post content"),console.error("Error updating content:",t)});return}x(!1),D();let e=B.oR.loading((()=>{switch(l){case"publish":return E("messages.publishing",{defaultValue:"Publishing posts..."});case"schedule":return E("messages.scheduling",{defaultValue:"Scheduling posts..."});case"draft":return E("messages.savingDraft",{defaultValue:"Saving draft..."});default:return"Processing..."}})());(async()=>{try{var t,n,s;let o=JSON.stringify({platformPayloads:d,scheduledFor:"schedule"===l&&r?r instanceof Date?r.toISOString():new Date(r).toISOString():null,isDraft:"draft"===l,editingGroupId:S,recurrence:"schedule"===l?m:null}),c=await fetch("/api/posts/create",{method:"POST",keepalive:o.length<=6e4,headers:{"Content-Type":"application/json"},body:o}),u=await c.json().catch(()=>null);if(!c.ok)throw Error((null==u?void 0:u.error)||"Failed to create posts: ".concat(c.statusText));if("publish"!==l||u.error||await tn(null==(n=u.results)||null==(t=n[0])?void 0:t.groupPostsId,null==(s=a[0])?void 0:s.workspaceId),B.oR.dismiss(e),u.error)B.oR.error(u.error||"Failed to process posts.");else{if("publish"===l){(0,tu.sx)(tu.qW.CREATE_POST_PUBLISH,{account_count:a.length,has_media:Object.values(i).some(e=>(null==e?void 0:e.media)&&e.media.length>0),platforms:a.map(e=>e.platform).join(",")});let e=!function(){try{return document.documentElement.classList.contains("dark")}catch(e){return!1}}()?[...tc]:[...td];(0,to.A)({particleCount:100,spread:70,origin:{y:.6},colors:e,...void 0}),B.oR.success(E("messages.publishSuccess"),{duration:5e3})}else"schedule"===l?((0,tu.sx)(tu.qW.CREATE_POST_SCHEDULE,{account_count:a.length,has_media:Object.values(i).some(e=>(null==e?void 0:e.media)&&e.media.length>0),platforms:a.map(e=>e.platform).join(",")}),await k(),B.oR.success(E(P?"messages.recurringConversionSuccess":"messages.scheduleSuccess"),{duration:5e3})):"draft"===l&&((0,tu.sx)(tu.qW.CREATE_POST_DRAFT,{account_count:a.length,has_media:Object.values(i).some(e=>(null==e?void 0:e.media)&&e.media.length>0),platforms:a.map(e=>e.platform).join(",")}),B.oR.success(E("messages.draftSuccess"),{duration:3e3}));try{await (0,W.xj)()}catch(e){console.error("Failed to refresh posts data:",e)}}}catch(t){B.oR.dismiss(e),B.oR.error(t instanceof Error?t.message:"An error occurred");try{await (0,W.xj)()}catch(e){console.error("Failed to refresh posts data:",e)}}})()}catch(e){C(e instanceof Error?e.message:"An error occurred","error"),D()}},[F,O]=(0,d.useState)(!1),L=async()=>{O(!1),A&&await T(),await R("schedule",!0)};return{publishAction:g,isLoading:b,handleActionSelect:e=>{if(v(e),"schedule"===e){if(!r){let e=new Date;e.setHours(e.getHours()+1),p(e)}}else f(null)},handleFinalAction:R,getButtonLabel:()=>{if(h)return E("actions.saveChanges",{defaultValue:"Save Changes"});if(P)return E("actions.makeRecurring",{defaultValue:"Make recurring"});switch(g){case"publish":default:return E("actions.publishNow");case"schedule":if(A&&!M&&u)return E("actions.saveChanges",{defaultValue:"Save Changes"});return A?E("actions.reschedule"):E("actions.schedule");case"draft":return E("actions.saveDraft")}}
1,showRescheduleConfirm:F,setShowRescheduleConfirm:O,handleConfirmReschedule:L}}({selectedAccounts:U,payloads:G,commonContent:H,scheduleFor:Y,initialPublishAction:ei,initialScheduleDate:(null==T?void 0:T.scheduledFor)?new Date(T.scheduledFor):null,hasContentChanges:tj,recurrence:eF,recurringSeriesId:P,setScheduleFor:X,setRecurrence:eO,onOpenChange:u}),tP=(0,d.useCallback)(async e=>{if(tN||ty)return;let t=e||tC;return"publish"===t?void ex(!0):tk(t)},[tC,tk,tN,ty]),tM=(0,d.useCallback)(async()=>{if(!tN&&!ty)return ex(!1),tk("publish")},[tk,tN,ty]),tD=(0,d.useCallback)(async()=>{if(!tN&&!ty)return tA()},[ty,tN,tA]),tR=(0,d.useCallback)(()=>{ep(!0)},[]),tF=(0,d.useCallback)(()=>{if(!ea)return void e0("No post ID found for deletion.","error");if(eg)return;let e=!!((null==T?void 0:T.groupStatus)===c.PostStatus.PENDING&&T.scheduledFor);ep(!1),l(!1),(0,ij.u)({key:"post:delete:".concat(ea),messages:{loading:R("messages.deletingPost",{defaultValue:"Deleting post..."}),success:R("messages.postDeleted",{defaultValue:"Post deleted"}),error:e=>e.message||R("messages.deletePostFailed",{defaultValue:"Failed to delete the post."})},action:async()=>{let e=await a6(ea);if(!e.success)throw Error(e.error||"Failed to delete the post.");return e},onSuccess:async()=>{e&&await L(),await (0,W.xj)()}})},[e0,ea,T,eg,l,L,R]),tO=!!ea,tz=!!((null==T?void 0:T.groupStatus)===c.PostStatus.PENDING&&T.scheduledFor),tL=!!(tO&&T&&(T.groupStatus===c.PostStatus.DRAFT||tz)),tU=(0,d.useCallback)(async()=>{if(!ea)return void e0(R("confirmations.deletePost.cancelToDraftFailed"),"error");if(!eg){ev(!0);try{let e=await a8(ea);if(!e.success)return void e0(e.error||R("confirmations.deletePost.cancelToDraftFailed"),"error");await L(),(0,W.xj)(),l(!1)}catch(e){console.error("Error cancelling schedule and creating draft:",e),e0(R("confirmations.deletePost.cancelToDraftFailed"),"error")}finally{ev(!1),ep(!1)}}},[e0,ea,eg,l,L,R]),t_=(0,d.useCallback)(()=>{if(tb)return void es(!0);(()=>{if(ea&&eB.current){let e=eB.current,t=U.map(e=>e.id).sort(),a=[...e.selectedAccountIds].sort();if(JSON.stringify(t)!==JSON.stringify(a))return!0;for(let a of t){let t=G[a],i=e.payloads[a];if(JSON.stringify(t)!==JSON.stringify(i))return!0}return!1}return!!(H&&""!==H.trim()||$&&$.length>0||U.some(e=>{let t=G[e.id];return t&&(t.content&&""!==t.content.trim()||t.media&&t.media.length>0)}))||U.some(e=>{var t;let a=G[e.id];return null!=a&&null!=(t=a.x)&&!!t.threadComments&&a.x.threadComments.some(e=>e.content&&""!==e.content.trim()||e.media&&e.media.length>0)})})()?es(!0):l(!1)},[U,G,H,$,l,es,ea,tb]);(0,d.useImperativeHandle)(t,()=>({handleAttemptClose:t_}),[t_]);let tB=async()=>{if(!tN&&!ty){try{ea&&"schedule"===ei?await tP("schedule"):await tP("draft")}catch(e){console.error("Error saving:",e)}es(!1),l(!1)}},tK=(0,d.useCallback)((e,t)=>{ej(e),eN(t=>({...t,[e]:!0})),ey(!0)},[]),tG=(0,d.useCallback)(e=>{ey(e),!e&&ew&&(eN(e=>({...e,[ew]:!1})),ej(null))},[ew]),tW=(0,d.useCallback)(e=>{if(!ew)return void console.error("[CreatePost] â No active account ID for upload");try{setTimeout(()=>{try{let t=e.map(e=>{var t,a,i,n,r;return{id:(0,tQ.A)(),mediaId:e.id,url:e.url,type:e.type,alt:"",duration:null!=(t=e.durationSeconds)?t:void 0,fileSize:null!=(a=e.sizeInBytes)?a:void 0,thumbnailUrl:null!=(i=e.thumbnailUrl)?i:void 0,width:null!=(n=e.width)?n:void 0,height:null!=(r=e.height)?r:void 0}}),a=G[ew],i=[...(null==a?void 0:a.media)||[],...t];eY.clearCacheForAccount(ew),V(ew,{media:i}),eN(e=>({...e,[ew]:!1})),ey(!1),ej(null)}catch(e){console.error("[CreatePost] â Error during media conversion:",e),eN(e=>({...e,[ew]:!1}))}},100)}catch(e){console.error("[CreatePost] â Error in upload completion handler:",e),eN(e=>({...e,[ew]:!1}))}},[ew,V,G]);return(0,i.jsxs)("div",{ref:eo,className:"absolute inset-0 min-h-0 min-w-0 overflow-hidden rounded-[inherit]",onDragEnterCapture:e=>{e.dataTransfer.types.includes("Files")&&0!==U.length&&!ty&&(e.preventDefault(),eA(!0))},onDragOverCapture:e=>{e.dataTransfer.types.includes("Files")&&eI&&(e.preventDefault(),e.dataTransfer.dropEffect="copy")},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||(eA(!1),eM(null))},onDrop:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),eA(!1),eM(null))},children:[eI&&(0,i.jsx)("div",{"data-testid":"media-drop-composer-overlay",className:"absolute inset-0 z-[80] hidden flex-col items-center justify-center gap-5 bg-background/95 p-5 backdrop-blur-sm md:flex",children:U.length>1?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)("div",{className:"pointer-events-none text-center",children:[(0,i.jsx)(iw.A,{className:"mx-auto mb-2 h-8 w-8 text-primary"}),(0,i.jsx)("p",{className:"text-base font-semibold",children:R("mediaDrop.cho
1oseDestination")})]}),(0,i.jsxs)("div",{className:"grid w-full max-w-2xl grid-cols-2 gap-4",children:[(0,i.jsxs)("div",{"data-testid":"media-drop-all-accounts",className:(0,m.cn)("flex min-h-52 flex-col items-center justify-center rounded-xl border-2 border-dashed p-5 text-center transition-all duration-150","all"===eP?"scale-[1.02] border-primary bg-primary/15 shadow-lg shadow-primary/10 ring-2 ring-primary/20":"border-muted-foreground/40 bg-muted/20","active"===eP&&"scale-[0.98] opacity-55"),onDragEnter:e=>{e.preventDefault(),eM("all")},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||"all"===eP&&eM(null)},onDrop:e=>e5(e,"all"),children:[(0,i.jsx)("span",{className:"font-semibold",children:R("mediaDrop.addToAll")}),(0,i.jsx)("span",{className:"mt-1 text-sm text-muted-foreground",children:R("mediaDrop.addToAllHint",{count:U.length})}),(0,i.jsx)("div",{className:"mt-4 grid max-h-28 w-full grid-cols-1 gap-2 overflow-y-auto rounded-lg bg-background/70 p-2 sm:grid-cols-2",children:U.map(e=>(0,i.jsx)(ik,{account:e,compact:!0,platformLabel:F("platformTypes.".concat(iS(e.platform)))},e.id))})]}),(0,i.jsxs)("div",{"data-testid":"media-drop-active-account",className:(0,m.cn)("flex min-h-52 flex-col items-center justify-center rounded-xl border-2 border-dashed p-5 text-center transition-all duration-150","active"===eP?"scale-[1.02] border-primary bg-primary/15 shadow-lg shadow-primary/10 ring-2 ring-primary/20":"border-muted-foreground/40 bg-muted/20","all"===eP&&"scale-[0.98] opacity-55"),onDragEnter:e=>{e.preventDefault(),eM("active")},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||"active"===eP&&eM(null)},onDrop:e=>e5(e,"active"),children:[(0,i.jsx)("span",{className:"font-semibold",children:R("mediaDrop.addToActive")}),(0,i.jsx)("span",{className:"mt-1 text-sm text-muted-foreground",children:R("mediaDrop.addToActiveHint")}),eX?(0,i.jsx)("div",{className:"mt-4 w-full rounded-lg bg-background/70 p-2",children:(0,i.jsx)(ik,{account:eX,compact:!0,platformLabel:F("platformTypes.".concat(iS(eX.platform)))})}):null]})]})]}):(0,i.jsxs)("div",{"data-testid":"media-drop-single-account",className:(0,m.cn)("flex w-full max-w-md min-h-52 flex-col items-center justify-center rounded-xl border-2 border-dashed p-5 text-center transition-all duration-150","active"===eP?"scale-[1.02] border-primary bg-primary/15 shadow-lg shadow-primary/10 ring-2 ring-primary/20":"border-muted-foreground/40 bg-muted/20"),onDragEnter:e=>{e.preventDefault(),eM("active")},onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||"active"===eP&&eM(null)},onDrop:e=>e5(e,"active"),children:[(0,i.jsx)(iw.A,{className:"mb-2 h-8 w-8 text-primary"}),(0,i.jsx)("span",{className:"font-semibold",children:R("mediaDrop.addToAccount")}),(0,i.jsx)("span",{className:"mt-1 text-sm text-muted-foreground",children:R("mediaDrop.addToAccountHint")}),eX?(0,i.jsx)("div",{className:"mt-4 w-full rounded-lg bg-background/70 p-2",children:(0,i.jsx)(ik,{account:eX,compact:!0,platformLabel:F("platformTypes.".concat(iS(eX.platform)))})}):U[0]?(0,i.jsx)("div",{className:"mt-4 w-full rounded-lg bg-background/70 p-2",children:(0,i.jsx)(ik,{account:U[0],compact:!0,platformLabel:F("platformTypes.".concat(iS(U[0].platform)))})}):null]})}
1),ty&&(0,i.jsx)("div",{className:"pointer-events-none absolute inset-x-0 top-[72px] z-[55] flex flex-col items-center gap-2 px-4",children:(0,i.jsxs)("div",{"data-testid":"media-drop-upload-progress",role:"status",className:"pointer-events-auto flex max-w-md items-center gap-3 rounded-xl border border-border/25 bg-background/45 px-4 py-3 text-center text-sm text-foreground shadow-lg shadow-black/5 ring-1 ring-black/5 backdrop-blur-xl dark:bg-background/35 dark:ring-white/10 animate-in fade-in-0 zoom-in-95 duration-200",children:[(0,i.jsx)(s.F.spinner,{className:"h-4 w-4 shrink-0 animate-spin text-muted-foreground"}),(0,i.jsx)("span",{className:"min-w-0 flex-1 text-center leading-snug",children:tb?R("mediaDrop.uploading",{progress:eT}):R("actions.waitForMediaProcessing")})]})}),(0,i.jsx)("div",{ref:ed,className:"absolute inset-x-0 top-0 z-30 rounded-t-[inherit]",children:(0,i.jsx)(Z,{filteredAccounts:_,selectedAccounts:U,toggleAccountSelection:K,selectedGroup:h,onGroupSelect:p,availableAccounts:f,onGroupCreated:x,preloadedSocialGroups:E,captionSyncEnabled:en,onCaptionSyncChange:eL,onClose:t_})}),(0,i.jsx)("div",{className:"absolute inset-x-0 top-px bottom-px overflow-x-hidden overflow-y-auto overscroll-y-contain ai-chat-scrollbar",children:(0,i.jsxs)("div",{className:(0,m.cn)("w-full px-3 pt-[calc(var(--create-post-header-height,116px)+0.5rem)] pb-[calc(var(--create-post-footer-height,76px)+1rem)] md:px-3",0===U.length?"flex min-h-full flex-col":"space-y-2"),children:[U.map((e,t)=>(0,i.jsx)(a5,{account:e,payload:G[e.id]||{},updatePayload:V,onSelectImageClick:S,onUploadFromPC:tK,isLast:t===U.length-1,onCopyField:J,isOpen:Q===e.id,onToggleOpen:tw,isUploading:eC[e.id]||eS.has(e.id),onCreateHashtag:eq,onCreateSnippet:eH,selectedAccountsCount:U.length,processingItemIds:tg.get(e.id),onConversionStarted:tx},e.id)),0===U.length&&(0,i.jsx)(iN,{selectedGroup:!!h})]})}),(0,i.jsx)("div",{ref:ec,className:"absolute inset-x-0 bottom-0 z-30 rounded-b-[inherit]",children:(0,i.jsx)(e6,{isLoading:tN,isDeleting:!1,publishAction:tC,onActionSelect:tS,onFinalAction:tP,getButtonLabel:tT,scheduleFor:Y,onScheduleChange:X,onCancelClick:t_,selectedAccountsCount:U.length,isEditing:tL,onDeleteClick:tL?tR:void 0,preloadedTimeSlots:A,onPreviewClick:eQ,isPreviewActive:eZ,isPreviewDisabled:eJ,recurrence:eF,onRecurrenceChange:eO,timezone:(null==e2?void 0:e2.country)||Intl.DateTimeFormat().resolvedOptions().timeZone,recurringEditMode:!!P,isMediaProcessing:ty})}),(0,i.jsx)(ta,{open:j,onOpenChange:C,onSelect:N,maxSelectionCount:k}),(0,i.jsx)(ti.C,{open:eb,onOpenChange:tG,onUploadComplete:tW,folderHierarchy:e1,initialFolderId:void 0}),(0,i.jsx)(aL.Lt,{open:eu,onOpenChange:em,children:(0,i.jsxs)(aL.EO,{className:"z-[60]",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:R("captionSync.confirmTitle")}),(0,i.jsx)(aL.$v,{children:R("captionSync.confirmDescription",{platform:ez?F("platformTypes.".concat(iS(ez.platform))):"",account:ez?ez.platformUsername:""})})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>em(!1),children:R("captionSync.cancel")}),(0,i.jsx)(aL.Rx,{onClick:eU,children:R("captionSync.confirm")})]})]})}),(0,i.jsx)(aL.Lt,{open:el,onOpenChange:es,children:(0,i.jsxs)(aL.EO,{className:"z-[60]",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:R("confirmations.unsavedChanges.title")}),(0,i.jsx)(aL.$v,{children:R("confirmations.unsavedChanges.description")})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>es(!1),disabled:tN,children:R("actions.cancel")}),(0,i.jsx)(D.$,{variant:"outline",onClick:()=>{var e;null==(e=eD.current)||e.abort(),l(!1),es(!1)},disabled:tN,children:R("confirmations.unsavedChanges.dontSave")}),(0,i.jsx)(aL.Rx,{onClick:tB,disabled:tN||ty,children:tN?R("actions.processing"):ea&&"schedule"===ei?R("actions.saveChanges",{defaultValue:"Save Changes"}):R("actions.saveDraft")})]})]})}),(0,i.jsx)(aL.Lt,{open:eh,onOpenChange:e=>{e||eg||ep(!1)},children:(0,i.jsxs)(aL.EO,{className:"z-[60] sm:max-w-md",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:R("confirmations.deletePost.title")}),(0,i.jsx)(aL.$v,{children:R(tz?"confirmations.deletePost.scheduledDescription":"confirmations.deletePost.defaultDescription")})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>ep(!1),disabled:eg,children:R("confirmations.deletePost.cancel")}),tz&&(0,i.jsxs)(D.$,{variant:"outline",onClick:()=>void tU(),disabled:eg,className:"gap-2 whitespace-nowrap",children:[eg&&(0,i.jsx)(s.F.spinner,{className:"h-4 w-4 animate-spin"}
1),eg?R("confirmations.deletePost.cancelToDraftProcessing"):R("confirmations.deletePost.cancelToDraft")]}),(0,i.jsx)(aL.Rx,{onClick:e=>{e.preventDefault(),tF()},disabled:eg,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90 gap-2",children:R("confirmations.deletePost.confirm")})]})]})}),(0,i.jsx)(aL.Lt,{open:ef,onOpenChange:ex,children:(0,i.jsxs)(aL.EO,{className:"z-[60]",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:R("confirmations.publishNow.title")}),(0,i.jsx)(aL.$v,{children:R("confirmations.publishNow.description")})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>ex(!1),disabled:tN,children:R("confirmations.publishNow.cancel")}),(0,i.jsx)(aL.Rx,{onClick:tM,disabled:tN||ty,className:"bg-primary text-primary-foreground hover:bg-primary/90",children:tN?R("actions.processing"):R("confirmations.publishNow.confirm")})]})]})}),(0,i.jsx)(aL.Lt,{open:tE,onOpenChange:tI,children:(0,i.jsxs)(aL.EO,{className:"z-[60]",children:[(0,i.jsxs)(aL.wd,{children:[(0,i.jsx)(aL.r7,{children:R("confirmations.reschedulePost.title")}),(0,i.jsx)(aL.$v,{children:R("confirmations.reschedulePost.description")})]}),(0,i.jsxs)(aL.ck,{children:[(0,i.jsx)(aL.Zr,{onClick:()=>tI(!1),disabled:tN,children:R("confirmations.reschedulePost.cancel")}),(0,i.jsx)(aL.Rx,{onClick:tD,disabled:tN||ty,className:"bg-primary text-primary-foreground hover:bg-primary/90",children:tN?R("actions.processing"):R("confirmations.reschedulePost.confirm")})]})]})}),(0,i.jsx)(a9.n,{open:eK,onOpenChange:eG,onDataChange:()=>{if(null==e2?void 0:e2.id){(0,W.tW)(e2.id);try{let e="/api/queries/hashtags?workspaceId=".concat(e2.id);O(e,void 0,{revalidate:!0}),O("/api/queries/settings",void 0,{revalidate:!0}),O(e=>"string"==typeof e&&e.includes("hashtags"),void 0,{revalidate:!0})}catch(e){console.error("Failed to refresh hashtags cache:",e)}}}}),(0,i.jsx)(a7.V,{open:eW,onOpenChange:eV,onDataChange:()=>{if(null==e2?void 0:e2.id){(0,W.tW)(e2.id);try{let e="/api/queries/text-snippets?workspaceId=".concat(e2.id);O(e,void 0,{revalidate:!0}),O("/api/queries/settings",void 0,{revalidate:!0}),O(e=>"string"==typeof e&&e.includes("text-snippets"),void 0,{revalidate:!0})}catch(e){console.error("Failed to refresh text snippets cache:",e)}}}})]})});iT.displayName="DialogContent";var iE=a(79857);a(5781),a(80810);var iI=a(12691);function iA(e){switch(e){case c.SocialPlatform.X:return"twitter";case c.SocialPlatform.INSTAGRAM:case c.SocialPlatform.INSTAGRAM_DIRECT:return"instagram";case c.SocialPlatform.LINKEDIN:case c.SocialPlatform.LINKEDIN_ORGANIZATION:return"linkedin";case c.SocialPlatform.FACEBOOK:return"facebook";case c.SocialPlatform.TIKTOK:return"tiktok";case c.SocialPlatform.YOUTUBE:return"youtube";case c.SocialPlatform.PINTEREST:return"pinterest";case c.SocialPlatform.THREADS:return"threads";case c.SocialPlatform.BLUESKY:return"bluesky";case c.SocialPlatform.MASTODON:return"mastodon";case c.SocialPlatform.TELEGRAM:return"telegram";default:return null}}function iP(e,t){var a,i,n,r,l,s,o,d,c,u,m,h,p,f,x,g,v,b,y,w,j,C,N,S,k,T;let E=null==(a=t.media)?void 0:a[0],I=null!=(h=null!=(m=null==E?void 0:E.thumbnailUrl)?m:null==E?void 0:E.url)?h:null,A=(t.media||[]).map(e=>{var t,a,i,n;return{url:null!=(t=e.thumbnailUrl)?t:e.url,type:e.type||"image/jpeg",width:null!=(a=e.width)?a:void 0,height:null!=(i=e.height)?i:void 0,thumbnailUrl:null!=(n=e.thumbnailUrl)?n:void 0}}),P=[];if(null==(n=t.x)||null==(i=n.threadComments)?void 0:i.length)for(let e of t.x.threadComments)e.content&&P.push({text:e.content,image:null!=(x=null==(f=e.media)||null==(p=f[0])?void 0:p.url)?x:null});if(null==(l=t.threads)||null==(r=l.threadComments)?void 0:r.length)for(let e of t.threads.threadComments)e.content&&P.push({text:e.content,image:null!=(b=null==(v=e.media)||null==(g=v[0])?void 0:g.url)?b:null});if((null==(o=t.linkedin)||null==(s=o.comment)?void 0:s.content)&&P.push({text:t.linkedin.comment.content,image:null!=(j=null==(w=t.linkedin.comment.media)||null==(y=w[0])?void 0:y.url)?j:null}),null==(c=t.mastodon)||null==(d=c.threadComments)?void 0:d.length)for(let e of t.mastodon.threadComments)e.content&&P.push({text:e.content,image:null!=(S=null==(N=e.media)||null==(C=N[0])?void 0:C.url)?S:null});return{text:null!=(k=t.content)?k:"",image:null!=I?I:null,media:A.length>0?A:void 0,username:e.platformUsername,displayName:e.platformUsername,avatarUrl:function(e){try{if(!e.metadata)return null;let t="string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata,a=t.avatar;if(a&&"object"==typeof a&&a.r2Key&&1)return"https://".concat("media.dopost.co","/").concat(a.r2Key);for(let e of[t.profilePictureUrl,t.profile_picture_url,t.profile_image_url,t.threads_profile_picture_url,t.profilePicture,t.profile_image,t.avatar_url,"string"==typeof t.avatar?t.avatar:null])if("string"==typeof e&&e)return e;let i=t.picture;if(i&&"object"==typeof i){let e=i.data;if(e&&"object"==typeof e){let t=e.url;if("string"==typeof t&&t)return t}}return null}catch(e){return null}}(e),date:new Date,verified:!1,isPinned:null!=(T=null==(u=t.telegram)?void 0:u.pin)&&T,...P.length>0?{threadItems:P}:{}}}var iM=a(47269),iD=a(75950),iR=a(49466),iF=a(63568),iO=a(86118),iz=a(37395),iL=a(98240),iU=a(25883),i_=a(29315),iB=a(63655),iK=a(49291);let iG={twitter:"Twitter/X",instagram:"Instagram",linkedin:"LinkedIn",facebook:"Facebook",tiktok:"TikTok",youtube:"YouTube",pinterest:"Pinterest",threads:"Threads",bluesky:"Bluesky",mastodon:"Mastodon",telegram:"Telegram"}
1,iW={twitter:iM.R,instagram:iD.q,linkedin:iR.Q,facebook:iF.C,tiktok:iO.q,youtube:iz.Z,pinterest:iL.i,threads:iU.R,bluesky:i_.x,mastodon:iB.N,telegram:iK.d};function iV(e){let{account:t,payload:a,onClose:n}=e,[r,s]=(0,d.useState)(null),o=(0,d.useRef)(null),{resolvedTheme:c}=(0,iE.D)(),u=iA(t.platform),m=iP(t,a),h=!!u&&iI.zW.includes(u),p=!!u&&iI.oG.includes(u);if((0,d.useEffect)(()=>{let e=()=>{let e=document.querySelector(".create-post-dialog-content");if(!e)return void s(null);let t=e.offsetWidth,a=e.offsetHeight;if(0===t||0===a)return;let i=Math.min(236,Math.max(0,(window.innerWidth-t)/2-16));e.style.transition="transform ".concat(150,"ms ease-out"),e.style.transform="translate(calc(-50% - ".concat(i,"px), -50%)");let n=window.innerWidth/2+t/2-i+12,r=Math.min(460,Math.max(280,window.innerWidth-16-n));s({left:n,top:(window.innerHeight-a)/2,height:a,width:r})};e(),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0);let t=document.querySelector(".create-post-dialog-content");return t&&(o.current=new ResizeObserver(e),o.current.observe(t)),()=>{var t;window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0),null==(t=o.current)||t.disconnect();let a=document.querySelector(".create-post-dialog-content");a&&(a.style.transition="transform ".concat(150,"ms ease-out"),a.style.transform="translate(-50%, -50%)",setTimeout(()=>{a&&(a.style.transition="")},150))}},[]),!r)return null;let f=u?iW[u]:null,x="story"===a.postType?"story":"reel"===a.postType?"reel":"feed",g="short"===a.postType?"short":"video",v=(0,i.jsxs)("div",{style:{position:"fixed",left:r.left,top:r.top,height:r.height,width:r.width,zIndex:50},className:"flex flex-col bg-background border border-border rounded-lg shadow-xl overflow-hidden animate-in fade-in-0 slide-in-from-left-8 duration-150 ease-out",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-background/80 backdrop-blur-sm flex-shrink-0",children:[(0,i.jsx)("div",{className:"flex items-center gap-2 min-w-0",children:(0,i.jsx)("span",{className:"text-sm font-semibold text-foreground",children:u?"".concat(iG[u]," Preview"):"Preview"})}),(0,i.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:n,"aria-label":"Close preview",children:(0,i.jsx)(tA.A,{className:"h-4 w-4"})})})]}),(0,i.jsx)("div",{className:"flex-1 overflow-y-auto ai-chat-scrollbar p-3".concat("instagram"===u||"youtube"===u&&"short"===g?" flex items-start justify-center":""),children:f?(0,i.jsx)(f,{data:m,theme:h||p&&"dark"===c?"dark":"light",instagramVariant:"instagram"===u?x:void 0,youtubeVariant:"youtube"===u?g:void 0}):(0,i.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground text-center p-4",children:"Preview not available for this platform."})})]});return(0,l.createPortal)(v,document.body)}var iq=a(31033),iH=a(94335);let i$=d.createContext(null);function iY(){let e=d.useContext(i$);if(!e)throw Error("useCarousel must be used within a <Carousel />");return e}let iX=d.forwardRef((e,t)=>{let{orientation:a="horizontal",opts:n,setApi:r,plugins:l,className:s,children:o,...c}=e,[u,h]=(0,iq.A)({...n,axis:"horizontal"===a?"x":"y"},l),[p,f]=d.useState(!1),[x,g]=d.useState(!1),v=d.useCallback(e=>{e&&(f(e.canScrollPrev()),g(e.canScrollNext()))},[]),b=d.useCallback(()=>{null==h||h.scrollPrev()},[h]),y=d.useCallback(()=>{null==h||h.scrollNext()},[h]),w=d.useCallback(e=>{"ArrowLeft"===e.key?(e.preventDefault(),b()):"ArrowRight"===e.key&&(e.preventDefault(),y())},[b,y]);return d.useEffect(()=>{h&&r&&r(h)},[h,r]),d.useEffect(()=>{if(h)return v(h),h.on("reInit",v),h.on("select",v),()=>{null==h||h.off("select",v)}},[h,v]),(0,i.jsx)(i$.Provider,{value:{carouselRef:u,api:h,opts:n,orientation:a||((null==n?void 0:n.axis)==="y"?"vertical":"horizontal"),scrollPrev:b,scrollNext:y,canScrollPrev:p,canScrollNext:x},children:(0,i.jsx)("div",{ref:t,onKeyDownCapture:w,className:(0,m.cn)("relative",s),role:"region","aria-roledescription":"carousel",...c,children:o})})});
1iX.displayName="Carousel";let iZ=d.forwardRef((e,t)=>{let{className:a,...n}=e,{carouselRef:r,orientation:l}=iY();return(0,i.jsx)("div",{ref:r,className:"overflow-hidden",children:(0,i.jsx)("div",{ref:t,className:(0,m.cn)("flex","horizontal"===l?"-ml-4":"-mt-4 flex-col",a),...n})})});iZ.displayName="CarouselContent";let iJ=d.forwardRef((e,t)=>{let{className:a,...n}=e,{orientation:r}=iY();return(0,i.jsx)("div",{ref:t,role:"group","aria-roledescription":"slide",className:(0,m.cn)("min-w-0 shrink-0 grow-0 basis-full","horizontal"===r?"pl-4":"pt-4",a),...n})});iJ.displayName="CarouselItem",d.forwardRef((e,t)=>{let{className:a,variant:n="outline",size:r="icon",...l}=e,{orientation:s,scrollPrev:o,canScrollPrev:d}=iY();return(0,i.jsxs)(D.$,{ref:t,variant:n,size:r,className:(0,m.cn)("absolute h-8 w-8 rounded-full","horizontal"===s?"-left-12 top-1/2 -translate-y-1/2":"-top-12 left-1/2 -translate-x-1/2 rotate-90",a),disabled:!d,onClick:o,...l,children:[(0,i.jsx)(Y.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"sr-only",children:"Previous slide"})]})}).displayName="CarouselPrevious",d.forwardRef((e,t)=>{let{className:a,variant:n="outline",size:r="icon",...l}=e,{orientation:s,scrollNext:o,canScrollNext:d}=iY();return(0,i.jsxs)(D.$,{ref:t,variant:n,size:r,className:(0,m.cn)("absolute h-8 w-8 rounded-full","horizontal"===s?"-right-12 top-1/2 -translate-y-1/2":"-bottom-12 left-1/2 -translate-x-1/2 rotate-90",a),disabled:!d,onClick:o,...l,children:[(0,i.jsx)(iH.A,{className:"h-4 w-4"}),(0,i.jsx)("span",{className:"sr-only",children:"Next slide"})]})}).displayName="CarouselNext";let iQ={twitter:"Twitter/X",instagram:"Instagram",linkedin:"LinkedIn",facebook:"Facebook",tiktok:"TikTok",youtube:"YouTube",pinterest:"Pinterest",threads:"Threads",bluesky:"Bluesky",mastodon:"Mastodon",telegram:"Telegram"},i0={twitter:iM.R,instagram:iD.q,linkedin:iR.Q,facebook:iF.C,tiktok:iO.q,youtube:iz.Z,pinterest:iL.i,threads:iU.R,bluesky:i_.x,mastodon:iB.N,telegram:iK.d};function i1(e){let{accounts:t,payloadsByAccountId:a,initialAccountId:n,onClose:r,onSlideChange:l}=e,[s,o]=(0,d.useState)(),[c,u]=(0,d.useState)(0),{resolvedTheme:m}=(0,iE.D)(),h=(0,d.useMemo)(()=>{if(!n)return 0;let e=t.findIndex(e=>e.id===n);return e>=0?e:0},[t,n]);(0,d.useEffect)(()=>{s&&(s.scrollTo(h,!0),u(h))},[s,h]),(0,d.useEffect)(()=>{if(!s)return;let e=()=>{let e=s.selectedScrollSnap();u(e);let a=t[e];a&&l(a.id)};return e(),s.on("select",e),s.on("reInit",e),()=>{s.off("select",e),s.off("reInit",e)}},[s,t,l]);let p=t[c],f=p?iA(p.platform):null;return(0,i.jsx)("div",{className:"fixed inset-0 z-[55] bg-black/50 backdrop-blur-sm animate-in fade-in-0 duration-200",children:(0,i.jsx)("div",{className:"fixed inset-x-0 top-0 h-[92vh] bg-background border-b border-border rounded-b-xl shadow-2xl animate-in slide-in-from-top-8 duration-300 ease-out",children:(0,i.jsxs)("div",{className:"flex h-full flex-col",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-background/90 backdrop-blur-sm",children:[(0,i.jsx)("div",{className:"min-w-0",children:(0,i.jsx)("p",{className:"text-sm font-semibold text-foreground truncate",children:f?"".concat(iQ[f]," Preview"):"Preview"})}),(0,i.jsx)(D.$,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:r,"aria-label":"Close preview",children:(0,i.jsx)(tA.A,{className:"h-4 w-4"})})]}),(0,i.jsx)("div",{className:"flex justify-center py-2",children:(0,i.jsx)("div",{className:"flex items-center gap-1.5",children:t.map((e,t)=>(0,i.jsx)("span",{className:t===c?"h-1.5 w-1.5 rounded-full bg-foreground":"h-1.5 w-1.5 rounded-full bg-muted-foreground/40","aria-hidden":"true"},e.id))})}),(0,i.jsx)("div",{className:"flex-1 overflow-hidden px-1 pb-2",children:(0,i.jsx)(iX,{setApi:o,opts:{align:"start"},className:"h-full",children:(0,i.jsx)(iZ,{className:"h-full",children:t.map(e=>{var t;let n=null!=(t=a[e.id])?t:{},r=iA(e.platform),l=iP(e,n),s=r?i0[r]:null,o=!!r&&iI.zW.includes(r),d=!!r&&iI.oG.includes(r),c="story"===n.postType?"story":"reel"===n.postType?"reel":"feed",u="short"===n.postType?"short":"video";return(0,i.jsx)(iJ,{className:"h-full",children:(0,i.jsx)("div",{className:"h-full overflow-y-auto ai-chat-scrollbar px-1 py-2",children:s?(0,i.jsx)(s,{data:l,theme:o||d&&"dark"===m?"dark":"light",instagramVariant:"instagram"===r?c:void 0,youtubeVariant:"youtube"===r?u:void 0,fullWidth:!0}):(0,i.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground text-center p-4",children:"Preview not available for this platform."})})},e.id)})})})})]})})})}var i2=a(55335),i4=a(40382),i3=a(34351);let i5=(0,d.memo)(e=>{var t,a;let{setMainDialogOpenState:n,forceClose:r,socialAccounts:l,onGroupCreated:s,preloadedSocialGroups:o,preloadedT
1imeSlots:c,registerCloseAttemptHandler:u,initialPostGroup:m,recurringSeriesId:h,initialRecurrence:p}=e,{currentGroupId:f,setCurrentGroupId:x,setSelectedAccounts:g,selectedAccounts:v,payloads:b,updatePayload:y,openCardId:w}=I(),[j,C]=(0,d.useState)(null),N=(0,H.a)();(0,d.useEffect)(()=>{j&&w&&w!==j&&C(w)},[w]);let[S,k]=(0,d.useState)(!1),[T,E]=(0,d.useState)(null),[A,P]=(0,d.useState)(null),M=(0,d.useRef)(null);(0,d.useEffect)(()=>{u(()=>{var e;null==(e=M.current)||e.handleAttemptClose()})},[u]);let D=(0,d.useRef)(!1);(0,d.useEffect)(()=>{if(m||!(null==o?void 0:o.length)||D.current||null!==f)return;let e=o.find(e=>{var t;return e.isDefault&&(null==(t=e.socialAccounts)?void 0:t.length)>0&&e.socialAccounts.some(e=>e.isActive)});e&&x(e.id),D.current=!0},[m,o,f,x]);let R=(0,d.useCallback)(e=>{if(x(e),null!==e&&l){let t=l.filter(t=>Array.isArray(t.socialGroups)&&t.socialGroups.some(t=>t.id===e));g(t),t.forEach(e=>{b[e.id]||y(e.id,{})})}},[x,g,l,b,y]),F=(0,d.useCallback)(async(e,t)=>{E(e),P(t||null),k(!0)},[]),O=(0,d.useCallback)(e=>{if(e&&T&&b){let n=v.find(e=>e.id===T),r=Array.isArray(e)?e:[e],l=(A||(null==n?void 0:n.platform)!=="YOUTUBE"?r:r.slice(0,1)).map(e=>{var t,a,i,n,r;return{id:(0,tQ.A)(),mediaId:e.id,url:e.url,type:e.type,alt:"",duration:null!=(t=e.durationSeconds)?t:void 0,fileSize:null!=(a=e.sizeInBytes)?a:void 0,thumbnailUrl:null!=(i=e.thumbnailUrl)?i:void 0,width:null!=(n=e.width)?n:void 0,height:null!=(r=e.height)?r:void 0}});if(A){var t,a,i;let e=b[T];if(null==e||null==(t=e.x)?void 0:t.threadComments){let t=e.x.threadComments.map(e=>{if(e.id===A){let t=e.media||[];return{...e,media:[...t,...l]}}return e});y(T,{x:{...e.x,threadComments:t}})}if(null==e||null==(a=e.threads)?void 0:a.threadComments){let t=e.threads.threadComments.map(e=>{if(e.id===A){let t=e.media||[];return{...e,media:[...t,...l]}}return e});y(T,{threads:{...e.threads,threadComments:t}})}if(null==e||null==(i=e.mastodon)?void 0:i.threadComments){let t=e.mastodon.threadComments.map(e=>{if(e.id===A){let t=e.media||[];return{...e,media:[...t,...l]}}return e});y(T,{mastodon:{...e.mastodon,threadComments:t}})}}else{let e=b[T],t=[...(null==e?void 0:e.media)||[],...l];eY.clearCacheForAccount(T),y(T,{media:t})}}k(!1),E(null),P(null)},[T,A,v,y,b]),z=v.find(e=>e.id===T),L=A||(null==z?void 0:z.platform)!=="YOUTUBE"?void 0:1,U=j&&null!=(t=v.find(e=>e.id===j))?t:null,_=j&&null!=(a=b[j])?a:{};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(iT,{ref:M,onOpenChange:n,forceClose:r,selectedGroup:f,onGroupSelect:R,availableAccounts:null!=l?l:[],onGroupCreated:s,activePreviewAccountId:j,setActivePreviewAccountId:C,isMediaGalleryOpen:S,setIsMediaGalleryOpen:k,handleMediaSelectConfirm:O,handleSelectImageClick:F,mediaSelectionLimit:L,initialPostGroup:m,preloadedSocialGroups:o,preloadedTimeSlots:c,recurringSeriesId:h,initialRecurrence:p}),U&&(N?(0,i.jsx)(i1,{accounts:v,payloadsByAccountId:b,initialAccountId:j,onClose:()=>C(null),onSlideChange:C}):(0,i.jsx)(iV,{account:U,payload:_,onClose:()=>C(null)}))]})});function i6(e){var t;let{open:a,onOpenChange:c,initialPostGroup:u,initialMedia:m,initialScheduledDate:h,initialPublishAction:p,initialContent:f,preloadedSocialAccounts:x,preloadedSocialGroups:g,preloadedTimeSlots:v,duplicateMode:b,recurringSeriesId:y,initialRecurrence:w}=e,j=(0,o.useTranslations)("CreatePost.header"),{socialAccounts:C,isLoading:N,error:S,setSocialAccounts:k}=(0,M.I)(a,x),{user:T,isLoading:I}=(0,i3.x)(),{hashtagCollections:A,isLoading:P}=(0,i2.l)(),{textSnippetCollections:D,isLoading:R}=(0,i4.l)(),[F,O]=(0,d.useState)(a),z=(0,d.useRef)(null),L=(0,d.useRef)(0),U=(0,d.useRef)(null);(0,d.useEffect)(()=>{a&&!F&&(L.current=Date.now()),O(a)},[a,F]);let _=e=>{let t=Date.now();if(e)L.current=t,O(!0),a||c(!0);else{if(t-L.current<300)return;z.current?z.current():(O(!1),c(!1))}},B=(0,d.useCallback)(e=>{z.current=e},[]),K=(0,d.useCallback)(()=>{z.current=null,O(!1),c(!1)},[c]);return(0,d.useEffect)(()=>{if(F){let e=window.innerWidth-document.documentElement.clientWidth;document.body.style.overflow="hidden",document.body.style.paddingRight="".concat(e,"px")}else document.querySelector('[data-state="open"][role="dialog"]')||(document.body.style.overflow="",document.body.style.paddingRight="");return()=>{document.querySelector('[data-state="open"][role="dialog"]')||(document.body.style.overflow="",document.body.style.paddingRight="")}},[F]),(0,i.jsxs)(i.Fragment,{children:[F&&"undefined"!=typeof document&&(0,l.createPortal)((0,i.jsx)("div",{className:"fixed inset-0 z-[35] hidden bg-black/50 backdrop-blur-sm animate-in fade-in-0 duration-200 create-post-dialog-backdrop md:block",onClick:e=>{e.stopPropagation(),Date.now()-L.current>300&&_(!1)}}),document.body),(0,i.jsx)(n.lG,{open:F,onOpenChange:_,modal:!1,children:(0,i.jsxs)(n.Cf,{ref:U,tabIndex:-1,hideOverlay:!0,className:"inset-0 left-0 top-0 z-[40] flex h-[100dvh] w-screen max-w-none max-md:!max-w-none translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden rounded-none border-0 p-0 shadow-none create-post-dialog-content max-md:data-[state=closed]:zoom-out-100 max-md:data-[state=open]:zoom-in-100 max-md:data-[state=closed]:slide-out-to-left-0 max-md:data-[state=open]:slide-in-from-left-0 max-md:data-[state=closed]:slide-out-to-top-0 max-md:data-[state=open]:slide-in-from-top-0 md:left-[50%] md:top-[50%] md:h-[90vh] md:w-[calc(100vw-3rem)] md:max-w-[900px] md:translate-x-[-50%] md:translate-y-[-50%] md:rounded-lg md:border-0 md:after:pointer-events-none md:after:absolute md:after:inset-0 md:after:z-50 md:after:rounded-[inherit] md:after:border md:after:border-border md:shadow-lg [&>[data-slot=dialog-close]]:max-md:hidden",onOpenAutoFocus:e=>{var t;
1e.preventDefault(),null==(t=U.current)||t.focus({preventScroll:!0})},onPointerDownOutside:e=>{let t=e.target;if(Date.now()-L.current<300||t.closest('[role="dialog"]')||t.closest(".create-post-dialog-content"))return void e.preventDefault()},onInteractOutside:e=>{},onFocusOutside:e=>{e.preventDefault()},onEscapeKeyDown:e=>{},children:[(0,i.jsx)(r.s6,{children:(0,i.jsx)(n.L3,{children:j("title")})}),N||I?(0,i.jsxs)("div",{className:"flex flex-col items-center justify-center h-full space-y-4",children:[(0,i.jsx)(s.F.spinner,{className:"h-8 w-8 animate-spin text-primary"}),(0,i.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading social accounts..."})]}):S?(0,i.jsxs)("div",{className:"flex flex-col items-center justify-center h-full space-y-4",children:[(0,i.jsx)(s.F.helpCircle,{className:"h-8 w-8 text-destructive"}),(0,i.jsx)("p",{className:"text-sm text-destructive",children:S})]}):C?(0,i.jsx)(E,{allSocialAccounts:C,initialPostGroup:u,initialMedia:m,initialScheduledDate:h,initialPublishAction:p,initialContent:f,hashtagCollections:A,textSnippetCollections:D,isLoadingHashtagsAndSnippets:P||R,duplicateMode:b||!!y,initialCaptionSyncEnabled:null!=(t=null==T?void 0:T.syncPostCaptions)&&t,children:(0,i.jsx)(tl,{children:(0,i.jsx)(i5,{setMainDialogOpenState:e=>{e||(z.current=null),O(e),c(e)},forceClose:K,socialAccounts:C,onGroupCreated:e=>{let t=new Set(e.socialAccounts.map(e=>e.id));k(C.map(a=>{var i;return{...a,socialGroups:[...(null!=(i=a.socialGroups)?i:[]).map(t=>e.isDefault?{...t,isDefault:!1}:t),...t.has(a.id)?[e]:[]]}}))},preloadedSocialGroups:g,preloadedTimeSlots:v,registerCloseAttemptHandler:B,initialPostGroup:u,recurringSeriesId:y,initialRecurrence:w})})}):(0,i.jsxs)("div",{className:"flex flex-col items-center justify-center h-full space-y-4",children:[(0,i.jsx)(s.F.helpCircle,{className:"h-8 w-8 text-destructive"}),(0,i.jsx)("p",{className:"text-sm text-destructive",children:"No social accounts found."})]})]})})]})}i5.displayName="ContentWrapper"},28863:(e,t,a)=>{"use strict";a.d(t,{R:()=>r});var i=a(7778);a(85418);var n=a(25065);function r(e){let{children:t,className:a,contentClassName:r,contained:l=!1,variant:s="page",containedSize:o="default",disableScroll:d=!1}=e;return(0,i.jsx)("div",{className:(0,n.cn)("bg-white dark:bg-[#1a1a1b] text-foreground flex flex-col focus:outline-none focus-visible:outline-none","page"===s&&"min-h-[var(--dashboard-content-height)] max-h-[var(--dashboard-content-height)]","page"===s&&"lg:min-h-[calc(var(--dashboard-available-height)-32px)] lg:max-h-[calc(var(--dashboard-available-height)-32px)] lg:mt-[16px]","page"===s&&!d&&"overflow-y-auto ai-chat-scrollbar","page"===s&&d&&"overflow-hidden","page"===s&&"rounded-lg [scrollbar-gutter:stable]","calendar"===s&&"h-full rounded-lg","card"===s&&"rounded-lg","dialog"===s&&"rounded-lg",a),children:(0,i.jsx)("div",{className:(0,n.cn)("flex flex-col flex-1 min-h-0","page"===s&&"px-4 md:px-6 py-6 max-lg:pb-[calc(1.5rem+var(--dashboard-bottom-nav-space,0px))]","page"===s&&!d&&"max-lg:flex-none max-lg:min-h-full","card"===s&&"p-6","dialog"===s&&"p-4","calendar"===s&&"h-full","calendar"===s&&"h-full",l&&"default"===o&&"container w-full max-w-screen-md mx-auto",l&&"wide"===o&&"container w-full max-w-4xl mx-auto","overflow-visible",r),children:t})})}},31194:(e,t,a)=>{"use strict";a.d(t,{Kg:()=>u,Lf:()=>m,b:()=>d,cs:()=>s,jt:()=>o,mx:()=>h,x9:()=>c,xV:()=>p});var i=a(49737),n=a(11357),r=a(16698);function l(e,t){var a,l,s,o;let{workspace:d}=(0,n.k)(),c=null==d?void 0:d.id,u=c?"/api/queries/media/".concat(e).concat(e.includes("?")?"&":"?","workspaceId=").concat(c):null,{data:m,error:h,isLoading:p,mutate:f}=(0,i.Ay)(u,async t=>{let a=new AbortController,i=setTimeout(()=>a.abort(),3e4);try{let n=await fetch(t,{signal:a.signal});if(clearTimeout(i),!n.ok)throw console.error("â [FETCH DEBUG] API request failed: ".concat(n.status," ").concat(n.statusText," for ").concat(t)),Error("Failed to fetch ".concat(e));return await n.json()}catch(a){if(clearTimeout(i),a instanceof Error&&"AbortError"===a.name)throw console.error("â [FETCH DEBUG] Request timeout for ".concat(t)),Error("Request timeout for ".concat(e));throw a}},{refreshInterval:null!=(a=null==t?void 0:t.refreshInterval)?a:6e4,revalidateOnFocus:null==(l=null==t?void 0:t.revalidateOnFocus)||l,revalidateOnMount:null==(s=null==t?void 0:t.revalidateOnMount)||s,dedupingInterval:null!=(o=null==t?void 0:t.dedupingInterval)?o:2e3,errorRetryCount:1,errorRetryInterval:5e3,shouldRetryOnError:e=>{var t;return null==e||null==(t=e.message)||!t.includes("timeout")},onError:t=>{console.error("[SWR] Error fetching ".concat(e,":"),null==t?void 0:t.message)}});return(0,r.t4)(e=>{f()}),{data:null==m?void 0:m.data,error:h,isLoading:p||!c,mutate:f}}function s(e,t){var a,i;let{workspace:s}=(0,n.k)(),o=null==s?void 0:s.id,d=l(e?"contents?folderId=".concat(e):"contents",{refreshInterval:3e4,revalidateOnFocus:null==(a=null==t?void 0:t.revalidateOnFocus)||a,revalidateOnMount:null==(i=null==t?void 0:t.revalidateOnMount)||i,dedupingInterval:2e3}),c=async()=>
1{if(o)return await (0,r.A)(o)},u=async()=>{if(o)return await (0,r.A)(o)},m=async()=>{if(o)return await (0,r.A)(o)};return{...d,refreshContents:c,refreshContentsAndHierarchy:u,refreshAllMediaData:m}}function o(e){let{workspace:t}=(0,n.k)(),a=null==t?void 0:t.id,i=l("".concat(e?"contents?folderId=".concat(e):"contents").concat(e?"&":"?","youTubeThumbnailOnly=true"),{refreshInterval:3e4,revalidateOnFocus:!0,dedupingInterval:2e3}),s=async()=>{if(a)return await (0,r.A)(a)},o=async()=>{if(a)return await (0,r.A)(a)},d=async()=>{if(a)return await (0,r.A)(a)};return{...i,refreshContents:s,refreshContentsAndHierarchy:o,refreshAllMediaData:d}}function d(){let{workspace:e}=(0,n.k)(),t=null==e?void 0:e.id,a=l("hierarchy",{refreshInterval:3e5,revalidateOnFocus:!1,dedupingInterval:1e4}),i=async()=>{if(t)return await (0,r.A)(t)};return{data:a.data,error:a.error,isLoading:a.isLoading,mutate:a.mutate,refreshHierarchy:i}}function c(e){let t=s(e),a=d(),{workspace:i}=(0,n.k)(),l=null==i?void 0:i.id;return{contents:t.data,hierarchy:a.data,isLoadingContents:t.isLoading,isLoadingHierarchy:a.isLoading,isLoading:t.isLoading,contentsError:t.error,hierarchyError:a.error,error:t.error||a.error,mutateContents:t.mutate,mutateHierarchy:a.mutate,refreshTargeted:{contents:async()=>await t.refreshContents(),hierarchy:async()=>await a.refreshHierarchy(),contentsAndHierarchy:async()=>await t.refreshContentsAndHierarchy(),all:async()=>await t.refreshAllMediaData(),byOperation:async(e,t)=>l?"update-media"===e&&t?await (0,r.A)(l,{action:"replace",targetMediaId:t}):await (0,r.A)(l,{aggressive:"update-media"===e}):void console.warn("No workspace ID available for cache invalidation")},refreshContents:t.refreshContents,refreshHierarchy:a.refreshHierarchy,refreshAllMediaData:t.refreshAllMediaData}}async function u(e){let{itemIds:t,itemType:a,destinationFolderId:i}=e,n=await fetch("/api/media/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({itemIds:t,itemType:a,destinationFolderId:i})});if(!n.ok)throw Error((await n.json().catch(()=>({error:"Unknown error"}))).error||"Failed to move ".concat(a,"s"));return await n.json()}async function m(e){let{name:t,parentId:a,color:i}=e,n=await fetch("/api/media/create-folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t,parentId:a,color:i})});if(!n.ok)throw Error((await n.json().catch(()=>({error:"Unknown error"}))).error||"Failed to create folder");return await n.json()}async function h(e){let{items:t}=e,a=await fetch("/api/media/bulk-delete",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:t})});if(!a.ok)throw Error((await a.json().catch(()=>({error:"Unknown error"}))).error||"Failed to bulk delete items");return await a.json()}async function p(e){let{itemId:t,itemType:a,newName:i,color:n}=e,r=await fetch("/api/media/update",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({itemId:t,itemType:a,newName:i,color:n})});if(!r.ok)throw Error((await r.json().catch(()=>({error:"Unknown error"}))).error||"Failed to update ".concat(a));return await r.json()}},36088:(e,t,a)=>{"use strict";a.d(t,{d:()=>n});var i=a(85418);function n(e,t){let[a,n]=(0,i.useState)(e);return(0,i.useEffect)(()=>{let a=setTimeout(()=>{n(e)},t);return()=>{clearTimeout(a)}},[e,t]),a}},37606:(e,t,a)=>{"use strict";a.d(t,{k:()=>J});var i=a(7778),n=a(20389),r=a(3854),l=a(50330),s=a(72488),o=a(72374),d=a(92919),c=a(2713),u=a(85191),m=a(30605),h=a(85418),p=a(95258),f=a(90137);function x(e,t,a){return"px"===e.unit?{unit:"px",x:e.x,y:e.y,width:e.width,height:e.height}:{unit:"px",x:e.x/100*t,y:e.y/100*a,width:e.width/100*t,height:e.height/100*a}}function g(e,t){if(!e.naturalWidth||!e.naturalHeight||!e.width||!e.height)return null;let a=x(t,e.width,e.height),i=e.naturalWidth/e.width,n=e.naturalHeight/e.height,r=Math.round(a.x*i),l=Math.round(a.y*n),s=Math.round(a.width*i),o=Math.round(a.height*n);return s<1||o<1?null:{x:Math.max(0,Math.min(r,e.naturalWidth-1)),y:Math.max(0,Math.min(l,e.naturalHeight-1)),width:Math.min(s,e.naturalWi
1dth-r),height:Math.min(o,e.naturalHeight-l)}}var v=a(15033),b=a(28067);let y=(0,b.createServerReference)("40bf5253c536ab1e5f7230c84f652da1e14625f55c",b.callServer,void 0,b.findSourceMapURL,"startConvertMediaAction");var w=a(31194),j=a(19873),C=a(66467);let N=[{id:"ig-feed-landscape",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-feed-landscape",labelKey:"ig-feed-landscape",width:1080,height:566,mediaKinds:["image","video"],linkedPostType:"feed",noteKey:"ig-feed-landscape"},{id:"ig-feed-vertical",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-feed-vertical",labelKey:"ig-feed-vertical",width:1080,height:1350,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"ig-feed-square",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-feed-square",labelKey:"ig-feed-square",width:1080,height:1080,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"ig-carousel",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-carousel",labelKey:"ig-carousel",width:1080,height:1350,mediaKinds:["image","video"],linkedPostType:"carousel",noteKey:"ig-carousel"},{id:"ig-story",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-story",labelKey:"ig-story",width:1080,height:1920,mediaKinds:["image","video"],linkedPostType:"story"},{id:"ig-reel-feed",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-reel-feed",labelKey:"ig-reel-feed",width:1080,height:1920,mediaKinds:["video"],linkedPostType:"reel"},{id:"ig-reel-grid",platform:C.SocialPlatform.INSTAGRAM,contentTypeKey:"ig-reel-grid",labelKey:"ig-reel-grid",width:1080,height:1440,mediaKinds:["video"],linkedPostType:"reel",noteKey:"ig-reel-grid"},{id:"tt-video",platform:C.SocialPlatform.TIKTOK,contentTypeKey:"tt-video",labelKey:"tt-video",width:1080,height:1920,mediaKinds:["video"],linkedPostType:"post",noteKey:"tt-video"},{id:"tt-carousel",platform:C.SocialPlatform.TIKTOK,contentTypeKey:"tt-carousel",labelKey:"tt-carousel",width:1080,height:1920,mediaKinds:["image","video"],linkedPostType:"post",noteKey:"tt-carousel"},{id:"tt-carousel-square",platform:C.SocialPlatform.TIKTOK,contentTypeKey:"tt-carousel-square",labelKey:"tt-carousel-square",width:1080,height:1080,mediaKinds:["image"],linkedPostType:"post",noteKey:"tt-carousel-square"},{id:"tt-carousel-vertical",platform:C.SocialPlatform.TIKTOK,contentTypeKey:"tt-carousel-vertical",labelKey:"tt-carousel-vertical",width:1080,height:1350,mediaKinds:["image"],linkedPostType:"post",noteKey:"tt-carousel-vertical"},{id:"tt-story",platform:C.SocialPlatform.TIKTOK,contentTypeKey:"tt-story",labelKey:"tt-story",width:1080,height:1920,mediaKinds:["image","video"],noteKey:"tt-story"},{id:"fb-feed-landscape",platform:C.SocialPlatform.FACEBOOK,contentTypeKey:"fb-feed-landscape",labelKey:"fb-feed-landscape",width:1080,height:566,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"fb-feed-vertical",platform:C.SocialPlatform.FACEBOOK,contentTypeKey:"fb-feed-vertical",labelKey:"fb-feed-vertical",width:1080,height:1359,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"fb-feed-square",platform:C.SocialPlatform.FACEBOOK,contentTypeKey:"fb-feed-square",labelKey:"fb-feed-square",width:1080,height:1080,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"fb-story",platform:C.SocialPlatform.FACEBOOK,contentTypeKey:"fb-story",labelKey:"fb-story",width:1080,height:1920,mediaKinds:["image","video"],linkedPostType:"story",noteKey:"fb-story"},{id:"fb-reel",platform:C.SocialPlatform.FACEBOOK,contentTypeKey:"fb-reel",labelKey:"fb-reel",width:1080,height:1920,mediaKinds:["video"],linkedPostType:"reel"},{id:"x-instream-landscape",platform:C.SocialPlatform.X,contentTypeKey:"x-instream-landscape",labelKey:"x-instream-landscape",width:1280,height:720,mediaKinds:["image"],linkedPostType:"feed"},{id:"x-instream-vertical",platform:C.SocialPlatform.X,contentTypeKey:"x-instream-vertical",labelKey:"x-instream-vertical",width:720,height:1280,mediaKinds:["image"],linkedPostType:"feed",noteKey:"x-instream-vertical"},{id:"x-instream-square",platform:C.SocialPlatform.X,contentTypeKey:"x-instream-square",labelKey:"x-instream-square",width:1080,height:1080,mediaKinds:["image"],linkedPostType:"feed",noteKey:"x-instream-square"},{id:"x-gif",platform:C.SocialPlatform.X,contentTypeKey:"x-gif",labelKey:"x-gif",width:1280,height:1080,mediaKinds:["image"],linkedPostType:"feed",noteKey:"x-gif"},{id:"bsky-square",platform:C.SocialPlatform.BLUESKY,contentTypeKey:"bsky-square",labelKey:"bsky-square",width:1e3,height:1e3,mediaKinds:["image"],linkedPostType:"post"},{id:"bsky-vertical",platform:C.SocialPlatform.BLUESKY,contentTypeKey:"bsky-vertical",labelKey:"bsky-vertical",width:563,height:1e3,mediaKinds:["image"],linkedPostType:"post",noteKey:"bsky-vertical"},{id:"bsky-3-4",platform:C.SocialPlatform.BLUESKY,contentTypeKey:"bsky-3-4",labelKey:"bsky-3-4",width:750,height:1e3,mediaKinds:["image"],linkedPostType:"post"},{id:"bsky-4-5",platform:C.SocialPlatform.BLUESKY,contentTypeKey:"bsky-4-5",labelKey:"bsky-4-5",width:800,height:1e3,mediaKinds:["image"],linkedPostType:"post",noteKey:"bsky-4-5"},{id:"yt-thumbnail",platform:C.SocialPlatform.YOUTUBE,contentTypeKey:"yt-thumbnail",labelKey:"yt-thumbnail",width:1280,height:720,mediaKinds:["image"],noteKey:"yt-thumbnail"},{id:"yt-podcast-playlist",platform:C.SocialPlatform.YOUTUBE,contentTypeKey:"yt-podcast-playlist",labelKey:"yt-podcast-playlist",width:1280,height:1280,mediaKinds:["image"]},{id:"li-link-landscape",platform:C.SocialPlatform.LINKEDIN,contentTypeKey:"li-link-landscape",labelKey:"li-link-landscape",width:1200,height:627,mediaKinds:["image"],linkedPostType:"feed",noteKey:"li-link-landscape"},{id:"li-landscape",platform:C.SocialPlatform.LINKEDIN,contentTypeKey:"li-landscape",labelKey:"li-landscape",width:1200,height:627,mediaKinds:["image","video"],linkedPostType:"feed"}
1,{id:"li-vertical",platform:C.SocialPlatform.LINKEDIN,contentTypeKey:"li-vertical",labelKey:"li-vertical",width:720,height:900,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"li-square",platform:C.SocialPlatform.LINKEDIN,contentTypeKey:"li-square",labelKey:"li-square",width:1200,height:1200,mediaKinds:["image","video"],linkedPostType:"feed"},{id:"pin-standard",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-standard",labelKey:"pin-standard",width:1e3,height:1500,mediaKinds:["image","video"],linkedPostType:"pin"},{id:"pin-9-16",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-9-16",labelKey:"pin-9-16",width:563,height:1e3,mediaKinds:["image"],linkedPostType:"pin",noteKey:"pin-9-16"},{id:"pin-3-4",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-3-4",labelKey:"pin-3-4",width:750,height:1e3,mediaKinds:["image"],linkedPostType:"pin"},{id:"pin-4-5",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-4-5",labelKey:"pin-4-5",width:800,height:1e3,mediaKinds:["image"],linkedPostType:"pin"},{id:"pin-square",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-square",labelKey:"pin-square",width:1e3,height:1e3,mediaKinds:["image"],linkedPostType:"pin"},{id:"pin-collection-square",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-collection-square",labelKey:"pin-collection-square",width:1e3,height:1e3,mediaKinds:["image"],linkedPostType:"pin",noteKey:"pin-collection-square"},{id:"pin-collection-2-3",platform:C.SocialPlatform.PINTEREST,contentTypeKey:"pin-collection-2-3",labelKey:"pin-collection-2-3",width:1e3,height:1500,mediaKinds:["image"],linkedPostType:"pin",noteKey:"pin-collection-2-3"},{id:"threads-post",platform:C.SocialPlatform.THREADS,contentTypeKey:"threads-post",labelKey:"threads-post",width:1440,height:1920,mediaKinds:["image"],linkedPostType:"post",noteKey:"threads-post"}];function S(e){let t=e?"video":"image";return N.filter(e=>e.mediaKinds.includes(t))}var k=a(95609),T=a(20836),E=a(55754),I=a(25065),A=a(38514),P=a(18545),M=a(89017),D=a(5898),R=a(11759);function F(e){let{width:t,height:a}=e,n=20/Math.max(t,a);return(0,i.jsx)("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center","aria-hidden":"true",children:(0,i.jsx)("span",{className:"rounded-[3px] border-[1.5px] border-current bg-current/5",style:{width:t*n,height:a*n}})})}function O(e){let{value:t,onValueChange:a,isVideo:r,preferredPlatform:o,sourceWidth:d,sourceHeight:c}=e,u=(0,n.useTranslations)("Media.convert"),[p,f]=(0,h.useState)(!1),[x,g]=(0,h.useState)(C.SocialPlatform.INSTAGRAM),v=S(r),b=Array.from(new Set(S(r).map(e=>e.platform))).sort((e,t)=>Number(e===C.SocialPlatform.PINTEREST)-Number(t===C.SocialPlatform.PINTEREST)),y=v.find(e=>e.id===t),w=function(e){let t=new Map;for(let a of e){let e="".concat(a.platform,":").concat(a.width,"x").concat(a.height),i=t.get(e);i?i.push(a):t.set(e,[a])}return[...t.values()]}(v),j=y?u("presets.contentTypes.".concat(y.labelKey)):"original"===t?u("keepOriginalSize"):"custom"===t?u("customSize"):t,N=y?"".concat(u("presets.platforms.".concat(y.platform))," \xb7 ").concat(y.width," \xd7 ").concat(y.height):"original"===t&&d&&c?"".concat(d," \xd7 ").concat(c):void 0;return(0,i.jsxs)(M.AM,{modal:!0,open:p,onOpenChange:e=>{if(e){var a;g(null!=(a=null==y?void 0:y.platform)?a:"original"===t||"custom"===t?t:o&&b.includes(o)?o:b[0])}f(e)},children:[(0,i.jsx)(M.Wv,{asChild:!0,children:(0,i.jsxs)(l.$,{id:"conversion-preset",variant:"outline","aria-label":"".concat(u("sections.preset"),": ").concat(y?"".concat(u("presets.platforms.".concat(y.platform))," \xb7 "):"").concat(j),title:N,className:"h-8 w-full justify-start gap-2 px-3 py-0 text-left font-normal",children:[(0,i.jsx)(s.m,{children:u("sections.preset")}),y?(0,i.jsx)(R.BP,{platform:y.platform,size:"sm",className:"h-5 w-5 [&>svg]:h-3 [&>svg]:w-3"}):"original"===t&&d&&c?(0,i.jsx)(F,{width:d,height:c}):(0,i.jsx)(A.A,{className:"mx-2 h-4 w-4 shrink-0 text-muted-foreground"}),(0,i.jsx)("span",{className:"min-w-0 flex-1 truncate",children:j}),(0,i.jsx)(m.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),(0,i.jsx)(M.hl,{align:"start",sideOffset:8,"aria-label":u("sections.preset"),className:"w-[380px] max-w-[calc(100vw-2rem)] overflow-hidden rounded-xl p-0 shadow-lg",children:(0,i.jsxs)(D.tU,{value:x,onValueChange:g,orientation:"vertical",className:"flex overflow-hidden",style:{height:"min(".concat((b.length+2)*44+8,"px, var(--radix-popover-content-available-height))")},children:[(0,i.jsxs)("div",{className:"grid h-full min-h-0 w-44 shrink-0 gap-1 bg-muted/40 p-1.5",style:{gridTemplateRows:"repeat(".concat(b.length+2,", minmax(0, 1fr))")},children:[["original","custom"].map(e=>(0,i.jsxs)("button",{type:"button","aria-pressed":x===e,onClick:()=>{a(e),f(!1)},className:(0,I.cn)("flex min-h-0 w-full items-center gap-2 rounded-md px-2 py-1 text-left text-xs focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hover:bg-accent",x===e&&"bg-background font-medium shadow-sm"),children:["original"===e?(0,i.jsx)(F,{width:d||1,height:c||1}):(0,i.jsx)(A.A,{className:"h-6 w-6 shrink-0 p-1"}),u("original"===e?"keepOriginalSize":"customSize")]},e)),(0,i.jsx)(D.j7,{"aria-label":u("presetCategories"),className:"contents bg-transparent p-0",children:b.map(e=>(0,i.jsxs)(D.Xi,{value:e,className:"min-h-0 cursor-pointer justify-start gap-3 px-2.5 py-1 text-xs data-[state=inactive]:hover:bg-accent data-[state=inactive]:hover:text-foreground",children:[(0,i.jsx)(R.BP,{platform:e,size:"sm",className:"h-5 w-5 [&>svg]:h-3 [&>svg]:w-3"}),u("presets.platforms.".concat(e))]},e))})]}),("original"===x||"custom"===x)&&(0,i.jsx)("div",{className:"min-w-0 flex-1 p-4 text-xs leading-relaxed text-muted-foreground",children:u("presetEmptyHint")}),b.map(e=>(0,i.jsx)(D.av,{value:e,className:"h-full min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain p-2",children:(0,i.jsx)("div",{className:"grid gap-1",children:w.filter(t=>t[0].platform===e).map(e=>{var n;let r,l=null!=(n=e.find(e=>e.id===t))?n:e[0];return(0,i.jsxs)("button",{type:"button","aria-pressed":t===l.id,onClick:()=>{a(l.id),f(!1)},className:(r=t===l.id,(0,I.cn)("relative flex min-h-11 items-center gap-2 rounded-md border px-2 py-1.5 pr-6 text-left text-sm transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",r?"border-primary bg-primary/5 text-primary":"border-transparent")),children:[(0,i.jsx)(F,{width:l.width,height:l.height}),t===l.id&&(0,i.jsx)(P.A,{className:"absolute right-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2"}),(0,i.jsxs)("span",{children:[(0,i.jsx)("span",{className:"block text-xs font-medium leading-4",children:e.map(e=>u("presets.contentTypes.".concat(e.labelKey))).join(" / ")}),(0,i.jsxs)("span",{className:"mt-0.5 block text-[11px] leading-3 text-muted-foreground",children:[l.width," \xd7 ",l.height]})]})]},e[0].id)})})},e))]})})]})}
1function z(e){let{src:t,sourceWidth:a,sourceHeight:r,aspect:l,crop:s,onChange:o,children:d}=e,c=(0,n.useTranslations)("Media.convert");return(0,i.jsx)(f.Ay,{className:"max-h-[var(--conversion-preview-height)] align-top",crop:{unit:"%",x:s.x/a*100,y:s.y/r*100,width:s.width/a*100,height:s.height/r*100},aspect:l,ruleOfThirds:!0,keepSelection:!0,onChange:(e,t)=>o(x(t,a,r)),children:null!=d?d:(0,i.jsx)("img",{src:t,alt:c("previewOriginal"),draggable:!1,className:"h-auto w-auto max-w-full object-contain"})})}a(70423);var L=a(90947),U=a(42749);function _(e,t,a,i,n){var r,l;let s=null!=(r=null==a?void 0:a.width)?r:e,o=null!=(l=null==a?void 0:a.height)?l:t;if(!(null==i?void 0:i.width)&&!(null==i?void 0:i.height))return{width:Math.round(s),height:Math.round(o)};if(i.width&&i.height){let e=null!=n?n:"legacy";return"fill"===e||"cover"===e||"fit"===e||"blur"===e?{width:i.width,height:i.height}:{width:Math.min(i.width,Math.round(s)),height:Math.min(i.height,Math.round(o))}}let d=1;return i.width?d=i.width/s:i.height&&(d=i.height/o),{width:Math.max(1,Math.round(s*(d=Math.min(d,1)))),height:Math.max(1,Math.round(o*d))}}function B(e,t,a,i,n){var r,l;if(!(null==i?void 0:i.width)&&!(null==i?void 0:i.height))return!1;let s=null!=n?n:"legacy";if("fill"===s||"cover"===s||"fit"===s||"blur"===s)return!1;let o=null!=(r=null==a?void 0:a.width)?r:e,d=null!=(l=null==a?void 0:a.height)?l:t;if(i.width&&i.height)return i.width>o||i.height>d;let c=1;return i.width?c=i.width/o:i.height&&(c=i.height/d),c>1}function K(e,t,a){let i=Math.max(0,Math.min(Math.round(e.x),t-1)),n=Math.max(0,Math.min(Math.round(e.y),a-1));return{x:i,y:n,width:Math.max(1,Math.min(Math.round(e.width),t-i)),height:Math.max(1,Math.min(Math.round(e.height),a-n))}}function G(e,t,a,i,n){let r=a?K(a,e,t):{x:0,y:0,width:e,height:t},l=_(e,t,r,i,n),s=Math.min(1,720/Math.max(l.width,l.height)),o=Math.max(1,Math.round(l.width*s)),d=Math.max(1,Math.round(l.height*s)),c=e=>{let t=(e?Math.max:Math.min)(o/r.width,d/r.height),a=r.width*t,i=r.height*t;return{x:(o-a)/2,y:(d-i)/2,width:a,height:i}},u=!!((null==i?void 0:i.width)&&(null==i?void 0:i.height)),m=u&&["fit","blur","cover"].includes(n)?c("cover"===n):{x:0,y:0,width:o,height:d};return{source:r,width:o,height:d,foreground:m,background:u&&"blur"===n?c(!0):null,blur:24*s}}function W(e){var t;let{src:a,dimensions:r,crop:s,resize:o,mode:d,original:c,editing:m,aspect:p,onCropChange:f,onDimensions:x}=e,g=(0,n.useTranslations)("Media.convert"),v=(0,h.useRef)(null),b=(0,h.useRef)(null),y=(0,h.useRef)(!1),[w,j]=(0,h.useState)(null),[C,N]=(0,h.useState)(!1),[S,k]=(0,h.useState)(!1),[T,E]=(0,h.useState)(!1);(0,h.useEffect)(()=>{if(C||T)return;let e=setTimeout(()=>E(!0),3e4);return()=>clearTimeout(e)},[C,T]);let I=null!=(t=null!=w?w:r)?t:{width:16,height:9},A=c||m,P=G(I.width,I.height,A?void 0:s,A?void 0:o,d),M=(0,h.useCallback)(()=>{let e=v.current,t=b.current;if(!e||!t||e.readyState<2)return;let a=t.getContext("2d");if(!a)return;let i=G(e.videoWidth,e.videoHeight,A?void 0:s,A?void 0:o,d);t.width!==i.width&&(t.width=i.width),t.height!==i.height&&(t.height=i.height),a.clearRect(0,0,i.width,i.height),a.fillStyle="black",a.fillRect(0,0,i.width,i.height);let n=t=>a.drawImage(e,i.source.x,i.source.y,i.source.width,i.source.height,t.x,t.y,t.width,t.height);i.background&&(a.save(),a.filter="blur(".concat(i.blur,"px)"),n(i.background),a.restore()),n(i.foreground)},[s,o,d,A]);(0,h.useEffect)(()=>{if(M(),!S)return;let e=0,t=0,a=i=>{i-t>=1e3/30&&(M(),t=i),e=requestAnimationFrame(a)};return e=requestAnimationFrame(a),()=>cancelAnimationFrame(e)},[M,S,C,m]),(0,h.useEffect)(()=>{let e=v.current,t=()=>{document.hidden&&(y.current=!1,null==e||e.pause())};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t),null==e||e.pause()}},[]);let D=()=>{var e;y.current=!1,null==(e=v.current)||e.pause()},R=()=>{let e=v.current;e&&!T&&(y.current=!0,e.play().then(()=>{y.current||e.pause()}).catch(()=>{e.error&&E(!0)}))},F=(0,i.jsx)("canvas",{ref:b,width:P.width,height:P.height,"aria-label":g(c?"previewOriginal":"previewSection"),className:"block h-auto max-h-[var(--conversion-preview-height)] w-auto max-w-full"});return(0,i.jsxs)("div",{className:"relative max-w-full",onPointerEnter:e=>{"mouse"===e.pointerType&&R()},onPointerLeave:e=>{"mouse"===e.pointerType&&D()},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||D()},children:[(0,i.jsx)("video",{ref:v,src:a,muted:!0,loop:!0,playsInl
1ine:!0,preload:"auto","aria-hidden":"true",tabIndex:-1,className:"pointer-events-none absolute h-px w-px opacity-0",onLoadedMetadata:e=>{let t=e.currentTarget,a={width:t.videoWidth,height:t.videoHeight};a.width>0&&a.height>0&&(j(a),x(a))},onLoadedData:()=>{N(!0),E(!1),M()},onSeeked:M,onPlay:()=>k(!0),onPause:()=>k(!1),onError:()=>{E(!0),k(!1)}}),m&&s&&p&&C?(0,i.jsx)(z,{src:"",sourceWidth:I.width,sourceHeight:I.height,aspect:p,crop:s,onChange:f,children:F}):F,!C&&!T&&(0,i.jsx)("div",{role:"status",className:"absolute inset-0 flex items-center justify-center bg-muted/30",children:(0,i.jsx)(u.A,{className:"h-5 w-5 animate-spin","aria-label":g("loadingPreview")})}),T?(0,i.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-3 bg-background/95 p-3 text-center",children:[(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:g("videoPreviewUnavailable")}),(0,i.jsx)(l.$,{type:"button",size:"sm",variant:"outline",onClick:()=>{var e;E(!1),N(!1),null==(e=v.current)||e.load()},children:g("retryPreview")})]}):C&&(0,i.jsx)("button",{type:"button","aria-label":g(S?"pausePreview":"playPreview"),title:g(S?"pausePreview":"playPreview"),className:"absolute bottom-2 right-2 z-10 flex h-7 w-7 items-center justify-center rounded-full bg-black/60 text-white hover:bg-black/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white md:hidden",onClick:()=>{var e;(null==(e=v.current)?void 0:e.paused)?R():D()},children:S?(0,i.jsx)(L.A,{className:"h-3.5 w-3.5"}):(0,i.jsx)(U.A,{className:"h-3.5 w-3.5"})})]})}function V(e){return e===C.SocialPlatform.INSTAGRAM_DIRECT?C.SocialPlatform.INSTAGRAM:e===C.SocialPlatform.LINKEDIN_ORGANIZATION?C.SocialPlatform.LINKEDIN:e}async function q(e,t){let a=await fetch("/api/media/proxy?url=".concat(encodeURIComponent(e)),{signal:t});if(!a.ok)throw Error("Preview request failed (".concat(a.status,")"));let i=await a.blob();t.throwIfAborted();let n=URL.createObjectURL(i),r=new Image;try{return await new Promise((e,a)=>{let i=()=>{r.onload=null,r.onerror=null,t.removeEventListener("abort",l)},l=()=>{i(),r.src="",a(t.reason)};r.onload=()=>{i(),r.naturalWidth&&r.naturalHeight?e():a(Error("Preview image has no dimensions"))},r.onerror=()=>{i(),a(Error("Could not decode preview image"))},t.addEventListener("abort",l,{once:!0}),r.src=n}),t.throwIfAborted(),{image:r,blobUrl:n}}catch(e){throw URL.revokeObjectURL(n),e}}let H={low:.35,medium:.55,high:.75},$={"image/jpeg":.9,"image/png":1.1};function Y(e,t){return Math.max(1,e)*Math.max(1,t)}var X=a(88697);let Z={"image/jpeg":"JPEG","image/png":"PNG","video/mp4":"MP4","video/quicktime":"MOV"};function J(e){var t,a,f,x,b,C,S,A;let{isOpen:P,onOpenChange:M,media:D,preferredPlatform:R,preferredPostType:F,allowReplace:L=!0,onConversionStarted:U}=e,G=(0,n.useTranslations)("Media.convert"),J=(0,n.useTranslations)("Media"),Q=D?(0,v.Z0)(D.type,D.url||D.name):"",ee=Q.startsWith("video/"),et=V(R),ea=(0,h.useRef)(null),ei=(0,h.useRef)(null),[en,er]=(0,h.useState)(null),[el,es]=(0,h.useState)(!1),[eo,ed]=(0,h.useState)(),[ec,eu]=(0,h.useState)(null),[em,eh]=(0,h.useState)(!1),[ep,ef]=(0,h.useState)(!1),[ex,eg]=(0,h.useState)(0),[ev,eb]=(0,h.useState)(!1),[ey,ew]=(0,h.useState)(null),[ej,eC]=(0,h.useState)("copy"),[eN,eS]=(0,h.useState)(!1),[ek,eT]=(0,h.useState)(!1),[eE,eI]=(0,h.useState)(!1),[eA,eP]=(0,h.useState)(""),[eM,eD]=(0,h.useState)("none"),[eR,eF]=(0,h.useState)("fit"),[eO,ez]=(0,h.useState)(null!=(x=null==D?void 0:D.folderId)?x:null),{data:eL=[]}=(0,w.b)(),[eU,e_]=(0,h.useState)("original"),[eB,eK]=(0,h.useState)(""),[eG,eW]=(0,h.useState)(""),[eV,eq]=(0,h.useState)(""),eH=(0,h.useMemo)(()=>N.find(e=>e.id===eV),[eV]),[e$,eY]=(0,h.useState)(!1),[eX,eZ]=(0,h.useState)(!1),[eJ,eQ]=(0,h.useState)(!1),{limits:e0,usage:e1}=(0,k.Q)(),e2=(0,h.useMemo)(()=>D?(0,v.Ks)(Q):[],[D,Q]),e4=(0,h.useMemo)(()=>!!(eo&&eo.width>0&&eo.height>0),[eo]),e3=(0,h.useMemo)(()=>{if("custom"===eU||eV){let e=parseInt(eB,10),t=parseInt(eG,10);if(!isNaN(e)||!isNaN(t))return{...!isNaN(e)&&e>0?{width:e}:{},...!isNaN(t)&&t>0?{height:t}:{}}}},[eU,eB,eG,eV]),e5=!!((null==e3?void 0:e3.width)&&(null==e3?void 0:e3.height)),e6=(0,h.useMemo)(()=>
1{if((null==e3?void 0:e3.width)&&(null==e3?void 0:e3.height))return e3.width/e3.height},[e3]),e8="cover"===eR&&e5&&!!e6;(0,h.useEffect)(()=>{var e,t,a,i;if(!P){ei.current=null;return}if(!D||ei.current===D.id)return;ei.current=D.id;let n=(0,v.Ks)(Q),r=function(e){var t;let{platform:a,postType:i,isVideo:n,width:r,height:l}=e,s=V(a);if(!s||!i)return;let o=(function(e,t){let a=t?"video":"image";return N.filter(t=>t.platform===e&&t.mediaKinds.includes(a))})(s,n).filter(e=>e.linkedPostType===i&&!["x-gif","li-link-landscape","pin-collection-square","pin-collection-2-3"].includes(e.id)),d=o.find(e=>"ig-reel-feed"===e.id||n&&"tt-video"===e.id);if(d)return d;if(r&&l&&r>0&&l>0){let e=r/l;return o.toSorted((t,a)=>Math.abs(Math.log(t.width/t.height/e))-Math.abs(Math.log(a.width/a.height/e)))[0]}return null!=(t=o.find(e=>["ig-feed-vertical","fb-feed-square","li-square","pin-standard","bsky-square","tt-carousel"].includes(e.id)))?t:o[0]}({platform:et,postType:F,isVideo:ee,width:D.width,height:D.height});eP(null!=(t=null!=(e=n.find(e=>e===Q))?e:n[0])?t:""),eC("copy"),eT(!1),eS(!1),eI(!1),ew(null),eD("none"),eF("fit"),e_(r?"custom":"original"),eK(r?String(r.width):""),eW(r?String(r.height):""),eq(null!=(a=null==r?void 0:r.id)?a:""),ez(null!=(i=D.folderId)?i:null),ed(void 0),eZ(!1)},[P,D,Q,et,F,ee]);let e9=ee?null:null!=(b=null==D?void 0:D.url)?b:null,e7=ee?null!=(C=null==ey?void 0:ey.width)?C:null==D?void 0:D.width:null==(t=ea.current)?void 0:t.naturalWidth,te=ee?null!=(S=null==ey?void 0:ey.height)?S:null==D?void 0:D.height:null==(a=ea.current)?void 0:a.naturalHeight,tt=ee?!!ey:ev;(0,h.useEffect)(()=>{let e;if(ea.current=null,eu(null),eb(!1),er(null),es(!1),ef(!1),eh(!1),!P||!e9)return;let t=!1,a=new AbortController,i=setTimeout(()=>a.abort(),3e4);return eh(!0),q(e9,a.signal).then(a=>{let{image:i,blobUrl:n}=a;if(t)return void URL.revokeObjectURL(n);e=n,ea.current=i,eu(n),eb(!0)}).catch(e=>{t||(console.warn("Failed to load conversion preview",e),ef(!0))}).finally(()=>{clearTimeout(i),t||eh(!1)}),()=>{t=!0,clearTimeout(i),a.abort(),e&&URL.revokeObjectURL(e)}},[P,null==D?void 0:D.id,e9,ex]),(0,h.useEffect)(()=>{if(ee||!ev)return;let e=ea.current;if(null==e?void 0:e.naturalWidth)try{let t=(function(e,t,a,i,n,r,l){let s=function(e,t,a){if(a&&t){let a=document.createElement("canvas"),i=a.getContext("2d");if(!i)throw Error("Canvas 2D context not available");let n=g(e,t);if(!n)throw Error("Invalid crop dimensions");return a.width=n.width,a.height=n.height,i.imageSmoothingQuality="high",i.drawImage(e,n.x,n.y,n.width,n.height,0,0,n.width,n.height),a}let i=document.createElement("canvas");i.width=e.naturalWidth,i.height=e.naturalHeight;let n=i.getContext("2d");if(!n)throw Error("Canvas 2D context not available");return n.drawImage(e,0,0),i}(e,t,a),o=a?{width:s.width,height:s.height}:null;if(!(null==i?void 0:i.width)&&!(null==i?void 0:i.height))return s;let d=_(r,l,o,i,n),c=document.createElement("canvas");c.width=d.width,c.height=d.height;let u=c.getContext("2d");if(!u)throw Error("Canvas 2D context not available");u.imageSmoothingQuality="high";let m=s.width,h=s.height,p=d.width,f=d.height;if(!i.width||!i.height)return u.drawImage(s,0,0,p,f),c;let x=null!=n?n:"legacy";if("fill"===x)return u.drawImage(s,0,0,p,f),c;if("fit"===x||"blur"===x){if("blur"===x){let e=Math.max(p/m,f/h),t=m*e,a=h*e;u.save(),u.filter="blur(24px)",u.drawImage(s,(p-t)/2,(f-a)/2,t,a),u.restore()}else u.fillStyle="rgba(0, 0, 0, 0.92)",u.fillRect(0,0,p,f);let e=Math.min(p/m,f/h),t=m*e,a=h*e,i=(p-t)/2,n=(f-a)/2;return u.drawImage(s,i,n,t,a),c}if("cover"===x){let e=Math.max(p/m,f/h),t=m*e,a=h*e,i=(p-t)/2,n=(f-a)/2;return u.drawImage(s,i,n,t,a),c}return u.drawImage(s,0,0,p,f),c})(e,eo,e4,e3,eR,e.naturalWidth,e.naturalHeight).toDataURL("image/jpeg",.92);if("data:,"===t)throw Error("Invalid preview canvas size");er(t),es(!1)}catch(e){console.warn("Failed to render conversion preview",e),er(null),es(!0)}},[ee,eo,e4,e3,eR,ec,ev,e8]);let ta=e=>{e7&&te&&ed(function(e,t,a){if(![e,t,a].every(e=>Number.isFinite(e)&&e>0))return;let i=Math.min(e,t*a),n=i/a;return{unit:"px",x:(e-i)/2,y:(t-n)/2,width:i,height:n}}(e7,te,e))};(0,h.useEffect)(()=>
1{if(!e8){eT(!1),ed(void 0);return}e6&&tt&&(ta(e6),eS(!1),eT(!0))},[e8,e6,tt,e7,te,eB,eG]);let ti=()=>{ed(void 0)},tn=()=>{var e;if(!e4||!eo)return;if(ee&&e7&&te)return K(eo,e7,te);let t=null!=(e=ea.current)?e:ea.current;if(!(null==t?void 0:t.naturalWidth))return;let a=g(t,eo);if(a)return a},tr=()=>ee&&ey?ey:!ee&&ea.current?{width:ea.current.naturalWidth,height:ea.current.naturalHeight}:(null==D?void 0:D.width)&&(null==D?void 0:D.height)?{width:D.width,height:D.height}:null,tl=(0,h.useMemo)(()=>{var e,t;if(!D||!eA)return null;let a=Number(null!=(e=D.sizeInBytes)?e:0);if(a<=0)return null;let i=tr();return function(e){var t,a,i,n,r,l;let s=null!=(t=e.crop)?t:null,o=null!=(a=null==s?void 0:s.width)?a:e.sourceWidth,d=null!=(i=null==s?void 0:s.height)?i:e.sourceHeight,c=_(e.sourceWidth,e.sourceHeight,s,null!=(n=e.resize)?n:null,e.scaleMode),u=Y(o,d),m=Y(c.width,c.height)/u,h=e.sourceBytes;if(e.isVideo){let t=e.quality?null!=(r=H[e.quality])?r:.55:.9;h=Math.round(e.sourceBytes*t*Math.min(m,1))}else{let t=null!=(l=$[e.target])?l:.9;
1h=Math.round(e.sourceBytes*m*t)}h=Math.max(1,h);let p="copy"===e.mode?h:h-e.sourceBytes;return{estimatedBytes:h,estimatedDimensions:c,storageDeltaBytes:p}}({sourceBytes:a,sourceWidth:(null==i?void 0:i.width)||D.width||1920,sourceHeight:(null==i?void 0:i.height)||D.height||1080,isVideo:ee,target:eA,crop:null!=(t=tn())?t:null,resize:null!=e3?e3:null,scaleMode:eR,quality:ee&&"none"!==eM?eM:void 0,mode:ej})},[D,eA,ej,ee,eM,eR,e3,eo,e4,ev,ey]),ts=(0,h.useMemo)(()=>!!D&&"copy"===ej&&!!(null==e0?void 0:e0.media_storage.max)&&!!tl&&((null==e1?void 0:e1.mediaStorageMB)||0)+tl.estimatedBytes/1048576>e0.media_storage.max,[D,e0,e1,ej,tl]),to=(0,h.useMemo)(()=>{let e=tr();if(!e)return{dimensions:null,capped:!1,fitted:!1,targetDimensions:null};let t=(()=>{let e=tr();if(!e)return null;if(!e4)return e;let t=tn();return t?{width:t.width,height:t.height}:e})();if(!t)return{dimensions:null,capped:!1,fitted:!1,targetDimensions:null};if(!(null==e3?void 0:e3.width)&&!(null==e3?void 0:e3.height))return{dimensions:"".concat(t.width,"\xd7").concat(t.height),capped:!1,fitted:!1,upscaleWarning:!1,targetDimensions:null};let a=e4?t:null,i=_(e.width,e.height,a,e3,eR),n=B(e.width,e.height,a,e3,eR),r=function(e,t,a,i,n){if(!(null==i?void 0:i.width)||!(null==i?void 0:i.height))return!1;let r=null!=n?n:"legacy";if("fill"===r||"cover"===r||"fit"===r||"blur"===r||B(e,t,a,i,n))return!1;let l=_(e,t,a,i,n);return l.width!==i.width||l.height!==i.height}(e.width,e.height,a,e3,eR),l=function(e,t,a,i,n){var r,l,s,o;if(!(null==i?void 0:i.width)||!(null==i?void 0:i.height))return!1;let d=null!=n?n:"legacy";if("fill"===d||"cover"===d){let n=null!=(r=null==a?void 0:a.width)?r:e,s=null!=(l=null==a?void 0:a.height)?l:t;return i.width>n||i.height>s}if("fit"===d||"blur"===d){let n=null!=(s=null==a?void 0:a.width)?s:e,r=null!=(o=null==a?void 0:a.height)?o:t;return Math.min(i.width/n,i.height/r)>1}return!1}(e.width,e.height,a,e3,eR),s=(null==e3?void 0:e3.width)&&(null==e3?void 0:e3.height)?"".concat(e3.width,"\xd7").concat(e3.height):null;return{dimensions:"".concat(i.width,"\xd7").concat(i.height),capped:n,fitted:r,upscaleWarning:l,targetDimensions:s}},[e4,eo,eB,eG,eU,eV,D,ee,ec,eR,e3,ev,ey]),td=async()=>{if(!D||!eA)return;let e=tn();eY(!0);try{let t={mediaId:D.id,mode:ej,target:eA,crop:e,resize:e3,scaleMode:e5&&"legacy"!==eR?eR:void 0,estimatedBytes:null==tl?void 0:tl.estimatedBytes,..."copy"===ej?{folderId:eO}:{},...ee&&"none"!==eM?{quality:eM}:{}},a=await y(t);if(a.error||!a.data)return void p.oR.error(a.error||G("conversionFailed"));null==U||U(a.data,ej,D),M(!1)}catch(e){p.oR.error(e instanceof Error?e.message:G("conversionFailed"))}finally{eY(!1),eZ(!1)}};if(!D)return null;let tc=e=>!e||Number.isInteger(Number(e))&&Number(e)>0,tu="custom"!==eU||!!(eB||eG)&&tc(eB)&&tc(eG),tm=!!eA&&(ee||!!ec)&&tu,th=tr(),tp=eN?th&&"".concat(th.width,"\xd7").concat(th.height):to.dimensions,tf=eN?null!=(A=Z[Q])?A:null==(f=Q.split("/")[1])?void 0:f.toUpperCase():eA&&Z[eA],tx=()=>eg(e=>e+1);return(0,i.jsxs)(r.lG,{open:P,onOpenChange:M,children:[(0,i.jsx)(r.Cf,{className:"flex h-[90dvh] max-h-[90dvh] md:h-[min(632px,90dvh)] flex-col gap-0 overflow-hidden p-0 [--conversion-preview-height:min(360px,42dvh)] sm:max-w-[840px]",children:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(r.c7,{className:"shrink-0 px-5 py-4 pr-12 text-left",children:[(0,i.jsx)(r.L3,{className:"font-medium",children:G("title")}),(0,i.jsx)(r.rr,{className:"sr-only",children:G(ee?"descriptionVideo":"descriptionImage")})]}),(0,i.jsxs)("div",{className:"grid min-h-0 flex-1 auto-rows-min gap-6 overflow-y-auto px-5 pb-2 md:auto-rows-fr md:grid-cols-[minmax(0,0.7fr)_minmax(0,1.3fr)] md:overflow-hidden",children:[(0,i.jsxs)("section",{className:"min-h-0 min-w-0 space-y-5 [&_.border-r]:w-[72px] md:pt-10 md:overflow-y-auto md:[scrollbar-gutter:stable]",children:[(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsx)(O,{value:eV||eU,onValueChange:e=>{if(e8||ti(),eS(!1),N.some(t=>t.id===e)){eq(e);let t=N.find(t=>t.id===e);t&&(eF("blur"),e_("custom"),eK(t.width.toString()),eW(t.height.toString()))}else e_(e),eq(""),"custom"!==e?(eK(""),eW("")):eB||eG||(eK(String(null!=e7?e7:"")),eW(String(null!=te?te:"")))}
1,isVideo:ee,preferredPlatform:et,sourceWidth:null==D?void 0:D.width,sourceHeight:null==D?void 0:D.height}),"custom"===eU&&!eV&&(0,i.jsxs)("div",{className:"grid grid-cols-1 gap-2 pt-1",children:[(0,i.jsxs)("div",{className:"flex h-8 min-w-0 items-center rounded-md border border-input bg-background pl-3 focus-within:ring-1 focus-within:ring-ring",children:[(0,i.jsx)(s.m,{children:G("widthTitle")}),(0,i.jsx)(E.p,{id:"conversion-width","aria-label":G("widthLabel"),type:"number",min:1,className:"h-full min-w-0 border-0 bg-transparent shadow-none focus-visible:ring-0",placeholder:G("automatic"),value:eB,onChange:e=>eK(e.target.value)})]}),(0,i.jsxs)("div",{className:"flex h-8 min-w-0 items-center rounded-md border border-input bg-background pl-3 focus-within:ring-1 focus-within:ring-ring",children:[(0,i.jsx)(s.m,{children:G("heightTitle")}),(0,i.jsx)(E.p,{id:"conversion-height","aria-label":G("heightLabel"),type:"number",min:1,className:"h-full min-w-0 border-0 bg-transparent shadow-none focus-visible:ring-0",placeholder:G("automatic"),value:eG,onChange:e=>eW(e.target.value)})]})]}),!tu&&(0,i.jsx)("p",{role:"alert",className:"text-xs text-destructive",children:G("invalidSize")})]}),e5&&(0,i.jsxs)("div",{className:"flex h-8 min-w-0 items-center gap-2 rounded-md border border-input pl-3",children:[(0,i.jsx)(s.m,{children:G("framing")}),(0,i.jsx)(c.z,{"aria-label":G("framing"),value:eR,onValueChange:e=>{"cover"!==e&&"cover"===eR&&ti(),eF(e),eS(!1),eT("cover"===e)},className:"grid h-full min-w-0 flex-1 grid-cols-3 gap-0.5 p-0.5",children:[{value:"fit",label:"framingFit",hint:"scaleModeFit"},{value:"blur",label:"framingBlur",hint:"scaleModeBlur"},{value:"cover",label:"framingCrop",hint:"scaleModeCover"}].map(e=>(0,i.jsxs)("label",{title:G(e.hint),className:(0,I.cn)("flex cursor-pointer items-center justify-center rounded px-1 py-0 text-sm transition-colors [&:has(:focus-visible)]:ring-1 [&:has(:focus-visible)]:ring-ring",eR===e.value?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground"),children:[(0,i.jsx)(c.C,{value:e.value,className:"sr-only focus-visible:ring-0 focus-visible:ring-offset-0"}),(0,i.jsx)("span",{children:G(e.label)})]},e.value))})]}),(0,i.jsxs)("div",{children:[(0,i.jsxs)("button",{type:"button","aria-expanded":eE,"aria-controls":"conversion-output-settings",onClick:()=>eI(e=>!e),className:"flex w-full items-center justify-between gap-2 rounded py-1 text-left text-xs font-medium text-muted-foreground hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[G("moreSettings"),(0,i.jsx)(m.A,{className:(0,I.cn)("h-3.5 w-3.5 transition-transform",eE&&"rotate-180")})]}),eE&&(0,i.jsxs)("div",{id:"conversion-output-settings",className:"mt-4 space-y-4",children:[(0,i.jsx)("div",{className:"space-y-1.5",children:(0,i.jsxs)(o.Select,{value:eA,onValueChange:e=>eP(e),children:[(0,i.jsx)(o.SelectTrigger,{fieldLabel:G("format"),"aria-label":G("format"),className:"h-8 [&:focus:not(:focus-visible)]:ring-0",children:(0,i.jsx)(o.SelectValue,{})}),(0,i.jsx)(o.SelectContent,{children:e2.map(e=>(0,i.jsx)(o.SelectItem,{value:e,children:Z[e]},e))})]})}),ee&&(0,i.jsx)("div",{className:"space-y-1.5",children:(0,i.jsxs)(o.Select,{value:eM,onValueChange:eD,children:[(0,i.jsx)(o.SelectTrigger,{fieldLabel:G("quality"),"aria-label":G("quality"),className:"h-8 [&:focus:not(:focus-visible)]:ring-0",children:(0,i.jsx)(o.SelectValue,{})}),(0,i.jsxs)(o.SelectContent,{children:[(0,i.jsx)(o.SelectItem,{value:"none",children:G("qualityKeep")}),(0,i.jsx)(o.SelectItem,{value:"high",children:G("qualityCompressHigh")}),(0,i.jsx)(o.SelectItem,{value:"medium",children:G("qualityCompressMedium")}),(0,i.jsx)(o.SelectItem,{value:"low",children:G("qualityCompressLow")})]})]})}),!ee&&"image/gif"===Q&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:G("gifHint")}),(null==eH?void 0:eH.noteKey)&&(0,i.jsx)("p",{className:"text-[11px] text-muted-foreground",children:G("presets.notes.".concat(eH.noteKey))})]})]})]}),(0,i.jsxs)("section",{className:"min-h-0 min-w-0 space-y-3 md:overflow-y-auto md:[scrollbar-gutter:stable]",children:[(0,i.jsxs)("div",{className:"flex h-[calc(var(--conversion-preview-height)+118px)] flex-col gap-3 overflow-hidden",children:[(0,i.jsx)("div",{className:"flex min-h-7 shrink-0 justify-center",children:(0,i.jsx)("div",{role:"group","aria-label":G("previewSection"),className:"flex gap-1",children:[!1,!0].map(e=>(0,i.jsx)("button",{type:"button","aria-pressed":eN===e,onClick:()=>{eS(e),eT(!1)},className:(0,I.cn)("rounded px-3 py-1 text-xs font-medium focus-visible:ring-2 focus-visible:ring-ring",eN===e?"bg-muted text-foreground":"text-muted-foreground hover:text-foreground"),children:G(e?"previewOriginal":"previewSection")},String(e)))})}),(0,i.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col justify-center gap-3 md:justify-start",children:[(0,i.jsx)("div",{className:"relative flex min-h-0 items-center justify-center",children:ee?(0,i.jsx)(W,{src:D.url,dimensions:th,crop:eo,resize:e3,mode:eR,original:eN,editing:ek&&e8,aspect:e6,onCropChange:ed,onDimensions:ew},D.id):em?(0,i.jsxs)("div",{role:"status",className:"flex flex-col items-center gap-3 text-xs text-muted-foreground",children:[(0,i.jsx)(u.A,{"aria-hidden":"true",className:"h-6 w-6 animate-spin"}),G("loadingPreview")]}):!ep&&e9&&(ee||ec)?eN?(0,i.jsx)("img",{src:ec,alt:G("previewOriginal"),className:"max-h-[var(--conversion-preview-height)] max-w-full object-contain"}):ek&&e8&&e6&&ec&&eo&&ea.current?(0,i.jsx)(z,{src:ec,sourceWidth:ea.current.naturalWi
1dth,sourceHeight:ea.current.naturalHeight,aspect:e6,crop:eo,onChange:ed}):el?(0,i.jsxs)("div",{className:"space-y-3 text-center",children:[(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:G("previewUnavailable")}),(0,i.jsx)(l.$,{type:"button",variant:"outline",size:"sm",onClick:tx,children:G("retryPreview")})]}):en?(0,i.jsx)("img",{src:en,alt:G("previewResult"),className:"max-h-[var(--conversion-preview-height)] max-w-full object-contain shadow-sm ring-1 ring-border"}):(0,i.jsxs)("div",{role:"status",className:"flex flex-col items-center gap-3 text-xs text-muted-foreground",children:[(0,i.jsx)(u.A,{"aria-hidden":"true",className:"h-6 w-6 animate-spin"}),G("loadingPreview")]}):(0,i.jsxs)("div",{className:"space-y-3 text-center",children:[(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:G("loadImageError")}),e9&&(0,i.jsx)(l.$,{type:"button",variant:"outline",size:"sm",onClick:tx,children:G("retryPreview")})]})}),(0,i.jsxs)("div",{className:"flex min-h-8 shrink-0 flex-wrap items-center justify-center gap-3",children:[!ek&&(0,i.jsxs)("p",{className:"text-xs tabular-nums text-muted-foreground",children:[null!=tp?tp:"â",tf&&" \xb7 ".concat(tf)]}),!eN&&e8&&tt&&eo&&(ek?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{className:"mr-auto text-xs text-muted-foreground",children:G("cropPositionHint")}),(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>{e6&&ta(e6)},children:G("resetCrop")}),(0,i.jsx)(l.$,{type:"button",variant:"outline",size:"sm",onClick:()=>eT(!1),children:G("doneEditingCrop")})]})]}):(0,i.jsx)(l.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>{eS(!1),eT(!0)},children:G("editCrop")}))]})]})]}),!eN&&to.upscaleWarning&&(0,i.jsx)("p",{className:"text-center text-xs text-amber-600",children:G("willUpscaleWarning")}),!eN&&to.capped&&to.targetDimensions&&(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:G("outputNoteCapped",{target:to.targetDimensions})})]})]}),(0,i.jsxs)(r.Es,{className:"grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-center gap-3 px-5 py-4 md:flex md:flex-row md:justify-between",children:[(0,i.jsx)(l.$,{variant:"ghost",size:"sm",className:"col-start-1 row-start-2 shrink-0 justify-self-start",onClick:()=>M(!1),children:G("cancel")}),(0,i.jsxs)("div",{className:"contents md:flex md:min-w-0 md:flex-wrap md:items-center md:justify-end md:gap-3",children:[(0,i.jsxs)("div",{className:"col-span-2 min-w-0 space-y-2 text-xs text-muted-foreground md:max-w-sm",children:["copy"===ej&&(0,i.jsx)("div",{role:"group","aria-label":G("folder"),className:"flex w-full flex-wrap items-center justify-end gap-2 md:flex-nowrap",children:(0,i.jsx)("div",{className:"w-full min-w-0 md:w-56",children:(0,i.jsx)(j.D,{fieldLabel:G("folder"),value:eO,onChange:ez,folderHierarchy:eL})})}),"replace"===ej&&(0,i.jsx)("p",{children:G("replaceHelper")}),ts&&"copy"===ej&&(0,i.jsxs)("div",{className:"flex items-center gap-2 text-amber-600",children:[(0,i.jsx)("span",{children:J("exceedsStorageLimit")}),(0,i.jsx)(l.$,{variant:"link",size:"sm",className:"h-auto p-0 text-amber-700",onClick:()=>eQ(!0),children:J("upgradeYourPlan")})]})]}),(0,i.jsxs)("div",{className:"col-start-2 row-start-2 flex justify-self-end",children:[(0,i.jsxs)(l.$,{size:"sm",disabled:!tm||e$||"copy"===ej&&ts,onClick:()=>{if("replace"===ej)return void eZ(!0);td()},className:(0,I.cn)(L&&"rounded-r-none"),children:[e$&&(0,i.jsx)(u.A,{className:"mr-2 h-4 w-4 animate-spin"}),G("copy"===ej?"createCopy":"replaceOriginal")]}),L&&(0,i.jsxs)(d.rI,{children:[(0,i.jsx)(d.ty,{asChild:!0,children:(0,i.jsx)(l.$,{size:"sm",disabled:e$,"aria-label":G("saveOptions"),className:"rounded-l-none border-l border-primary-foreground/20 px-2",children:(0,i.jsx)(m.A,{className:"h-4 w-4"})})}),(0,i.jsx)(d.SQ,{align:"end",className:"max-w-72",children:(0,i.jsxs)(d.Hr,{value:ej,onValueChange:e=>eC(e),children:[(0,i.jsx)(d.Ht,{value:"copy",children:(0,i.jsxs)("div",{children:[(0,i.jsx)("span",{className:"block",children:G("createCopy")}),(0,i.jsx)("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:G("copyHelper")})]})}),(0,i.jsx)(d.Ht,{value:"replace",children:(0,i.jsxs)("div",{children:[(0,i.jsx)("span",{className:"block",children:G("replaceOriginal")}),(0,i.jsx)("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:G("replaceHelper")})]})})]})})]})]})]})]})]})}),(0,i.jsx)(X.Lt,{open:eX,onOpenChange:eZ,children:(0,i.jsxs)(X.EO,{children:[(0,i.jsxs)(X.wd,{children:[(0,i.jsx)(X.r7,{children:G("confirmReplaceTitle")}),(0,i.jsx)(X.$v,{children:G("confirmReplaceDescription")})]}),(0,i.jsxs)(X.ck,{children:[(0,i.jsx)(X.Zr,{disabled:e$,onClick:()=>eZ(!1),children:G("cancel")}),(0,i.jsxs)(X.Rx,{disabled:e$,onClick:()=>void td(),children:[e$&&(0,i.jsx)(u.A,{className:"h-4 w-4 mr-2 animate-spin"}),G("replaceOriginal")]})]})]})}),(0,i.jsx)(T.PricingDialog,{open:eJ,onOpenChange:eQ})]})}},42128:(e,t,a)=>{"use strict";a.d(t,{X:()=>n});var i=a(28067);let n=(0,i.createServerReference)("783f50e650c7eed5215fae05cc7e37005200a4ee99",i.callServer,void 0,i.findSourceMapURL,"generatePresignedPutUrl")},44367:(e,t,a)=>{"use strict";a.d(t,{X:()=>s});var i=a(7778),n=a(25065),r=a(17739),l=a(17987);function s(e){let{title:t,description:a,className:s,children:o,variant:d="page",showDescription:c=!1,isHidden:u=!1}=e;return u?null:(0,i.jsxs)("div",{"data-dashboard-section-header":!0,className:(0,n.cn)("flex items-center justify-between gap-4","page"===d&&"w-full pl-4 pr-6 py-4 h-[65px]","card"===d&&"px-6 py-3","dialog"===d&&"px-4 py-3","block lg:hidden",s),children:[(0,i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,i.jsx)("h2",{className:(0,n.cn)("tracking-tight leading-none","page"===d&&"text-xl font-semibold","card"===d&&"text-base font-semibold","dialog"===d&&"text-lg font-semibold"),children:t}),a&&!c&&(0,i.jsx)(l.TooltipProvider,{children:(0,i.jsxs)(l.Tooltip,{children:[(0,i.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,i.jsx)(r.A,{className:"h-3 w-3 text-muted-foreground cursor-pointer ml-1 mt-1 align-middle"})}),(0,i.jsx)(l.TooltipContent,{children:(0,i.jsx)("p",{className:"max-w-xs",children:a})})]})}),a&&c&&(0,i.jsx)("p",{className:(0,n.cn)("text-muted-foreground","page"===d&&"text-sm leading-none",("card"===d||"dialog"===d)&&"text-xs"),children:a})]}),o&&(0,i.jsx)("div",{className:"flex items-center gap-2",children:o})]})}},45528:(e,t,a)=>{"use strict";a.d(t,{o:()=>u});var i=a(85418),n=a(49737),r=a(95258),l=a(20389),s=a(11357),o=a(16698);let d="dopost-conversion-toasts";function c(){try{let e=sessionStorage.getItem(d);return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}function u(){var e,t,a,u;let m=!(arguments.length>0)||void 0===arguments[0]||arguments[0],h=arguments.length>1?arguments[1]:void 0,{workspace:p}=(0,s.k)(),f=null==p?void 0:p.id,x=(0,l.useTranslations)("Media.convert"),g=(0,i.useRef)(new Set),[v,b]=(0,i.useState)([]),y=v.length>0?"&watchIds=".concat(v.join(",")):"",w=m&&f?"/api/queries/media/conversion-jobs?workspaceId=".concat(f).concat(y):null,{data:j,mutate:C}=(0,n.Ay)(w,async e=>{let t=await fetch(e);if(!t.ok)throw Error("Failed to fetch conversion jobs");return t.json()},{refreshInterval:e=>{var t,a,i;return 2e3*((null!=(i=null==e||null==(a=e.data)||null==(t=a.active)?void 0:t.length)?i:0)>0||v.length>0)},revalidateOnFocus:!0,dedupingInterval:500}),N=(0,i.useCallback)(e=>{b(t=>t.includes(e)?t:[...t,e])},[]),S=null!=(u=null==j||null==(t=j.data)||null==(e=t.active)?void 0:e.length)?u:0;return(0,i.useEffect)(()=>{var e,t;let a=(null!=(t=null==j||null==(e=j.data)?void 0:e.active)?t:[]).map(e=>e.id);0!==a.length&&b(e=>{let t=[...new Set([...e,...a])];return t.length===e.length&&t.every(t=>e.includes(t))?e:t})},[null==j||null==(a=j.data)?void 0:a.active]),(0,i.useEffect)(()=>{var e,t,a,i;let n=function(e){let t=new Set,a=[];for(let i of e){if("pending"===i.status)continue;let e=i.conversionJobId;!e||t.has(e)||(t.add(e),a.push(i))}return a}([...null!=(a=null==j||null==(e=j.data)?void 0:e.completed)?a:[],...null!=(i=null==j||null==(t=j.data)?void 0:t.recentFinished)?i:[]]);if(0===n.length)return;let l=!1,s=[];for(let e of n){let t=e.conversionJobId;if(!t||g.current.has(t))continue;if(c().has(t)){g.current.add(t),s.push(t),null==h||h(e);continue}g.current.add(t),s.push(t);let a=c();a.add(t);let i=Array.from(a).slice(-50);if(sessionStorage.setItem(d,JSON.stringify(i)),l=!0,"completed"===e.status){let t="replace"===e.mode?x("conversionCompleteReplace",{name:e.mediaName}):x("conversionCompleteCopy",{name:e.mediaName});r.oR.success(t),null==h||h(e)}else if("failed"===e.status){let t="replace"===e.mode?x("conversionFailedReplaceKept",{error:e.error||x("c
1onversionFailed")}):e.error||x("conversionFailed");r.oR.error(t),null==h||h(e)}else"cancelled"===e.status&&(r.oR.info(x("conversionCancelled",{name:e.mediaName})),null==h||h(e))}s.length>0&&b(e=>s.reduce((e,t)=>e.filter(e=>e!==t),e)),l&&f&&((0,o.A)(f),C())},[j,C,x,f,h]),{activeCount:S,mutate:C,registerConversionJob:N}}},47940:()=>{},49553:(e,t,a)=>{"use strict";a.d(t,{M:()=>n});var i=a(28067);let n=(0,i.createServerReference)("7033c9f14b7dc90bf90d11058faaf81211262de7e2",i.callServer,void 0,i.findSourceMapURL,"getSignedUploadPartUrl")},50366:(e,t,a)=>{"use strict";a.d(t,{X:()=>l});var i=a(7778),n=a(85191),r=a(20389);function l(){let e=(0,r.useTranslations)("Media");return(0,i.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,i.jsx)(n.A,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,i.jsx)("span",{className:"text-xs text-muted-foreground",children:e("processing")})]})}},51708:(e,t,a)=>{"use strict";a.d(t,{H:()=>n});let i="https://media.dopost.co";function n(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"media.dopost.co",a=function(e){let t=null==e?void 0:e.trim().replace(/\/+$/,"");if(!t||"undefined"===t||"null"===t)return i;let a=/^https?:\/\//i.test(t)?t:"https://".concat(t);try{let e=new URL(a),t=e.hostname.includes(".");if("http:"!==e.protocol&&"https:"!==e.protocol||!t)return i;return e.search="",e.hash="",e.toString().replace(/\/+$/,"")}catch(e){return i}}(t),n=e.replace(/^\/+/,"").split("/").map(e=>encodeURIComponent(e)).join("/");return"".concat(a,"/").concat(n)}},57645:(e,t,a)=>{"use strict";a.d(t,{m:()=>n});var i=a(28067);let n=(0,i.createServerReference)("6038e5e05147d91ed9eb7209f4508111e9b1591a0b",i.callServer,void 0,i.findSourceMapURL,"createMultipartUpload")},57783:(e,t,a)=>{"use strict";a.d(t,{C:()=>O});var i=a(7778),n=a(85418),r=a(20389),l=a(27169),s=a(69704),o=a(12237),d=a(2367),c=a(99290),u=a(3854),m=a(96116),h=a(42128),p=a(57645),f=a(49553),x=a(9463),g=a(9716),v=a(62505),b=a(95609),y=a(19348),w=a(20836),j=a(23860),C=a(11357),N=a(19873),S=a(25065),k=a(15033),T=a(51708),E=a(73431),I=a(85191),A=a(37811);let P="https://api.dopost.co/companion",M=A.env.NEXT_PUBLIC_UPPY_COMPANION_HEADERS;var D=a(83734);function R(e,t){return e&&"object"==typeof e&&"data"in e&&e.data&&"object"==typeof e.data&&"media"in e.data&&Array.isArray(e.data.media)?{...e,data:{...e.data,media:e.data.media.filter(e=>!((0,D.S)(e)&&e.storageKey===t))}}:e}var F=a(60238);function O(e){let{open:t,onOpenChange:a,onUploadComplete:A,folderHierarchy:O,initialFolderId:z}=e,L=(0,n.useRef)(t);L.current=t;let U=(0,r.useTranslations)("Media"),_=(0,r.useLocale)(),B=(0,n.useMemo)(()=>(()=>{let e=P?{id:"Dropbox",companionUrl:P,companionAllowedHosts:(e=>{if(e)return e.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{try{return new RegExp(e)}catch(t){return e}})})("api.dopost.co"),companionHeaders:(e=>{if(e)try{let t=JSON.parse(e);if(t&&"object"==typeof t)return t}catch(e){}})(M),companionCookiesRule:"include"}:null,t=["AwsS3"];return e&&t.push("Dropbox"),{dropboxOptions:e,googleDriveOptions:null,pluginIds:t}})(),[]),K=(0,l.useSearchParams)(),{workspace:G}=(0,C.k)(),[W,V]=(0,n.useState)(null),{usage:q,limits:H,isLoading:$,planTier:Y,trialEligible:X,subscriptionOwnership:Z,subscriptionId:J}=(0,b.Q)(),{onMediaUploaded:Q}=(0,y.f)(),[ee,et]=(0,n.useState)(z||K.get("folderId")||null),ea=(0,n.useRef)(ee),[ei,en]=(0,n.useState)(!1),er=(0,n.useRef)([]),el=(0,n.useRef)(new Map),es=(0,n.useRef)(new Map),eo=(0,n.useRef)(0),ed=(0,n.useRef)(0),ec=(0,n.useRef)(!1),eu=(0,n.useRef)(!1),em=(0,n.useRef)(!1),[eh,ep]=(0,n.useState)(new Map),[ef,ex]=(0,n.useState)(!1),[eg,ev]=(0,n.use
1State)(!1),eb=(0,n.useRef)(A),ey=(0,n.useRef)(A);(0,n.useEffect)(()=>{eb.current=A},[A]),(0,n.useEffect)(()=>{if(t){let e=z||K.get("folderId")||null;et(e),ea.current=e}},[t,z,K]),(0,n.useEffect)(()=>{if(!t)return;W&&(W.destroy(),V(null));let e="FREE"===Y?50:1024,a=new s.A({restrictions:{maxFileSize:1024*e*1024,maxNumberOfFiles:10,allowedFileTypes:k.kh},autoProceed:!1,locale:{strings:{..."es"===_?{uploadXFiles:{0:"Cargar %{smart_count} archivo",1:"Cargar %{smart_count} archivos"},uploadXNewFiles:{0:"Cargar +%{smart_count} archivo",1:"Cargar +%{smart_count} archivos"},processingXFiles:{0:"Procesando %{smart_count} archivo",1:"Procesando %{smart_count} archivos"},selectedXFiles:{0:"%{smart_count} archivo seleccionado",1:"%{smart_count} archivos seleccionados"},xFilesSelected:{0:"%{smart_count} archivo seleccionado",1:"%{smart_count} archivos seleccionados"},dropPaste:"Suelta archivos aqu\xed o %{browse}",browse:"explorar",uploadComplete:"Carga completa",uploadPaused:"Carga pausada",processing:"Procesando...",removeFile:"Eliminar archivo",editFile:"Editar archivo",done:"Listo",retry:"Reintentar",retryUpload:"Reintentar carga",cancel:"Cancelar",close:"Cerrar",poweredBy:"Desarrollado por",addMore:"A\xf1adir m\xe1s",addMoreFiles:"A\xf1adir m\xe1s archivos",removeAll:"Eliminar todo",dropHereOr:"Suelta archivos aqu\xed o %{browse}"}:{uploadXFiles:{0:"Upload %{smart_count} file",1:"Upload %{smart_count} files"},uploadXNewFiles:{0:"Upload +%{smart_count} file",1:"Upload +%{smart_count} files"},processingXFiles:{0:"Processing %{smart_count} file",1:"Processing %{smart_count} files"},selectedXFiles:{0:"%{smart_count} file selected",1:"%{smart_count} files selected"},xFilesSelected:{0:"%{smart_count} file selected",1:"%{smart_count} files selected"},dropPaste:"Drop files here or %{browse}",browse:"browse",uploadComplete:"Upload complete",uploadPaused:"Upload paused",processing:"Processing...",removeFile:"Remove file",editFile:"Edit file",done:"Done",retry:"Retry",retryUpload:"Retry upload",cancel:"Cancel",close:"Close",poweredBy:"Powered by",addMore:"Add more",addMoreFiles:"Add more files",removeAll:"Remove all",dropHereOr:"Drop files here or %{browse}"},dropPaste:U("dropPaste",{browse:U("browse")}),dropHereOr:U("dropHereOr",{browse:U("browse")})},pluralize:e=>+(1!==e)}}),i=async()=>{let e=eo.current;if(e<=0||ed.current<e||em.current)return;em.current=!0;let t=[...er.current];try{ey.current&&t.length>0&&await ey.current(t)}catch(e){console.error("Error calling upload complete callback:",e)}finally{ep(new Map),ex(!1),es.current.clear(),el.current.clear(),er.current=[],ed.current=0,eo.current=0,ec.current=!1,eu.current=!1,L.current||a.destroy()}},n=async()=>{ed.current+=1,await i()};B.dropboxOptions&&a.use(c.A,B.dropboxOptions),a.use(d.A,{async getUploadParameters(e){try{let t=await (0,h.X)(e.name||"unknown",e.type||"application/octet-stream");if(t.error)throw Error(t.error);let a=t.data.key;return es.current.set(e.id,{name:e.name||"unknown",type:e.type||"application/octet-stream",size:e.size||0,key:a,preProcessedData:e.meta.preProcessedData}),{method:"PUT",url:t.data.url,fields:{},headers:{"Content-Type":e.type||"application/octet-stream"}}}catch(e){throw e}},async createMultipartUpload(e){try{let t=await (0,p.m)(e.name||"unknown",e.type||"application/octet-stream");if(t.error)throw Error(t.error);let a=t.data.key;return es.current.set(e.id,{name:e.name||"unknown",type:e.type||"application/octet-stream",size:e.size||0,key:a,preProcessedData:e.meta.preProcessedData}),{uploadId:t.data.uploadId,key:t.data.key}}catch(e){throw e}},async listParts(e,t){let{uploadId:a,key:i}=t;return[]},async signPart(e,t){let{uploadId:a,key:i,partNumber:n}=t;try{if(!i||!a||!n)throw Error("Missing required parameters for signing part");let e=await (0,f.M)(i,a,n);if(e.error)throw Error(e.error);return{url:e.data.url}}catch(e){throw e}},async completeMultipartUpload(e,t){let{uploadId:a,key:i,parts:n}=t;try{let e=n.map(e=>({ETag:e.etag||e.ETag,PartNumber:e.number||e.PartNumber}));if(!i||!a)throw Error("Missing key or uploadId for completing multipart upload");let t=await (0,x.d)(i,a,e);if(t.error)throw Error(t.error);return{location:t.data.location}}catch(e){throw e}},async abortMultipartUpload(e,t){let{uploadId:a,key:i}=t;try{if(!i||!a)return void console.warn("[UploadDialog] Missing key or uploadId for aborting multipart upload");await (0,g.W)(i,a)}catch(e){console.error("[UploadDialog] Failed to abort multipart upload:",e)}},shouldUseMultipart:e=>{var t;return(null!=(t=e.size)?t:0)>0x6400000},getChunkSize:e=>{var t;return(null!=(t=e.size)?t:0)>524288e3?0x1400000:0xa00000}}),a.on("file-added",async e=>{var t,i,n;if(ep(t=>{let a=new Map(t);a.set(e.id,{name:e.name||"unknown",size:e.size||0});let i=Array.from(a.values()).reduce((e,t)=>
1e+t.size,0),n=(null==q?void 0:q.mediaStorageMB)||0,r=(null==H?void 0:H.media_storage.max)||null;return ex(!!r&&n+i/1048576>r),a}),e.type.startsWith("video/")&&e.data&&(0,m.$b)(e.data))try{let t=await (0,m.Gn)(e.data,{width:200});t.success&&t.dataUrl&&a.setFileState(e.id,{preview:t.dataUrl})}catch(e){}else if((null==(t=e.name)?void 0:t.toLowerCase().endsWith(".mov"))&&(!e.type||""===e.type)&&e.data)try{let t=await (0,m.Gn)(e.data,{width:200});t.success&&t.dataUrl&&a.setFileState(e.id,{preview:t.dataUrl})}catch(e){}else if((null==(i=e.name)?void 0:i.toLowerCase().endsWith(".mov"))&&e.data&&(0,m.$b)(e.data))try{let t=await (0,m.Gn)(e.data,{width:200});t.success&&t.dataUrl&&a.setFileState(e.id,{preview:t.dataUrl})}catch(e){}try{let t,i,r,l;if(es.current.has(e.id)||es.current.set(e.id,{name:e.name||"unknown",type:e.type||"application/octet-stream",size:e.size||0,key:"",preProcessedData:e.meta.preProcessedData}),e.type.startsWith("video/")&&e.data)try{let a=await (0,F.s)(e.data);t=a.duration,i=a.width,r=a.height}catch(e){}else if(e.type.startsWith("image/")&&e.data)try{let t=await (0,F.k)(e.data);i=t.width,r=t.height}catch(e){}if(e.data&&(0,m.$b)(e.data))try{let t=await (0,m.Gn)(e.data);t.success&&t.blob&&(l={blob:t.blob,width:t.width||0,height:t.height||0,dataUrl:t.dataUrl})}catch(e){}let s={metadata:e.type.startsWith("video/")?{duration:t,width:i,height:r}:{width:i,height:r},thumbnailBlob:null==l?void 0:l.blob,thumbnailDataUrl:null==l?void 0:l.dataUrl};el.current.set(e.id,{metadata:s.metadata,thumbnailBlob:s.thumbnailBlob,thumbnailDataUrl:s.thumbnailDataUrl,originalFileName:e.name||"unknown",fileType:e.type||"application/octet-stream",fileSize:e.size||0}),e.meta={...e.meta,preProcessedData:s};let o=es.current.get(e.id);o&&es.current.set(e.id,{...o,preProcessedData:s}),ea.current=ee,(null==l?void 0:l.dataUrl)&&e.type.startsWith("video/")?a.setFileState(e.id,{preview:l.dataUrl}):(null==l?void 0:l.dataUrl)&&(null==(n=e.name)?void 0:n.toLowerCase().endsWith(".mov"))&&a.setFileState(e.id,{preview:l.dataUrl})}catch(e){}}),a.on("files-added",e=>{}),a.on("file-removed",e=>{ep(t=>{let a=new Map(t);a.delete(e.id);let i=Array.from(a.values()).reduce((e,t)=>e+t.size,0),n=(null==q?void 0:q.mediaStorageMB)||0,r=(null==H?void 0:H.media_storage.max)||null;return ex(!!r&&n+i/1048576>r),a}),el.current.delete(e.id),es.current.delete(e.id)});let r=a.getFiles();return r.length>0&&r.forEach(e=>{a.emit("file-added",e)}),a.on("upload-progress",(e,t)=>{}),a.on("upload-error",(e,t,i)=>{a.info({message:"Upload failed for ".concat(null==e?void 0:e.name,": ").concat((null==t?void 0:t.message)||"Unknown error")})}),a.on("upload-success",async(e,t)=>{var i,r,l,s,o;let d=null==e?void 0:e.id;if(!d)return void await n();let c=es.current.get(d);if(!c||!c.key){let a=null==t?void 0:t.body,r=(null==a?void 0:a.key)||(null==a?void 0:a.Key)||((null==t?void 0:t.uploadURL)?new URL(t.uploadURL).pathname.substring(1):null);if(r)c?(c.key=r,0===c.size&&(null==e?void 0:e.size)&&(c.size=e.size)):c={name:(null==e?void 0:e.name)||"unknown",type:(null==e?void 0:e.type)||"application/octet-stream",size:(null==e?void 0:e.size)||0,key:r,preProcessedData:null==e||null==(i=e.meta)?void 0:i.preProcessedData},es.current.set(d,c);else{console.error("Could not determine S3 key for file",d,t),await n();return}}let u=a.getFile(d);try{let e,t,a={},i=el.current.get(d),n=ea.current,p=n===U("home")?null:n,f=(0,T.H)(c.key),x=null==i?void 0:i.thumbnailDataUrl,g=c.type.startsWith("image/")&&x?x:f,b={id:"temp-".concat(d),name:c.name,type:c.type,url:g,thumbnailUrl:x||f,sizeInBytes:BigInt(c.size),durationSeconds:null!=(l=null==i?void 0:i.metadata.duration)?l:null,width:null!=(s=null==i?void 0:i.metadata.width)?s:null,height:null!=(o=null==i?void 0:i.metadata.height)?o:null,storageKey:c.key,thumbnailStorageKey:null,deletedAt:null,assetId:null,visibility:"LIBRARY",composerExpiresAt:null,status:"READY",folderId:p,workspaceId:(null==G?void 0:G.id)||"",createdAt:new Date,updatedAt:new Date,_isOptimistic:!0,_tempId:d},y=null==G?void 0:G.id,w=y?"/api/queries/media/contents".concat(p?"?folderId=".concat(p,"&"):"?","workspaceId=").concat(y):null;w&&await (0,j.j)(w,e=>(function(e,t){if(!e||"object"!=typeof e||!("data"in e)||!e.data||"object"!=typeof e.data||!("media"in e.data)||!Array.isArray(e.data.media))return e;let a=e.data.media.filter(e=>!((0,D.S)(e)&&e.storageKey===t.storageKey));return{...e,data:{...e.data,media:[t,...a]}}})(e,b),{revalidate:!1});let C=el.current.get(d),N=null==u||null==(r=u.meta)?void 0:r.preProcessedData,k=c.preProcessedData,E=C||N||k;if(E){if(C){if(a=C.metadata,C.thumbnailBlob)try{if(!c.key)return;let a=await (0,m.Jm)(C.thumbnailBlob,c.key,h.X);e=a.thumbnailUrl,t=a.thumbnailKey}catch(e){}}else if("object"==typeof E){a=E.metadata||{};let i=E.thumbnailBlob;if(i)try{let a=await (0,m.Jm)(i,c.key,h.X);e=a.thumbnailUrl,t=a.thumbnailKey}catch(e){}}}let I={};a.duration&&(I.durationSeconds=a.duration),a.width&&(I.width=a.width),a.height&&(I.height=a.height);let A=await (0,v.e)({name:c.name,type:c.type,url:f,sizeInBytes:c.size,storageKey:c.key,thumbnailUrl:e,thumbnailStorageKey:t,folderId:p,subscriptionId:J||void 0,skipPathRevalidation:!0,...I});if(A.data){w&&await (0,j.j)(w,e=>(function(e,t){if(!e||"object"!=typeof e||!("data"in e)||!e.data||"object"!=typeof e.data||!("media"in e.data)||!Array.isArray(e.data.media))return e;let a=new Map(t.map(e=>[e.id,e])),i=new Map(t.filter(e=>!!e.storageKey).map(e=>[e.storageKey,e])),n=new Set,r=e.data.media.map(e=>{let t=(0,D.S)(e)?e.storageKey?i.get(e.storageKey):void 0:a.get(e.id);return t?(n.add(t.id),t):e}),l=t.filter(e=>!n.has(e.id)),s=new Set,o=new Set,d=[...l,...r].filter(e=>{if((0,D.S)(e)){let t=e.storageKey||e.id;return!o.has(t)&&(o.add(t),!0)}return!s.has(e.id)&&(s.add(e.id),!0)});return{...e,data:{...e.data,media:d}}})(e,[A.data]),{revalidate:!1}),el.current.delete(d),er.current.push(A.data);let e=(0,S.LI)(c.size)/1048576;e>0&&await Q(e)}else console.warn("Failed to create media record for ".concat(c.name,":"),A.error),w&&await (0,j.j)(w,e=>R(e,c.key),{revalidate:!1}),el.current.delete(d)}catch(n){console.error("Error processing uploaded file:",n),el.current.delete(d);let e=c,t=ea.current===U("home")?null:ea.current,a=null==G?void 0:G.id,i=a?"/api/queries/media/contents".concat(t?"?folderId=".concat(t,"&"):"?","workspaceId=").concat(a):null;e&&i&&await (0,j.j)(i,t=>R(t,e.key),{revalidate:!1})}finally{await n()}}),a.on("complete",e=>{var t,a;eu.current=!0;let n=null!=(a=null==(t=e.failed)?void 0:t.length)?a:0;n>0&&(ed.current+=n,i())}),a.on("upload",async(e,t)=>{ec.current=!0,eu.current=!1,em.current=!1,ey.current=eb.current,eo.current=t.length,ed.current=0;let i=t.reduce((e,t)=>
1e+(t.size||0),0)/1048576,n=(null==q?void 0:q.mediaStorageMB)||0,r=(null==H?void 0:H.media_storage.max)||null;if(r&&n+i>r){a.cancelAll(),a.info({message:"Upload cancelled: Would exceed storage limit by ".concat((n+i-r).toFixed(1),"MB. Please remove some files or upgrade your plan.")}),ec.current=!1;return}let l=t.map(e=>e.id);if(!l.every(e=>el.current.has(e))){let e=0;for(;e<1e4&&!l.every(e=>el.current.has(e));)await new Promise(e=>setTimeout(e,100)),e+=100}}),V(a),setTimeout(()=>{},1e3),()=>{if(ec.current&&!em.current)return;let e=es.current,t=el.current;e.clear(),t.clear(),er.current=[],ed.current=0,eo.current=0,ec.current=!1,eu.current=!1,em.current=!1,ep(new Map),ex(!1),null==a||a.destroy()}},[t,Y,B]),(0,n.useEffect)(()=>{if(!t&&W){let e=setTimeout(()=>{V(e=>e===W?null:e)},300);return()=>clearTimeout(e)}},[t,W]);let ew=(null==q?void 0:q.mediaStorageMB)||0,ej=(null==H?void 0:H.media_storage.max)||null,eC=ej&&ej>0?Math.min(ew/ej*100,100):0,eN=ej&&eC>=100,eS="FREE"===Y;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(u.lG,{open:t,onOpenChange:e=>{(e||!ec.current||eu.current)&&a(e)},children:(0,i.jsxs)(u.Cf,{className:"sm:max-w-[800px] max-h-[90vh] p-0 min-h-[500px]",children:[(0,i.jsx)(u.c7,{className:"px-2 pt-4 md:px-3 ",children:(0,i.jsx)(u.L3,{children:U("uploadTitle")})}),(0,i.jsx)("div",{className:"px-3",children:(0,i.jsxs)("div",{className:"",children:[(0,i.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,i.jsx)("div",{className:"text-xs font-semibold text-muted-foreground",children:U("folderLabel")}),(0,i.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,i.jsxs)("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[(0,i.jsx)(E.A,{className:"h-3 w-3"}),$?(0,i.jsx)(I.A,{className:"h-3 w-3 animate-spin inline-block"}):(0,i.jsxs)("span",{children:[(0,S.s8)(ew),ej?"/".concat((0,S.s8)(ej)):""]})]}),ej&&!$&&(0,i.jsxs)("span",{className:(0,S.cn)("text-[10px] px-1 py-0.5 rounded font-medium",eC>=100?"bg-red-100 text-red-800":eC>=90?"bg-orange-100 text-orange-800":"bg-green-100 text-green-700"),children:[Math.round(eC),"%"]})]})]}),(0,i.jsx)(N.D,{value:ee,onChange:e=>{et(e),ea.current=e,en(!1)},onOpenChange:en,folderHierarchy:O||[]})]})}),W&&!eN&&(0,i.jsxs)("div",{className:"relative p-3",children:[(0,i.jsx)(o.xh,{uppy:W,plugins:B.pluginIds,width:"100%",height:"400px",showProgressDetails:!0,doneButtonHandler:()=>a(!1),proudlyDisplayPoweredByUppy:!1,showSelectedFiles:!0,showRemoveButtonAfterComplete:!1,metaFields:[],fileManagerSelectionType:"files",disableStatusBar:!1,disableInformer:!1,disableThumbnailGenerator:!1,waitForThumbnailsBeforeUpload:!1,className:(0,S.cn)("rounded-lg ",ei&&"pointer-events-none opacity-60",ef&&"upload-disabled"),note:"".concat(U("maxFileSizeNote")," ").concat((0,S.s8)(eS?50:1024),". ").concat(U("fileTypesNote"))}),ef&&(0,i.jsx)("div",{className:"absolute bottom-16 left-1/2 transform -translate-x-1/2 z-30 mb-2",children:(0,i.jsx)("div",{className:"bg-gray-100 text-destructive px-4 py-2 rounded-lg text-sm font-medium border flex items-center gap-2 min-w-max",children:(0,i.jsxs)("span",{children:[U("exceedsStorageLimit")," ",(0,i.jsx)("button",{onClick:()=>ev(!0),className:"underline hover:no-underline font-semibold",children:U("upgradeYourPlan")})]})})})]}),eN&&(0,i.jsxs)("div",{className:"p-6 text-center",children:[(0,i.jsx)("div",{className:"text-lg font-semibold text-destructive mb-2",children:U("storageLimitReached")}),(0,i.jsx)("div",{className:"text-sm text-muted-foreground mb-4",children:U("storageLimitReachedDescription")}),(0,i.jsxs)("div",{className:"text-xs text-muted-foreground",children:[U("currentUsage")," ",(0,S.s8)(ew)," /"," ",ej?(0,S.s8)(ej):U("unlimited")]})]})]})}),(0,i.jsx)(w.PricingDialog,{open:eg,onOpenChange:ev,currentPlanTier:Y,context:"media-storage",loading:!1,trialEligible:X,subscriptionOwnership:Z})]})}a(47940),a(70791),a(92304)},60238:(e,t,a)=>{"use strict";function i(e,t,a){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"load";return new Promise(n=>{let r=URL.createObjectURL(t),l=t=>{URL.revokeObjectURL(r),e.removeAttribute("src"),e.onerror=null,n(t)};e.addEventListener(i,()=>l(a(e)),{once:!0}),e.onerror=()=>l({}),e.src=r})}async function n(e){return e.type.startsWith("image/")?i(document.createElement("img"),e,e=>
1({width:e.naturalWidth||void 0,height:e.naturalHeight||void 0})):{}}async function r(e){if(!(e.type.startsWith("video/")||/\.(mov|mp4)$/i.test(e.name)))return{};let t=document.createElement("video");return t.preload="metadata",i(t,e,e=>({duration:Number.isFinite(e.duration)?Math.round(e.duration):void 0,width:e.videoWidth||void 0,height:e.videoHeight||void 0}),"loadedmetadata")}a.d(t,{k:()=>n,s:()=>r})},62505:(e,t,a)=>{"use strict";a.d(t,{e:()=>n});var i=a(28067);let n=(0,i.createServerReference)("409a894af35ef0d52a074c2b696f15a42a16d21a4d",i.callServer,void 0,i.findSourceMapURL,"createMediaRecordAction")},68380:(e,t,a)=>{"use strict";a.d(t,{I:()=>s,p:()=>l});var i=a(85418),n=a(11357);let r=null;function l(){r=null}function s(e,t){let a=null!=t,{workspace:l}=(0,n.k)(),s=null==l?void 0:l.id,[o,d]=(0,i.useState)(t||null),[c,u]=(0,i.useState)(!a),[m,h]=(0,i.useState)(null);return(0,i.useEffect)(()=>{if(a){d(t),u(!1),h(null);return}(async()=>{if(!e||!s)return;let t=Date.now();if(r&&t-r.timestamp<r.maxAge){d(r.data),u(!1),h(null);return}u(!0),h(null),d(null);try{let e=await fetch("/api/queries/social-connections?workspaceId=".concat(s));if(!e.ok)throw Error("Failed to fetch social connections");let a=await e.json(),i={data:a.data,error:a.success?null:"Failed to fetch social connections"};if(i.error)h(i.error);else{let e=i.data||[];d(e),r={data:e,timestamp:t,maxAge:3e5}}}catch(e){console.error("Failed to fetch social accounts:",e),h("An unexpected error occurred while fetching accounts.")}finally{u(!1)}})()},[e,t,a,s]),{socialAccounts:o,isLoading:c,error:m,setSocialAccounts:d}}},70791:()=>{},76609:(e,t,a)=>{"use strict";a.d(t,{Y:()=>f});var i=a(7778),n=a(85418),r=a(50330),l=a(3854),s=a(55754),o=a(79536),d=a(97237),c=a(85191),u=a(5853),m=a(25065),h=a(20389);let p=e=>[...e].sort((e,t)=>e.isActive!==t.isActive?t.isActive?1:-1:e.platform!==t.platform?e.platform.localeCompare(t.platform):e.platformUsername.localeCompare(t.platformUsername));function f(e){let{isOpen:t,onOpenChange:a,accounts:f,onSubmit:x,isLoading:g}=e,v=(0,h.useTranslations)("EditGroupDialog"),[b,y]=(0,n.useState)(""),[w,j]=(0,n.useState)(new Set),[C,N]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{t&&(y(""),j(new Set),N(!1))},[t]),(0,i.jsx)(l.lG,{open:t,onOpenChange:a,children:(0,i.jsxs)(l.Cf,{className:"max-h-[80vh] h-[80vh] md:h-auto flex flex-col gap-0 p-0",children:[(0,i.jsxs)(l.c7,{className:"p-4 pb-3 flex-none",children:[(0,i.jsx)(l.L3,{children:"Create Group"}),(0,i.jsx)(l.rr,{children:"Create a new group for your social accounts."})]}),(0,i.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,i.jsx)("div",{className:"h-full max-h-[calc(80vh-200px)] overflow-y-auto px-6",children:(0,i.jsxs)("div",{className:"space-y-4",children:[(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsx)(o.J,{htmlFor:"new-group-name",children:"Group Name"}),(0,i.jsx)(s.p,{id:"new-group-name",value:b,onChange:e=>y(e.target.value),placeholder:"Enter group name",disabled:g})]}),(0,i.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,i.jsx)(d.S,{id:"new-group-default",checked:C,onCheckedChange:e=>N(!0===e),disabled:g}),(0,i.jsx)(o.J,{htmlFor:"new-group-default",className:"text-sm font-normal cursor-pointer",children:v("form.useAsDefault")})]}),(0,i.jsxs)("div",{className:"space-y-2",children:[(0,i.jsx)(o.J,{children:"Select Accounts"}),(0,i.jsxs)("div",{className:"pr-1",children:[p(f).map((e,t,a)=>{let n=w.has(e.id),r=t===a.length-1,l=1===a.length,s="border-x ";return l?s+="border-y rounded-md":(s+="border-t ",0===t&&(s+="rounded-t-md"),r&&(s+="border-b rounded-b-md")),(0,i.jsxs)("div",{className:(0,m.cn)("flex items-center justify-between w-full p-3 transition-colors text-left cursor-pointer rounded-none",s,n?"bg-muted/30":"hover:bg-muted/50",g?"opacity-70 pointer-events-none":""),onClick:()=>{if(g)return;let t=new Set(w);w.has(e.id)?t.delete(e.id):t.add(e.id),j(t)},role:"button",tabIndex:g?-1:0,onKeyDown:t=>{if(!g&&("Enter"===t.key||" "===t.key)){t.preventDefault();let a=new Set(w);w.has(e.id)?a.delete(e.id):a.add(e.id),j(a)}},children:[(0,i.jsxs)("div",{className:"flex items-center gap-3",children:[(0,i.jsx)(u.u,{account:{id:e.id,platform:e.platform,platformUsername:e.platformUsername,metadata:"string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata},size:"sm"}),(0,i.jsxs)("div",{children:[(0,i.jsx)("p",{className:"font-medium",children:(()=>{let t=e.platformUsername;try{if(e.metadata){let a="string"==typeof e.metadata?JSON.parse(e.metadata):e.metadata;a&&(t=a.displayName||a.name||t)}}catch(e){}return t})()}),(0,i.jsx)("p",{className:"text-xs text-muted-foreground",children:"FACEBOOK"===e.platform?"Facebook":"INSTAGRAM"===e.platform||"INSTAGRAM_DIRECT"===e.platform?"Instagram":"LINKEDIN"===e.platform||"LINKEDIN_ORGANIZATION"===e.platform?"LinkedIn":"X"===e.platform?"X/Twitter":"TIKTOK"===e.platform?"TikTok Account":"THREADS"===e.platform?"Threads Account":"MASTODON"===e.platform?"Mastodon Account":"BLUESKY"===e.platform?"BlueSky Account":"PINTEREST"===e.platform?"Pinterest Account":"YOUTUBE"===e.platform?"YouTube Channel":"TELEGRAM"===e.platform?"Telegram Destination":"GOOGLE_BUSINESS"===e.platform?"Google Business Location":"".concat(e.platform," Account")}
1)]})]}),(0,i.jsx)(d.S,{checked:n,className:"pointer-events-none",disabled:g})]},e.id)}),0===p(f).length&&(0,i.jsx)("p",{className:"text-sm text-muted-foreground py-2",children:"No accounts available to add."})]})]})]})})}),(0,i.jsxs)(l.Es,{className:"px-6 py-4 flex-none backdrop-blur-sm bg-background/75",children:[(0,i.jsx)(r.$,{variant:"outline",onClick:()=>a(!1),disabled:g,className:"cursor-pointer",children:"Cancel"}),(0,i.jsxs)(r.$,{onClick:()=>{x(b,Array.from(w),C)},disabled:g||!b.trim(),className:"cursor-pointer",children:[g&&(0,i.jsx)(c.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Create Group"]})]})]})})}},80683:(e,t,a)=>{"use strict";a.d(t,{F:()=>l});var i=a(85418),n=a(93846);let r=new Map;function l(e,t){let[a,l]=(0,i.useState)(()=>{var a;return!!t&&(null!=(a=r.get(e))?a:null)});return(0,i.useEffect)(()=>{if(!t)return void l(!1);let a=r.get(e);if(void 0!==a)return void l(a);let i=new AbortController;return(0,n.p)(e,i.signal).then(t=>{r.set(e,t),l(t)}),()=>i.abort()},[e,t]),a}},83734:(e,t,a)=>{"use strict";function i(e){return"_isOptimistic"in e&&!0===e._isOptimistic}function n(e){return!!e._error}a.d(t,{S:()=>i,o:()=>n})},92304:()=>{},93846:(e,t,a)=>{"use strict";function i(e,t,a){var i,n,r;if("image/gif"===e.toLowerCase())return!0;let l=null!=(n=null==t||null==(i=t.split("?")[0])?void 0:i.toLowerCase())?n:"",s=null!=(r=null==a?void 0:a.toLowerCase())?r:"";return l.endsWith(".gif")||s.endsWith(".gif")}async function n(e,t){let a={Range:"bytes=0-65535"};try{let i=await fetch(e,{signal:t,headers:a});if(i.ok||206===i.status)return new Uint8Array(await i.arrayBuffer())}catch(e){}try{let i="/api/media/proxy?url=".concat(encodeURIComponent(e)),n=await fetch(i,{signal:t,headers:a});if(n.ok||206===n.status){let e=await n.arrayBuffer();return new Uint8Array(e.slice(0,65536))}}catch(e){}return null}async function r(e,t){let a=await n(e,t);if(!a)return!1;if(a.length<10)return!1;let i=String.fromCharCode(...a.slice(0,6));if("GIF87a"!==i&&"GIF89a"!==i)return!1;let r=0;for(let e=0;e<a.length-1;e++)if(33===a[e]&&249===a[e+1]&&++r>1)return!0;return!1}a.d(t,{p:()=>r,x:()=>i})},96116:(e,t,a)=>{"use strict";a.d(t,{$b:()=>c,Gn:()=>o,Jm:()=>d});var i=a(25065);let n={width:-1,quality:.8,format:"webp",seekTime:1};async function r(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a={...n,...t},i=document.createElement("video"),r=i.canPlayType(e.type),l=e.name.toLowerCase().endsWith(".mov");return""!==r||l?new Promise(t=>{let n=document.createElement("canvas"),r=!1,l=()=>{i.src&&i.src.startsWith("blob:")&&URL.revokeObjectURL(i.src);try{i.src="",i.load(),i.onloadedmetadata=null,i.onerror=null,i.onseeked=null,i.remove()}catch(e){console.warn("[generateVideoThumbnail] Video cleanup warning:",e)}},s=e=>{r||(r=!0,t(e))};i.onerror=()=>{l(),s({success:!1,error:"Failed to load video file"})},i.onloadedmetadata=()=>{try{var e;if(!i.videoWidth||!i.videoHeight){l(),s({success:!1,error:"Invalid video dimensions"});return}let t=(e=i.duration,!Number.isFinite(e)||e<=0||e<=.25?0:Math.min(Math.min(Math.max(.1*e,.25),3),Math.max(0,e-.05)));i.currentTime=t}catch(e){l(),s({success:!1,error:"Failed to seek video: ".concat(e instanceof Error?e.message:"Unknown error")})}},i.onseeked=()=>{try{let e,t,r=i.videoWidth,o=i.videoHeight;if(-1===a.width){if(e=r,t=o,e>4096||t>4096){let a=Math.min(4096/e,4096/t);e=Math.round(e*a),t=Math.round(t*a)}}else{let i=o/r;e=a.width,t=Math.round(a.width*i)}let d=t%2==0?t:t+1;n.width=e,n.height=d;let c=n.getContext("2d");if(!c){l(),s({success:!1,error:"Failed to get 2D context"});return}c.imageSmoothingEnabled=!0,c.imageSmoothingQuality="high",c.drawImage(i,0,0,e,d),n.toBlob(t=>{if(l(),t){let i=n.toDataURL("image/".concat(a.format),a.quality);s({success:!0,blob:t,dataUrl:i,width:e,height:d})}else s({success:!1,error:"Failed to convert canvas to blob"});try{let e=n.getContext("2d");e&&e.clearRect(0,0,n.width,n.height),n.width=0,n.height=0}catch(e){console.warn("[generateVideoThumbnail] Canvas cleanup warning:",e)}},"image/".concat(a.format),a.quality)}catch(e){l(),s({success:!1,error:"Canvas processing error: ".concat(e instanceof Error?e.message:"Unknown error")})}}
1,i.preload="metadata",i.muted=!0,i.playsInline=!0,i.crossOrigin="anonymous",i.src=URL.createObjectURL(e);let o=Math.max(15e3,Math.min(45e3,1500*(e.size/1048576)));setTimeout(()=>{r||(console.warn("[generateVideoThumbnail] â° Timeout after ".concat((o/1e3).toFixed(1),"s for ").concat(e.name)),l(),s({success:!1,error:"Thumbnail generation timeout"}))},o)}):(console.warn("[generateVideoThumbnail] â Browser cannot play ".concat(e.type," - falling back to server-side generation")),{success:!1,error:"Browser does not support ".concat(e.type," video format")})}async function l(e,t,a,i){let n=document.createElement("canvas"),{width:r,height:l}=function(e,t,a){let i,n;if(-1===a||a<=0){let a=e>300?300/e:1;i=Math.max(1,Math.round(e*a)),n=Math.max(1,Math.round(t*a))}else i=a,n=Math.max(1,Math.round(t/e*a));if(i>4096||n>4096){let e=Math.min(4096/i,4096/n);i=Math.round(i*e),n=Math.round(n*e)}return{width:i,height:n}}(t,a,i.width);n.width=r,n.height=l;let s=n.getContext("2d");return s?(s.imageSmoothingEnabled=!0,s.imageSmoothingQuality="high",s.drawImage(e,0,0,r,l),new Promise(e=>{n.toBlob(t=>{t?e({success:!0,blob:t,dataUrl:n.toDataURL("image/".concat(i.format),i.quality),width:r,height:l}):e({success:!1,error:"Failed to convert canvas to blob"});try{s.clearRect(0,0,n.width,n.height),n.width=0,n.height=0}catch(e){}},"image/".concat(i.format),i.quality)})):{success:!1,error:"Failed to get 2D context"}}async function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a={...n,...t};if("undefined"!=typeof createImageBitmap)try{let t=await createImageBitmap(e,{imageOrientation:"from-image"});try{return await l(t,t.width,t.height,a)}finally{t.close()}}catch(e){}return new Promise(t=>{let i=new Image,n=!1,r=()=>{i.src&&i.src.startsWith("blob:")&&URL.revokeObjectURL(i.src),i.src="",i.onload=null,i.onerror=null},s=e=>{n||(n=!0,t(e))};i.onerror=()=>{r(),s({success:!1,error:"Failed to load image file"})},i.onload=()=>{l(i,i.width,i.height,a).then(e=>{r(),s(e)}).catch(e=>{r(),s({success:!1,error:"Canvas processing error: ".concat(e instanceof Error?e.message:"Unknown error")})})},i.src=URL.createObjectURL(e),setTimeout(()=>{n||(r(),s({success:!1,error:"Image thumbnail generation timeout"}))},Math.max(1e4,Math.min(3e4,1e3*(e.size/1048576))))})}async function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=e.type.startsWith("video/"),i=e.type.startsWith("image/");return a||e.name.toLowerCase().endsWith(".mov")||e.name.toLowerCase().endsWith(".mp4")||e.name.toLowerCase().endsWith(".webm")?await r(e,t):i?await s(e,t):{success:!1,error:"Unsupported media type for thumbnail generation: ".concat(e.type)}}async function d(e,t,a){try{let n=(0,i.Cu)(t).split("/").pop()||"thumbnail.webp",r=await a(n,"image/webp");if(r.error||!r.data)return console.error("[uploadThumbnailDirect] â Failed to get presigned URL:",r.error),{success:!1,error:r.error||"Failed to get presigned URL"};let l=await fetch(r.data.url,{method:"PUT",body:e,headers:{"Content-Type":"image/webp"}});if(!l.ok)return console.error("[uploadThumbnailDirect] â R2 upload failed:",{status:l.status,statusText:l.statusText}),{success:!1,error:"Upload failed: ".concat(l.status," ").concat(l.statusText)};let s="https://".concat("media.dopost.co","/").concat(r.data.key);return{success:!0,thumbnailUrl:s,thumbnailKey:r.data.key}}catch(e){return console.error("[uploadThumbnailDirect] â Error in presigned URL upload:",e),{success:!1,error:"Presigned URL upload error: ".concat(e instanceof Error?e.message:"Unknown error")}}}function c(e){if(e.size>0xc800000)return!1;let t=e.type.startsWith("video/"),a=e.type.startsWith("image/"),i=["video/mp4","video/webm","video/quicktime"].includes(e.type),n=["image/jpeg","image/jpg","image/png","image/gif","image/webp"].includes(e.type),r=e.name.toLowerCase().endsWith(".mov");return(!t||!!i||!!r)&&(!!r&&!t||(!a||!!n)&&(!!t||!!a||!!r))}},97237:(e,t,a)=>{"use strict";a.d(t,{S:()=>o});var i=a(7778),n=a(85418),r=a(34304),l=a(18545),s=a(25065);let o=n.forwardRef((e,t)=>{let{className:a,...n}=e;return(0,i.jsx)(r.bL,{ref:t,className:(0,s.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",a),...n,children:(0,i.jsx)(r.C1,{className:(0,s.cn)("flex items-center justify-center text-current"),children:(0,i.jsx)(l.A,{className:"h-4 w-4"})})})});o.displayName=r.bL.displayName}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.