PageSourceSearch

https://sociovia.ai/assets/AdStudio-agxVP6YW.js

js sociovia.ai collected 2026-10-05 13:37:00 UTC 49,082 bytes, 4 lines download raw bytes

1import{aE as is,r as c,j as e,B as O,a7 as ds,E as V,b9 as he,o as ce,aR as cs,b1 as Ze,L as T,X as ae,G as je,aN as d,Z as ms,c as xs,m as b,g as Ne,I as Ye,d as Je,A as me,aG as Ke,a3 as Xe,C as Qe,F as us,aa as hs,aV as gs,ag as ps}from"./index-CZbe8K7G.js";import{B as D}from"./badge-CGfHTdwf.js";import{T as fs}from"./textarea-_LI_mWhq.js";import{I as $e}from"./input-DHFvAwYM.js";import{S as Ie,a as Ee,b as Be,c as Le,d as Me}from"./select-BXCURI_Z.js";import{T as bs,a as vs,b as Oe}from"./tabs-CucJzqku.js";import{g as es,r as js,b as Ns,n as ys,c as ws,d as ks,e as Cs,t as Ss,v as _s,f as As}from"./api-B9J4_fPQ.js";import{s as ss}from"./svAuthHeaders-DqkSxtim.js";import{I as Rs}from"./image-plus-3bz-Twgw.js";import{I as Ge}from"./image-CILA0ZUd.js";import{P as Ts}from"./pencil-CKgtdzXg.js";import{D as Ps}from"./download-Dm5B4mgI.js";import{S as $s}from"./sun-DVLjh-Gq.js";import{T as Is}from"./type-7rmkZb8r.js";import{C as Es}from"./crop-9rH1_gFJ.js";import{I as Bs}from"./images-BqjtYN-Z.js";import{R as ze}from"./rotate-ccw-DobbIZSj.js";import{B as De}from"./bookmark-rSxgd9Q_.js";import{C as fe}from"./compass-FJENhR02.js";import{I as Ve}from"./info-CvoueSrA.js";import{C as Ls}from"./clock-DBDuGPpk.js";import{H as Ms}from"./history-kAvbkWiQ.js";import{L as Os}from"./lightbulb-Bx172IJR.js";import{T as Gs}from"./trophy-Cr-249yU.js";import{M as zs}from"./maximize-2-CGpbQxI-.js";import"./index-BdQq_4o_.js";import"./chevron-up-B7XG24j4.js";import"./useQuery-bAi4J6nk.js";import"./useMutation-Bi4UUmTv.js";const ts=`${is}/api/adstudio/v2`,Ds=()=>Number(es()||0);async function be(s){const r=await fetch(`${ts}${s}`,{credentials:"include",headers:ss()});if(!r.ok)throw new Error(`${s} ${r.status}`);return r.json()}async function ve(s,r){const i=await fetch(`${ts}${s}`,{method:"POST",headers:{"Content-Type":"application/json",...ss()},credentials:"include",body:JSON.stringify({workspace_id:Ds(),...r})});if(!i.ok)throw new Error(`${s} ${i.status}`);return i.json()}const se={health:()=>be("/health"),commands:s=>be(`/commands${s?`?business=${encodeURIComponent(s)}`:""}`),generate:s=>ve("/generate",s),topPerforming:s=>ve("/topperforming",s),edit:s=>ve("/edit",s),session:s=>be(`/session/${encodeURIComponent(s)}`)},Vs=["general","bakery","restaurant","cafe","saas","fashion","jewelry","ecommerce","realestate","fitness","beauty","travel","education"],Fs=["1:1","4:5","9:16","16:9","4:3","3:2"],Us=[{key:"enhance",label:"Enhance",command:"/enhance"},{key:"relight",label:"Relight",command:"/relight"},{key:"background",label:"New background",command:"/background"},{key:"addtext",label:"Add text",command:"/addtext"},{key:"reframe_9x16",label:"→ 9:16 Story",command:"/reframe"}],te="#34b233",qs=10*60*1e3,Fe=new Map;async function Hs(s){const r=Fe.get(s);if(r&&Date.now()-r.ts<qs)return r.data;const i=await se.commands(s);return(i==null?void 0:i.ok)!==!1&&Fe.set(s,{data:i,ts:Date.now()}),i}function Ws({onBack:s}){const[r,i]=c.useState(null),[h,k]=c.useState(null),[x,j]=c.useState("general"),[l,p]=c.useState("ideate"),[f,_]=c.useState(""),[o,u]=c.useState(5),[C,A]=c.useState("4:5"),[g,I]=c.useState([]),[E,ge]=c.useState(!1),[N,Y]=c.useState(!1),[P,R]=c.useState([]),[S,B]=c.useState(null),[$,J]=c.useState(null),[re,K]=c.useState(null),[L,F]=c.useState(""),[U,ne]=c.useState(null);c.useEffect(()=>{se.health().then(i).catch(()=>{})},[]),c.useEffect(()=>{Hs(x).then(t=>{k(t),I([])}).catch(()=>{})},[x]);const oe=(h==null?void 0:h.pack)??[],G=(r==null?void 0:r.effective_backend)??"",X=(r==null?void 0:r.max_images)??24,q=t=>I(w=>w.includes(t)?w.filter(v=>v!==t):[...w,t].slice(0,X));async function Q(){if(!f.trim()&&l==="ideate"){d.error("Add a brief (what to advertise).");return}if(l==="commands"&&g.length===0){d.error("Pick at least one command.");return}Y(!0),R([]),B(null),J(null);try{let t;if(l==="ideate")t=await se.topPerforming({subject:f.trim(),count:o,aspect_ratio:C,use_business_context:!0});else{const v=g.map(y=>({command:`/${y}`,subject:f.trim(),count:1,aspect_ratio:C}));t=await se.generate({jobs:v,grounded:!0})}if(!t.ok){J(t.error||"Generation failed. Try a smaller batch or a simpler brief."),d.error(t.error||"Generation failed");return}B(t),R(t.assets||[]);const w=t.real??(t.assets||[]).filter(v=>!v.mock).length;t.backend_note&&d.warning(t.backend_note),(t.assets||[]).length===0?d.warning("Generation finished but returned no images."):d.success(`${w} creative${w===1?"":"s"} generated${t.brand_name?` for ${t.brand_name}`:""}.`)}catch{J("Could not reach the generator. Large batches can exceed a short timeout — the server keeps working and the images still land in your library."),d.error("Could not reach the generator.")}finally{Y(!1)}}async function z(t,w){ne(t.id);try{const v=await se.edit({image_url:t.url,...w});if(!v.ok||!v.asset){d.error(v.error||"Edit failed");return}const y={...v.asset,source_url:v.asset.source_url||t.url};R(pe=>[y,...pe]),d.success("Edited variant added."),K(null),F("")}catch{d.error("Edit request failed.")}finally{ne(null)}}const le=t=>t==="enhance"?e.jsx(ms,{className:"h-3.5 w-3.5"}):t==="relight"?e.jsx($s,{className:"h-3.5 w-3.5"}):t==="background"?e.jsx(Ge,{className:"h-3.5 w-3.5"}):t==="addtext"?e.jsx(Is,{className:"h-3.5 w-3.5"}):e.jsx(Es,{className:"h-3.5 w-3.5"});return e.jsx("div",{style:{"--sv-green":te},className:"min-h-screen bg-background",children:e.jsxs("div",{className:"mx-auto max-w-7xl px-4 py-6 sm:px-6 sm:py-8 lg:px-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[s&&e.jsxs(O,{variant:"ghost",size:"sm",onClick:s,className:"gap-1.5",children:[e.jsx(ds,{className:"h-4 w-4"})," Classic"]}),e.jsx("div",{className:"grid h-11 w-11 shrink-0 place-items-center rounded-2xl text-white shadow-sm",style:{backgroundColor:"var(--sv-green)"},children:e.jsx(V,{className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl font-bold text-foreground",children:"Ad Studio v2 — Bulk & Campaigns"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ideate ad sets, batch-generate on-brand creatives, refine any image."})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[G&&e.jsxs(D,{variant:"secondary",className:"gap-1",children:[e.jsx(he,{className:"h-3 w-3"})," ",G==="openai"?"gpt-image-2":G]}),h&&e.jsxs(D,{variant:"outline",children:[h.count," commands"]})]})]}),e.jsxs(ce,{className:"mt-6 p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs(Ie,{value:x,onValueChange:j,children:[e.jsx(Ee,{className:"h-9 w-[190px]",children:e.jsx(Be,{placeholder:"Business type"})}),e.jsx(Le,{children:Vs.map(t=>e.jsx(Me,{value:t,children:t[0].toUpperCase()+t.slice(1)},t))})]})]}),e.jsx(bs,{value:l,onValueChange:t=>p(t),children:e.jsxs(vs,{children:[e.jsxs(Oe,{value:"ideate",className:"gap-1.5",children:[e.jsx(V,{className:"h-3.5 w-3.5"})," Campaign ideas"]}),e.jsxs(Oe,{value:"commands",className:"gap-1.5",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"})," Creative types"]})]})}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Count"}),e.jsx($e,{type:"number",min:1,max:X,value:o,onChange:t=>u(Math.max(1,Math.min(X,Number(t.target.value)||1))),className:"h-9 w-16"}),e.jsxs(Ie,{value:C,onValueChange:A,children:[e.jsx(Ee,{className:"h-9 w-[92px]",children:e.jsx(Be,{})}),e.jsx(Le,{children:Fs.map(t=>e.jsx(Me,{value:t,children:t},t))})]})]})]}),e.jsx(fs,{value:f,onChange:t=>_(t.target.value),placeholder:l==="ideate"?"What are we advertising? e.g. “launch of our AI ad-automation platform” — headlines & angles are written for you.":"Optional subject/brief applied to each picked command (e.g. “our flagship product”).",className:"mt-3 min-h-[76px]"}),l==="commands"&&e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:E?"All commands":`${x} pack`}),e.jsx(O,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>ge(t=>!t),children:E?"Show pack":"Browse all"}),g.length>0&&e.jsxs(D,{variant:"secondary",children:[g.length," selected"]})]}),E?e.jsx("div",{className:"max-h-64 space-y-3 overflow-y-auto pr-1",children:Object.entries((h==null?void 0:h.categories)??{}).map(([t,w])=>e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-[11px] font-semibold text-muted-foreground",children:t}),e.jsx("div",{className:"flex flex-wrap gap-2",children:w.map(v=>e.jsx(Ue,{c:v,on:g.includes(v.name),onClick:()=>q(v.name)}
1,v.name))})]},t))}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[oe.map(t=>e.jsx(Ue,{c:t,on:g.includes(t.name),onClick:()=>q(t.name)},t.name)),oe.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"No pack loaded."})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-3",children:[e.jsxs(O,{onClick:Q,disabled:N,className:"gap-2 text-white",style:{backgroundColor:"var(--sv-green)"},children:[N?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(Rs,{className:"h-4 w-4"}),N?"Generating…":l==="ideate"?`Generate ${o} ad set`:`Generate ${g.length||""} creatives`]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"gpt-image-2 · ~30s/image · on-brand + logo · saved to your library"})]})]}),N&&P.length===0&&e.jsxs("div",{className:"mt-10 flex flex-col items-center gap-3 text-muted-foreground",children:[e.jsx(T,{className:"h-7 w-7 animate-spin",style:{color:te}}),e.jsx("p",{className:"text-sm",children:"Ideating concepts & rendering on-brand creatives…"})]}),$&&!N&&e.jsx(ce,{className:"mt-8 border-destructive/40 bg-destructive/5 p-4",children:e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:$})]})}),S&&!N&&P.length>0&&e.jsxs("div",{className:"mt-8 flex flex-wrap items-center gap-2",children:[S.business_grounded&&e.jsxs(D,{className:"gap-1 text-white",style:{backgroundColor:te},children:[e.jsx(je,{className:"h-3 w-3"})," On-brand",S.brand_name?` · ${S.brand_name}`:""]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[S.real??P.filter(t=>!t.mock).length," of ",P.length," rendered"]}),S.backend_note&&e.jsx("span",{className:"text-xs text-amber-600 dark:text-amber-400",children:S.backend_note})]}),S&&!N&&P.length===0&&e.jsxs(ce,{className:"mt-8 p-8 text-center",children:[e.jsx(Ge,{className:"mx-auto h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"mt-2 text-sm font-medium text-foreground",children:"No images came back"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"The request succeeded but returned no creatives. Try a smaller count or a clearer brief — and check your library, where images render durably even if a call times out."})]}),P.length>0&&e.jsx("div",{className:"mt-4 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3",children:P.map(t=>{var w,v;return e.jsxs(ce,{className:"overflow-hidden",children:[e.jsxs("div",{className:"relative bg-muted",children:[e.jsx("img",{src:t.url,alt:t.command||"creative",className:"w-full object-cover",loading:"lazy"}),t.mock&&e.jsx(D,{className:"absolute left-2 top-2",variant:"destructive",children:"preview"}),t.source_url&&e.jsx(D,{className:"absolute left-2 top-2",variant:"secondary",children:"edited"})]}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:"outline",className:"text-[10px]",children:t.command||"creative"}),t.aspect_ratio&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:t.aspect_ratio})]}),((w=t.concept)==null?void 0:w.headline)&&e.jsxs("div",{className:"mt-1 truncate text-sm font-semibold text-foreground",title:t.concept.headline,children:["“",t.concept.headline,"”"]}),((v=t.concept)==null?void 0:v.angle)&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:t.concept.angle}),!t.mock&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[Us.map(y=>e.jsxs(O,{size:"sm",variant:"secondary",className:"h-7 gap-1 px-2 text-[11px]",disabled:U===t.id,onClick:()=>z(t,y.key==="reframe_9x16"?{command:y.command,aspect_ratio:"9:16"}:{command:y.command,instruction:y.instruction}),children:[U===t.id?e.jsx(T,{className:"h-3 w-3 animate-spin"}):le(y.key)," ",y.label]},y.key)),e.jsxs(O,{size:"sm",variant:"secondary",className:"h-7 gap-1 px-2 text-[11px]",onClick:()=>{K(re===t.id?null:t.id),F("")},children:[e.jsx(Ts,{className:"h-3.5 w-3.5"})," Refine"]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer",children:e.jsxs(O,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-[11px]",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"})," Open"]})})]}),re===t.id&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx($e,{autoFocus:!0,value:L,onChange:y=>F(y.target.value),placeholder:"Describe the change… e.g. warmer tones, add a 20% OFF badge",className:"h-8 text-xs",onKeyDown:y=>{y.key==="Enter"&&L.trim()&&z(t,{instruction:L.trim()})}}),e.jsx(O,{size:"sm",className:"h-8 px-2 text-white",style:{backgroundColor:te},disabled:!L.trim()||U===t.id,onClick:()=>z(t,{instruction:L.trim()}),children:U===t.id?e.jsx(T,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(je,{className:"h-3.5 w-3.5"})}),e.jsx(O,{size:"sm",variant:"ghost",className:"h-8 px-2",onClick:()=>K(null),children:e.jsx(ae,{className:"h-3.5 w-3.5"})})]})]})]},t.id)})})]})})}function Ue({c:s,on:r,onClick:i}){return e.jsxs("button",{onClick:i,title:s.description,className:`rounded-full border px-3 py-1 text-xs transition ${r?"border-transparent text-white":"border-border bg-card text-foreground hover:bg-muted"}`,style:r?{backgroundColor:te}:void 0,children:[r&&e.jsx(je,{className:"mr-1 inline h-3 w-3"}),s.name]})}const ue=[.16,1,.3,1],Z={hidden:{opacity:0,y:16},show:(s=0)=>({opacity:1,y:0,transition:{delay:s*.05,duration:.45,ease:ue}})},as={hidden:{},show:{transition:{staggerChildren:.05}}},rs={hidden:{opacity:0,y:18,scale:.96},show:{opacity:1,y:0,scale:1,transition:{duration:.45,ease:ue}}},Zs="#34b233",Ys="#2c9a2b",qe=s=>s==null||Number.isNaN(s)?null:Math.max(0,Math.min(100,Math.round(Math.abs(s)<=1?s*100:s))),Js=s=>{if(s==null||Number.isNaN(s))return null;const r=Math.round(Math.abs(s)<=1?s*100:s);return`${r>0?"+":""}${r}%`},ye=s=>{if(!s)return null;const r=s.toLowerCase();return r.includes("pro-image")?"Pro":r.includes("flash-image")?"Flash":r.includes("imagen")?"Imagen":s.length>10?"Gen":s};function Pt(){var we,ke,Ce,Se,_e,Ae,Re,Te;const s=es(),i=(we=xs().state)==null?void 0:we.brief,[h,k]=c.useState(!1),[x,j]=c.useState(i??""),[l,p]=c.useState(3),[f,_]=c.useState(!0),[o,u]=c.useState(null),[C,A]=c.useState(null),[g,I]=c.useState(null),[E,ge]=c.useState("all"),[N,Y]=c.useState(null),[P,R]=c.useState(!1),S=js(),B=Ns(),$=ys(s,48);c.useEffect(()=>{i&&j(i)},[i]);const J=()=>{if(!x.trim()){d.error("Add a brief",{description:"Describe the product, audience, and goal."});return}S.mutate({brief:x.trim(),variation_count:l,mode:f?"launch":"dry_run"},{onSuccess:a=>{var m,M;if(!(a!=null&&a.session_id)){d.error("Run failed");return}u(a);const n=(a.ad_rooms||[]).reduce((de,ee)=>{var Pe;return de+(((Pe=ee.candidates)==null?void 0:Pe.length)||0)},0);d.success("Ad Room ready",{description:`${((M=(m=a.plan)==null?void 0:m.ad_sets)==null?void 0:M.length)||0} ad set(s) · ${n} ranked variations.`}),$.refetch()},onError:()=>d.error("Run failed",{description:"Pick a workspace + try again."})})},re=async(a,n)=>{if(o){u({...o,ad_rooms:(o.ad_rooms||[]).map(m=>m.ad_set_ref!==a.ad_set_ref?m:{...m,candidates:m.candidates.map(M=>({...M,selected:M.asset.id===n}))})});try{await Ss(o.session_id,a.ad_set_ref,n)}catch{}}},K=async a=>{if(o){if(o.mode!=="launch"){d.info("Prepare-only run",{description:"Enable Launch mode in the composer, re-run, then publish."});return}if(window.confirm(`Publish "${a.ad_set_ref}" as a LIVE Meta ad now?
2
3This creates an ACTIVE ad and will spend budget. This cannot be undone from here.`)){A(a.ad_set_ref);try{const n=await _s(o.session_id,a.ad_set_ref);n!=null&&n.ok?d.success("Launched",{description:`"${a.ad_set_ref}" sent to Meta.`}):d.error("Launch blocked",{description:(n==null?void 0:n.error)||"Could not launch."})}catch{d.error("Launch failed")}finally{A(null)}}}},L=a=>{j(a||""),I(null),window.scrollTo({top:0,behavior:"smooth"}),d.message("Prompt loaded into the brief — tweak + run.")},F=()=>
3{if(!s){d.error("Pick a workspace first");return}R(!0),B.mutate({ws:s,brief:x.trim()||void 0},{onSuccess:a=>{if(!(a!=null&&a.summary)){d.error("Couldn't generate strategy");return}Y(a),d.success("Marketing strategy ready",{description:a.generated_by==="gemini"?"Grounded in your live data.":"Prepared from your workspace."})},onError:()=>d.error("Couldn't generate strategy",{description:"Pick a workspace + try again."})})},U=a=>{var m,M,de;const n=[];return a.summary&&n.push(a.summary),(m=a.target_audience)!=null&&m.length&&n.push(`Audience: ${a.target_audience.map(ee=>ee.segment).join(", ")}.`),(M=a.creative_angles)!=null&&M.length&&n.push(`Angle: ${a.creative_angles[0].hook}`),(de=a.channels)!=null&&de.length&&n.push(`Channels: ${a.channels.map(ee=>ee.channel).join(", ")}.`),n.join(" ").trim()},ne=()=>{N&&(j(U(N)),R(!1),window.scrollTo({top:0,behavior:"smooth"}),d.message("Strategy loaded into the brief — review + Run Ad Room."))},[oe,G]=c.useState(null),[X,q]=c.useState(!1),Q=ws(s),z=ks(),le=Cs(),t=((ke=Q.data)==null?void 0:ke.items)||[],w=async()=>{var a;if(!(!N||!s))try{const n=await z.mutateAsync({ws:s,strategy:N,label:(N.summary||"").trim().slice(0,60)||void 0,brief:x.trim()||void 0,source:"ad_studio"});n!=null&&n.ok?(G(((a=n.saved)==null?void 0:a.id)??null),await Q.refetch(),d.success("Strategy saved",{description:"Reload it anytime from Saved."})):d.error("Couldn't save strategy",{description:n==null?void 0:n.error})}catch{d.error("Couldn't save strategy")}},v=async a=>{var n;if(s){q(!1),R(!0);try{const m=await As(s,a);m!=null&&m.ok&&((n=m.saved)!=null&&n.strategy)?(Y({workspace_id:Number(s)||0,generated_by:m.saved.generated_by||"fallback",...m.saved.strategy}),G(a),d.success("Strategy loaded")):d.error("Couldn't load strategy",{description:m==null?void 0:m.error})}catch{d.error("Couldn't load strategy")}}},y=async a=>{if(s)try{const n=await le.mutateAsync({ws:s,id:a});n!=null&&n.ok?(oe===a&&G(null),await Q.refetch(),d.success("Deleted")):d.error("Couldn't delete",{description:n==null?void 0:n.error})}catch{d.error("Couldn't delete")}},pe=((Ce=o==null?void 0:o.ranking)==null?void 0:Ce.absolute_suppressed)!==!1,ie=S.isPending,os=((o==null?void 0:o.ad_rooms)||[]).reduce((a,n)=>{var m;return a+(((m=n.candidates)==null?void 0:m.length)||0)},0),H=((Se=$.data)==null?void 0:Se.items)??[],ls=c.useMemo(()=>E==="all"?H:H.filter(a=>a.source===E),[H,E]);return h?e.jsx(Ws,{onBack:()=>k(!1)}):e.jsxs("div",{className:"min-h-screen bg-background text-foreground",style:{"--sv-green":Zs,"--sv-green-strong":Ys},children:[e.jsxs("div",{className:"mx-auto max-w-7xl px-4 py-6 sm:px-6 sm:py-8 lg:px-8",children:[e.jsxs(b.header,{variants:Z,initial:"hidden",animate:"show",className:"mb-6 flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"grid h-11 w-11 shrink-0 place-items-center rounded-2xl text-white shadow-sm",style:{backgroundColor:"var(--sv-green)"},children:e.jsx(he,{className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight sm:text-3xl",children:"Ad Room"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Brief → strategy → on-brand variations → audience-ranked → pick a winner → launch."})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>k(!0),className:"inline-flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-semibold text-white shadow-sm transition hover:opacity-90",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(V,{className:"h-4 w-4"})," ",e.jsx("span",{className:"hidden sm:inline",children:"Bulk & Campaigns"}),e.jsx("span",{className:"sm:hidden",children:"v2"})]}),e.jsxs(Ne,{to:"/creatives",className:"inline-flex items-center gap-1.5 rounded-xl border border-border bg-card px-3 py-2 text-sm font-medium text-foreground shadow-sm transition hover:bg-muted",children:[e.jsx(Bs,{className:"h-4 w-4 text-muted-foreground"})," ",e.jsx("span",{className:"hidden sm:inline",children:"Library"})]}),e.jsxs(Ne,{to:"/societies/test",className:"inline-flex items-center gap-1.5 rounded-xl border px-3 py-2 text-sm font-medium shadow-sm transition hover:brightness-105",style:{borderColor:"color-mix(in srgb, var(--sv-green) 45%, transparent)",color:"var(--sv-green-strong)",backgroundColor:"color-mix(in srgb, var(--sv-green) 10%, transparent)"},children:[e.jsx(Ye,{className:"h-4 w-4"})," ",e.jsx("span",{className:"hidden sm:inline",children:"Test with"})," Audience ",e.jsx(Je,{className:"h-3.5 w-3.5 opacity-60"})]})]})]}),e.jsxs(b.div,{variants:Z,initial:"hidden",animate:"show",custom:1,className:"rounded-3xl border border-border bg-card p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("label",{className:"block text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground",children:"Creative brief"}),x&&e.jsxs("button",{onClick:()=>j(""),className:"inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground transition hover:text-foreground",children:[e.jsx(ze,{className:"h-3 w-3"})," Clear"]})]}),e.jsx("textarea",{value:x,onChange:a=>j(a.target.value),rows:3,placeholder:"Product/service, audience, key benefit, tone, and CTA. e.g. Sociovia AI automates Meta+Google ads end-to-e
3nd for SMBs — bold, results-driven, CTA: Book a Free Demo.",className:"w-full resize-none rounded-2xl border border-border bg-background p-3.5 text-sm text-foreground outline-none transition placeholder:text-muted-foreground focus:border-[color:var(--sv-green)] focus:ring-4 focus:ring-[color:var(--sv-green)]/15"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ze,{className:"h-4 w-4"})," Variations / ad set",e.jsx("select",{value:l,onChange:a=>p(Number(a.target.value)),className:"rounded-lg border border-border bg-background px-2.5 py-1.5 text-sm font-medium text-foreground outline-none focus:border-[color:var(--sv-green)]",children:[2,3,4,5].map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("label",{className:`flex cursor-pointer select-none items-center gap-2 rounded-lg border px-2.5 py-1.5 text-sm font-medium transition
4              ${f?"border-rose-300 bg-rose-50 text-rose-700 dark:border-rose-500/40 dark:bg-rose-500/10 dark:text-rose-300":"border-border bg-background text-muted-foreground"}`,children:[e.jsx("input",{type:"checkbox",checked:f,onChange:a=>_(a.target.checked),className:"accent-rose-600"}),"Launch mode"]}),t.length>0&&e.jsxs("div",{className:"relative ml-auto",children:[e.jsxs(b.button,{whileTap:{scale:.97},onClick:()=>q(a=>!a),className:"inline-flex items-center gap-2 rounded-2xl border border-border bg-background px-3.5 py-2.5 text-sm font-semibold text-foreground transition hover:border-foreground
4/30",children:[e.jsx(De,{className:"h-4 w-4",style:{color:"var(--sv-green)"}})," Saved",e.jsx("span",{className:"rounded-full border border-border bg-muted px-1.5 text-[11px] font-medium text-muted-foreground",children:t.length})]}),e.jsx(me,{children:X&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>q(!1)}),e.jsxs(b.div,{initial:{opacity:0,y:-6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},transition:{duration:.16},className:"absolute right-0 z-50 mt-2 max-h-72 w-72 overflow-auto rounded-2xl border border-border bg-card p-2 shadow-xl",children:[e.jsx("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Saved strategies"}),t.map(a=>e.jsxs("div",{className:"group flex items-center gap-2 rounded-xl px-2 py-1.5 hover:bg-muted/60",children:[e.jsxs("button",{onClick:()=>v(a.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",title:"Load this strategy",children:[e.jsx(fe,{className:"h-3.5 w-3.5 flex-none",style:{color:"var(--sv-green)"}}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-foreground",children:a.label||a.summary||`Strategy #${a.id}`}),a.created_at&&e.jsx("span",{className:"block text-[10px] text-muted-foreground",children:new Date(a.created_at).toLocaleDateString("en-IN",{day:"numeric",month:"short"})})]})]}),e.jsx("button",{onClick:()=>y(a.id),disabled:le.isPending,title:"Delete",className:"flex-none rounded-md p-1 text-muted-foreground/50 transition hover:text-rose-500 disabled:opacity-40",children:e.jsx(ae,{className:"h-3.5 w-3.5"})})]},a.id))]})]})})]}),e.jsxs(b.button,{whileTap:{scale:.97},onClick:F,disabled:B.isPending||!s,className:`${t.length>0?"":"ml-auto"} inline-flex items-center gap-2 rounded-2xl border px-4 py-2.5 text-sm font-semibold transition hover:brightness-105 disabled:opacity-60`,style:{borderColor:"color-mix(in srgb, var(--sv-green) 45%, transparent)",color:"var(--sv-green-strong)",backgroundColor:"color-mix(in srgb, var(--sv-green) 10%, transparent)"},children:[B.isPending?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(fe,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Generate"})," Strategy"]}),e.jsxs(b.button,{whileTap:{scale:.97},onClick:J,disabled:ie,className:"inline-flex items-center gap-2 rounded-2xl px-5 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:brightness-105 disabled:opacity-60",style:{backgroundColor:f?"#e11d48":"var(--sv-green)"},children:[ie?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(V,{className:"h-4 w-4"}),ie?"Generating…":f?"Run (Launch mode)":"Run Ad Room"]})]}),f&&e.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-xs font-medium text-rose-600 dar
4k:text-rose-400",children:[e.jsx(Ve,{className:"h-3.5 w-3.5"}),` Launch mode is on by default — ad rooms can publish live to Meta (spends budget); you'll confirm before each publish. Uncheck "Launch mode" to stay in prepare-only (draft, no spend).`]})]}),e.jsx(me,{children:ie&&!o&&e.jsxs(b.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"mt-6 flex items-center justify-center gap-3 rounded-3xl border border-dashed border-border bg-card/50 py-20 text-muted-foreground",children:[e.jsx(T,{className:"h-5 w-5 animate-spin",style:{color:"var(--sv-green)"}}),"Strategy → on-brand images → audience ranking…"]})}),o&&e.jsxs("div",{className:"mt-6 space-y-6",children:[o.plan&&e.jsxs(b.div,{variants:Z,initial:"hidden",animate:"show",className:"rounded-3xl border border-border bg-card p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4",style:{color:"var(--sv-green)"}}),e.jsx("h2",{className:"font-semibold",children:"Strategy"}),e.jsxs("span",{className:"ml-auto text-xs text-muted-foreground",children:[((_e=o.ad_rooms)==null?void 0:_e.length)||0," ad room",(((Ae=o.ad_rooms)==null?void 0:Ae.length)||0)===1?"":"s"," · ",os," variations"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(xe,{label:"Objective",value:o.plan.objective||"—"}),e.jsx(xe,{label:"Budget",value:`${o.plan.budget_type||""} ₹${o.plan.daily_budget??"—"}/day`.trim()}),e.jsx(xe,{label:"Ad sets",value:String(((Re=o.plan.ad_sets)==null?void 0:Re.length)||0)}),e.jsx(xe,{label:"Mode",value:o.mode,tone:o.mode==="launch"?"warn":"default"})]})]}),pe&&e.jsxs(b.div,{variants:Z,initial:"hidden",animate:"show",className:"flex items-start gap-2 rounded-2xl border border-border bg-muted p-3 text-xs text-muted-foreground",children:[e.jsx(Ve,{className:"mt-0.5 h-4 w-4 flex-none"}),e.jsxs("span",{children:["Rankings are ",e.jsx("b",{className:"mx-0.5 text-foreground",children:"relative-only"})," — the workspace isn't calibrated yet, so the audience simulator shows order + directional bands, not absolute metrics."]})]}),(o.ad_rooms||[]).map((a,n)=>e.jsx(Xs,{room:a,index:n,mode:o.mode,busy:C===a.ad_set_ref,onSelect:m=>re(a,m),onLaunch:()=>K(a),onPreviewAsset:m=>I({id:m.asset.id,url:m.asset.public_url,prompt:m.asset.prompt_used||m.asset.caption||null,model:m.asset.model_version||null,source:"generated_asset"})},a.ad_set_ref))]}),e.jsx(et,{ws:s,loading:$.isLoading,error:$.isError,items:ls,total:(Te=$.data)==null?void 0:Te.total,counts:{all:H.length,generated_asset:H.filter(a=>a.source==="generated_asset").length,creative:H.filter(a=>a.source==="creative").length},filter:E,onFilter:ge,onRetry:()=>$.refetch(),onOpen:I,onReuse:a=>L(a.prompt)})]}),e.jsx(me,{children:g&&e.jsxs(b.div,{initial:{opacity:0}
4,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/70 p-4 backdrop-blur-md",onClick:()=>I(null),children:[e.jsx("button",{onClick:()=>I(null),className:"absolute right-3 top-3 grid h-10 w-10 place-items-center rounded-full bg-card text-foreground shadow",children:e.jsx(ae,{className:"h-5 w-5"})}),e.jsxs(b.div,{initial:{scale:.94,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0},transition:{duration:.28,ease:ue},onClick:a=>a.stopPropagation(),className:"flex max-h-[90vh] w-full max-w-3xl flex-col overflow-hidden rounded-3xl border border-border bg-card shadow-2xl sm:flex-row",children:[e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-muted p-3",children:e.jsx("img",{src:g.url,alt:g.prompt||"creative",className:"max-h-[72vh] max-w-full rounded-2xl object-contain"})}),e.jsxs("div",{className:"shrink-0 p-4 sm:w-72",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-1.5",children:[ye(g.model)&&e.jsx(ns,{label:ye(g.model)}),g.dimensions&&e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:g.dimensions})]}),g.created_at&&e.jsxs("p",{className:"mb-2 flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(Ls,{className:"h-3 w-3"}),new Date(g.created_at).toLocaleString()]}),g.prompt&&e.jsx("p",{className:"mb-4 max-h-40 overflow-auto text-xs leading-relaxed text-muted-foreground",children:g.prompt}),e.jsxs("button",{onClick:()=>L(g.prompt),className:"inline-flex w-full items-center justify-center gap-1.5 rounded-xl px-3 py-2.5 text-sm font-semibold text-white transition hover:brightness-105",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(V,{className:"h-4 w-4"})," Reuse as brief"]})]})]})]})}),e.jsx(me,{children:P&&e.jsx(b.div,{initial:{opacity:0}
4,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/70 p-4 backdrop-blur-md",onClick:()=>R(!1),children:e.jsxs(b.div,{initial:{scale:.94,opacity:0,y:12},animate:{scale:1,opacity:1,y:0},exit:{scale:.96,opacity:0},transition:{duration:.28,ease:ue},onClick:a=>a.stopPropagation(),className:"flex max-h-[90vh] w-full max-w-2xl flex-col overflow-hidden rounded-3xl border border-border bg-card shadow-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border p-4 sm:p-5",children:[e.jsx("div",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-xl text-white",style:{backgroundColor:"var(--sv-green)"},children:e.jsx(fe,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-base font-bold tracking-tight",children:"Marketing Strategy"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:"Full-funnel plan for this workspace — advisory only."})]}),N&&e.jsx("span",{className:"ml-auto rounded-full border px-2 py-0.5 text-[11px] font-semibold",style:{borderColor:"color-mix(in srgb, var(--sv-green) 45%, transparent)",background:"color-mix(in srgb, var(--sv-green) 12%, transparent)",color:"var(--sv-green-strong)"},children:N.generated_by==="gemini"?"AI":"Prepared"}),e.jsx("button",{onClick:()=>R(!1),className:`grid h-9 w-9 place-items-center rounded-full bg-muted text-foreground transition hover:brightness-95 ${N?"ml-2":"ml-auto"}`,children:e.jsx(ae,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-4 sm:p-5",children:B.isPending?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-20 text-sm text-muted-foreground",children:[e.jsx(T,{className:"h-5 w-5 animate-spin",style:{color:"var(--sv-green)"}})," Building your full-funnel strategy…"]}):N?e.jsx(Ks,{s:N}):e.jsxs("div",{className:"flex flex-col items-center gap-3 py-16 text-center text-sm text-muted-foreground",children:[e.jsx(Xe,{className:"h-7 w-7 text-rose-500"}),"Couldn't generate a strategy.",e.jsxs("button",{onClick:F,className:"inline-flex items-center gap-1.5 rounded-xl px-4 py-2 text-sm font-semibold text-white transition hover:brightness-105",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(ze,{className:"h-4 w-4"})," Retry"]})]})}),N&&!B.isPending&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border p-4 sm:px-5",children:[e.jsx("p",{className:"mr-auto text-[11px] text-muted-foreground",children:"Advisory — nothing runs until you Run Ad Room."}),e.jsx("button",{onClick:()=>R(!1),className:"rounded-xl border border-border bg-card px-3.5 py-2 text-sm font-medium text-muted-foreground transition hover:text-foreground",children:"Close"}),e.jsxs(b.button,{whileTap:{scale:.97},onClick:w,disabled:z.isPending,className:"inline-flex items-center gap-1.5 rounded-xl border px-4 py-2 text-sm font-semibold transition hover:brightness-105 disabled:opacity-60",style:{borderColor:"color-mix(in srgb, var(--sv-green) 45%, transparent)",color:"var(--sv-green-strong)",backgroundColor:"color-mix(in srgb, var(--sv-green) 10%, transparent)"},children:[z.isPending?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(De,{className:"h-4 w-4"})," Save"]}),e.jsxs(b.button,{whileTap:{scale:.97},onClick:ne,className:"inline-flex items-center gap-1.5 rounded-xl px-4 py-2 text-sm font-semibold text-white transition hover:brightness-105",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(V,{className:"h-4 w-4"})," Use as brief"]})]})]})})})]})}const He={high:"border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-500/40 dark:bg-emerald-500/10 dark:text-emerald-300",medium:"border-border bg-muted text-muted-foreground",low:"border-border bg-muted/60 text-muted-foreground"};function Ks({s}){var r,i,h,k,x,j;return e.jsxs("div",{className:"space-y-5",children:[s.summary&&e.jsx("p",{className:"text-[14px] leading-relaxed text-foreground/90",children:s.summary}),!!((r=s.target_audience)!=null&&r.length)&&e.jsx(W,{icon:Ye,title:"Target audience",children:e.jsx("div",{className:"space-y-2",children:s.target_audience.map((l,p)=>e.jsxs("div",{className:"rounded-xl border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:l.segment}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-muted-foreground",children:l.why})]},p))})}),!!((i=s.channels)!=null&&i.length)&&e.jsx(W,{icon:hs,title:"Channels",children:e.jsx("div",{className:"space-y-2",children:s.channels.map((l,p)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border border-border bg-background px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:l.channel}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-muted-foreground",children:l.role})]}),e.jsx("span",{className:`flex-none rounded-full border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider ${He[String(l.priority)]||He.medium}`,children:String(l.priority||"medium")})]},p))})}),!!((h=s.budget_split)!=null&&h.length)&&e.jsx(W,{icon:gs,title:"Budget split",children:e.jsx("div",{className:"space-y-2.5",children:s.budget_split.map((l,p)=>{const f=Math.max(0,Math.min(100,Number(l.pct||0)));return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[12px]",children:[e.jsx("span",{className:"text-foreground
4/80",children:l.channel}),e.jsxs("span",{className:"font-semibold text-foreground",children:[f,"%"]})]}),e.jsx("span",{className:"block h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${f}%`,backgroundColor:"var(--sv-green)"}})})]},p)})})}),!!((k=s.creative_angles)!=null&&k.length)&&e.jsx(W,{icon:he,title:"Creative angles",children:e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:s.creative_angles.map((l,p)=>e.jsxs("div",{className:"rounded-xl border border-border bg-background px-3 py-2",children:[e.jsxs("div",{className:"text-[13px] font-semibold leading-snug text-foreground",children:["“",l.hook,"”"]}),e.jsx("div",{className:"mt-1 text-[12px] leading-snug text-muted-foreground",children:l.angle})]},p))})}),!!((x=s.funnel)!=null&&x.length)&&e.jsx(W,{icon:Ke,title:"Funnel",children:e.jsx("div",{className:"space-y-2",children:s.funnel.map((l,p)=>e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl border border-border bg-background px-3 py-2",children:[e.jsx("span",{className:"flex-none rounded-md border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider",style:{borderColor:"color-mix(in srgb, var(--sv-green) 40%, transparent)",background:"color-mix(in srgb, var(--sv-green) 10%, transparent)",color:"var(--sv-green-strong)"},children:l.stage}),e.jsx("span",{className:"min-w-0 flex-1 text-[12px] leading-snug text-muted-foreground",children:l.action})]},p))})}),!!((j=s.recommendations)!=null&&j.length)&&e.jsx(W,{icon:Os,title:"Recommendations",children:e.jsx("ol",{className:"space-y-1.5",children:s.recommendations.map((l,p)=>e.jsxs("li",{className:"flex items-start gap-2 text-[13px] leading-snug text-foreground/85",children:[e.jsx("span",{className:"mt-0.5 flex h-4 w-4 flex-none items-center justify-center rounded-full text-[10px] font-bold text-white",style:{backgroundColor:"var(--sv-green)"},children:p+1}),e.jsx("span",{className:"min-w-0 flex-1",children:l})]},p))})})]})}function W({icon:s,title:r,children:i}){return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:[e.jsx(s,{className:"h-3.5 w-3.5",style:{color:"var(--sv-green)"}})," ",r]}),i]})}function Xs({room:s,index:r,mode:i,busy:h,onSelect:k,onLaunch:x,onPreviewAsset:j}){var _,o;const l=[...s.candidates].sort((u,C)=>{var A,g;return(((A=u.ranking)==null?void 0:A.rank)??99)-(((g=C.ranking)==null?void 0:g.rank)??99)}),p=s.candidates.filter(u=>
4u.selected).length,f=((o=(_=s.recommended_audience)==null?void 0:_.custom_audiences)==null?void 0:o.length)||0;return e.jsxs(b.div,{variants:Z,initial:"hidden",animate:"show",custom:r+1,className:"rounded-3xl border border-border bg-card p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:"var(--sv-green)"}}),e.jsx("h3",{className:"font-semibold",children:s.ad_set_ref}),e.jsxs("span",{className:"rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground",children:[s.candidates.length," variations"]}),f>0&&e.jsxs("span",{className:"rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground",children:["retargeting · ",f]}),p>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-semibold text-white",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(Qe,{className:"h-3 w-3"})," picked"]}),e.jsxs(b.button,{whileTap:{scale:.96},disabled:h,onClick:x,className:"ml-auto inline-flex items-center gap-1.5 rounded-xl px-3.5 py-1.5 text-sm font-semibold text-white shadow-sm transition hover:brightness-105 disabled:opacity-60",style:{backgroundColor:i==="launch"?"#e11d48":"var(--sv-green)"},children:[h?e.jsx(T,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(us,{className:"h-3.5 w-3.5"}),i==="launch"?"Launch":"Prepare"]})]}),e.jsx(b.div,{variants:as,initial:"hidden",animate:"show",className:"grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4",children:l.map(u=>e.jsx(Qs,{c:u,onSelect:()=>k(u.asset.id),onExpand:()=>j(u)},u.asset.id))})]})}function Qs({c:s,onSelect:r,onExpand:i}){var o,u,C,A;const h=(o=s.ranking)==null?void 0:o.rank,k=h===1,x=(u=s.ranking)==null?void 0:u.scores,j=qe(x==null?void 0:x.brand_fit),l=qe(x==null?void 0:x.engagement_index),p=Js((C=s.ranking)==null?void 0:C.predicted_lift_vs_baseline),f=((A=x==null?void 0:x.flags)==null?void 0:A.filter(Boolean))??[],_=j!=null||l!=null||!!p;return e.jsxs(b.div,{variants:rs,whileHover:{y:-4},transition:{type:"spring",stiffness:300,damping:22},className:`group relative overflow-hidden rounded-2xl border-2 text-left transition-colors ${s.selected?"":"border-border hover:border-muted-foreground/40"}`,style:s.selected?{borderColor:"var(--sv-green)",boxShadow:"0 0 0 3px color-mix(in srgb, var(--sv-green) 30%, transparent)"}:void 0,children:[e.jsx("button",{onClick:r,className:"block w-full text-left","aria-label":`Select variation ${h??""}`,children:e.jsxs("div",{className:"relative aspect-square w-full bg-muted",children:[e.jsx("img",{src:s.asset.public_url,alt:s.asset.caption||"ad variation",loading:"lazy",className:"h-full w-full object-cover transition duration-300 group-hover:scale-[1.04]"}),k?e.jsxs("span",{className:"absolute left-2 top-2 inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-bold text-white shadow-sm",style:{backgroundColor:"var(--sv-green)"},children:[e.jsx(Gs,{className:"h-3 w-3"})," #1"]}):h?e.jsxs("span",{className:"absolute left-2 top-2 rounded-full bg-slate-900/70 px-2 py-0.5 text-[11px] font-semibold text-white backdrop-blur",children:["#",h]}):null,p&&e.jsxs("span",{className:"absolute right-2 top-2 inline-flex items-center gap-0.5 rounded-full bg-slate-900/70 px-2 py-0.5 text-[10px] font-semibold text-white backdrop-blur",children:[e.jsx(ps,{className:"h-3 w-3"}),p]}),s.selected&&e.jsx("span",{className:"absolute bottom-2 right-2 rounded-full p-1 text-white shadow-sm",style:{backgroundColor:"var(--sv-green)"},children:e.jsx(Qe,{className:"h-3.5 w-3.5"})})]})}),e.jsx("button",{onClick:i,title:"Preview",className:"absolute right-2 top-2 grid h-7 w-7 place-items-center rounded-full bg-slate-900/60 text-white opacity-0 shadow-sm backdrop-blur transition group-hover:opacity-100",style:p?{top:"2.25rem"}:void 0,children:e.jsx(zs,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"bg-card p-2.5",children:[e.jsx("p",{className:"line-clamp-2 min-h-[2.1rem] text-[11px] leading-snug text-muted-foreground",children:s.asset.caption||s.asset.prompt_used}
4),_&&e.jsxs("div",{className:"mt-2 space-y-1.5",children:[j!=null&&e.jsx(We,{label:"Brand fit",pct:j}),l!=null&&e.jsx(We,{label:"Engagement",pct:l})]}),f.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[f.slice(0,2).map(g=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-amber-50 px-1.5 py-0.5 text-[9px] font-medium text-amber-700 dark:bg-amber-500/10 dark:text-amber-300",children:[e.jsx(Xe,{className:"h-2.5 w-2.5"}),g.replace(/_/g," ")]},g)),f.length>2&&e.jsxs("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground",children:["+",f.length-2]})]})]})]})}function We({label:s,pct:r}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-16 shrink-0 text-[9px] font-medium uppercase tracking-wide text-muted-foreground",children:s}),e.jsx("span",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${r}%`,backgroundColor:"var(--sv-green)"}})}),e.jsx("span",{className:"w-7 shrink-0 text-right text-[9px] font-semibold text-foreground",children:r})]})}function et({ws:s,loading:r,error:i,items:h,total:k,counts:x,filter:j,onFilter:l,onRetry:p,onOpen:f,onReuse:_}){const o=[["all","All"],["generated_asset","Ad Studio"],["creative","Saved"]];return e.jsxs(b.section,{variants:Z,initial:"hidden",animate:"show",custom:2,className:"mt-10",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3",children:[e.jsx(Ms,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"font-semibold",children:"Previous generations"}),k?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[k," saved"]}):null,e.jsxs(Ne,{to:"/creatives",className:"ml-auto inline-flex items-center gap-1 text-xs font-medium transition hover:underline",style:{color:"var(--sv-green)"},children:["Open Library ",e.jsx(Je,{className:"h-3 w-3"})]})]}),s&&x.all>0&&e.jsx("div",{className:"mb-4 flex items-center gap-1 rounded-full border border-border bg-card p-1 w-fit",children:o.map(([u,C])=>e.jsxs("button",{onClick:()=>l(u),className:`rounded-full px-3.5 py-1.5 text-xs font-semibold transition ${j===u?"text-white":"text-muted-foreground hover:text-foreground"}`,style:j===u?{backgroundColor:"var(--sv-green)"}:void 0,children:[C," ",e.jsx("span",{className:j===u?"opacity-80":"opacity-60",children:x[u]})]},u))}),!s&&e.jsx("div",{className:"rounded-3xl border border-border bg-card p-6 text-sm text-muted-foreground",children:"Select a workspace to see your past generations."}),s&&r&&e.jsx("div",{className:"grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6",children:Array.from({length:12}).map((u,C)=>e.jsx("div",{className:"aspect-square animate-pulse rounded-2xl bg-muted"},C))}),s&&i&&e.jsxs("div",{className:"rounded-3xl border border-border bg-card p-6 text-sm text-muted-foreground",children:["Couldn't load past generations. ",e.jsx("button",{onClick:p,className:"underline",style:{color:"var(--sv-green)"},children:"Retry"})]}),s&&!r&&!i&&h.length===0&&e.jsxs("div",{className:"rounded-3xl border border-dashed border-border bg-card p-10 text-center text-sm text-muted-foreground",children:[e.jsx(he,{className:"mx-auto mb-2 h-7 w-7",style:{color:"var(--sv-green)"}}),x.all===0?"No generations yet — run a brief above to create your first on-brand ad set.":"Nothing in this filter yet."]}),s&&!r&&!i&&h.length>0&&e.jsx(b.div,{variants:as,initial:"hidden",animate:"show",className:"grid grid-cols-3 gap-3 sm:grid-cols-4 lg:grid-cols-6",children:h.map(u=>e.jsx(st,{it:u,onOpen:()=>f(u),onReuse:()=>_(u)},u.id))})]})}function st({it:s,onOpen:r,onReuse:i}){const h=ye(s.model);return e.jsxs(b.div,{variants:rs,className:"group relative overflow-hidden rounded-2xl border border-border bg-card shadow-sm transition hover:shadow-md",children:[e.jsxs("button",{onClick:r,className:"block w-full","aria-label":"Open generation",children:[e.jsx("div",{className:"aspect-square w-full overflow-hidden bg-muted",children:e.jsx("img",{src:s.url,alt:s.prompt||"past creative",loading:"lazy",className:"h-full w-full object-cover transition duration-500 group-hover:scale-[1.05]"})}),e.jsxs("div",{className:"pointer-events-none absolute left-2 top-2 flex flex-wrap gap-1",children:[h&&e.jsx(ns,{label:h}),s.dimensions&&e.jsx("span",{className:"rounded-full bg-white/90 px-2 py-0.5 text-[10px] font-medium text-slate-600 shadow-sm",children:s.dimensions})]}),s.prompt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-black/55 opacity-0 transition group-hover:opacity-100"}),e.jsx("p",{className:"pointer-events-none absolute inset-x-2 bottom-2 line-clamp-2 text-left text-[10px] leading-snug text-white opacity-0 transition group-hover:opacity-100",children:s.prompt})]})]}),e.jsx("button",{onClick:i,title:"Reuse prompt as brief",className:"absolute right-1.5 top-1.5 grid h-7 w-7 place-items-center rounded-full text-white opacity-0 shadow-sm transition group-hover:opacity-100",style:{backgroundColor:"var(--sv-green)"},children:e.jsx(V,{className:"h-3.5 w-3.5"})})]})}function ns({label:s}){const r=s==="Pro";return e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-bold text-white shadow-sm ${r?"":"bg-slate-700"}`,style:r?{backgroundColor:"var(--sv-green)"}:void 0,children:s})}function xe({label:s,value:r,tone:i="default"}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-background px-3 py-2.5",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("div",{className:`mt-0.5 truncate text-sm font-semibold ${i==="warn"?"text-rose-600 dar
4k:text-rose-400":"text-foreground"}`,title:r,children:r})]})}export{Pt 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.