1import{r as c,i as C,j as e,cV as Ta,ep as bl,U as da,G as K,be as Ie,dv as fl,bB as ss,g as ce,bL as Ls,gm as xa,_ as Ke,dh as ma,H as vt,bm as ha,bF as ua,b as pa,f8 as ts,ch as Ms,bK as jt,aC as Aa,a_ as Nl,ca as ga,bz as Ye,gn as Rs,fj as za,e as ft,b$ as bs,cv as Hs,aL as Ue,c6 as De,bN as _a,go as Nt,J as qs,c2 as yl,cY as wl,bH as Sl,K as bt,c0 as Ua,a1 as va,gp as kl,X as Qs,gq as Cl,c4 as yt,cg as Tl,cm as as,aT as Al,aF as Ia,gr as zl,gs as _l,dp as Ul,aS as wt,W as Il,gt as Pl,aA as Bl,fv as Fl,eZ as ja}from"./vendor-B3bqREfz.js";import{T as Xs}from"./toolsMeta-BvCHlySA.js";import{u as kt,D as ne,h as ie,j as re,k as oe,g as T,B as r,I as y,f as R,T as Ol,o as El,p as ue,r as pe,C as ge,a as Ks,b as Gs,d as je,P as $l,x as Ll,y as Ml,q as p,m as $e}from"./index-BHZdkTHk.js";import{L as m}from"./label-USjEtjxC.js";import{S as be}from"./switch-CEyu8DAw.js";import{S as P,a as B,b as F,c as O,d as g}from"./select-CdK0CD7c.js";import{S as ba,a as fa,b as Na,c as ya}from"./sheet-h38iqo5g.js";import{C as es}from"./checkbox-CT0eb10X.js";import{T as Pa}from"./textarea-BFtGXtJd.js";import{S as wa}from"./separator-CBOTbc_x.js";import{A as Rl}from"./AdminLayout-C31anzfd.js";import{A as ql}from"./AiBannerMaker-E6lz9S7v.js";import{A as Zs}from"./AnimatedGradientBanner-BsGyXLTH.js";import{B as Ws,H as Sa,i as Kl}from"./HpgStudio-BytyEbCK.js";import"./harbor-shoppers-logo-BwiOLETu.js";import"./InsufficientTokensDialog-BN65R27R.js";import"./auth-url-CN_iq7Nz.js";import"./VoiceMicButton-Cf6zBGsF.js";import"./slider-CiHPkUoi.js";import"./collapsible-BGo1RwKi.js";const ka={indigo:"Navy Blue â AI & Technology",emerald:"Forest Green â Selling & Merchants",boatzhub:"Ocean Teal â Community & Brands",harborOS:"Harbor Blue â Platform Features",violet:"Purple â Premium & Exclusive",cyan:"Cyan â Search & Discovery",orange:"Sunset Orange â Deals & Urgency"};function Gl({open:t,onOpenChange:d,existingBanners:de=[],onSave:we}){const{toast:se}=kt(),[z,X]=c.useState(""),[j,J]=c.useState("none"),[_,Y]=c.useState(null),[E,ve]=c.useState(""),[Z,u]=c.useState(""),[b,k]=c.useState(""),[G,H]=c.useState(""),h=j!=="none"&&de.find(v=>String(v.id)===j)||null,W=C({mutationFn:async()=>{const v=await R("POST","/api/ai/banner/animated",{purpose:z.trim()||void 0,existingBanner:h?{title:h.title,subtitle:h.subtitle}:void 0});if(!v.ok){const Ge=await v.json();throw new Error(Ge.message||"Generation failed")}return v.json()},onSuccess:v=>{Y(v),ve(v.headline),u(v.subtitle),k(v.ctaText),H(v.ctaUrl)},onError:v=>{se({title:"Generation failed",description:v.message,variant:"destructive"})}}),te=()=>{if(!z.trim()&&!h){se({title:"Please describe your banner or pick an existing one",variant:"destructive"});return}W.mutate()},Se=()=>{_&&(we({title:E,subtitle:Z,videoUrl:_.gradient,linkUrl:G,showCta:!0,ctaText:b,ctaUrl:G,mediaType:"gradient"}),se({title:"Animated banner created!",description:"Find it in your banner list."}),ke(),d(!1))},ke=()=>{Y(null),X(""),J("none"),ve(""),u(""),k(""),H("")},Ce=_?{title:E,subtitle:Z,videoUrl:_.gradient,linkUrl:G,showCta:!0,ctaText:b}:null;return e.jsx(ne,{open:t,onOpenChange:d,children:e.jsxs(ie,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(re,{children:e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(Ta,{className:"w-5 h-5 text-teal-500"}),"AI Animated Banner Builder",e.jsx(T,{variant:"outline",className:"ml-2 text-xs text-teal-700 border-teal-300",children:"Free â No Tokens"})]})}),_?e.jsxs("div",{className:"space-y-4",children:[_.explanation&&e.jsxs("div",{className:"flex items-start gap-2 p-2.5 bg-teal-50 border border-teal-200 rounded-lg text-xs text-teal-800",children:[e.jsx(fl,{className:"w-3.5 h-3.5 shrink-0 mt-0.5"}),e.jsxs("span",{children:[e.jsxs("strong",{children:["Theme: ",ka[_.theme]||_.theme]})," â"," ",_.explanation]})]}),e.jsxs("div",{className:"border rounded-xl overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"px-3 py-1.5 bg-slate-50 border-b text-xs font-medium text-slate-500 flex items-center justify-between",children:[e.jsx("span",{children:"Live Preview"}),e.jsx("span",{className:"text-teal-600 font-semibold",children:ka[_.theme]||_.theme})]}),Ce&&e.jsx(Zs,{banner:Ce,height:180})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Headline"}),e.jsx(y,{value:E,onChange:v=>ve(v.target.value),className:"mt-1 h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"CTA Button Text"}),e.jsx(y,{value:b,onChange:v=>k(v.target.value),className:"mt-1 h-8 text-sm"})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Subtitle"}),e.jsx(y,{value:Z,onChange:v=>u(v.target.value),className:"mt-1 h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Link URL"}),e.jsx(y,{value:G,onChange:v=>H(v.target.value),placeholder:"/shop",className:"mt-1 h-8 text-sm font-mono"})]}),e.jsxs("div",{className:"p-2.5 bg-slate-50 border rounded-lg text-xs text-slate-500 font-mono break-all",children:[e.jsx("span",{className:"text-slate-400 mr-1",children:"CSS:"}),_.gradient]}),e.jsxs("div",{className:"flex gap-2 pt-2 border-t",children:[e.jsxs(r,{onClick:Se,disabled:!E,className:"flex-1 gap-2 bg-teal-600 hover:bg-teal-700 text-white",children:[e.jsx(ss,{className:"w-4 h-4"}),"Save Animated Banner"]}),e.jsxs(r,{variant:"outline",onClick:ke,className:"gap-1.5",children:[e.jsx(da,{className:"w-4 h-4"}),"Try Again"]}),e.jsx(r,{variant:"ghost",onClick:()=>d(!1),children:"Cancel"})]})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"p-3 bg-gradient-to-r from-teal-50 to-cyan-50 border border-teal-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-teal-800",children:[e.jsx(bl,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"Describe your banner's purpose and AI will pick the best animated theme, write the headline and copy, and give you a live preview â ready to save instantly."]})}),de.length>0&&e.jsxs("div",{children:[e.jsxs(m,{className:"text-sm font-medium flex items-center gap-1.5",children:[e.jsx(da,{className:"w-4 h-4"}),"Convert an Existing Banner (optional)"]}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5 mb-2",children:"Pick an existing banner to convert its message into an animated style"}),e.jsxs(P,{value:j,onValueChange:J,children:[e.jsx(B,{className:"h-9 text-sm",children:e.jsx(F,{placeholder:"â Skip, I'll describe from scratch â"})}),e.jsxs(O,{children:[e.jsx(g,{value:"none",children:"â Skip, I'll describe from scratch â"}),de.map(v=>e.jsxs(g,{value:String(v.id),children:[v.title,v.mediaType&&v.mediaType!=="gradient"&&e.jsxs("span",{className:"ml-2 text-xs text-slate-400",children:["(",v.mediaType,")"]})]},v.id))]})]}),h&&e.jsxs("div",{className:"mt-2 p-2 bg-slate-50 border rounded text-xs text-slate-600",children:[e.jsx("strong",{children:h.title}),h.subtitle&&e.jsxs(e.Fragment,{children:[" â ",h.subtitle]})]})]}),e.jsxs("div",{children:[e.jsxs(m,{className:"text-sm font-medium",children:["What should this banner promote?"," ",!h&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Pa,{value:z,onChange:v=>X(v.target.value),placeholder:h?'Optional extra notes: e.g. "make it feel urgent" or "focus on the community aspect"':`e.g. "Promote our AI Boat Captain tool that gives smart marine advice" 2or "Flash sale on marine electronics this weekend" 3or "Invite boat owners to join our community"`,rows:4,className:"mt-1 text-sm"})]}
3),e.jsx(r,{onClick:te,disabled:W.isPending||!z.trim()&&!h,className:"w-full gap-2 bg-gradient-to-r from-teal-500 to-cyan-600 hover:from-teal-600 hover:to-cyan-700 text-white",children:W.isPending?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 animate-spin"}),"AI is choosing theme & writing copyâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4"}),"Generate Animated Banner"]})})]})]})})}const Vs={"full-width":"Full Width","728x90":"728Ã90 Leaderboard","300x250":"300Ã250 Rectangle","160x600":"160Ã600 Skyscraper","336x280":"336Ã280 Large Rectangle","300x600":"300Ã600 Half Page","970x90":"970Ã90 Billboard",custom:"Custom"},js={draft:{label:"Draft",color:"bg-slate-100 text-slate-700"},pending_review:{label:"Pending Review",color:"bg-yellow-100 text-yellow-800"},approved:{label:"Approved",color:"bg-green-100 text-green-800"},rejected:{label:"Rejected",color:"bg-red-100 text-red-800"},expired:{label:"Expired",color:"bg-gray-100 text-gray-600"},scheduled:{label:"Scheduled",color:"bg-blue-100 text-blue-800"}},St=["Harbor Shoppers","Boatz Pro","Boatz Hub","Yachtz Pro","Shopz","Bulk Lister","Nautical Trips"],Ct=t=>{const d=t.match(/(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|embed\/|shorts\/))([\w-]+)/);return d?`https://www.youtube.com/embed/${d[1]}`:""},Wl=[{value:"inherit",label:"System Default"},{value:"sans",label:"Sans-Serif (Inter)"},{value:"serif",label:"Serif (Georgia)"},{value:"mono",label:"Monospace"},{value:"display",label:"Display (Impact)"},{value:"rounded",label:"Rounded (Nunito)"}],Hl=[{value:"none",label:"None (instant)"},{value:"typing",label:"â¨ï¸ Typewriter"},{value:"fade-in",label:"⨠Fade In"},{value:"slide-up",label:"â¬ï¸ Slide Up"},{value:"slide-down",label:"â¬ï¸ Slide Down"}],Vl=[{value:"none",label:"None"},{value:"soft",label:"Soft Dark"},{value:"hard",label:"Hard Drop"},{value:"glow",label:"White Glow"},{value:"glow-blue",label:"Blue Glow"},{value:"glow-gold",label:"Gold Glow"},{value:"outline",label:"Black Outline"},{value:"emboss",label:"Emboss"}],Ql=[{value:"top-left",label:"â Top Left"},{value:"top-center",label:"â Top Center"},{value:"top-right",label:"â Top Right"},{value:"center-left",label:"â Center Left"},{value:"center",label:"â Center"},{value:"center-right",label:"â Center Right"},{value:"bottom-left",label:"â Bottom Left"},{value:"bottom-center",label:"â Bottom Center"},{value:"bottom-right",label:"â Bottom Right"}],Xl=[{value:"solid",label:"Solid Fill"},{value:"outline",label:"Outline"},{value:"ghost",label:"Glass / Ghost"},{value:"pill",label:"Pill (Rounded)"}],Zl=["xs","sm","md","lg","xl","2xl","3xl","4xl"],Jl=["normal","medium","semibold","bold","extrabold","black"];function Yl({formData:t,setFormData:d,onSubmit:de,onCancel:we,isSubmitting:se,isEditing:z,isUploading:X,fileInputRef:j,handleFileUpload:J,onUploadFile:_,adZonesList:Y=[]}){const[E,ve]=c.useState(!1),[Z,u]=c.useState(!1),[b,k]=c.useState(!1),[G,H]=c.useState(!1),[h,W]=c.useState("all"),[te,Se]=c.useState(""),[ke,Ce]=c.useState(1),{data:v,isLoading:Ge}=ce({queryKey:["/api/upload/list",h,ke],queryFn:async()=>{const n=await fetch(`/api/upload/list?filter=${h}&page=${ke}&limit=48`,{credentials:"include"});return n.ok?n.json():{items:[],total:0,page:1,pages:0}},enabled:G,staleTime:3e4}),Js=n=>{n.preventDefault(),k(!0)},fs=()=>k(!1),Ys=n=>{var V;n.preventDefault(),k(!1);const q=(V=n.dataTransfer.files)==null?void 0:V[0];q&&_(q)},Ns=n=>{n.type==="video"?d({...t,videoUrl:n.url,mediaType:"video",imageUrl:""}):n.type==="gif"?d({...t,imageUrl:n.url,mediaType:"gif"}):d({...t,imageUrl:n.url}),H(!1)},ys=((v==null?void 0:v.items)||[]).filter(n=>!te||n.name.toLowerCase().includes(te.toLowerCase())),Le=t.adType==="marketing";return e.jsxs("form",{onSubmit:de,className:"flex flex-col flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"overflow-y-auto flex-1 px-5 py-4 space-y-3 border-r border-slate-100",children:[!z&&e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide mb-2 block",children:"Banner Purpose"}),e.jsx("div",{className:"flex gap-2",children:[{value:"standard",label:"Standard Banner",desc:"Home or store slideshow"},{value:"marketing",label:"Marketing Banner",desc:"Paid placement in ad zones"}].map(n=>e.jsxs("button",{type:"button",onClick:()=>d({...t,adType:n.value}),className:`flex-1 p-2.5 rounded-lg border-2 text-left transition-colors ${t.adType===n.value?"border-blue-500 bg-blue-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsx("div",{className:"text-xs font-semibold",children:n.label}),e.jsx("div",{className:"text-[10px] text-slate-500 mt-0.5",children:n.desc})]},n.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(m,{className:"text-xs font-medium",children:["Title ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(y,{className:"mt-1 h-8 text-sm",value:t.title,onChange:n=>d({...t,title:n.target.value}),placeholder:"Banner title",required:!0})]}),e.jsxs("div",{children:[e.jsxs(m,{className:"text-xs font-medium",children:["Subtitle ",e.jsx("span",{className:"text-slate-400 font-normal",children:"(optional)"})]}),e.jsx(y,{className:"mt-1 h-8 text-sm",value:t.subtitle||"",onChange:n=>d({...t,subtitle:n.target.value}),placeholder:"Supporting text..."})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Media Type"}),e.jsxs(P,{value:t.mediaType,onValueChange:n=>d({...t,mediaType:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsxs(O,{children:[e.jsx(g,{value:"image",children:"Image (JPG, PNG, WebP)"}),e.jsx(g,{value:"gif",children:"GIF (Animated)"}),e.jsx(g,{value:"video",children:"Video (MP4, WebM)"}),e.jsx(g,{value:"youtube",children:"YouTube Video"}),e.jsx(g,{value:"gradient",children:"Gradient (CSS Animated)"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Display Duration (sec)"}),e.jsx(y,{className:"mt-1 h-8 text-xs",type:"number",min:2,max:60,step:1,value:t.displayDuration,onChange:n=>d({...t,displayDuration:parseInt(n.target.value)||5})})]})]}),t.mediaType==="gradient"&&e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"CSS Gradient"}),e.jsx(y,{className:"mt-1 h-8 font-mono text-xs",value:t.videoUrl||"",onChange:n=>d({...t,videoUrl:n.target.value}),placeholder:"linear-gradient(135deg, #060d1a 0%, #0a1f4e 30%, #0e7490 100%)"}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:"Any valid CSS background value"})]}),t.mediaType!=="youtube"&&t.mediaType!=="gradient"&&e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Upload Media"}),e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsx("input",{type:"file",ref:j,accept:t.mediaType==="video"?"video/mp4,video/webm,video/mov":t.mediaType==="gif"?"image/gif":"image/*,image/gif",onChange:J,className:"hidden"}),e.jsx("div",{onDragOver:Js,onDragLeave:fs,onDrop:Ys,onClick:()=>{var n;return(n=j.current)==null?void 0:n.click()},className:`relative flex flex-col items-center justify-center gap-1.5 rounded-lg border-2 border-dashed cursor-pointer transition-colors py-4 ${b?"border-blue-400 bg-blue-50":"border-slate-200 hover:border-slate-400 hover:bg-slate-50"}`,children:X?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-5 h-5 animate-spin text-slate-400"}),e.jsx("span",{className:"text-xs text-slate-500",children:"Uploadingâ¦"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Hs,{className:"w-5 h-5 text-slate-400"}),e.jsx("span",{className:"text-xs text-slate-500 text-center px-2",children:b?"Drop to upload":"Click or drag & drop to upload"}),e.jsx("span",{className:"text-[10px] text-slate-400",children:t.mediaType==="video"?"MP4, WebM, MOV":"JPG, PNG, WebP, GIF, AVIF"})]})}),e.jsxs(r,{type:"button",variant:"outline",size:"sm",onClick:()=>H(!0),className:"w-full gap-1.5 h-7 text-xs",children:[e.jsx(zl,{className:"w-3.5 h-3.5"}),"Browse Previous Uploads"]})]})]}),e.jsx(ne,{open:G,onOpenChange:H,children:e.jsxs(ie,{className:"max-w-3xl max-h-[80vh] flex flex-col",children:[e.jsx(re,{children:e.jsx(oe,{className:"text-base",children:"Media Library"})}),e.jsxs("div",{className:"flex gap-2 items-center flex-wrap shrink-0",children:[["all","image","gif","video"].map(n=>e.jsx(r,{type:"button",size:"sm",variant:h===n?"default":"outline",className:"h-7 text-xs px-3 capitalize",onClick:()=>{W(n),Ce(1)},children:n==="gif"?"GIF":n},n)),e.jsxs("div",{className:"relative ml-auto",children:[e.jsx(ft,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-slate-400 pointer-events-none"}),e.jsx(y,{className:"pl-7 h-7 text-xs w-40",placeholder:"Search f
3ilenameâ¦",value:te,onChange:n=>Se(n.target.value)})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:Ge?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(K,{className:"w-6 h-6 animate-spin text-slate-300"})}):ys.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-2 text-slate-400",children:[e.jsx(_l,{className:"w-8 h-8"}),e.jsx("p",{className:"text-sm",children:"No uploads found"})]}):e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-6 gap-2 p-1",children:ys.map(n=>e.jsxs("button",{type:"button",onClick:()=>Ns(n),className:"group relative aspect-square rounded-lg overflow-hidden border border-slate-200 hover:border-blue-400 hover:shadow-md transition-all bg-slate-50",title:n.name,children:[n.type==="video"?e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center gap-1 text-slate-400",children:[e.jsx(Ul,{className:"w-6 h-6"}),e.jsx("span",{className:"text-[9px] px-1 truncate w-full text-center",children:n.name})]}):e.jsx("img",{src:n.url,alt:n.name,className:"w-full h-full object-cover group-hover:opacity-90 transition-opacity",loading:"lazy"}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity px-1 py-0.5",children:e.jsx("p",{className:"text-[9px] text-white truncate",children:n.name})}),n.type==="gif"&&e.jsx("span",{className:"absolute top-1 right-1 bg-purple-600 text-white text-[8px] font-bold px-1 rounded",children:"GIF"})]},n.url))})}),v&&v.pages>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 shrink-0 pt-1 border-t border-slate-100",children:[e.jsx(r,{type:"button",size:"sm",variant:"outline",className:"h-7 text-xs",disabled:ke<=1,onClick:()=>Ce(n=>n-1),children:"â Prev"}),e.jsxs("span",{className:"text-xs text-slate-500",children:["Page ",v.page," of ",v.pages]}),e.jsx(r,{type:"button",size:"sm",variant:"outline",className:"h-7 text-xs",disabled:ke>=v.pages,onClick:()=>Ce(n=>n+1),children:"Next â"})]})]})}),t.mediaType!=="gradient"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(m,{className:"text-xs font-medium",children:t.mediaType==="video"?"Thumbnail Image URL":"Image URL"}),t.imageUrl&&e.jsxs("button",{type:"button",onClick:()=>d({...t,imageUrl:""}),className:"text-[10px] text-red-500 hover:text-red-700 flex items-center gap-0.5",children:[e.jsx(Qs,{className:"w-2.5 h-2.5"})," Clear"]})]}),e.jsx(y,{className:"h-8 text-xs",value:t.imageUrl,onChange:n=>d({...t,imageUrl:n.target.value}),placeholder:"https://example.com/image.jpg or /uploads/..."}),t.imageUrl&&e.jsx("div",{className:"mt-1.5 rounded overflow-hidden border border-slate-200 bg-slate-50 h-16 flex items-center justify-center",children:t.mediaType==="gif"||t.imageUrl.toLowerCase().endsWith(".gif")?e.jsx("img",{src:t.imageUrl,alt:"Current GIF",className:"h-full object-contain"}):e.jsx("img",{src:t.imageUrl,alt:"Current thumbnail",className:"h-full object-contain",onError:n=>{n.target.style.display="none"}})})]}),t.mediaType==="video"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(m,{className:"text-xs font-medium",children:"Video URL"}),t.videoUrl&&e.jsxs("button",{type:"button",onClick:()=>d({...t,videoUrl:""}),className:"text-[10px] text-red-500 hover:text-red-700 flex items-center gap-0.5",children:[e.jsx(Qs,{className:"w-2.5 h-2.5"})," Clear"]})]}),e.jsx(y,{className:"h-8 text-xs",value:t.videoUrl,onChange:n=>d({...t,videoUrl:n.target.value}),placeholder:"https://example.com/video.mp4 or /uploads/..."})]}),t.mediaType==="youtube"&&e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"YouTube URL"}),e.jsx(y,{className:"mt-1 h-8 text-xs",value:t.youtubeUrl,onChange:n=>d({...t,youtubeUrl:n.target.value}),placeholder:"https://www.youtube.com/watch?v=..."})]}),e.jsxs("div",{children:[e.jsxs(m,{className:"text-xs font-medium",children:["Link URL ",e.jsx("span",{className:"text-slate-400 font-normal",children:"(where banner links)"})]}),e.jsx(y,{className:"mt-1 h-8 text-xs",value:t.linkUrl,onChange:n=>d({...t,linkUrl:n.target.value}),placeholder:"https://example.com/page"})]}),t.mediaType!=="gradient"&&e.jsxs("div",{className:"flex items-center justify-between py-1",children:[e.jsx(m,{htmlFor:"showTitle",className:"cursor-pointer text-xs font-medium",children:"Show Title/Subtitle Overlay"}),e.jsx(be,{id:"showTitle",checked:t.showTitle,onCheckedChange:n=>d({...t,showTitle:n})})]}),t.showTitle&&t.mediaType!=="gradient"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Text Position"}),e.jsxs(P,{value:t.overlayPosition||"bottom-left",onValueChange:n=>d({...t,overlayPosition:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsxs(O,{children:[e.jsx(g,{value:"bottom-left",children:"Bottom Left"}),e.jsx(g,{value:"bottom-center",children:"Bottom Center"}),e.jsx(g,{value:"bottom-right",children:"Bottom Right"}),e.jsx(g,{value:"center",children:"Center"}),e.jsx(g,{value:"top-left",children:"Top Left"}),e.jsx(g,{value:"top-center",children:"Top Center"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Overlay Style"}),e.jsxs(P,{value:t.overlayStyle||"gradient",onValueChange:n=>d({...t,overlayStyle:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsxs(O,{children:[e.jsx(g,{value:"gradient",children:"Dark Gradient"}),e.jsx(g,{value:"solid",children:"Solid Dark Bar"}),e.jsx(g,{value:"glass",children:"Glass Blur"}),e.jsx(g,{value:"none",children:"Text Only (Drop Shadow)"})]})]})]})]}),Le&&e.jsxs("div",{className:"border border-blue-200 rounded-lg p-4 bg-blue-50/50 space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold text-blue-700 uppercase tracking-wide",children:"Marketing Banner Settings"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Ad Size"}),e.jsxs(P,{value:t.adSize||"728x90",onValueChange:n=>d({...t,adSize:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Object.entries(Vs).map(([n,q])=>e.jsx(g,{value:n,className:"text-xs",children:q},n))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Ad Zone (Marketing Override)"}),e.jsxs(P,{value:t.zoneId||"__none__",onValueChange:n=>d({...t,zoneId:n==="__none__"?"":n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{placeholder:"Select zone"})}),e.jsxs(O,{children:[e.jsx(g,{value:"__none__",children:"Unassigned"}),Y.map(n=>e.jsx(g,{value:n.zoneKey,className:"text-xs",children:n.name},n.zoneKey))]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Target Brands (leave empty for all)"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:St.map(n=>e.jsx("button",{type:"button",onClick:()=>{const q=t.targetBrands||[];d({...t,targetBrands:q.includes(n)?q.filter(V=>V!==n):[...q,n]})},className:`px-2 py-0.5 rounded text-xs border transition-colors ${(t.targetBrands||[]).includes(n)?"bg-blue-600 text-white border-blue-600":"bg-white text-slate-600 border-slate-300 hover:border-blue-400"}`,children:n},n))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Schedule Start (optional)"}),e.jsx(y,{type:"date",className:"h-8 text-xs mt-1",value:t.scheduleStart||"",onChange:n=>d({...t,scheduleStart:n.target.value})})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Schedule End (optional)"}),e.jsx(y,{type:"date",className:"h-8 text-xs mt-1",value:t.scheduleEnd||"",onChange:n=>d({...t,scheduleEnd:n.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Campaign Budget (optional, for tracking)"}),e.jsx(y,{className:"h-8 text-xs mt-1",placeholder:"e.g. $500",value:t.campaignBudget||"",onChange:n=>d({...t,campaignBudget:n.target.value})})]})]}),e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",className:"w-full flex items-center justify-between px-4 py-3 bg-slate-50 hover:bg-slate-100 transition-colors text-left",onClick:()=>ve(n=>!n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-800",children:"Text Overlay / Words on Banner"}),t.overlayText&&e.jsx("span",{className:"text-[10px] bg-blue-100 text-blue-700 rounded-full px-2 py-0.5 font-medium",children:"Active"})]}),e.jsx(wt,{className:`w-4 h-4 text-slate-500 transition-transform ${E?"rotate-180":""}`})]}),E&&e.jsxs("div",{className:"p-4 space-y-4 border-t bg-white",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Overlay Text"}),e.jsx("textarea",{className:"w-full mt-1 rounded-md border border-input bg-background px-3 py-2 text-sm r
3ing-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring min-h-[64px] resize-y",placeholder:"Text to display on the banner...",value:t.overlayText||"",onChange:n=>d({...t,overlayText:n.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Animation Style"}),e.jsxs(P,{value:t.overlayAnimation||"none",onValueChange:n=>d({...t,overlayAnimation:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Hl.map(n=>e.jsx(g,{value:n.value,className:"text-xs",children:n.label},n.value))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Appear After (seconds)"}),e.jsx(y,{type:"number",min:"0",max:"30",className:"h-8 text-xs mt-1",placeholder:"0 = immediately",value:t.overlayDelay??0,onChange:n=>d({...t,overlayDelay:Number(n.target.value)})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Font Family"}),e.jsxs(P,{value:t.overlayFont||"inherit",onValueChange:n=>d({...t,overlayFont:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Wl.map(n=>e.jsx(g,{value:n.value,className:"text-xs",children:n.label},n.value))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Font Size"}),e.jsxs(P,{value:t.overlayFontSize||"lg",onValueChange:n=>d({...t,overlayFontSize:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Zl.map(n=>e.jsx(g,{value:n,className:"text-xs",children:n},n))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Font Weight"}),e.jsxs(P,{value:t.overlayFontWeight||"bold",onValueChange:n=>d({...t,overlayFontWeight:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Jl.map(n=>e.jsx(g,{value:n,className:"text-xs capitalize",children:n},n))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Text Color"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("input",{type:"color",className:"h-8 w-10 rounded border cursor-pointer",value:t.overlayColor||"#ffffff",onChange:n=>d({...t,overlayColor:n.target.value})}),e.jsx(y,{className:"h-8 text-xs font-mono flex-1",value:t.overlayColor||"#ffffff",onChange:n=>d({...t,overlayColor:n.target.value}),placeholder:"#ffffff"})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Text Shadow"}),e.jsxs(P,{value:t.overlayShadow||"none",onValueChange:n=>d({...t,overlayShadow:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Vl.map(n=>e.jsx(g,{value:n.value,className:"text-xs",children:n.label},n.value))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Position"}),e.jsxs(P,{value:t.overlayPosition2||"center",onValueChange:n=>d({...t,overlayPosition2:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Ql.map(n=>e.jsx(g,{value:n.value,className:"text-xs",children:n.label},n.value))})]})]})]})]})]}),e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button",className:"w-full flex items-center justify-between px-4 py-3 bg-slate-50 hover:bg-slate-100 transition-colors text-left",onClick:()=>u(n=>!n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-800",children:"Call to Action Button"}),t.showCta&&e.jsx("span",{className:"text-[10px] bg-green-100 text-green-700 rounded-full px-2 py-0.5 font-medium",children:"Enabled"})]}),e.jsx(wt,{className:`w-4 h-4 text-slate-500 transition-transform ${Z?"rotate-180":""}`})]}),Z&&e.jsxs("div",{className:"p-4 space-y-4 border-t bg-white",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:!!t.showCta,onCheckedChange:n=>d({...t,showCta:n})}),e.jsx(m,{className:"text-sm",children:"Enable CTA button on this banner"})]}),t.showCta&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Button Text"}),e.jsx(y,{className:"h-8 text-xs mt-1",placeholder:"e.g. Shop Now, Learn More",value:t.ctaText||"",onChange:n=>d({...t,ctaText:n.target.value})})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Button URL (optional)"}),e.jsx(y,{className:"h-8 text-xs mt-1",placeholder:"https://... or use banner link",value:t.ctaUrl||"",onChange:n=>d({...t,ctaUrl:n.target.value})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Button Style"}),e.jsxs(P,{value:t.ctaStyle||"solid",onValueChange:n=>d({...t,ctaStyle:n}),children:[e.jsx(B,{className:"h-8 text-xs mt-1",children:e.jsx(F,{})}),e.jsx(O,{children:Xl.map(n=>e.jsx(g,{value:n.value,className:"text-xs",children:n.label},n.value))})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Show After (seconds)"}),e.jsx(y,{type:"number",min:"0",max:"60",className:"h-8 text-xs mt-1",placeholder:"0 = with banner",value:t.ctaDelay??0,onChange:n=>d({...t,ctaDelay:Number(n.target.value)})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Button Color"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("input",{type:"color",className:"h-8 w-10 rounded border cursor-pointer",value:t.ctaColor||"#2563eb",onChange:n=>d({...t,ctaColor:n.target.value})}),e.jsx(y,{className:"h-8 text-xs font-mono flex-1",value:t.ctaColor||"#2563eb",onChange:n=>d({...t,ctaColor:n.target.value}),placeholder:"#2563eb"})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs font-medium",children:"Text Color"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("input",{type:"color",className:"h-8 w-10 rounded border cursor-pointer",value:t.ctaTextColor||"#ffffff",onChange:n=>d({...t,ctaTextColor:n.target.value})}),e.jsx(y,{className:"h-8 text-xs font-mono flex-1",value:t.ctaTextColor||"#ffffff",onChange:n=>d({...t,ctaTextColor:n.target.value}),placeholder:"#ffffff"})]})]})]}),e.jsx("div",{className:"p-3 bg-slate-800 rounded-lg flex items-center justify-center min-h-[60
3px]",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-semibold rounded-md",style:{backgroundColor:t.ctaStyle==="solid"||t.ctaStyle==="pill"?t.ctaColor||"#2563eb":"transparent",color:t.ctaTextColor||"#ffffff",border:t.ctaStyle==="outline"?`2px solid ${t.ctaColor||"#2563eb"}`:"none",borderRadius:t.ctaStyle==="pill"?"9999px":"6px"},children:[t.ctaText||"Button Text"," â"]})})]})]})]})]}),e.jsx("div",{className:"w-72 shrink-0 flex flex-col bg-slate-50/50",children:e.jsxs("div",{className:"overflow-y-auto flex-1 p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-2",children:"Live Preview"}),e.jsx("div",{className:"relative rounded-lg overflow-hidden border border-slate-200 bg-slate-900",style:{height:300},children:t.mediaType==="gradient"?e.jsx(Zs,{banner:{title:t.title||"Banner Title",subtitle:t.subtitle,videoUrl:t.videoUrl,linkUrl:t.linkUrl,ctaText:t.ctaText,showCta:t.showCta},height:300}):t.mediaType==="youtube"&&t.youtubeUrl?e.jsx("iframe",{src:Ct(t.youtubeUrl),className:"w-full h-full",allowFullScreen:!0,allow:"autoplay; encrypted-media"}):(t.mediaType==="video"||t.mediaType==="gif")&&t.videoUrl?e.jsx("video",{src:t.videoUrl,poster:t.imageUrl||void 0,className:"w-full h-full object-cover",autoPlay:!0,muted:!0,loop:!0,playsInline:!0},t.videoUrl):t.imageUrl?e.jsxs("div",{className:"relative w-full h-full",children:[e.jsx("img",{src:t.imageUrl,alt:"Preview",className:"w-full h-full object-cover"}),t.showTitle&&(()=>{const n=t.overlayPosition||"bottom-left",q=t.overlayStyle||"gradient",V=q==="gradient"?n.startsWith("top")?"bg-gradient-to-b from-black/60 via-trans
3parent to-transparent":"bg-gradient-to-t from-black/60 via-transparent to-transparent":q==="solid"?n.startsWith("top")?"bg-gradient-to-b from-black/70 via-black/70 to-transparent":"bg-gradient-to-t from-black/70 via-black/70 to-transparent":"",Pe=n==="center"?"absolute inset-0 flex items-center justify-center text-center":n==="top-left"||n==="top-center"?`absolute top-0 left-0 right-0 p-3 ${n==="top-center"?"text-center":""}`:n==="bottom-center"?"absolute bottom-0 left-0 right-0 p-3 text-center":n==="bottom-right"?"absolute bottom-0 left-0 right-0 p-3 text-right":"absolute bottom-0 left-0 right-0 p-3",We=q==="glass"?"backdrop-blur-md bg-black/30 border border-white/20 rounded-xl p-3 shadow-xl max-w-xs mx-auto":"";return e.jsxs(e.Fragment,{children:[V&&e.jsx("div",{className:`absolute inset-0 ${V}`}),e.jsx("div",{className:Pe,children:e.jsxs("div",{className:We,children:[e.jsx("p",{className:"text-white text-sm font-black drop-shadow-2xl tracking-tight uppercase",children:t.title}),t.subtitle&&e.jsx("p",{className:"text-white/90 text-[10px] font-semibold drop-shadow mt-0.5",children:t.subtitle})]})})]})})(),t.overlayText&&(()=>{const n={"top-left":"absolute top-2 left-2","top-center":"absolute top-2 left-0 right-0 text-center px-2","top-right":"absolute top-2 right-2 text-right",center:"absolute inset-0 flex items-center justify-center text-center px-2","bottom-left":"absolute bottom-2 left-2","bottom-center":"absolute bottom-2 left-0 right-0 text-center px-2","bottom-right":"absolute bottom-2 right-2 text-right"},q={sm:"text-xs",md:"text-sm",lg:"text-sm",xl:"text-base","2xl":"text-lg"},V={normal:"font-normal",bold:"font-bold",extrabold:"font-extrabold"},Pe={none:"",sm:"drop-shadow",md:"drop-shadow-md",lg:"drop-shadow-lg"},We=t.overlayPosition2||"center";return e.jsx("div",{className:n[We]||"absolute inset-0 flex items-center justify-center text-center px-2",style:{pointerEvents:"none"},children:e.jsx("p",{className:`${q[t.overlayFontSize||"lg"]||"text-sm"} ${V[t.overlayFontWeight||"bold"]||"font-bold"} ${Pe[t.overlayShadow||"none"]||""} whitespace-pre-line leading-tight`,style:{color:t.overlayColor||"#ffffff",fontFamily:t.overlayFont&&t.overlayFont!=="inherit"?t.overlayFont:void 0},children:t.overlayText})})})(),t.showCta&&t.ctaText&&e.jsx("div",{className:"absolute bottom-3 left-0 right-0 flex justify-center",style:{pointerEvents:"none"},children:e.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-semibold",style:{backgroundColor:t.ctaStyle==="solid"||t.ctaStyle==="pill"?t.ctaColor||"#2563eb":"transparent",color:t.ctaTextColor||"#ffffff",border:t.ctaStyle==="outline"?`2px solid ${t.ctaColor||"#2563eb"}`:"none",borderRadius:t.ctaStyle==="pill"?"9999px":"6px"},children:[t.ctaText," â"]})})]}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-slate-400 text-xs",children:"No media selected"})})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-white rounded-lg border border-slate-200",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-slate-700",children:"Active on site"}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-0.5",children:"Visible to all visitors"})]}),e.jsx(be,{checked:t.isActive,onCheckedChange:n=>d({...t,isActive:n})})]}),Y.length>0&&e.jsxs("div",{children:[e.jsx(m,{className:"text-[10px] font-bold text-slate-500 uppercase tracking-widest mb-1 block",children:"Ad Zone"}),e.jsxs(P,{value:t.zoneId||"__none__",onValueChange:n=>d({...t,zoneId:n==="__none__"?"":n}),children:[e.jsx(B,{className:"h-8 text-xs",children:e.jsx(F,{placeholder:"Select zone"})}),e.jsxs(O,{children:[e.jsx(g,{value:"__none__",children:"Unassigned"}),Y.map(n=>e.jsx(g,{value:n.zoneKey,className:"text-xs",children:n.name},n.zoneKey))]})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-1",children:"Where this banner appears on site"})]})]})})]}),e.jsxs($e,{className:"px-6 py-4 border-t shrink-0",children:[e.jsx(r,{type:"button",variant:"outline",onClick:we,children:"Cancel"}),e.jsxs(r,{type:"submit",disabled:se,className:"gap-2",children:[se&&e.jsx(K,{className:"w-4 h-4 animate-spin"}),e.jsx(ss,{className:"w-4 h-4"}),z?"Save Changes":Le?"Create Marketing Banner":"Create Banner"]})]})]})}function Ca({banner:t,index:d,total:de,onEdit:we,onDelete:se,onToggleActive:z,onMove:X,onDuplicate:j,onToggleTemplate:J,onPreview:_,onFavorite:Y,onAiRedo:E,showOwner:ve=!1,selected:Z=!1,onSelect:u,onArchive:b}){var G,H;const k=h=>{switch(h){case"video":return e.jsx(ja,{className:"w-4 h-4 text-blue-500"});case"gif":return e.jsx(as,{className:"w-4 h-4 text-purple-500"});case"youtube":return e.jsx(ja,{className:"w-4 h-4 text-red-500"});default:return e.jsx(as,{className:"w-4 h-4 text-green-500"})}};return e.jsx(ge,{className:`overflow-hidden ${t.isActive?"":"opacity-60"}`,children:e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"flex items-center px-2 bg-slate-50 border-r cursor-grab active:cursor-grabbing select-none",title:"Drag to reorder",children:e.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[u&&e.jsx(es,{checked:Z,onCheckedChange:h=>u(t.id,h===!0),onClick:h=>h.stopPropagation(),className:"mb-1 bg-white","aria-label":`Select ${t.title}`}),e.jsx(za,{className:"w-4 h-4 text-slate-400"}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("button",{className:"p-0 h-4 w-4 flex items-center justify-center hover:text-slate-700 text-slate-300 disabled:opacity-20",disabled:d===0,onClick:h=>{h.stopPropagation(),X(t,"up")},title:"Move up",children:e.jsx(Il,{className:"w-3 h-3"})}),e.jsx("button",{className:"p-0 h-4 w-4 flex items-center justify-center hover:text-slate-700 text-slate-300 disabled:opacity-20",disabled:d===de-1,onClick:h=>{h.stopPropagation(),X(t,"down")},title:"Move down",children:e.jsx(Pl,{className:"w-3 h-3"})})]})]})}),e.jsxs("div",{className:"w-48 h-28 flex-shrink-0 bg-slate-100 relative group cursor-zoom-in",onClick:()=>_==null?void 0:_(t),title:"Click to preview full banner",children:[t.mediaType==="youtube"&&t.youtubeUrl?e.jsx("iframe",{src:Ct(t.youtubeUrl),className:"w-full h-full pointer-events-none",allowFullScreen:!0,allow:"autoplay; encrypted-media",draggable:!1}):t.mediaType==="video"&&t.videoUrl?e.jsx("video",{src:t.videoUrl,className:"w-full h-full object-cover",muted:!0,playsInl
3ine:!0,draggable:!1}):t.mediaType==="gradient"?e.jsx("div",{className:"w-full h-full overflow-hidden pointer-events-none",draggable:!1,children:e.jsx(Zs,{banner:{title:t.title,subtitle:t.subtitle,videoUrl:t.videoUrl,linkUrl:t.linkUrl,ctaText:t.ctaText,showCta:t.showCta},height:112})}):t.imageUrl?e.jsx("img",{src:t.imageUrl,alt:t.title,className:"w-full h-full object-cover",loading:"lazy",draggable:!1,onError:h=>{const W=h.currentTarget;W.style.display="none";const te=W.nextElementSibling;te&&(te.style.display="flex")}}):null,e.jsxs("div",{className:"w-full h-full hidden flex-col items-center justify-center bg-slate-200 gap-1",children:[e.jsx(as,{className:"w-6 h-6 text-slate-400"}),e.jsx("span",{className:"text-[10px] text-slate-500",children:"No preview"})]}),t.overlayText&&(()=>{const h=t,W={"top-left":"absolute top-1 left-1","top-center":"absolute top-1 left-0 right-0 text-center px-1","top-right":"absolute top-1 right-1 text-right",center:"absolute inset-0 flex items-center justify-center text-center px-1","bottom-left":"absolute bottom-1 left-1","bottom-center":"absolute bottom-1 left-0 right-0 text-center px-1","bottom-right":"absolute bottom-1 right-1 text-right"},te=h.overlayPosition2||"center";return e.jsx("div",{className:W[te]||"absolute inset-0 flex items-center justify-center text-center px-1",style:{pointerEvents:"none"},children:e.jsx("p",{className:"text-[9px] font-bold leading-tight whitespace-pre-line drop-shadow",style:{color:h.overlayColor||"#ffffff",fontFamily:h.overlayFont&&h.overlayFont!=="inherit"?h.overlayFont:void 0},children:h.overlayText.length>40?h.overlayText.substring(0,40)+"â¦":h.overlayText})})})(),t.showCta&&t.ctaText&&e.jsx("div",{className:"absolute bottom-1 left-0 right-0 flex justify-center",style:{pointerEvents:"none"},children:e.jsx("span",{className:"text-[8px] font-semibold px-1.5 py-0.5 rounded",style:{backgroundColor:t.ctaColor||"#2563eb",color:t.ctaTextColor||"#ffffff"},children:t.ctaText})}),e.jsxs("div",{className:"absolute top-2 left-2 bg-white/90 rounded px-1.5 py-0.5 flex items-center gap-1",children:[k(t.mediaType||"image"),e.jsx("span",{className:"text-xs font-medium capitalize",children:t.mediaType||"image"})]}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/30 transition-colors flex items-center justify-center",children:e.jsx(Bl,{className:"w-6 h-6 text-white opacity-0 group-hover:opacity-100 transition-opacity drop-shadow-lg"})})]}),e.jsxs("div",{className:"flex-1 p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsxs("span",{className:"text-xs bg-slate-200 text-slate-600 px-2 py-0.5 rounded",children:["#",d+1]}),e.jsx("h3",{className:"font-semibold text-slate-900",children:t.title}),!t.isActive&&e.jsx(T,{variant:"outline",className:"text-amber-700 border-amber-200 bg-amber-50",children:"Hidden"}),t.isTemplate&&e.jsxs(T,{variant:"outline",className:"text-purple-700 border-purple-200 bg-purple-50",children:[e.jsx(ts,{className:"w-3 h-3 mr-1"}),"Template"]}),ve&&t.ownerId&&e.jsxs(T,{variant:"outline",className:"text-blue-700 border-blue-200 bg-blue-50",children:[e.jsx(Aa,{className:"w-3 h-3 mr-1"}),"User #",t.ownerId]}),((G=t.imageUrl)==null?void 0:G.startsWith("/uploads/"))&&e.jsx(T,{variant:"outline",className:"text-red-700 border-red-200 bg-red-50 cursor-help",title:"This banner's image was uploaded locally and won't appear in production. Edit this banner and replace the image URL with a permanent link (CDN, Unsplash, etc.).",children:"â ï¸ Broken in prod"})]}),((H=t.imageUrl)==null?void 0:H.startsWith("/uploads/"))&&e.jsxs("p",{className:"text-xs text-red-600 bg-red-50 border border-red-200 rounded px-2 py-1 mt-1 mb-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"font-semibold",children:"Image not available in production."})," Edit this banner and paste a permanent image URL (e.g. from the Harbor Shoppers CDN or an external host)."]}),t.linkUrl&&e.jsxs("div",{className:"flex items-center gap-1 text-sm text-slate-600",children:[e.jsx(Fl,{className:"w-3 h-3"}),e.jsx("span",{className:"truncate max-w-xs",children:t.linkUrl})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 justify-start sm:justify-end",children:[e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>z(t),className:"gap-1",children:t.isActive?e.jsxs(e.Fragment,{children:[e.jsx(yt,{className:"w-4 h-4"}),"Visible"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ia,{className:"w-4 h-4"}),"Hidden"]})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>j(t.id),title:"Duplicate banner",children:e.jsx(_a,{className:"w-4 h-4"})}),Y&&e.jsx(r,{variant:"outline",size:"sm",onClick:()=>Y(t.id),title:"Save to Favorites (creates a protected copy)",className:"text-amber-500 border-amber-200 hover:bg-amber-50 hover:text-amber-600",children:e.jsx(Ye,{className:"w-4 h-4"})}),J&&e.jsx(r,{variant:"outline",size:"sm",onClick:()=>J(t.id),title:t.isTemplate?"Remove from templates":"Save as template",className:t.isTemplate?"text-purple-600 border-purple-200":"",children:e.jsx(ts,{className:"w-4 h-4"})}),E&&e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>
3E(t.id),title:"AI Redo â open HPG Studio with this banner pre-loaded",className:"text-purple-700 border-purple-200 hover:bg-purple-50 hover:text-purple-800 gap-1",children:[e.jsx(Ie,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs font-semibold",children:"AI Redo"})]}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>we(t),children:e.jsx(De,{className:"w-4 h-4"})}),b&&e.jsx(r,{variant:"outline",size:"sm",onClick:()=>b(t),title:t.archived?"Restore from archive":"Archive banner (hides it everywhere, keeps it saved)",className:"text-slate-600",children:t.archived?e.jsx(Nt,{className:"w-4 h-4"}):e.jsx(bs,{className:"w-4 h-4"})}),e.jsx(r,{variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50",onClick:()=>{confirm("Delete this banner?")&&se(t.id)},children:e.jsx(Ue,{className:"w-4 h-4"})})]})]})]})})}const qe={title:"",subtitle:"",mediaType:"image",imageUrl:"",videoUrl:"",youtubeUrl:"",linkUrl:"",displayDuration:5,showTitle:!1,overlayPosition:"bottom-left",overlayStyle:"gradient",isActive:!0,sortOrder:0,adType:"standard",adSize:"728x90",targetBrands:[],scheduleStart:"",scheduleEnd:"",zoneId:"",campaignBudget:"",overlayText:"",overlayDelay:0,overlayFont:"inherit",overlayFontSize:"lg",overlayFontWeight:"bold",overlayColor:"#ffffff",overlayShadow:"none",overlayAnimation:"none",overlayPosition2:"center",showCta:!1,ctaText:"",ctaUrl:"",ctaDelay:0,ctaStyle:"solid",ctaColor:"#2563eb",ctaTextColor:"#ffffff"};function Dl({toolBanners:t,onRefresh:d,onOpenStudio:de,onToggle:we,onDelete:se}){const{toast:z}=kt(),[X,j]=c.useState(null),[J,_]=c.useState(!1),Y=u=>t.find(b=>b.zoneId===`tool_hero_${u}`),E=Xs.filter(u=>!Y(u.slug)),ve=async u=>{j(u.slug);try{const b=await R("POST","/api/admin/tool-banners/generate",{slug:u.slug,name:u.name,tagline:u.tagline,description:u.description,gradientFrom:u.gradientFrom,gradientTo:u.gradientTo,accentColor:u.accentColor,primaryPath:u.primaryPath,instructions:u.studioDescription||""});if(b.status===409)z({title:"Already exists",description:`${u.name} already has a banner.`});else if(b.ok)z({title:"Banner created!",description:`AI banner generated for ${u.name}.`}),d();
3else{const k=await b.json();z({title:"Generation failed",description:k.message,variant:"destructive"})}}catch(b){z({title:"Error",description:b.message,variant:"destructive"})}finally{j(null)}},Z=async()=>{if(E.length===0){z({title:"All tools have banners",description:"Nothing to generate."});return}_(!0);let u=0,b=0;for(const k of E)try{j(k.slug);const G=await R("POST","/api/admin/tool-banners/generate",{slug:k.slug,name:k.name,tagline:k.tagline,description:k.description,gradientFrom:k.gradientFrom,gradientTo:k.gradientTo,accentColor:k.accentColor,primaryPath:k.primaryPath,instructions:k.studioDescription||""});G.ok||G.status===409?u++:b++}catch{b++}j(null),_(!1),z({title:"Batch complete",description:`${u} banners created. ${b>0?`${b} failed.`:""}`}),d()};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold text-slate-900 dark:text-white",children:"Tool Page Banners"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Create and toggle hero banners for each Harbor OS tool page. Banners are shown at the top of the tool's landing page."}),E.length>0&&e.jsxs("p",{className:"text-xs text-amber-600 mt-1",children:[E.length," tool",E.length!==1?"s":""," missing banners"]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[E.length>0&&e.jsxs(r,{size:"sm",variant:"outline",onClick:Z,disabled:J||!!X,className:"gap-1.5 text-xs border-violet-200 text-violet-700 hover:bg-violet-50",children:[J?e.jsx(K,{className:"w-3 h-3 animate-spin"}):e.jsx(Ie,{className:"w-3 h-3"}),J?`Generating ${X}â¦`:`AI Generate All (${E.length})`]}),e.jsxs(r,{variant:"outline",size:"sm",onClick:d,className:"gap-1.5",children:[e.jsx(Ua,{className:"w-3.5 h-3.5"}),"Refresh"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:Xs.map(u=>{const b=Y(u.slug),k=u.icon;return e.jsxs(ge,{className:"overflow-hidden",children:[e.jsxs("div",{className:"h-16 flex items-center px-4 gap-3",style:{background:`linear-gradient(135deg, ${u.gradientFrom} 0%, ${u.gradientTo} 100%)`},children:[e.jsx("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center shrink-0",style:{background:`${u.accentColor}25`,border:`1px solid ${u.accentColor}50`},children:e.jsx(k,{className:"w-4 h-4",style:{color:u.accentColor}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-white text-sm truncate",children:u.name}),e.jsx("div",{className:"text-xs truncate",style:{color:u.accentColor+"cc"},children:u.tagline.slice(0,50)})]})]}),e.jsx(je,{className:"p-4 space-y-3",children:b?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-semibold text-slate-700 dark:text-slate-300 truncate",children:b.title}),b.subtitle&&e.jsx("div",{className:"text-xs text-slate-500 truncate mt-0.5",children:b.subtitle})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-1",children:[e.jsx(be,{checked:!!b.isActive,onCheckedChange:()=>we(b),className:"scale-75"}),e.jsx(T,{variant:b.isActive?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:b.isActive?"Live":"Off"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 h-7 text-xs flex-1",onClick:()=>de(u.slug),children:[e.jsx(Ie,{className:"w-3 h-3"}),"Redesign"]}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7 text-red-500 hover:text-red-600 shrink-0",onClick:()=>{confirm(`Delete banner for ${u.name}?`)&&se(b.id)},children:e.jsx(Ue,{className:"w-3 h-3"})})]})]}):e.jsxs("div",{className:"space-y-2 py-1",children:[e.jsx("div",{className:"text-xs text-slate-400 text-center",children:"No banner yet"}),e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 h-7 text-xs w-full",onClick:()=>de(u.slug),children:[e.jsx(Ke,{className:"w-3 h-3"}),"HPG Studio"]}),e.jsx(r,{size:"sm",variant:"outline",className:"gap-1.5 h-7 text-xs w-full border-dashed border-violet-300 text-violet-600 hover:bg-violet-50",onClick:()=>ve(u),disabled:X===u.slug,children:X===u.slug?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-3 h-3 animate-spin"})," Generatingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-3 h-3"})," AI Quick Generate"]})})]})})]},u.slug)})})]})}const Nn=()=>{var Jt,Yt,Dt,ea,sa,ta,aa,la,na,ia,ra,oa;const{toast:t}=kt(),[d,de]=c.useState(()=>{const s=new URLSearchParams(window.location.search).get("tab");return["home","store","service_request","templates","marketing","google_ads","vendor_ads","placements","tool_pages"].includes(s??"")?s:"home"}),[we,se]=c.useState(!1),[z,X]=c.useState(null),[j,J]=c.useState(new Set),[_,Y]=c.useState(""),[E,ve]=c.useState(!1),[Z,u]=c.useState(!1),[b,k]=c.useState(!1),[G,H]=c.useState(0),[h,W]=c.useState({applySchedule:!1,scheduleStart:"",scheduleEnd:"",applyBrands:!1,targetBrands:[],activeState:"no_change"}),te=(s,a)=>{J(l=>{const i=new Set(l);return a?i.add(s):i.delete(s),i})},Se=()=>J(new Set),[ke,Ce]=c.useState(!1),[v,Ge]=c.useState("home"),[Js,fs]=c.useState(!1),[Ys,Ns]=c.useState(!1),[ys,Le]=c.useState(!1),[n,q]=c.useState(!1),[V,Pe]=c.useState([]),[We,Ba]=c.useState(!0),[Tt,At]=c.useState(!1),[ae,ws]=c.useState(null);c.useState(!1);const[Fa,ls]=c.useState(!1),[ns,Ds]=c.useState([]),[et,zt]=c.useState(!1),[Oa,_t]=c.useState(null),Ss=c.useRef(null),[st,Ut]=c.useState(null),[Ea,ks]=c.useState(!1),[He,tt]=c.useState([]),[Be,Ve]=c.useState(new Set),[f,Qe]=c.useState(null),$a=c.useRef(null),[is,Fe]=c.useState({...qe}),[It,La]=c.useState(null),Cs=c.useRef(!1),[Ma,Pt]=c.useState(!1),[D,Te]=c.useState({adsense_publisher_id:"",adsense_auto_ads_enabled:"false",vendor_ad_base_price_monthly:"29",vendor_ad_premium_price_monthly:"99",show_google_ads_in_empty_zones:"false",hide_empty_zones:"true"}),[le,rs]=c.useState({size:"all",brand:"all",status:"all",zone:"all",search:""}),[Bt,Ra]=c.useState(!1),[Ts,qa]=c.useState("all"),[Ka,Ga]=c.useState({}),[Me,os]=c.useState({banner:null,open:!1}),[fe,cs]=c.useState({banner:null,open:!1,reason:""}),[at,Ft]=c.useState(""),[lt,Wa]=c.useState("30"),[ds,Ha]=c.useState("impressions"),[Ot,Va]=c.useState("desc"),[Xe,Et]=c.useState(1),[xe,xs]=c.useState({name:"",slotId:"",adSize:"300x250",zoneId:"",isActive:!0}),[Qa,As]=c.useState(!1),{data:Ae=[],isLoading:Xa}=ce({queryKey:["/api/banners","all"],queryFn:async()=>{const s=await fetch("/api/banners?all=true",{cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:ze=[],isLoading:Za}=ce({queryKey:["/api/admin/store-banners"],queryFn:async()=>{const s=await fetch("/api/admin/store-banners",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:nt=[],isLoading:Ja}=ce({queryKey:["/api/banner-templates"],queryFn:async()=>{const s=await fetch("/api/banner-templates",{cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:ms=[],isLoading:Ya}=ce({queryKey:["/api/banners/scope/service_request"],queryFn:async()=>{const s=await fetch("/api/banners/scope/service_request",{cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:it=[],isLoading:Da}=ce({queryKey:["/api/admin/banners/scope/nautical-trips"],queryFn:async()=>{const s=await fetch("/api/admin/banners/scope/nautical-trips",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:Q=[]}=ce({queryKey:["/api/admin/ad-zones"],queryFn:async()=>{const s=await fetch("/api/admin/ad-zones",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0}),{data:Re=[]}=ce({queryKey:["/api/admin/banners/vendor-pending"],queryFn:async()=>{const s=await fetch("/api/admin/banners/vendor-pending",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),{data:$=[],refetch:$t}=ce({queryKey:["/api/admin/marketing-banners"],queryFn:async()=>{const s=await fetch("/api/admin/marketing-banners",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0}),{data:S}=ce({queryKey:["/api/admin/ad-analytics",lt],queryFn:async()=>{const s=await fetch(`/api/admin/ad-analytics?days=${lt}`,{credentials:"include"});return s.ok?s.json():null}}),{data:ee}=ce({queryKey:["/api/admin/ad-settings"],queryFn:async()=>{const s=await fetch("/api/admin/ad-settings",{credentials:"include"});if(!s.ok)return{};const a=await s.json();return Te(l=>({...l,...a})),a},staleTime:6e4}),zs=C({mutationFn:async({id:s,zoneId:a,scheduleStart:l,scheduleEnd:i})=>R("PUT",`/api/admin/banners/${s}/approve`,{zoneId:a,scheduleStart:l,scheduleEnd:i}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/banners/vendor-pending"]}),p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),t({title:"Ad approved and set live"}),os({banner:null,open:!1}),Ft("")},onError:s=>t({title:"Failed to approve",description:s.message,variant:"destructive"})}),rt=C({mutationFn:async({id:s,rejectionReason:a})=>R("PUT",`/api/admin/banners/${s}/reject`,{rejectionReason:a}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/banners/vendor-pending"]}),t({title:"Ad rejected",description:"Vendor will see the rejection reason."}),cs({banner:null,open:!1,reason:""})},onError:s=>t({title:"Failed to reject",description:s.message,variant:"destructive"})}),Oe=C({mutationFn:async s=>R("PUT","/api/admin/ad-settings",s),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-settings"]}),t({title:"Ad settings saved"})},onError:s=>t({title:"Failed to save settings",description:s.message,variant:"destructive"})});C({mutationFn:async s=>R("POST","/api/admin/ad-zones",s),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),t({title:"Zone created"})}});const ot=C({mutationFn:async({id:s,adsenseSlotId:a})=>R("PUT",`/api/admin/ad-zones/${s}`,{adsenseSlotId:a}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),t({title:"Zone AdSense slot saved"})},onError:s=>t({title:"Save failed",description:s.message,variant:"destructive"})});C({mutationFn:async({bannerId:s,zoneId:a})=>R("PUT",`/api/admin/banners/${s}`,{zoneId:a}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),p.invalidateQueries({queryKey:["/api/banners","all"]}),t({title:"Zone assignment updated"})}});const ct=C({mutationFn:async({bannerId:s,zoneIds:a})=>R("PUT",`/api/admin/banners/${s}/zones`,{zoneIds:a}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),p.invalidateQueries({queryKey:["/api/banners","all"]}),p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),t({title:"Zone assignments saved"})}}),Lt=C({mutationFn:async s=>R("PATCH",`/api/admin/ad-zones/${s}/toggle`,{}),onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/ad-zones"]}),t({title:"Zone status updated"})}}),[U,Mt]=c.useState(null),Ne=()=>{p.invalidateQueries({queryKey:["/api/banners","all"]}),p.invalidateQueries({queryKey:["/api/admin/store-banners"]}),p.invalidateQueries({queryKey:["/api/banner-templates"]}),p.invalidateQueries({queryKey:["/api/banners/scope/service_request"]}),p.invalidateQueries({queryKey:["/api/admin/banners/scope/nautical-trips"]}),p.invalidateQueries({queryKey:["/api/banners/scope/nautical-trips"]}),p.invalidateQueries({queryKey:["/api/admin/banners/vendor-pending"]}),p.invalidateQueries({queryKey:["/api/admin/ad-zones"]})},el=s=>{p.setQueryData(["/api/banners","all"],a=>a&&a.map(l=>l.id===s.id?s:l)),p.setQueryData(["/api/admin/store-banners"],a=>a&&a.map(l=>l.id===s.id?s:l)),p.setQueryData(["/api/banner-templates"],a=>a&&a.map(l=>l.id===s.id?s:l))},me=C({mutationFn:async({ids:s,set:a})=>(await R("POST","/api/admin/banners/bulk-update",{ids:s,set:a})).json(),onSuccess:(s,a)=>{Ne(),p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),$t();const l=a.ids.length,i=typeof(s==null?void 0:s.updated)=="number"?s.updated:l;if(i<l){const o=l-i;t({title:`${i} of ${l} banner${l===1?"":"s"} updated`,description:`${o} no longer exist${o===1?"s":""} â the list has been refreshed.`,variant:"destructive"})}else t({title:`${i} banner${i===1?"":"s"} updated`});Se(),k(!1)},onError:s=>{t({title:"Bulk update failed",description:s.message,variant:"destructive"})}}),_s=C({mutationFn:async s=>R("POST","/api/admin/banners/bulk-delete",{ids:s}),onSuccess:(s,a)=>{Ne(),p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),$t(),t({title:`${a.length} banner${a.length===1?"":"s"} deleted`}),Se(),H(0)},onError:s=>{t({title:"Bulk delete failed",description:s.message,variant:"destructive"}),H(0)}}),dt=s=>{me.mutate({ids:[s.id],set:{archived:!s.archived}})},hs=$.filter(s=>Z?s.archived:!s.archived).filter(s=>le.size==="all"||s.adSize===le.size).filter(s=>le.status==="all"||(le.status==="active"?s.isActive:!s.isActive)).filter(s=>le.zone==="all"||s.zoneId===le.zone).filter(s=>le.search===""||s.title.toLowerCase().includes(le.search.toLowerCase())||(s.linkUrl||"").toLowerCase().includes(le.search.toLowerCase())),ye=s=>s.filter(a=>!a.archived).length,Ze=C({mutationFn:async s=>R("POST","/api/admin/banners",{...s,scope:s.scope||v}),onSuccess:()=>{Ne(),t({title:"Banner created successfully"}),Fs()},onError:s=>{t({title:"Failed to create banner",description:s.message,variant:"destructive"})}}),us=C({mutationFn:async({id:s,data:a})=>
3await(await R("PUT",`/api/admin/banners/${s}`,a)).json(),onMutate:({id:s,data:a})=>{const l=o=>o&&o.map(x=>x.id===s?{...x,...a}:x),i={home:p.getQueryData(["/api/banners","all"]),store:p.getQueryData(["/api/admin/store-banners"])};return p.setQueryData(["/api/banners","all"],l),p.setQueryData(["/api/admin/store-banners"],l),i},onSuccess:s=>{el(s),Ne(),t({title:"Banner updated successfully"}),Fs()},onError:(s,a,l)=>{l!=null&&l.home&&p.setQueryData(["/api/banners","all"],l.home),l!=null&&l.store&&p.setQueryData(["/api/admin/store-banners"],l.store),t({title:"Failed to update banner",description:s.message,variant:"destructive"})}}),Us=C({mutationFn:async s=>{const a=await fetch(`/api/admin/banners/${s}`,{method:"DELETE",credentials:"include"});if(a.status===404)return{alreadyGone:!0,id:s};if(!a.ok)throw new Error((await a.json()).message||"Delete failed");return{alreadyGone:!1,id:s}},onSuccess:s=>{Ne(),s!=null&&s.alreadyGone||t({title:"Banner deleted"})},onError:s=>{t({title:"Failed to delete banner",description:s.message,variant:"destructive"})}}),xt=C({mutationFn:async s=>R("POST",`/api/admin/banners/${s}/duplicate`,{}),onSuccess:()=>{Ne(),t({title:"Banner duplicated successfully"})},onError:s=>{t({title:"Failed to duplicate banner",description:s.message,variant:"destructive"})}}),{data:Is=[]}=ce({queryKey:["/api/admin/banner-favorites"],queryFn:async()=>{const s=await fetch("/api/admin/banner-favorites",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch favorites");return s.json()}}),{data:mt=[],refetch:sl}=ce({queryKey:["/api/admin/tool-banners"],queryFn:async()=>{const s=await fetch("/api/admin/tool-banners",{credentials:"include",cache:"no-store"});return s.ok?s.json():[]},staleTime:0,refetchOnMount:"always"}),[Ee,ht]=c.useState(null),Rt=C({mutationFn:async s=>{const a=await fetch(`/api/admin/banners/${s}/favorite`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!a.ok)throw new Error((await a.json()).message||"Failed");return a.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/banner-favorites"]}),t({title:"â Saved to Favorites!",description:"A protected copy is stored in your Favorites tab."})},onError:s=>t({title:"Failed to save favorite",description:s.message,variant:"destructive"})}),Ps=C({mutationFn:async({id:s,deployAs:a})=>{const l=await fetch(`/api/admin/banner-favorites/${s}/deploy`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({deployAs:a})});if(!l.ok)throw new Error((await l.json()).message||"Failed");return l.json()},onSuccess:(s,a)=>{Ne(),t({title:`Deployed to ${a.deployAs==="marketing"?"Marketing Banners":"Home Page"}`,description:"A live copy was created. Your favorite is still safe."})},onError:s=>t({title:"Deploy failed",description:s.message,variant:"destructive"})}),tl=C({mutationFn:async s=>{const a=await fetch(`/api/admin/banner-favorites/${s}`,{method:"DELETE",credentials:"include"});if(!a.ok)throw new Error("Failed");return a.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/banner-favorites"]}),t({title:"Removed from favorites"})},onError:()=>t({title:"Failed to remove favorite",variant:"destructive"})}),al=C({mutationFn:async s=>R("PUT",`/api/admin/banners/${s}/template`,{}),onSuccess:()=>{Ne(),t({title:"Template status updated"})},onError:s=>{t({title:"Failed to update template",description:s.message,variant:"destructive"})}}),ps=C({mutationFn:async s=>{const a=await fetch("/api/admin/marketing-banners",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(s)});if(!a.ok)throw new Error((await a.json()).message||"Failed");return a.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),t({title:"Marketing banner created!"})},onError:s=>t({title:"Failed to create banner",description:s.message,variant:"destructive"})});C({mutationFn:async({id:s,data:a})=>{const l=await fetch(`/api/admin/marketing-banners/${s}`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(a)});if(!l.ok)throw new Error((await l.json()).message||"Failed");return l.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),t({title:"Banner updated!"})},onError:s=>t({title:"Failed to update banner",description:s.message,variant:"destructive"})});const ll=C({mutationFn:async s=>{if(!(await fetch(`/api/admin/marketing-banners/${s}`,{method:"DELETE",credentials:"include"})).ok)throw new Error("Delete failed")},onSuccess:()=>{p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),t({title:"Banner deleted"})}}),nl=C({mutationFn:async({id:s,isActive:a})=>(await fetch(`/api/admin/marketing-banners/${s}/toggle`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({isActive:a})})).json(),onSuccess:()=>p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]})}),il=async()=>{try{const s=await fetch("/api/admin/marketing-banners/export",{credentials:"include"});if(!s.ok){t({title:"Export failed",variant:"destructive"});return}const a=await s.blob(),l=new Date().toISOString().slice(0,10),i=URL.createObjectURL(a),o=document.createElement("a");o.href=i,o.download=`hs3_marketing_banners_${l}.json`,o.click(),URL.revokeObjectURL(i),t({title:"Exported!",description:`${$.length} banners downloaded as JSON.`})}catch{t({title:"Export failed",variant:"destructive"})}},rl=async()=>{zt(!0),ls(!0),Ds([]);try{const s=await fetch("/api/admin/marketing-banners/duplicates",{credentials:"include"}),a=await s.json();if(!s.ok){t({title:"Failed to load duplicates",variant:"destructive"}),ls(!1);return}Ds(a.groups||[])}catch{t({title:"Failed to load duplicates",variant:"destructive"}),ls(!1)}finally{zt(!1)}},ol=async(s,a)=>{_t(a);try{if(!(await fetch("/api/admin/marketing-banners/deduplicate",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({keepId:s,title:a})})).ok){t({title:"Failed to resolve",variant:"destructive"});return}Ds(i=>i.filter(o=>o.title!==a)),p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]}),t({title:"Resolved",description:`Kept banner #${s} for "${a}".`})}catch{t({title:"Failed to resolve",variant:"destructive"})}finally{_t(null)}},cl=s=>{var i;const a=(i=s.target.files)==null?void 0:i[0];if(!a)return;const l=new FileReader;l.onload=o=>{var x;try{const w=JSON.parse((x=o.target)==null?void 0:x.result),L=Array.isArray(w)?w:w.banners;if(!Array.isArray(L)){t({title:"Invalid file â expected a JSON export from HS3",variant:"destructive"});return}Pe(L),ws(null),q(!0)}catch{t({title:"Could not parse JSON file",variant:"destructive"})}},l.readAsText(a),Ss.current&&(Ss.current.value="")},dl=async()=>{At(!0);try{const s=await fetch("/api/admin/marketing-banners/import",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({banners:V,deactivateImported:We})}),a=await s.json();if(!s.ok){t({title:"Import failed",description:a.message,variant:"destructive"});return}ws(a),p.invalidateQueries({queryKey:["/api/admin/marketing-banners"]})}catch{t({title:"Import failed",variant:"destructive"})}finally{At(!1)}},qt=C({mutationFn:async s=>R("PUT","/api/admin/banners/reorder",{items:s}),onMutate:s=>{const a=new Map(s.map(({id:o,sortOrder:x})=>[o,x])),l=o=>o&&o.map(x=>a.has(x.id)?{...x,sortOrder:a.get(x.id)}:x),i={home:p.getQueryData(["/api/banners","all"]),store:p.getQueryData(["/api/admin/store-banners"])};return p.setQueryData(["/api/banners","all"],l),p.setQueryData(["/api/admin/store-banners"],l),i},onError:(s,a,l)=>{l!=null&&l.home&&p.setQueryData(["/api/banners","all"],l.home),l!=null&&l.store&&p.setQueryData(["/api/admin/store-banners"],l.store),t({title:"Failed to reorder banners",variant:"destructive"})},onSuccess:()=>{Ne()}}),Bs=C({mutationFn:async()=>{const s=await fetch("/api/admin/banners/wp-import-preview",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch WordPress banners");return s.json()},onSuccess:s=>{tt(s.banners);const a=new Set(s.banners.filter(l=>l.imageUrl).map(l=>l.wpId));Ve(a)},onError:()=>{t({title:"Failed to fetch WordPress banners",variant:"destructive"})}}),ut=C({mutationFn:async s=>R("POST","/api/admin/banners/wp-import",{banners:s}),onSuccess:s=>
3{Ne(),ks(!1),tt([]),Ve(new Set),t({title:`Imported ${s.imported} banner${s.imported!==1?"s":""} from WordPress`})},onError:()=>{t({title:"Failed to import banners",variant:"destructive"})}}),xl=()=>{ks(!0),tt([]),Ve(new Set),Bs.mutate()},ml=s=>{Ve(a=>{const l=new Set(a);return l.has(s)?l.delete(s):l.add(s),l})},hl=()=>{const s=He.filter(a=>Be.has(a.wpId)&&a.imageUrl).map(a=>({title:a.title,imageUrl:a.imageUrl,linkUrl:a.linkUrl}));if(s.length===0){t({title:"No banners with images selected",variant:"destructive"});return}ut.mutate(s)},Kt=async s=>{Ce(!0);const a=new FormData;a.append("images",s);try{const l=await fetch("/api/upload/images",{method:"POST",body:a,credentials:"include"});if(!l.ok)throw new Error("Upload failed");const o=(await l.json()).files[0].url;s.type.startsWith("video/")?(Fe(x=>({...x,videoUrl:o,mediaType:"video",imageUrl:""})),t({title:"Video uploaded! Add a thumbnail image below."})):s.name.toLowerCase().endsWith(".gif")||s.type==="image/gif"?(Fe(x=>({...x,imageUrl:o,mediaType:"gif"})),t({title:"GIF uploaded successfully"})):(Fe(x=>({...x,imageUrl:o})),t({title:"Image uploaded successfully"}))}catch{t({title:"Upload failed",variant:"destructive"})}finally{Ce(!1)}},ul=async s=>{var l;const a=(l=s.target.files)==null?void 0:l[0];a&&await Kt(a)},pt=(s="home")=>{X(null),Ge(s),Fe({...qe,sortOrder:(s==="home"?Ae:ze).length}),se(!0)},_e=s=>{X(s),Ge(s.scope||"home"),Fe({title:s.title,mediaType:s.mediaType||"image",imageUrl:s.imageUrl||"",videoUrl:s.videoUrl||"",youtubeUrl:s.youtubeUrl||"",linkUrl:s.linkUrl||"",displayDuration:s.displayDuration||5,showTitle:s.showTitle===!0,overlayPosition:s.overlayPosition||"bottom-left",overlayStyle:s.overlayStyle||"gradient",subtitle:s.subtitle||"",isActive:s.isActive,sortOrder:s.sortOrder||0,adType:s.adType||"standard",adSize:s.adSize||"728x90",targetBrands:[],scheduleStart:"",scheduleEnd:"",zoneId:s.zoneId||"",campaignBudget:s.campaignBudget||"",overlayText:s.overlayText||"",overlayDelay:s.overlayDelay??0,overlayFont:s.overlayFont||"inherit",overlayFontSize:s.overlayFontSize||"lg",overlayFontWeight:s.overlayFontWeight||"bold",overlayColor:s.overlayColor||"#ffffff",overlayShadow:s.overlayShadow||"none",overlayAnimation:s.overlayAnimation||"none",overlayPosition2:s.overlayPosition2||"center",showCta:s.showCta===!0,ctaText:s.ctaText||"",ctaUrl:s.ctaUrl||"",ctaDelay:s.ctaDelay??0,ctaStyle:s.ctaStyle||"solid",ctaColor:s.ctaColor||"#2563eb",ctaTextColor:s.ctaTextColor||"#ffffff"}),se(!0)};c.useEffect(()=>{const s=new URLSearchParams(window.location.search),a=s.get("editBanner"),l=s.get("returnTo");if(l&&La(decodeURIComponent(l)),!a||Cs.current)return;const i=parseInt(a,10);if(isNaN(i))return;const x=[...Ae,...ze,...ms,...$].find(w=>w.id===i);if(x){Cs.current=!0,_e(x);return}R("GET",`/api/admin/banners/${i}`).then(w=>w.json()).then(w=>{w!=null&&w.id&&!Cs.current&&(Cs.current=!0,_e(w))}).catch(()=>{})},[Ae,ze,ms,$]);const Fs=()=>{se(!1),X(null),Fe({...qe})},pl="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",gl=s=>{s.preventDefault();const a=is.mediaType==="gradient"?{...is,imageUrl:is.imageUrl||pl}:is;z?us.mutate({id:z.id,data:a}):Ze.mutate(a)},Gt=s=>{us.mutate({id:s.id,data:{isActive:!s.isActive}})},Os=c.useRef(-1),gt=c.useRef(-1),[Wt,Ht]=c.useState(-1),[Vt,Qt]=c.useState(-1),Xt=s=>{gt.current=s,Qt(s)},Zt=()=>{Os.current=-1,gt.current=-1,Ht(-1),Qt(-1)},vl=(s,a,l)=>{const i=[...l].sort((A,M)=>(A.sortOrder||0)-(M.sortOrder||0)),o=i.findIndex(A=>A.id===s.id),x=a==="up"?o-1:o+1;if(x<0||x>=i.length)return;const w=[...i],[L]=w.splice(o,1);w.splice(x,0,L),qt.mutate(w.map((A,M)=>({id:A.id,sortOrder:M+1})))},jl=(s,a)=>{const l=Os.current;if(l<0||a<0)return;const i=[...s].sort((A,M)=>(A.sortOrder||0)-(M.sortOrder||0)),o=i.findIndex(A=>A.id===l);if(o<0||a===o||a===o+1)return;const x=[...i],[w]=x.splice(o,1),L=a>o?a-1:a;x.splice(L,0,w),qt.mutate(x.map((A,M)=>({id:A.id,sortOrder:M+1})))},gs=(s,a,l,i=!1)=>{const o=_.trim().toLowerCase(),x=N=>!o||(N.title||"").toLowerCase().includes(o)||(N.linkUrl||"").toLowerCase().includes(o),w=s.filter(x),L=w.filter(N=>!N.archived),A=w.filter(N=>N.archived),M=[...L].sort((N,he)=>(N.sortOrder||0)-(he.sortOrder||0)),Je=[...A].sort((N,he)=>(N.sortOrder||0)-(he.sortOrder||0)),vs=e.jsxs("div",{className:"relative mb-3",children:[e.jsx(ft,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}
3),e.jsx(y,{value:_,onChange:N=>Y(N.target.value),placeholder:"Search banners by title or linkâ¦",className:"pl-9 h-9"})]}),Es=A.length>0&&e.jsxs("div",{className:"mt-6 border-t pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>ve(N=>!N),className:"flex items-center gap-2 text-sm font-medium text-slate-600 hover:text-slate-900 mb-3",children:[e.jsx(bs,{className:"w-4 h-4"}),"Archived (",A.length,")",e.jsx(wt,{className:`w-4 h-4 transition-transform ${E?"rotate-180":""}`})]}),E&&e.jsx("div",{className:"flex flex-col gap-2 opacity-80",children:Je.map((N,he)=>e.jsx(Ca,{banner:N,index:he,total:Je.length,onEdit:_e,onDelete:I=>Us.mutate(I),onToggleActive:Gt,onMove:()=>{},onDuplicate:I=>xt.mutate(I),onPreview:Qe,showOwner:i,selected:j.has(N.id),onSelect:te,onArchive:dt},N.id))})]});if(a)return e.jsx("div",{className:"grid gap-4",children:[1,2,3].map(N=>e.jsx("div",{className:"h-32 bg-slate-200 animate-pulse rounded-lg"},N))});if(L.length===0)return e.jsxs("div",{children:[(s.length>0||o)&&vs,e.jsx(ge,{children:e.jsxs(je,{className:"py-12 text-center",children:[e.jsx(as,{className:"w-12 h-12 mx-auto text-slate-400 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:o?"No banners match your search":"No banners yet"}),e.jsx("p",{className:"text-slate-600 mb-4",children:o?"Try a different title or link.":l==="home"?"Create your first banner to display on the home page.":l==="template"?"Mark banners as templates to make them available for vendors to copy.":"No store banners from vendors yet."}),l!=="template"&&!o&&e.jsxs(r,{onClick:()=>pt(l),variant:"outline",className:"gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"Create Banner"]})]})}),Es]});const ca=Os.current>=0||Wt>=0;return e.jsxs("div",{children:[vs,e.jsxs("div",{className:"flex flex-col",onDragOver:N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},onDrop:N=>{N.preventDefault(),N.stopPropagation(),jl(L,gt.current),Zt()},onDragLeave:N=>{N.currentTarget.contains(N.relatedTarget)||Xt(-1)},children:[M.map((N,he)=>e.jsxs("div",{children:[e.jsx("div",{className:`mx-3 rounded-full transition-all duration-100 ${ca&&Vt===he?"h-[3px] bg-primary shadow-sm my-1":"h-0 bg-transparent my-0"}`}),e.jsx("div",{draggable:!0,onDragStart:I=>{Os.current=N.id,Ht(he),I.dataTransfer.effectAllowed="move"},onDragOver:I=>{I.preventDefault(),I.stopPropagation(),I.dataTransfer.dropEffect="move";const $s=I.currentTarget.getBoundingClientRect();Xt(I.clientY<$s.top+$s.height/2?he:he+1)},onDragEnd:Zt,className:`rounded-lg transition-all duration-150 ${Wt===he?"opacity-30":""}`,children:e.jsx(Ca,{banner:N,index:he,total:M.length,onEdit:_e,onDelete:I=>Us.mutate(I),onToggleActive:Gt,onMove:(I,$s)=>vl(I,$s,L),onDuplicate:I=>xt.mutate(I),onToggleTemplate:I=>al.mutate(I),onPreview:Qe,onFavorite:I=>Rt.mutate(I),onAiRedo:I=>{Ut(I),Le(!0)},showOwner:i,selected:j.has(N.id),onSelect:te,onArchive:dt})})]},N.id)),e.jsx("div",{className:`mx-3 rounded-full transition-all duration-100 ${ca&&Vt===M.length?"h-[3px] bg-primary shadow-sm my-1":"h-0 bg-transparent my-0"}`})]}),Es]})};return e.jsxs(Rl,{children:[It&&e.jsxs("div",{className:"sticky top-0 z-40 bg-blue-600 text-white px-4 py-2 flex items-center gap-3 shadow-md",children:[e.jsx(r,{size:"sm",variant:"ghost",className:"text-white hover:text-white hover:bg-blue-700 gap-1.5 h-7 px-2",onClick:()=>{window.location.href=It},children:"â Back to page"}),e.jsx("span",{className:"text-blue-200 text-sm",children:"|"}),e.jsx("span",{className:"text-blue-100 text-sm",children:z?`Editing banner #${z.id}: ${z.title}`:"Quick-edit mode â banner will auto-open below"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-slate-900",children:"Banner & Ad Management"}),e.jsx("p",{className:"text-slate-600 mt-1",children:"Manage banners, ads, and the full ad monetization platform."})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap justify-end",children:[e.jsxs(r,{onClick:xl,variant:"outline",className:"gap-2",children:[e.jsx(Ls,{className:"w-4 h-4"}),"Import from WordPress"]}),e.jsxs(r,{onClick:()=>Le(!0),variant:"outline",className:"gap-2 border-blue-200 bg-blue-50 text-blue-700 hover:bg-blue-100",children:[e.jsx(xa,{
3className:"w-4 h-4"}),"HPG Studio"]}),e.jsxs(r,{onClick:()=>fs(!0),className:"gap-2 bg-gradient-to-r from-amber-500 to-orange-500 hover:from-amber-600 hover:to-orange-600 text-white",children:[e.jsx(Ie,{className:"w-4 h-4"}),"AI Banner Maker"]}),e.jsxs(r,{onClick:()=>Ns(!0),className:"gap-2 bg-gradient-to-r from-teal-500 to-cyan-600 hover:from-teal-600 hover:to-cyan-700 text-white",children:[e.jsx(Ta,{className:"w-4 h-4"}),"AI Animated"]}),e.jsxs(r,{onClick:()=>pt(d==="store"?"store":d==="service_request"?"service_request":"home"),className:"gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"Add Banner"]}),e.jsx(r,{variant:"outline",size:"icon",onClick:()=>Pt(!0),title:"Ad System Settings",children:e.jsx(ma,{className:"w-4 h-4"})})]})]}),e.jsxs(Ol,{value:d,onValueChange:s=>{de(s),Se(),Y("")},children:[e.jsx("div",{style:{overflowX:"auto",paddingBottom:"4px"},children:e.jsxs(El,{style:{width:"max-content",justifyContent:"flex-start"},children:[e.jsxs(ue,{value:"home",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(vt,{className:"w-4 h-4"}),"Home Page",ye(Ae)>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:ye(Ae)})]}),e.jsxs(ue,{value:"store",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(ha,{className:"w-4 h-4"}),"Store",ye(ze)>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:ye(ze)})]}),e.jsxs(ue,{value:"service_request",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(ua,{className:"w-4 h-4"}),"Services",ye(ms)>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:ye(ms)})]}),e.jsxs(ue,{value:"nautical_trips",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(pa,{className:"w-4 h-4"}),"Nautical Trips",ye(it)>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:ye(it)})]}),e.jsxs(ue,{value:"templates",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(ts,{className:"w-4 h-4"}),"Templates",nt.length>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:nt.length})]}),e.jsxs(ue,{value:"marketing",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(Ms,{className:"w-4 h-4"}),"Marketing Banners"]}),e.jsxs(ue,{value:"google_ads",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(jt,{className:"w-4 h-4"}),"Google Ads"]}),e.jsxs(ue,{value:"vendor_ads",className:"gap-1.5 whitespace-nowrap relative",children:[e.jsx(Aa,{className:"w-4 h-4"}),"Vendor Ads",Re.length>0&&e.jsx("span",{className:"ml-1 inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold bg-red-500 text-white rounded-full",children:Re.length})]}),e.jsxs(ue,{value:"placements",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(Nl,{className:"w-4 h-4"}),"Placements"]}),e.jsxs(ue,{value:"analytics",className:"gap-1.5 whitespace-nowrap",children:[e.jsx(ga,{className:"w-4 h-4"}),"Analytics"]}),e.jsxs(ue,{value:"favorites",className:"gap-1.5 whitespace-nowrap text-amber-600 data-[state=active]:text-amber-700",children:[e.jsx(Ye,{className:"w-4 h-4"}),"Favorites",Is.length>0&&e.jsx("span",{className:"ml-1 bg-amber-100 text-amber-700 text-xs font-semibold rounded-full px-1.5 py-0.5 leading-none",children:Is.length})]}),e.jsxs(ue,{value:"tool_pages",className:"gap-1.5 whitespace-nowrap text-cyan-600 data-[state=active]:text-cyan-700",children:[e.jsx(Rs,{className:"w-4 h-4"}),"Tool Pages",ye(mt)>0&&e.jsx(T,{variant:"secondary",className:"ml-1 h-5 px-1.5 text-xs",children:ye(mt)})]})]})}),e.jsxs(pe,{value:"home",className:"mt-6",children:[e.jsx("div",{className:"mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-blue-800",children:[e.jsx(vt,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"These banners appear on the main home page hero carousel. Drag the ",e.jsx(za,{className:"w-3.5 h-3.5 inline mx-0.5 -mt-0.5"})," handle to reorder, or use the ââ arrows."]})}),gs(Ae,Xa,"home")]}),e.jsxs(pe,{value:"store",className:"mt-6",children:[e.jsx("div",{className:"mb-4 p-3 bg-emerald-50 border border-emerald-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-emerald-800",children:[e.jsx(ha,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}
3),"Store banners created by vendors for their individual store pages. You can manage, edit, or copy any vendor's banners."]})}),gs(ze,Za,"store",!0)]}),e.jsxs(pe,{value:"service_request",className:"mt-6",children:[e.jsx("div",{className:"mb-4 p-3 bg-orange-50 border border-orange-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-orange-800",children:[e.jsx(ua,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"These banners appear at the top of the ",e.jsx("strong",{children:"Request Help"})," page (/services/request/new). Use them to attract boaters to broadcast their service needs to vendors."]})}),gs(ms,Ya,"service_request")]}),e.jsxs(pe,{value:"nautical_trips",className:"mt-6",children:[e.jsx("div",{className:"mb-4 p-3 bg-sky-50 border border-sky-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-sky-800",children:[e.jsx(pa,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"These banners appear in the hero of the ",e.jsx("strong",{children:"Nautical Trips"})," brand landing page (/nauticaltrips, nauticaltrips.com). The first active banner is used as the hero background."]})}),gs(it,Da,"nautical-trips")]}),e.jsxs(pe,{value:"templates",className:"mt-6",children:[e.jsx("div",{className:"mb-4 p-3 bg-purple-50 border border-purple-200 rounded-lg",children:e.jsxs("p",{className:"text-sm text-purple-800",children:[e.jsx(ts,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"Banner templates that vendors can copy and customize for their store pages. Mark any banner as a template using the template button."]})}),gs(nt,Ja,"template")]}),e.jsxs(pe,{value:"marketing",className:"mt-6",children:[e.jsxs("div",{className:`mb-4 p-3 rounded-lg border flex flex-wrap items-center justify-between gap-3 ${(ee==null?void 0:ee.marketing_banners_enabled)==="false"?"bg-red-50 border-red-200":"bg-emerald-50 border-emerald-200"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:`text-sm font-semibold ${(ee==null?void 0:ee.marketing_banners_enabled)==="false"?"text-red-800":"text-emerald-800"}`,children:(ee==null?void 0:ee.marketing_banners_enabled)==="false"?"Marketing banners are HIDDEN site-wide":"Marketing banners are showing site-wide"}),e.jsx("p",{className:"text-xs text-slate-600 mt-0.5",children:"Turn this off to hide every marketing banner zone (top bar, homepage, shop, footerâ¦) across the whole site without deleting or deactivating individual banners."})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-xs text-slate-500",children:(ee==null?void 0:ee.marketing_banners_enabled)==="false"?"Hidden":"Visible"}),e.jsx(be,{checked:(ee==null?void 0:ee.marketing_banners_enabled)!=="false",onCheckedChange:s=>Oe.mutate({marketing_banners_enabled:s?"true":"false"}),disabled:Oe.isPending})]})]}),e.jsxs("div",{className:"mb-4 p-3 bg-indigo-50 border border-indigo-200 rounded-lg flex items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm text-indigo-800",children:[e.jsx(Ms,{className:"w-4 h-4 inline mr-1.5 -mt-0.5"}),"Paid placement banners shown in ad zones across the site. Use filters below to find and manage them."]}),e.jsxs(r,{variant:"outline",size:"sm",className:"shrink-0 gap-1.5 border-indigo-300 text-indigo-700 hover:bg-indigo-100",onClick:()=>Ra(s=>!s),children:[e.jsx(ts,{className:"w-3.5 h-3.5"}),Bt?"Hide":"Create Default Banners"]})]}),Bt&&e.jsxs("div",{className:"mb-5 border border-purple-200 rounded-xl bg-purple-50/60 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-purple-900 text-sm flex items-center gap-1.5",children:[e.jsx(ts,{className:"w-4 h-4"})," Default Zone Banners"]}),e.jsx("p",{className:"text-xs text-purple-700 mt-0.5",children:'Click any zone to instantly create a gradient "Advertise Here" placeholder banner for it.'})]}),e.jsxs(r,{size:"sm",className:"gap-1.5 bg-purple-600 hover:bg-purple-700 text-white",disabled:ps.isPending,onClick:async()=>{const s={leaderboard_top:"728x90",vendor_store_banner:"728x90",brand_front_banner:"728x90",homepage_mid:"300x250",shop_top:"728x90",footer_bar:"728x90",sidebar_right:"160x600",sidebar_left:"160x600"},a=new Set($.map(i=>i.zoneId)),l=Q.filter(i=>!a.has(i.zoneKey));if(l.length===0){t({title:"All zones already have banners!"});return}for(const i of l)await ps.mutateAsync({title:`${i.name}
3 â Advertise Here`,subtitle:"Your brand, front and center",mediaType:"gradient",imageUrl:"",isActive:!0,sortOrder:0,adType:"marketing",adSize:s[i.zoneKey]||"728x90",zoneId:i.zoneKey,showCta:!0,ctaText:"Advertise Here",ctaUrl:"/advertise",ctaDelay:1,ctaStyle:"pill",ctaColor:"#7c3aed",ctaTextColor:"#ffffff",overlayText:i.name,overlayAnimation:"fade",overlayPosition2:"center",overlayFontSize:"2xl",overlayFontWeight:"bold",overlayColor:"#ffffff",overlayShadow:"md"});t({title:`Created ${l.length} default banner(s)!`})},children:[e.jsx(Ke,{className:"w-3.5 h-3.5"}),"Create All Missing Defaults"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2",children:Q.map(s=>{const a={leaderboard_top:"728x90",vendor_store_banner:"728x90",brand_front_banner:"728x90",homepage_mid:"300x250",shop_top:"728x90",footer_bar:"728x90",sidebar_right:"160x600",sidebar_left:"160x600"},l=$.some(i=>i.zoneId===s.zoneKey);return e.jsxs("div",{className:`flex items-center justify-between rounded-lg border p-2.5 text-xs ${l?"bg-white border-slate-200 opacity-60":"bg-white border-purple-200 hover:border-purple-400"}`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-slate-800 truncate max-w-[100px]",children:s.name}),e.jsx("div",{className:"text-slate-400 font-mono",children:a[s.zoneKey]||"728x90"})]}),l?e.jsx(T,{variant:"secondary",className:"text-xs shrink-0",children:"â Has banner"}):e.jsxs(r,{size:"sm",variant:"outline",className:"h-7 text-xs shrink-0 border-purple-300 text-purple-700 hover:bg-purple-100",disabled:ps.isPending,onClick:()=>{ps.mutate({title:`${s.name} â Advertise Here`,subtitle:"Your brand, front and center",mediaType:"gradient",imageUrl:"",isActive:!0,sortOrder:0,adType:"marketing",adSize:a[s.zoneKey]||"728x90",zoneId:s.zoneKey,showCta:!0,ctaText:"Advertise Here",ctaUrl:"/advertise",ctaDelay:1,ctaStyle:"pill",ctaColor:"#7c3aed",ctaTextColor:"#ffffff",overlayText:s.name,overlayAnimation:"fade",overlayPosition2:"center",overlayFontSize:"2xl",overlayFontWeight:"bold",overlayColor:"#ffffff",overlayShadow:"md"})},children:[e.jsx(Ke,{className:"w-3 h-3 mr-0.5"}),"Create"]})]},s.zoneKey)})})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsxs(P,{value:le.size,onValueChange:s=>rs(a=>({...a,size:s})),children:[e.jsx(B,{className:"w-40 h-8 text-xs",children:e.jsx(F,{placeholder:"All Sizes"})}),e.jsxs(O,{children:[e.jsx(g,{value:"all",children:"All Sizes"}),Object.entries(Vs).map(([s,a])=>e.jsx(g,{value:s,children:a},s))]})]}),e.jsxs(P,{value:le.brand,onValueChange:s=>rs(a=>({...a,brand:s})),children:[e.jsx(B,{className:"w-44 h-8 text-xs",children:e.jsx(F,{placeholder:"All Brands"})}),e.jsxs(O,{children:[e.jsx(g,{value:"all",children:"All Brands"}),St.map(s=>e.jsx(g,{value:s,children:s},s))]})]}),e.jsxs(P,{value:le.status,onValueChange:s=>rs(a=>({...a,status:s})),children:[e.jsx(B,{className:"w-36 h-8 text-xs",children:e.jsx(F,{placeholder:"All Statuses"})}),e.jsxs(O,{children:[e.jsx(g,{value:"all",children:"All Statuses"}),Object.entries(js).map(([s,a])=>e.jsx(g,{value:s,children:a.label},s))]})]}),e.jsxs(P,{value:le.zone,onValueChange:s=>rs(a=>({...a,zone:s})),children:[e.jsx(B,{className:"w-44 h-8 text-xs",children:e.jsx(F,{placeholder:"All Zones"})}),e.jsxs(O,{children:[e.jsx(g,{value:"all",children:"All Zones"}),Q.map(s=>e.jsx(g,{value:s.zoneKey,children:s.name},s.zoneKey))]})]}),e.jsxs("div",{className:"relative w-56",children:[e.jsx(ft,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-slate-400"}),e.jsx(y,{placeholder:"Search banners by title or linkâ¦",value:le.search,onChange:s=>rs(a=>({...a,search:s.target.value})),className:"h-8 text-xs pl-8","data-testid":"input-mkt-banner-search"})]}),e.jsxs(r,{size:"sm",variant:Z?"default":"outline",className:"gap-1.5 h-8",onClick:()=>{u(s=>!s),Se()},title:Z?"Back to active banners":"Show archived banners",children:[e.jsx(bs,{className:"w-3.5 h-3.5"}),Z?"Viewing Archived":`Archived (${$.filter(s=>s.archived).length})`]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"file",accept:".json,application/json",ref:Ss,onChange:cl,className:"hidden"}),e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 h-8 text-slate-600",onClick:il,title:"Download all marketing banners as JSON",children:[e.jsx(Ls,{className:"w-3.5 h-3.5"})," Export"]}),e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 h-8 text-slate-600",onClick:()=>{var s;return(s=Ss.current)==null?void 0:s.click()},title:"Import banners from a JSON file",children:[e.jsx(Hs,{className:"w-3.5 h-3.5"})," Import"]}),e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 h-8 text-amber-700 border-amber-200 hover:bg-amber-50",onClick:rl,disabled:et,title:"Review and resolve duplicate banners",children:[et?e.jsx(K,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Ue,{className:"w-3.5 h-3.5"})," Manage Dupes"]}),e.jsxs(r,{size:"sm",className:"gap-1.5 h-8",onClick:()=>{pt("home"),Fe(s=>({...s,adType:"marketing"}))},children:[e.jsx(Ke,{className:"w-3.5 h-3.5"})," Add Marketing Banner"]})]})]}),$.some(s=>{var a,l,i,o;return((a=s.imageUrl)==null?void 0:a.startsWith("/uploads/"))||((l=s.imageUrl)==null?void 0:l.startsWith("/ads/"))||((i=s.videoUrl)==null?void 0:i.startsWith("/uploads/"))||((o=s.videoUrl)==null?void 0:o.startsWith("/ads/"))})&&e.jsxs("div",{className:"flex items-start gap-3 bg-amber-50 border border-amber-200 rounded-lg p-3 mb-3",children:[e.jsx("span",{className:"text-amber-500 text-lg shrink-0",children:"â ï¸"}),e.jsxs("div",{className:"text-sm text-amber-800",children:[e.jsx("p",{className:"font-semibold",children:"Some banners reference local image files that won't work in production."}),e.jsxs("p",{className:"text-xs mt-0.5",children:[e.jsx("strong",{children:"To fix automatically:"})," use ",e.jsx("strong",{children:"Export"})," on this dev site, then ",e.jsx("strong",{children:"Import"})," on production â the import will download and store the images on the production server automatically. No manual editing needed."]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 bg-blue-50 border border-blue-200 rounded-lg p-3 mb-3 text-sm text-blue-700",children:[e.jsx("span",{className:"text-blue-500 text-lg shrink-0",children:"ð¡"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"Syncing banners between dev and production"}),e.jsxs("p",{className:"text-xs mt-0.5",children:["Use ",e.jsx("strong",{children:"Export"})," (above) on your dev site to download all marketing banners as a JSON file, then use ",e.jsx("strong",{children:"Import"})," on the production site to restore them. Banner images must use permanent URLs (CDN or external links) â locally uploaded files won't carry over."]})]})]}),e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[760px] text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3 w-10",children:e.jsx(es,{checked:hs.length>0&&hs.every(s=>j.has(s.id)),onCheckedChange:s=>{J(a=>
3{const l=new Set(a);return hs.forEach(i=>{s===!0?l.add(i.id):l.delete(i.id)}),l})},"aria-label":"Select all visible banners"})}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600 w-20",children:"Preview"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Name"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Size"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Zone"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Active"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"Impressions"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"Clicks"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"CTR%"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"Actions"})]})}),e.jsxs("tbody",{className:"divide-y",children:[hs.map(s=>{const a=s.impressions??0,l=s.clicks??0,i=a>0?(l/a*100).toFixed(1):"â",o=Q.find(x=>x.zoneKey===s.zoneId);return e.jsxs("tr",{className:`hover:bg-slate-50 ${s.isActive?"":"opacity-50"}`,children:[e.jsx("td",{className:"p-3",children:e.jsx(es,{checked:j.has(s.id),onCheckedChange:x=>te(s.id,x===!0),"aria-label":`Select ${s.title}`})}),e.jsx("td",{className:"p-3",children:e.jsx("div",{className:"w-16 h-10 rounded overflow-hidden relative cursor-pointer ring-1 ring-slate-200",onClick:()=>Qe(s),title:"Click to preview",children:e.jsx(Ws,{banner:s})})}),e.jsxs("td",{className:"p-3",children:[e.jsx("div",{className:"font-medium text-slate-900 max-w-xs truncate",children:s.title}),s.subtitle&&e.jsx("div",{className:"text-xs text-slate-400 truncate max-w-xs",children:s.subtitle})]}),e.jsx("td",{className:"p-3",children:e.jsx(T,{variant:"secondary",className:"text-xs font-mono",children:s.adSize||"â"})}),e.jsx("td",{className:"p-3 text-xs text-slate-600",children:o?o.name:e.jsx("span",{className:"text-slate-400",children:"Unassigned"})}),e.jsx("td",{className:"p-3",children:e.jsx(be,{checked:s.isActive??!0,onCheckedChange:x=>nl.mutate({id:s.id,isActive:x}),className:"scale-75"})}),e.jsx("td",{className:"p-3 text-right text-slate-700 tabular-nums",children:a.toLocaleString()}),e.jsx("td",{className:"p-3 text-right text-slate-700 tabular-nums",children:l.toLocaleString()}),e.jsxs("td",{className:"p-3 text-right text-slate-700 tabular-nums",children:[i,a>0?"%":""]}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",title:"Save to Favorites",onClick:()=>Rt.mutate(s.id),children:e.jsx(Ye,{className:"w-3.5 h-3.5 text-amber-400"})}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",title:"Edit",onClick:()=>_e(s),children:e.jsx(De,{className:"w-3.5 h-3.5 text-slate-600"})}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",title:"Duplicate",onClick:()=>xt.mutate(s.id),children:e.jsx(_a,{className:"w-3.5 h-3.5 text-blue-500"})}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",title:s.archived?"Restore from archive":"Archive",onClick:()=>dt(s),children:s.archived?e.jsx(Nt,{className:"w-3.5 h-3.5 text-slate-600"}):e.jsx(bs,{className:"w-3.5 h-3.5 text-slate-600"})}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",title:"Delete",onClick:()=>{confirm("Delete this banner?")&&ll.mutate(s.id)},children:e.jsx(Ue,{className:"w-3.5 h-3.5 text-red-500"})})]})})]},s.id)}),hs.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"p-8 text-center text-slate-400",children:Z?"No archived marketing banners.":$.length===0?'No marketing banners yet. Click "Add Marketing Banner" to create one.':"No marketing banners match the current filters."})})]})]})})]}),e.jsxs(pe,{value:"google_ads",className:"mt-6 space-y-6",children:[e.jsxs(ge,{className:"border-blue-200 bg-blue-50/50",children:[e.jsx(Ks,{className:"pb-3",children:e.jsxs(Gs,{className:"flex items-center gap-2 text-base",children:[e.jsx(jt,{className:"w-5 h-5 text-blue-600"}),"Google AdSense Settings"]})}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(m,{className:"text-sm font-medium",children:"AdSense Publisher ID"}),e.jsx(y,{value:D.adsense_publisher_id,onChange:s=>Te(a=>({...a,adsense_publisher_id:s.target.value})),placeholder:"ca-pub-XXXXXXXXXXXXXXXXXX",className:"max-w-sm font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-slate-500",children:["Your publisher ID from Google AdSense. Get it at ",e.jsx("a",{href:"https://adsense.google.com",target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline",children:"adsense.google.com â"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:D.adsense_auto_ads_enabled==="true",onCheckedChange:s=>Te(a=>({...a,adsense_auto_ads_enabled:s?"true":"false"}))}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Enable Google Auto Ads"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Lets Google automatically place ads throughout all pages on the site."})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[D.adsense_publisher_id?e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-green-700 font-medium",children:[e.jsx(qs,{className:"w-4 h-4"})," Publisher ID configured"]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-amber-700 font-medium",children:[e.jsx(yl,{className:"w-4 h-4"})," No Publisher ID set â AdSense ads will not display"]}),e.jsxs(r,{size:"sm",onClick:()=>Oe.mutate({adsense_publisher_id:D.adsense_publisher_id,adsense_auto_ads_enabled:D.adsense_auto_ads_enabled}),disabled:Oe.isPending,children:[Oe.isPending?e.jsx(K,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ss,{className:"w-3.5 h-3.5"}),"Save AdSense Settings"]})]})]})]}),e.jsxs(ge,{children:[e.jsxs(Ks,{className:"pb-3",children:[e.jsxs(Gs,{className:"text-sm flex items-center gap-2",children:[e.jsx(wl,{className:"w-4 h-4 text-blue-500"}),"Per-Zone AdSense Slot IDs"]}),e.jsx("p",{className:"text-xs text-slate-500",children:"Assign a specific AdSense slot ID to each zone. When a zone has no HS banner, it will fall back to this AdSense unit."})]}),e.jsx(je,{children:e.jsxs("div",{className:"space-y-3",children:[Q.map(s=>{const a=Ka[s.id]??s.adsenseSlotId??"";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.name}),e.jsx("p",{className:"text-xs text-slate-500 font-mono",children:s.zoneKey})]}),e.jsx(y,{className:"w-48 font-mono text-xs h-8",placeholder:"AdSense Slot ID",value:a,onChange:l=>Ga(i=>({...i,[s.id]:l.target.value}))}),e.jsxs(r,{size:"sm",variant:"outline",className:"h-8 text-xs shrink-0",disabled:ot.isPending,onClick:()=>ot.mutate({id:s.id,adsenseSlotId:a}),children:[ot.isPending?e.jsx(K,{className:"w-3 h-3 animate-spin"}):e.jsx(ss,{className:"w-3 h-3"}),"Save"]})]},s.id)}),Q.length===0&&e.jsx("p",{className:"text-sm text-slate-400 text-center py-4",children:"No ad zones configured yet."})]})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-slate-800",children:"Ad Units"}),e.jsxs(r,{size:"sm",className:"gap-1.5",onClick:()=>As(!0),children:[e.jsx(Ke,{className:"w-3.5 h-3.5"})," Add Google Ad Unit"]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Ad Unit Name"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Size"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Zone"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Active"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"Actions"})]})}),e.jsxs("tbody",{className:"divide-y",children:[$.filter(s=>s.adType==="google_adsense").map(s=>{var a;return e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"p-3 font-medium",children:s.title}),e.jsx("td",{className:"p-3",children:e.jsx(T,{variant:"secondary",className:"font-mono text-xs",children:Vs[s.adSize||""]||s.adSize})}),e.jsx("td",{className:"p-3 text-sm text-slate-600",children:((a=Q.find(l=>l.zoneKey===s.zoneId))==null?void 0:a.name)||e.jsx("span",{className:"text-slate-400",children:"Unassigned"})}),e.jsx("td",{className:"p-3",children:e.jsx(be,{checked:s.adStatus==="approved"&&s.isActive,onCheckedChange:l=>us.mutate({id:s.id,data:{isActive:l,adStatus:l?"approved":"draft"}})})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>_e(s),children:e.jsx(De,{className:"w-3.5 h-3.5"})}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7 text-red-500",onClick:()=>Us.mutate(s.id),children:e.jsx(Ue,{className:"w-3.5 h-3.5"})})]})})]},s.id)}),$.filter(s=>s.adType==="google_adsense").length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-8 text-center text-slate-400",children:'No Google Ad Units yet. Click "+ Add Google Ad Unit" to create one.'})})]})]})})]}),e.jsxs(pe,{value:"vendor_ads",className:"mt-6 space-y-5",children:[e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:[{key:"all",label:"All"},{key:"pending_review",label:"Pending Review"},{key:"approved",label:"Approved"},{key:"rejected",label:"Rejected"}].map(({key:s,label:a})=>{const l=s==="all"?[...Re,...$.filter(i=>i.vendorId&&i.adStatus!=="pending_review")].length:s==="pending_review"?Re.filter(i=>i.adStatus==="pending_review").length:$.filter(i=>i.vendorId&&i.adStatus===s).length;return e.jsxs("button",{onClick:()=>qa(s),className:`px-3 py-1.5 rounded-full text-xs font-medium border transition-colors ${Ts===s?"bg-slate-800 text-white border-slate-800":"bg-white text-slate-600 border-slate-200 hover:border-slate-400"}`,children:[a," ",e.jsx("span",{className:`ml-1 px-1.5 py-0.5 rounded-full text-[10px] ${Ts===s?"bg-white/20 text-white":"bg-slate-100 text-slate-500"}`,children:l})]},s)})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(ge,{className:"border-yellow-200 bg-yellow-50",children:e.jsxs(je,{className:"p-4",children:[e.jsx("div",{className:"text-2xl font-bold text-yellow-800",children:Re.filter(s=>s.adStatus==="pending_review").length}),e.jsxs("div",{className:"text-sm text-yellow-700 mt-0.5 flex items-center gap-1",children:[e.jsx(Sl,{className:"w-3.5 h-3.5"})," Pending Review"]})]})}),e.jsx(ge,{className:"border-green-200 bg-green-50",children:e.jsxs(je,{className:"p-4",children:[e.jsx("div",{className:"text-2xl font-bold text-green-800",children:$.filter(s=>s.vendorId&&s.adStatus==="approved").length}),e.jsxs("div",{className:"text-sm text-green-700 mt-0.5 flex items-center gap-1",children:[e.jsx(qs,{className:"w-3.5 h-3.5"})," Approved"]})]})}),e.jsx(ge,{className:"border-red-200 bg-red-50",children:e.jsxs(je,{className:"p-4",children:[e.jsx("div",{className:"text-2xl font-bold text-red-800",children:$.filter(s=>s.vendorId&&s.adStatus==="rejected").length}),e.jsxs("div",{className:"text-sm text-red-700 mt-0.5 flex items-center gap-1",children:[e.jsx(bt,{className:"w-3.5 h-3.5"})," Rejected"]})]})})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-3 font-medium text-slate-600 w-20",children:"Preview"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Ad Name"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Vendor"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Size"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Submitted"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Status"}),e.jsx("th",{className:"text-left p-3 font-medium text-slate-600",children:"Assigned Zone"}),e.jsx("th",{className:"text-right p-3 font-medium text-slate-600",children:"Actions"})]})}),e.jsxs("tbody",{className:"divide-y",children:[[...Re,...$.filter(s=>s.vendorId&&s.adStatus!=="pending_review")].filter(s=>Ts==="all"||s.adStatus===Ts).map(s=>{const a=js[s.adStatus||"draft"]||js.draft,l=Q.find(o=>o.zoneKey===s.zoneId),i=s;return e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"p-3",children:e.jsx("div",{className:"w-16 h-10 bg-slate-100 rounded overflow-hidden cursor-pointer",onClick:()=>Qe(s),children:s.imageUrl&&e.jsx("img",{src:s.imageUrl,alt:"",className:"w-full h-full object-cover"})})}),e.jsx("td",{className:"p-3 font-medium",children:s.title}),e.jsx("td",{className:"p-3 text-xs text-slate-600",children:[i.first_name,i.last_name].filter(
3Boolean).join(" ")||i.username||i.email||`User #${s.vendorId}`}),e.jsx("td",{className:"p-3",children:e.jsx(T,{variant:"secondary",className:"font-mono text-xs",children:s.adSize})}),e.jsx("td",{className:"p-3 text-xs text-slate-600",children:s.submittedByVendorAt?new Date(s.submittedByVendorAt).toLocaleDateString():"â"}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${a.color}`,children:a.label})}),e.jsx("td",{className:"p-3 text-xs text-slate-600",children:(l==null?void 0:l.name)||e.jsx("span",{className:"text-slate-400",children:"Unassigned"})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[s.adStatus==="pending_review"&&e.jsxs(e.Fragment,{children:[e.jsxs(r,{size:"sm",variant:"outline",className:"h-7 text-xs text-green-700 border-green-300 hover:bg-green-50",onClick:()=>os({banner:s,open:!0}),children:[e.jsx(qs,{className:"w-3 h-3 mr-1"})," Approve"]}),e.jsxs(r,{size:"sm",variant:"outline",className:"h-7 text-xs text-red-700 border-red-300 hover:bg-red-50",onClick:()=>cs({banner:s,open:!0,reason:""}),children:[e.jsx(bt,{className:"w-3 h-3 mr-1"})," Reject"]})]}),s.adStatus==="approved"&&e.jsxs(r,{size:"sm",variant:"ghost",className:"h-7 text-xs text-slate-500",onClick:()=>zs.mutate({id:s.id}),children:[e.jsx(Ua,{className:"w-3 h-3 mr-1"})," Revoke"]}),s.adStatus==="rejected"&&e.jsx(r,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>os({banner:s,open:!0}),children:"Re-review"}),e.jsx(r,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>_e(s),children:e.jsx(De,{className:"w-3.5 h-3.5"})})]})})]},s.id)}),Re.length===0&&$.filter(s=>s.vendorId).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"p-8 text-center text-slate-400",children:"No vendor ads submitted yet."})})]})]})})]}),e.jsxs(pe,{value:"placements",className:"mt-6",children:[e.jsx(ne,{open:!!U,onOpenChange:s=>!s&&Mt(null),children:e.jsxs(ie,{className:"max-w-3xl p-4",children:[e.jsx(re,{children:e.jsx(oe,{className:"text-sm font-semibold truncate",children:U==null?void 0:U.title})}),U&&e.jsx("div",{className:"w-full rounded-lg overflow-hidden bg-slate-900 flex items-center justify-center min-h-[200px]",children:U.adType==="starlink_promo"?e.jsxs("div",{className:"w-full text-center text-white p-8 bg-gradient-to-r from-blue-900 to-slate-900",children:[e.jsx("div",{className:"text-2xl font-black mb-2",children:"ð Starlink Promo"}),e.jsx("div",{className:"text-slate-300",children:U.subtitle||"Satellite Internet for Mariners"}),e.jsxs("div",{className:"mt-3 text-xs text-blue-400",children:[U.adSize," · ",U.scope]})]}):U.imageUrl?e.jsx("img",{src:U.imageUrl,alt:U.title,className:"w-full h-auto max-h-[400px] object-contain"}):U.videoUrl?e.jsx("video",{src:U.videoUrl,controls:!0,className:"w-full max-h-[400px]"}):e.jsx("div",{className:"text-slate-400 text-sm p-8",children:"No preview available for this banner type"})}),U&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[e.jsx(T,{variant:"outline",className:"text-xs font-mono",children:U.adSize||"full-width"}),(Jt=U.zoneIds)==null?void 0:Jt.map(s=>{var a;return e.jsxs(T,{className:"text-xs bg-blue-100 text-blue-700 border-blue-200",children:[e.jsx(Rs,{className:"w-3 h-3 mr-1"}),((a=Q.find(l=>l.zoneKey===s))==null?void 0:a.name)||s]},s)}),!((Yt=U.zoneIds)!=null&&Yt.length)&&U.zoneId&&e.jsxs(T,{className:"text-xs bg-blue-100 text-blue-700 border-blue-200",children:[e.jsx(Rs,{className:"w-3 h-3 mr-1"}),((Dt=Q.find(s=>s.zoneKey===U.zoneId))==null?void 0:Dt.name)||U.zoneId]}),U.linkUrl&&e.jsxs("a",{href:U.linkUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-600 hover:underline flex items-center gap-1",children:[e.jsx(va,{className:"w-3 h-3"}),U.linkUrl]})]})]})}),e.jsxs("div",{className:"grid grid-cols-5 gap-6",children:[e.jsxs("div",{className:"col-span-3 space-y-4",children:[e.jsx("h3",{className:"font-semibold text-slate-800",children:"Placement Zones"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Toggle zones on/off without losing assignments. Inactive zones show nothing on the site."}),Q.map(s=>{const a=$.filter(i=>(i.zoneIds??(i.zoneId?[i.zoneId]:[])).includes(s.zoneKey)&&i.adStatus==="approved");let l=["all"];try{l=JSON.parse(s.allowedSizes||'["all"]')}catch{}return e.jsx(ge,{className:`border transition-opacity ${s.isActive?"":"opacity-60"}`,children:e.jsxs(je,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-slate-900",children:s.name}),e.jsx("p",{className:"text-xs text-slate-500 font-mono",children:s.zoneKey}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:s.description})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("button",{onClick:()=>Lt.mutate(s.id),disabled:Lt.isPending,title:s.isActive?"Disable zone":"Enable zone",className:`flex items-center gap-1.5 text-xs font-semibold px-2.5 py-1 rounded-full border transition-colors ${s.isActive?"bg-green-50 border-green-200 text-green-700 hover:bg-red-50 hover:border-red-200 hover:text-red-600":"bg-slate-100 border-slate-200 text-slate-500 hover:bg-green-50 hover:border-green-200 hover:text-green-700"}`,children:[e.jsx(kl,{className:"w-3 h-3"}),s.isActive?"Active":"Off"]})})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:l.includes("all")?e.jsx(T,{variant:"outline",className:"text-xs",children:"All sizes"}):l.map(i=>e.jsx(T,{variant:"outline",className:"text-xs font-mono",children:i},i))}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-slate-500 mb-1.5",children:[a.length," of ",s.maxAdsInRotation," ads in rotation"]}),a.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(i=>{const o=i.zoneIds??(i.zoneId?[i.zoneId]:[]);return e.jsxs("div",{className:"flex items-center gap-1 bg-white border rounded-full px-2 py-0.5 text-xs",children:[i.imageUrl&&e.jsx("img",{src:i.imageUrl,className:"w-4 h-4 object-cover rounded-full flex-shrink-0",alt:""}),e.jsx("span",{className:"max-w-[120px] truncate",children:i.title}),e.jsx("button",{onClick:()=>ct.mutate({bannerId:i.id,zoneIds:o.filter(x=>x!==s.zoneKey)}),className:"text-slate-400 hover:text-red-500 ml-0.5",title:"Remove from this zone",children:e.jsx(Qs,{className:"w-3 h-3"})})]},i.id)})}):e.jsx("p",{className:"text-xs text-slate-400",children:"No ads assigned â use the panel on the right to assign one."})]})]})},s.id)})]}),e.jsx("div",{className:"col-span-2",children:e.jsxs("div",{className:"sticky top-4",children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-1",children:"Available Ads"}),e.jsx("p",{className:"text-xs text-slate-500 mb-3",children:"Click the zones button to assign a banner to one or more zones. Click the thumbnail to preview."}),e.jsxs("div",{className:"border rounded-lg overflow-y-auto max-h-[680px] divide-y",children:[["marketing","brand_specific","starlink_promo","google_adsense"].map(s=>{const a=$.filter(i=>i.adType===s&&i.adStatus==="approved");if(!a.length)return null;const l=s==="google_adsense"?"Google Ad Units":s==="starlink_promo"?"Starlink":"Marketing Banners";return e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-2 bg-slate-50 text-xs font-medium text-slate-600 uppercase tracking-wide sticky top-0 z-10",children:l}),a.map(i=>{const o=i.zoneIds??(i.zoneId?[i.zoneId]:[]);return e.jsxs("div",{className:"flex items-center gap-2 p-2.5 hover:bg-slate-50 group",children:[e.jsxs("button",{onClick:()=>Mt(i),className:"w-14 h-9 bg-slate-100 rounded overflow-hidden flex-shrink-0 relative group/thumb border hover:border-blue-300 transition-colors",title:"Preview banner",children:[e.jsx(Ws,{banner:i}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover/thumb:opacity-100 transition-opacity flex items-center justify-center",children:e.jsx(Cl,{className:"w-3.5 h-3.5 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium truncate",children:i.title}),e.jsx("div",{className:"text-xs text-slate-400",children:i.adSize||"full-width"}),o.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-0.5 mt-0.5",children:[o.slice(0,2).map(x=>{var w,L;return e.jsx("span",{className:"text-[10px] bg-blue-100 text-blue-600 px-1.5 py-0 rounded-full leading-5",children:((L=(w=Q.find(A=>A.zoneKey===x))==null?void 0:w.name)==null?void 0:L.split(" ").slice(0,2).join(" "))||x},x)}),o.length>2&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",o.length-2," more"]})]})]}),e.jsxs($l,{children:[e.jsx(Ll,{asChild:!0,children:e.jsxs(r,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1 shrink-0",children:[e.jsx(Rs,{className:"w-3 h-3"}),o.length>0?`${o.length} zone${o.length>
31?"s":""}`:"Assign"]})}),e.jsxs(Ml,{className:"w-56 p-2",align:"end",children:[e.jsx("div",{className:"text-xs font-semibold text-slate-700 mb-2 px-1",children:"Assign to zones"}),e.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:Q.map(x=>{const w=o.includes(x.zoneKey);return e.jsxs("label",{className:"flex items-center gap-2 px-1 py-1 rounded hover:bg-slate-50 cursor-pointer",children:[e.jsx(es,{checked:w,onCheckedChange:L=>{const A=L?[...o,x.zoneKey]:o.filter(M=>M!==x.zoneKey);ct.mutate({bannerId:i.id,zoneIds:A})}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium leading-tight truncate",children:x.name}),!x.isActive&&e.jsx("div",{className:"text-[10px] text-slate-400",children:"inactive"})]})]},x.zoneKey)})}),o.length>0&&e.jsx("button",{onClick:()=>ct.mutate({bannerId:i.id,zoneIds:[]}),className:"w-full mt-2 text-xs text-red-500 hover:text-red-700 px-1 py-1 text-left",children:"Remove from all zones"})]})]})]},i.id)})]},s)}),$.filter(s=>s.adStatus==="approved"&&s.adType&&["marketing","brand_specific","google_adsense","starlink_promo"].includes(s.adType)).length===0&&e.jsx("div",{className:"p-6 text-center text-sm text-slate-400",children:"No approved ads yet. Approve ads in the Vendor Ads tab or create Marketing Banners."})]})]})})]})]}),e.jsxs(pe,{value:"analytics",className:"mt-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex gap-2",children:[["7","Last 7 days"],["30","Last 30 days"],["90","Last 90 days"]].map(([s,a])=>e.jsx(r,{size:"sm",variant:lt===s?"default":"outline",className:"h-8 text-xs",onClick:()=>Wa(s),children:a},s))}),e.jsx(r,{size:"sm",variant:"outline",className:"gap-1.5 h-8",asChild:!0,children:e.jsxs("a",{href:"/api/admin/ad-analytics/export",download:!0,children:[e.jsx(Ls,{className:"w-3.5 h-3.5"})," Export CSV"]})})]}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:[{label:"Total Impressions",value:Number(((ea=S==null?void 0:S.summary)==null?void 0:ea.total_impressions)||0).toLocaleString(),icon:yt,color:"text-blue-600"},{label:"Total Clicks",value:Number(((sa=S==null?void 0:S.summary)==null?void 0:sa.total_clicks)||0).toLocaleString(),icon:Tl,color:"text-green-600"},{label:"Average CTR",value:((ta=S==null?void 0:S.summary)==null?void 0:ta.total_impressions)>0?`${(S.summary.total_clicks/S.summary.total_impressions*100).toFixed(1)}%`:"â",icon:ga,color:"text-purple-600"},{label:"Active Ads",value:((aa=S==null?void 0:S.summary)==null?void 0:aa.active_ads)||"â",icon:Ms,color:"text-orange-600"}].map(({label:s,value:a,icon:l,color:i})=>e.jsx(ge,{children:e.jsxs(je,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-sm text-slate-500",children:s}),e.jsx(l,{className:`w-4 h-4 ${i}`})]}),e.jsx("div",{className:"text-2xl font-bold text-slate-900",children:a})]})},s))}),e.jsxs(ge,{children:[e.jsx(Ks,{className:"pb-3",children:e.jsx(Gs,{className:"text-sm font-semibold",children:"Top 10 Banners by Impressions"})}),e.jsxs(je,{children:[((S==null?void 0:S.topBanners)||[]).slice(0,10).map((s,a)=>{var o;const l=((o=S.topBanners[0])==null?void 0:o.impressions)||1,i=Math.round(s.impressions/l*100);return e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"text-xs text-slate-400 w-5 text-right",children:a+1}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsx("span",{className:"text-xs font-medium truncate max-w-[200px]",children:s.title}),e.jsx("span",{className:"text-xs text-slate-500",children:Number(s.impressions||0).toLocaleString()})]}),e.jsx("div",{className:"h-1.5 bg-slate-100 rounded-full",children:e.jsx("div",{className:"h-full bg-blue-500 rounded-full transition-all",style:{width:`${i}%`}})})]})]},s.id)}),!((la=S==null?void 0:S.topBanners)!=null&&la.length)&&e.jsx("p",{className:"text-sm text-slate-400 text-center py-4",children:"No impression data yet."})]})]}),e.jsxs(ge,{children:[e.jsx(Ks,{className:"pb-3",children:e.jsx(Gs,{className:"text-sm font-semibold",children:"Performance Table"})}),e.jsx(je,{className:"p-0",children:e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"border-b bg-slate-50",children:e.jsxs("tr",{children:[[["rank","#"],["title","Banner Name"],["ad_type","Type"],["zone_id","Zone"],["impressions","Impressions"],["clicks","Clicks"],["ctr","CTR%"],["ad_status","Status"]].map(([s,a])=>e.jsxs("th",{className:"text-left p-3 font-medium text-slate-600 cursor-pointer hover:text-slate-900 select-none",onClick:()=>{Ha(s),Va(l=>l==="asc"?"desc":"asc")},children:[a,ds===s&&e.jsx("span",{className:"ml-1",children:Ot==="asc"?"â
3":"â"})]},s)),e.jsx("th",{className:"p-3"})]})}),e.jsx("tbody",{className:"divide-y",children:(()=>{const s=[...(S==null?void 0:S.topBanners)||[]];return s.sort((l,i)=>{const o=ds==="ctr"?l.impressions>0?l.clicks/l.impressions:0:l[ds]??0,x=ds==="ctr"?i.impressions>0?i.clicks/i.impressions:0:i[ds]??0;return Ot==="asc"?o>x?1:-1:o<x?1:-1}),s.slice((Xe-1)*25,Xe*25).map((l,i)=>{const o=Number(l.impressions||0),x=Number(l.clicks||0),w=o>0?`${(x/o*100).toFixed(1)}%`:"â",L=js[l.ad_status]||js.approved,A=Q.find(M=>M.zoneKey===l.zone_id);return e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"p-3 text-slate-400 text-xs",children:(Xe-1)*25+i+1}),e.jsx("td",{className:"p-3 font-medium max-w-xs truncate",children:l.title}),e.jsx("td",{className:"p-3",children:e.jsx(T,{variant:"secondary",className:"text-xs",children:l.ad_type})}),e.jsx("td",{className:"p-3 text-xs text-slate-500",children:(A==null?void 0:A.name)||"â"}),e.jsx("td",{className:"p-3 text-right",children:o.toLocaleString()}),e.jsx("td",{className:"p-3 text-right",children:x.toLocaleString()}),e.jsx("td",{className:"p-3 text-right",children:w}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${L.color}`,children:L.label})}),e.jsx("td",{className:"p-3",children:e.jsx(r,{size:"sm",variant:"ghost",className:"h-6 text-xs",onClick:()=>{const M=$.find(Je=>Je.id===l.id);M&&_e(M)},children:"Edit"})})]},l.id)})})()})]}),(((na=S==null?void 0:S.topBanners)==null?void 0:na.length)||0)>25&&e.jsxs("div",{className:"flex justify-center gap-2 p-3 border-t",children:[e.jsx(r,{size:"sm",variant:"outline",className:"h-7",disabled:Xe===1,onClick:()=>Et(s=>s-1),children:"Prev"}),e.jsxs("span",{className:"text-xs text-slate-500 self-center",children:["Page ",Xe]}),e.jsx(r,{size:"sm",variant:"outline",className:"h-7",disabled:Xe*25>=(((ia=S==null?void 0:S.topBanners)==null?void 0:ia.length)||0),onClick:()=>Et(s=>s+1),children:"Next"})]})]})})]})]}),e.jsxs(pe,{value:"favorites",className:"mt-6",children:[e.jsxs("div",{className:"mb-4 p-3 bg-amber-50 border border-amber-200 rounded-lg flex items-start gap-2.5",children:[e.jsx(Ye,{className:"w-4 h-4 text-amber-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-amber-900 font-medium",children:"Your Banner Vault"}),e.jsx("p",{className:"text-xs text-amber-700 mt-0.5",children:"Click the â star on any banner (in any tab) to save a protected copy here. Favorites are never overwritten or published â they just sit safely in this vault until you choose to deploy them. Deploying creates a fresh live copy while leaving this favorite intact."})]})]}),Is.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-slate-400 border-2 border-dashed border-amber-200 rounded-xl bg-amber-50/30",children:[e.jsx(Ye,{className:"w-12 h-12 text-amber-200 mb-4"}),e.jsx("p",{className:"text-lg font-medium text-slate-500",children:"No favorites yet"}),e.jsx("p",{className:"text-sm text-slate-400 mt-1 max-w-xs text-center",children:"Click the â star button on any banner in any tab to save a protected copy here."})]}):e.jsx("div",{className:"space-y-3",children:Is.map(s=>e.jsx("div",{className:"border border-amber-200 rounded-xl bg-white overflow-hidden shadow-sm hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex gap-0 items-stretch",children:[e.jsxs("div",{className:"w-40 shrink-0 relative cursor-pointer",onClick:()=>Qe(s),title:"Click to preview",children:[e.jsx(Ws,{banner:s,className:"w-full h-full min-h-[90px]",size:"lg"}),e.jsx("div",{className:"absolute top-1.5 right-1.5 bg-amber-400 rounded-full p-0.5",children:e.jsx(Ye,{className:"w-3 h-3 text-white fill-white"})})]}),e.jsx("div",{className:"flex-1 p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-slate-900 truncate",children:s.title}),s.subtitle&&e.jsx("p",{className:"text-xs text-slate-500 mt-0.5 truncate",children:s.subtitle}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 flex-wrap",children:[e.jsx(T,{variant:"secondary",className:"text-xs capitalize",children:s.mediaType||"image"}),s.scope&&e.jsx(T,{variant:"outline",className:"text-xs capitalize",children:s.scope}),s.adSize&&e.jsx(T,{variant:"outline",className:"text-xs font-mono",children:s.adSize}),e.jsxs("span",{className:"text-xs text-slate-400",children:["Saved ",s.createdAt?new Date(s.createdAt).toLocaleDateString():""]})]}),s.overlayText&&e.jsxs("p",{className:"text-xs text-slate-500 mt-1.5 italic line-clamp-1",children:['"',s.overlayText,'"']})]}),e.jsxs("div",{className:"flex flex-col gap-2 shrink-0",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(r,{size:"sm",className:"gap-1.5 bg-blue-600 hover:bg-blue-700 text-white text-xs",disabled:Ps.isPending,onClick:()=>Ps.mutate({id:s.id,deployAs:"hero"}),title:"Create a live copy on the Home Page banners",children:[e.jsx(vt,{className:"w-3.5 h-3.5"}),"Deploy to Home"]}),e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 border-indigo-300 text-indigo-700 hover:bg-indigo-50 text-xs",disabled:Ps.isPending,onClick:()=>Ps.mutate({id:s.id,deployAs:"marketing"}),title:"Create a live copy in Marketing Banners",children:[e.jsx(Ms,{className:"w-3.5 h-3.5"}),"Deploy to Marketing"]})]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(r,{size:"sm",variant:"outline",className:"gap-1.5 text-xs flex-1",onClick:()=>_e(s),title:"Edit this favorite in-place",children:[e.jsx(De,{className:"w-3.5 h-3.5"}),"Edit"]}),e.jsxs(r,{size:"sm",variant:"ghost",className:"gap-1.5 text-red-500 hover:text-red-600 hover:bg-red-50 text-xs",onClick:()=>{confirm("Remove this from favorites? The original banner is not affected.")&&tl.mutate(s.id)},title:"Remove from favorites",children:[e.jsx(Ue,{className:"w-3.5 h-3.5"}),"Remove"]})]})]})]})})]})},s.id))})]}),e.jsx(pe,{value:"tool_pages",className:"mt-6 space-y-6",children:e.jsx(Dl,{toolBanners:mt,onRefresh:sl,onOpenStudio:s=>ht(s),onToggle:s=>us.mutate({id:s.id,data:{isActive:!s.isActive}}),onDelete:s=>Us.mutate(s)})})]}),e.jsx(ba,{open:!!Ee,onOpenChange:s=>{s||ht(null)},children:e.jsxs(fa,{side:"right",className:"w-full sm:max-w-2xl p-0 overflow-y-auto",children:[e.jsx(Na,{className:"px-6 pt-6 pb-3 border-b",children:e.jsxs(ya,{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"w-5 h-5 text-cyan-500"}),"HPG Studio â Tool Page Banner"]})}
3),Ee&&e.jsx(Sa,{productContext:{title:`Harbor OS Tool Page: ${Ee.replace(/-/g," ")}`,description:(ra=Xs.find(s=>s.slug===Ee))==null?void 0:ra.tagline},onBannerSave:async s=>{const a=`tool_hero_${Ee}`,l=Xs.find(o=>o.slug===Ee),i={...qe,title:s.title||`${Ee} hero banner`,subtitle:s.subtitle||(l==null?void 0:l.tagline)||"",imageUrl:s.imageUrl||"",mediaType:s.mediaType||"gradient",videoUrl:s.videoUrl||(l?`linear-gradient(135deg, ${l.gradientFrom} 0%, ${l.gradientTo} 100%)`:"linear-gradient(135deg, #0f2027 0%, #203a43 100%)"),linkUrl:s.linkUrl||(l==null?void 0:l.primaryPath)||"",adType:"tool_hero",zoneId:a,scope:"tool_hero",adStatus:"approved",isActive:!0};await Ze.mutateAsync(i),p.invalidateQueries({queryKey:["/api/admin/tool-banners"]}),ht(null),t({title:"Tool banner created!",description:`Banner created for ${(l==null?void 0:l.name)||Ee} tool page.`})}})]})}),e.jsx(ne,{open:we,onOpenChange:s=>!s&&Fs(),children:e.jsxs(ie,{className:"sm:max-w-4xl max-h-[90vh] flex flex-col overflow-hidden p-0",children:[e.jsx(re,{className:"px-6 pt-6 pb-2 shrink-0",children:e.jsx(oe,{children:z?"Edit Banner":`Create New ${v==="store"?"Store":"Home Page"} Banner`})}),e.jsx(Yl,{formData:is,setFormData:Fe,onSubmit:gl,onCancel:Fs,isSubmitting:Ze.isPending||us.isPending,isEditing:!!z,isUploading:ke,fileInputRef:$a,handleFileUpload:ul,onUploadFile:Kt,adZonesList:Q})]})}),e.jsx(ql,{open:Js,onOpenChange:fs,isAdmin:!0,scope:d==="store"?"store":d==="service_request"?"service_request":"home",onBannerSave:s=>{Ze.mutate({...qe,title:s.title,imageUrl:s.imageUrl,linkUrl:s.linkUrl,mediaType:s.mediaType,isActive:!0,sortOrder:(d==="store"?ze:Ae).length})}}),e.jsx(Gl,{open:Ys,onOpenChange:Ns,existingBanners:[...Ae,...ze].map(s=>({id:s.id,title:s.title,subtitle:s.subtitle||null,linkUrl:s.linkUrl||null,mediaType:s.mediaType||"image"})),onSave:s=>{Ze.mutate({...qe,title:s.title,subtitle:s.subtitle,videoUrl:s.videoUrl,linkUrl:s.linkUrl,showCta:s.showCta,ctaText:s.ctaText,ctaUrl:s.ctaUrl,mediaType:"gradient",isActive:!0,sortOrder:(d==="store"?ze:Ae).length})}}),e.jsx(ne,{open:n,onOpenChange:s=>{s||(q(!1),Pe([]),ws(null))},children:e.jsxs(ie,{className:"sm:max-w-lg max-h-[80vh] flex flex-col",children:[e.jsx(re,{children:e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(Hs,{className:"w-5 h-5 text-blue-600"}),"Import Marketing Banners"]})}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-4",children:ae?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`p-4 rounded-lg border text-sm ${ae.errors.length===0?"bg-green-50 border-green-200 text-green-800":"bg-amber-50 border-amber-200 text-amber-800"}`,children:[e.jsx("div",{className:"font-semibold mb-1",children:"Import complete"}),ae.created>0&&e.jsxs("div",{children:["â
",ae.created," banner",ae.created!==1?"s":""," created"]}),ae.updated>0&&e.jsxs("div",{children:["ð ",ae.updated," banner",ae.updated!==1?"s":""," updated (existing, same title)"]}),ae.skipped>0&&e.jsxs("div",{children:["â ",ae.skipped," skipped (no title)"]}),((oa=ae.warnings)==null?void 0:oa.length)>0&&e.jsxs("div",{className:"mt-2 p-2 bg-amber-50 border border-amber-200 rounded text-amber-700",children:[e.jsx("div",{className:"font-medium text-xs mb-1",children:"â ï¸ Local URL warnings â these banners will have no image until you update the URL:"}),e.jsx("ul",{className:"text-xs space-y-0.5 max-h-28 overflow-y-auto",children:ae.warnings.map((s,a)=>e.jsx("li",{className:"truncate",children:s},a))})]}),ae.errors.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"font-medium text-red-700",children:"Errors:"}),e.jsx("ul",{className:"text-xs mt-1 space-y-0.5",children:ae.errors.map((s,a)=>e.jsx("li",{className:"text-red-600",children:s},a))})]})]}),e.jsx(r,{className:"w-full",onClick:()=>{q(!1),Pe([]),ws(null)},children:"Done"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 bg-blue-50 border border-blue-200 rounded-lg text-sm text-blue-800",children:["Found ",e.jsxs("strong",{children:[V.length," banner",V.length!==1?"s":""]})," ready to import. Existing banners with the same title will be updated, not duplicated."]}),V.some(s=>{var a,l;return((a=s.imageUrl)==null?void 0:a.startsWith("/"))||((l=s.videoUrl)==null?void 0:l.startsWith("/"))})&&e.jsxs("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded-lg text-xs text-amber-800",children:["â ï¸ ",e.jsx("strong",{children:"Local file URLs detected."})," Some banners reference local paths that won't load on production. After import, edit those banners to use CDN or external URLs."]}),e.jsx("div",{className:"max-h-48 overflow-y-auto border rounded-lg divide-y text-sm",children:V.map((s,a)=>{var i,o,x,w;const l=((i=s.imageUrl)==null?void 0:i.startsWith("/"))&&!((o=s.imageUrl)!=null&&o.startsWith("//"))||((x=s.videoUrl)==null?void 0:x.startsWith("/"))&&!((w=s.videoUrl)!=null&&w.startsWith("//"));return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 ${l?"bg-amber-50":""}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:s.title}),e.jsxs("div",{className:"text-xs text-slate-400 truncate",children:[s.zoneId||"No zone"," · ",s.mediaType||"image"," · ",s.adSize||"â",l?" · â ï¸ local URL":""]})]}),e.jsx(T,{variant:"outline",className:"text-[10px] shrink-0",children:s.adType||"marketing"})]},a)})}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-amber-50 border border-amber-200 rounded-lg",children:[e.jsx("input",{type:"checkbox",id:"import-deactivate",checked:We,onChange:s=>Ba(s.target.checked),className:"w-4 h-4 rounded"}),e.jsxs("label",{htmlFor:"import-deactivate",className:"text-sm text-amber-800 cursor-pointer",children:["Import as ",e.jsx("strong",{children:"inactive"})," â review before going live"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(r,{className:"flex-1 gap-2",onClick:dl,disabled:Tt,children:Tt?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 animate-spin"})," Importingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Hs,{className:"w-4 h-4"})," Import ",V.length," Banner",V.length!==1?"s":""]})}),e.jsx(r,{variant:"outline",onClick:()=>{q(!1),Pe([])},children:"Cancel"})]})]})})]})}),e.jsx(ne,{open:ys,onOpenChange:s=>{Le(s),s||Ut(null)},children:e.jsxs(ie,{className:"max-w-5xl max-h-[90vh] overflow-y-auto",children:[e.jsx(re,{children:e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(xa,{
3className:"w-5 h-5 text-blue-600"}),st?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4 text-purple-600"}),"AI Redo â HPG Studio"]}):"HPG Studio"]})}),st&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-purple-700 bg-purple-50 border border-purple-200 rounded-lg px-3 py-2 -mt-2",children:[e.jsx(Ie,{className:"w-3.5 h-3.5 shrink-0"}),"Banner pre-loaded from your list. Adjust the description or redesign instructions below, then generate a new version."]}),e.jsx(Sa,{adminMode:!0,initialBannerId:st,initialBannerType:"hero",onBannerSave:s=>new Promise((a,l)=>{ps.mutate({title:s.title,subtitle:s.subtitle||"",imageUrl:s.imageUrl||"",videoUrl:s.videoUrl||"",mediaType:s.mediaType,linkUrl:s.linkUrl||"",zoneId:s.zoneId||"leaderboard_top",adType:s.adType||"marketing",adSize:s.adSize||"970x250",isActive:!0},{onSuccess:()=>{a(void 0),Le(!1)},onError:i=>l(i)})})})]})}),e.jsx(ne,{open:Ea,onOpenChange:ks,children:e.jsxs(ie,{className:"max-w-3xl max-h-[80vh] flex flex-col",children:[e.jsx(re,{children:e.jsx(oe,{children:"Import Banners from WordPress"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[Bs.isPending&&e.jsxs("div",{className:"flex items-center justify-center py-16 gap-3 text-slate-500",children:[e.jsx(K,{className:"w-6 h-6 animate-spin"}),"Fetching WordPress banners..."]}),!Bs.isPending&&He.length===0&&Bs.isSuccess&&e.jsxs("div",{className:"text-center py-12 text-slate-500",children:[e.jsx(as,{className:"w-10 h-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"font-medium",children:"No banner slides found in WordPress"}),e.jsx("p",{className:"text-sm mt-1",children:"No slide/banner post types with images were found on harborshoppers.com."})]}),He.length>0&&e.jsxs("div",{className:"space-y-2 p-1",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("p",{className:"text-sm text-slate-600",children:[Be.size," of ",He.filter(s=>s.imageUrl).length," selected (only banners with images can be imported)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>Ve(new Set(He.filter(s=>s.imageUrl).map(s=>s.wpId))),children:"Select All"}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>Ve(new Set),children:"Deselect All"})]})]}),He.map(s=>e.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${Be.has(s.wpId)?"border-blue-400 bg-blue-50":"border-slate-200 bg-white hover:bg-slate-50"} ${s.imageUrl?"":"opacity-50 cursor-not-allowed"}`,onClick:()=>s.imageUrl&&ml(s.wpId),children:[e.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center shrink-0 ${Be.has(s.wpId)?"bg-blue-500 border-blue-500":"border-slate-300"}`,children:Be.has(s.wpId)&&e.jsx(Al,{className:"w-3 h-3 text-white"})}),s.imageUrl?e.jsx("img",{src:s.imageUrl,alt:s.title,className:"w-20 h-12 object-cover rounded shrink-0"}):e.jsx("div",{className:"w-20 h-12 bg-slate-200 rounded shrink-0 flex items-center justify-center",children:e.jsx(as,{className:"w-5 h-5 text-slate-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-slate-900 truncate",children:s.title}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s.wpType," · ",s.status," · ",new Date(s.date).toLocaleDateString()]}),!s.imageUrl&&e.jsx("p",{className:"text-xs text-amber-600",children:"No featured image â cannot import"})]})]},s.wpId))]})]}),e.jsxs($e,{className:"pt-3 border-t",children:[e.jsx(r,{variant:"outline",onClick:()=>ks(!1),children:"Cancel"}),e.jsx(r,{onClick:hl,disabled:Be.size===0||ut.isPending,className:"gap-2",children:ut.isPending?e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"w-4 h-4 animate-spin"}),"Importing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{className:"w-4 h-4"}),"Import ",Be.size," Banner",Be.size!==1?"s":""]})})]})]})})]}),e.jsx(ne,{open:!!f,onOpenChange:s=>!s&&Qe(null),children:e.jsxs(ie,{className:"max-w-4xl p-0 overflow-hidden",children:[e.jsx(re,{className:"px-4 py-3 border-b",children:e.jsx(oe,{className:"text-base",children:f==null?void 0:f.title})}),f&&e.jsxs("div",{className:"relative bg-slate-900",style:{height:480},children:[f.mediaType==="gradient"?e.jsx(Zs,{banner:{title:f.title,subtitle:f.subtitle,videoUrl:f.videoUrl,linkUrl:f.linkUrl,ctaText:f.ctaText,showCta:f.showCta},height:480}):f.mediaType==="youtube"&&f.youtubeUrl?e.jsx("iframe",{src:Ct(f.youtubeUrl),className:"w-full h-full",allowFullScreen:!0,allow:"autoplay; encrypted-media"}):f.mediaType==="video"&&f.videoUrl?e.jsx("video",{src:f.videoUrl,poster:f.imageUrl||void 0,className:"w-full h-full object-cover",autoPlay:!0,muted:!0,loop:!0,playsInl
3ine:!0,controls:!0}):e.jsx(Ws,{banner:f,size:"lg"}),f.showTitle&&f.imageUrl&&!Kl(f.imageUrl)&&f.mediaType!=="gradient"&&(()=>{const s=f.overlayPosition||"bottom-left",a=f.overlayStyle||"gradient",l=a==="gradient"?s.startsWith("top")?"bg-gradient-to-b from-black/60 via-transparent to-transparent":"bg-gradient-to-t from-black/60 via-transparent to-transparent":a==="solid"?"bg-gradient-to-t from-black/70 via-black/70 to-transparent":"",i=s==="center"?"absolute inset-0 flex items-center justify-center text-center":s.startsWith("top")?`absolute top-0 left-0 right-0 p-6 ${s==="top-center"?"text-center":""}`:s==="bottom-center"?"absolute bottom-0 left-0 right-0 p-6 text-center":s==="bottom-right"?"absolute bottom-0 left-0 right-0 p-6 text-right":"absolute bottom-0 left-0 right-0 p-6",o=a==="glass"?"backdrop-blur-md bg-black/30 border border-white/20 rounded-xl p-4 shadow-xl max-w-lg mx-auto":"";return e.jsxs(e.Fragment,{children:[l&&e.jsx("div",{className:`absolute inset-0 ${l}`}),e.jsx("div",{className:i,children:e.jsxs("div",{className:o,children:[e.jsx("p",{className:"text-white text-2xl font-black drop-shadow-2xl tracking-tight uppercase",children:f.title}),f.subtitle&&e.jsx("p",{className:"text-white/90 text-sm font-semibold drop-shadow mt-1",children:f.subtitle})]})})]})})(),f.overlayText&&(()=>{const s=f,a={"top-left":"absolute top-6 left-6","top-center":"absolute top-6 left-0 right-0 text-center px-6","top-right":"absolute top-6 right-6 text-right",center:"absolute inset-0 flex items-center justify-center text-center px-6","bottom-left":"absolute bottom-6 left-6","bottom-center":"absolute bottom-6 left-0 right-0 text-center px-6","bottom-right":"absolute bottom-6 right-6 text-right"},l={sm:"text-sm",md:"text-lg",lg:"text-xl",xl:"text-3xl","2xl":"text-5xl"},i={normal:"font-normal",bold:"font-bold",extrabold:"font-extrabold"},o={none:"",sm:"drop-shadow",md:"drop-shadow-md",lg:"drop-shadow-lg"},x=s.overlayPosition2||"center";return e.jsx("div",{className:a[x]||"absolute inset-0 flex items-center justify-center text-center px-6",style:{pointerEvents:"none"},children:e.jsx("p",{className:`${l[s.overlayFontSize||"lg"]||"text-xl"} ${i[s.overlayFontWeight||"bold"]||"font-bold"} ${o[s.overlayShadow||"none"]||""} whitespace-pre-line leading-tight`,style:{color:s.overlayColor||"#ffffff",fontFamily:s.overlayFont&&s.overlayFont!=="inherit"?s.overlayFont:void 0},children:s.overlayText})})})(),f.showCta&&f.ctaText&&(()=>{const s=f;return e.jsx("div",{className:"absolute bottom-8 left-0 right-0 flex justify-center",style:{pointerEvents:"none"},children:e.jsxs("span",{className:"inline-flex items-center gap-2 px-6 py-3 text-base font-semibold",style:{backgroundColor:s.ctaStyle==="solid"||s.ctaStyle==="pill"?s.ctaColor||"#2563eb":"transparent",color:s.ctaTextColor||"#ffffff",border:s.ctaStyle==="outline"?`2px solid ${s.ctaColor||"#2563eb"}`:"none",borderRadius:s.ctaStyle==="pill"?"9999px":"6px"},children:[s.ctaText," â"]})})})()]})]})}),e.jsx(ba,{open:Ma,onOpenChange:Pt,children:e.jsxs(fa,{className:"w-full sm:w-[480px] sm:max-w-[480px] overflow-y-auto",children:[e.jsx(Na,{children:e.jsxs(ya,{className:"flex items-center gap-2",children:[e.jsx(ma,{className:"w-5 h-5"})," Ad System Settings"]})}),e.jsxs("div",{className:"mt-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-semibold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(jt,{className:"w-4 h-4 text-blue-500"})," Google AdSense"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Publisher ID"}),e.jsx(y,{value:D.adsense_publisher_id,onChange:s=>Te(a=>({...a,adsense_publisher_id:s.target.value})),placeholder:"ca-pub-XXXXXXXXXXXXXXXXXX",className:"mt-1 font-mono text-xs"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:D.adsense_auto_ads_enabled==="true",onCheckedChange:s=>Te(a=>({...a,adsense_auto_ads_enabled:s?"true":"false"}))}),e.jsx(m,{className:"text-sm",children:"Enable Google Auto Ads"})]}),e.jsxs("a",{href:"https://adsense.google.com",target:"_blank",rel:"noreferrer",className:"text-xs text-blue-600 hover:underline flex items-center gap-1",children:["Open AdSense Dashboard ",e.jsx(va,{className:"w-3 h-3"})]})]})]}),e.jsx(wa,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"Vendor Advertising Pricing"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Base Plan ($/month) â 1 zone, 300Ã250 only"}),e.jsx(y,{type:"number",value:D.vendor_ad_base_price_monthly,onChange:s=>Te(a=>({...a,vendor_ad_base_price_monthly:s.target.value})),className:"mt-1 w-32"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Premium Plan ($/month) â All zones, all sizes"}),e.jsx(y,{type:"number",value:D.vendor_ad_premium_price_monthly,onChange:s=>Te(a=>({...a,vendor_ad_premium_price_monthly:s.target.value})),className:"mt-1 w-32"})]})]})]}),e.jsx(wa,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-800 mb-3",children:"Zone Defaults"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:D.show_google_ads_in_empty_zones==="true",onCheckedChange:s=>Te(a=>({...a,show_google_ads_in_empty_zones:s?"true":"false"}))}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Show Google Ads in empty zones"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Render AdSense in zones with no assigned ad"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{checked:D.hide_empty_zones==="true",onCheckedChange:s=>Te(a=>({...a,hide_empty_zones:s?"true":"false"}))}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Hide empty zones"}),e.jsx("p",{className:"text-xs text-slate-500",children:"Don't render zone HTML when no ad is assigned"})]})]})]})]}),e.jsxs(r,{className:"w-full",onClick:()=>Oe.mutate(D),disabled:Oe.isPending,children:[Oe.isPending?e.jsx(K,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ss,{className:"w-4 h-4 mr-2"}),"Save All Settings"]})]})]})}),e.jsx(ne,{open:Me.open,onOpenChange:s=>!s&&os({banner:null,open:!1}),children:e.jsxs(ie,{className:"sm:max-w-md",children:[e.jsx(re,{children:e.jsx(oe,{children:"Approve This Ad"})}),Me.banner&&e.jsxs("div",{className:"space-y-4",children:[Me.banner.imageUrl&&e.jsx("div",{className:"w-full h-32 bg-slate-100 rounded-lg overflow-hidden",children:e.jsx("img",{src:Me.banner.imageUrl,alt:"",className:"w-full h-full object-cover"})}),e.jsx("p",{className:"text-sm font-medium",children:Me.banner.title}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Assign to Zone (required)"}),e.jsxs(P,{value:at,onValueChange:Ft,children:[e.jsx(B,{className:"mt-1",children:e.jsx(F,{placeholder:"Select a zone..."})}),e.jsx(O,{children:Q.map(s=>e.jsx(g,{value:s.zoneKey,children:s.name},s.zoneKey))})]})]})]}),e.jsxs($e,{children:[e.jsx(r,{variant:"outline",onClick:()=>os({banner:null,open:!1}),children:"Cancel"}),e.jsxs(r,{className:"bg-green-600 hover:bg-green-700",disabled:!at||zs.isPending,onClick:()=>Me.banner&&zs.mutate({id:Me.banner.id,zoneId:at}),children:[zs.isPending?e.jsx(K,{className:"w-4 h-4 animate-spin mr-1"}):e.jsx(qs,{className:"w-4 h-4 mr-1"}),"Confirm Approval"]})]})]})}),e.jsx(ne,{open:fe.open,onOpenChange:s=>!s&&cs({banner:null,open:!1,reason:""}),children:e.jsxs(ie,{className:"sm:max-w-md",children:[e.jsx(re,{children:e.jsx(oe,{children:"Reject This Ad"})}),fe.banner&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium",children:fe.banner.title}),e.jsxs("div",{children:[e.jsxs(m,{className:"text-sm",children:["Rejection Reason ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Pa,{value:fe.reason,onChange:s=>cs(a=>({...a,reason:s.target.value})),placeholder:"Explain why this ad is being rejected (min 10 characters). The vendor will see this reason.",className:"mt-1 min-h-[100px]"}),fe.reason.length>0&&fe.reason.length<10&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:"Must be at least 10 characters"})]})]}),e.jsxs($e,{children:[e.jsx(r,{variant:"outline",onClick:()=>cs({banner:null,open:!1,reason:""}),children:"Cancel"}),e.jsxs(r,{variant:"destructive",disabled:fe.reason.length<10||rt.isPending,onClick:()=>fe.banner&&rt.mutate({id:fe.banner.id,rejectionReason:fe.reason}),children:[rt.isPending?e.jsx(K,{className:"w-4 h-4 animate-spin mr-1"}):e.jsx(bt,{className:"w-4 h-4 mr-1"}),"Confirm Rejection"]})]})]})}),e.jsx(ne,{open:Qa,onOpenChange:As,children:e.jsxs(ie,{className:"sm:max-w-md",children:[e.jsx(re,{children:e.jsx(oe,{children:"Add Google Ad Unit"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Ad Unit Name"}),e.jsx(y,{value:xe.name,onChange:s=>xs(a=>({...a,name:s.target.value})),placeholder:"e.g. Shop Sidebar Rectangle",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"AdSense Ad Slot ID"}),e.jsx(y,{value:xe.slotId,onChange:s=>xs(a=>({...a,slotId:s.target.value})),placeholder:"XXXXXXXXXX",className:"mt-1 font-mono"}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"The slot ID from your AdSense dashboard for this specific ad unit"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Ad Size"}),e.jsxs(P,{value:xe.adSize,onValueChange:s=>xs(a=>({...a,adSize:s})),children:[e.jsx(B,{className:"mt-1",children:e.jsx(F,{})}),e.jsxs(O,{children:[Object.entries(Vs).map(([s,a])=>e.jsx(g,{value:s,children:a},s)),e.jsx(g,{value:"responsive",children:"Responsive (recommended)"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm",children:"Zone Assignment"}),e.jsxs(P,{value:xe.zoneId,onValueChange:s=>xs(a=>({...a,zoneId:s})),children:[e.jsx(B,{className:"mt-1",children:e.jsx(F,{placeholder:"Select a zone..."})}),e.jsx(O,{children:Q.map(s=>e.jsx(g,{value:s.zoneKey,children:s.name},s.zoneKey))})]})]}),xe.slotId&&D.adsense_publisher_id&&e.jsxs("div",{children:[e.jsx(m,{className:"text-sm text-slate-500",children:"Generated AdSe
3nse Code Preview"}),e.jsx("pre",{className:"mt-1 p-2 bg-slate-50 border rounded text-xs overflow-x-auto whitespace-pre-wrap",children:`<ins class="adsbygoogle" 4 style="display:block" 5 data-ad-client="${D.adsense_publisher_id}" 6 data-ad-slot="${xe.slotId}" 7 data-ad-format="auto" 8 data-full-width-responsive="true"></ins>`})]})]}),e.jsxs($e,{children:[e.jsx(r,{variant:"outline",onClick:()=>As(!1),children:"Cancel"}),e.jsxs(r,{disabled:!xe.name||!xe.slotId,onClick:()=>{const s=`<ins class="adsbygoogle" style="display:block" data-ad-client="${D.adsense_publisher_id}" data-ad-slot="${xe.slotId}" data-ad-format="auto" data-full-width-responsive="true"></ins>`;Ze.mutate({...qe,title:xe.name,imageUrl:"",adType:"google_adsense",adSize:xe.adSize,zoneId:xe.zoneId||null,googleAdsenseCode:s,adStatus:"approved",isActive:!0}),As(!1),xs({name:"",slotId:"",adSize:"300x250",zoneId:"",isActive:!0})},children:[e.jsx(ss,{className:"w-4 h-4 mr-1"})," Save Ad Unit"]})]})]})}),e.jsx(ne,{open:Fa,onOpenChange:ls,children:e.jsxs(ie,{className:"max-w-3xl max-h-[85vh] flex flex-col gap-0 p-0",children:[e.jsxs(re,{className:"px-6 pt-5 pb-3 border-b shrink-0",children:[e.jsxs(oe,{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"w-5 h-5 text-red-500"}),"Manage Duplicate Banners"]}),e.jsxs("p",{className:"text-sm text-slate-500 mt-1",children:["Each group below has multiple banners with the same title. Review all copies and click ",e.jsx("strong",{children:"Keep this one"})," to delete the others. Pick the one with a real image URL and the correct settings."]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:et?e.jsxs("div",{className:"flex items-center justify-center py-16",children:[e.jsx(K,{className:"w-7 h-7 animate-spin text-slate-400"}),e.jsx("span",{className:"ml-3 text-slate-500",children:"Loading duplicatesâ¦"})]}):ns.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-slate-400 gap-3",children:[e.jsx("div",{className:"text-4xl",children:"â "}),e.jsx("p",{className:"text-sm font-medium",children:"No duplicate banners found."}),e.jsx("p",{className:"text-xs",children:"All your banner titles are unique."})]}):ns.map(s=>{const a=Oa===s.title;return e.jsxs("div",{className:"border rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"bg-amber-50 border-b border-amber-200 px-4 py-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-amber-600 text-sm",children:"â ï¸"}),e.jsx("span",{className:"font-semibold text-sm text-amber-800 truncate",children:s.title}),e.jsxs("span",{className:"ml-auto text-xs text-amber-600 shrink-0",children:[s.banners.length," copies"]})]}),e.jsx("div",{className:"grid gap-px bg-slate-100",style:{gridTemplateColumns:`repeat(${Math.min(s.banners.length,3)}, 1fr)`},children:s.banners.map(l=>{var vs;const i=l.image_url||l.imageUrl||"",o=l.video_url||l.videoUrl||"",x=i&&i.startsWith("/")&&!i.startsWith("//"),w=o&&o.startsWith("/")&&!o.startsWith("//"),L=i&&!x,A=l.is_active??l.isActive,M=l.created_at?new Date(l.created_at).toLocaleDateString():"â",Je=l.zone_id||l.zoneId||(Array.isArray(l.zone_ids)?(vs=l.zone_ids)==null?void 0:vs[0]:null)||"â";return e.jsxs("div",{className:"bg-white p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"relative rounded-lg overflow-hidden bg-slate-100 aspect-video flex items-center justify-center shrink-0",children:[L?e.jsx("img",{src:i,alt:l.title,className:"w-full h-full object-cover",onError:Es=>{Es.target.style.display="none"}}):e.jsxs("div",{className:"flex flex-col items-center gap-1 text-slate-400 text-xs p-3 text-center",children:[e.jsx("span",{className:"text-2xl",children:x?"â ï¸":"ð¼"}),e.jsx("span",{children:x?"Local path â broken in prod":"No image"})]}),A?e.jsx("span",{className:"absolute top-1.5 right-1.5 bg-green-500 text-white text-[10px] px-1.5 py-0.5 rounded-full font-medium",children:"Active"}):e.jsx("span",{className:"absolute top-1.5 right-1.5 bg-slate-400 text-white text-[10px] px-1.5 py-0.5 rounded-full font-medium",children:"Inactive"})]}),e.jsxs("div",{className:"text-xs space-y-1 flex-1",children:[e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"ID"}),e.jsxs("span",{className:"font-mono font-semibold text-slate-700",children:["#",l.id]})]}),e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"Zone"}),e.jsx("span",{className:"text-slate-700 truncate max-w-[120px]",children:Je})]}),e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"Type"}),e.jsx("span",{className:"text-slate-700",children:l.ad_type||l.adType||"â"})]}),e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"Size"}),e.jsx("span",{className:"text-slate-700",children:l.ad_size||l.adSize||"â"})]}),e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"Impr."}),e.jsx("span",{className:"text-slate-700",children:l.impressions??0})]}),e.jsxs("div",{className:"flex justify-between text-slate-500",children:[e.jsx("span",{children:"Created"}),e.jsx("span",{className:"text-slate-700",children:M})]}),i&&e.jsxs("div",{className:`mt-1 truncate text-[10px] rounded px-1.5 py-1 ${x?"bg-red-50 text-red-600":"bg-green-50 text-green-700"}`,children:[x?"â ï¸ Local: ":"â ",i]}),o&&e.jsxs("div",{className:`truncate text-[10px] rounded px-1.5 py-1 ${w?"bg-red-50 text-red-600":"bg-blue-50 text-blue-700"}`,children:["ð¬ ",o]})]}),e.jsxs(r,{size:"sm",className:"w-full mt-auto gap-1.5",disabled:a,onClick:()=>ol(l.id,s.title),children:[a?e.jsx(K,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx("span",{children:"â"}),"Keep this one"]})]},l.id)})})]},s.title)})}),e.jsxs($e,{className:"px-6 py-4 border-t shrink-0 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-slate-400",children:ns.length>0?`${ns.length} group${ns.length!==1?"s":""} remaining`:"All resolved"}),e.jsx(r,{variant:"outline",onClick:()=>ls(!1),children:"Close"})]})]})}),j.size>0&&e.jsxs("div",{className:"fixed bottom-4 left-1/2 -translate-x-1/2 z-50 bg-slate-900 text-white rounded-xl shadow-2xl px-4 py-3 flex flex-wrap items-center gap-2 max-w-[95vw]",children:[e.jsxs("span",{className:"text-sm font-medium mr-1",children:[j.size," selected"]}),e.jsxs(r,{size:"sm",variant:"secondary",className:"h-8 gap-1",disabled:me.isPending,onClick:()=>me.mutate({ids:Array.from(j),set:{isActive:!0}}),children:[e.jsx(yt,{className:"w-3.5 h-3.5"})," Activate"]}),e.jsxs(r,{size:"sm",variant:"secondary",className:"h-8 gap-1",disabled:me.isPending,onClick:()=>me.mutate({ids:Array.from(j),set:{isActive:!1}}),children:[e.jsx(Ia,{className:"w-3.5 h-3.5"})," Deactivate"]}),e.jsxs(r,{size:"sm",variant:"secondary",className:"h-8 gap-1",disabled:me.isPending,onClick:()=>me.mutate({ids:Array.from(j),set:{archived:!0}}),children:[e.jsx(bs,{className:"w-3.5 h-3.5"})," Archive"]}),e.jsxs(r,{size:"sm",variant:"secondary",className:"h-8 gap-1",disabled:me.isPending,onClick:()=>me.mutate({ids:Array.from(j),set:{archived:!1}}),children:[e.jsx(Nt,{className:"w-3.5 h-3.5"})," Unarchive"]}),e.jsxs(r,{size:"sm",variant:"secondary",className:"h-8 gap-1",onClick:()=>{W({applySchedule:!1,scheduleStart:"",scheduleEnd:"",applyBrands:!1,targetBrands:[],activeState:"no_change"}),k(!0)},children:[e.jsx(De,{className:"w-3.5 h-3.5"})," Bulk Edit"]}),e.jsxs(r,{size:"sm",variant:"destructive",className:"h-8 gap-1",disabled:_s.isPending,onClick:()=>H(1),children:[e.jsx(Ue,{className:"w-3.5 h-3.5"})," Delete"]}),e.jsxs(r,{size:"sm",variant:"ghost",className:"h-8 text-slate-300 hover:text-white hover:bg-slate-800",onClick:Se,children:[e.jsx(Qs,{className:"w-3.5 h-3.5"})," Clear"]})]}),e.jsx(ne,{open:b,onOpenChange:k,children:e.jsxs(ie,{className:"max-w-md",children:[e.jsx(re,{children:e.jsxs(oe,{children:["Bulk Edit ",j.size," Banner",j.size===1?"":"s"]})}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{checked:h.applySchedule,onCheckedChange:s=>W(a=>({...a,applySchedule:s===!0})),id:"bulk-apply-schedule"}),e.jsx(m,{htmlFor:"bulk-apply-schedule",className:"text-sm font-medium",children:"Update schedule"})]}),h.applySchedule&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 pl-6",children:[e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"Start (empty = no start limit)"}
8),e.jsx(y,{type:"datetime-local",value:h.scheduleStart,onChange:s=>W(a=>({...a,scheduleStart:s.target.value})),className:"h-8 text-xs mt-1"})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-xs",children:"End (empty = no end limit)"}),e.jsx(y,{type:"datetime-local",value:h.scheduleEnd,onChange:s=>W(a=>({...a,scheduleEnd:s.target.value})),className:"h-8 text-xs mt-1"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{checked:h.applyBrands,onCheckedChange:s=>W(a=>({...a,applyBrands:s===!0})),id:"bulk-apply-brands"}),e.jsx(m,{htmlFor:"bulk-apply-brands",className:"text-sm font-medium",children:"Update target brands"})]}),h.applyBrands&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 pl-6",children:[St.map(s=>e.jsx("button",{type:"button",onClick:()=>W(a=>({...a,targetBrands:a.targetBrands.includes(s)?a.targetBrands.filter(l=>l!==s):[...a.targetBrands,s]})),className:`px-2 py-0.5 rounded text-xs border transition-colors ${h.targetBrands.includes(s)?"bg-blue-600 text-white border-blue-600":"bg-white text-slate-600 border-slate-300 hover:border-blue-400"}`,children:s},s)),e.jsx("p",{className:"w-full text-[11px] text-slate-400 mt-1",children:"Leave all unselected to show on all brands."})]})]}),e.jsxs("div",{children:[e.jsx(m,{className:"text-sm font-medium",children:"Visibility"}),e.jsxs(P,{value:h.activeState,onValueChange:s=>W(a=>({...a,activeState:s})),children:[e.jsx(B,{className:"h-9 mt-1",children:e.jsx(F,{})}),e.jsxs(O,{children:[e.jsx(g,{value:"no_change",children:"No change"}),e.jsx(g,{value:"active",children:"Set Active (visible)"}),e.jsx(g,{value:"inactive",children:"Set Inactive (hidden)"})]})]})]})]}),e.jsxs($e,{children:[e.jsx(r,{variant:"outline",onClick:()=>k(!1),children:"Cancel"}),e.jsxs(r,{disabled:me.isPending||!h.applySchedule&&!h.applyBrands&&h.activeState==="no_change",onClick:()=>{const s={};h.applySchedule&&(s.scheduleStart=h.scheduleStart||null,s.scheduleEnd=h.scheduleEnd||null),h.applyBrands&&(s.targetBrands=h.targetBrands),h.activeState!=="no_change"&&(s.isActive=h.activeState==="active"),me.mutate({ids:Array.from(j),set:s})},children:[me.isPending?e.jsx(K,{className:"w-4 h-4 animate-spin mr-1"}):null,"Apply to ",j.size," banner",j.size===1?"":"s"]})]})]})}),e.jsx(ne,{open:G>0,onOpenChange:s=>{s||H(0)},children:e.jsxs(ie,{className:"max-w-sm",children:[e.jsx(re,{children:e.jsxs(oe,{className:"text-red-600 flex items-center gap-2",children:[e.jsx(Ue,{className:"w-5 h-5"}),G===1?`Delete ${j.size} banner${j.size===1?"":"s"}?`:"Are you absolutely sure?"]})}),e.jsx("p",{className:"text-sm text-slate-600",children:G===1?"This will permanently delete the selected banners. If you just want to hide them, use Archive instead.":`This action cannot be undone. ${j.size} banner${j.size===1?"":"s"} will be permanently deleted.`}),e.jsxs($e,{children:[e.jsx(r,{variant:"outline",onClick:()=>H(0),children:"Cancel"}),G===1?e.jsx(r,{variant:"destructive",onClick:()=>H(2),children:"Continue"}):e.jsxs(r,{variant:"destructive",disabled:_s.isPending,onClick:()=>_s.mutate(Array.from(j)),children:[_s.isPending?e.jsx(K,{className:"w-4 h-4 animate-spin mr-1"}):null,"Yes, delete permanently"]})]})]})})]})};export{Nn 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.