1import{K as Wt,r as i,cg as Is,j as e,aR as Ss,cj as ir,ce as lr,cA as Ga,aM as he,ci as or,cB as cr,cC as dr,c as Es,cJ as mr,_ as $s,a5 as za,a as se,a6 as E,ak as Pe,cb as hr,B as n,al as Fe,am as Ae,an as Ie,C as N,b as fe,d as ye,F as ae,e as b,s as C,S as ze,ab as m,aF as L,h as xr,$ as W,a0 as Y,a1 as X,a2 as Z,a3 as p,ap as Ee,a4 as me,a7 as pr,bU as ur,ao as Qe,R as Ne,bJ as Bt,w as qa,bS as _t,aq as Ge,N as gr,bD as Mt,o as Be,f as te,ba as ms,bb as hs,U as pa,aK as rt,bc as xs,L as jr,aD as nt,aY as ua,aE as ps,H as Rt,a8 as ga,a9 as ja,aa as va,D as ce,au as Te,E as _e,V as fa,T as ya,J as vr,v as us,bC as Kt,M as gs,l as Na,b7 as js,aH as vs,bd as ba,bj as fr,Q as wa,z as fs,n as yr,x as Nr,ar as Ma,aL as br,bT as wr,aG as Cr,g as kr,as as Sr,at as Tr,av as Pr,aw as Fr,ax as Ar,ay as Ir,az as Er,aA as $r,aB as Or}from"./index-CuSEeJFb.js";import{T as Lr,a as Dr,b as bt,c as wt}from"./tabs-CcPOXtvT.js";import{P as Ra}from"./progress-B2eMqtVV.js";import{S as Ut}from"./skeleton-BRByoc1c.js";import{S as Ts}from"./slider-1BwPyzha.js";import{R as Gr,a as Ca}from"./radio-group-Cg3Pu9OU.js";import{M as it}from"./mic-BSL7EuWM.js";import{P as ka}from"./pause-DRo4KdS6.js";import{P as Sa}from"./play-oR40AlEL.js";import{S as de}from"./save-DMqvNvzo.js";import{V as Ua}from"./volume-2-bzvEFd58.js";import{u as zr,a as Ta,D as qr,c as Mr,S as Rr,v as Ur,d as Vr,C as Br,s as _r,K as Kr,P as Qr,f as Hr}from"./sortable.esm-CaaY9462.js";import{W as Pa}from"./wand-sparkles-Cnc6tXs_.js";import{R as ys}from"./rocket-DokzAs0d.js";import{B as Jr}from"./bot-ecRnbbNU.js";import{M as Fa,r as Aa}from"./index-C9j0a0yw.js";import{C as Ke}from"./copy-Ctw93tQ7.js";import{M as Wr}from"./mail-open-DbuTRLNH.js";import{a as Ns,F as Os}from"./folder-XQRCjIoi.js";import{T as Yr}from"./tags-CBvfOqZS.js";import{G as Ia}from"./grid-3x3-CB6J-yDX.js";import{L as Xr}from"./list-CcOCoqUW.js";import{F as Ea}from"./folder-open-nDEnLPQX.js";import{U as Zr}from"./upload-rep3KVPL.js";import{F as $a}from"./filter-DIYm3mPi.js";import{H as bs}from"./hash-jasa6rMo.js";import{I as Qt}from"./image-fQC3p4ps.js";import{V as Ct}from"./video-AMZtj4XD.js";import{M as ws}from"./mail-Dl1RGATy.js";import{S as Ps}from"./square-pen-Wwme7SiP.js";import{C as ei}from"./chart-no-axes-column-increasing-CE8VvCUt.js";import{G as ti}from"./grip-vertical-DtmmqDbO.js";import{S as Oa}from"./share-2-BVJnd9fZ.js";import{f as si}from"./formatDistanceToNow-JmSQUCLK.js";import"./constructNow-CAQUuh76.js";import"./en-US-BOoww7nS.js";import"./differenceInCalendarMonths-CdYt3YUn.js";import"./endOfDay-CTvcx9iE.js";import"./endOfMonth-DMtDxPW7.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ai=Wt("BrainCircuit",[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M9 13a4.5 4.5 0 0 0 3-4",key:"10igwf"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M12 13h4",key:"1ku699"}],["path",{d:"M12 18h6a2 2 0 0 1 2 2v1",key:"105ag5"}],["path",{d:"M12 8h8",key:"1lhi5i"}],["path",{d:"M16 8V5a2 2 0 0 1 2-2",key:"u6izg6"}],["circle",{cx:"16",cy:"13",r:".5",key:"ry7gng"}],["circle",{cx:"18",cy:"3",r:".5",key:"1aiba7"}],["circle",{cx:"20",cy:"21",r:".5",key:"yhc1fs"}],["circle",{cx:"20",cy:"8",r:".5",key:"1e43v0"}]]);/** 7 * @license lucide-react v0.453.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Cs=Wt("CalendarPlus",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M21 13V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8",key:"3spt84"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M16 19h6",key:"xwg31i"}],["path",{d:"M19 16v6",key:"tddt3s"}]]);/** 12 * @license lucide-react v0.453.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const ni=Wt("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/** 17 * @license lucide-react v0.453.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Va=Wt("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);var ri="Toggle",Ls=i.forwardRef((a,c)=>
21{const{pressed:l,defaultPressed:f=!1,onPressedChange:u,...g}=a,[h=!1,F]=Is({prop:l,onChange:u,defaultProp:f});return e.jsx(Ss.button,{type:"button","aria-pressed":h,"data-state":h?"on":"off","data-disabled":a.disabled?"":void 0,...g,ref:c,onClick:ir(a.onClick,()=>{a.disabled||F(!h)})})});Ls.displayName=ri;var Ba=Ls,lt="ToggleGroup",[_a,el]=lr(lt,[Ga]),Ka=Ga(),Ds=he.forwardRef((a,c)=>{const{type:l,...f}=a;if(l==="single"){const u=f;return e.jsx(ii,{...u,ref:c})}if(l==="multiple"){const u=f;return e.jsx(li,{...u,ref:c})}throw new Error(`Missing prop \`type\` expected on \`${lt}\``)});Ds.displayName=lt;var[Qa,Ha]=_a(lt),ii=he.forwardRef((a,c)=>{const{value:l,defaultValue:f,onValueChange:u=()=>{},...g}=a,[h,F]=Is({prop:l,defaultProp:f,onChange:u});return e.jsx(Qa,{scope:a.__scopeToggleGroup,type:"single",value:h?[h]:[],onItemActivate:F,onItemDeactivate:he.useCallback(()=>F(""),[F]),children:e.jsx(Ja,{...g,ref:c})})}),li=he.forwardRef((a,c)=>{const{value:l,defaultValue:f,onValueChange:u=()=>{},...g}=a,[h=[],F]=Is({prop:l,defaultProp:f,onChange:u}),P=he.useCallback(S=>F((V=[])=>[...V,S]),[F]),K=he.useCallback(S=>F((V=[])=>V.filter($=>$!==S)),[F]);return e.jsx(Qa,{scope:a.__scopeToggleGroup,type:"multiple",value:h,onItemActivate:P,onItemDeactivate:K,children:e.jsx(Ja,{...g,ref:c})})});Ds.displayName=lt;var[oi,ci]=_a(lt),Ja=he.forwardRef((a,c)=>{const{__scopeToggleGroup:l,disabled:f=!1,rovingFocus:u=!0,orientation:g,dir:h,loop:F=!0,...P}=a,K=Ka(l),S=or(h),V={role:"group",dir:S,...P};return e.jsx(oi,{scope:l,rovingFocus:u,disabled:f,children:u?e.jsx(cr,{asChild:!0,...K,orientation:g,dir:S,loop:F,children:e.jsx(Ss.div,{...V,ref:c})}):e.jsx(Ss.div,{...V,ref:c})})}),Jt="ToggleGroupItem",Wa=he.forwardRef((a,c)=>{const l=Ha(Jt,a.__scopeToggleGroup),f=ci(Jt,a.__scopeToggleGroup),u=Ka(a.__scopeToggleGroup),g=l.value.includes(a.value),h=f.disabled||a.disabled,F={...a,pressed:g,disabled:h},P=he.useRef(null);return f.rovingFocus?e.jsx(dr,{asChild:!0,...u,focusable:!h,active:g,ref:P,children:e.jsx(La,{...F,ref:c})}):e.jsx(La,{...F,ref:c})});Wa.displayName=Jt;var La=he.forwardRef((a,c)=>{const{__scopeToggleGroup:l,value:f,...u}=a,g=Ha(Jt,l),h={role:"radio","aria-checked":a.pressed,"aria-pressed":void 0},F=g.type==="single"?h:void 0;
21return e.jsx(Ls,{...F,...u,ref:c,onPressedChange:P=>{P?g.onItemActivate(f):g.onItemDeactivate(f)}})}),Ya=Ds,Xa=Wa;const Za=mr("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 gap-2",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3 min-w-10",sm:"h-9 px-2.5 min-w-9",lg:"h-11 px-5 min-w-11"}},defaultVariants:{variant:"default",size:"default"}}),di=i.forwardRef(({className:a,variant:c,size:l,...f},u)=>e.jsx(Ba,{ref:u,className:Es(Za({variant:c,size:l,className:a})),...f}));di.displayName=Ba.displayName;const en=i.createContext({size:"default",variant:"default"}),tn=i.forwardRef(({className:a,variant:c,size:l,children:f,...u},g)=>e.jsx(Ya,{ref:g,className:Es("flex items-center justify-center gap-1",a),...u,children:e.jsx(en.Provider,{value:{variant:c,size:l},children:f})}));tn.displayName=Ya.displayName;const Ht=i.forwardRef(({className:a,children:c,variant:l,size:f,...u},g)=>{const h=i.useContext(en);return e.jsx(Xa,{ref:g,className:Es(Za({variant:h.variant||l,size:h.size||f}),a),...u,children:c})});Ht.displayName=Xa.displayName;function Vt({contentItem:a,onScheduled:c}){var He;const{toast:l}=$s(),f=za(),[u,g]=i.useState(!1),[h,F]=i.useState(""),[P,K]=i.useState("09:00"),[S,V]=i.useState(a.platform||"Facebook"),[$,qe]=i.useState("default"),[B,be]=i.useState("scheduled"),[A,_]=i.useState(""),[ne,q]=i.useState(((He=a.tags)==null?void 0:He.join(", "))||""),[v,re]=i.useState(""),{data:Q}=se({queryKey:["/api/marketing-calendar"],enabled:u}),H=Array.isArray(Q)?Q:(Q==null?void 0:Q.calendars)||[],G=y=>{if(!y)return!1;const pe=new Date(y),we=new Date;return we.setHours(0,0,0,0),pe<we?(re("Date must be today or in the future"),!1):(re(""),!0)},xe=y=>{F(y),G(y)},$e=E({mutationFn:async()=>{if(!G(h))throw new Error("Date must be today or in the future");const y=new Date(`${h}T${P}`);return pr("/api/marketing-calendar/events","POST",{title:a.title,description:A||`Scheduled content: ${a.title}`,scheduledDate:y.toISOString(),platform:S,calendarId:$!=="default"?$:void 0,contentId:a.id,status:B,content:a.content,metadata:{postingNotes:A,hashtags:ne.split(",").map(pe=>pe.trim()).filter(Boolean),targetAudience:a.phase,contentType:a.contentType}})},onSuccess:y=>{f.invalidateQueries({queryKey:["/api/marketing-calendar/events"]}),l({title:"ð
Content Scheduled!",description:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("span",{children:['"',a.title,'" has been added to your marketing calendar']}),e.jsxs("a",{href:"/marketing-calendar",className:"text-orange-600 hover:text-orange-700 underline flex items-center gap-1 text-sm",children:["View in Calendar ",e.jsx(ur,{className:"h-3 w-3"})]})]})}),g(!1),F(""),K("09:00"),_(""),c==null||c(y)},onError:y=>{l({title:"Scheduling Failed",description:y.message||"Failed to schedule content. Please try again.",variant:"destructive"})}}),ie=y=>({Facebook:"15:00",Instagram:"17:00",LinkedIn:"09:00",Twitter:"12:00",TikTok:"18:00"})[y]||"12:00";return he.useEffect(()=>{S&&!P&&K(ie(S))},[S,P]),e.jsxs(Pe,{open:u,onOpenChange:g,children:[e.jsx(hr,{asChild:!0,children:e.jsxs(n,{variant:"outline",size:"sm",className:"flex items-center gap-2","data-testid":"button-schedule-to-calendar",children:[e.jsx(Cs,{className:"h-4 w-4"}),"Schedule to Calendar"]})}),e.jsxs(Fe,{className:"max-w-2xl max-h-[90vh] overflow-y-auto","data-testid":"dialog-schedule-content",children:[e.jsx(Ae,{children:e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(Cs,{className:"h-5 w-5 text-orange-500"}),"Schedule to Marketing Calendar"]})}),e.jsxs("div",{className:"space-y-6 overflow-y-auto flex-1",children:[e.jsxs(N,{children:[e.jsx(fe,{children:e.jsxs(ye,{className:"text-sm flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),"Content Preview"]})}),e.jsx(b,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-semibold",children:a.title}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 line-clamp-3",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[a.aiGenerated&&e.jsxs(C,{variant:"secondary",className:"bg-purple-100 text-purple-800",children:[e.jsx(ze,{className:"h-3 w-3 mr-1"}),"AI Generated"]}),e.jsx(C,{variant:"outline",children:a.category}),e.jsxs(C,{variant:"outline",children:[a.phase," audience"]}),a.quality&&e.jsx(C,{variant:"outline",children:a.quality})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(m,{htmlFor:"date",children:["Scheduled Date ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(L,{id:"date",type:"date",value:h,onChange:y=>xe(y.target.value),min:new Date().toISOString().split("T")[0],"data-testid":"input-schedule-date",className:v?"border-red-500":""}),v&&e.jsxs("p",{className:"text-xs text-red-500 mt-1 flex items-center gap-1",children:[e.jsx(xr,{className:"h-3 w-3"}),v]})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"time",children:"Scheduled Time"}),e.jsx(L,{id:"time",type:"time",value:P,onChange:y=>K(y.target.value),"data-testid":"input-schedule-time"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Optimal time for ",S,": ",ie(S)]})]})]}),H.length>0&&e.jsxs("div",{children:[e.jsx(m,{htmlFor:"calendar",children:"Calendar"}),e.jsxs(W,{value:$,onValueChange:qe,children:[e.jsx(Y,{"data-testid":"select-schedule-calendar",children:e.jsx(X,{placeholder:"Select a calendar"})}),e.jsxs(Z,{children:[e.jsx(p,{value:"default",children:"Default Calendar"}),H.map(y=>e.jsx(p,{value:y.id.toString(),children:y.name||`Calendar ${y.id}`},y.id))]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"platform",children:"Platform"}),e.jsxs(W,{value:S,onValueChange:V,children:[e.jsx(Y,{"data-testid":"select-schedule-platform",children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"Facebook",children:"Facebook"}),e.jsx(p,{value:"Instagram",children:"Instagram"}),e.jsx(p,{value:"LinkedIn",children:"LinkedIn"}),e.jsx(p,{value:"Twitter",children:"Twitter"}),e.jsx(p,{value:"TikTok",children:"TikTok"}),e.jsx(p,{value:"YouTube",children:"YouTube"}),e.jsx(p,{value:"Email",children:"Email"}),e.jsx(p,{value:"Blog",children:"Blog"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"status",children:"Status"}),e.jsxs(W,{value:B,onValueChange:y=>be(y),children:[e.jsx(Y,{children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"draft",children:"Save as Draft"}),e.jsx(p,{value:"scheduled",children:"Schedule for Publishing"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"hashtags",children:"Hashtags"}),e.jsx(L,{id:"hashtags",value:ne,onChange:y=>q(y.target.value),placeholder:"hashtag1, hashtag2, hashtag3"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Separate hashtags with commas"})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"notes",children:"Notes / Description (Optional)"}),e.jsx(Ee,{id:"notes",value:A,onChange:y=>_(y.target.value),placeholder:"Add any special instructions or notes for this post...",rows:3})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t",children:[e.jsx(n,{onClick:()=>$e.mutate(),disabled:$e.isPending||!h||!P||!!v,className:"flex-1 bg-gradient-to-r from-orange-500 to-red-500 hover:from-orange-600 hover:to-red-600","data-testid":"button-confirm-schedule",children:$e.isPending?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin"}),"Scheduling..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),B==="draft"?"Save to Calendar":"Schedule Content"]})}),e.jsx(n,{variant:"outline",onClick:()=>g(!1),children:"Cancel"})]})]})]})]})}const ks=[{id:"alloy",name:"Alloy",gender:"Neutral",description:"Neutral and balanced voice",accent:"American",tone:"Professional"},{id:"echo",name:"Echo",gender:"Male",description:"Male voice with depth",accent:"American",tone:"Authoritative"},{id:"fable",name:"Fable",gender:"Male",description:"British-accented male voice",accent:"British",tone:"Conversational"},{id:"onyx",name:"Onyx",gender:"Male",description:"Deep male voice",accent:"American",tone:"Calm"},{id:"nova",name:"Nova",gender:"Female",description:"Female voice with clarity",accent:"American",tone:"Energetic"}
21,{id:"shimmer",name:"Shimmer",gender:"Female",description:"Soft female voice",accent:"American",tone:"Professional"}],mi=[{value:"tts-1",label:"Standard",description:"Good quality, faster generation"},{value:"tts-1-hd",label:"HD",description:"Best quality, slower generation"}];function hi({open:a,onClose:c,initialText:l="",onSave:f}){const{toast:u}=$s(),g=i.useRef(null),[h,F]=i.useState(l),[P,K]=i.useState("nova"),[S,V]=i.useState(1),[$,qe]=i.useState("tts-1"),[B,be]=i.useState(1),[A,_]=i.useState(!1),[ne,q]=i.useState(!1),[v,re]=i.useState(null),[Q,H]=i.useState(null),[G,xe]=i.useState(0),[$e,ie]=i.useState(0),[He,y]=i.useState(0),[pe,we]=i.useState(!1),[ue,Je]=i.useState("voice-over"),[ot,Yt]=i.useState({}),[U,M]=i.useState({}),[x,D]=i.useState(null),Me=i.useRef({});i.useEffect(()=>{F(l)},[l]),i.useEffect(()=>()=>{v&&URL.revokeObjectURL(v)},[v]),i.useEffect(()=>{g.current&&(g.current.volume=B)},[B]),i.useEffect(()=>{const o=g.current;if(!o)return;const w=()=>{y(o.currentTime),o.duration&&xe(o.currentTime/o.duration*100)},d=()=>{ie(o.duration)},k=()=>{q(!1),xe(0),y(0)};return o.addEventListener("timeupdate",w),o.addEventListener("loadedmetadata",d),o.addEventListener("ended",k),()=>{o.removeEventListener("timeupdate",w),o.removeEventListener("loadedmetadata",d),o.removeEventListener("ended",k)}},[v]);const We=async()=>{if(!h.trim()){u({title:"Text Required",description:"Please enter some text to convert to speech.",variant:"destructive"});return}if(h.length>4096){u({title:"Text Too Long",description:"Text must be 4096 characters or less.",variant:"destructive"});return}_(!0),xe(0);try{const o=await fetch("/api/voice-over/generate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({text:h,voice:P,model:$,speed:S})});if(!o.ok){const k=await o.json();throw new Error(k.message||"Failed to generate voice-over")}const w=await o.blob();H(w),v&&URL.revokeObjectURL(v);const d=URL.createObjectURL(w);re(d),u({title:"Voice-Over Generated!",description:"Your audio has been created successfully."})}catch(o){u({title:"Generation Failed",description:o.message||"Failed to generate voice-over. Please try again.",variant:"destructive"})}finally{_(!1)}},Xt=()=>{!g.current||!v||(ne?(g.current.pause(),q(!1)):(g.current.play(),q(!0)))},kt=()=>{if(!Q)return;const o=URL.createObjectURL(Q),w=document.createElement("a");w.href=o,w.download=`${ue}.mp3`,document.body.appendChild(w),w.click(),document.body.removeChild(w),URL.revokeObjectURL(o),u({title:"Downloaded!",description:"Voice-over saved to your downloads folder."})},Zt=async()=>{if(!Q||!v){u({title:"No Audio",description:"Please generate voice-over first before saving.",variant:"destructive"});return}if(!ue.trim()){u({title:"File Name Required",description:"Please enter a file name before saving.",variant:"destructive"});return}try{const o=new FormData;o.append("audio",Q,`${ue.trim()}.mp3`),o.append("text",h),o.append("voice",P),o.append("metadata",JSON.stringify({voice:P,speed:S,quality:$,duration:$e,voiceDetails:ks.find(k=>k.id===P)})),console.log("Saving to library with data:",{fileName:ue.trim(),text:h.length+" characters",voice:P,quality:$,speed:S,audioSize:Q.size+" bytes"});const w=await fetch("/api/content-library/audio",{method:"POST",credentials:"include",body:o});if(!w.ok){const k=await w.text();throw console.error("Save failed:",w.status,k),new Error(`Failed to save audio: ${w.status}`)}const d=await w.json();console.log("Save successful:",d),f&&f({url:d.url,text:h,voice:P,metadata:d.metadata}),u({title:"Saved to Library!",description:`"${ue.trim()}" has been added to your content library.`})}catch(o){console.error("Library save error:",o),u({title:"Save Failed",description:o.message||"Failed to save audio to library. Please try again.",variant:"destructive"})}},Ye=o=>{const w=Math.floor(o/60),d=Math.floor(o%60);return`${w}:${d.toString().padStart(2,"0")}`},es=async o=>{const w=`${o}-${h.trim()||"sample"}-${$}-${S}`;if(ot[w]||U[o])return w;M(d=>({...d,[o]:!0}));try{const d=h.trim()||"The quick brown fox jumps over the lazy dog",k=await fetch("/api/voice-over/generate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({text:d,voice:o,model:$,speed:S}
21)});if(!k.ok)throw new Error("Failed to generate preview");const Le=await k.blob(),De=URL.createObjectURL(Le);Yt(St=>({...St,[w]:De}));const le=new Audio(De);return le.addEventListener("ended",()=>{D(null)}),Me.current[w]=le,w}catch{return u({title:"Preview Failed",description:"Couldn't generate voice preview. Please try again.",variant:"destructive"}),null}finally{M(d=>({...d,[o]:!1}))}},Xe=async o=>{const w=`${o}-${h.trim()||"sample"}-${$}-${S}`;if(x&&x!==w){const k=Me.current[x];k&&(k.pause(),k.currentTime=0),D(null)}if(!ot[w]){const k=await es(o);if(!k)return;setTimeout(()=>{const Le=Me.current[k];Le&&(Le.currentTime=0,Le.play().then(()=>{D(k)}).catch(De=>{console.error("Error playing preview:",De)}))},100);return}const d=Me.current[w];d&&(x===w?(d.pause(),d.currentTime=0,D(null)):(d.currentTime=0,d.play().then(()=>{D(w)}).catch(k=>{console.error("Error playing preview:",k),u({title:"Playback Error",description:"Could not play audio preview. Please try again.",variant:"destructive"})})))};i.useEffect(()=>()=>{Object.values(ot).forEach(o=>{URL.revokeObjectURL(o)}),Object.values(Me.current).forEach(o=>{o.pause()})},[]);const Oe=ks.find(o=>o.id===P),ct=h.length;return e.jsx(Pe,{open:a,onOpenChange:c,children:e.jsxs(Fe,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(it,{className:"h-5 w-5 text-orange-500"}),"AI Voice-Over Generator"]}),e.jsx(Qe,{children:"Transform your text into professional voice-overs using AI"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 py-4",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"text",children:"Text to Convert"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{id:"text",value:h,onChange:o=>F(o.target.value),placeholder:"Enter the text you want to convert to speech...",className:"min-h-[200px] pr-16",maxLength:4096}),e.jsxs("div",{className:"absolute bottom-2 right-2 text-xs text-gray-500",children:[ct,"/4096"]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Voice Selection"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["Click play to preview: ",h.trim()?"uses your text":"uses sample text",". Click anywhere on a voice card to select it."]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:ks.map(o=>e.jsx(N,{className:`transition-all ${P===o.id?"ring-2 ring-orange-500 bg-orange-50 dark:bg-orange-950":"hover:shadow-md"}`,children:e.jsx(b,{className:"p-3",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1 cursor-pointer",onClick:()=>K(o.id),children:[e.jsx("div",{className:"font-medium",children:o.name}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:[o.gender," ⢠",o.accent]}),e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:o.description})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx(C,{variant:o.tone==="Professional"?"default":"secondary",className:"text-xs",children:o.tone}),e.jsx(n,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0",onClick:w=>{w.stopPropagation(),Xe(o.id)},disabled:U[o.id],title:h.trim()?"Preview with your text":"Preview with sample text",children:U[o.id]?e.jsx(Ne,{className:"h-3 w-3 animate-spin"}):x===`${o.id}-${h.trim()||"sample"}-${$}-${S}`?e.jsx(ka,{className:"h-3 w-3"}):e.jsx(Sa,{className:"h-3 w-3"})})]})]})})},o.id))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(n,{variant:"ghost",size:"sm",onClick:()=>we(!pe),className:"w-full justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Bt,{className:"h-4 w-4"}),"Advanced Settings"]}),e.jsx(qa,{className:`h-4 w-4 transition-transform ${pe?"rotate-90":""}`})]}),pe&&e.jsxs("div",{className:"space-y-4 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg",children:[e.jsxs("div",{children:[e.jsxs(m,{children:["Speed: ",S,"x"]}),e.jsx(Ts,{value:[S],onValueChange:([o])=>V(o),min:.75,max:1.25,step:.25,className:"mt-2"}),e.jsxs("div",{className:"flex justify-between text-xs text-gray-500 mt-1",children:[e.jsx("span",{children:"Slow"}),e.jsx("span",{children:"Normal"}),e.jsx("span",{children:"Fast"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Quality"}),e.jsxs(W,{value:$,onValueChange:qe,children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{})}),e.jsx(Z,{children:mi.map(o=>e.jsx(p,{value:o.value,children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:o.label}),e.jsx("div",{className:"text-xs text-gray-500",children:o.description})]})},o.value))})]})]}),e.jsxs("div",{children:[e.jsx(m,{htmlFor:"filename",children:"File Name"}),e.jsx(L,{id:"filename",value:ue,onChange:o=>Je(o.target.value),placeholder:"voice-over",className:"mt-2"})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"main-filename",children:"File Name"}),e.jsx(L,{id:"main-filename",value:ue,onChange:o=>Je(o.target.value),placeholder:"my-voice-over",className:"mt-2"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Name for download and library"})]}),e.jsx(n,{onClick:We,disabled:A||!h.trim(),className:"w-full bg-orange-500 hover:bg-orange-600",children:A?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Generate Voice-Over"]})}),v&&e.jsx(N,{children:e.jsxs(b,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(Va,{className:"h-3 w-3"}),Oe==null?void 0:Oe.name]}),e.jsxs("span",{className:"text-xs text-gray-500",children:[Ye(He)," / ",Ye($e)]})]}),e.jsx(Ra,{value:G,className:"h-2"}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-4",children:[e.jsx(n,{size:"icon",variant:"outline",onClick:()=>{g.current&&(g.current.currentTime=0,y(0),xe(0))},title:"Restart",children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx(n,{size:"icon",onClick:Xt,className:"bg-orange-500 hover:bg-orange-600",title:"Play/Pause",children:ne?e.jsx(ka,{className:"h-4 w-4"}):e.jsx(Sa,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs(n,{variant:"outline",onClick:kt,className:"flex items-center justify-center gap-2",children:[e.jsx(_t,{className:"h-4 w-4"}),"Download"]}),e.jsxs(n,{onClick:Zt,className:"bg-green-600 hover:bg-green-700 flex items-center justify-center gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"Save to Library"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ua,{className:"h-4 w-4 text-gray-500"}),e.jsx(Ts,{value:[B],onValueChange:([o])=>be(o),min:0,max:1,step:.1,className:"flex-1"})]})]})}),e.jsx(N,{className:"bg-orange-50 dark:bg-orange-950 border-orange-200",children:e.jsxs(b,{className:"p-4",children:[e.jsx("h4",{className:"font-medium text-sm mb-2",children:"Qu
21ick Tips"}),e.jsxs("ul",{className:"text-xs text-gray-600 dark:text-gray-400 space-y-1",children:[e.jsx("li",{children:"⢠Each voice has unique characteristics"}),e.jsx("li",{children:"⢠HD quality provides better audio but takes longer"}),e.jsx("li",{children:"⢠Adjust speed for different content types"}),e.jsx("li",{children:"⢠Save to library for easy reuse"})]})]})})]})]}),e.jsx("audio",{ref:g,src:v||void 0}),e.jsx(Ge,{children:e.jsx(n,{variant:"outline",onClick:c,children:"Close"})})]})})}const Da=[{name:"gray",value:"#6b7280",label:"Gray"},{name:"blue",value:"#3b82f6",label:"Blue"},{name:"green",value:"#22c55e",label:"Green"},{name:"orange",value:"#f97316",label:"Orange"},{name:"red",value:"#ef4444",label:"Red"},{name:"purple",value:"#a855f7",label:"Purple"}],Fs=[{name:"folder",Icon:Os,label:"Folder"},{name:"star",Icon:ce,label:"Star"},{name:"bookmark",Icon:br,label:"Bookmark"},{name:"tag",Icon:wr,label:"Tag"},{name:"archive",Icon:Cr,label:"Archive"},{name:"briefcase",Icon:kr,label:"Briefcase"}],As=a=>{const c=Fs.find(l=>l.name===a);return(c==null?void 0:c.Icon)||Os};function xi({collection:a,isExpanded:c,itemCount:l,collectionItems:f,contentLibrary:u,onToggleExpand:g,onEdit:h,onDelete:F,onRemoveItem:P}){const{attributes:K,listeners:S,setNodeRef:V,transform:$,transition:qe,isDragging:B}=Vr({id:a.id}),be={transform:Br.Transform.toString($),transition:qe,opacity:B?.5:1},A=As(a.icon),_=ne=>u.find(q=>q.id===ne);return e.jsx(N,{ref:V,style:be,className:`transition-shadow ${B?"shadow-lg ring-2 ring-orange-500":""}`,"data-testid":`collection-card-${a.id}`,children:e.jsxs(b,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{...K,...S,className:"cursor-grab hover:bg-gray-100 dark:hover:bg-gray-800 p-1 rounded",children:e.jsx(ti,{className:"h-5 w-5 text-gray-400"})}),e.jsx("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center",style:{backgroundColor:`${a.color}20`},children:e.jsx(A,{className:"h-5 w-5",style:{color:a.color}})}),e.jsxs("div",{className:"cursor-pointer",onClick:g,children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[a.name,e.jsxs(C,{variant:"secondary",className:"text-xs",children:[l," items"]})]}),a.description&&e.jsx("p",{className:"text-sm text-gray-500 line-clamp-1",children:a.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n,{size:"sm",variant:"ghost",onClick:g,children:c?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(rt,{className:"h-4 w-4"})}),e.jsx(n,{size:"sm",variant:"ghost",onClick:h,children:e.jsx(Ps,{className:"h-4 w-4"})}),e.jsxs(Sr,{children:[e.jsx(Tr,{asChild:!0,children:e.jsx(n,{size:"sm",variant:"ghost",className:"text-red-500 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-950",children:e.jsx(Te,{className:"h-4 w-4"})})}),e.jsxs(Pr,{children:[e.jsxs(Fr,{children:[e.jsx(Ar,{children:"Delete Collection"}),e.jsxs(Ir,{children:['Are you sure you want to delete "',a.name,'"? This will not delete the content items inside, only the collection itself.']})]}),e.jsxs(Er,{children:[e.jsx($r,{children:"Cancel"}),e.jsx(Or,{onClick:F,className:"bg-red-500 hover:bg-red-600",children:"Delete"})]})]})]})]})]}),c&&e.jsx("div",{className:"mt-4 pt-4 border-t space-y-2","data-testid":`collection-items-${a.id}`,children:f.length===0?e.jsx("p",{className:"text-sm text-gray-500 text-center py-4",children:"No items in this collection yet"}):f.map(ne=>{const q=_(ne.contentId);return q?e.jsxs("div",{className:"flex items-center justify-between p-2 bg-gray-50 dark:bg-gray-900 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-6 h-6 bg-white dark:bg-gray-800 rounded flex items-center justify-center",children:[q.contentType==="text"&&e.jsx(ae,{className:"h-3 w-3 text-gray-400"}),q.contentType==="image"&&e.jsx(Qt,{className:"h-3 w-3 text-gray-400"}),q.contentType==="video"&&e.jsx(Ct,{className:"h-3 w-3 text-gray-400"})]}),e.jsx("span",{className:"text-sm line-clamp-1",children:q.title})]}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>P(q.id),className:"h-6 w-6 p-0 text-gray-400 hover:text-red-500",children:e.jsx(Ma,{className:"h-3 w-3"})})]},ne.id):null})})]})})}
21function tl(){var oa,ca,da;const{toast:a}=$s(),c=za(),{activeCompanyId:l,isLoading:f}=gr(),[u,g]=i.useState("generate"),[h,F]=i.useState("social-post"),[P,K]=i.useState("grid"),[S,V]=i.useState(""),[$,qe]=i.useState("all"),[B,be]=i.useState(!1),[A,_]=i.useState([]),[ne,q]=i.useState(!1),[v,re]=i.useState(null),[Q,H]=i.useState(!1),[G,xe]=i.useState(null),[$e,ie]=i.useState(!1);i.useState(null),i.useState("all"),i.useState(!1),i.useState(""),i.useState(!1),i.useState(0);const[He,y]=i.useState(!1),[pe,we]=i.useState(!1),[ue,Je]=i.useState(null),[ot,Yt]=i.useState(new Set),[U,M]=i.useState({name:"",description:"",color:"#6b7280",icon:"folder"});i.useState(null),i.useState(null);const[x,D]=i.useState({topic:"",avatarId:"",temperature:"warm",contentType:"educational",tone:"professional",desiredAction:"",instructions:""}),[Me,We]=i.useState(!1),[Xt,kt]=i.useState(""),[Zt,Ye]=i.useState(!1),[es,Xe]=i.useState(!1),[Oe,ct]=i.useState(""),[o,w]=i.useState(""),[d,k]=i.useState({selectedPrompt:"",niche:"",offer:"",platform:"",product:"",audience:"",painPoint1:"",painPoint2:"",painPoint3:"",specificTopic:"",productService:"",additionalContext:""}),[Le,De]=i.useState(!1),[le,St]=i.useState(null),[sn,dt]=i.useState(!1),[Gs,an]=i.useState(!0),[Re,zs]=i.useState(!1),[nn,mt]=i.useState(!1),[J,Ze]=i.useState([]),[Ue,Tt]=i.useState(!1),[rn,Ve]=i.useState(0),[ln,qs]=i.useState(0),[ge,on]=i.useState(3),[je,cn]=i.useState("variation"),[Ms,ht]=i.useState(!1),[R,Pt]=i.useState(null),[dn,xt]=i.useState(!1),[Rs,mn]=i.useState(!1),[pt,Us]=i.useState(null),[Ft,ts]=i.useState(""),[At,ss]=i.useState(!1),[Vs,hn]=i.useState(!1),[ut,Bs]=i.useState(""),[gt,_s]=i.useState(""),[et,Ks]=i.useState([]),[tt,Qs]=i.useState([]),[jt,Hs]=i.useState("all"),[st,Js]=i.useState([]),[It,Ws]=i.useState("createdAt"),[vt,Ys]=i.useState("desc"),xn=[{value:"social-post",label:"Social Post"},{value:"email",label:"Email"},{value:"blog",label:"Blog"},{value:"ad-copy",label:"Ad Copy"},{value:"flyer",label:"Flyer"},{value:"testimonial",label:"Testimonial"},{value:"portfolio",label:"Portfolio"}],pn=[{value:"facebook",label:"Facebook"},{value:"instagram",label:"Instagram"},{value:"linkedin",label:"LinkedIn"},{value:"twitter",label:"Twitter"},{value:"email",label:"Email"},{value:"blog",label:"Blog"},{value:"print",label:"Print"}],un=[{value:"all",label:"All"},{value:"draft",label:"Draft"},{value:"published",label:"Published"},{value:"scheduled",label:"Scheduled"}],as=[ut,gt,et.length>0,tt.length>
210,jt!=="all",st.length>0,It!=="createdAt",vt!=="desc"].filter(Boolean).length,gn=()=>{Bs(""),_s(""),Ks([]),Qs([]),Hs("all"),Js([]),Ws("createdAt"),Ys("desc")},jn=t=>{Ks(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])},vn=t=>{Qs(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])},fn=t=>{Js(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])},{data:Xs,isLoading:yn}=se({queryKey:["/api/content-library/items",l,S,$,ut,gt,et,tt,jt,st,It,vt],queryFn:async()=>{const t=new URLSearchParams;S&&t.append("search",S),$!=="all"&&t.append("category",$),ut&&t.append("dateFrom",ut),gt&&t.append("dateTo",gt),et.length>0&&t.append("contentType",et.join(",")),tt.length>0&&t.append("platform",tt.join(",")),jt!=="all"&&t.append("status",jt),st.length>0&&t.append("tags",st.join(",")),t.append("sortBy",It),t.append("sortOrder",vt),t.append("limit","50");const s=await fetch(`/api/content-library/items?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch content");return s.json()}}),Zs=Array.from(new Set((Xs||[]).flatMap(t=>t.tags||[]))).filter(Boolean),{data:ns,isLoading:Nn}=se({queryKey:["/api/content-templates",l],queryFn:async()=>{const t=await fetch("/api/content-templates",{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch templates");return t.json()}});se({queryKey:["/api/ai-training/documents",l],queryFn:async()=>{const t=await fetch("/api/ai-training/documents",{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch training documents");return t.json()}});const Et={totalContent:0,generatedToday:0,templatesCount:7,aiTrainingPercentage:0},{data:bn=Et,isLoading:$t,isError:wn}=se({queryKey:["/api/content-library/stats",l],queryFn:async()=>{try{const t=await fetch("/api/content-library/stats",{credentials:"include"});return t.ok?await t.json():Et}catch(t){return console.warn("Failed to fetch content stats, using defaults:",t),Et}},retry:1,staleTime:6e4,throwOnError:!1}),Ot=wn?Et:bn,{data:ft,isLoading:Cn}=se({queryKey:["/api/avatars",{companyId:l??null}],queryFn:async()=>{const t=await fetch("/api/avatars",{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch avatars");return t.json()},enabled:!f}),{data:ee,isLoading:pi}=se({queryKey:["/api/competitors",l],queryFn:async()=>{const t=new URLSearchParams;l&&t.append("companyId",l.toString());const s=await fetch(`/api/competitors?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch competitors");return s.json()},enabled:!f}),I=ee==null?void 0:ee.find(t=>t.id===pt),kn=E({mutationFn:async({websiteUrl:t,competitorId:s})=>{const r=await fetch("/api/competitors/analyze",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({websiteUrl:t,competitorId:s,companyId:l})});if(!r.ok)throw new Error("Failed to analyze competitor");return r.json()},onSuccess:t=>{var s;ss(!1),a({title:"Analysis Complete",description:"Competitor website has been analyzed successfully."}),c.invalidateQueries({queryKey:["/api/competitors",l]}),(s=t.competitor)!=null&&s.id&&Us(t.competitor.id),ts("")},onError:t=>{ss(!1),a({title:"Analysis Failed",description:t.message||"Failed to analyze competitor website.",variant:"destructive"})}}),Sn=()=>{if(!I)return;const t=I.toneProfile||{},s=t.contentThemes||[],r=t.commonPhrases||[],j=t.writingStyle||"professional",T=t.formalityLevel||"mixed";let z=`Match competitor's ${T} tone with ${j} writing style.`;s.length>0&&(z+=` Focus on themes: ${s.slice(0,3).join(", ")}.`),r.length>0&&(z+=` Consider using phrases like: ${r.slice(0,3).join(", ")}.`);const ve={formal:"professional",casual:"casual",mixed:"friendly"};D(Se=>({...Se,tone:ve[T]||"professional",instructions:Se.instructions?`${Se.instructions} 22 23${z}`:z})),a({title:"Competitor Style Applied",description:"Generation settings updated with competitor insights."})},ea=()=>{if(!Ft.trim()){a({title:"URL Required",description:"Please enter a website URL to analyze.",variant:"destructive"});return}ss(!0),kn.mutate({websiteUrl:Ft.trim(),competitorId:pt||void 0})},{data:rs,isLoading:Tn}=se({queryKey:["/api/content-studio/presets",l],queryFn:async()=>{const t=new URLSearchParams;l&&t.append("companyId",l.toString());
23const s=await fetch(`/api/content-studio/presets?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch presets");return s.json()},enabled:!f}),{data:Ce,isLoading:Pn}=se({queryKey:["/api/content-studio/history",l],queryFn:async()=>{const t=new URLSearchParams;l&&t.append("companyId",l.toString()),t.append("limit","10");const s=await fetch(`/api/content-studio/history?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch generation history");return s.json()},enabled:!f}),{data:Lt,isLoading:Fn}=se({queryKey:["/api/content-studio/favorites",l],queryFn:async()=>{const t=new URLSearchParams;l&&t.append("companyId",l.toString());const s=await fetch(`/api/content-studio/favorites?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch favorites");return s.json()},enabled:!f}),ke=t=>Lt?Lt.some(s=>s.templateId===t):!1,An=E({mutationFn:async t=>{const s=await fetch("/api/content-studio/favorites",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({templateId:t,companyId:l})});if(!s.ok)throw new Error("Failed to add favorite");return s.json()},onMutate:async t=>{await c.cancelQueries({queryKey:["/api/content-studio/favorites",l]});const s=c.getQueryData(["/api/content-studio/favorites",l]);return c.setQueryData(["/api/content-studio/favorites",l],r=>[...r||[],{templateId:t,companyId:l,createdAt:new Date().toISOString()}]),{previousFavorites:s}},onSuccess:()=>{a({title:"Added to Favorites",description:"Template has been added to your favorites."})},onError:(t,s,r)=>{c.setQueryData(["/api/content-studio/favorites",l],r==null?void 0:r.previousFavorites),a({title:"Failed to Add Favorite",description:t.message||"Could not add template to favorites. Please try again.",variant:"destructive"})},onSettled:()=>{c.invalidateQueries({queryKey:["/api/content-studio/favorites",l]})}}),In=E({mutationFn:async t=>{const s=new URLSearchParams;l&&s.append("companyId",l.toString());const r=await fetch(`/api/content-studio/favorites/${t}?${s}`,{method:"DELETE",credentials:"include"});if(!r.ok)throw new Error("Failed to remove favorite");return r.json()},onMutate:async t=>{await c.cancelQueries({queryKey:["/api/content-studio/favorites",l]});const s=c.getQueryData(["/api/content-studio/favorites",l]);return c.setQueryData(["/api/content-studio/favorites",l],r=>(r||[]).filter(j=>j.templateId!==t)),{previousFavorites:s}},onSuccess:()=>{a({title:"Removed from Favorites",description:"Template has been removed from your favorites."})},onError:(t,s,r)=>{c.setQueryData(["/api/content-studio/favorites",l],r==null?void 0:r.previousFavorites),a({title:"Failed to Remove Favorite",description:t.message||"Could not remove template from favorites. Please try again.",variant:"destructive"})},onSettled:()=>{c.invalidateQueries({queryKey:["/api/content-studio/favorites",l]})}}),{data:O,isLoading:En}=se({queryKey:["/api/content-studio/collections",l],queryFn:async()=>{const t=new URLSearchParams;l&&t.append("companyId",l.toString());const s=await fetch(`/api/content-studio/collections?${t}`,{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch collections");return s.json()},enabled:!f}),{data:at}=se({queryKey:["/api/content-studio/collection-items",l,O==null?void 0:O.map(t=>t.id)],queryFn:async()=>{if(!O||O.length===0)return{};const t={};return await Promise.all(O.map(async s=>{const r=await fetch(`/api/content-studio/collections/${s.id}/items`,{credentials:"include"});r.ok?t[s.id]=await r.json():t[s.id]=[]})),t},enabled:!f&&!!O&&O.length>0}),is=E({mutationFn:async t=>{const s=await fetch("/api/content-studio/collections",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({...t,companyId:l})});if(!s.ok)throw new Error("Failed to create collection");return s.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collections",l]}),y(!1),M({name:"",description:"",color:"#6b7280",icon:"folder"}),a({title:"Collection Created",description:"Your new collection has been created successfully."})},onError:t=>{a({title:"Failed to Create Collection",description:t.message||"Could not create collection. Please try again.",variant:"destructive"})}}),ls=E({mutationFn:async({id:t,...s})=>{const r=await fetch(`/api/content-studio/collections/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(s)});if(!r.ok)throw new Error("Failed to update collection");return r.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collections",l]}),we(!1),Je(null),a({title:"Collection Updated",description:"Collection has been updated successfully."})},onError:t=>{a({title:"Failed to Update Collection",description:t.message||"Could not update collection. Please try again.",variant:"destructive"})}}),$n=E({mutationFn:async t=>{const s=await fetch(`/api/content-studio/collections/${t}`,{method:"DELETE",credentials:"include"});if(!s.ok)throw new Error("Failed to delete collection");return s.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collections",l]}),a({title:"Collection Deleted",description:"Collection has been deleted successfully."})},onError:t=>{a({title:"Failed to Delete Collection",description:t.message||"Could not delete collection. Please try again.",variant:"destructive"})}}),On=E({mutationFn:async({collectionId:t,contentId:s})=>{const r=await fetch(`/api/content-studio/collections/${t}/items`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({contentId:s})});if(!r.ok)throw new Error("Failed to add item to collection");return r.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collection-items",l]}
23),a({title:"Item Added",description:"Content has been added to the collection."})},onError:t=>{a({title:"Failed to Add Item",description:t.message||"Could not add item to collection. Please try again.",variant:"destructive"})}}),Ln=E({mutationFn:async({collectionId:t,contentId:s})=>{const r=await fetch(`/api/content-studio/collections/${t}/items/${s}`,{method:"DELETE",credentials:"include"});if(!r.ok)throw new Error("Failed to remove item from collection");return r.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collection-items",l]}),a({title:"Item Removed",description:"Content has been removed from the collection."})},onError:t=>{a({title:"Failed to Remove Item",description:t.message||"Could not remove item from collection. Please try again.",variant:"destructive"})}}),Dn=E({mutationFn:async({order:t})=>{const s=await fetch("/api/content-studio/collections/reorder",{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({order:t,companyId:l})});if(!s.ok)throw new Error("Failed to reorder collections");return s.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["/api/content-studio/collections",l]})},onError:t=>{a({title:"Failed to Reorder",description:t.message||"Could not reorder collections. Please try again.",variant:"destructive"})}}),Gn=zr(Ta(Qr,{activationConstraint:{distance:5}}),Ta(Kr,{coordinateGetter:_r})),zn=t=>{const{active:s,over:r}=t;if(r&&s.id!==r.id&&O){const j=O.findIndex(z=>z.id===s.id),T=O.findIndex(z=>z.id===r.id);if(j!==-1&&T!==-1){const z=Hr(O,j,T).map(ve=>ve.id);Dn.mutate({order:z})}}},qn=t=>{Yt(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},Mn=t=>{var s;return((s=at==null?void 0:at[t])==null?void 0:s.length)||0},Dt=t=>{ke(t)?In.mutate(t):An.mutate(t)},ta=E({mutationFn:async t=>{const s=await fetch(`/api/content-studio/history/${t}`,{method:"DELETE",credentials:"include"});if(!s.ok)throw new Error("Failed to delete history entry");return s.json()},onSuccess:()=>{a({title:"Deleted",description:"History entry has been removed."}),c.invalidateQueries({queryKey:["/api/content-studio/history",l]})},onError:t=>{a({title:"Delete Failed",description:t.message||"Failed to delete history entry. Please try again.",variant:"destructive"})}}),os=E({mutationFn:async()=>{const s=(Ce||[]).map(r=>fetch(`/api/content-studio/history/${r.id}`,{method:"DELETE",credentials:"include"}));return await Promise.all(s),{success:!0}},onSuccess:()=>{a({title:"History Cleared",description:"All generation history has been removed."}),c.invalidateQueries({queryKey:["/api/content-studio/history",l]})},onError:t=>{a({title:"Clear Failed",description:"Failed to clear history. Please try again.",variant:"destructive"})}}),Rn=t=>{const s=t.requestPayload||{};D({topic:s.topic||"",avatarId:s.avatarId||"",temperature:s.temperature||"warm",contentType:s.contentType||"educational",tone:s.tone||"professional",desiredAction:s.desiredAction||s.customInstructions||"",instructions:s.customInstructions||""}),a({title:"Settings Loaded",description:"Previous generation settings have been applied to the form."})},cs=E({mutationFn:async t=>{const s=await fetch("/api/content-studio/presets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({name:t.name,description:t.description,config:t.config,companyId:l})});if(!s.ok)throw new Error("Failed to create preset");return s.json()},onSuccess:()=>{a({title:"Preset Saved",description:"Your generation settings have been saved as a preset."}),c.invalidateQueries({queryKey:["/api/content-studio/presets",l]}),Xe(!1),ct(""),w("")},onError:t=>{a({title:"Save Failed",description:t.message||"Failed to save preset. Please try again.",variant:"destructive"})}}),sa=E({mutationFn:async t=>{const s=await fetch(`/api/content-studio/presets/${t}`,{method:"DELETE",credentials:"include"});if(!s.ok)throw new Error("Failed to delete preset");return s.json()},onSuccess:()=>{a({title:"Preset Deleted",description:"The preset has been removed."}
23),c.invalidateQueries({queryKey:["/api/content-studio/presets",l]})},onError:t=>{a({title:"Delete Failed",description:t.message||"Failed to delete preset. Please try again.",variant:"destructive"})}}),aa=E({mutationFn:async t=>{const s=await fetch(`/api/content-studio/presets/${t}/set-default`,{method:"POST",credentials:"include"});if(!s.ok)throw new Error("Failed to set default preset");return s.json()},onSuccess:()=>{a({title:"Default Preset Updated",description:"This preset is now your default."}),c.invalidateQueries({queryKey:["/api/content-studio/presets",l]})},onError:t=>{a({title:"Update Failed",description:t.message||"Failed to set default. Please try again.",variant:"destructive"})}}),Un=t=>{const s=t.config||{};D({topic:s.topic||"",avatarId:s.avatarId||"",temperature:s.temperature||"warm",contentType:s.contentType||"educational",tone:s.tone||"professional",desiredAction:s.desiredAction||s.customInstructions||"",instructions:s.customInstructions||""}),Ye(!1),a({title:"Preset Loaded",description:`"${t.name}" settings have been applied.`})},Vn=()=>{if(!Oe.trim()){a({title:"Name Required",description:"Please enter a name for your preset.",variant:"destructive"});return}cs.mutate({name:Oe.trim(),description:o.trim()||void 0,config:{topic:x.topic,avatarId:x.avatarId,temperature:x.temperature,contentType:x.contentType,tone:x.tone,desiredAction:x.desiredAction,customInstructions:x.instructions}})},Bn=E({mutationFn:async t=>{const s=await fetch("/api/content-studio/bulk-generate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({...t,companyId:l})});if(!s.ok){const r=await s.json();throw new Error(r.error||"Failed to bulk generate content")}return s.json()},onSuccess:t=>{var s;Tt(!1),Ve(100),Ze(t.variants||[]),ht(!0),a({title:"Bulk Generation Complete",description:`Successfully generated ${((s=t.variants)==null?void 0:s.length)||0} content variants.`}),c.invalidateQueries({queryKey:["/api/content-studio/history",l]})},onError:t=>{Tt(!1),Ve(0),a({title:"Bulk Generation Failed",description:t.message||"Failed to generate content variants. Please try again.",variant:"destructive"})}}),_n=()=>
23{if(!x.topic.trim()){a({title:"Topic Required",description:"Please enter a topic for content generation.",variant:"destructive"});return}Tt(!0),Ve(0),Ze([]),ht(!1),qs(0);const t=setInterval(()=>{Ve(s=>s>=90?(clearInterval(t),90):s+90/(ge*3)),qs(s=>Math.min(s+1,ge))},1e3);Bn.mutate({contentType:h,topic:x.topic,avatarId:x.avatarId||void 0,temperature:x.temperature,tone:x.tone,desiredAction:x.desiredAction||void 0,instructions:x.instructions||void 0,variantCount:ge,variantMode:je})},Kn=()=>{Tt(!1),Ve(0),Ze([])},ds=t=>{xe({content:t.output,topic:x.topic,tone:x.tone,contentType:h,metrics:t.metrics}),ie(!0),mt(!1),a({title:"Variant Applied",description:`${t.variantLabel} has been applied to the generated content area.`})},na=async()=>{try{for(const t of J)await fetch("/api/content-library/items",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({title:`${x.topic} - ${t.variantLabel}`,content:t.output,contentType:"text",category:h,tags:[je==="variation"?"variation":"ab-test",t.variantLabel.toLowerCase().replace(" ","-")],companyId:l})});a({title:"Variants Saved",description:`All ${J.length} variants have been saved to your library.`}),c.invalidateQueries({queryKey:["/api/content-library/items",l]})}catch{a({title:"Save Failed",description:"Failed to save variants to library. Please try again.",variant:"destructive"})}},yt=[{key:"approach-1",label:"Benefits Focus",description:"Emphasizes positive outcomes and value"},{key:"approach-2",label:"Features Focus",description:"Highlights specific details and capabilities"},{key:"approach-3",label:"Urgency Focus",description:"Creates sense of scarcity and time-sensitivity"},{key:"approach-4",label:"Social Proof",description:"Leads with testimonials and credibility"},{key:"approach-5",label:"Problem-Solution",description:"Addresses pain points directly"}],ra=[{bg:"bg-orange-500",text:"text-orange-500",border:"border-orange-500",headerBg:"bg-orange-50 dark:bg-orange-950/30"},{bg:"bg-blue-500",text:"text-blue-500",border:"border-blue-500",headerBg:"bg-blue-50 dark:bg-blue-950/30"},{bg:"bg-green-500",text:"text-green-500",border:"border-green-500",headerBg:"bg-green-50 dark:bg-green-950/30"},{bg:"bg-purple-500",text:"text-purple-500",border:"border-purple-500",headerBg:"bg-purple-50 dark:bg-purple-950/30"},{bg:"bg-pink-500",text:"text-pink-500",border:"border-pink-500",headerBg:"bg-pink-50 dark:bg-pink-950/30"}],Qn=t=>ra[t%ra.length],Hn=()=>{if(J.length===0)return;const t=J.map((T,z)=>{var Se,ma,ha,xa;const ve=je==="ab-test"?yt[z]:null;return` 24======================================== 25VARIANT ${String.fromCharCode(65+z)}: ${T.variantLabel} 26======================================== 27${ve?`Approach: ${ve.label} 28${ve.description} 29`:""} 30Metrics: 31- Word Count: ${((Se=T.metrics)==null?void 0:Se.wordCount)||"N/A"} 32- Character Count: ${((ma=T.metrics)==null?void 0:ma.charCount)||"N/A"} 33- Sentence Count: ${((ha=T.metrics)==null?void 0:ha.sentenceCount)||"N/A"} 34- Readability Score: ${((xa=T.metrics)==null?void 0:xa.readability)||"N/A"} 35 36Content: 37${T.output} 38 `.trim()}).join(` 39 40`),s=new Blob([t],{type:"text/plain"}),r=URL.createObjectURL(s),j=document.createElement("a");j.href=r,j.download=`content-variants-${new Date().toISOString().split("T")[0]}.txt`,document.body.appendChild(j),j.click(),document.body.removeChild(j),URL.revokeObjectURL(r),a({title:"Variants Exported",description:`${J.length} variants have been exported to a text file.`})},Jn=(t,s)=>{ds(t),xt(!1),a({title:`Variant ${String.fromCharCode(65+s)} Selected`,description:`${t.variantLabel} has been applied to the generated content area.`})},Wn=()=>{xt(!1),Ze([]),ht(!1),mt(!0)},Gt=Xs||[],Yn=[{value:"all",label:"All Content",icon:Ia},{value:"social",label:"Social Media",icon:Oa},{value:"email",label:"Email Campaigns",icon:ws},{value:"blog",label:"Blog Posts",icon:fs},{value:"flyer",label:"Flyers & Print",icon:ae},{value:"ads",label:"Advertisements",icon:gs},{value:"portfolio",label:"Portfolio",icon:Qt},{value:"testimonial",label:"Testimonials",icon:ce}],Xn=[{id:"social-post",name:"Social Media Post",icon:Oa,description:"Engaging posts for Facebook, Instagram, LinkedIn",color:"bg-blue-500"},{id:"email-campaign",name:"Email Campaign",icon:ws,description:"Professional email templates for marketing",color:"bg-purple-500"},{id:"blog-article",name:"Blog Article",icon:fs,description:"SEO-optimized blog posts and articles",color:"bg-green-500"},{id:"flyer",name:"Flyer / Print Ad",icon:ae,description:"Professional flyer and print advertising content",color:"bg-teal-500"},{id:"ad-copy",name:"Ad Copy",icon:gs,description:"Compelling advertisements for Google, Facebook",color:"bg-red-500"},{id:"testimonial",name:"Testimonial Request",icon:ce,description:"Templates to request customer reviews",color:"bg-yellow-500"},{id:"landing-page",name:"Landing Page Copy",icon:ua,description:"Conversion-focused website content",color:"bg-indigo-500"}],zt=E({mutationFn:async()=>{be(!0);const t=await fetch("/api/content-library/generate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({contentType:x.contentType,topic:x.topic,avatarId:x.avatarId,temperature:x.temperature,tone:x.tone,desiredAction:x.desiredAction,instructions:x.instructions,platform:ia(h)})});if(!t.ok)throw new Error("Failed to generate content");return t.json()},onSuccess:t=>
40{be(!1),xe({id:t.id||0,title:t.title||"New Generated Content",content:t.content||"",contentType:x.contentType||"social-post",platform:ia(h)||"Facebook",phase:"awareness",tags:t.tags||[],status:"draft",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),userId:t.userId}),ie(!0),a({title:"ð Content Generated Successfully!",description:"Your AI-powered content is ready to review, save, and schedule."}),c.invalidateQueries({queryKey:["/api/content-library/items",l]}),c.invalidateQueries({queryKey:["/api/content-studio/history",l]})},onError:t=>{be(!1),a({title:"Generation Failed",description:t.message||"Failed to generate content. Please try again.",variant:"destructive"})}}),Zn=E({mutationFn:async()=>{De(!0);const s={lead_magnet:`Create a unique lead magnet idea for ${d.niche||"[niche]"} that I can use to generate high-quality leads for my ${d.offer||"[specific offer]"}.`,offer_optimizer:`Rewrite this offer to be more irresistible and increase perceived value, focusing on these three pain points: ${d.painPoint1||"[pain point 1]"}, ${d.painPoint2||"[pain point 2]"}, and ${d.painPoint3||"[pain point 3]"}.`,workflow_creator:`Create a step-by-step automation workflow for nurturing leads from ${d.platform||"[platform]"} to a booked call.`,ad_copy_creator:`Write an engaging, high-converting Facebook ad for a ${d.product||"[product]"} targeting ${d.audience||"[audience]"}. Include pain points, objections, and a powerful call to action.`,market_research:`Create a market research report on the current trends in ${d.niche||"[niche]"} with a focus on ${d.specificTopic||"[specific topic]"}, pulling insights from top competitors and social media.`,email_sequence:`Generate an email sequence for onboarding new customers, emphasizing value and setting expectations for ${d.productService||"[product/service]"}.`,content_ideas:`Create a list of 10 new content ideas for ${d.niche||"[niche]"}, with angles that will resonate with my audience's current concerns.`}[d.selectedPrompt],r=d.additionalContext?`${s} 41 42Additional Context: ${d.additionalContext}`:s,j=await fetch("/api/content-library/generate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({contentType:"improvement",topic:r,avatarId:x.avatarId,temperature:"warm",tone:"professional",desiredAction:"improve_content",instructions:`This is a content improvement request using the ${d.selectedPrompt} prompt template.`,platform:"Content Improvement",promptType:d.selectedPrompt})});if(!j.ok)throw new Error("Failed to generate improved content");return j.json()},onSuccess:t=>{De(!1),St({id:t.id||0,title:t.title||"Improved Content",content:t.content||"",contentType:"improvement",platform:"Content Improvement",phase:"warm",tags:t.tags||[],status:"draft",createdAt:new Date().toISOString(),promptType:d.selectedPrompt}
42),dt(!0),a({title:"ð Content Improved Successfully!",description:"Your AI-enhanced content is ready to review, copy, or schedule."}),c.invalidateQueries({queryKey:["/api/content-library/items",l]}),c.invalidateQueries({queryKey:["/api/content-library/stats",l]})},onError:t=>{De(!1),a({title:"Generation Failed",description:t.message||"Failed to generate improved content. Please try again.",variant:"destructive"})}}),ia=t=>({"social-post":"Facebook","email-campaign":"Email","blog-article":"Blog",flyer:"Print","ad-copy":"Google Ads",testimonial:"Reviews","landing-page":"Website"})[t]||"General",er=async()=>{if(!x.topic.trim()){a({title:"Topic Required",description:"Please enter a topic or business context for content generation.",variant:"destructive"});return}ie(!1),xe(null),zt.mutate()},tr=E({mutationFn:async t=>{const s=await fetch(`/api/content-library/items/${t}`,{method:"DELETE",credentials:"include"});if(!s.ok)throw new Error("Failed to delete content");return s.json()},onSuccess:()=>{a({title:"Content Deleted",description:"The content has been removed from your library."}),c.invalidateQueries({queryKey:["/api/content-library/items",l]})},onError:t=>{a({title:"Delete Failed",description:"Failed to delete content. Please try again.",variant:"destructive"})}}),qt=t=>{tr.mutate(t)},sr=E({mutationFn:async t=>{const s=await fetch("/api/content-library/bulk",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({action:"delete",itemIds:t})});if(!s.ok)throw new Error("Failed to delete items");return s.json()},onSuccess:()=>{a({title:"Items Deleted",description:`${A.length} items have been removed from your library.`}),_([]),q(!1),c.invalidateQueries({queryKey:["/api/content-library/items",l]})},onError:t=>{a({title:"Bulk Delete Failed",description:"Failed to delete selected items. Please try again.",variant:"destructive"})}});E({mutationFn:async({itemIds:t,folderId:s})=>{const r=await fetch("/api/content-library/bulk",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({action:"move",itemIds:t,folderId:s})});if(!r.ok)throw new Error("Failed to move items");return r.json()},onSuccess:()=>{a({title:"Items Moved",description:`${A.length} items have been moved successfully.`}),_([]),c.invalidateQueries({queryKey:["/api/content-library/items",l]})},onError:t=>{a({title:"Move Failed",description:"Failed to move selected items. Please try again.",variant:"destructive"})}}),E({mutationFn:async({itemIds:t,tags:s})=>{const r=await fetch("/api/content-library/bulk",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({action:"tag",itemIds:t,tags:s})});if(!r.ok)throw new Error("Failed to add tags");return r.json()},onSuccess:()=>{a({title:"Tags Added",description:`Tags have been added to ${A.length} items.`}),_([]),c.invalidateQueries({queryKey:["/api/content-library/items",l]})},onError:t=>{a({title:"Tag Failed",description:"Failed to add tags to selected items. Please try again.",variant:"destructive"})}});const la=t=>{_(s=>s.includes(t)?s.filter(r=>r!==t):[...s,t])},ar=()=>{A.length===oe.length?_([]):_(oe.map(t=>t.id))},nr=()=>{A.length!==0&&sr.mutate(A)},Nt=t=>{navigator.clipboard.writeText(t),a({title:"Copied!",description:"Content has been copied to clipboard."})},rr=()=>{const t=oe.map(T=>({title:T.title,content:T.content,category:T.category,tags:T.tags,createdAt:T.createdAt})),s=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),r=URL.createObjectURL(s),j=document.createElement("a");j.href=r,j.download=`content-library-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(j),j.click(),document.body.removeChild(j),URL.revokeObjectURL(r),a({title:"Exported!",description:`${oe.length} items exported successfully.`})};i.useCallback(async t=>{const s=new FormData;Array.from(t).forEach(r=>{s.append("documents",r)});try{const r=await fetch("/api/ai-training/upload",{method:"POST",body:s,credentials:"include"});if(!r.ok)throw new Error("Upload failed");const j=await r.json();a({title:"Documents Uploaded",description:`Successfully uploaded ${j.count} document(s) for AI training.`}),c.invalidateQueries({queryKey:["/api/ai-training/documents"]})}catch{a({title:"Upload Failed",description:"Failed to upload documents. Please try again.",variant:"destructive"})}},[a,c]);const oe=Gt;return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(ze,{className:"h-8 w-8 text-orange-500"}),"Content Studio"]}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-1",children:"Generate, manage, and optimize all your marketing content in one place"})]})}),e.jsxs(Lr,{value:u,onValueChange:g,className:"space-y-6",children:[e.jsxs(Dr,{className:"grid grid-cols-5 w-full max-w-4xl",children:[e.jsxs(bt,{value:"generate",className:"flex flex-col sm:flex-row items-center gap-1 sm:gap-2 py-2","data-testid":"tab-generate",children:[e.jsx(Pa,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[10px] sm:text-sm",children:"Generate"})]}),e.jsxs(bt,{value:"improve",className:"flex flex-col sm:flex-row items-center gap-1 sm:gap-2 py-2","data-testid":"tab-improve",children:[e.jsx(ys,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[10px] sm:text-sm",children:"Improve"})]}),e.jsxs(bt,{value:"library",className:"flex flex-col sm:flex-row items-center gap-1 sm:gap-2 py-2","data-testid":"tab-library",children:[e.jsx(Mt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[10px] sm:text-sm",children:"Library"})]}),e.jsxs(bt,{value:"templates",className:"flex flex-col sm:flex-row items-center gap-1 sm:gap-2 py-2","data-testid":"tab-templates",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[10px] sm:text-sm",children:"Templates"})]}),e.jsxs(bt,{value:"voiceover",className:"flex flex-col sm:flex-row items-center gap-1 sm:gap-2 py-2","data-testid":"tab-voiceover",children:[e.jsx(it,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[10px] sm:text-sm",children:"Voice-Over"})]})]}),e.jsx(wt,{value:"generate",className:"space-y-6",children:e.jsxs(N,{children:[e.jsxs(fe,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(Pa,{className:"h-5 w-5"}),"AI Content Generator"]}),e.jsx(Be,{children:"Choose a content type and let AI create professional marketing content instantly"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Xn.map(t=>{const s=t.icon;
42return e.jsx(N,{className:`cursor-pointer transition-all hover:shadow-lg ${h===t.id?"ring-2 ring-orange-500":""}`,onClick:()=>F(t.id),children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t.color} text-white`,children:e.jsx(s,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium",children:t.name}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t.description})]}),h===t.id&&e.jsx(te,{className:"h-5 w-5 text-orange-500"})]})})},t.id)})}),e.jsxs("div",{className:"space-y-4 border-t pt-6",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Topic or Business Context"}),e.jsx(Ee,{placeholder:"E.g., Spring cleaning special offer for residential homes...",className:"mt-2",rows:3,value:x.topic,onChange:t=>D(s=>({...s,topic:t.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Target Audience (Avatar)"}),e.jsxs(W,{value:x.avatarId,onValueChange:t=>D(s=>({...s,avatarId:t})),children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{placeholder:"Select a client avatar"})}),e.jsx(Z,{children:ft&&ft.length>0?ft.map(t=>e.jsxs(p,{value:t.id.toString(),children:[t.name," - ",t.description||"Customer Profile"]},t.id)):e.jsx(p,{value:"general",children:"General Audience"})})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Temperature Level"}),e.jsxs(W,{value:x.temperature,onValueChange:t=>D(s=>({...s,temperature:t})),children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"cold",children:"ð§ Cold - Service Unaware"}),e.jsx(p,{value:"warm",children:"ð¥ Warm - Provider Unaware"}),e.jsx(p,{value:"hot",children:"ð Hot - Existing Customer"})]})]})]})]}),e.jsx(ms,{open:Rs,onOpenChange:mn,"data-testid":"section-competitor-insights",children:e.jsxs("div",{className:"border rounded-lg p-4 bg-muted/30",children:[e.jsx(hs,{asChild:!0,children:e.jsxs("div",{className:"flex items-center justify-between cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pa,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Competitor Insights"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:(ee==null?void 0:ee.length)>0?`${ee.length} competitor${ee.length!==1?"s":""} analyzed`:"No competitors yet"}),Rs?e.jsx(rt,{className:"h-4 w-4"}):e.jsx(qa,{className:"h-4 w-4"})]})]})}),e.jsxs(xs,{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Select Competitor"}),(ee==null?void 0:ee.length)>0?e.jsxs(W,{value:(pt==null?void 0:pt.toString())||"",onValueChange:t=>Us(t?parseInt(t):null),"data-testid":"select-competitor",children:[e.jsx(Y,{children:e.jsx(X,{placeholder:"Choose a competitor to analyze..."})}),e.jsx(Z,{children:ee.map(t=>e.jsxs(p,{value:t.id.toString(),children:[t.name," ",t.website&&`(${t.website})`]},t.id))})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"No competitors added yet."}),e.jsx(jr,{href:"/market-research",children:e.jsxs(n,{variant:"outline",size:"sm",children:[e.jsx(nt,{className:"h-4 w-4 mr-1"}),"Add Competitor"]})})]})]}),I&&e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:I.name}),I.website&&e.jsxs("a",{href:I.website.startsWith("http")?I.website:`https://${I.website}`,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-500 hover:underline flex items-center gap-1",children:[e.jsx(ua,{className:"h-3 w-3"}),I.website]})]}),e.jsxs(n,{onClick:Sn,size:"sm",disabled:!I.toneProfile,"data-testid":"button-apply-competitor-style",children:[e.jsx(ze,{className:"h-4 w-4 mr-1"}),"Apply Style"]})]}),I.toneProfile?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-xs text-muted-foreground",children:"Tone & Style"}),e.jsxs("div",{className:"space-y-1","data-testid":"text-competitor-tone",children:[e.jsxs(C,{variant:"outline",className:"mr-1",children:[I.toneProfile.formalityLevel||"mixed"," tone"]}),e.jsxs(C,{variant:"secondary",className:"mr-1",children:[I.toneProfile.writingStyle||"professional"," style"]}),I.toneProfile.primaryTone&&e.jsx(C,{className:"mr-1",children:I.toneProfile.primaryTone})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-xs text-muted-foreground",children:"Content Themes"}),e.jsxs("div",{className:"flex flex-wrap gap-1","data-testid":"text-competitor-keywords",children:[(I.toneProfile.contentThemes||[]).slice(0,5).map((t,s)=>e.jsx(C,{variant:"outline",className:"text-xs",children:t},s)),(!I.toneProfile.contentThemes||I.toneProfile.contentThemes.length===0)&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"No themes analyzed"})]})]}),((oa=I.toneProfile.commonPhrases)==null?void 0:oa.length)>0&&e.jsxs("div",{className:"space-y-2 md:col-span-2",children:[e.jsx(m,{className:"text-xs text-muted-foreground",children:"Common Phrases"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:I.toneProfile.commonPhrases.slice(0,6).map((t,s)=>e.jsxs(C,{variant:"secondary",className:"text-xs",children:['"',t,'"']},s))})]})]}):e.jsxs("div",{className:"text-center py-4 bg-muted/50 rounded-lg",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"No anal
42ysis data available for this competitor."}),e.jsx(n,{variant:"outline",size:"sm",onClick:()=>{ts(I.website||""),ea()},disabled:!I.website||At,"data-testid":"button-analyze-website",children:At?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-1 animate-spin"}),"Analyzing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-4 w-4 mr-1"}),"Analyze Website"]})})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx(m,{className:"text-xs text-muted-foreground mb-2 block",children:"Quick Website Analysis"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{placeholder:"Enter competitor website URL...",value:Ft,onChange:t=>ts(t.target.value),className:"flex-1"}),e.jsx(n,{onClick:ea,disabled:!Ft.trim()||At,"data-testid":"button-analyze-website",children:At?e.jsx(me,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{className:"h-4 w-4 mr-1"}),"Analyze"]})})]})]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Content Type"}),e.jsxs(W,{value:x.contentType,onValueChange:t=>D(s=>({...s,contentType:t})),children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"educational",children:"Educational"}),e.jsx(p,{value:"promotional",children:"Promotional"}),e.jsx(p,{value:"informational",children:"Informational"}),e.jsx(p,{value:"testimonial",children:"Testimonial"}),e.jsx(p,{value:"announcement",children:"Announcement"}),e.jsx(p,{value:"seasonal",children:"Seasonal"}),e.jsx(p,{value:"engagement",children:"Engagement"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Tone of Voice"}),e.jsxs(W,{value:x.tone,onValueChange:t=>D(s=>({...s,tone:t})),children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"professional",children:"Professional"}),e.jsx(p,{value:"friendly",children:"Friendly"}),e.jsx(p,{value:"casual",children:"Casual"}),e.jsx(p,{value:"urgent",children:"Urgent"}),e.jsx(p,{value:"educational",children:"Educational"}),e.jsx(p,{value:"enthusiastic",children:"Enthusiastic"}),e.jsx(p,{value:"empathetic",children:"Empathetic"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Desired Action"}),e.jsx(Ee,{placeholder:"What action do you want the audience to take? E.g., Call for a free quote, Visit website, Book appointment...",className:"mt-2",rows:2,value:x.desiredAction,onChange:t=>D(s=>({...s,desiredAction:t.target.value}))})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Additional Instructions (Optional)"}),e.jsx(Ee,{placeholder:"Any specific requirements, keywords, or style preferences...",className:"mt-2",rows:2,value:x.instructions,onChange:t=>D(s=>({...s,instructions:t.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx(n,{className:"bg-orange-500 hover:bg-orange-600",onClick:er,disabled:B||zt.isPending,"data-testid":"button-generate-content",children:B||zt.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Generate Content"]})}),e.jsxs(n,{variant:"outline",onClick:()=>mt(!0),disabled:B||zt.isPending,"data-testid":"button-bulk-generate",children:[e.jsx(Rt,{className:"h-4 w-4 mr-2"}),"Bulk Generate"]}),e.jsxs(ga,{open:Zt,onOpenChange:Ye,children:[e.jsx(ja,{asChild:!0,children:e.jsxs(n,{variant:"outline","data-testid":"button-presets",children:[e.jsx(Bt,{className:"h-4 w-4 mr-2"}),"Presets",e.jsx(rt,{className:"h-4 w-4 ml-1"})]})}),e.jsxs(va,{className:"w-80 p-0",align:"start",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsx("h4",{className:"font-medium",children:"Generation Presets"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Save and load your generation settings"})]}),e.jsx("div",{"data-testid":"preset-list",className:"max-h-64 overflow-y-auto",children:Tn?e.jsxs("div",{className:"flex items-center justify-center p-6",children:[e.jsx(me,{className:"h-5 w-5 animate-spin text-gray-400"}),e.jsx("span",{className:"ml-2 text-sm text-gray-500",children:"Loading presets..."})]}):rs&&rs.length>0?e.jsx("div",{className:"py-2",children:rs.map(t=>e.jsxs("div",{"data-testid":`preset-item-${t.id}`,className:"flex items-center gap-2 px-4 py-2 hover:bg-gray-50 dark:hover:bg-gray-800 group cursor-pointer",onClick:()=>Un(t),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:t.name}),t.isDefault&&e.jsx(ce,{className:"h-3 w-3 text-yellow-500 fill-yellow-500"})]}),t.description&&e.jsx("p",{className:"text-xs text-gray-500 truncate",children:t.description})]}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(n,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:s=>{s.stopPropagation(),aa.mutate(t.id)},disabled:t.isDefault||aa.isPending,title:"Set as default",children:e.jsx(ce,{className:`h-4 w-4 ${t.isDefault?"text-yellow-500 fill-yellow-500":"text-gray-400"}`})}),e.jsx(n,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:s=>{s.stopPropagation(),sa.mutate(t.id)},disabled:sa.isPending,title:"Delete preset",children:e.jsx(Te,{className:"h-4 w-4"})})]})]},t.id))}):e.jsxs("div",{className:"p-6 text-center text-gray-500",children:[e.jsx(Bt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No presets saved yet"}),e.jsx("p",{className:"text-xs",children:"Save your current settings to get started"})]})}),e.jsx("div",{className:"p-3 border-t bg-gray-50 dark:bg-gray-800/50",children:e.jsxs(n,{variant:"outline",size:"sm",className:"w-full","data-testid":"button-save-preset",onClick:()=>{Ye(!1),Xe(!0)},children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save Current Settings"]})})]})]}),e.jsxs(n,{variant:"outline",onClick:()=>a({title:"Smart Assistant",description:"AI Assistant feature coming soon! Use the main generation tools for now."}),children:[e.jsx(Jr,{className:"h-4 w-4 mr-2"}),"Use Smart Assistant"]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"After Generation:"}),e.jsxs("div",{className:"flex gap-2 text-sm",children:[e.jsx("span",{className:"text-gray-500",children:"â Save to Library"}),e.jsx("span",{className:"text-gray-500",children:"â Schedule to Calendar"}),e.jsx("span",{className:"text-gray-500",children:"â Organize in Folders"})]})]}),$e&&G&&e.jsxs("div",{className:"border-t pt-6 mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-lg font-semibold text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5 text-green-500"}),"Generated Content Ready!"]}),e.jsx(n,{variant:"ghost",size:"sm",onClick:()=>ie(!1),children:"â"})]}),e.jsxs(N,{className:"border-2 border-green-200 bg-green-50 dark:bg-green-900/20",children:[e.jsxs(fe,{children:[e.jsx(ye,{className:"text-base",children:G.title}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(C,{variant:"outline",children:G.platform}),e.jsx(C,{variant:"outline",children:G.contentType})]})]}),e.jsx(b,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-white dark:bg-gray-800 rounded-lg border",children:[e.jsxs("div",{className:"prose prose-sm dark:prose-invert max-w-none max-h-48 overflow-hidden relative",children:[e.jsx(Fa,{remarkPlugins:[Aa],children:G.content.length>500?`${G.content.substring(0,500)}...`:G.content}),G.content.length>500&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-white dark:from-gray-800 to-transparent"})]}),G.content.length>500&&e.jsx(n,{variant:"link",size:"sm",className:"p-0 h-auto mt-2",onClick:()=>{re(G),H(!0)},children:"Read full content â"})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>Nt(G.content),className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"}),"Copy Content"]}),e.jsx(Vt,{contentItem:G,onScheduled:t=>
42{a({title:"ð
Content Scheduled!",description:"Your generated content has been added to the marketing calendar."}),ie(!1)}}),e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>{re(G),H(!0)},className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"Preview"]}),e.jsxs(n,{size:"sm",className:"bg-green-600 hover:bg-green-700",onClick:()=>{a({title:"â
Content Saved!",description:"Your content is now available in the Content Library."}),ie(!1),g("library")},children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save to Library"]})]})]})})]})]})]})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx("h3",{className:"font-medium mb-3",children:"Quick Actions"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsxs(n,{variant:"outline",size:"sm","data-testid":"quick-action-trending",onClick:()=>{D(t=>({...t,topic:"Top trends in my industry that customers need to know about",contentType:"educational",temperature:"cold",tone:"informative"})),a({title:"Trending Topics",description:"Form pre-filled with trending topic template"})},children:[e.jsx(fa,{className:"h-3 w-3 mr-1"}),"Trending Topics"]}),e.jsxs(n,{variant:"outline",size:"sm","data-testid":"quick-action-campaign",onClick:()=>{D(t=>({...t,topic:"Limited-time promotional campaign for our services",contentType:"promotional",temperature:"warm",tone:"persuasive",desiredAction:"Book a consultation or make a purchase"})),a({title:"Campaign Ideas",description:"Form pre-filled with campaign template"})},children:[e.jsx(ya,{className:"h-3 w-3 mr-1"}),"Campaign Ideas"]}),e.jsxs(n,{variant:"outline",size:"sm","data-testid":"quick-action-avatar",disabled:Cn,onClick:()=>{var T;const t=Array.isArray(ft)?ft:[],s=t.length>0?t[0]:null,r=((T=s==null?void 0:s.id)==null?void 0:T.toString())||"",j=(s==null?void 0:s.name)||"your avatar";D(z=>({...z,topic:"Content specifically tailored for my ideal customer",contentType:"engagement",temperature:"warm",avatarId:r,tone:"conversational"})),a(s?{title:"Avatar-Based",description:`Form pre-filled with "${j}" selected`}:{title:"No Avatars Found",description:"Create a customer avatar first for personalized content",variant:"default"})},children:[e.jsx(pa,{className:"h-3 w-3 mr-1"}),"Avatar-Based"]}),e.jsxs(n,{variant:"outline",size:"sm","data-testid":"quick-action-seasonal",onClick:()=>{const t=new Date().toLocaleString("default",{month:"long"});D(s=>({...s,topic:`${t} seasonal promotion and holiday-themed content`,contentType:"promotional",temperature:"warm",tone:"festive",desiredAction:"Take advantage of our seasonal offer"})),a({title:"Seasonal Content",description:`Form pre-filled with ${t} seasonal template`})},children:[e.jsx(vr,{className:"h-3 w-3 mr-1"}),"Seasonal Content"]})]})]}),e.jsx("div",{className:"border-t pt-6","data-testid":"history-section",children:e.jsxs(ms,{open:Gs,onOpenChange:an,children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(hs,{asChild:!0,children:e.jsxs(n,{variant:"ghost",className:"flex items-center gap-2 p-0 h-auto hover:bg-transparent",children:[e.jsx(us,{className:"h-5 w-5 text-gray-500"}),e.jsxs("h3",{className:"font-medium text-gray-900 dark:text-white",children:["Recent Generations",Ce&&Ce.length>0&&e.jsx(C,{variant:"secondary",className:"ml-2",children:Ce.length})]}),Gs?e.jsx(Kt,{className:"h-4 w-4 text-gray-500"}):e.jsx(rt,{className:"h-4 w-4 text-gray-500"})]})}),Ce&&Ce.length>0&&e.jsxs(n,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>os.mutate(),disabled:os.isPending,"data-testid":"button-clear-history",children:[os.isPending?e.jsx(me,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(Te,{className:"h-4 w-4 mr-1"}),"Clear History"]})]}),e.jsx(xs,{children:Pn?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(t=>e.jsxs("div",{className:"flex items-start gap-3 p-3 border rounded-lg",children:[e.jsx(Ut,{className:"h-10 w-10 rounded"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(Ut,{className:"h-4 w-3/4"}),e.jsx(Ut,{className:"h-3 w-1/2"})]}),e.jsx(Ut,{className:"h-8 w-20"})]},t))}):Ce&&Ce.length>0?e.jsx("div",{className:"space-y-3",children:Ce.map(t=>{var s;return e.jsx(N,{className:"hover:shadow-md transition-shadow","data-testid":`history-item-${t.id}`,children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(C,{variant:"outline",className:t.outputType==="html"?"bg-purple-50 text-purple-700 border-purple-200":t.outputType==="json"?"bg-blue-50 text-blue-700 border-blue-200":"bg-gray-50 text-gray-700 border-gray-200",children:t.outputType||"text"}),e.jsx("span",{className:"text-xs text-gray-500",children:t.createdAt?si(new Date(t.createdAt),{addSuffix:!0}):"recently"}),t.tokensUsed&&e.jsxs("span",{className:"text-xs text-gray-400",children:["⢠",t.tokensUsed," tokens"]})]}),e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300 line-clamp-2",children:t.output?t.output.length>100?`${t.output.substring(0,100)}...`:t.output:"No content available"}),((s=t.requestPayload)==null?void 0:s.topic)&&e.jsxs("p",{className:"text-xs text-gray-500 mt-1 truncate",children:["Topic: ",t.requestPayload.topic]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(n,{variant:"ghost",size:"sm",className:"h-8 px-2",onClick:()=>Rn(t),title:"Reuse these settings","data-testid":"button-reuse-settings",children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx(n,{variant:"ghost",size:"sm",className:"h-8 px-2",onClick:()=>{navigator.clipboard.writeText(t.output||""),a({title:"Copied!",description:"Content copied to clipboard."})},title:"Copy content","data-testid":"button-copy-content",children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsx(n,{variant:"ghost",size:"sm",className:"h-8 px-2 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>ta.mutate(t.id),disabled:ta.isPending,title:"Delete","data-testid":"button-delete-history",children:e.jsx(Te,{className:"h-4 w-4"})})]})]})})},t.id)})}):e.jsxs("div",{className:"text-center py-8 text-gray-500",children:[e.jsx(us,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm font-medium",children:"No generation history yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Your AI-generated content will appear here"})]})})]})})]})]})}),e.jsx(wt,{value:"improve",className:"space-y-6",children:e.jsxs(N,{children:[e.jsxs(fe,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5"}),"Improve My Content"]}),e.jsx(Be,{children:"AI-powered prompts to enhance, optimize, and scale your marketing content"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[{id:"lead_magnet",title:"Lead Magnet Generator",description:"Create unique lead magnet ideas for high-quality lead generation",icon:ya,color:"bg-blue-500",prompt:"Create a unique lead magnet idea for a [niche] that I can use to generate high-quality leads for my [specific offer]."},{id:"offer_optimizer",title:"Offer Optimizer",description:"Rewrite offers to be more irresistible and increase perceived value",icon:fa,color:"bg-green-500",prompt:"Rewrite this offer to be more irresistible and increase perceived value, focusing on these three pain points: [pain point 1], [pain point 2], and [pain point 3]."},{id:"workflow_creator",title:"Workflow Creator",description:"Create step-by-step automation workflows for nurturing leads",icon:ai,color:"bg-purple-500",prompt:"Create a step-by-step automation workflow for nurturing leads from [platform] to a booked call."},{id:"ad_copy_creator",title:"Ad Copy Creator",description:"Write high-converting ads with pain points and powerful CTAs",icon:gs,color:"bg-red-500",prompt:"Write an engaging, high-converting Facebook ad for a [product] targeting [audience]. Include pain points, objections, and a powerful call to action."},{id:"market_research",title:"Market Research",description:"Generate market research reports on current trends and competitors",icon:ni,color:"bg-indigo-500",prompt:"Create a market research report on the current trends in [niche] with a focus on [specific topic], pulling insights from top competitors and s
42ocial media."},{id:"email_sequence",title:"Email Sequence",description:"Generate email sequences for onboarding and customer nurturing",icon:Wr,color:"bg-yellow-500",prompt:"Generate an email sequence for onboarding new customers, emphasizing value and setting expectations for [product/service]."},{id:"content_ideas",title:"Content Ideas",description:"Create fresh content ideas that resonate with your audience",icon:Na,color:"bg-orange-500",prompt:"Create a list of 10 new content ideas for [niche], with angles that will resonate with my audience's current concerns."}].map(t=>{const s=t.icon;return e.jsx(N,{className:`cursor-pointer transition-all hover:shadow-lg ${d.selectedPrompt===t.id?"ring-2 ring-orange-500":""}`,onClick:()=>k(r=>({...r,selectedPrompt:t.id})),children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t.color} text-white`,children:e.jsx(s,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium",children:t.title}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t.description})]}),d.selectedPrompt===t.id&&e.jsx(te,{className:"h-5 w-5 text-orange-500"})]})})},t.id)})}),d.selectedPrompt&&e.jsxs("div",{className:"border-t pt-6 space-y-4",children:[e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-900/20 p-4 rounded-lg",children:[e.jsx("h4",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:"AI Prompt Preview"}),e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:{lead_magnet:"Create a unique lead magnet idea for a [niche] that I can use to generate high-quality leads for my [specific offer].",offer_optimizer:"Rewrite this offer to be more irresistible and increase perceived value, focusing on these three pain points: [pain point 1], [pain point 2], and [pain point 3].",workflow_creator:"Create a step-by-step automation workflow for nurturing leads from [platform] to a booked call.",ad_copy_creator:"Write an engaging, high-converting Facebook ad for a [product] targeting [audience]. Include pain points, objections, and a powerful call to action.",market_research:"Create a market research report on the current trends in [niche] with a focus on [specific topic], pulling insights from top competitors and social media.",email_sequence:"Generate an email sequence for onboarding new customers, emphasizing value and setting expectations for [product/service].",content_ideas:"Create a list of 10 new content ideas for [niche], with angles that will resonate with my audience's current concerns."}[d.selectedPrompt]||""})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[["lead_magnet","market_research","content_ideas"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Your Niche/Industry"}),e.jsx(L,{placeholder:"e.g., Real Estate, Fitness, Local Services",className:"mt-2",value:d.niche,onChange:t=>k(s=>({...s,niche:t.target.value}))})]}),["lead_magnet"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Specific Offer"}),e.jsx(L,{placeholder:"e.g., Free Home Valuation, 30-Day Meal Plan",className:"mt-2",value:d.offer,onChange:t=>k(s=>({...s,offer:t.target.value}))})]}),["workflow_creator"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Platform"}),e.jsxs(W,{value:d.platform,onValueChange:t=>k(s=>({...s,platform:t})),children:[e.jsx(Y,{className:"mt-2",children:e.jsx(X,{placeholder:"Select platform"})}),e.jsxs(Z,{children:[e.jsx(p,{value:"facebook",children:"Facebook"}),e.jsx(p,{value:"instagram",children:"Instagram"}),e.jsx(p,{value:"linkedin",children:"LinkedIn"}),e.jsx(p,{value:"google-ads",children:"Google Ads"}),e.jsx(p,{value:"email",children:"Email"}),e.jsx(p,{value:"website",children:"Website"})]})]})]}),["ad_copy_creator"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Product/Service"}),e.jsx(L,{placeholder:"e.g., Digital Marketing Course, Lawn Care Service",className:"mt-2",value:d.product,onChange:t=>k(s=>({...s,product:t.target.value}))})]}),["ad_copy_creator"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Target Audience"}),e.jsx(L,{placeholder:"e.g., Small business owners, Busy homeowners",className:"mt-2",value:d.audience,onChange:t=>k(s=>({...s,audience:t.target.value}))})]}),["market_research"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Specific Topic"}),e.jsx(L,{placeholder:"e.g., AI automation tools, Social media trends",className:"mt-2",value:d.specificTopic,onChange:t=>k(s=>({...s,specificTopic:t.target.value}))})]}),["email_sequence"].includes(d.selectedPrompt)&&e.jsxs("div",{children:[e.jsx(m,{children:"Product/Service"}
42),e.jsx(L,{placeholder:"e.g., SaaS platform, Consulting service",className:"mt-2",value:d.productService,onChange:t=>k(s=>({...s,productService:t.target.value}))})]})]}),["offer_optimizer"].includes(d.selectedPrompt)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{children:"Three Main Pain Points"}),e.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[e.jsx(L,{placeholder:"Pain Point 1: e.g., Not enough qualified leads",value:d.painPoint1,onChange:t=>k(s=>({...s,painPoint1:t.target.value}))}),e.jsx(L,{placeholder:"Pain Point 2: e.g., Time-consuming manual processes",value:d.painPoint2,onChange:t=>k(s=>({...s,painPoint2:t.target.value}))}),e.jsx(L,{placeholder:"Pain Point 3: e.g., Inconsistent marketing results",value:d.painPoint3,onChange:t=>k(s=>({...s,painPoint3:t.target.value}))})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Additional Context (Optional)"}),e.jsx(Ee,{placeholder:"Any additional details, brand voice, or specific requirements...",className:"mt-2",rows:3,value:d.additionalContext,onChange:t=>k(s=>({...s,additionalContext:t.target.value}))})]}),e.jsx(n,{className:"w-full bg-orange-500 hover:bg-orange-600",onClick:()=>{dt(!1),St(null),Zn.mutate()},disabled:Le||!d.selectedPrompt,"data-testid":"btn-generate-improvement",children:Le?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ys,{className:"h-4 w-4 mr-2"}),"Generate Improved Content"]})}),sn&&le&&e.jsx("div",{className:"mt-6 pt-6 border-t",children:e.jsx(N,{className:"border-green-200 bg-green-50 dark:bg-green-900/20 dark:border-green-800",children:e.jsxs(b,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5 text-green-600"}),e.jsx("span",{className:"font-medium text-green-800 dark:text-green-200",children:"Improved Content Ready!"})]}),e.jsx(n,{variant:"ghost",size:"sm",onClick:()=>dt(!1),children:"Ã"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-lg",children:le.title}),e.jsx("div",{className:"mt-2 p-3 bg-white dark:bg-gray-800 rounded-lg max-h-[200px] overflow-y-auto",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:le.content})}),le.content.length>300&&e.jsx(n,{variant:"link",className:"p-0 h-auto",onClick:()=>{re(le),H(!0)},children:"Read full content â"})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>Nt(le.content),"data-testid":"btn-copy-improved",children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Copy Content"]}),e.jsx(Vt,{contentItem:le,onScheduled:t=>{a({title:"ð
Content Scheduled!",description:"Your improved content has been added to the marketing calendar."}),dt(!1)}}),e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>{re(le),H(!0)},"data-testid":"btn-preview-improved",children:[e.jsx(_e,{className:"h-4 w-4 mr-2"}),"Preview"]}),e.jsxs(n,{size:"sm",className:"bg-green-600 hover:bg-green-700",onClick:()=>{a({title:"â
Content Saved!",description:"Your improved content is now available in the Content Library."}),dt(!1),k({selectedPrompt:"",niche:"",offer:"",platform:"",product:"",audience:"",painPoint1:"",painPoint2:"",painPoint3:"",specificTopic:"",productService:"",additionalContext:""}),g("library")},"data-testid":"btn-save-improved",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save to Library"]})]})]})})})]})]})]})}),e.jsx(wt,{value:"library",className:"space-y-6",children:e.jsxs(N,{children:[e.jsx(fe,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(Mt,{className:"h-5 w-5"}),"Content Library",A.length>0&&e.jsxs(C,{variant:"secondary",className:"ml-2",children:[A.length," selected"]})]}),e.jsx(Be,{children:"All your generated and saved content in one place"})]}),e.jsx("div",{className:"flex gap-2",children:A.length>0?e.jsxs(e.Fragment,{children:[e.jsx(n,{variant:"outline",onClick:ar,children:A.length===oe.length?"Deselect All":"Select All"}),e.jsxs(n,{variant:"outline",onClick:()=>q(!0),children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),"Move"]}),e.jsxs(n,{variant:"outline",children:[e.jsx(Yr,{className:"h-4 w-4 mr-2"}),"Tag"]}),e.jsxs(n,{variant:"destructive",onClick:nr,children:[e.jsx(Te,{className:"h-4 w-4 mr-2"}),"Delete (",A.length,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(tn,{type:"single",value:P,onValueChange:t=>t&&K(t),className:"border rounded-md",children:[e.jsx(Ht,{value:"grid","aria-label":"Grid view",className:"px-3",children:e.jsx(Ia,{className:"h-4 w-4"})}),e.jsx(Ht,{value:"list","aria-label":"List view",className:"px-3",children:e.jsx(Xr,{className:"h-4 w-4"})}),e.jsx(Ht,{value:"collections","aria-label":"Collections view",className:"px-3","data-testid":"view-mode-collections",children:e.jsx(Ea,{className:"h-4 w-4"})})]}),e.jsxs(n,{variant:"outline",children:[e.jsx(Zr,{className:"h-4 w-4 mr-2"}),"Import"]}),e.jsxs(n,{variant:"outline",onClick:rr,children:[e.jsx(_t,{className:"h-4 w-4 mr-2"}),"Export"]})]})})]})}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(ps,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx(L,{placeholder:"Search content by title, tags...",className:"pl-10",value:S,onChange:t=>V(t.target.value)})]}),e.jsxs(W,{value:$,onValueChange:qe,children:[e.jsxs(Y,{className:"w-full sm:w-[200px]",children:[e.jsx($a,{className:"h-4 w-4 mr-2"}),e.jsx(X,{})]}),e.jsx(Z,{children:Yn.map(t=>{const s=t.icon;return e.jsx(p,{value:t.value,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s,{className:"h-4 w-4"}),t.label]})},t.value)})})]})]}
42),e.jsxs(ms,{open:Vs,onOpenChange:hn,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hs,{asChild:!0,children:e.jsxs(n,{variant:"outline",className:"gap-2","data-testid":"button-toggle-filters",children:[e.jsx($a,{className:"h-4 w-4"}),"Filters",as>0&&e.jsx(C,{className:"ml-1 bg-orange-500 text-white","data-testid":"badge-active-filters",children:as}),Vs?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(rt,{className:"h-4 w-4"})]})}),as>0&&e.jsx(n,{variant:"ghost",size:"sm",onClick:gn,className:"text-orange-600 hover:text-orange-700 hover:bg-orange-50 dark:hover:bg-orange-950","data-testid":"button-clear-filters",children:"Clear Filters"})]}),e.jsx(xs,{className:"mt-4",children:e.jsx(N,{className:"border-orange-200 dark:border-orange-800",children:e.jsxs(b,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"filter-date-from",className:"text-sm font-medium",children:"From Date"}),e.jsx(L,{id:"filter-date-from",type:"date",value:ut,onChange:t=>Bs(t.target.value),className:"w-full","data-testid":"filter-date-from"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"filter-date-to",className:"text-sm font-medium",children:"To Date"}),e.jsx(L,{id:"filter-date-to",type:"date",value:gt,onChange:t=>_s(t.target.value),className:"w-full","data-testid":"filter-date-to"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"filter-status",className:"text-sm font-medium",children:"Status"}),e.jsxs(W,{value:jt,onValueChange:Hs,children:[e.jsx(Y,{id:"filter-status","data-testid":"filter-status",children:e.jsx(X,{placeholder:"Select status"})}),e.jsx(Z,{children:un.map(t=>e.jsx(p,{value:t.value,children:t.label},t.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-sm font-medium",children:"Sort"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(W,{value:It,onValueChange:Ws,children:[e.jsx(Y,{className:"flex-1","data-testid":"filter-sort-by",children:e.jsx(X,{})}),e.jsxs(Z,{children:[e.jsx(p,{value:"createdAt",children:"Created Date"}),e.jsx(p,{value:"title",children:"Title"}),e.jsx(p,{value:"updatedAt",children:"Updated Date"})]})]}),e.jsx(n,{variant:"outline",size:"icon",onClick:()=>Ys(t=>t==="asc"?"desc":"asc"),className:"shrink-0","data-testid":"filter-sort-order",children:vt==="desc"?e.jsx(rt,{className:"h-4 w-4"}):e.jsx(Kt,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-gray-500",children:vt==="desc"?"Newest first":"Oldest first"})]})]}),e.jsx(js,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-sm font-medium",children:"Content Type"}),e.jsx("div",{className:"flex flex-wrap gap-2","data-testid":"filter-content-type",children:xn.map(t=>e.jsx(C,{variant:et.includes(t.value)?"default":"outline",className:`cursor-pointer transition-colors ${et.includes(t.value)?"bg-orange-500 hover:bg-orange-600 text-white border-orange-500":"hover:bg-orange-50 hover:border-orange-300 dark:hover:bg-orange-950"}`,onClick:()=>jn(t.value),children:t.label},t.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-sm font-medium",children:"Platform"}),e.jsx("div",{className:"flex flex-wrap gap-2","data-testid":"filter-platform",children:pn.map(t=>e.jsx(C,{variant:tt.includes(t.value)?"default":"outline",className:`cursor-pointer transition-colors ${tt.includes(t.value)?"bg-orange-500 hover:bg-orange-600 text-white border-orange-500":"hover:bg-orange-50 hover:border-orange-300 dark:hover:bg-orange-950"}`,onClick:()=>vn(t.value),children:t.label},t.value))})]}),Zs.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{className:"text-sm font-medium",children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-2","data-testid":"filter-tags",children:Zs.map(t=>e.jsxs(C,{variant:st.includes(t)?"default":"outline",className:`cursor-pointer transition-colors ${st.includes(t)?"bg-orange-500 hover:bg-orange-600 text-white border-orange-500":"hover:bg-orange-50 hover:border-orange-300 dark:hover:bg-orange-950"}`,onClick:()=>fn(t),children:[e.jsx(bs,{className:"h-3 w-3 mr-1"}),t]},t))})]})]})})})]}),yn?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):P==="collections"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-lg font-medium flex items-center gap-2",children:[e.jsx(Os,{className:"h-5 w-5"}),"Collections",O&&e.jsx(C,{variant:"secondary",children:O.length})]}),e.jsxs(n,{onClick:()=>{M({name:"",description:"",color:"#6b7280",icon:"folder"}),y(!0)},className:"bg-orange-500 hover:bg-orange-600","data-testid":"button-create-collection",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Create Collection"]})]}),En?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):!O||O.length===0?e.jsx(N,{className:"p-12 text-center",children:e.jsxs(b,{className:"space-y-4",children:[e.jsx(Ea,{className:"h-12 w-12 mx-auto text-gray-400"}),e.jsx("h3",{className:"text-lg font-medium",children:"No Collections Yet"}),e.jsx("p",{className:"text-gray-500",children:"Create a collection to organize your content"}),e.jsxs(n,{onClick:()=>{M({name:"",description:"",color:"#6b7280",icon:"folder"}),y(!0)},className:"bg-orange-500 hover:bg-orange-600",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Create Collection"]})]})}):e.jsx(qr,{sensors:Gn,collisionDetection:Mr,onDragEnd:zn,children:e.jsx(Rr,{items:O.map(t=>
42t.id),strategy:Ur,children:e.jsx("div",{className:"space-y-3",children:O.map(t=>{As(t.icon);const s=ot.has(t.id),r=Mn(t.id),j=(at==null?void 0:at[t.id])||[];return e.jsx(xi,{collection:t,isExpanded:s,itemCount:r,collectionItems:j,contentLibrary:Gt,onToggleExpand:()=>qn(t.id),onEdit:()=>{Je(t),M({name:t.name,description:t.description||"",color:t.color,icon:t.icon}),we(!0)},onDelete:()=>$n.mutate(t.id),onRemoveItem:T=>Ln.mutate({collectionId:t.id,contentId:T})},t.id)})})})}),oe.length>0&&O&&O.length>0&&e.jsxs(N,{className:"mt-6",children:[e.jsx(fe,{children:e.jsxs(ye,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(nt,{className:"h-4 w-4"}),"Add Content to Collections"]})}),e.jsxs(b,{children:[e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Select content items below and add them to your collections"}),e.jsx(vs,{className:"h-[300px] pr-4",children:e.jsx("div",{className:"space-y-2",children:oe.slice(0,20).map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-900 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"w-8 h-8 bg-white dark:bg-gray-800 rounded flex items-center justify-center",children:[t.contentType==="text"&&e.jsx(ae,{className:"h-4 w-4 text-gray-400"}),t.contentType==="image"&&e.jsx(Qt,{className:"h-4 w-4 text-gray-400"}),t.contentType==="video"&&e.jsx(Ct,{className:"h-4 w-4 text-gray-400"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium line-clamp-1",children:t.title}),e.jsx("p",{className:"text-xs text-gray-500",children:t.category})]})]}),e.jsxs(ga,{children:[e.jsx(ja,{asChild:!0,children:e.jsxs(n,{size:"sm",variant:"outline","data-testid":"button-add-to-collection",children:[e.jsx(Ns,{className:"h-3 w-3 mr-1"}),"Add"]})}),e.jsx(va,{className:"w-48 p-2",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 px-2 py-1",children:"Add to collection:"}),O.map(s=>{const r=As(s.icon);return e.jsxs(n,{variant:"ghost",size:"sm",className:"w-full justify-start",onClick:()=>On.mutate({collectionId:s.id,contentId:t.id}),children:[e.jsx("div",{className:"w-2 h-2 rounded-full mr-2",style:{backgroundColor:s.color}}),e.jsx(r,{className:"h-3 w-3 mr-2"}),s.name]},s.id)})]})})]})]},t.id))})})]})]})]}):oe.length===0?e.jsx(N,{className:"p-12 text-center",children:e.jsxs(b,{className:"space-y-4",children:[e.jsx(Mt,{className:"h-12 w-12 mx-auto text-gray-400"}),e.jsx("h3",{className:"text-lg font-medium",children:"No Content Yet"}),e.jsx("p",{className:"text-gray-500",children:"Start generating content to build your library"}),e.jsxs(n,{onClick:()=>g("generate"),className:"bg-orange-500 hover:bg-orange-600",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Generate Content"]})]})}):P==="grid"?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:oe.map(t=>{var s;return e.jsxs(N,{className:`hover:shadow-lg transition-shadow relative ${A.includes(t.id)?"ring-2 ring-orange-500":""}`,children:[e.jsx("div",{className:"absolute top-2 left-2 z-10",children:e.jsx(ba,{checked:A.includes(t.id),onCheckedChange:()=>la(t.id)})}),e.jsxs(b,{className:"p-4",children:[t.contentType==="image"&&e.jsx("div",{className:"aspect-video bg-gray-100 rounded-lg mb-3 overflow-hidden",children:e.jsx("img",{src:t.content,alt:t.title,className:"w-full h-full object-cover"})}),t.contentType==="video"&&e.jsx("div",{className:"aspect-video bg-gray-100 rounded-lg mb-3 flex items-center justify-center",children:e.jsx(Ct,{className:"h-12 w-12 text-gray-400"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium line-clamp-1",children:t.title}),t.contentType==="text"&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:t.content}),e.jsx("div",{className:"flex flex-wrap gap-1",children:(s=t.tags)==null?void 0:s.map(r=>e.jsx(C,{variant:"secondary",className:"text-xs",children:r},r))}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("span",{className:"text-xs text-gray-500",children:new Date(t.createdAt).toLocaleDateString()}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>{re(t),H(!0)},"data-testid":`button-preview-${t.id}`,children:e.jsx(_e,{className:"h-3 w-3"})}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>Nt(t.content),"data-testid":`button-copy-${t.id}`,children:e.jsx(Ke,{className:"h-3 w-3"})}
42),e.jsx(Vt,{contentItem:{id:t.id,title:t.title||"Untitled Content",content:t.content,contentType:t.contentType||"social-post",platform:t.platform||"Facebook",phase:t.phase||t.category||"awareness",tags:t.tags||[],status:t.status||"draft",createdAt:t.createdAt,updatedAt:t.updatedAt||t.createdAt,userId:t.userId},onScheduled:r=>{a({title:"Content Scheduled",description:`"${t.title}" has been added to your marketing calendar`})}}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>qt(t.id),"data-testid":`button-delete-${t.id}`,children:e.jsx(Te,{className:"h-3 w-3"})})]})]})]})]})]},t.id)})}):e.jsx("div",{className:"space-y-2",children:oe.map(t=>e.jsx(N,{className:`${A.includes(t.id)?"ring-2 ring-orange-500":""}`,children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ba,{checked:A.includes(t.id),onCheckedChange:()=>la(t.id)}),e.jsxs("div",{className:"w-12 h-12 bg-gray-100 rounded-lg flex items-center justify-center",children:[t.contentType==="text"&&e.jsx(ae,{className:"h-6 w-6 text-gray-400"}),t.contentType==="image"&&e.jsx(Qt,{className:"h-6 w-6 text-gray-400"}),t.contentType==="video"&&e.jsx(Ct,{className:"h-6 w-6 text-gray-400"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx("span",{children:t.category}),e.jsx("span",{children:"â¢"}),e.jsx("span",{children:new Date(t.createdAt).toLocaleDateString()})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:t.status==="active"?"default":"secondary",children:t.status||"active"}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>{re(t),H(!0)},"data-testid":`button-preview-list-${t.id}`,children:e.jsx(_e,{className:"h-4 w-4"})}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>Nt(t.content),"data-testid":`button-copy-list-${t.id}`,children:e.jsx(Ke,{className:"h-4 w-4"})}),e.jsx(Vt,{contentItem:{id:t.id,title:t.title||"Untitled Content",content:t.content,contentType:t.contentType||"social-post",platform:t.platform||"Facebook",phase:t.phase||t.category||"awareness",tags:t.tags||[],status:t.status||"draft",createdAt:t.createdAt,updatedAt:t.updatedAt||t.createdAt,userId:t.userId},onScheduled:s=>{a({title:"Content Scheduled",description:`"${t.title}" has been added to your marketing calendar`})}}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>qt(t.id),"data-testid":`button-delete-list-${t.id}`,children:e.jsx(Te,{className:"h-4 w-4"})})]})]})})},t.id))})]})]})}),e.jsx(wt,{value:"templates",className:"space-y-6",children:e.jsxs(N,{children:[e.jsxs(fe,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5"}),"Marketing Templates"]}),e.jsx(Be,{children:"Reusable templates and workflows for consistent content creation"})]}),e.jsxs(b,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 p-3 bg-gray-50 dark:bg-gray-900 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"h-4 w-4 text-yellow-500"}),e.jsx(m,{htmlFor:"favorites-toggle",className:"text-sm font-medium cursor-pointer",children:"Show Favorites Only"})]}),e.jsx(fr,{id:"favorites-toggle","data-testid":"favorites-toggle",checked:Re,onCheckedChange:zs})]}),Nn||Fn?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[!Re&&e.jsx(N,{className:"border-2 border-dashed hover:border-orange-500 transition-colors cursor-pointer",children:e.jsxs(b,{className:"p-6 text-center",children:[e.jsx(nt,{className:"h-12 w-12 mx-auto text-gray-400 mb-3"}),e.jsx("h4",{className:"font-medium",children:"Create New Template"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"Build a custom template from scratch"})]})}),((da=(ca=ns==null?void 0:ns.templates)==null?void 0:ca.slice(0,3))==null?void 0:da.filter(t=>{var s;return!Re||ke(((s=t.id)==null?void 0:s.toString())||t.id)}).map(t=>{var s;return e.jsxs(N,{className:"relative","data-testid":`template-favorite-${t.id}`,children:[e.jsx("button",{onClick:r=>{var j;r.stopPropagation(),Dt(((j=t.id)==null?void 0:j.toString())||t.id)},className:"absolute top-3 right-3 p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-all hover:scale-110 z-10","data-testid":`button-favorite-star-${t.id}`,children:e.jsx(ce,{className:`h-5 w-5 transition-colors ${ke(((s=t.id)==null?void 0:s.toString())||t.id)?"fill-yellow-400 text-yellow-400":"text-gray-400 hover:text-yellow-400"}`})}),e.jsx(b,{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 ${t.color||"bg-blue-100"} rounded-lg`,children:e.jsx(ae,{className:"h-5 w-5 text-blue-600"})}),e.jsxs("div",{className:"flex-1 pr-8",children:[e.jsx("h4",{className:"font-medium",children:t.name}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t.description}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(n,{size:"sm",variant:"outline",children:"Use Template"}),e.jsx(n,{size:"sm",variant:"ghost",children:"Preview"})]})]})]})})]},t.id)}
42))||e.jsxs(e.Fragment,{children:[(!Re||ke("social-media-series"))&&e.jsxs(N,{className:"relative","data-testid":"template-favorite-social-media-series",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),Dt("social-media-series")},className:"absolute top-3 right-3 p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-all hover:scale-110 z-10","data-testid":"button-favorite-star-social-media-series",children:e.jsx(ce,{className:`h-5 w-5 transition-colors ${ke("social-media-series")?"fill-yellow-400 text-yellow-400":"text-gray-400 hover:text-yellow-400"}`})}),e.jsx(b,{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 rounded-lg",children:e.jsx(wa,{className:"h-5 w-5 text-blue-600"})}),e.jsxs("div",{className:"flex-1 pr-8",children:[e.jsx("h4",{className:"font-medium",children:"Social Media Series"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"5-post series template for product launches"}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(n,{size:"sm",variant:"outline",children:"Use Template"}),e.jsx(n,{size:"sm",variant:"ghost",children:"Preview"})]})]})]})})]}),(!Re||ke("email-drip-campaign"))&&e.jsxs(N,{className:"relative","data-testid":"template-favorite-email-drip-campaign",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),Dt("email-drip-campaign")},className:"absolute top-3 right-3 p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-all hover:scale-110 z-10","data-testid":"button-favorite-star-email-drip-campaign",children:e.jsx(ce,{className:`h-5 w-5 transition-colors ${ke("email-drip-campaign")?"fill-yellow-400 text-yellow-400":"text-gray-400 hover:text-yellow-400"}`})}),e.jsx(b,{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-100 rounded-lg",children:e.jsx(ws,{className:"h-5 w-5 text-purple-600"})}),e.jsxs("div",{className:"flex-1 pr-8",children:[e.jsx("h4",{className:"font-medium",children:"Email Drip Campaign"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"7-day nurture sequence for new leads"}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(n,{size:"sm",variant:"outline",children:"Use Template"}),e.jsx(n,{size:"sm",variant:"ghost",children:"Preview"})]})]})]})})]}),(!Re||ke("blog-post-framework"))&&e.jsxs(N,{className:"relative","data-testid":"template-favorite-blog-post-framework",children:[e.jsx("button",{onClick:t=>{t.stopPropagation(),Dt("blog-post-framework")},className:"absolute top-3 right-3 p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800 transition-all hover:scale-110 z-10","data-testid":"button-favorite-star-blog-post-framework",children:e.jsx(ce,{className:`h-5 w-5 transition-colors ${ke("blog-post-framework")?"fill-yellow-400 text-yellow-400":"text-gray-400 hover:text-yellow-400"}`})}),e.jsx(b,{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 bg-green-100 rounded-lg",children:e.jsx(fs,{className:"h-5 w-5 text-green-600"})}),e.jsxs("div",{className:"flex-1 pr-8",children:[e.jsx("h4",{className:"font-medium",children:"Blog Post Framework"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"SEO-optimized article structure"}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(n,{size:"sm",variant:"outline",children:"Use Template"}),e.jsx(n,{size:"sm",variant:"ghost",children:"Preview"})]})]})]})})]})]}),Re&&(!Lt||Lt.length===0)&&e.jsxs("div",{className:"col-span-full text-center py-12",children:[e.jsx(ce,{className:"h-12 w-12 mx-auto text-gray-300 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-gray-600 dark:text-gray-400",children:"No Favorites Yet"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-500 mt-1",children:"Click the star icon on any template to add it to your favorites"}),e.jsx(n,{variant:"outline",className:"mt-4",onClick:()=>zs(!1),children:"Show All Templates"})]})]})]})]})}),e.jsx(wt,{value:"voiceover",className:"space-y-6",children:e.jsxs(N,{children:[e.jsxs(fe,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(it,{className:"h-5 w-5"}),"AI Voice-Over Studio"]}),e.jsx(Be,{children:"Convert your marketing content into professional voice-overs with AI-powered text-to-speech"})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsx(N,{className:"bg-orange-50 dark:bg-orange-950 border-orange-200",children:e.jsxs(b,{className:"p-4",children:[e.jsx(Ua,{className:"h-8 w-8 text-orange-500 mb-2"}),e.jsx("h4",{className:"font-medium mb-1",children:"6 Natural Voices"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Choose from male and female voices with different accents and tones"})]})}),e.jsx(N,{className:"bg-blue-50 dark:bg-blue-950 border-blue-200",children:e.jsxs(b,{className:"p-4",children:[e.jsx(Bt,{className:"h-8 w-8 text-blue-500 mb-2"}),e.jsx("h4",{className:"font-medium mb-1",children:"Customizable Speed"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Adjust speaking rate from slow to fast for perfect delivery"})]})}),e.jsx(N,{className:"bg-green-50 dark:bg-green-950 border-green-200",children:e.jsxs(b,{className:"p-4",children:[e.jsx(de,{className:"h-8 w-8 text-green-500 mb-2"}),e.jsx("h4",{className:"font-medium mb-1",children:"Save to Library"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Store audio files in your content library for easy reuse"})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs(n,{onClick:()=>{kt(""),We(!0)},className:"flex-1 bg-orange-500 hover:bg-orange-600",children:[e.jsx(it,{className:"h-4 w-4 mr-2"}),"Create New Voice-Over"]}),e.jsxs(n,{variant:"outline",onClick:()=>{const t=oe.find(s=>
42A.includes(s.id));t?(kt(t.content),We(!0)):a({title:"Select Content",description:"Please select a content item from your library first.",variant:"destructive"})},disabled:A.length===0,className:"flex-1",children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),"Convert Selected Content"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"font-medium flex items-center gap-2",children:[e.jsx(us,{className:"h-4 w-4"}),"Recent Voice-Overs"]}),Gt.filter(t=>t.contentType==="audio").length>0?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Gt.filter(t=>t.contentType==="audio").slice(0,6).map(t=>{var s;return e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Va,{className:"h-4 w-4 text-orange-500"}),e.jsx("h4",{className:"font-medium text-sm",children:t.title})]}),e.jsxs("p",{className:"text-xs text-gray-500 mb-2",children:["Voice: ",((s=t.metadata)==null?void 0:s.voice)||"Nova"," ⢠Created: ",new Date(t.createdAt).toLocaleDateString()]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 line-clamp-2",children:t.content})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>{var j;const r=(j=t.metadata)==null?void 0:j.audioUrl;r&&new Audio(r).play()},children:e.jsx(Play,{className:"h-4 w-4"})}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>{var j;const r=(j=t.metadata)==null?void 0:j.audioUrl;if(r){const T=document.createElement("a");T.href=r,T.download=`${t.title}.mp3`,T.click()}},children:e.jsx(_t,{className:"h-4 w-4"})}),e.jsx(n,{size:"sm",variant:"ghost",onClick:()=>qt(t.id),children:e.jsx(Te,{className:"h-4 w-4"})})]})]})})},t.id)})}):e.jsx(N,{children:e.jsxs(b,{className:"p-8 text-center",children:[e.jsx(it,{className:"h-12 w-12 mx-auto text-gray-400 mb-4"}),e.jsx("p",{className:"text-gray-500",children:"No voice-overs created yet"}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Create your first voice-over to enhance your marketing content"}),e.jsxs(n,{onClick:()=>We(!0),className:"mt-4 bg-orange-500 hover:bg-orange-600",children:[e.jsx(it,{className:"h-4 w-4 mr-2"}),"Create Voice-Over"]})]})})]}),e.jsx(N,{className:"bg-gray-50 dark:bg-gray-900",children:e.jsxs(b,{className:"p-4",children:[e.jsxs("h4",{className:"font-medium text-sm mb-2 flex items-center gap-2",children:[e.jsx(Na,{className:"h-4 w-4 text-yellow-500"}),"Pro Tips for Voice-Overs"]}),e.jsxs("ul",{className:"text-sm text-gray-600 dark:text-gray-400 space-y-1",children:[e.jsx("li",{children:"⢠Keep sentences short and clear for better pronunciation"}),e.jsx("li",{children:"⢠Use punctuation to control pauses and emphasis"}),e.jsx("li",{children:"⢠Test different voices to find the best match for your brand"}),e.jsx("li",{children:"⢠Adjust speed based on content type (slower for tutorials, faster for ads)"})]})]})})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Total Content"}),$t?e.jsx("div",{className:"h-8 w-12 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"}):e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-total-content",children:Ot.totalContent})]}),e.jsx(Mt,{className:"h-8 w-8 text-orange-500"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Generated Today"}),$t?e.jsx("div",{className:"h-8 w-8 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"}):e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-generated-today",children:Ot.generatedToday})]}),e.jsx(ze,{className:"h-8 w-8 text-blue-500"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Templates"}),$t?e.jsx("div",{className:"h-8 w-8 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"}):e.jsx("p",{className:"text-2xl font-bold","data-testid":"stat-templates",children:Ot.templatesCount})]}),e.jsx(ae,{className:"h-8 w-8 text-green-500"})]})})}),e.jsx(N,{children:e.jsx(b,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-500",children:"AI Usage"}),$t?e.jsx("div",{className:"h-8 w-12 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"}):e.jsxs("p",{className:"text-2xl font-bold","data-testid":"stat-ai-usage",children:[Ot.aiTrainingPercentage,"%"]})]}),e.jsx(yr,{className:"h-8 w-8 text-purple-500"})]})})})]}),e.jsx(Pe,{open:Q,onOpenChange:H,children:e.jsxs(Fe,{className:"max-w-3xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-5 w-5"}),"Content Preview"]}),e.jsx(Qe,{children:"Preview and manage your content"})]}),v&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:v.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(C,{children:v.category}),e.jsx(C,{variant:"secondary",children:v.phase}),v.aiGenerated&&e.jsxs(C,{variant:"outline",className:"flex items-center gap-1",children:[e.jsx(ze,{className:"h-3 w-3"}),"AI Generated"]})]})]}),e.jsx(js,{}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium mb-2",children:"Content"}),e.jsx("div",{className:"p-4 bg-gray-50 dark:bg-gray-900 rounded-lg",children:v.contentType==="image"?e.jsx("img",{src:v.content,alt:v.title,className:"w-full rounded"}):v.contentType==="video"?e.jsxs("div",{className:"aspect-video bg-gray-200 dark:bg-gray-800 rounded flex items-center justify-center",children:[e.jsx(Ct,{className:"h-12 w-12 text-gray-400"}),e.jsx("p",{className:"ml-2 text-gray-500",children:"Video Preview"})]}):e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:e.jsx(Fa,{remarkPlugins:[Aa],children:v.content})})})]}),v.tags&&v.tags.length>0&&e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium mb-2",children:"Tags"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:v.tags.map(t=>e.jsxs(C,{variant:"secondary",children:[e.jsx(bs,{className:"h-3 w-3 mr-1"}),t]},t))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Created"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:new Date(v.createdAt).toLocaleStr
42ing()})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Last Updated"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:v.updatedAt?new Date(v.updatedAt).toLocaleString():"Never"})]})]}),v.metadata&&e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium mb-2",children:"Metadata"}),e.jsx("div",{className:"p-3 bg-gray-50 dark:bg-gray-900 rounded text-sm",children:e.jsx("pre",{children:JSON.stringify(v.metadata,null,2)})})]})]}),e.jsxs(Ge,{className:"flex justify-between",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(n,{variant:"outline",onClick:()=>Nt((v==null?void 0:v.content)||""),children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Copy"]}),e.jsxs(n,{variant:"outline",children:[e.jsx(Ps,{className:"h-4 w-4 mr-2"}),"Edit"]}),e.jsxs(n,{variant:"outline",children:[e.jsx(Nr,{className:"h-4 w-4 mr-2"}),"Schedule"]})]}),e.jsxs(n,{variant:"destructive",onClick:()=>{v&&(qt(v.id),H(!1))},children:[e.jsx(Te,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})}),e.jsx(hi,{open:Me,onClose:()=>We(!1),initialText:Xt,onSave:t=>{a({title:"Voice-Over Saved!",description:"Your audio has been added to the content library."}),c.invalidateQueries({queryKey:["/api/content-library/items",l]})}}),e.jsx(Pe,{open:es,onOpenChange:Xe,children:e.jsxs(Fe,{className:"max-w-md",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"h-5 w-5"}),"Save Preset"]}),e.jsx(Qe,{children:"Save your current generation settings as a preset for quick access later."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"preset-name",children:"Preset Name *"}),e.jsx(L,{id:"preset-name",placeholder:"e.g., Social Media Promo, Email Newsletter...",value:Oe,onChange:t=>ct(t.target.value),"data-testid":"input-preset-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"preset-description",children:"Description (Optional)"}),e.jsx(Ee,{id:"preset-description",placeholder:"Brief description of when to use this preset...",value:o,onChange:t=>w(t.target.value),rows:2,"data-testid":"input-preset-description"})]}),e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Settings to save:"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-gray-600 dark:text-gray-400",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"h-3 w-3 text-green-500"}),"Content Type: ",x.contentType]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"h-3 w-3 text-green-500"}),"Tone: ",x.tone]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"h-3 w-3 text-green-500"}),"Temperature: ",x.temperature]}),x.avatarId&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"h-3 w-3 text-green-500"}),"Avatar Selected"]})]})]})]}),e.jsxs(Ge,{children:[e.jsx(n,{variant:"outline",onClick:()=>{Xe(!1),ct(""),w("")},children:"Cancel"}),e.jsx(n,{onClick:Vn,disabled:!Oe.trim()||cs.isPending,className:"bg-orange-500 hover:bg-orange-600","data-testid":"button-confirm-save-preset",children:cs.isPending?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save Preset"]})})]})]})}),e.jsx(Pe,{open:He,onOpenChange:y,children:e.jsxs(Fe,{className:"max-w-md",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(Ns,{className:"h-5 w-5"}),"Create Collection"]}),e.jsx(Qe,{children:"Create a new collection to organize your content"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"collection-name",children:"Collection Name *"}),e.jsx(L,{id:"collection-name",placeholder:"e.g., Social Media Posts, Email Campaigns...",value:U.name,onChange:t=>M(s=>({...s,name:t.target.value})),"data-testid":"input-collection-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"collection-description",children:"Description (Optional)"}),e.jsx(Ee,{id:"collection-description",placeholder:"Brief description of this collection...",value:U.description,onChange:t=>M(s=>({...s,description:t.target.value})),rows:2,"data-testid":"input-collection-description"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Color"}),e.jsx("div",{className:"flex gap-2",children:Da.map(t=>e.jsx("button",{type:"button",className:`w-8 h-8 rounded-full transition-all ${U.color===t.value?"ring-2 ring-offset-2 ring-gray-400":"hover:scale-110"}`,style:{backgroundColor:t.value},onClick:()=>M(s=>({...s,color:t.value})),title:t.label,"data-testid":`color-${t.name}`},t.name))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Icon"}),e.jsx("div",{className:"flex gap-2",children:Fs.map(t=>{const s=t.Icon;return e.jsx("button",{type:"button",className:`w-10 h-10 rounded-lg flex items-center justify-center transition-all ${U.icon===t.name?"bg-
42orange-100 dark:bg-orange-900 text-orange-600 ring-2 ring-orange-500":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"}`,onClick:()=>M(r=>({...r,icon:t.name})),title:t.label,"data-testid":`icon-${t.name}`,children:e.jsx(s,{className:"h-5 w-5"})},t.name)})})]})]}),e.jsxs(Ge,{children:[e.jsx(n,{variant:"outline",onClick:()=>{y(!1),M({name:"",description:"",color:"#6b7280",icon:"folder"})},children:"Cancel"}),e.jsx(n,{onClick:()=>is.mutate(U),disabled:!U.name.trim()||is.isPending,className:"bg-orange-500 hover:bg-orange-600","data-testid":"button-save-collection",children:is.isPending?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Create Collection"]})})]})]})}),e.jsx(Pe,{open:pe,onOpenChange:we,children:e.jsxs(Fe,{className:"max-w-md",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-5 w-5"}),"Edit Collection"]}),e.jsx(Qe,{children:"Update collection details"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"edit-collection-name",children:"Collection Name *"}),e.jsx(L,{id:"edit-collection-name",placeholder:"e.g., Social Media Posts, Email Campaigns...",value:U.name,onChange:t=>M(s=>({...s,name:t.target.value})),"data-testid":"input-edit-collection-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{htmlFor:"edit-collection-description",children:"Description (Optional)"}),e.jsx(Ee,{id:"edit-collection-description",placeholder:"Brief description of this collection...",value:U.description,onChange:t=>M(s=>({...s,description:t.target.value})),rows:2,"data-testid":"input-edit-collection-description"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Color"}),e.jsx("div",{className:"flex gap-2",children:Da.map(t=>e.jsx("button",{type:"button",className:`w-8 h-8 rounded-full transition-all ${U.color===t.value?"ring-2 ring-offset-2 ring-gray-400":"hover:scale-110"}`,style:{backgroundColor:t.value},onClick:()=>M(s=>({...s,color:t.value})),title:t.label},t.name))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(m,{children:"Icon"}),e.jsx("div",{className:"flex gap-2",children:Fs.map(t=>{const s=t.Icon;return e.jsx("button",{type:"button",className:`w-10 h-10 rounded-lg flex items-center justify-center transition-all ${U.icon===t.name?"bg-orange-100 dark:bg-orange-900 text-orange-600 ring-2 ring-orange-500":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"}`,onClick:()=>M(r=>({...r,icon:t.name})),title:t.label,children:e.jsx(s,{className:"h-5 w-5"})},t.name)})})]})]}),e.jsxs(Ge,{children:[e.jsx(n,{variant:"outline",onClick:()=>{we(!1),Je(null),M({name:"",description:"",color:"#6b7280",icon:"folder"})},children:"Cancel"}),e.jsx(n,{onClick:()=>{ue&&ls.mutate({id:ue.id,...U})},disabled:!U.name.trim()||ls.isPending,className:"bg-orange-500 hover:bg-orange-600","data-testid":"button-update-collection",children:ls.isPending?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2 animate-spin"}),"Updating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Update Collection"]})})]})]})}),e.jsx(Pe,{open:nn,onOpenChange:t=>{Ue||(mt(t),t||(ht(!1),Ze([]),Ve(0)))},children:e.jsxs(Fe,{className:"max-w-4xl max-h-[85vh] overflow-y-auto","data-testid":"dialog-bulk-generate",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(Rt,{className:"h-5 w-5 text-orange-500"}),"Bulk Generate Content Variants"]}),e.jsx(Qe,{children:"Generate multiple variations of your content for A/B testing"})]}),Ms?e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-medium flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5 text-green-500"}),"Generated Variants (",J.length,")"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(n,{variant:"outline",size:"sm",onClick:na,"data-testid":"button-save-all-variants",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save All to Library"]}),je==="ab-test"&&J.length>=2&&e.jsxs(n,{variant:"outline",size:"sm",onClick:()=>xt(!0),"data-testid":"button-compare-variants",children:[e.jsx(Rt,{className:"h-4 w-4 mr-2"}),"Compare Side by Side"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:J.map((t,s)=>e.jsxs(N,{className:"overflow-hidden","data-testid":`variant-card-${s}`,children:[e.jsxs(fe,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(ye,{className:"text-sm flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-orange-500 text-white flex items-center justify-center text-xs font-bold",children:String.fromCharCode(65+s)}),t.variantLabel]}),e.jsx("div",{className:"flex items-center gap-2",children:t.metrics&&e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"secondary",className:"text-xs",children:[t.metrics.wordCount," words"]}),e.jsx(C,{variant:"outline",className:`text-xs ${t.metrics.readabilityScore==="easy"?"text-green-600 border-green-300":t.metrics.readabilityScore==="moderate"?"text-yellow-600 border-yellow-300":"text-red-600 border-red-300"}`,children:t.metrics.readabilityScore})]})})]}),je==="ab-test"&&yt[s]&&e.jsx(Be,{className:"text-xs",children:yt[s].description})]}),e.jsxs(b,{className:"pb-3",children:[e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-3 mb-3 max-h-32 overflow-y-auto",children:e.jsx("p",{className:"text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap",children:t.output.length>300?`${t.output.substring(0,300)}...`:t.output})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(n,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>Pt(t),children:[e.jsx(_e,{className:"h-4 w-4 mr-1"}),"View Full"]}),e.jsxs(n,{size:"sm",className:"flex-1 bg-orange-500 hover:bg-orange-600",onClick:()=>ds(t),"data-testid":"button-use-variant",children:[e.jsx(te,{className:"h-4 w-4 mr-1"}),"Use This"]})]})]})]},t.id||s))}),e.jsx("div",{className:"flex justify-center pt-4",children:e.jsxs(n,{variant:"outline",onClick:()=>{ht(!1),Ze([]),Ve(0)},children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Generate More Variants"]})})]}):e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(m,{children:"Number of Variants"}),e.jsxs(C,{variant:"secondary",className:"text-sm font-medium",children:[ge," variant",ge>1?"s":""]})]}),e.jsx(Ts,{value:[ge],onValueChange:t=>on(t[0]),min:2,max:5,step:1,disabled:Ue,"data-testid":"slider-variant-count",className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-gray-500",children:[e.jsx("span",{children:"2"}),e.jsx("span",{children:"3"}),e.jsx("span",{children:"4"}),e.jsx("span",{children:"5"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{children:"Generation Mode"}),e.jsxs(Gr,{value:je,onValueChange:t=>cn(t),disabled:Ue,"data-testid":"select-variant-mode",className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:`flex items-start space-x-3 p-4 border rounded-lg cursor-pointer transition-all ${je==="variation"?"border-orange-500 bg-orange-50 dark:bg-orange-950":"border-gray-200 dark:border-gray-700 hover:border-gray-300"}`,children:[e.jsx(Ca,{value:"variation",id:"mode-variation"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(m,{htmlFor:"mode-variation",className:"text-sm font-medium cursor-pointer",children:"Variations"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Same prompt, different creative outputs"})]})]}),e.jsxs("div",{className:`flex items-start space-x-3 p-4 border rounded-lg cursor-pointer transition-all ${je==="ab-test"?"border-orange-500 bg-orange-50 dark:bg-orange-950":"border-gray-200 dark:border-gray-700 hover:border-gray-300"}`,children:[e.jsx(Ca,{value:"ab-test",id:"mode-abtest"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(m,{htmlFor:"mode-abtest",className:"text-sm font-medium cursor-pointer",children:"A/B Test"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Different approaches for testing"})]})]})]})]}),je==="ab-test"&&e.jsxs("div",{className:"space-y-2 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg",children:[e.jsx(m,{className:"text-sm",children:"Approaches to be generated:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:yt.slice(0,ge).map((t,s)=>e.jsxs(C,{variant:"outline",className:"text-xs",children:[String.fromCharCode(65+s),": ",t.label]},t.key))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(m,{className:"text-sm font-medium",children:"Current Generation Settings"}),e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-900 rounded-lg space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Content Type:"}),e.jsx("span",{className:"ml-2 font-medium",children:h||"Not set"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Tone:"}),e.jsx("span",{className:"ml-2 font-medium capitalize",children:x.tone})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Temperature:"}),e.jsx("span",{className:"ml-2 font-medium capitalize",children:x.temperature})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Avatar:"}),e.jsx("span",{className:"ml-2 font-medium",children:x.avatarId||"None"})]})]}),x.topic&&e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("span",{className:"text-gray-500 text-sm",children:"Topic:"}),e.jsx("p",{className:"mt-1 text-sm font-medium line-clamp-2",children:x.topic})]})]})]}),Ue&&e.jsxs("div",{className:"space-y-3 p-4 border border-orange-200 bg-orange-50 dark:bg-orange-950/50 dark:border-orange-900 rounded-lg","data-testid":"progress-bulk-generate",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4 animate-spin text-orange-500"}),e.jsxs("span",{className:"text-sm font-medium",children:["Generating variant ",Math.min(ln+1,ge)," of ",ge,"..."]})]}),e.jsxs(n,{variant:"ghost",size:"sm",onClick:Kn,className:"text-gray-500 hover:text-gray-700",children:[e.jsx(Ma,{className:"h-4 w-4 mr-1"}),"Cancel"]})]}),e.jsx(Ra,{value:rn,className:"h-2"})]})]}),!Ms&&e.jsxs(Ge,{children:[e.jsx(n,{variant:"outline",onClick:()=>mt(!1),disabled:Ue,children:"Cancel"}),e.jsx(n,{onClick:_n,disabled:Ue||!x.topic.trim(),className:"bg-orange-500 hover:bg-orange-600",children:Ue?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Generate ",ge," Variants"]})})]})]})}),e.jsx(Pe,{open:!!R,onOpenChange:t=>!t&&Pt(null),children:e.jsxs(Fe,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-5 w-5"}),R==null?void 0:R.variantLabel]}),(R==null?void 0:R.metrics)&&e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(C,{variant:"secondary",children:[R.metrics.wordCount," words"]}),e.jsxs(C,{variant:"outline",children:[R.metrics.sentenceCount," sentences"]}),e.jsxs(C,{variant:"outline",children:[R.metrics.readabilityScore," readability"]})]})]}),e.jsx("div",{className:"py-4",children:e.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:R==null?void 0:R.output})})}),e.jsxs(Ge,{children:[e.jsx(n,{variant:"outline",onClick:()=>Pt(null),children:"Close"}),e.jsxs(n,{variant:"outline",onClick:()=>{navigator.clipboard.writeText((R==null?void 0:R.output)||""),a({title:"Copied",description:"Content copied to clipboard"})},children:[e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Copy"]}),e.jsxs(n,{className:"bg-orange-500 hover:bg-orange-600",onClick:()=>{ds(R),Pt(null)},children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Use This Variant"]})]})]})}),e.jsx(Pe,{open:dn,onOpenChange:xt,children:e.jsxs(Fe,{className:"max-w-7xl w-[95vw] max-h-[90vh] overflow-hidden flex flex-col","data-testid":"dialog-compare-variants",children:[e.jsxs(Ae,{className:"flex-shrink-0",children:[e.jsxs(Ie,{className:"flex items-center gap-2 text-xl",children:[e.jsx(Rt,{className:"h-6 w-6 text-orange-500"}),"Compare Content Variants"]}),e.jsxs(Qe,{className:"text-base",children:["Compare ",J.length," variant",J.length!==1?"s":""," side by side to find the best content for your needs"]})]}),e.jsx(vs,{className:"flex-1 -mx-6 px-6",children:e.jsx("div",{className:"py-4",children:e.jsx("div",{className:`grid gap-4 ${J.length===2?"md:grid-cols-2":J.length>=3?"md:grid-cols-2 lg:grid-cols-3":"grid-cols-1"}`,children:J.map((t,s)=>{var T,z,ve,Se;const r=Qn(s),j=je==="ab-test"?yt[s]:null;return e.jsxs(N,{className:`flex flex-col border-2 transition-all hover:shadow-lg ${r.border}`,"data-testid":`compare-variant-${s}`,children:[e.jsxs(fe,{className:`pb-3 ${r.headerBg}`,children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:`${r.bg} text-white font-bold px-2.5 py-1`,children:String.fromCharCode(65+s)}),e.jsx(ye,{className:"text-base font-semibold",children:t.variantLabel})]})}),j&&e.jsxs("div",{className:"mt-2",children:[e.jsx("span",{className:`text-sm font-medium ${r.text}`,children:j.label}),e.jsx(Be,{className:"text-xs mt-0.5",children:j.description})]})]}),e.jsxs(b,{className:"flex-1 flex flex-col pt-3",children:[e.jsx(vs,{className:"flex-1 h-48 md:h-56 lg:h-64 roun
42ded-lg border bg-gray-50 dark:bg-gray-900 p-3",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap text-gray-700 dark:text-gray-300 leading-relaxed",children:t.output})}),e.jsxs("div",{className:"mt-3 pt-3 border-t",children:[e.jsx("div",{className:"text-xs font-medium text-gray-500 mb-2",children:"Metrics"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(ae,{className:"h-3.5 w-3.5 text-gray-400"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Words:"}),e.jsx("span",{className:"font-medium",children:((T=t.metrics)==null?void 0:T.wordCount)||0})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(bs,{className:"h-3.5 w-3.5 text-gray-400"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Chars:"}),e.jsx("span",{className:"font-medium",children:((z=t.metrics)==null?void 0:z.charCount)||0})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(wa,{className:"h-3.5 w-3.5 text-gray-400"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Sentences:"}),e.jsx("span",{className:"font-medium",children:((ve=t.metrics)==null?void 0:ve.sentenceCount)||0})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(ei,{className:"h-3.5 w-3.5 text-gray-400"}),e.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:"Readability:"}),e.jsx("span",{className:"font-medium",children:((Se=t.metrics)==null?void 0:Se.readability)||"N/A"})]})]})]}),e.jsxs(n,{className:`w-full mt-3 ${r.bg} hover:opacity-90 text-white`,onClick:()=>Jn(t,s),"data-testid":`button-select-variant-${s}`,children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Select This One"]})]})]},t.id||s)})})})}),e.jsx(js,{className:"my-2"}),e.jsxs(Ge,{className:"flex-shrink-0 flex-col sm:flex-row gap-2 sm:gap-0",children:[e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto",children:[e.jsxs(n,{variant:"outline",onClick:Hn,className:"flex-1 sm:flex-none","data-testid":"button-export-comparison",children:[e.jsx(_t,{className:"h-4 w-4 mr-2"}),"Export All"]}),e.jsxs(n,{variant:"outline",onClick:na,className:"flex-1 sm:flex-none",children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Save All to Library"]})]}),e.jsxs("div",{className:"flex gap-2 w-full sm:w-auto sm:ml-auto",children:[e.jsxs(n,{variant:"outline",onClick:Wn,className:"flex-1 sm:flex-none",children:[e.jsx(Ne,{className:"h-4 w-4 mr-2"}),"Generate More"]}),e.jsx(n,{variant:"outline",onClick:()=>xt(!1),className:"flex-1 sm:flex-none",children:"Close"})]})]})]})})]})}export{tl as default};
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.