1import{b as ka,r,d as m,j as e,m as ie,S as ye,C as Be,X as kt,h as qe,k as Vo,o as Go,g as Ho,y as Bi,L as wr,p as ol}from"./AuthContext-BHU8ixGq.js";import{k as Wo,M as Jo,l as Ko,e as Xo}from"./fileDropFeedback-CvutpKT6.js";import{L as Pr,a as Ya,T as $r,I as qo,S as Tr,D as Yo,U as kl,E as Qo,b as Zo,c as zi,M as Vi,A as ed,W as td,d as ad,C as sd,e as rd,f as ld}from"./EmailCampaignStudio-9QfBDgFr.js";import{A as es}from"./arrow-right-BxMdSMzP.js";import{L as V}from"./loader-circle-M7VR685a.js";import{E as dl}from"./eye-CSP5OGKH.js";import{R as $s}from"./rocket-BRfakbsJ.js";import{T as ct}from"./trash-2-4aoyPhMZ.js";import{C as id}from"./circle-alert-COCg2HWs.js";import{F as Rt}from"./file-text-CPmxeqtC.js";import{U as Za}from"./upload-BWpItxXJ.js";import{S as Ds}from"./search-CxtytqWX.js";import{C as Ce}from"./circle-check-USQNwlH0.js";import{G as nd}from"./graduation-cap-BceRvrYo.js";import{B as rn}from"./book-open-C7F4qbNe.js";import{T as Rs}from"./target-BFQhuqIj.js";import{B as ss}from"./building-2-BD3XI1in.js";import{L as aa}from"./layers-CVmcPRbL.js";import{I as Ir}from"./image-D15vxKSK.js";import{B as od}from"./briefcase-BPpk3ZeA.js";import{M as dd}from"./minimize-2-DSpVUViC.js";import{B as cd}from"./box-CyYNTrLC.js";import{P as yl}from"./palette-CaLx3NBY.js";import{C as ln}from"./camera-y_7jPuQS.js";import{N as nn}from"./navigation-BBC0d8r1.js";import{Z as Dt,A as yt,L as Ea,C as xd}from"./zap-CMCS0uxF.js";import{G as St}from"./globe-CAcUfNTo.js";import{R as tt}from"./refresh-cw-DndmQay3.js";import{M as Ot}from"./monitor-DAME03yF.js";import{S as Is}from"./smartphone-CaWXwa3Q.js";import{B as fa}from"./bot-C39O27cO.js";import{S as wl}from"./send-BhrUfl5F.js";import{S as Ct}from"./save-u8ShwAJL.js";import{C as Gi}from"./code-C0XyVFUi.js";import{M as md}from"./maximize-2-A0EtFgLe.js";import{E as sa}from"./external-link-BpfKBhV5.js";import{W as ts}from"./wand-sparkles-CeELJ7m0.js";import{C as hd}from"./circle-play-CRWJd_Aq.js";import{V as Es}from"./video-C0GBw1-8.js";import{S as pd}from"./scissors-Cr_yh6x9.js";import{C as on}from"./clipboard-check-D4a7vQLS.js";import{U as Er}from"./users-CD7OPAsM.js";import{A as Ut}from"./activity-BVeh8RZS.js";import{C as _a}from"./cloud-upload-CKFzV9Ll.js";import{K as bd}from"./key-round-fzzO-wGF.js";import{T as Lr}from"./trending-up-DX9MHzW1.js";import{T as Ar}from"./triangle-alert-BdZoV68j.js";import{C as Sl}from"./chart-column-BZNab0j_.js";import{G as dn}from"./gauge-BW5rJZuG.js";import{C as cn}from"./clock-3-Cy1poin-.js";import{P as Ls}from"./plus-BTIu3GKn.js";import{E as xn}from"./earth-B2ZAcrVF.js";import{R as ud}from"./radio-BwjFPXKf.js";import{B as mn}from"./brain-O24TEYE3.js";import{P as gd}from"./play-D8m2jqF6.js";import{U as fd}from"./user-round-C_MY-Uh4.js";import{C as kd}from"./circle-dollar-sign-Bhp4H0Lj.js";import{M as _s}from"./mail-DK1JyBHj.js";import{P as hn}from"./phone-1d5am--P.js";import{M as wd}from"./message-square-text-BN16Zc1J.js";import{B as jd}from"./brain-circuit-DjAlKgY4.js";import{V as Nd}from"./volume-2-Smdqss84.js";import{M as vd}from"./mic-off-D1iXdyYx.js";import{M as jl}from"./mic-D83A0-k1.js";import{M as pn}from"./index-BShrfig7.js";import{M as Hi}from"./moon-CpFIqK0a.js";import{S as Lt}from"./shield-alert-Bxi7OXXG.js";import{C as cl}from"./chart-no-axes-column-aZriW2Hs.js";import{D as ga}from"./database-CalLWzHc.js";import{B as yd}from"./briefcase-business-D3ivgxtW.js";import{C as Wi}from"./calendar-CQGz8t-H.js";import{M as Cs}from"./message-circle-Cr04V0yU.js";import{K as jr}from"./key-B_X9s5r3.js";import{T as Nr,a as Ji}from"./thumbs-up-C3qg1UUM.js";import{F as Sd}from"./flask-conical-BgvHjIne.js";import{S as xl}from"./server-wbhD66ZT.js";import{R as Cd}from"./rotate-ccw-B9dpqr74.js";import{D as Ja}from"./download-DoFbbx8C.js";import{M as Ki}from"./message-square-BGAN7yzV.js";import{S as Td}from"./shield-B0pV0xgu.js";import{C as ml}from"./copy-BVpZVTf2.js";import{L as vr}from"./languages-CzseUrqS.js";import{P as Xi}from"./panels-top-left-B2v8pU04.js";import{C as Ad}from"./clock-Clrfa7v3.js";import{U as Pd}from"./user-DFsXUMpA.js";import{C as $d}from"./circle-x-IZz5QrjC.js";import{P as qi}from"./printer-gvrhvEYF.js";import{A as Id}from"./archive-BSUL1mFt.js";import{P as Ed}from"./presentation-C7hSa8Pk.js";import"./terminal-HV-FzrHH.js";import"./history-DrWdIrka.js";import"./lock-keyhole-BywF_LQk.js";import"./check-nZ18aBW0.js";import"./file-check-2-Df3Yl24k.js";/** 2 * @license lucide-react v0.546.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ld=[["path",{d:"M16 14v2.2l1.6 1",key:"fo4ql5"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],_d=ka("calendar-clock",Ld);/** 7 * @license lucide-react v0.546.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Dd=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],Rd=ka("circle-stop",Dd);/** 12 * @license lucide-react v0.546.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree.
16 */const Md=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]],Od=ka("clipboard-copy",Md);/** 17 * @license lucide-react v0.546.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Ud=[["path",{d:"M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z",key:"q8bfy3"}],["path",{d:"M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14",key:"1853fq"}],["path",{d:"M8 6v8",key:"15ugcq"}]],as=ka("megaphone",Ud);/** 22 * @license lucide-react v0.546.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const Fd=[["path",{d:"M15 18h-5",key:"95g1m2"}],["path",{d:"M18 14h-8",key:"sponae"}],["path",{d:"M4 22h16a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8a2 2 0 0 0-2 2v16a2 2 0 0 1-4 0v-9a2 2 0 0 1 2-2h2",key:"39pd36"}],["rect",{width:"8",height:"4",x:"10",y:"6",rx:"1",key:"aywv1n"}]],bn=ka("newspaper",Fd);/** 27 * @license lucide-react v0.546.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const Bd=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],zd=ka("pen-line",Bd);/** 32 * @license lucide-react v0.546.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const Vd=[["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m18 3-4 4h6l-4 4",key:"16psg9"}]],un=ka("plug-zap",Vd);/** 37 * @license lucide-react v0.546.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const Gd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2",key:"4125el"}],["path",{d:"M3 11h3c.8 0 1.6.3 2.1.9l1.1.9c1.6 1.6 4.1 1.6 5.7 0l1.1-.9c.5-.5 1.3-.9 2.1-.9H21",key:"1dpki6"}]],gn=ka("wallet-cards",Gd),Hd={Building2:ss,Rocket:$s,Target:Rs,BookOpen:rn,GraduationCap:nd},Wd={photorealistic:ln,illustration:yl,"3d-render":cd,minimalist:dd,corporate:od,abstract:ye},Jd=[{id:"none",label:"Landing Page Only",desc:"Standalone page, not in navigation",icon:Jo},{id:"analyze",label:"Analyze Now!",desc:"Under the Analyze Now dropdown",icon:Dt},{id:"verticals",label:"Verticals",desc:"Under the Verticals dropdown",icon:ss},{id:"about",label:"About",desc:"Under the About dropdown",icon:St},{id:"top-level",label:"Top-Level Link",desc:"Direct link in main navigation bar",icon:nn}],dt=()=>sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",Kd=({initialPageSlug:i,lang:p="en"})=>{var Fa,cs;const[u,M]=r.useState("manage"),[o,B]=r.useState([]),[g,_]=r.useState([]),[S,Q]=r.useState([]),[P,j]=r.useState([]),[z,G]=r.useState(!0),[Z,re]=r.useState("industry-vertical"),[Y,K]=r.useState("professional"),[U,J]=r.useState("photorealistic"),[de,b]=r.useState(""),[C,ne]=r.useState(""),[we,be]=r.useState(""),[T,l]=r.useState(""),[f,le]=r.useState("none"),[O,q]=r.useState(""),[Te,Oe]=r.useState(""),[Ye,Ge]=r.useState(!1),[Ke,nt]=r.useState(!1),[w,x]=r.useState(!1),[D,ae]=r.useState(null),je=r.useRef(null),[Ue,ot]=r.useState("none"),[E,ge]=r.useState(""),[Ie,Fe]=r.useState(""),[A,he]=r.useState(null),[Ne,He]=r.useState(null),[We,rt]=r.useState(!1),[Tt,_e]=r.useState(null),[xe,Ee]=r.useState(null),[De,xt]=r.useState([]),[mt,Qe]=r.useState(""),[lt,Je]=r.useState(!1),[At,Pt]=r.useState("content"),[at,ht]=r.useState(1),[Bt,rs]=r.useState(1e3),[zt,Cl]=r.useState(!1),[Me,ra]=r.useState(!1),Ze=r.useRef(null);r.useRef(null);const la=r.useRef(null),[et,Vt]=r.useState(null),[wa,ia]=r.useState("ai"),[pt,Ms]=r.useState(null),[wn,Tl]=r.useState(null),[st,Gt]=r.useState(""),[_r,ls]=r.useState(!1),[ja,is]=r.useState(!1),[ns,Da]=r.useState(""),[Ht,Ra]=r.useState(""),[Wt,Na]=r.useState(!1),ze=r.useRef(null);r.useEffect(()=>{if(i&&P.length>0&&u==="manage"){const d=P.find($=>$.slug===i);d&&Ua(d)}},[i,P,u]);const va=r.useCallback(async()=>{try{const $=await(await fetch(`${m}/api/pages/templates`)).json();B($.templates||[]),_($.styles||[]),Q($.imageStyles||[])}catch(d){console.error("Failed to fetch templates:",d)}},[]),Jt=r.useCallback(async()=>{G(!0);try{const d=await fetch(`${m}/api/admin/pages?all=1`,{headers:{"x-admin-token":dt()}});if(!d.ok)j([]);else{const $=await d.json();j(Array.isArray($)?$:[])}}catch(d){console.error("Failed to fetch pages:",d),j([])}G(!1)},[]);r.useEffect(()=>{va(),Jt()},[va,Jt]),r.useEffect(()=>{var d;(d=la.current)==null||d.scrollIntoView({behavior:"smooth"})},[De]),r.useEffect(()=>{const d=async $=>{if($.data){if($.data.type==="wysiwyg-edit"&&$.data.keyPath){console.log("WYSIWYG edit received:",$.data),ia("ai"),Qe(`Update the text for "${$.data.keyPath}" to: ${$.data.currentValue}`);return}if($.data.type==="wysiwyg-save"&&$.data.keyPath)try{if((await fetch(`${m}/api/admin/cms/content`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({lang:p,key_path:$.data.keyPath,content:$.data.newValue})})).ok){const F=sessionStorage.getItem("emlo_preview_data");if(F){const Ae=JSON.parse(F);Ae.translations=Ae.translations||{}
41,Ae.translations[$.data.keyPath]=$.data.newValue,sessionStorage.setItem("emlo_preview_data",JSON.stringify(Ae))}}}catch(I){console.error("WYSIWYG Save failed",I)}}};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[p]);const Os=async d=>{if(!(!d||d.length<50)){x(!0);try{const $=await fetch(`${m}/api/admin/pages/analyze-reference`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({content:d})}),I=await $.json();$.ok&&I.success&&(I.suggestedTitle&&b(I.suggestedTitle),I.suggestedDescription&&ne(I.suggestedDescription),I.suggestedTargetAudience&&be(I.suggestedTargetAudience),I.suggestedStyle&&K(I.suggestedStyle),I.suggestedTemplate&&re(I.suggestedTemplate),I.suggestedImageStyle&&J(I.suggestedImageStyle),I.suggestedAdditionalContext&&l(I.suggestedAdditionalContext))}catch($){console.error("Failed to analyze content:",$)}x(!1)}},Ma=async()=>{let d=O.trim();if(d){!d.startsWith("http://")&&!d.startsWith("https://")&&(d="https://"+d,q(d)),Ge(!0),ae(null);try{const $=await fetch(`${m}/api/admin/pages/scrape`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({url:d})}),I=await $.json();if(!$.ok)throw new Error(I.error||"Scrape failed");Oe(I.content||""),I.content&&Os(I.content)}catch($){ae($.message)}Ge(!1)}},Us=async d=>{var I;const $=(I=d.target.files)==null?void 0:I[0];if($){nt(!0),ae(null);try{const F=new FormData;F.append("pdf",$);const Ae=await fetch(`${m}/api/admin/pages/parse-pdf`,{method:"POST",headers:{"x-admin-token":dt()},body:F}),Xe=await Ae.json();if(!Ae.ok)throw new Error(Xe.error||"PDF parse failed");Oe(Xe.content||""),Xe.content&&Os(Xe.content)}catch(F){ae(F.message)}nt(!1)}},os=async()=>{if(!(!de.trim()||!C.trim())){M("generating"),He(null);try{const d=await fetch(`${m}/api/admin/pages/generate`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({title:de,description:C,targetAudience:we,template:Z,style:Y,imageStyle:U,additionalContext:T,startingPointContent:Te||void 0})}),$=await d.json();if(!d.ok)throw new Error($.error||"Generation failed");sessionStorage.setItem("emlo_preview_data",JSON.stringify({...$.page,translations:$.page.translations})),he($.page),fe("draft",$.page)}catch(d){He(d.message),M("describe")}}},ya=async()=>{if(!Ht.trim()||!A||Wt)return;const d=Ht.trim();Ra(""),Na(!0);try{const $=await fetch(`${m}/api/admin/pages/refine-json`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({pageJson:{...A,translations:void 0},translations:A.translations,instruction:d})}),I=await $.json();if(!$.ok)throw new Error(I.error||"Refinement failed");const F=I.page;F.translations=I.translations,sessionStorage.setItem("emlo_preview_data",JSON.stringify(F)),he(F),ze.current&&(ze.current.src=`${window.location.origin}/p/preview?t=${Date.now()}`)}catch($){alert("Refinement failed: "+$.message)}Na(!1)},fe=async(d,$)=>{const I=$||A;if(I){rt(!0);try{const F=await fetch(`${m}/api/admin/pages`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({slug:I.slug,title:I.title,metaDescription:I.metaDescription,pageJson:{sections:I.sections,ogTitle:I.ogTitle,ogDescription:I.ogDescription,canonicalPath:I.canonicalPath,seoKeywords:I.seoKeywords},status:d,ogTitle:I.ogTitle,ogDescription:I.ogDescription,canonicalUrl:I.canonicalPath,translations:I.translations,navLabel:Ue!=="none"?E||I.title:"",navPosition:Ue!=="none"?Ue:""})}),Ae=await F.json();if(!F.ok)throw new Error(Ae.error||"Save failed");if(sessionStorage.setItem("emlo_preview_data",JSON.stringify(I)),$){const Bs=(await(await fetch(`${m}/api/admin/pages?all=1`,{headers:{"x-admin-token":dt()}})).json()).find(xs=>xs.slug===I.slug);Bs?Ua(Bs):M("preview")}else M("published");Jt()}catch(F){alert("Save failed: "+F.message),$||M("preview")}rt(!1)}},Fs=async d=>{const $=d.status==="published"?"draft":"published";rt(!0);try{if(!(await fetch(`${m}/api/admin/pages/${d.id}`,{method:"PATCH",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({status:$})})).ok)throw new Error("Failed to update status");Jt()}catch(I){alert("Status update failed: "+I.message)}rt(!1)},Dr=async d=>{try{await fetch(`${m}/api/admin/pages/${d}`,{method:"DELETE",headers:{"x-admin-token":dt()}}),_e(null),Jt()}catch($){console.error("Delete failed:",$)}},wt=async d=>{const $=mt.trim();if(!(!$||!xe||lt)){Qe(""),xt(I=>[...I,{role:"user",content:$,timestamp:new Date}]),Je(!0);try{const I=await fetch(`${m}/api/admin/pages/${xe.id}/ai-edit`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({command:$,messages:De})}),F=await I.json();if(!I.ok)throw new Error(F.error||"AI edit failed");let Ae=`â ${F.summary}`;const Xe=F.generatedImages||[];if(xt($t=>[...$t,{role:"assistant",content:Ae,timestamp:new Date,images:Xe.length>0?Xe:void 0}]),F.pageJson){const $t={slug:xe.slug,title:F.pageJson.title||xe.title,sections:F.pageJson.sections||[],translations:F.translations||{},metaDescription:F.pageJson.metaDescription||"",ogTitle:F.pageJson.ogTitle||"",ogDescription:F.pageJson.ogDescription||""};sessionStorage.setItem("emlo_preview_data",JSON.stringify($t))}if(xe&&ds(xe.id),Ze.current){const $t=`/p/${xe.slug}?active_editor=true&cms_lang=${p}`;Ze.current.src=`${$t}&_t=${Date.now()}`}Jt()}catch(I){xt(F=>[...F,{role:"assistant",content:`â Error: ${I.message}`,timestamp:new Date}])}Je(!1)}},Oa=r.useRef(null),na=async d=>{var I;const $=(I=d.target.files)==null?void 0:I[0];if(!(!$||!xe)){xt(F=>[...F,{role:"user",content:`ð Uploading image: ${$.name}`,timestamp:new Date}]),Je(!0);try{const F=new FormData;F.append("image",$),F.append("slug",xe.slug);const Ae=await fetch(`${m}/api/admin/pages/upload-image`,{method:"POST",headers:{"x-admin-token":dt()},body:F}),Xe=await Ae.json();if(!Ae.ok)throw new Error(Xe.error||"Upload failed");xt($t=>[...$t,{role:"assistant",content:`â Image uploaded successfully! Path: \`${Xe.path}\` 42 43Tell me where you'd like to place this image, or I can add it to a section.`,timestamp:new Date,images:[Xe.path]}]),Qe(`Add the uploaded image ${Xe.path} to `)}catch(F){xt(Ae=>[...Ae,{role:"assistant",content:`â Upload failed: ${F.message}`,timestamp:new Date}])}Je(!1),Oa.current&&(Oa.current.value="")}},ds=async d=>{var $;if(d===-1&&A){Ms({page:{id:-1,slug:"preview",title:A.title,meta_description:A.metaDescription,status:"draft",nav_label:"",created_at:new Date().toISOString(),updated_at:new Date().toISOString()},translations:Object.entries(A.translations).map(([I,F])=>({key_path:I.startsWith("t:")?I.slice(2):I,content:F,lang:"en"}))});return}try{const I=await fetch(`${m}/api/admin/pages/${d}`,{headers:{"x-admin-token":dt()}}),F=await I.json();
43if(I.ok&&(Ms(F),F.page)){const Ae={};Array.isArray(F.translations)&&F.translations.forEach(Xe=>{Ae[Xe.key_path]=Xe.content}),sessionStorage.setItem("emlo_preview_data",JSON.stringify({slug:F.page.slug,title:F.page.title,sections:typeof F.page.page_json=="string"?JSON.parse(F.page.page_json).sections:(($=F.page.page_json)==null?void 0:$.sections)||[],translations:Ae,metaDescription:F.page.meta_description,ogTitle:F.page.og_title,ogDescription:F.page.og_description}))}}catch(I){console.error("Failed to fetch page detail:",I)}},Ua=async d=>{Ee(d),xt([{role:"assistant",content:`Ready to edit "${d.title}". I can modify text, layout, colors, add/remove sections, and **generate or place images**. Upload an image or ask me to create one!`,timestamp:new Date}]),ia("ai"),await ds(d.id),M("editor")},Kt=()=>{M("manage"),he(null),He(null),b(""),ne(""),be(""),l(""),le("none"),q(""),Oe(""),Ee(null),xt([]),ot("none"),ge("")};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 space-y-4 md:space-y-8",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl md:text-3xl font-black tracking-tight flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-purple-500 to-indigo-500 flex items-center justify-center shrink-0",children:e.jsx(Pr,{className:"w-5 h-5 text-white"})}),"AI Page Builder"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mt-1",children:"Create stunning pages with AI-powered content generation"})]}),u!=="manage"&&e.jsxs("button",{onClick:Kt,className:"flex items-center justify-center gap-2 px-4 py-2 rounded-xl bg-black/5 dark:bg-white/5 text-sm font-bold hover:bg-black/10 dark:hover:bg-white/10 transition w-full md:w-auto",children:[e.jsx(Wo,{className:"w-4 h-4"})," Back to Pages"]})]}),u==="manage"&&e.jsxs(ie.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("button",{onClick:()=>M("describe"),className:"w-full p-5 md:p-6 rounded-2xl md:rounded-[2rem] border-2 border-dashed border-purple-300 dark:border-purple-500/30 bg-purple-50/50 dark:bg-purple-500/5 hover:bg-purple-100 dark:hover:bg-purple-500/10 transition-all group flex flex-col md:flex-row items-center md:justify-center text-center md:text-left gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-gradient-to-br from-purple-500 to-indigo-500 flex items-center justify-center group-hover:scale-110 transition-transform shrink-0",children:e.jsx(ye,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-black text-lg text-purple-700 dark:text-purple-300",children:"Create New Page with AI"}),e.jsx("div",{className:"text-xs md:text-sm text-purple-600/60 dark:text-purple-300/50",children:"Describe your page and let AI generate content & SEO"})]}),e.jsx(es,{className:"w-5 h-5 text-purple-400 group-hover:translate-x-1 transition-transform hidden md:block"})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:["Your Pages (",P.length,")"]}),z?e.jsxs("div",{className:"text-center py-12 text-black/30 dark:text-white/30",children:[e.jsx(V,{className:"w-6 h-6 animate-spin mx-auto mb-2"}),"Loading pages..."]}):P.length===0?e.jsxs("div",{className:"text-center py-16 text-black/30 dark:text-white/30",children:[e.jsx(Pr,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"font-medium",children:"No pages yet"}),e.jsx("p",{className:"text-sm mt-1",children:"Create your first AI-generated page above"})]}):e.jsx("div",{className:"grid gap-4",children:P.map(d=>e.jsxs("div",{className:"p-4 rounded-xl bg-white dark:bg-white/5 border border-black/5 dark:border-white/10 flex flex-col sm:flex-row sm:items-center justify-between hover:shadow-lg transition-all group gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full shrink-0 ${d.status==="published"?"bg-emerald-500":"bg-amber-400"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-bold text-sm truncate",children:d.title}),e.jsxs("div",{className:"text-[10px] md:text-xs text-black/40 dark:text-white/40 flex flex-wrap items-center gap-x-2 gap-y-1 mt-1 font-medium italic",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[9px] font-black uppercase tracking-tighter ${d.status==="published"?"bg-emerald-100 dark:bg-emerald-500/15 text-emerald-700 dark:text-emerald-400":"bg-amber-100 dar
43k:bg-amber-500/15 text-amber-700 dark:text-amber-400"}`,children:d.status}),e.jsxs("span",{className:"truncate max-w-[120px]",children:["/p/",d.slug]}),e.jsx("span",{className:"hidden sm:inline",children:"·"}),e.jsx("span",{children:new Date(d.created_at).toLocaleDateString()})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:opacity-0 group-hover:opacity-100 transition border-t sm:border-0 pt-2 sm:pt-0",children:[e.jsxs("button",{onClick:()=>Ua(d),className:"flex-1 sm:flex-none flex items-center justify-center gap-2 p-2 rounded-lg bg-purple-500/5 sm:bg-transparent hover:bg-purple-50 dark:hover:bg-purple-500/10 transition text-purple-600 dark:text-purple-400 font-bold sm:font-normal",title:"Edit with AI",children:[e.jsx(zd,{className:"w-3.5 h-3.5"})," ",e.jsx("span",{className:"sm:hidden text-[10px] uppercase",children:"Edit"})]}),e.jsx("a",{href:`/p/${d.slug}`,target:"_blank",rel:"noopener noreferrer",className:"p-2 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition text-black/40 dark:text-white/40 hover:text-teal-600 dark:hover:text-teal-400",title:"Preview",children:e.jsx(dl,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Fs(d),disabled:We,className:`p-2 rounded-lg transition-all ${d.status==="published"?"text-emerald-500 hover:bg-emerald-50 dark:hover:bg-emerald-500/10":"text-amber-500 hover:bg-amber-50 dark:hover:bg-amber-500/10"}`,title:d.status==="published"?"Unpublish":"Publish Now",children:We?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx($s,{className:`w-4 h-4 ${d.status==="published"?"fill-emerald-500/20":""}`})}),Tt===d.id?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx("button",{onClick:()=>Dr(d.id),className:"px-2 py-1 rounded-lg bg-red-500 text-white text-[10px] font-black uppercase hover:bg-red-600 transition",children:"Delete"}),e.jsx("button",{onClick:()=>_e(null),className:"px-2 py-1 rounded-lg bg-black/5 dark:bg-white/10 text-[10px] font-black uppercase hover:bg-black/10 dark:hover:bg-white/15 transition",children:"No"})]}):e.jsx("button",{onClick:()=>_e(d.id),className:"p-2 rounded-lg hover:bg-red-50 dark:hover:bg-red-500/10 transition text-black/30 dark:text-white/30 hover:text-red-500 ml-auto",title:"Delete",children:e.jsx(ct,{className:"w-4 h-4"})})]})]},d.id))})]})]}),u==="describe"&&e.jsxs(ie.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-8",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-3 overflow-x-auto pb-2 scrollbar-hide",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 rounded-full bg-purple-100 dark:bg-purple-500/15 text-purple-700 dark:text-purple-400 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx("span",{className:"w-4 md:w-5 h-4 md:h-5 rounded-full bg-purple-500 text-white flex items-center justify-center text-[8px] md:text-[10px] font-black",children:"1"})," Describe"]}),e.jsx(Be,{className:"w-3 md:w-4 h-3 md:h-4 text-black/20 dark:text-white/20 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 rounded-full bg-black/5 dark:bg-white/5 text-black/30 dark:text-white/30 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx("span",{className:"w-4 md:w-5 h-4 md:h-5 rounded-full bg-black/10 dark:bg-white/10 flex items-center justify-center text-[8px] md:text-[10px] font-black",children:"2"})," Preview"]}),e.jsx(Be,{className:"w-3 md:w-4 h-3 md:h-4 text-black/20 dark:text-white/20 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 rounded-full bg-black/5 dark:bg-white/5 text-black/30 dark:text-white/30 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx("span",{className:"w-4 md:w-5 h-4 md:h-5 rounded-full bg-black/10 dark:bg-white/10 flex items-center justify-center text-[8px] md:text-[10px] font-black",children:"3"})," Publish"]})]}),Ne&&e.jsxs("div",{className:"p-4 rounded-xl bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-500/20 flex items-center gap-3 text-sm text-red-700 dark:text-red-400",children:[e.jsx(id,{className:"w-5 h-5 shrink-0"})," ",Ne]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:"Starting Point (Optional)"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4",children:[["none","Start Fresh",Rt],["url","Scrape URL",Ya],["pdf","Upload PDF",Za]].map(([d,$,I])=>e.jsxs("button",{onClick:()=>
43le(d),className:`p-3 md:p-4 rounded-xl border-2 text-left transition-all flex items-center gap-3 ${f===d?"border-purple-500 bg-purple-50 dark:bg-purple-500/10":"border-transparent bg-white dark:bg-white/5 border-black/5 dark:border-white/10 hover:bg-black/5 dark:hover:bg-white/5"}`,children:[e.jsx(I,{className:"w-4 md:w-5 h-4 md:h-5 shrink-0"}),e.jsx("span",{className:"text-xs md:text-sm font-bold",children:$})]},d))}),f==="url"&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{type:"url",value:O,onChange:d=>q(d.target.value),placeholder:"https://example.com/page-to-reference",className:"flex-1 px-5 py-3 rounded-xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 outline-none transition text-sm"}),e.jsxs("button",{onClick:Ma,disabled:Ye||!O.trim(),className:"px-6 py-3 rounded-xl bg-purple-500 text-white font-bold text-sm hover:bg-purple-400 transition disabled:opacity-50 flex items-center gap-2",children:[Ye?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ds,{className:"w-4 h-4"})," Scrape"]})]}),f==="pdf"&&e.jsxs("div",{children:[e.jsx("input",{ref:je,type:"file",accept:".pdf",onChange:Us,className:"hidden"}),e.jsxs("button",{onClick:()=>{var d;return(d=je.current)==null?void 0:d.click()},disabled:Ke,className:"px-6 py-3 rounded-xl border-2 border-dashed border-purple-300 dark:border-purple-500/30 bg-purple-50/50 dark:bg-purple-500/5 text-sm font-bold text-purple-700 dark:text-purple-300 hover:bg-purple-100 transition disabled:opacity-50 flex items-center gap-2",children:[Ke?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Za,{className:"w-4 h-4"})," ",Ke?"Parsing PDF...":"Choose PDF File"]})]}),w&&e.jsx("div",{className:"mt-3 p-3 rounded-xl bg-purple-50 dark:bg-purple-500/5 border border-purple-200 dark:border-purple-500/20 text-xs text-purple-700 dark:text-purple-400 animate-pulse",children:e.jsxs("div",{className:"flex items-center gap-2 font-bold italic",children:[e.jsx(ye,{className:"w-4 h-4 animate-spin text-purple-500"}),"AI is analyzing reference material to pre-fill the form..."]})}),D&&e.jsx("p",{className:"text-red-500 text-xs mt-2 font-bold",children:D}),Te&&e.jsxs("div",{className:"mt-3 p-3 rounded-xl bg-emerald-50 dark:bg-emerald-500/5 border border-emerald-200 dark:border-emerald-500/20 text-xs text-emerald-700 dark:text-emerald-400",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),e.jsxs("span",{className:"font-bold",children:["Content extracted (",Te.length," chars)"]})]}),e.jsxs("p",{className:"line-clamp-3 text-emerald-600/70 dark:text-emerald-400/60",children:[Te.substring(0,200),"..."]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:"Choose a Template"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:o.map(d=>{const $=Hd[d.icon]||aa;return e.jsxs("button",{onClick:()=>re(d.id),className:`p-5 rounded-2xl border-2 text-left transition-all ${Z===d.id?"border-purple-500 bg-purple-50 dark:bg-purple-500/10 shadow-lg shadow-purple-500/10":"border-transparent bg-white dark:bg-white/5 hover:bg-black/5 dark:hover:bg-white/5 border-black/5 dark:border-white/10"}`,children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center mb-3 ${Z===d.id?"bg-purple-500 text-white":"bg-black/5 dark:bg-white/10"}`,children:e.jsx($,{className:"w-5 h-5"})}),e.jsx("div",{className:"font-bold text-sm mb-1",children:d.name}),e.jsx("div",{className:"text-xs text-black/40 dark:text-white/40 leading-relaxed",children:d.description})]},d.id)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:"Writing Style"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:g.map(d=>e.jsxs("button",{onClick:()=>K(d.id),className:`p-4 rounded-xl border-2 text-left transition-all ${Y===d.id?"border-indigo-500 bg-indigo-50 dark:bg-indigo-500/10":"border-transparent bg-white dark:bg-white/5 border-black/5 dark:border-white/10"}`,children:[e.jsx("div",{className:"font-bold text-sm mb-1",children:d.name}),e.jsx("div",{className:"text-xs text-black/40 dark:text-white/40",children:d.description})]},d.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ir,{className:"w-3.5 h-3.5"})," Photo / Image Style"]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:S.map(d=>{const $=Wd[d.id]||ln;return e.jsxs("button",{onClick:()=>J(d.id),className:`p-4 rounded-xl border-2 text-left transition-all flex items-center gap-3 ${U===d.id?"border-pink-500 bg-pink-50 dark:bg-pink-500/10":"border-transparent bg-white dark:bg-white/5 border-black/5 dark:border-white/10"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center shrink-0 ${U===d.id?"bg-pink-500 text-white":"bg-black/5 dark:bg-white/10"}`,children:e.jsx($,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-sm",children:d.name}),e.jsx("div",{className:"text-[11px] text-black/40 dark:text-white/40",children:d.description})]})]},d.id)})})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-2",children:"Page Title *"}),e.jsx("input",{type:"text",value:de,onChange:d=>b(d.target.value),placeholder:"e.g., Voice Analysis for Legal Depositions",className:"w-full px-5 py-4 rounded-2xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20 outline-none text-lg font-medium transition"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-2",children:"Page Description *"}),e.jsx("textarea",{value:C,onChange:d=>ne(d.target.value),placeholder:"Describe what this page is about...",rows:4,className:"w-full px-5 py-4 rounded-2xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 focus:ring-2 focus:ring-purple-500/20 outline-none resize-none transition"})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-2",children:"Target Audience"}),e.jsx("input",{type:"text",value:we,onChange:d=>be(d.target.value),placeholder:"e.g., Law firm partners, corporate legal teams",className:"w-full px-5 py-3 rounded-xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 outline-none transition"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-2",children:"Additional Context"}),e.jsx("input",{type:"text",value:T,onChange:d=>l(d.target.value),placeholder:"Any specific features, data points, or tone details",className:"w-full px-5 py-3 rounded-xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 outline-none transition"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(nn,{className:"w-3.5 h-3.5"})," Page Placement"]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:Jd.map(d=>e.jsx("button",{onClick:()=>ot(d.id),className:`p-4 rounded-xl border-2 text-left transition-all ${Ue===d.id?"border-teal-500 bg-teal-50 dark:bg-teal-500/10":"border-transparent bg-white dark:bg-white/5 border-black/5 dark:border-white/10"}`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center shrink-0 ${Ue===d.id?"bg-teal-500 text-white":"bg-black/5 dark:bg-white/10"}`,children:e.jsx(d.icon,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold text-sm",children:d.label}),e.jsx("div",{className:"text-[11px] text-black/40 dark:text-white/40",children:d.desc})]})]})},d.id))}),Ue!=="none"&&e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{className:"block text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-2",children:"Navigation Label"}),e.jsx("input",{type:"text",value:E,onChange:d=>ge(d.target.value),placeholder:de||"Menu label for this page",className:"w-full px-5 py-3 rounded-xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-teal-500 outline-none transition"})]})]}),e.jsxs("button",{onClick:os,disabled:!de.trim()||!C.trim(),className:"w-full py-5 rounded-2xl bg-gradient-to-r from-purple-500 to-indigo-500 text-white font-black text-lg flex items-center justify-center gap-3 hover:shadow-xl hover:shadow-
43purple-500/20 transition-all disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ye,{className:"w-6 h-6"})," Generate Page with AI"]})]}),u==="generating"&&e.jsxs(ie.div,{initial:{opacity:0},animate:{opacity:1},className:"text-center py-24",children:[e.jsxs("div",{className:"relative inline-flex",children:[e.jsx("div",{className:"w-20 h-20 rounded-3xl bg-gradient-to-br from-purple-500 to-indigo-500 flex items-center justify-center animate-pulse",children:e.jsx(ye,{className:"w-10 h-10 text-white"})}),e.jsx("div",{className:"absolute -inset-4 rounded-[2rem] border-2 border-purple-500/30 animate-ping"})]}),e.jsx("h3",{className:"text-2xl font-black mt-8 mb-3",children:"Generating Your Page..."}),e.jsx("p",{className:"text-black/40 dark:text-white/40 max-w-md mx-auto",children:"The AI is crafting compelling content, optimal structure, and SEO metadata. This usually takes 10-20 seconds."}),e.jsx("div",{className:"flex justify-center gap-2 mt-8",children:["Structure","Content","SEO","Translations"].map((d,$)=>e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/5 dark:bg-white/5 text-xs font-medium",children:[e.jsx(V,{className:"w-3 h-3 animate-spin",style:{animationDelay:`${$*300}ms`}})," ",d]},d))})]}),u==="preview"&&A&&e.jsxs(ie.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 md:gap-3 overflow-x-auto pb-2 scrollbar-hide",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 rounded-full bg-emerald-100 dark:bg-emerald-500/15 text-emerald-700 dark:text-emerald-400 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx(Ce,{className:"w-3 md:w-4 h-3 md:h-4 text-emerald-500 shrink-0"})," Describe"]}),e.jsx(Be,{className:"w-3 md:w-4 h-3 md:h-4 text-black/20 dark:text-white/20 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 md:px-4 py-2 rounded-full bg-purple-100 dark:bg-purple-500/15 text-purple-700 dark:text-purple-400 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx("span",{className:"w-4 md:w-5 h-4 md:h-5 rounded-full bg-purple-500 text-white flex items-center justify-center text-[8px] md:text-[10px] font-black",children:"2"})," Preview & Refine"]}),e.jsx(Be,{className:"w-3 md:w-4 h-3 md:h-4 text-black/20 dark:text-white/20 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 rounded-full bg-black/5 dark:bg-white/5 text-black/30 dark:text-white/30 text-[10px] md:text-xs font-bold whitespace-nowrap",children:[e.jsx("span",{className:"w-4 md:w-5 h-4 md:h-5 rounded-full bg-black/10 dark:bg-white/10 flex items-center justify-center text-[8px] md:text-[10px] font-black",children:"3"})," Publish"]})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{onClick:Kt,className:"px-4 py-2 rounded-xl bg-black/5 dark:bg-white/5 text-xs font-bold hover:bg-black/10 dark:hover:bg-white/10 transition",children:"Discard"})})]}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[e.jsxs("div",{className:"flex-1 flex flex-col rounded-[2.5rem] border border-black/10 dark:border-white/10 bg-white dark:bg-[#0a0a0a] overflow-hidden shadow-2xl transition-all duration-500 h-[600px] lg:h-[700px]",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-white dark:bg-[#0d0d0d] border-b border-black/5 dark:border-white/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-400"})]}),e.jsxs("div",{className:"flex px-4 py-1.5 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 items-center gap-2",children:[e.jsx(St,{className:"w-3 h-3 text-black/30 dark:text-white/30"}),e.jsx("span",{className:"text-[11px] font-mono text-black/40 dark:text-white/40 tracking-tight",children:"emotionlogic.ai/preview"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("button",{onClick:()=>{ze.current&&(ze.current.src=ze.current.src)},className:"w-10 h-10 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 flex items-center justify-center transition group active:scale-95",children:e.jsx(tt,{className:"w-4 h-4 text-black/40 dark:text-white/40 group-hover:rotate-180 transition-transform duration-500"})})})]}),e.jsxs("div",{className:"flex-1 relative bg-white dark:bg-[#111]",children:[e.jsx("iframe",{ref:ze,src:"/p/preview",className:"w-full h-full border-0 absolute inset-0",title:"Page Preview"}),Wt&&e.jsx("div",{className:"absolute inset-0 bg-black/20 backdrop-blur-[2px] z-20 flex items-center justify-center",children:e.jsxs("div",{className:"px-6 py-4 rounded-3xl bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 shadow-2xl flex items-center gap-4",children:[e.jsx(V,{className:"w-6 h-6 animate-spin text-purple-500"}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"text-sm font-black uppercase tracking-widest text-purple-500",children:"Refining Page..."}),e.jsx("div",{className:"text-[10px] text-black/40 dark:text-white/40",children:"The AI is applying your changes now."})]})]})})]}),e.jsx("div",{className:"flex items-center justify-center gap-4 py-3 bg-gray-50/50 dark:bg-white/[0.01] border-t border-black/5 dark:border-white/5",children:[{icon:Ot,label:"Desktop",width:"100%"},{icon:$r,label:"Tablet",width:"768px"},{icon:Is,label:"Mobile",width:"375px"}].map(d=>e.jsxs("button",{onClick:()=>{ze.current&&(ze.current.style.width=d.width,ze.current.style.margin=d.width==="100%"?"0":"0 auto")},className:"px-3 py-1.5 rounded-xl text-[10px] font-black uppercase tracking-widest flex items-center gap-2 hover:bg-black/5 dark:hover:bg-white/5 transition text-black/40 dark:text-white/40",children:[e.jsx(d.icon,{className:"w-3.5 h-3.5"})," ",d.label]},d.label))})]}),e.jsxs("div",{className:"w-full lg:w-[400px] flex flex-col gap-6 shrink-0",children:[e.jsxs("div",{className:"p-8 rounded-[2.5rem] bg-gradient-to-br from-purple-600 to-indigo-700 text-white shadow-2xl relative overflow-hidden group",children:[e.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-10 group-hover:scale-110 transition-transform duration-700",children:e.jsx(ye,{className:"w-24 h-24"})}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(fa,{className:"w-4 h-4 text-white"})}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest opacity-70",children:"AI Designer Assistant"})]}),e.jsxs("h3",{className:"text-2xl font-black mb-4 leading-tight",children:["Something not right?",e.jsx("br",{}),"Just ask me."]}),e.jsx("p",{className:"text-white/70 text-xs mb-8 leading-relaxed",children:'I can change headings, swap colors, add sections, or adjust the tone. Try: "Make the title more punchy"'}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{value:Ht,onChange:d=>Ra(d.target.value),onKeyDown:d=>
43{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),ya())},placeholder:"Ask for any changes...",className:"w-full bg-white/10 border border-white/20 rounded-2xl p-4 pr-12 text-sm outline-none focus:bg-white/20 placeholder:text-white/40 transition-all min-h-[100px] resize-none",disabled:Wt}),e.jsx("button",{onClick:ya,disabled:!Ht.trim()||Wt,className:"absolute bottom-3 right-3 w-10 h-10 rounded-xl bg-white text-purple-600 flex items-center justify-center shadow-lg disabled:opacity-50 disabled:scale-95 active:scale-90 transition-all",children:Wt?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(wl,{className:"w-4 h-4"})})]})]})]}),e.jsxs("div",{className:"p-6 rounded-3xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/10",children:[e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4 block",children:"Quick Refinements"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["Make it more professional","Add a benefits section","Change primary color to blue","Shorter headlines"].map(d=>e.jsx("button",{onClick:()=>{Ra(d)},className:"px-3 py-2 rounded-xl bg-white dark:bg-white/5 border border-black/5 dark:border-white/10 text-[10px] font-bold text-black/60 dark:text-white/60 hover:border-purple-500/50 hover:text-purple-500 transition-all",children:d},d))})]}),e.jsxs("div",{className:"mt-auto space-y-3",children:[e.jsxs("button",{onClick:()=>fe("published"),disabled:We,className:"w-full py-4 rounded-2xl bg-gradient-to-r from-emerald-500 to-teal-500 text-white flex items-center justify-center gap-3 text-sm font-black uppercase tracking-widest hover:shadow-2xl hover:shadow-emerald-500/20 active:scale-95 transition-all disabled:opacity-50 h-16",children:[We?e.jsx(V,{className:"w-5 h-5 animate-spin"}):e.jsx($s,{className:"w-5 h-5"}),"Publish Now"]}),e.jsxs("button",{onClick:()=>fe("draft"),disabled:We,className:"w-full py-4 rounded-2xl bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 flex items-center justify-center gap-3 text-sm font-bold hover:bg-black/5 dark:hover:bg-white/10 active:scale-95 transition-all text-black/60 dark:text-white/60",children:[e.jsx(Ct,{className:"w-4 h-4"})," Save as Draft"]}),e.jsx("div",{className:"pt-4 text-center",children:e.jsxs("button",{onClick:()=>{Ee({...A,id:-1,status:"draft",created_at:"",updated_at:""}),M("editor")},className:"text-[10px] font-black uppercase tracking-widest text-purple-500 hover:text-purple-400 flex items-center justify-center gap-2 mx-auto",children:["Open Detailed Editor ",e.jsx(Be,{className:"w-3 h-3"})]})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 pt-12",children:[e.jsx("div",{className:"lg:col-span-1 space-y-6",children:e.jsxs("div",{className:"p-8 rounded-[2rem] bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx(Ds,{className:"w-5 h-5 text-emerald-500"}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-emerald-600 dark:text-emerald-400",children:"SEO Footprint"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase font-black tracking-widest opacity-40 mb-1",children:"Search Title"}),e.jsx("div",{className:"text-sm font-bold text-blue-600 dark:text-blue-400",children:(A==null?void 0:A.ogTitle)||(A==null?void 0:A.title)||"Untitled Page"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase font-black tracking-widest opacity-40 mb-1",children:"Meta Description"}),e.jsx("div",{className:"text-xs text-black/60 dark:text-white/60 leading-relaxed",children:(A==null?void 0:A.metaDescription)||"No description generated."})]}),(A==null?void 0:A.seoKeywords)&&Array.isArray(A.seoKeywords)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase font-black tracking-widest opacity-40 mb-2",children:"Keywords"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:A.seoKeywords.map((d,$)=>e.jsx("span",{className:"px-2 py-0.5 rounded-lg bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 text-[10px] font-bold",children:d},$))})]})]})]})}),e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"p-8 rounded-[2rem] bg-white dark:bg-white/5 border border-black/5 dark:border-white/10",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(aa,{className:"w-5 h-5 text-purple-500"}),e.jsx("h4",{className:"text-lg font-black tracking-tight",children:"Structured Content"})]}),e.jsxs("span",{className:"px-3 py-1 rounded-full bg-black/5 dark:bg-white/5 text-[10px] font-black uppercase tracking-widest",children:[((Fa=A==null?void 0:A.sections)==null?void 0:Fa.length)||0," Blocks"]})]}),e.jsx("div",{className:"space-y-4",children:(A==null?void 0:A.sections)&&Array.isArray(A.sections)&&A.sections.map((d,$)=>{var I;return e.jsxs("div",{className:"group p-4 rounded-2xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5 hover:border-purple-500/30 transition-all flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white dark:bg-black/20 flex items-center justify-center text-xs font-black text-purple-500 shadow-sm",children:$+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"font-bold text-sm",children:((d==null?void 0:d.type)||"unknown").replace(/_/g," ").replace(/\b\w/g,F=>F.toUpperCase())}),e.jsx("div",{className:"text-[10px] text-black/40 dark:text-white/40 truncate mt-0.5",children:d!=null&&d.title?typeof d.title=="string"&&d.title.startsWith("t:")&&((I=A.translations)==null?void 0:I[d.title.slice(2)])||d.title:`Configured ${d==null?void 0:d.type} component`})]}),e.jsx("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx("div",{className:"w-8 h-8 rounded-lg bg-white dark:bg-white/10 flex items-center justify-center cursor-move",children:e.jsx(aa,{className:"w-3.5 h-3.5 opacity-40"})})})]},$)})})]})})]})]}),u==="published"&&A&&e.jsxs(ie.div,{initial:{opacity:0,scale:.95}
43,animate:{opacity:1,scale:1},className:"text-center py-16 space-y-6",children:[e.jsx("div",{className:"w-20 h-20 rounded-3xl bg-gradient-to-br from-emerald-500 to-teal-500 flex items-center justify-center mx-auto",children:e.jsx(Ce,{className:"w-10 h-10 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-3xl font-black mb-2",children:"Page Published! ð"}),e.jsxs("p",{className:"text-black/40 dark:text-white/40",children:["Your page is live at ",e.jsxs("code",{className:"px-2 py-1 rounded bg-black/5 dark:bg-white/5 font-mono text-teal-600 dark:text-teal-400",children:["/p/",A.slug]})]})]}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsxs("a",{href:`/p/${A.slug}`,target:"_blank",rel:"noopener noreferrer",className:"px-6 py-3 rounded-xl bg-teal-500 text-white font-bold flex items-center gap-2 hover:bg-teal-400 transition",children:[e.jsx(dl,{className:"w-4 h-4"})," View Page"]}),e.jsxs("button",{onClick:Kt,className:"px-6 py-3 rounded-xl bg-black/5 dark:bg-white/5 font-bold flex items-center gap-2 hover:bg-black/10 dark:hover:bg-white/10 transition",children:[e.jsx(es,{className:"w-4 h-4"})," Back to Pages"]})]})]}),u==="editor"&&xe&&e.jsxs(ie.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"flex-1 flex flex-col lg:flex-row gap-4 md:gap-6 w-full min-h-[600px] pb-4",children:[e.jsxs("div",{className:"w-full lg:w-[420px] h-[60vh] lg:h-full shrink-0 flex flex-col rounded-3xl md:rounded-[2.5rem] border border-black/10 dark:border-white/10 bg-white dark:bg-[#0a0a0a] overflow-hidden shadow-2xl relative transition-all duration-500",children:[e.jsx("div",{className:"px-6 pt-6 pb-4 shrink-0 bg-white dark:bg-[#0a0a0a] z-10",children:e.jsxs("div",{className:"flex p-1.5 rounded-2xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/10",children:[e.jsxs("button",{onClick:()=>ia("ai"),className:`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl text-xs font-black uppercase tracking-wider transition-all duration-300 ${wa==="ai"?"bg-purple-600 text-white shadow-lg shadow-purple-500/20 scale-[1.02]":"text-black/40 dark:text-white/40 hover:text-black dark:hover:text-white"}`,children:[e.jsx(fa,{className:"w-4 h-4"})," AI Agent"]}),e.jsxs("button",{onClick:()=>ia("html"),className:`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl text-xs font-black uppercase tracking-wider transition-all duration-300 ${wa==="html"?"bg-blue-600 text-white shadow-lg shadow-blue-500/20 scale-[1.02]":"text-black/40 dark:text-white/40 hover:text-black dark:hover:text-white"}`,children:[e.jsx(Gi,{className:"w-4 h-4"})," Source"]})]})}),e.jsx(yt,{mode:"wait",children:wa==="ai"?e.jsxs(ie.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20},className:"flex-1 flex flex-col min-h-0",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar flex flex-col",children:[e.jsx("div",{className:"flex-1 min-h-4"}),e.jsxs("div",{className:"space-y-4 mt-auto",children:[De.map((d,$)=>e.jsx("div",{className:`flex ${d.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[85%] rounded-[1.5rem] text-sm leading-relaxed shadow-sm transition-all hover:shadow-md ${d.role==="user"?"bg-gradient-to-br from-purple-500 to-indigo-600 text-white rounded-br-md px-5 py-4":"bg-black/5 dark:bg-white/[0.03] border border-black/5 dark:border-white/10 text-black/80 dark:text-white/80 rounded-bl-md px-5 py-4"}`,children:[e.jsx("span",{className:"whitespace-pre-wrap",children:d.content}),d.images&&d.images.length>0&&e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:d.images.map((I,F)=>e.jsxs("button",{onClick:()=>Vt(I),className:"block cursor-pointer group relative overflow-hidden rounded-xl border border-white/20",children:[e.jsx("img",{src:I.startsWith("/pages/")?`${m}${I}`:I,alt:"Generated",className:"w-full max-w-[200px] object-cover aspect-video group-hover:scale-110 transition-transform duration-500"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/40 transition flex items-center justify-center backdrop-blur-0 group-hover:backdrop-blur-[2px]",children:e.jsx(dl,{className:"w-5 h-5 text-white opacity-0 group-hover:opacity-100 transition drop-shadow-lg"})})]},F))})]})},$)),lt&&e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"px-5 py-4 rounded-[1.5rem] rounded-bl-md bg-black/5 dark:bg-white/[0.03] border border-black/5 dark:border-white/10 flex items-center gap-3 text-xs text-black/40 dark:text-white/40",children:[e.jsx(V,{className:"w-4 h-4 animate-spin text-purple-500"}),e.jsx("span",{children:"Analyzing request & generating assets..."})]})}),e.jsx("div",{ref:la})]})]}),e.jsxs("div",{className:"shrink-0 p-6 border-t border-black/5 dark:border-white/5 bg-white/50 dark:bg-black/20 backdrop-blur-xl",children:[e.jsx("input",{ref:Oa,type:"file",accept:"image/*",onChange:na,className:"hidden"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:()=>{var d;return(d=Oa.current)==null?void 0:d.click()},disabled:lt,className:"w-12 h-12 flex items-center justify-center rounded-2xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/10 hover:bg-purple-500/10 hover:border-purple-500/20 transition-all disabled:opacity-50 group",children:e.jsx(qo,{className:"w-5 h-5 text-black/40 dark:text-white/40 group-hover:text-purple-500"})}),e.jsxs("div",{className:"flex-1 relative group",children:[e.jsx("input",{type:"text",value:mt,onChange:d=>Qe(d.target.value),onKeyDown:d=>d.key==="Enter"&&wt(),placeholder:"e.g., Update the title to be warmer...",className:"w-full h-12 pl-5 pr-12 rounded-2xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 focus:border-purple-500 focus:bg-white dark:focus:bg-black outline-none text-sm transition-all",disabled:lt}),e.jsx("button",{onClick:()=>wt(),disabled:!mt.trim()||lt,className:`absolute right-1.5 top-1.5 w-9 h-9 flex items-center justify-center rounded-xl transition-all ${mt.trim()&&!lt?"bg-purple-600 text-white shadow-lg shadow-purple-500/30":"bg-black/10 dark:bg-white/10 text-black/30 dark:text-white/30"}`,children:e.jsx(wl,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-4",children:["Change background to dark","Make it more professional","Add a call to action"].map(d=>e.jsx("button",{onClick:()=>{Qe(d)},className:"px-3 py-1.5 rounded-xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/10 text-[10px] font-black uppercase tracking-wider text-black/40 dark:text-white/40 hover:bg-purple-500/10 hover:text-purple-600 dar
43k:hover:text-purple-400 hover:border-purple-500/20 transition-all",children:d},d))})]})]},"ai"):e.jsxs(ie.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:"flex-1 flex flex-col min-h-0 bg-[#0a0a0a] border-t border-white/10 relative",children:[e.jsxs("div",{className:"px-6 py-4 flex items-center justify-between border-b border-white/5 bg-black/40",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gi,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-[10px] font-black tracking-widest uppercase text-blue-500",children:"Raw JSON Source"})]}),e.jsx("span",{className:"text-[9px] text-white/30 uppercase",children:"Saves automatically on blur"})]}),e.jsx("div",{className:"flex-1 p-6 overflow-y-auto custom-scrollbar",children:e.jsx("textarea",{className:"w-full h-full min-h-[400px] bg-transparent text-emerald-400 font-mono text-xs leading-relaxed outline-none resize-none",defaultValue:(()=>{var d,$;try{return JSON.stringify(JSON.parse(((d=pt==null?void 0:pt.page)==null?void 0:d.page_json)||"{}"),null,2)}catch{return(($=pt==null?void 0:pt.page)==null?void 0:$.page_json)||""}})(),onBlur:async d=>{const $=d.target.value;ls(!0);try{const I=JSON.parse($);if((await fetch(`${m}/api/admin/pages/${xe.id}`,{method:"PATCH",headers:{"Content-Type":"application/json","x-admin-token":dt()},body:JSON.stringify({page_json:JSON.stringify(I)})})).ok&&(ds(xe.id),Ze.current)){const Ae=`/p/${xe.slug}?active_editor=true`;Ze.current.src=`${Ae}&_t=${Date.now()}`}}catch{alert("Invalid JSON structure. Please fix formatting before saving.")}ls(!1)},spellCheck:!1},(cs=pt==null?void 0:pt.page)==null?void 0:cs.id)}),_r&&e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-10",children:e.jsx(V,{className:"w-8 h-8 text-blue-500 animate-spin"})})]},"html")})]}),e.jsxs(ie.div,{layout:!0,className:`flex flex-col rounded-3xl md:rounded-[2.5rem] border border-black/10 dark:border-white/10 bg-white dark:bg-[#0a0a0a] overflow-hidden shadow-2xl transition-all duration-500 relative ${Me?"fixed inset-4 z-[100] m-0 self-auto":"flex-1 min-h-[500px] lg:h-full"}`,children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between px-4 md:px-6 py-3 md:py-4 bg-white dark:bg-[#0d0d0d] border-b border-black/5 dark:border-white/5 shrink-0 gap-3",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-400"})]}),e.jsxs("div",{className:"flex px-4 py-1.5 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 items-center gap-2 overflow-hidden",children:[e.jsx(St,{className:"w-3 h-3 text-black/30 dark:text-white/30 shrink-0"}),e.jsxs("span",{className:"text-[10px] md:text-[11px] font-mono text-black/40 dark:text-white/40 tracking-tight truncate",children:["emotionlogic.ai/p/",xe.slug]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-black/5 dark:bg-white/5 p-1 rounded-xl border border-black/5 dark:border-white/5 mr-2",children:[e.jsx("button",{onClick:()=>ht(Math.max(.25,at-.25)),className:"w-7 h-7 flex items-center justify-center text-[10px] font-bold hover:bg-black/10 dark:hover:bg-white/10 rounded-lg transition-colors",children:"ï¼"}),e.jsxs("span",{className:"min-w-[40px] text-center text-[10px] font-mono font-bold opacity-40",children:[Math.round(at*100),"%"]}),e.jsx("button",{onClick:()=>ht(Math.min(2,at+.25)),className:"w-7 h-7 flex items-center justify-center text-[10px] font-bold hover:bg-black/10 dark:hover:bg-white/10 rounded-lg transition-colors",children:"ï¼"})]}),e.jsx("button",{onClick:()=>ra(!Me),className:`w-9 h-9 md:w-10 md:h-10 rounded-xl flex items-center justify-center transition active:scale-[0.9] ${Me?"bg-emerald-500 text-white shadow-lg":"bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 text-black/40 dark:text-white/40"}`,title:Me?"Exit Fullscreen":"Fullscreen Preview",children:e.jsx(md,{className:"w-3.5 h-3.5 md:w-4 md:h-4"})}),e.jsx("button",{onClick:()=>{Ze.current&&(Ze.current.src=Ze.current.src)},className:"w-9 h-9 md:w-10 md:h-10 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 flex items-center justify-center transition group active:scale-[0.9]",title:"Reload Preview",children:e.jsx(tt,{className:"w-3.5 h-3.5 md:w-4 md:h-4 text-black/40 dark:text-white/40 group-hover:rotate-180 transition-transform duration-500"})}),e.jsx("button",{onClick:()=>window.open(`/p/${xe.slug}`,"_blank"),className:"w-9 h-9 md:w-10 md:h-10 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 flex items-center justify-center transition active:scale-[0.9]",title:"Open in new tab",children:e.jsx(sa,{className:"w-3.5 h-3.5 md:w-4 md:h-4 text-black/40 dark:text-white/40"})}),xe.status==="draft"&&e.jsxs("button",{onClick:()=>Fs(xe),disabled:We,className:"px-4 py-1.5 rounded-xl bg-amber-500 text-white text-[10px] font-black uppercase tracking-widest hover:bg-amber-400 hover:shadow-lg transition-all active:scale-[0.98] flex items-center gap-2 h-9 md:h-10",children:[We?e.jsx(V,{className:"w-3 h-3 animate-spin"}):e.jsx($s,{className:"w-3 h-3"}),"Publish Now"]})]})]}),e.jsx("div",{className:"flex items-center justify-center gap-1 md:gap-2 py-2 bg-gray-50/50 dark:bg-white/[0.01] border-b border-black/5 dark:border-white/5 shrink-0 overflow-x-auto",children:[{icon:Ot,label:"Desktop",width:"100%"},{icon:$r,label:"Tablet",width:"768px"},{icon:Is,label:"Mobile",width:"375px"}].map(d=>e.jsxs("button",{onClick:()=>{Ze.current&&(Ze.current.style.width=d.width,Ze.current.style.margin=d.width==="100%"?"0":"0 auto")},className:"px-2 md:px-3 py-1.5 rounded-xl text-[9px] md:text-[10px] font-black uppercase tracking-widest flex items-center gap-1 md:gap-1.5 hover:bg-black/5 dark:hover:bg-white/5 transition text-black/40 dark:text-white/40 whitespace-nowrap",children:[e.jsx(d.icon,{className:"w-3 h-3"})," ",d.label]},d.label))}),e.jsx("div",{className:"flex-1 bg-white/50 dark:bg-[#111] overflow-auto relative scrollbar-hide",children:e.jsx("div",{className:"transition-all duration-500 ease-out origin-top",style:{transform:`scale(${at})`,width:`${100/at}%`,height:`${100/at}%`},children:e.jsx("iframe",{ref:Ze,src:`/p/${xe.slug}?active_editor=true`,className:"w-full h-full border-0 bg-white shadow-inner",title:"Page Preview"})})}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-gray-50 dark:bg-white/[0.02] border-t border-black/5 dark:border-white/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-black/30 dark:text-white/30",children:"Live Preview"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-[10px] font-mono text-black/20 dark:text-white/20",children:xe.slug}),Me&&e.jsx("button",{onClick:()=>ra(!1),className:"text-[10px] font-black uppercase tracking-widest text-emerald-500 hover:text-emerald-400",children:"Exit Fullscreen"})]})]})]})]})]}),e.jsx(yt,{children:et&&e.jsx(ie.div,{initial:{opacity:0}
43,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[9999] bg-black/80 backdrop-blur-sm flex items-center justify-center p-8",onClick:()=>Vt(null),children:e.jsxs(ie.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.8,opacity:0},className:"relative max-w-4xl max-h-[85vh] flex flex-col items-center gap-4",onClick:d=>d.stopPropagation(),children:[e.jsx("img",{src:et.startsWith("/pages/")?`${m}${et}`:et,alt:"Full size preview",className:"max-w-full max-h-[75vh] rounded-2xl shadow-2xl border border-white/10 object-contain"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("a",{href:et,download:!0,className:"px-5 py-2.5 rounded-xl bg-white/10 hover:bg-white/20 text-white text-sm font-bold flex items-center gap-2 transition backdrop-blur-sm border border-white/10",onClick:d=>d.stopPropagation(),children:[e.jsx(es,{className:"w-4 h-4 rotate-90"})," Download"]}),e.jsxs("button",{onClick:()=>Vt(null),className:"px-5 py-2.5 rounded-xl bg-white/10 hover:bg-white/20 text-white text-sm font-bold flex items-center gap-2 transition backdrop-blur-sm border border-white/10",children:[e.jsx(kt,{className:"w-4 h-4"})," Close"]})]})]})})})]})};function Xd({settings:i,setSettings:p,onSettingsSave:u}){const[M,o]=r.useState(""),[B,g]=r.useState(!1),[_,S]=r.useState(""),[Q,P]=r.useState(""),[j,z]=r.useState(!1),G=async()=>{if(!i.higgsfieldApiKey){S("Please set the Higgsfield API key in the configuration first."),z(!0);return}if(!M.trim()){S("Please enter a script or prompt for the video.");return}g(!0),S(""),P("");try{const Z=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",re=await fetch(`${m}/api/admin/videos/generate`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":Z},body:JSON.stringify({prompt:M,characterImage:i.higgsfieldCharacterImage})}),Y=await re.json();re.ok?(P("Video generation task started. It will appear in your videos list once completed."),o("")):S(Y.error||"Failed to start video generation.")}catch{S("Network error or server unavailable.")}finally{g(!1)}};return e.jsxs("div",{className:"bg-white dark:bg-black/40 border border-black/5 dark:border-white/5 rounded-2xl p-6 mb-10 space-y-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-indigo-600 dark:text-indigo-400",children:[e.jsx(ts,{className:"w-5 h-5"})," AI Video Creator"]}),e.jsxs("button",{onClick:()=>z(!j),className:"text-xs flex items-center gap-1 text-black/50 dark:text-white/50 hover:text-indigo-500 transition",children:[e.jsx(Tr,{className:"w-4 h-4"})," Config"]})]}),e.jsx("p",{className:"text-sm text-black/60 dark:text-white/60 mb-4",children:"Use the Higgsfield MCP integration to generate professional videos featuring a consistent character speaking your script."}),j&&e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl p-4 mb-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-black/60 dark:text-white/60 uppercase tracking-wider mb-2",children:"Higgsfield API Key"}),e.jsx("input",{type:"password",value:i.higgsfieldApiKey||"",onChange:Z=>p({...i,higgsfieldApiKey:Z.target.value}),className:"w-full text-sm p-3 bg-white dark:bg-black border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500",placeholder:"sk-..."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-black/60 dark:text-white/60 uppercase tracking-wider mb-2",children:"Consistent Character Image URL"}),e.jsx("div",{className:"flex gap-2",children:e.jsx("input",{type:"text",value:i.higgsfieldCharacterImage||"",onChange:Z=>p({...i,higgsfieldCharacterImage:Z.target.value}),className:"flex-1 text-sm p-3 bg-white dark:bg-black border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500",placeholder:"https://..."})})]}),e.jsx("button",{onClick:u,className:"bg-indigo-600 hover:bg-indigo-700 text-white text-xs font-bold py-2 px-4 roun
43ded-lg transition",children:"Save Configuration"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("textarea",{value:M,onChange:Z=>o(Z.target.value),placeholder:"Enter the script for the AI character...",className:"w-full text-sm p-4 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 min-h-[120px] resize-y"}),_&&e.jsx("div",{className:"text-xs text-red-500 p-2 bg-red-500/10 rounded border border-red-500/20",children:_}),Q&&e.jsx("div",{className:"text-xs text-emerald-500 p-2 bg-emerald-500/10 rounded border border-emerald-500/20",children:Q}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:G,disabled:B,className:"bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-6 rounded-xl transition flex items-center gap-2 shadow-lg disabled:opacity-50",children:[B?e.jsx(V,{className:"w-5 h-5 animate-spin"}):e.jsx(hd,{className:"w-5 h-5"}),"Generate Video"]})})]})]})}function qd(){const[i,p]=r.useState(!1),[u,M]=r.useState(null),[o,B]=r.useState(null),[g,_]=r.useState(!1),[S,Q]=r.useState(""),[P,j]=r.useState("trim"),[z,G]=r.useState(0),[Z,re]=r.useState(100),[Y,K]=r.useState(0),[U,J]=r.useState(100),[de,b]=r.useState(100),[C,ne]=r.useState(100),[we,be]=r.useState(!1),[T,l]=r.useState([]),[f,le]=r.useState(!1),[O,q]=r.useState("br"),[Te,Oe]=r.useState("medium"),[Ye,Ge]=r.useState([]),Ke=r.useRef(null),nt=r.useRef(null),w=r.useRef([]),x=r.useRef(null),D=r.useRef(null),ae=r.useRef(null),je=r.useRef(null),Ue=async()=>{try{const A=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:{ideal:30}},audio:!0});let he=null;try{f?he=await navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280},height:{ideal:720}},audio:{echoCancellation:!0,noiseSuppression:!0}}):he=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}})}catch(_e){console.error("Mic/Webcam access denied:",_e)}const Ne=new AudioContext,He=Ne.createMediaStreamDestination();A.getAudioTracks().length>0&&Ne.createMediaStreamSource(new MediaStream([A.getAudioTracks()[0]])).connect(He),he&&he.getAudioTracks().length>0&&Ne.createMediaStreamSource(new MediaStream([he.getAudioTracks()[0]])).connect(He);let We=A.getVideoTracks()[0];if(f&&he&&x.current&&D.current&&ae.current){const _e=x.current,xe=D.current,Ee=ae.current,De=Ee.getContext("2d");_e.srcObject=A,xe.srcObject=he,await _e.play().catch(Qe=>console.error("Screen video play error:",Qe)),await xe.play().catch(Qe=>console.error("Webcam video play error:",Qe));const xt=()=>{if(De){if(Ee.width=_e.videoWidth||1920,Ee.height=_e.videoHeight||1080,Ee.width>0&&Ee.height>0){De.drawImage(_e,0,0,Ee.width,Ee.height);let Qe=.2;Te==="small"&&(Qe=.15),Te==="large"&&(Qe=.3);const lt=Ee.width*Qe,Je=xe.videoHeight/(xe.videoWidth||1)*lt,At=40;let Pt=Ee.width-At-lt/2,at=Ee.height-At-Je/2;O==="bl"&&(Pt=At+lt/2),O==="tr"&&(at=At+Je/2),O==="tl"&&(Pt=At+lt/2,at=At+Je/2);const ht=Math.min(lt,Je)/2;De.save(),De.beginPath(),De.arc(Pt,at,ht+5,0,Math.PI*2),De.fillStyle="#6366f1",De.fill(),De.beginPath(),De.arc(Pt,at,ht,0,Math.PI*2),De.clip();const Bt=Math.min(xe.videoWidth,xe.videoHeight),rs=(xe.videoWidth-Bt)/2,zt=(xe.videoHeight-Bt)/2;De.drawImage(xe,rs,zt,Bt,Bt,Pt-ht,at-ht,ht*2,ht*2),De.restore()}je.current=requestAnimationFrame(xt)}};xt(),We=Ee.captureStream(30).getVideoTracks()[0]}const rt=new MediaStream([We,...He.stream.getAudioTracks()]);nt.current=rt;const Tt=new MediaRecorder(rt,{mimeType:"video/webm; codecs=vp9"});w.current=[],Tt.ondataavailable=_e=>{_e.data.size>0&&w.current.push(_e.data)},Tt.onstop=()=>{const _e=new Blob(w.current,{type:"video/webm"}),xe=URL.createObjectURL(_e);B(xe),je.current&&cancelAnimationFrame(je.current),rt.getTracks().forEach(Ee=>Ee.stop()),he&&he.getTracks().forEach(Ee=>Ee.stop()),A.getTracks().forEach(Ee=>Ee.stop())},Tt.start(1e3),M(Tt),p(!0),B(null),A.getVideoTracks()[0].onended=()=>{ot()}}catch(A){console.error("Error starting recording:",A),alert("Could not start screen recording. Please make sure you granted permissions.")}},ot=()=>{u&&u.state!=="inactive"&&(u.stop(),p(!1))},E=()=>{Ke.current&&K(Ke.current.duration)},ge=()=>{be(!0),setTimeout(()=>{l([{time:"00:01 - 00:03",text:"Welcome to this demo recording."},{time:"00:04 - 00:06",text:"Here we will showcase the new features."}]),be(!1)},2500)},Ie=async()=>
43{if(w.current.length!==0){_(!0),Q("Applying edits and uploading...");try{const A=new Blob(w.current,{type:"video/webm"}),he=new FormData;he.append("video",A,`studio_recording_${Date.now()}.webm`),he.append("title",`Studio Recording ${new Date().toLocaleString()}`),he.append("edits",JSON.stringify({trimStart:z,trimEnd:Z,brightness:U,contrast:de,saturation:C,subtitles:T,higgsfieldEffects:Ye}));const Ne=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"";(await fetch(`${m}/api/admin/videos/upload`,{method:"POST",headers:{"x-admin-token":Ne},body:he})).ok?(Q("Upload & Render successful!"),setTimeout(()=>{Fe()},3e3)):Q("Upload failed.")}catch(A){console.error(A),Q("Network error.")}finally{_(!1)}}},Fe=()=>{o&&URL.revokeObjectURL(o),B(null),w.current=[],l([]),J(100),b(100),ne(100),G(0),re(100),Ge([])};return e.jsxs("div",{className:"bg-white dark:bg-[#0a0a0a] border border-black/5 dark:border-white/5 rounded-2xl overflow-hidden mb-10 shadow-xl",children:[e.jsxs("div",{className:"p-6 border-b border-black/5 dark:border-white/5 bg-gradient-to-r from-indigo-500/5 to-purple-500/5",children:[e.jsxs("h3",{className:"text-2xl font-black flex items-center gap-3 text-transparent bg-clip-text bg-gradient-to-r from-indigo-600 to-purple-600 dark:from-indigo-400 dark:to-purple-400",children:[e.jsx(ye,{className:"w-6 h-6 text-indigo-500"})," EMLO Video Studio"]}),e.jsx("p",{className:"text-sm text-black/60 dark:text-white/60 mt-2 font-medium",children:"Record, trim, enhance, and subtitle your video presentations using AI."})]}),e.jsx("div",{className:"p-6",children:o?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{className:"rounded-2xl overflow-hidden bg-black aspect-video border border-black/10 dark:border-white/10 shadow-2xl relative group",children:[e.jsx("video",{ref:Ke,src:o,controls:!0,onLoadedMetadata:E,className:"w-full h-full object-contain transition-all duration-300",style:{filter:`brightness(${U}%) contrast(${de}%) saturate(${C}%)`}}),T.length>0&&e.jsx("div",{className:"absolute bottom-16 left-0 right-0 flex justify-center pointer-events-none",children:e.jsxs("div",{className:"bg-black/80 backdrop-blur-sm text-white px-6 py-2 rounded-lg border border-white/10 text-lg font-bold shadow-2xl",children:[T[0].text," "]})})]}),e.jsxs("div",{className:"bg-black/5 dark:bg-white/5 rounded-2xl p-6 border border-black/5 dark:border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"font-bold flex items-center gap-2",children:[e.jsx(pd,{className:"w-4 h-4 text-indigo-500"})," Timeline Trimmer"]}),e.jsxs("span",{className:"text-xs font-mono font-bold text-black/50 dark:text-white/50",children:[Y.toFixed(1),"s Total"]})]}),e.jsxs("div",{className:"relative h-16 bg-black/10 dark:bg-black/50 rounded-xl overflow-hidden border border-black/10 dark:border-white/10 cursor-ew-resize",children:[e.jsx("div",{className:"absolute top-0 bottom-0 left-0 bg-black/40 backdrop-blur-sm z-10",style:{width:`${z}%`}}),e.jsx("div",{className:"absolute top-0 bottom-0 right-0 bg-black/40 backdrop-blur-sm z-10",style:{width:`${100-Z}%`}}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-between px-2 opacity-30",children:Array.from({length:40}).map((A,he)=>e.jsx("div",{className:"w-1 bg-indigo-500 rounded-full",style:{height:`${Math.random()*80+20}%`}},he))}),e.jsx("div",{className:"absolute top-0 bottom-0 w-3 bg-indigo-500 rounded-full z-10 shadow-[0_0_10px_rgba(99,102,241,0.5)] cursor-ew-resize transform -translate-x-1.5 flex items-center justify-center pointer-events-none",style:{left:`${z}%`},children:e.jsx("div",{className:"w-1 h-4 bg-white/50 rounded-full"})}),e.jsx("div",{className:"absolute top-0 bottom-0 w-3 bg-indigo-500 rounded-full z-10 shadow-[0_0_10px_rgba(99,102,241,0.5)] cursor-ew-resize transform translate-x-1.5 flex items-center justify-center pointer-events-none",style:{right:`${100-Z}%`},children:e.jsx("div",{className:"w-1 h-4 bg-white/50 rounded-full"})}),e.jsx("input",{type:"range",min:"0",max:Z-1,value:z,onChange:A=>G(Number(A.target.value)),className:"absolute inset-0 w-full h-full opacity-0 z-20 cursor-ew-resize"}),e.jsx("input",{type:"range",min:z+1,max:"100",value:Z,onChange:A=>re(Number(A.target.value)),className:"absolute inset-0 w-full h-full opacity-0 z-20 cursor-ew-resize"})]}),e.jsxs("div",{className:"flex justify-between mt-2 text-xs font-bold text-indigo-600 dark:text-indigo-400 font-mono",children:[e.jsxs("span",{children:[(Y*(z/100)).toFixed(1),"s"]}),e.jsxs("span",{children:[(Y*(Z/100)).toFixed(1),"s"]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex p-1 bg-black/5 dark:bg-white/5 rounded-xl",children:[e.jsx("button",{onClick:()=>j("trim"),className:`flex-1 py-2 text-sm font-bold rounded-lg transition ${P==="trim"?"bg-white dark:bg-[#1a1a1a] shadow text-indigo-600 dark:text-indigo-400":"text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white"}`,children:"Timeline"}),e.jsx("button",{onClick:()=>j("effects"),className:`flex-1 py-2 text-sm font-bold rounded-lg transition ${P==="effects"?"bg-white dark:bg-[#1a1a1a] shadow text-indigo-600 dark:text-indigo-400":"text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white"}`,children:"Effects"}),e.jsx("button",{onClick:()=>j("ai"),className:`flex-1 py-2 text-sm font-bold rounded-lg transition ${P==="ai"?"bg-white dark:bg-[#1a1a1a] shadow text-purple-600 dar
43k:text-purple-400":"text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white"}`,children:"AI Subtitles"}),e.jsx("button",{onClick:()=>j("higgsfield"),className:`flex-1 py-2 text-sm font-bold rounded-lg transition ${P==="higgsfield"?"bg-white dark:bg-[#1a1a1a] shadow text-pink-600 dark:text-pink-400":"text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white"}`,children:"Higgsfield"})]}),e.jsxs("div",{className:"bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-5 min-h-[300px] max-h-[500px] overflow-y-auto",children:[P==="trim"&&e.jsx("div",{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-black/60 dark:text-white/60",children:"Drag the edges of the timeline to trim the start and end of your video. The server will cut the video flawlessly during rendering."})}),P==="effects"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs font-bold mb-2",children:[e.jsx("span",{children:"Brightness"}),e.jsxs("span",{children:[U,"%"]})]}),e.jsx("input",{type:"range",min:"50",max:"150",value:U,onChange:A=>J(Number(A.target.value)),className:"w-full accent-indigo-500"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs font-bold mb-2",children:[e.jsx("span",{children:"Contrast"}),e.jsxs("span",{children:[de,"%"]})]}),e.jsx("input",{type:"range",min:"50",max:"150",value:de,onChange:A=>b(Number(A.target.value)),className:"w-full accent-indigo-500"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs font-bold mb-2",children:[e.jsx("span",{children:"Saturation"}),e.jsxs("span",{children:[C,"%"]})]}),e.jsx("input",{type:"range",min:"0",max:"200",value:C,onChange:A=>ne(Number(A.target.value)),className:"w-full accent-indigo-500"})]}),e.jsx("button",{onClick:()=>{J(100),b(100),ne(100)},className:"text-xs font-bold text-indigo-500 hover:text-indigo-600",children:"Reset Defaults"})]}),P==="ai"&&e.jsxs("div",{className:"space-y-4 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-purple-500/10 text-purple-500 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(Ko,{className:"w-8 h-8"})}),e.jsx("p",{className:"text-sm text-black/60 dark:text-white/60 mb-6",children:"Automatically transcribe audio and generate cinematic subtitles perfectly synced with the video."}),e.jsxs("button",{onClick:ge,disabled:we||T.length>0,className:"w-full bg-purple-600 hover:bg-purple-700 text-white py-3 rounded-xl font-bold flex items-center justify-center gap-2 transition disabled:opacity-50",children:[we?e.jsx(V,{className:"w-5 h-5 animate-spin"}):e.jsx(ts,{className:"w-5 h-5"}),we?"Transcribing...":T.length>0?"Subtitles Applied":"Auto-Generate Subtitles"]}),T.length>0&&e.jsx("div",{className:"mt-6 text-left border border-white/10 rounded-lg p-3 max-h-[150px] overflow-y-auto bg-black/20",children:T.map((A,he)=>e.jsxs("div",{className:"mb-2 last:mb-0",children:[e.jsx("div",{className:"text-[10px] font-mono text-purple-400 mb-0.5",children:A.time}),e.jsx("div",{className:"text-xs text-white/80",children:A.text})]},he))})]}),P==="higgsfield"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"w-16 h-16 bg-pink-500/10 text-pink-500 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(ts,{className:"w-8 h-8"})}),e.jsx("p",{className:"text-sm font-bold text-pink-600 dark:text-pink-400 mb-2",children:"Higgsfield AI Video Enhancements"}),e.jsx("p",{className:"text-xs text-black/60 dark:text-white/60",children:"Select advanced AI effects to apply to your video during the final rendering process."})]}),e.jsx("div",{className:"space-y-3",children:[{id:"character_swap",title:"Character Swap (Image-to-Video)",desc:"Replace the speaker with your Consistent Character Reference."},{id:"stylization",title:"Cinematic Stylization",desc:"Apply Video-to-Video filters to make the recording look like a professional studio shot."},{id:"b_roll",title:"Auto B-Roll Generation",desc:"Read subtitles and inject AI-generated B-roll clips automatically."},{id:"motion_brush",title:"Motion Brushes",desc:"Animate static background elements in your screen share dynamically."},{id:"inpainting",title:"AI Inpainting / Cleanup",desc:"Automatically remove messy backgrounds or sensitive onscreen data."}].map(A=>{const he=Ye.includes(A.id);return e.jsxs("div",{onClick:()=>Ge(Ne=>Ne.includes(A.id)?Ne.filter(He=>He!==A.id):[...Ne,A.id]),className:`p-4 rounded-xl cursor-pointer transition-all border ${he?"bg-pink-50 dark:bg-pink-900/20 border-pink-500 shadow-md scale-[1.02]":"bg-white dark:bg-black/40 border-black/10 dark:border-white/10 hover:border-pink-300"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("h5",{className:`text-sm font-bold ${he?"text-pink-700 dark:text-pink-400":"text-black dark:text-white"}`,children:A.title}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center ${he?"border-pink-500 bg-pink-500":"border-black/20 dark:border-white/20"}`,children:he&&e.jsx("div",{className:"w-1.5 h-1.5 bg-white rounded-full"})})]}),e.jsx("p",{className:"text-[10px] text-black/50 dark:text-white/50 leading-relaxed",children:A.desc})]},A.id)})})]})]}),e.jsxs("div",{className:"pt-4 space-y-3",children:[S&&e.jsx("div",{className:"text-sm font-bold text-center text-emerald-500 bg-emerald-500/10 py-2 rounded-lg",children:S}),e.jsxs("button",{onClick:Ie,disabled:g,className:"w-full bg-emerald-500 hover:bg-emerald-600 text-white py-4 rounded-xl font-black uppercase tracking-widest flex items-center justify-center gap-3 transition-all hover:scale-[1.02] hover:shadow-[0_0_20px_rgba(16,185,129,0.3)] disabled:opacity-50",children:[g?e.jsx(V,{className:"w-6 h-6 animate-spin"}):e.jsx(Ct,{className:"w-6 h-6"}
43),g?"Rendering Video...":"Render & Save to Library"]}),e.jsxs("button",{onClick:Fe,className:"w-full py-3 text-red-500 hover:bg-red-500/10 rounded-xl font-bold transition flex items-center justify-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4"})," Discard Project"]})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 border-2 border-dashed border-indigo-500/20 rounded-2xl bg-indigo-50/50 dark:bg-indigo-900/10",children:[i?e.jsxs("div",{className:"flex flex-col items-center gap-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 bg-red-500 rounded-full animate-ping opacity-20 scale-150"}),e.jsx("div",{className:"w-24 h-24 bg-red-500/10 rounded-full flex items-center justify-center border-4 border-red-500/30",children:e.jsx("div",{className:"w-12 h-12 bg-red-500 rounded-full animate-pulse shadow-[0_0_20px_rgba(239,68,68,0.5)]"})})]}),e.jsx("span",{className:"font-bold text-red-500 text-lg tracking-widest uppercase",children:"Recording Live"}),e.jsxs("button",{onClick:ot,className:"mt-4 bg-red-500 hover:bg-red-600 text-white px-8 py-4 rounded-xl font-black uppercase tracking-widest flex items-center gap-3 transition-all hover:scale-105 hover:shadow-[0_0_30px_rgba(239,68,68,0.3)]",children:[e.jsx(Rd,{className:"w-6 h-6"})," Stop & Edit"]})]}):e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs("button",{onClick:Ue,className:"bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white px-10 py-5 rounded-2xl font-black text-lg flex items-center gap-4 transition-all hover:scale-105 hover:shadow-[0_0_40px_rgba(99,102,241,0.4)]",children:[e.jsx(Es,{className:"w-6 h-6"})," Initialize Recorder"]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer mt-4 bg-white dark:bg-black/20 px-6 py-3 rounded-full border border-black/10 dark:border-white/10 shadow-sm hover:border-indigo-500 transition",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:A=>le(A.target.checked),className:"w-5 h-5 rounded text-indigo-600 focus:ring-indigo-500"}),e.jsx("span",{className:"text-sm font-bold text-black/70 dark:text-white/70",children:"Enable Picture-in-Picture Webcam"})]}),f&&e.jsxs("div",{className:"flex gap-4 mt-2",children:[e.jsxs("select",{value:O,onChange:A=>q(A.target.value),className:"bg-white dark:bg-[#1a1a1a] border border-black/10 dark:border-white/10 rounded-lg px-3 py-2 text-sm font-bold text-black/80 dark:text-white/80 focus:ring-2 focus:ring-indigo-500 focus:outline-none",children:[e.jsx("option",{value:"br",children:"Bottom Right"}),e.jsx("option",{value:"bl",children:"Bottom Left"}),e.jsx("option",{value:"tr",children:"Top Right"}),e.jsx("option",{value:"tl",children:"Top Left"})]}),e.jsxs("select",{value:Te,onChange:A=>Oe(A.target.value),className:"bg-white dark:bg-[#1a1a1a] border border-black/10 dark:border-white/10 rounded-lg px-3 py-2 text-sm font-bold text-black/80 dark:text-white/80 focus:ring-2 focus:ring-indigo-500 focus:outline-none",children:[e.jsx("option",{value:"small",children:"Small"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"large",children:"Large"})]})]})]}),e.jsx("video",{ref:x,muted:!0,playsInline:!0,className:"opacity-0 absolute pointer-events-none w-1 h-1"}),e.jsx("video",{ref:D,muted:!0,playsInline:!0,className:"opacity-0 absolute pointer-events-none w-1 h-1"}),e.jsx("canvas",{ref:ae,className:"opacity-0 absolute pointer-events-none w-1 h-1"})]})})]})}const Yd=[{id:"desk",label:"Agency Desk",icon:ss},{id:"budget",label:"Budget",icon:gn},{id:"brand",label:"Brand",icon:yl},{id:"connections",label:"Connections",icon:un},{id:"approvals",label:"Approvals",icon:on}];function Ft(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function vt(i,p="USD"){return new Intl.NumberFormat("en-US",{style:"currency",currency:p,maximumFractionDigits:0}).format(Number(i||0))}function Ka(i){return i.split(` 44`).map(p=>p.trim()).filter(Boolean)}const Qa="h-12 w-full rounded-2xl border border-white/10 bg-black/35 px-4 text-sm font-bold text-white outline-none transition placeholder:text-white/25 focus:border-teal-200/50",ta="w-full resize-none rounded-2xl border border-white/10 bg-black/35 px-4 py-3 text-sm font-semibold leading-6 text-white outline-none transition placeholder:text-white/25 focus:border-teal-200/50";function Qd({initialTab:i="desk",navigationRequest:p=0}){var nt,w;const[u,M]=r.useState(i),[o,B]=r.useState(null),[g,_]=r.useState(null),[S,Q]=r.useState(null),[P,j]=r.useState(""),[z,G]=r.useState(""),[Z,re]=r.useState(""),[Y,K]=r.useState([]),[U,J]=r.useState(null),[de,b]=r.useState(null),[C,ne]=r.useState(""),[we,be]=r.useState("Emotion Logic"),[T,l]=r.useState("Owned for Emotion Logic marketing use"),f=async()=>{G("");try{const[x,D]=await Promise.all([fetch(`${m}/api/admin/advertising/agency/overview`,{credentials:"include",headers:Ft()}),fetch(`${m}/api/admin/advertising/creative-studio`,{credentials:"include",headers:Ft()})]),ae=await x.json().catch(()=>({})),je=await D.json().catch(()=>({}));if(!x.ok)throw new Error(ae.error||"Could not load the agency de
44sk.");B(ae),_(ae.budget.plan),Q(ae.brand.profile),D.ok&&K(je.assets||[])}catch(x){G(x instanceof Error?x.message:"Could not load the agency desk.")}};r.useEffect(()=>{f()},[]),r.useEffect(()=>{M(i)},[i,p]);const le=async()=>{if(g){j("budget"),G(""),re("");try{const x=await fetch(`${m}/api/admin/advertising/agency/budget`,{method:"PUT",credentials:"include",headers:Ft(),body:JSON.stringify({monthlyCeiling:g.monthlyCeiling,currency:g.currency,status:"approved"})}),D=await x.json().catch(()=>({}));if(!x.ok)throw new Error(D.error||"Budget authority was not saved.");re("Monthly ceiling approved. The agency calculated every planning assumption and project allocation automatically. Publishing still requires campaign approval."),await f()}catch(x){G(x instanceof Error?x.message:"Budget authority was not saved.")}finally{j("")}}},O=async()=>{var x;if(S){j("brand"),G(""),re("");try{const D=await fetch(`${m}/api/admin/advertising/agency/brand`,{method:"PUT",credentials:"include",headers:Ft(),body:JSON.stringify({...S,status:"approved"})}),ae=await D.json().catch(()=>({}));if(!D.ok)throw new Error(ae.error||"Brand truth was not saved.");Q(ae.profile),re(`${((x=ae.review)==null?void 0:x.summary)||"AI spelling, grammar, tone and claim review completed."} Brand truth is approved for future agency work.`),await f()}catch(D){G(D instanceof Error?D.message:"Brand truth was not saved.")}finally{j("")}}},q=async(x,D)=>{j(`approval-${x}`),G(""),re("");try{const ae=await fetch(`${m}/api/admin/advertising/agency/approvals/${x}`,{method:"PATCH",credentials:"include",headers:Ft(),body:JSON.stringify({decision:D})}),je=await ae.json().catch(()=>({}));if(!ae.ok)throw new Error(je.error||"The management decision was not recorded.");re(`Work ${D}. The decision is now in the agency audit ledger.`),await f()}catch(ae){G(ae instanceof Error?ae.message:"The management decision was not recorded.")}finally{j("")}},Te=async()=>{j("advisor"),G(""),re("");try{const x=await fetch(`${m}/api/admin/advertising/creative-studio/brand-advice`,{method:"POST",credentials:"include",headers:Ft(),body:"{}"}),D=await x.json().catch(()=>({}));if(!x.ok)throw new Error(D.error||"The AI brand review could not be completed.");J(D.review),re("AI brand review completed. Suggestions remain advisory until you edit and approve the brand truth.")}catch(x){G(x instanceof Error?x.message:"The AI brand review could not be completed.")}finally{j("")}},Oe=async x=>{if(x.preventDefault(),!!de){j("asset"),G(""),re("");try{const D=new FormData;D.set("file",de),D.set("name",C||de.name),D.set("rightsOwner",we),D.set("licenseTerms",T),D.set("sourceKind","uploaded"),D.set("consentStatus","not_applicable");const ae=sessionStorage.getItem("adminToken"),je=await fetch(`${m}/api/admin/advertising/creative-studio/assets/upload`,{method:"POST",credentials:"include",headers:ae?{"X-Admin-Token":ae}:{},body:D}),Ue=await je.json().catch(()=>({}));if(!je.ok)throw new Error(Ue.error||"The asset could not be uploaded.");b(null),ne(""),re("Asset validated and saved as a governed draft. Approve it only after reviewing rights and consent."),await f()}catch(D){G(D instanceof Error?D.message:"The asset could not be uploaded.")}finally{j("")}}},Ye=r.useMemo(()=>o?[o.budget.status==="approved",o.brand.status==="approved",o.connections.some(x=>x.configured)].filter(Boolean).length:0,[o]),Ge=r.useMemo(()=>{var x;return(((x=o==null?void 0:o.performance)==null?void 0:x.providers)||[]).reduce((D,ae)=>({impressions:D.impressions+ae.impressions,clicks:D.clicks+ae.clicks,spend:D.spend+ae.spend,conversions:D.conversions+ae.conversions,conversionValue:D.conversionValue+ae.conversionValue}),{impressions:0,clicks:0,spend:0,conversions:0,conversionValue:0})},[o]),Ke=r.useMemo(()=>{var x;return(((x=o==null?void 0:o.performance)==null?void 0:x.feedback)||[]).reduce((D,ae)=>D+ae.count,0)},[o]);return!o||!g||!S?e.jsx("section",{className:"rounded-3xl border border-white/10 bg-white/[0.04] p-8",children:z?e.jsx("p",{className:"font-bold text-rose-200",children:z}):e.jsx(V,{className:"h-6 w-6 animate-spin text-teal-200"})}):e.jsxs("section",{className:"overflow-hidden rounded-[2rem] border border-teal-200/15 bg-gradient-to-br from-[#0b1512] via-[#080b09] to-[#101508] shadow-2xl shadow-black/35",children:[e.jsxs("div",{className:"border-b border-white/10 px-5 py-5 lg:px-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-teal-200 to-lime-200 text-black",children:e.jsx(ss,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.24em] text-teal-100/60",children:"Management layer"}),e.jsx("h2",{className:"mt-1 text-2xl font-black",children:"Your AI Advert
44ising Agency"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/55",children:o.agency.promise})]})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-white/10 bg-black/25 px-4 py-3",children:[e.jsx(qe,{className:"h-5 w-5 text-lime-200"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black",children:"Approval-controlled"}),e.jsxs("p",{className:"mt-0.5 text-xs font-bold text-white/40",children:[Ye,"/3 foundations ready"]})]})]})]}),e.jsx("div",{className:"mt-5 flex gap-2 overflow-x-auto pb-1",children:Yd.map(x=>{const D=x.icon;return e.jsxs("button",{onClick:()=>{M(x.id),G(""),re("")},className:`inline-flex h-11 shrink-0 items-center gap-2 rounded-full px-4 text-sm font-black transition ${u===x.id?"bg-white text-black":"border border-white/10 bg-white/[0.035] text-white/55 hover:text-white"}`,children:[e.jsx(D,{className:"h-4 w-4"}),x.label,x.id==="approvals"&&o.approvals.length>0?e.jsx("span",{className:"rounded-full bg-rose-500 px-2 py-0.5 text-xs text-white",children:o.approvals.length}):null]},x.id)})})]}),e.jsxs("div",{className:"p-5 lg:p-7",children:[z&&e.jsx("div",{className:"mb-5 rounded-2xl border border-rose-400/25 bg-rose-500/10 px-4 py-3 text-sm font-bold text-rose-100",children:z}),Z&&e.jsx("div",{className:"mb-5 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 px-4 py-3 text-sm font-bold text-emerald-100",children:Z}),u==="desk"&&e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[1.15fr_0.85fr]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-5 grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[["30-day spend",vt(Ge.spend)],["Paid clicks",Ge.clicks.toLocaleString()],["Platform conversions",Ge.conversions.toLocaleString()],["Verified feedback",Ke.toLocaleString()]].map(([x,D])=>e.jsxs("div",{className:"rounded-2xl border border-lime-200/10 bg-lime-200/[0.04] p-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/35",children:x}),e.jsx("p",{className:"mt-3 text-2xl font-black text-lime-50",children:D})]},x))}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:o.agency.roles.map(x=>e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-4",children:[e.jsx(Er,{className:"h-4 w-4 text-teal-200"}),e.jsx("p",{className:"mt-3 text-sm font-black",children:x}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/38",children:"AI talent · supervised"})]},x))})]}),e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-white/35",children:"Agency activity"}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:"Latest work"})]}),e.jsx(Ut,{className:"h-5 w-5 text-lime-200"})]}),e.jsx("div",{className:"mt-4 space-y-3",children:o.activity.length?o.activity.slice(0,6).map(x=>e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-white/[0.025] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs font-black text-teal-100/75",children:x.role_name}),e.jsx("span",{className:"text-xs font-bold text-white/25",children:x.created_at})]}),e.jsx("p",{className:"mt-1 text-sm font-bold",children:x.title}),x.detail_safe&&e.jsx("p",{className:"mt-1 text-xs font-semibold leading-5 text-white/40",children:x.detail_safe})]},x.id)):e.jsx("p",{className:"rounded-2xl border border-dashed border-white/10 p-5 text-sm font-bold text-white/35",children:"The ledger will record research, strategy, creation, approvals, publishing, synchronization, and learning."})})]})]}),u==="budget"&&e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[1fr_0.72fr]",children:[e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.18em] text-white/35",children:"Your only budget decision"}),e.jsx("h3",{className:"mt-2 text-xl font-black",children:"Set the total monthly ceiling"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm font-semibold leading-6 text-white/48",children:"The agency automatically calculates conservative assumptions, channel allocations, project test budgets and stop rules. It will never exceed this ceiling."}),e.jsxs("div",{className:"mt-6 grid gap-4 sm:grid-cols-[130px_1fr]",children:[e.jsxs("label",{className:"text-sm font-black text-white/55",children:["Currency",e.jsxs("select",{value:g.currency,onChange:x=>_({...g,currency:x.target.value}),className:`${Qa} mt-2`,children:[e.jsx("option",{value:"USD",children:"USD"}),e.jsx("option",{value:"EUR",children:"EUR"}),e.jsx("option",{value:"ILS",children:"ILS"}),e.jsx("option",{value:"GBP",children:"GBP"})]})]}),e.jsxs("label",{className:"text-sm font-black text-white/55",children:["Monthly ceiling",e.jsx("input",{type:"number",min:"1",step:"100",value:g.monthlyCeiling||"",onChange:x=>_({...g,monthlyCeiling:Number(x.target.value)}),placeholder:"For example: 5,000",className:`${Qa} mt-2 text-lg`})]})]}),e.jsxs("button",{onClick:le,disabled:P==="budget"||g.monthlyCeiling<=0,className:"mt-5 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-gradient-to-r from-blue-500 to-pink-500 px-5 text-base font-black text-white disabled:opacity-40",children:[P==="budget"?e.jsx(V,{className:"h-5 w-5 animate-spin"}):e.jsx(Ce,{className:"h-5 w-5"}),"Approve Monthly Ceiling"]}),e.jsxs("div",{className:"mt-5 rounded-2xl border border-blue-300/15 bg-blue-300/[0.05] p-4",children:[e.jsx("p",{className:"text-sm font-black",children:"Automatically supplied by the agency"}),e.jsxs("div",{className:"mt-3 grid gap-2 text-sm font-semibold text-white/48 sm:grid-cols-2",children:[e.jsxs("p",{children:["Expected contract value: ",vt(g.averageContractValue,g.currency)]}),e.jsxs("p",{children:["Conservative gross margin: ",g.grossMarginPercent,"%"]}),e.jsxs("p",{children:["Qualified lead conversion: ",g.leadToCustomerPercent,"%"]}),e.jsxs("p",{children:["Risk mode: ",g.riskMode]}),e.jsxs("p",{children:["Target customers: ",g.targetCustomers]}),e.jsxs("p",{children:["Sales capacity assumption: ",g.salesCapacity]})]}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-5 text-blue-100/65",children:"These are planning defaultsânot business claims. Verified campaign and lead outcomes refine them over time."})]})]}),e.jsxs("div",{className:"rounded-3xl border border-lime-200/15 bg-lime-200/[0.055] p-5",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-lime-100/55",children:"Economic guardrail"}),e.jsx("h3",{className:"mt-1 text-xl font-black",children:"Recommended ceiling"}),e.jsx("p",{className:"mt-5 text-4xl font-black text-lime-100",children:vt(o.budget.projection.recommendedMonthlyBudget,g.currency)}),e.jsxs("div",{className:"mt-5 space-y-3 text-sm font-bold",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/45",children:"Maximum CAC"}),e.jsx("span",{children:vt(o.budget.projection.maxCac,g.currency)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/45",children:"Maximum qualified lead cost"}),e.jsx("span",{children:vt(o.budget.projection.maxQualifiedLeadCost,g.currency)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-white/45",children:"Economics-led budget"}),e.jsx("span",{children:vt(o.budget.projection.economicsBudget,g.currency)})]})]}),e.jsxs("div",{className:"mt-5 rounded-2xl border border-white/10 bg-black/20 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs font-black",children:[e.jsx("span",{className:"text-white/45",children:"Imported 30-day spend"}),e.jsx("span",{children:vt(Ge.spend,g.currency)})]}),e.jsx("div",{className:"mt-3 h-2 overflow-hidden rounded-full bg-white/8",children:e.jsx("div",{className:`h-full rounded-full ${Ge.spend>g.monthlyCeiling&&g.monthlyCeiling>0?"bg-rose-400":"bg-lime-200"}`,style:{width:`${Math.min(100,g.monthlyCeiling?Ge.spend/g.monthlyCeiling*100:0)}%`}})}),e.jsx("p",{className:"mt-2 text-xs font-bold text-white/35",children:g.monthlyCeiling?`${vt(Math.max(0,g.monthlyCeiling-Ge.spend),g.currency)}
44 authority remaining`:"Approve a ceiling before comparing imported spend."})]}),e.jsxs("div",{className:"mt-5 space-y-2",children:[o.budgetAllocation.allocations.map(x=>e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-xs font-black uppercase text-white/55",children:x.provider.replaceAll("_"," ")}),e.jsxs("span",{className:"text-sm font-black",children:[vt(x.dailyBudget,g.currency),"/day"]})]}),e.jsxs("p",{className:"mt-1 text-xs font-semibold text-white/35",children:[vt(x.monthlyBudget,g.currency)," monthly · ",x.basis]})]},x.provider)),e.jsx("div",{className:"rounded-2xl border border-fuchsia-200/10 bg-fuchsia-200/[0.04] p-3",children:e.jsxs("div",{className:"flex justify-between text-xs font-black",children:[e.jsx("span",{children:"Experiment reserve"}),e.jsx("span",{children:vt(o.budgetAllocation.experimentReserve,g.currency)})]})})]}),e.jsx("p",{className:"mt-5 rounded-2xl border border-emerald-300/15 bg-emerald-300/[0.06] p-3 text-sm font-bold leading-5 text-emerald-100",children:"Project budgets are generated automatically inside this cap and remain advisory until you approve a finished campaign."})]})]}),u==="brand"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[1fr_0.72fr]",children:[e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.18em] text-white/35",children:"Canonical identity"}),e.jsx("h3",{className:"mt-1 text-xl font-black",children:"What the entire agency must know"}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-5 text-white/42",children:"Edit freely. Every save is checked by AI for spelling, grammar, professional tone and risky claims before it reaches the agency."}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsx("input",{value:S.companyName,onChange:x=>Q({...S,companyName:x.target.value}),placeholder:"Company name",className:Qa}),e.jsx("textarea",{rows:3,value:S.shortDescription,onChange:x=>Q({...S,shortDescription:x.target.value}),placeholder:"Short description",className:ta}),e.jsx("textarea",{rows:5,value:S.brandStory,onChange:x=>Q({...S,brandStory:x.target.value}),placeholder:"Brand story",className:ta}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("textarea",{rows:4,value:S.audiences.join(` 45`),onChange:x=>Q({...S,audiences:Ka(x.target.value)}),placeholder:"Audiences â one per line",className:ta}),e.jsx("textarea",{rows:4,value:S.voiceTraits.join(` 46`),onChange:x=>Q({...S,voiceTraits:Ka(x.target.value)}),placeholder:"Voice traits â one per line",className:ta}),e.jsx("textarea",{rows:4,value:S.slogans.join(` 47`),onChange:x=>Q({...S,slogans:Ka(x.target.value)}),placeholder:"Slogans â one per line",className:ta}),e.jsx("textarea",{rows:5,value:S.approvedClaims.join(` 48`),onChange:x=>Q({...S,approvedClaims:Ka(x.target.value)}),placeholder:"Approved claims â one per line",className:ta}),e.jsx("textarea",{rows:5,value:S.prohibitedClaims.join(` 49`),onChange:x=>Q({...S,prohibitedClaims:Ka(x.target.value)}),placeholder:"Prohibited claims â one per line",className:ta})]}),e.jsx("textarea",{rows:4,value:S.assetRules.join(` 50`),onChange:x=>Q({...S,assetRules:Ka(x.target.value)}),placeholder:"Photo and asset rules â one per line",className:ta})]}),e.jsxs("button",{onClick:O,disabled:P==="brand",className:"mt-5 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-gradient-to-r from-blue-500 to-pink-500 px-5 text-base font-black text-white",children:[P==="brand"?e.jsx(V,{className:"h-5 w-5 animate-spin"}):e.jsx(Ct,{className:"h-5 w-5"}),"Save with AI Review"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-white/35",children:"AI brand director"}
50),e.jsx("h3",{className:"mt-1 text-lg font-black",children:"Advice everywhere it helps"})]}),e.jsx(ye,{className:"h-5 w-5 text-lime-200"})]}),e.jsxs("button",{onClick:Te,disabled:P==="advisor",className:"mt-4 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl bg-lime-200 text-sm font-black text-black",children:[P==="advisor"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(ye,{className:"h-4 w-4"}),"Review our identity"]}),e.jsx("p",{className:"mt-3 text-xs font-semibold leading-5 text-white/35",children:"The advisor suggests gaps, slogans, photo briefs and claim warnings. It never silently changes approved truth."})]}),U&&e.jsxs("div",{className:"rounded-3xl border border-lime-200/15 bg-lime-200/[0.045] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-lime-100/50",children:"Latest review"}),e.jsxs("span",{className:"text-2xl font-black text-lime-100",children:[U.completenessScore||0,"%"]})]}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/60",children:U.executiveAdvice}),e.jsx("div",{className:"mt-4 space-y-3",children:(nt=U.identityGaps)==null?void 0:nt.slice(0,5).map(x=>e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-black/20 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-black",children:x.gap}),e.jsx("span",{className:"text-xs font-black uppercase text-amber-100",children:x.priority})]}),e.jsx("p",{className:"mt-1 text-xs font-semibold leading-5 text-white/42",children:x.recommendedAction})]},x.gap))}),(w=U.sloganDirections)!=null&&w.length?e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.16em] text-white/35",children:"Suggested slogan directions"}),U.sloganDirections.slice(0,4).map(x=>e.jsxs("div",{className:"mt-2 rounded-xl bg-white/[0.035] p-3",children:[e.jsxs("p",{className:"text-sm font-black",children:["â",x.slogan,"â"]}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/38",children:x.reason})]},x.slogan))]}):null]}),e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-white/35",children:"Palette"}),e.jsx("div",{className:"mt-3 flex gap-3",children:S.colors.map(x=>e.jsx("div",{title:x,className:"h-12 flex-1 rounded-xl border border-white/10",style:{backgroundColor:x}},x))})]})]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[0.72fr_1fr]",children:[e.jsxs("form",{onSubmit:Oe,className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsx(_a,{className:"h-5 w-5 text-teal-200"}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:"Add a governed brand asset"}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-5 text-white/38",children:"Images, PDFs and video up to 20 MB. Rights and consent stay attached to the file."}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp,application/pdf,video/mp4,video/quicktime",onChange:x=>{var D;return b(((D=x.target.files)==null?void 0:D[0])||null)},className:"block w-full text-sm font-bold text-white/55 file:mr-3 file:rounded-full file:border-0 file:bg-white file:px-4 file:py-2 file:text-xs file:font-black file:text-black"}),e.jsx("input",{value:C,onChange:x=>ne(x.target.value),placeholder:"Asset name (optional)",className:Qa}),e.jsx("input",{value:we,onChange:x=>be(x.target.value),placeholder:"Rights owner",className:Qa}),e.jsx("textarea",{rows:3,value:T,onChange:x=>l(x.target.value),placeholder:"Permitted use / license terms",className:ta})]}),e.jsxs("button",{disabled:!de||P==="asset",className:"mt-4 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl bg-white text-sm font-black text-black disabled:opacity-40",children:[P==="asset"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(_a,{className:"h-4 w-4"}),"Upload securely"]})]}),e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-white/35",children:"Asset library"}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:"Photos, video, documents and AI work"})]}),e.jsx("span",{className:"text-sm font-black text-teal-100",children:Y.length})]}),e.jsx("div",{className:"mt-4 grid max-h-[430px] gap-3 overflow-y-auto sm:grid-cols-2",children:Y.length?Y.map(x=>e.jsxs("article",{className:"overflow-hidden rounded-2xl border border-white/10 bg-black/25",children:[x.asset_type==="image"&&e.jsx("img",{src:x.asset_url,alt:x.name,className:"h-32 w-full object-cover",loading:"lazy"}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-black",children:x.name}),e.jsx("span",{className:"rounded-full border border-white/10 px-2 py-0.5 text-xs font-black text-white/40",children:x.status})]}),e.jsxs("p",{className:"mt-2 text-xs font-semibold text-white/38",children:[x.source_kind.replaceAll("_"," ")," · ",x.rights_owner||"owner pending"]})]})]},x.id)):e.jsx("p",{className:"col-span-full rounded-2xl border border-dashed border-white/10 p-7 text-center text-sm font-bold text-white/35",children:"Upload real brand work or approve a campaign to generate governed AI assets."})})]})]})]}),u==="connections"&&e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:o.connections.map(x=>e.jsxs("div",{className:"space-y-3",children:[e.jsx(ec,{connection:x,onSaved:async D=>{re(D),await f()},onError:G}),e.jsx(Zd,{connection:x})]},x.provider))}),u==="approvals"&&e.jsx("div",{className:"space-y-3",children:o.approvals.length?o.approvals.map(x=>e.jsx("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-teal-100/55",children:x.work_type}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:x.title}),x.summary&&e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/50",children:x.summary}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsxs("span",{className:"rounded-full border border-amber-300/20 bg-amber-300/10 px-3 py-1 text-xs font-black text-amber-100",children:[x.risk_level," risk"]}),e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-xs font-black",children:vt(x.estimated_cost,x.currency)})]})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx("button",{disabled:P===`approval-${x.id}`,onClick:()=>q(x.id,"rejected"),className:"h-11 rounded-full border border-rose-300/20 px-4 text-sm font-black text-rose-100",children:"Reject"}),e.jsx("button",{disabled:P===`approval-${x.id}`,onClick:()=>q(x.id,"approved"),className:"h-11 rounded-full bg-lime-200 px-5 text-sm font-black text-black",children:"Approve"})]})]})},x.id)):e.jsxs("div",{className:"flex min-h-[220px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 text-center",children:[e.jsx(on,{className:"h-9 w-9 text-teal-200"}),e.jsx("h3",{className:"mt-4 text-lg font-black",children:"Nothing waiting for approval"}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/40",children:"Publishing, spend, sensitive claims, and material brand changes will appear here."})]})})]})]})}function Zd({connection:i}){var p;return e.jsxs("aside",{className:"rounded-3xl border border-blue-300/15 bg-blue-300/[0.045] p-4",children:[e.jsx("p",{className:"text-sm font-black",children:"Where to get the required access"}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/45",children:i.helpText||"Follow the providerâs account setup process, then return here to save the encrypted configuration."}),(p=i.helpLinks)!=null&&p.length?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.helpLinks.map(u=>e.jsxs("a",{href:u.url,target:"_blank",rel:"noreferrer",className:"inline-flex h-10 items-center gap-2 rounded-full border border-blue-200/20 bg-blue-200/10 px-4 text-sm font-black text-blue-50",children:[u.label,e.jsx(sa,{className:"h-4 w-4"})]},u.url))}):e.jsx("p",{className:"mt-3 text-sm font-bold text-emerald-100/65",children:"No external
50connection is needed. The built-in Leads CRM is already available in this Ad Center."})]})}function ec({connection:i,onSaved:p,onError:u}){const[M,o]=r.useState(!1),[B,g]=r.useState(""),[_,S]=r.useState({displayName:i.displayName,...i.config}),Q=i.provider==="google_ads"?[["clientId","OAuth client ID"],["clientSecret","OAuth client secret"],["developerToken","Developer token"],["customerId","Customer ID"],["loginCustomerId","Manager customer ID"]]:i.provider==="linkedin_ads"?[["clientId","OAuth client ID"],["clientSecret","OAuth client secret"],["adAccountId","Ad account ID"],["organizationId","Organization/Page ID"],["campaignGroupId","Campaign group ID (optional)"],["defaultLocationUrns","Default location URNs (optional)"]]:i.provider==="pr_distribution"?[["providerName","PR provider"],["apiBaseUrl","API base URL"],["healthPath","Connection test path"],["submissionPath","Submission path"],["apiKey","API key"],["webhookSecret","Webhook signing secret"]]:[["providerName","CRM provider"],["apiBaseUrl","API base URL"],["healthPath","Connection test path"],["apiKey","API key"],["webhookSecret","Webhook signing secret"]],P=async K=>{K.preventDefault(),o(!0),u("");try{const U=await fetch(`${m}/api/admin/advertising/agency/connections/${i.provider}`,{method:"PUT",credentials:"include",headers:Ft(),body:JSON.stringify(_)}),J=await U.json().catch(()=>({}));if(!U.ok)throw new Error(J.error||"Connection configuration was not saved.");S(de=>Object.fromEntries(Object.entries(de).filter(([b])=>!["clientSecret","developerToken","apiKey","webhookSecret","accessToken","refreshToken"].includes(b)))),await p(`${i.label} configuration saved securely. Authorization and a live connection test are still required.`)}catch(U){u(U instanceof Error?U.message:"Connection configuration was not saved.")}finally{o(!1)}},j=async(K="read_only")=>{g(K==="publish"?"publish":"authorize"),u("");try{const U=await fetch(`${m}/api/admin/advertising/agency/connections/${i.provider}/authorize?mode=${K}`,{method:"POST",credentials:"include",headers:Ft()}),J=await U.json().catch(()=>({}));if(!U.ok||!J.authorizationUrl)throw new Error(J.error||"Authorization could not be started.");window.location.assign(J.authorizationUrl)}catch(U){u(U instanceof Error?U.message:"Authorization could not be started."),g("")}},z=async()=>{g("test"),u("");try{const K=await fetch(`${m}/api/admin/advertising/agency/connections/${i.provider}/test`,{method:"POST",credentials:"include",headers:Ft()}),U=await K.json().catch(()=>({}));if(!K.ok)throw new Error(U.error||"The provider connection test failed.");await p(`${i.label} read-only access verified. No campaign was changed.`)}catch(K){u(K instanceof Error?K.message:"The provider connection test failed.")}finally{g("")}},G=async()=>{g("sync"),u("");try{const K=await fetch(`${m}/api/admin/advertising/agency/connections/${i.provider}/sync`,{method:"POST",credentials:"include",headers:Ft(),body:JSON.stringify({days:30})}),U=await K.json().catch(()=>({}));if(!K.ok)throw new Error(U.error||"Results could not be synchronized.");await p(`${i.label}: ${U.recordsImported||0} campaign-day result records imported safely.`)}catch(K){u(K instanceof Error?K.message:"Results could not be synchronized.")}finally{g("")}},Z=["google_ads","linkedin_ads"].includes(i.provider),re=["authorized_publish","connected_publish"].includes(i.status),Y=re||["authorized_readonly","connected_readonly","verified"].includes(i.status);return e.jsxs("form",{onSubmit:P,className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-2xl bg-white/[0.06]",children:e.jsx(bd,{className:"h-5 w-5 text-teal-200"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black text-white/40",children:i.category}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:i.label})]})]}),e.jsx("span",{className:`rounded-full px-3 py-1 text-xs font-black uppercase ${Y?"bg-emerald-300/10 text-emerald-100":i.configured?"bg-amber-300/10 text-amber-100":"bg-white/[0.05] text-white/35"}`,children:i.status.replaceAll("_"," ")})]}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:Q.map(([K,U])=>{const J=/secret|token|apiKey/i.test(K);return e.jsxs("label",{className:"text-xs font-black text-white/50",children:[U,e.jsx("input",{type:J?"password":"text",autoComplete:"off",value:_[K]||"",onChange:de=>S({..._,[K]:de.target.value}),placeholder:J&&i.configured?"Leave blank to keep stored value":U,className:`${Qa} mt-2`})]},K)})}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:i.capabilities.map(K=>e.jsx("span",{className:"rounded-full border border-white/10 px-2.5 py-1 text-xs font-bold text-white/35",children:K.replaceAll("_"," ")},K))}),e.jsxs("button",{disabled:M,className:"mt-5 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl bg-white text-sm font-black text-black transition hover:bg-teal-200 disabled:opacity-50",children:[M?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(qe,{className:"h-4 w-4"}),"Save encrypted configuration"]}),Z&&i.configured?e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsx("button",{type:"button",onClick:()=>j("read_only"),disabled:!!B,className:"h-11 rounded-2xl border border-teal-200/20 bg-teal-200/10 text-sm font-black text-teal-50",children:B==="authorize"?"Startingâ¦":Y?"Reauthorize":"Authorize"}),e.jsx("button",{type:"button",onClick:()=>j("publish"),disabled:!!B,className:"h-11 rounded-2xl border border-fuchsia-200/20 bg-fuchsia-200/10 text-sm font-black text-fuchsia-50",children:B==="publish"?"Startingâ¦":re?"Publishing ready":"Enable publishing"}),e.jsx("button",{type:"button",onClick:z,disabled:!!B||!Y,className:"h-11 rounded-2xl border border-lime-200/20 bg-lime-200/10 text-sm font-black text-lime-50 disabled:opacity-35",children:B==="test"?"Testingâ¦":"Test"}),e.jsx("button",{type:"button",onClick:G,disabled:!!B||!Y,className:"h-11 rounded-2xl border border-sky-200/20 bg-sky-200/10 text-sm font-black text-sky-50 disabled:opacity-35",children:B==="sync"?"Syncingâ¦":"Sync results"})]}):null,!Z&&i.configured?e.jsx("button",{type:"button",onClick:z,disabled:!!B,className:"mt-3 h-11 w-full rounded-2xl border border-lime-200/20 bg-lime-200/10 text-sm font-black text-lime-50",children:B==="test"?"Testingâ¦":Y?"Verify again":"Verify connection"}):null,i.lastSyncAt?e.jsxs("p",{className:"mt-3 text-center text-xs font-bold text-emerald-100/55",children:["Last results sync: ",i.lastSyncAt]}):null,e.jsx("p",{className:"mt-3 text-center text-xs font-semibold text-white/28",children:"Publishing permission enables the wiring; spend or outreach starts only from an approved one-button action."})]})}const tc={critical:"border-rose-300/25 bg-rose-300/10 text-rose-100",attention:"border-amber-300/25 bg-amber-300/10 text-amber-100",healthy:"border-emerald-300/25 bg-emerald-300/10 text-emerald-100",learning:"border-sky-300/20 bg-sky-300/10 text-sky-100",awaiting_data:"border-white/10 bg-white/[0.045] text-white/55"},ac={critical:"border-rose-300/25 bg-rose-300/[0.075]",warning:"border-amber-300/20 bg-amber-300/[0.065]",success:"border-emerald-300/20 bg-emerald-300/[0.065]",info:"border-sky-300/20 bg-sky-300/[0.055]"};function Ts(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function ft(i){return new Intl.NumberFormat("en-US",{maximumFractionDigits:1}).format(Number(i||0))}function _t(i){return i==null?"Not enough data":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(i)}function hl(i){return i==null?"Not enough data":`${ft(i)}%`}function pl(i){if(!i)return"Waiting for first sync";const p=new Date(i);if(!Number.isFinite(p.getTime()))return"Freshness unavailable";const u=Math.max(0,Math.floor((Date.now()-p.getTime())/36e5));return u<1?"Updated within the hour":u<24?`Updated ${u}h ago`:`Updated ${Math.floor(u/24)}d ago`}function Xa({label:i,value:p,detail:u,icon:M,tone:o="teal"}){const B=o==="lime"?"text-lime-200":o==="sky"?"text-sky-200":o==="amber"?"text-amber-200":"text-teal-200";return e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/42",children:i}),e.jsx(M,{className:`h-4 w-4 ${B}`})]}),e.jsx("p",{className:"mt-4 text-3xl font-black tracking-tight text-white",children:p}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-5 text-white/45",children:u})]})}function sc({overview:i}){const p=[{label:"Provider impressions",value:i.totals.impressions},{label:"Provider clicks",value:i.totals.clicks},{label:"Attributed visitors",value:i.totals.visitors},{label:"Demo leads",value:i.totals.leads},{label:"Qualified",value:i.totals.qualified},{label:"Won",value:i.totals.wins}],u=Math.max(1,...p.map(M=>M.value));return e.jsx("div",{className:"space-y-3",children:p.map((M,o)=>{const B=o?p[o-1].value:null,g=B?Math.round(M.value/B*1e3)/10:null;return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-3 text-xs font-black",children:[e.jsx("span",{className:"text-white/62",children:M.label}),e.jsxs("span",{children:[ft(M.value),g!==null?e.jsxs("span",{className:"ml-2 text-white/32",children:[g,"%"]}):null]})]}),e.jsx("div",{className:"h-2.5 overflow-hidden rounded-full bg-white/[0.055]",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-teal-300 to-lime-200",style:{width:`${Math.max(M.value?3:0,M.value/u*100)}%`}})})]},M.label)})})}function rc({weeklyPlanId:i,onOpenCreative:p}){const[u,M]=r.useState(30),[o,B]=r.useState(null),[g,_]=r.useState(!0),[S,Q]=r.useState(!1),[P,j]=r.useState(null),[z,G]=r.useState(""),[Z,re]=r.useState(""),[Y,K]=r.useState(null),[U,J]=r.useState(!!i),[de,b]=r.useState(!1),C=async(l=u)=>{G("");try{const f=await fetch(`${m}/api/admin/advertising/learning/overview?days=${l}`,{credentials:"include",headers:Ts()}),le=await f.json().catch(()=>({}));if(!f.ok)throw new Error(le.error||"Campaign learning could not be loaded.");B(le)}catch(f){G(f instanceof Error?f.message:"Campaign learning could not be loaded.")}finally{_(!1)}};r.useEffect(()=>{C(u)},[u]),r.useEffect(()=>{if(!i)return;let l=!0;return J(!0),fetch(`${m}/api/admin/advertising/weekly-learning-plans/${encodeURIComponent(i)}`,{credentials:"include",headers:Ts()}).then(async f=>{const le=await f.json().catch(()=>({}));if(!f.ok)throw new Error(le.error||"The weekly plan could not be loaded.");l&&K(le.plan||null)}
50).catch(f=>{l&&G(f instanceof Error?f.message:"The weekly plan could not be loaded.")}).finally(()=>{l&&J(!1)}),()=>{l=!1}},[i]);const ne=async()=>{if(i){b(!0),G(""),re("");try{const l=await fetch(`${m}/api/admin/advertising/weekly-learning-plans/${encodeURIComponent(i)}/approve`,{method:"POST",credentials:"include",headers:Ts(),body:"{}"}),f=await l.json().catch(()=>({}));if(!l.ok)throw new Error(f.error||"The weekly plan could not be approved.");K(f.plan||null),re("Plan approved for preparation. No campaign, audience, budget, or public page has changed.")}catch(l){G(l instanceof Error?l.message:"The weekly plan could not be approved.")}finally{b(!1)}}},we=async()=>{Q(!0),G(""),re("");try{const l=await fetch(`${m}/api/admin/advertising/learning/monitor`,{method:"POST",credentials:"include",headers:Ts(),body:JSON.stringify({days:u})}),f=await l.json().catch(()=>({}));if(!l.ok)throw new Error(f.error||"The agency health check could not finish.");B(f.overview),re("Agency check complete. Every recommendation is based on the reconciled data shown below.")}catch(l){G(l instanceof Error?l.message:"The agency health check could not finish.")}finally{Q(!1)}},be=async(l,f)=>{j(l.id),G(""),re("");try{const le=await fetch(`${m}/api/admin/advertising/learning/recommendations/${l.id}/decision`,{method:"POST",credentials:"include",headers:Ts(),body:JSON.stringify({decision:f})}),O=await le.json().catch(()=>({}));if(!le.ok)throw new Error(O.error||"The agency action could not be completed.");re(f==="dismiss"?"Recommendation dismissed. No external state changed.":"Approved action completed and its receipt was recorded."),await C(u)}catch(le){G(le instanceof Error?le.message:"The agency action could not be completed.")}finally{j(null)}},T=r.useMemo(()=>(o==null?void 0:o.campaigns.filter(l=>["critical","attention"].includes(l.health)).length)||0,[o]);return g&&!o?e.jsx("section",{className:"flex min-h-[420px] items-center justify-center rounded-[2rem] border border-white/10 bg-white/[0.035]",children:e.jsx(V,{className:"h-8 w-8 animate-spin text-teal-200"})}):o?e.jsxs("section",{id:"campaign-learning",className:"rounded-[2rem] border border-teal-200/15 bg-gradient-to-br from-[#0b1514] via-[#080b0a] to-[#12150b] p-5 shadow-2xl shadow-black/35 md:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-lime-200 text-black",children:e.jsx(Lr,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.22em] text-lime-100/55",children:"Campaigns & Learning"}),e.jsx("h2",{className:"mt-1 text-3xl font-black",children:"Management command center"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/52",children:"One reconciled view of provider delivery, website behavior, lead quality, approved spend, and CRM revenue. The agency recommends only actions it can actually wire after approval."})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"flex rounded-full border border-white/10 bg-black/30 p-1",children:[7,30,90].map(l=>e.jsxs("button",{onClick:()=>M(l),className:`h-9 rounded-full px-3 text-xs font-black transition ${u===l?"bg-white text-black":"text-white/48 hover:text-white"}`,children:[l," days"]},l))}),e.jsxs("button",{onClick:we,disabled:S,className:"inline-flex h-11 items-center gap-2 rounded-full bg-lime-200 px-4 text-sm font-black text-black transition hover:bg-white disabled:opacity-50",children:[S?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(ye,{className:"h-4 w-4"}),"Run Agency Check"]})]})]}),(z||Z)&&e.jsx("div",{className:`mt-5 rounded-2xl border px-4 py-3 text-sm font-bold ${z?"border-rose-300/20 bg-rose-300/10 text-rose-100":"border-emerald-300/20 bg-emerald-300/10 text-emerald-100"}`,children:z||Z}),i&&e.jsx("article",{className:"mt-5 rounded-3xl border border-blue-200/25 bg-blue-200/[0.08] p-5 shadow-xl shadow-black/10",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-blue-100/65",children:"Weekly report plan"}),U?e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-sm font-bold text-white/60",children:[e.jsx(V,{className:"h-4 w-4 animate-spin"}),"Loading the protected planâ¦"]}):Y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-xl font-black text-white",children:Y.title}),e.jsxs("span",{className:"rounded-full border border-blue-100/20 px-2.5 py-1 text-xs font-black uppercase text-blue-100",children:[Y.confidence," confidence"]}),e.jsx("span",{className:`rounded-full border px-2.5 py-1 text-xs font-black uppercase ${Y.status==="approved"?"border-emerald-200/25 bg-emerald-200/10 text-emerald-100":"border-white/10 text-white/60"}`,children:Y.status==="approved"?"Approved for preparation":"Awaiting approval"})]}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/75",children:Y.recommendation}),e.jsxs("p",{className:"mt-3 text-xs font-bold leading-5 text-white/48",children:["Evidence: ",Y.evidence]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-white/10 bg-black/20 p-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.16em] text-white/40",children:"Suggested next work"}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm font-semibold leading-6 text-white/65",children:[e.jsx("li",{children:"Keep the current page and audience as the measured control."}),e.jsx("li",{children:"Draft one bounded variant that follows the recommendation exactly."}),e.jsx("li",{children:"Set the success measure and review point before anything is published."})]})]})]}):e.jsx("p",{className:"mt-3 text-sm font-bold text-rose-100",children:"This weekly plan is no longer available."})]}),Y&&e.jsxs("div",{className:"flex shrink-0 flex-col gap-2",children:[e.jsxs("button",{onClick:ne,disabled:de||Y.status==="approved",className:"inline-flex h-11 items-center justify-center gap-2 rounded-full bg-white px-4 text-sm font-black text-black transition hover:bg-blue-100 disabled:cursor-not-allowed disabled:opacity-50",children:[de?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ce,{className:"h-4 w-4"}),Y.status==="approved"?"Plan approved":"Approve plan"]}),Y.status==="approved"&&p&&e.jsxs("button",{onClick:p,className:"inline-flex h-11 items-center justify-center gap-2 rounded-full border border-white/15 px-4 text-sm font-black text-white transition hover:bg-white/10",children:[e.jsx(es,{className:"h-4 w-4"}),"Open Creative workspace"]}),e.jsx("p",{className:"max-w-[220px] text-center text-xs font-semibold leading-5 text-white/42",children:"Approval allows preparation only. Publishing, spend, audience, and public-page edits stay separate."})]})]})}),e.jsxs("div",{className:"mt-6 grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(Xa,{label:"Provider spend",value:_t(o.totals.spend),detail:`${_t(o.totals.approvedCap)} approved test capacity`,icon:Yo}),e.jsx(Xa,{label:"Attributed leads",value:ft(o.totals.leads),detail:`${_t(o.totals.cpl)} per lead`,icon:Rs,tone:"sky"}),e.jsx(Xa,{label:"Qualified",value:ft(o.totals.qualified),detail:`${_t(o.totals.costPerQualifiedLead)} per qualified lead`,icon:Er,tone:"lime"}),e.jsx(Xa,{label:"Wins",value:ft(o.totals.wins),detail:`${_t(o.totals.cac)} acquisition cost`,icon:Ce,tone:"lime"}),e.jsx(Xa,{label:"CRM revenue",value:_t(o.totals.revenue),detail:o.totals.roas===null?"Waiting for signed revenue feedback":`${ft(o.totals.roas)}à return on ad spend`,icon:Lr}),e.jsx(Xa,{label:"Needs attention",value:ft(T),detail:`${o.recommendations.length}
50 open agency recommendations`,icon:Ar,tone:"amber"})]}),e.jsxs("div",{className:"mt-5 grid gap-5 xl:grid-cols-[0.8fr_1.2fr]",children:[e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"mb-5 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/38",children:"Truth funnel"}),e.jsx("h3",{className:"mt-1 text-xl font-black",children:"Delivery to revenue"})]}),e.jsx(Sl,{className:"h-5 w-5 text-teal-200"})]}),e.jsx(sc,{overview:o}),e.jsxs("div",{className:"mt-5 grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsx("p",{className:"text-xs font-black text-white/40",children:"Delivery data"}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/65",children:pl(o.freshness.latestMetricAt)})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsx("p",{className:"text-xs font-black text-white/40",children:"Revenue feedback"}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/65",children:pl(o.freshness.latestFeedbackAt)})]})]})]}),e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"mb-5 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/38",children:"Agency action queue"}),e.jsx("h3",{className:"mt-1 text-xl font-black",children:"Prepared decisions"})]}),e.jsx(qe,{className:"h-5 w-5 text-lime-200"})]}),e.jsx("div",{className:"space-y-3",children:o.recommendations.length?o.recommendations.map(l=>e.jsx("div",{className:`rounded-2xl border p-4 ${ac[l.severity]}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5",children:l.severity==="critical"||l.severity==="warning"?e.jsx(Ar,{className:"h-4 w-4 text-amber-200"}):e.jsx(Ce,{className:"h-4 w-4 text-sky-200"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-black",children:l.title}),e.jsxs("span",{className:"rounded-full border border-white/10 px-2 py-0.5 text-xs font-black uppercase text-white/42",children:[l.confidence," confidence"]})]}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/62",children:l.recommendation}),l.evidence&&e.jsx("p",{className:"mt-2 text-xs font-bold leading-5 text-white/38",children:l.evidence}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[l.actionLabel&&e.jsxs("button",{onClick:()=>be(l,"approve"),disabled:P===l.id,className:"inline-flex h-10 items-center gap-2 rounded-full bg-white px-4 text-xs font-black text-black transition hover:bg-lime-200 disabled:opacity-50",children:[P===l.id?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(es,{className:"h-4 w-4"}),l.actionLabel]}),e.jsxs("button",{onClick:()=>be(l,"dismiss"),disabled:P===l.id,className:"inline-flex h-10 items-center gap-2 rounded-full border border-white/10 px-4 text-xs font-black text-white/55 transition hover:border-white/25 hover:text-white disabled:opacity-50",children:[e.jsx(kt,{className:"h-4 w-4"}),"Dismiss"]})]})]})]})},l.id)):e.jsxs("div",{className:"rounded-2xl border border-dashed border-white/12 p-6 text-center",children:[e.jsx(dn,{className:"mx-auto h-7 w-7 text-teal-200"}),e.jsx("p",{className:"mt-3 text-sm font-black",children:"Run the agency check"}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-5 text-white/42",children:"The system will prepare evidence-backed actions without changing external state."})]})})]})]}),e.jsxs("div",{className:"mt-5 space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-end md:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/38",children:"Campaign portfolio"}),e.jsx("h3",{className:"mt-1 text-xl font-black",children:"Spend, signal, and outcomes"})]}),e.jsxs("div",{className:`inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-xs font-black ${o.reconciliation.unmatchedProviderCampaigns?"border-amber-300/20 bg-amber-300/10 text-amber-100":"border-emerald-300/20 bg-emerald-300/10 text-emerald-100"}`,children:[o.reconciliation.unmatchedProviderCampaigns?e.jsx(Ar,{className:"h-3.5 w-3.5"}):e.jsx(Ce,{className:"h-3.5 w-3.5"}),o.reconciliation.matchedProviderCampaigns," provider campaigns matched · ",o.reconciliation.unmatchedProviderCampaigns," unmatched"]})]}),o.campaigns.length?o.campaigns.map(l=>e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 xl:flex-row xl:items-start xl:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"text-lg font-black",children:l.name}),e.jsx("span",{className:`rounded-full border px-2.5 py-1 text-xs font-black uppercase ${tc[l.health]}`,children:l.health.replaceAll("_"," ")}),l.providers.map(f=>e.jsx("span",{className:"rounded-full border border-white/10 px-2.5 py-1 text-xs font-black text-white/48",children:f.provider.replaceAll("_"," ")},`${f.provider}-${f.externalCampaignId}`))]}),e.jsxs("p",{className:"mt-2 text-xs font-semibold text-white/40",children:[l.launchStatus||l.status," · ",pl(l.latestProviderAt)]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-x-5 gap-y-3 sm:grid-cols-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black",children:ft(l.impressions)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Impressions"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black",children:ft(l.clicks)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Clicks"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black",children:ft(l.visitors)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Visitors"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black",children:ft(l.leads)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Leads"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black text-lime-100",children:ft(l.qualified)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Qualified"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-black text-lime-100",children:ft(l.wins)}),e.jsx("p",{className:"text-xs font-black uppercase text-white/32",children:"Wins"})]})]})]}),e.jsxs("div",{className:"mt-5 grid gap-4 lg:grid-cols-[1.25fr_0.75fr]",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3 text-xs font-black",children:[e.jsx("span",{className:"text-white/46",children:"Approved test envelope"}),e.jsxs("span",{children:[_t(l.spend)," of ",_t(l.approvedCap)]})]}),e.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-white/[0.055]",children:e.jsx("div",{className:`h-full rounded-full ${l.capUsedPercent!==null&&l.capUsedPercent>100?"bg-rose-300":l.capUsedPercent!==null&&l.capUsedPercent>80?"bg-amber-300":"bg-gradient-to-r from-teal-300 to-lime-200"}`,style:{width:`${Math.min(100,Math.max(0,l.capUsedPercent||0))}%`}})}),e.jsxs("div",{className:"mt-2 flex flex-wrap justify-between gap-2 text-xs font-semibold text-white/35",children:[e.jsxs("span",{children:[hl(l.capUsedPercent)," of cap used"]}),e.jsxs("span",{children:[_t(l.remainingBudget)," remaining"]}),e.jsxs("span",{children:[hl(l.pacePercent)," of expected pace"]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsx("p",{className:"text-xs font-black text-white/35",children:"CTR"}),e.jsx("p",{className:"mt-1 text-sm font-black",children:hl(l.ctr)})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsx("p",{className:"text-xs font-black text-white/35",children:"CPL"}),e.jsx("p",{className:"mt-1 text-sm font-black",children:_t(l.cpl)})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-3",children:[e.jsx("p",{className:"text-xs font-black text-white/35",children:"CAC"}),e.jsx("p",{className:"mt-1 text-sm font-black",children:_t(l.cac)})]})]})]})]},l.id)):e.jsxs("div",{className:"rounded-3xl border border-dashed border-white/12 p-8 text-center",children:[e.jsx(cn,{className:"mx-auto h-8 w-8 text-teal-200"}),e.jsx("h4",{className:"mt-3 text-lg font-black",children:"No campaign learning yet"}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/42",children:"Approved and tracked campaigns will appear here automatically."})]})]}),e.jsx("div",{className:"mt-5 rounded-3xl border border-white/10 bg-white/[0.025] p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(tt,{className:"mt-0.5 h-4 w-4 shrink-0 text-teal-200"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.16em] text-white/42",children:"Metric contract"}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-5 text-white/45",children:"Spend, impressions, clicks, and provider conversions come from aggregated ad-platform imports. Leads, qualification, and wins come from first-party marketing attribution. Revenue comes only from signed CRM feedback; provider conversion value is never silently treated as booked revenue. Campaign-level conclusions exclude unmatched provider campaigns."})]})]})})]}):e.jsx("section",{className:"rounded-[2rem] border border-rose-300/20 bg-rose-300/10 p-6 text-sm font-bold text-rose-100",children:z||"Campaign learning is unavailable."})}function lc(){const i=sessionStorage.getItem("adminToken");return i?{"X-Admin-Token":i}:{}}function La(i=0){return new Intl.NumberFormat("en-US").format(i)}function Yi(i=0){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(i)}function ic({weeklyPlanId:i,onOpenCreative:p}){var S,Q;const[u,M]=r.useState({}),[o,B]=r.useState(""),g=async()=>{B("");try{const P=await fetch(`${m}/api/admin/advertising/summary?days=30`,{credentials:"include",headers:lc()}),j=await P.json().catch(()=>({}));if(!P.ok)throw new Error(j.error||"Campaign results could not be loaded.");M(j)}catch(P){B(P instanceof Error?P.message:"Campaign results could not be loaded.")}};r.useEffect(()=>{g()},[]);const _=u.totals||{};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("section",{className:"rounded-[2rem] border border-white/10 bg-[#080b09] p-5 shadow-2xl shadow-black/35 lg:p-7",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-teal-100/50",children:"Results room"}),e.jsx("h2",{className:"mt-2 text-2xl font-black",children:"Campaigns and accountable outcomes"})]}),e.jsxs("button",{onClick:g,className:"inline-flex h-11 items-center gap-2 rounded-full border border-white/10 px-4 text-sm font-black",children:[e.jsx(tt,{className:"h-4 w-4"}),"Refresh"]})]}),o&&e.jsx("p",{className:"mt-4 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-4 text-sm font-bold text-rose-100",children:o}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2 xl:grid-cols-5",children:[[Ut,"Paid visitors",La(_.visitors),`${La(_.pageviews)} pageviews`],[Rs,"Demo leads",La(_.leads),`${_.leadRate||0}% visitor to lead`],[Ce,"Qualified",La(_.qualified),`${_.qualifiedRate||0}% visitor to qualified`],[dn,"Daily authority",Yi(_.budget),"Across tracked campaigns"],[Sl,"Campaigns",La((S=u.campaigns)==null?void 0:S.length),"Receipt-backed status"]].map(([P,j,z,G])=>{const Z=P;return e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-4",children:[e.jsx(Z,{className:"h-4 w-4 text-teal-200"}),e.jsx("p",{className:"mt-3 text-xs font-black uppercase tracking-[0.15em] text-white/35",children:String(j)}),e.jsx("p",{className:"mt-2 text-2xl font-black",children:String(z)}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/35",children:String(G)})]},String(j))})}),e.jsx("div",{className:"mt-5 space-y-3",children:(Q=u.campaigns)!=null&&Q.length?u.campaigns.map(P=>e.jsx("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-black",children:P.name}),e.jsx("span",{className:"rounded-full border border-white/10 px-2.5 py-1 text-xs font-black uppercase text-white/42",children:P.status})]}),e.jsxs("p",{className:"mt-1 text-sm font-semibold text-white/40",children:[P.channel," · ",Yi(P.dailyBudgetUsd),"/day"]})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xl font-black",children:La(P.visitors)}),e.jsx("p",{className:"text-xs font-bold text-white/32",children:"visitors"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xl font-black",children:La(P.leads)}),e.jsx("p",{className:"text-xs font-bold text-white/32",children:"leads"})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xl font-black",children:[P.leadRate||0,"%"]}),e.jsx("p",{className:"text-xs font-bold text-white/32",children:"rate"})]})]})]})},P.id)):e.jsx("div",{className:"rounded-3xl border border-dashed border-white/12 p-10 text-center text-sm font-bold text-white/38",children:"Approved campaigns appear here automaticallyâno manual campaign form is needed."})})]}),e.jsx(rc,{weeklyPlanId:i,onOpenCreative:p})]})}function bl(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}const Qi="h-12 w-full rounded-2xl border border-white/10 bg-black/30 px-4 text-sm font-bold text-white outline-none placeholder:text-white/25 focus:border-teal-200/50";function nc(){var Oe,Ye,Ge,Ke,nt,w,x,D,ae,je,Ue,ot;const[i,p]=r.useState([]),[u,M]=r.useState([]),[o,B]=r.useState([]),[g,_]=r.useState(""),[S,Q]=r.useState("Generate qualified enterprise demo requests"),[P,j]=r.useState("Contact-center quality and customer-experience leaders"),[z,G]=r.useState("Book a workflow-mapping session"),[Z,re]=r.useState(["linkedin","google"]),[Y,K]=r.useState(!1),[U,J]=r.useState(""),[de,b]=r.useState(null),[C,ne]=r.useState(!1),[we,be]=r.useState(""),[T,l]=r.useState([]),f=async()=>{var E,ge,Ie;try{const Fe=await fetch(`${m}/api/admin/advertising/creative-studio`,{credentials:"include",headers:bl()}),A=await Fe.json().catch(()=>({}));if(!Fe.ok)throw new Error(A.error||"Creative Studio could not be loaded.");const he=A.projects||[];p(he),M(A.assets||[]),B(A.productionJobs||[]);const Ne=(E=he[0])==null?void 0:E.launch,He=(ge=Ne==null?void 0:Ne.selectedRegionIds)!=null&&ge.length?Ne.selectedRegionIds:(((Ie=Ne==null?void 0:Ne.geoPlan)==null?void 0:Ie.regions)||[]).filter(We=>We.selected||We.recommended).map(We=>We.id);l(We=>We.length&&(Ne==null?void 0:Ne.status)!=="launched"?We.filter(rt=>{var Tt;return(((Tt=Ne==null?void 0:Ne.geoPlan)==null?void 0:Tt.regions)||[]).some(_e=>_e.id===rt)}):He)}catch(Fe){J(Fe instanceof Error?Fe.message:"Creative Studio could not be loaded.")}};r.useEffect(()=>{f()},[]);const le=async E=>{if(E.preventDefault(),!!g.trim()){K(!0),J("");try{const ge=await fetch(`${m}/api/admin/advertising/creative-studio/projects`,{method:"POST",credentials:"include",headers:bl(),body:JSON.stringify({name:g,objective:S,audience:P,offer:z,channels:Z})}),Ie=await ge.json().catch(()=>({}));if(!ge.ok)throw new Error(Ie.error||"The agency could not create this package.");b(Ie.outputs),_(""),await f()}catch(ge){J(ge instanceof Error?ge.message:"The agency could not create this package.")}finally{K(!1)}}},O=de||((Oe=i[0])==null?void 0:Oe.outputs)||null,q=de?null:i[0],Te=async()=>{var E,ge;if((E=q==null?void 0:q.launch)!=null&&E.id){ne(!0),J(""),be("");try{if(!T.length)throw new Error("Choose at least one region to launch.");const Ie=await f
50etch(`${m}/api/admin/advertising/creative-brain/launches/${q.launch.id}/launch`,{method:"POST",credentials:"include",headers:bl(),body:JSON.stringify({selectedRegionIds:T})}),Fe=await Ie.json().catch(()=>({}));if(!Ie.ok){const A=(((ge=Fe.preflight)==null?void 0:ge.checks)||[]).filter(he=>he.blocking&&!he.passed).map(he=>he.label).join(", ");throw new Error(A?`${Fe.error} ${A}.`:Fe.error||"The campaign could not be launched.")}be(`${T.length} regional campaign${T.length===1?"":"s"} launched. Localized pages, provider settings, receipts and learning are active.`),await f()}catch(Ie){J(Ie instanceof Error?Ie.message:"The campaign could not be launched.")}finally{ne(!1)}}};return e.jsxs("section",{className:"rounded-[2rem] border border-fuchsia-200/12 bg-gradient-to-br from-[#130b14] via-[#090809] to-[#071310] p-5 shadow-2xl shadow-black/30 lg:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.24em] text-fuchsia-100/55",children:"Production floor"}),e.jsx("h2",{className:"mt-1 text-3xl font-black",children:"Creative Studio"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/52",children:"Approved opportunities arrive here already built: copy, channel-sized images, video production files, article and PR package. The agency keeps provenance and QA attached to every final asset."})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-black/25 px-4 py-3 text-xs font-black text-white/45",children:[i.length," projects · ",u.length," governed assets · ",o.length," production jobs"]})]}),U&&e.jsx("div",{className:"mt-5 rounded-2xl border border-rose-400/20 bg-rose-400/10 p-4 text-sm font-bold text-rose-100",children:U}),we&&e.jsx("div",{className:"mt-5 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-4 text-sm font-bold text-emerald-100",children:we}),e.jsxs("div",{className:"mt-6 grid gap-5",children:[e.jsxs("form",{onSubmit:le,className:"hidden rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-2xl bg-fuchsia-200 text-black",children:e.jsx(ye,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/35",children:"Agency brief"}),e.jsx("h3",{className:"text-lg font-black",children:"Create a campaign package"})]})]}),e.jsxs("div",{className:"mt-5 space-y-3",children:[e.jsx("input",{value:g,onChange:E=>_(E.target.value),placeholder:"Project name",className:Qi}),e.jsx("input",{value:S,onChange:E=>Q(E.target.value),placeholder:"Objective",className:Qi}),e.jsx("textarea",{value:P,onChange:E=>j(E.target.value),rows:3,placeholder:"Audience",className:"w-full resize-none rounded-2xl border border-white/10 bg-black/30 px-4 py-3 text-sm font-bold text-white outline-none focus:border-teal-200/50"}),e.jsx("textarea",{value:z,onChange:E=>G(E.target.value),rows:2,placeholder:"Offer",className:"w-full resize-none rounded-2xl border border-white/10 bg-black/30 px-4 py-3 text-sm font-bold text-white outline-none focus:border-teal-200/50"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["linkedin","google","social","article","pr","video"].map(E=>e.jsx("button",{type:"button",onClick:()=>re(ge=>ge.includes(E)?ge.filter(Ie=>Ie!==E):[...ge,E]),className:`rounded-full px-3 py-1.5 text-xs font-black ${Z.includes(E)?"bg-teal-200 text-black":"border border-white/10 text-white/40"}`,children:E},E))})]}),e.jsxs("button",{disabled:Y||!g.trim(),className:"mt-5 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-white text-sm font-black text-black disabled:opacity-40",children:[Y?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ls,{className:"h-4 w-4"}),Y?"Agency is creatingâ¦":"Create full package"]})]}),e.jsx("div",{className:"space-y-4",children:O?e.jsxs(e.Fragment,{children:[(q==null?void 0:q.launch)&&e.jsxs("div",{className:"rounded-3xl border border-lime-200/15 bg-lime-200/[0.055] p-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-lime-200 text-black",children:e.jsx(xn,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-lime-100/55",children:"Management decision"}),e.jsxs("h3",{className:"mt-1 text-xl font-black",children:["Where should ",q.name," launch?"]}
50),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/52",children:"The agency recommends the markets and explains why. Check the final footprint; Launch Campaign handles localization, naming, divided budget, targeting, tracking, provider setup, receipts and learning."})]})]}),e.jsx("div",{className:"mt-5 grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:(((Ye=q.launch.geoPlan)==null?void 0:Ye.regions)||[]).map(E=>{var Ie;const ge=T.includes(E.id);return e.jsxs("label",{className:`cursor-pointer rounded-2xl border p-4 transition ${ge?"border-lime-200/45 bg-lime-200/10":"border-white/10 bg-black/20 hover:border-white/20"}`,children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"checkbox",checked:ge,disabled:((Ie=q.launch)==null?void 0:Ie.status)==="launched",onChange:()=>l(Fe=>Fe.includes(E.id)?Fe.filter(A=>A!==E.id):[...Fe,E.id]),className:"mt-1 h-5 w-5 accent-lime-200"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xl","aria-hidden":"true",children:E.flag}),e.jsx("p",{className:"text-sm font-black",children:E.label})]}),e.jsxs("p",{className:"mt-1 text-xs font-black uppercase tracking-[0.12em] text-lime-100/55",children:[E.languageLabel," · ",E.locale]})]})]}),e.jsx("p",{className:"mt-3 text-xs font-semibold leading-5 text-white/48",children:E.reason}),e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs font-black",children:[e.jsxs("span",{className:"text-white/35",children:[E.confidence," confidence"]}),E.recommended&&e.jsx("span",{className:"rounded-full bg-lime-200/10 px-2.5 py-1 text-lime-100",children:"AI pick"})]})]},E.id)})}),e.jsxs("div",{className:"mt-5 flex flex-col gap-3 border-t border-white/10 pt-5 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("p",{className:"text-sm font-semibold text-white/48",children:[T.length," region",T.length===1?"":"s"," selected · the approved budget is divided across them, never multiplied."]}),q.launch.status==="launched"?e.jsxs("div",{className:"inline-flex h-12 items-center gap-2 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 px-5 text-sm font-black text-emerald-100",children:[e.jsx(Ce,{className:"h-4 w-4"}),"Campaign launched"]}):e.jsxs("button",{onClick:Te,disabled:C||!T.length,className:"inline-flex h-12 shrink-0 items-center justify-center gap-2 rounded-2xl bg-white px-7 text-sm font-black text-black disabled:opacity-45",children:[C?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx($s,{className:"h-4 w-4"}),C?"Agency is launchingâ¦":"Launch Campaign"]})]})]}),o.length>0&&e.jsx("div",{className:"rounded-3xl border border-fuchsia-200/15 bg-fuchsia-200/[0.045] p-5",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-fuchsia-100/50",children:"Final asset production"}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:"Generated files with provenance and QA"})]}),e.jsx("div",{className:"flex max-w-4xl flex-wrap gap-2 lg:justify-end",children:o.slice(0,20).map(E=>e.jsxs("span",{title:E.error_safe||"",className:`rounded-full px-3 py-1 text-xs font-black ${E.status==="ready"?"bg-emerald-300/10 text-emerald-100":E.status==="failed"?"bg-rose-300/10 text-rose-100":"bg-amber-300/10 text-amber-100"}`,children:[E.asset_kind.replaceAll("_"," ")," · ",E.status.replaceAll("_"," ")]},E.id))})]})}),u.some(E=>E.asset_type==="image"&&E.status==="approved")&&e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/[0.025] p-5",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/35",children:"Approved visual library"}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5",children:u.filter(E=>E.asset_type==="image"&&E.status==="approved").slice(0,10).map(E=>e.jsxs("a",{href:E.asset_url,target:"_blank",rel:"noreferrer",className:"group overflow-hidden rounded-2xl border border-white/10 bg-black/25",children:[e.jsx("img",{src:E.asset_url,alt:E.name,className:"aspect-square w-full object-cover transition group-hover:scale-[1.02]",loading:"lazy"}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"truncate text-xs font-black",children:E.name}),e.jsx("p",{className:"mt-1 text-xs font-semibold text-white/35",children:E.source_kind.replaceAll("_"," ")})]})]},E.id))})]}),e.jsxs("div",{className:"rounded-3xl border border-teal-200/15 bg-teal-200/[0.055] p-5",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-teal-100/50",children:"Creative strategy"}),e.jsx("h3",{className:"mt-2 text-xl font-black",children:(Ge=O.strategy)==null?void 0:Ge.singleMindedProposition}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:(nt=(Ke=O.strategy)==null?void 0:Ke.reasonToBelieve)==null?void 0:nt.map(E=>e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-xs font-bold text-white/55",children:E},E))})]}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:(w=O.textAds)==null?void 0:w.map((E,ge)=>e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsx(as,{className:"h-5 w-5 text-lime-200"}),e.jsx("p",{className:"mt-3 text-xs font-black uppercase text-white/35",children:E.channel}),e.jsx("h3",{className:"mt-2 text-lg font-black",children:E.headline}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/55",children:E.body}),e.jsxs("p",{className:"mt-3 text-xs font-black text-lime-100",children:["CTA · ",E.cta]})]},`${E.channel}-${ge}`))}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:(x=O.visualConcepts)==null?void 0:x.map((E,ge)=>e.jsxs("article",{className:"rounded-3xl border border-fuchsia-200/12 bg-fuchsia-200/[0.04] p-5",children:[e.jsx(Ir,{className:"h-5 w-5 text-fuchsia-200"}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:E.name}),e.jsx("p",{className:"mt-1 text-xs font-black uppercase text-white/30",children:E.format}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/55",children:E.prompt}),e.jsxs("p",{className:"mt-3 rounded-xl bg-black/25 p-3 text-xs font-bold text-fuchsia-100",children:["Overlay: ",E.overlayText||"No text"]})]},`${E.name}-${ge}`))}),O.video&&e.jsxs("article",{className:"rounded-3xl border border-sky-200/12 bg-sky-200/[0.04] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(Es,{className:"h-5 w-5 text-sky-200"}),e.jsx("h3",{className:"mt-3 text-xl font-black",children:O.video.hook})]}),e.jsx("span",{className:"rounded-full border border-sky-200/15 bg-sky-200/10 px-3 py-1 text-xs font-black text-sky-100",children:"Production package"})]}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/55",children:O.video.script}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:(D=O.video.shots)==null?void 0:D.map((E,ge)=>e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-black/20 p-3",children:[e.jsx("p",{className:"text-xs font-black text-sky-100",children:E.seconds}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-5 text-white/45",children:E.visual})]},ge))}),e.jsx("p",{className:"mt-4 rounded-2xl border border-white/10 bg-black/20 p-3 text-xs font-semibold leading-5 text-white/42",children:"The agency has generated the storyboard manifest and timed caption file. Final motion rendering becomes automatic when a verified video provider adapter is connected; until then this is honestly labeled as a production package, not a finished video."})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsx(Rt,{className:"h-5 w-5 text-amber-200"}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:(ae=O.article)==null?void 0:ae.title}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/50",children:(je=O.article)==null?void 0:je.thesis})]}),e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsx(as,{className:"h-5 w-5 text-rose-200"}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:(Ue=O.pr)==null?void 0:Ue.headline}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/50",children:(ot=O.pr)==null?void 0:ot.summary})]})]})]}):e.jsxs("div",{className:"flex min-h-[320px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 text-center",children:[e.jsx(ye,{className:"h-10 w-10 text-fuchsia-200"}),e.jsx("h3",{className:"mt-4 text-xl font-black",children:"Approve a Creative Brain recommendation"}),e.jsx("p",{className:"mt-2 max-w-md text-sm font-semibold leading-6 text-white/40",children:"The agency builds the full package automatically: ads, visual directions, video storyboard, article, PR angle, campaign variants, UTMs, budget envelope, and launch record. No second form."})]})})]})]})}function Zi(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function oc(){const[i,p]=r.useState({packages:[],connection:{status:"not_connected",configured:!1},coverage:[]}),[u,M]=r.useState(0),[o,B]=r.useState(""),[g,_]=r.useState(""),S=async()=>{B("");try{const j=await fetch(`${m}/api/admin/advertising/distribution`,{credentials:"include",headers:Zi()}),z=await j.json().catch(()=>({}));if(!j.ok)throw new Error(z.error||"Distribution work could not be loaded.");p(z)}catch(j){B(j instanceof Error?j.message:"Distribution work could not be loaded.")}};r.useEffect(()=>{S()},[]);const Q=async j=>{var z;M(j.id),B(""),_("");try{const G=await fetch(`${m}/api/admin/advertising/distribution/${j.id}/approve`,{method:"POST",credentials:"include",headers:Zi(),body:"{}"}),Z=await G.json().catch(()=>({}));if(!G.ok)throw new Error(Z.error||"The package could not be approved.");_(Z.status==="delivered"?`Approved and delivered. Provider receipt: ${((z=Z.receipt)==null?void 0:z.externalId)||"recorded"}.`:"Approved and export-ready. Nothing was sent because no verified PR submission adapter is connected."),await S()}catch(G){B(G instanceof Error?G.message:"The package could not be approved.")}finally{M(0)}}
50,P=async j=>{var z;await((z=navigator.clipboard)==null?void 0:z.writeText(JSON.stringify(j.package,null,2))),_("The complete PR package was copied.")};return e.jsxs("section",{className:"rounded-[2rem] border border-white/10 bg-[#080b09] p-5 shadow-2xl shadow-black/35 lg:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] text-rose-100/48",children:"Earned media and owned content"}),e.jsx("h2",{className:"mt-2 text-2xl font-black",children:"Distribution & PR desk"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/48",children:"The agency turns approved campaigns into source-linked press packages, articles and submission receiptsâwithout pretending an unconnected channel was published."})]}),e.jsxs("div",{className:`flex items-center gap-3 rounded-2xl border px-4 py-3 ${i.connection.status==="connected"||i.connection.status==="verified"?"border-emerald-300/20 bg-emerald-300/10":"border-white/10 bg-white/[0.035]"}`,children:[e.jsx(un,{className:"h-5 w-5 text-teal-200"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black",children:i.connection.displayName||"PR delivery adapter"}),e.jsx("p",{className:"mt-0.5 text-xs font-bold text-white/38",children:i.connection.status.replaceAll("_"," ")})]})]})]}),o&&e.jsx("div",{className:"mt-5 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-4 text-sm font-bold text-rose-100",children:o}),g&&e.jsx("div",{className:"mt-5 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-4 text-sm font-bold text-emerald-100",children:g}),e.jsxs("div",{className:"mt-6 grid gap-5 xl:grid-cols-[1.15fr_0.85fr]",children:[e.jsx("div",{className:"space-y-4",children:i.packages.length?i.packages.map(j=>{var z;return e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full bg-rose-200/10 px-3 py-1 text-xs font-black uppercase text-rose-100",children:j.status.replaceAll("_"," ")}),j.campaign_name&&e.jsx("span",{className:"text-xs font-bold text-white/32",children:j.campaign_name})]}),e.jsx("h3",{className:"mt-3 text-xl font-black",children:j.package.headline||j.title}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/55",children:j.package.summary})]}),e.jsx(as,{className:"h-6 w-6 shrink-0 text-rose-200"})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-white/8 bg-white/[0.025] p-4",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.16em] text-white/32",children:"Editorial angle"}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/52",children:j.package.angle})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:(z=j.package.targetMediaTypes)==null?void 0:z.map(G=>e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-xs font-bold text-white/48",children:G},G))}),j.receipt&&e.jsx("div",{className:"mt-4 rounded-2xl border border-emerald-300/15 bg-emerald-300/[0.055] p-3 text-xs font-bold leading-5 text-emerald-100",children:j.receipt.externalId?`${j.receipt.provider}: ${j.receipt.externalId} · ${j.receipt.providerStatus}`:j.receipt.reason}),e.jsxs("div",{className:"mt-5 flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>P(j),className:"inline-flex h-11 items-center gap-2 rounded-full border border-white/10 px-4 text-sm font-black",children:[e.jsx(Od,{className:"h-4 w-4"}),"Copy package"]}),j.package.sourceUrl&&e.jsxs("a",{href:j.package.sourceUrl,target:"_blank",rel:"noreferrer",className:"inline-flex h-11 items-center gap-2 rounded-full border border-white/10 px-4 text-sm font-black",children:[e.jsx(sa,{className:"h-4 w-4"}),"Review source page"]}),!["delivered","export_ready"].includes(j.status)&&e.jsxs("button",{onClick:()=>Q(j),disabled:u===j.id,className:"inline-flex h-11 items-center gap-2 rounded-full bg-white px-5 text-sm font-black text-black disabled:opacity-45",children:[u===j.id?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ce,{className:"h-4 w-4"}),"Approve"]})]})]},j.id)}):e.jsxs("div",{className:"flex min-h-[320px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 text-center",children:[e.jsx(bn,{className:"h-9 w-9 text-rose-200"}),e.jsx("h3",{className:"mt-4 text-xl font-black",children:"No PR package yet"}),e.jsx("p",{className:"mt-2 max-w-md text-sm font-semibold leading-6 text-white/40",children:"Approve a Creative Brain opportunity. The agency will write, source-link and package the PR work automatically."})]})}),e.jsxs("aside",{className:"space-y-4",children:[e.jsxs("article",{className:"rounded-3xl border border-teal-200/15 bg-teal-200/[0.05] p-5",children:[e.jsx(qe,{className:"h-5 w-5 text-teal-200"}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:"Truthful delivery states"}),e.jsxs("div",{className:"mt-4 space-y-3 text-sm font-semibold leading-6 text-white/50",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-white",children:"Review"})," â the AI draft is not approved."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-white",children:"Export ready"})," â approved, but no verified adapter sent it."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-white",children:"Delivered"})," â the provider returned a stored external receipt."]})]})]}),e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.035] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-white/35",children:"Coverage and feedback"}),e.jsx("h3",{className:"mt-1 text-lg font-black",children:"Latest outcomes"})]}),e.jsx(ud,{className:"h-5 w-5 text-lime-200"})]}),e.jsx("div",{className:"mt-4 space-y-3",children:i.coverage.length?
50i.coverage.map((j,z)=>e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-black/20 p-3",children:[e.jsx("p",{className:"text-xs font-black uppercase text-teal-100/55",children:j.event_type.replaceAll("_"," ")}),e.jsx("p",{className:"mt-1 text-sm font-bold",children:j.outcome||j.campaign_ref||"Recorded result"}),j.note_safe&&e.jsx("p",{className:"mt-1 text-xs font-semibold leading-5 text-white/38",children:j.note_safe})]},`${j.event_type}-${z}`)):e.jsx("p",{className:"rounded-2xl border border-dashed border-white/10 p-5 text-sm font-bold text-white/35",children:"Signed PR feedback and coverage events will appear here."})})]})]})]})]})}const yr="h-12 w-full rounded-2xl border border-white/10 bg-black/35 px-4 text-sm font-bold text-white outline-none focus:border-blue-300/50",As="w-full resize-none rounded-2xl border border-white/10 bg-black/35 px-4 py-3 text-sm font-semibold leading-6 text-white outline-none focus:border-blue-300/50";function dc(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function cc(i=0){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(i)}function xc({onCreativeReady:i}){var b,C,ne,we,be,T;const[p,u]=r.useState(null),[M,o]=r.useState(null),[B,g]=r.useState(null),[_,S]=r.useState(""),[Q,P]=r.useState(""),[j,z]=r.useState(""),G=async(l,f)=>{const le=await fetch(`${m}${l}`,{credentials:"include",headers:dc(),...f}),O=await le.json().catch(()=>({}));if(!le.ok)throw new Error(O.error||"The agency could not complete this work.");return O},Z=async()=>{P("");try{const[l,f]=await Promise.all([G("/api/admin/advertising/market-research"),G("/api/admin/advertising/brainstorm/daily")]);u(l),g(f)}catch(l){P(l instanceof Error?l.message:"Intelligence could not be loaded.")}};r.useEffect(()=>{Z()},[]);const re=l=>u(f=>f&&{...f,research:{...f.research||{},...l}}),Y=(l,f)=>{var le;return re({idealCustomerProfiles:(((le=p==null?void 0:p.research)==null?void 0:le.idealCustomerProfiles)||[]).map((O,q)=>q===l?{...O,...f}:O)})},K=async l=>{S(l),P(""),z("");try{const f=await G(l==="research"?"/api/admin/advertising/market-research/run":"/api/admin/advertising/news-research/run",{method:"POST",body:"{}"});l==="research"?u(f):g(f),o(null),z(l==="research"?"Market conclusions and customer profiles were refreshed.":"Todayâs news and seize-the-day opportunities were refreshed. Nothing was published.")}catch(f){P(f instanceof Error?f.message:"The scan failed.")}finally{S("")}},U=async()=>{if(p!=null&&p.research){S("advice"),P(""),z("");try{const l=await G("/api/admin/advertising/market-research/advice",{method:"POST",body:JSON.stringify({research:p.research})});o(l.suggestion),z("AI prepared an optimized version for comparison. It has not replaced or saved your text.")}catch(l){P(l instanceof Error?l.message:"AI advice could not be prepared.")}finally{S("")}}},J=async()=>{var l;if(p!=null&&p.research){S("save"),P(""),z("");try{const f=await G("/api/admin/advertising/market-research/current",{method:"PUT",body:JSON.stringify({research:p.research})});u(f),o(null),z(`${((l=f.review)==null?void 0:l.summary)||"AI quality review completed."} The strategy is saved for the entire agency.`)}catch(f){P(f instanceof Error?f.message:"The strategy was not saved.")}finally{S("")}}},de=async l=>{if(l.state!=="launched"){if(l.launchId){i();return}S(l.id),P(""),z("");try{await G(`/api/admin/advertising/creative-brain/ideas/${encodeURIComponent(l.id)}/approve`,{method:"POST",body:"{}"}),z("Approved. The agency created the full campaign package and geo recommendations. Choose launch regions in Creative Studio, then use one Launch Campaign button."),await Z(),i()}catch(f){P(f instanceof Error?f.message:"The campaign could not be prepared.")}finally{S("")}}};return e.jsxs("section",{className:"rounded-[2rem] border border-white/10 bg-[#09090b] p-5 shadow-2xl shadow-black/35 lg:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.18em] text-blue-100/50",children:"Research and opportunity desk"}),e.jsx("h2",{className:"mt-2 text-2xl font-black",children:"Know where to playâand why now"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/48",children:"AI turns market evidence, customer readiness and current news into editable conclusions. Every saved change passes an AI language and reputation check."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>K("research"),disabled:!!_,className:"inline-flex h-11 items-center gap-2 rounded-full border border-white/10 px-4 text-sm font-black",children:[e.jsx(xn,{className:"h-4 w-4"}),"Refresh markets"]}),e.jsxs("button",{onClick:()=>K("news"),disabled:!!_,className:"inline-flex h-11 items-center gap-2 rounded-full bg-blue-500 px-4 text-sm font-black text-white",children:[_==="news"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(bn,{className:"h-4 w-4"}),"Scan today"]})]})]}),Q&&e.jsx("div",{className:"mt-5 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-4 text-sm font-bold text-rose-100",children:Q}),j&&e.jsx("div",{className:"mt-5 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-4 text-sm font-bold text-emerald-100",children:j}),e.jsxs("article",{className:"mt-6 rounded-3xl border border-blue-300/15 bg-blue-300/[0.055] p-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx(mn,{className:"h-5 w-5 text-blue-300"}),e.jsx("h3",{className:"mt-3 text-xl font-black",children:"Executive conclusion"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white/40",children:"Edit it yourself, request AI optimization, or use both."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:U,disabled:!!_,className:"inline-flex h-11 items-center gap-2 rounded-full border border-pink-200/20 bg-pink-200/[0.07] px-4 text-sm font-black text-pink-50",children:[_==="advice"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(ts,{className:"h-4 w-4"}),"Optimize with AI"]}),e.jsxs("button",{onClick:J,disabled:!!_,className:"inline-flex h-11 items-center gap-2 rounded-full bg-white px-4 text-sm font-black text-black",children:[_==="save"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ct,{className:"h-4 w-4"}),"Save with AI Review"]})]})]}),e.jsx("textarea",{rows:5,value:((b=p==null?void 0:p.research)==null?void 0:b.summary)||"",onChange:l=>re({summary:l.target.value}),placeholder:"The agency is preparing its first market conclusion.",className:`${As} mt-4 text-base`}),(M==null?void 0:M.summary)&&e.jsxs("div",{className:"mt-4 rounded-2xl border border-pink-200/15 bg-pink-200/[0.055] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-black text-pink-100",children:"AI optimization suggestion"}),e.jsx("button",{onClick:()=>u(l=>l&&{...l,research:M}),className:"h-9 rounded-full bg-pink-200 px-4 text-sm font-black text-black",children:"Use suggestion"})]}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/62",children:M.summary}),e.jsx("p",{className:"mt-2 text-sm font-bold text-white/35",children:"Nothing changes until you use the suggestion and save."})]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{className:"h-6 w-6 text-emerald-300"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.16em] text-white/35",children:"Ideal customers"}),e.jsx("h3",{className:"text-xl font-black",children:"Different profiles for different readiness and budgets"})]})]}),e.jsx("div",{className:"mt-4 grid gap-4 xl:grid-cols-3",children:(ne=(C=p==null?void 0:p.research)==null?void 0:C.idealCustomerProfiles)==null?void 0:ne.map((l,f)=>{var le;return e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.03] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx(Rs,{className:"h-5 w-5 text-pink-300"}),e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-[12px] font-black uppercase text-white/45",children:l.readiness})]}),e.jsx("input",{value:l.label,onChange:O=>Y(f,{label:O.target.value}),className:`${yr} mt-4 text-base`,"aria-label":"Customer profile name"}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2 xl:grid-cols-1 2xl:grid-cols-2",children:[e.jsxs("label",{className:"text-sm font-black text-white/45",children:["Budget",e.jsx("input",{value:l.budgetBand,onChange:O=>Y(f,{budgetBand:O.target.value}),className:`${yr} mt-2`})]}),e.jsxs("label",{className:"text-sm font-black text-white/45",children:["Readiness",e.jsx("input",{value:l.readiness,onChange:O=>Y(f,{readiness:O.target.value}),className:`${yr} mt-2`})]})]}),e.jsxs("label",{className:"mt-3 block text-sm font-black text-white/45",children:["Buyer",e.jsx("input",{value:l.buyer,onCh
50ange:O=>Y(f,{buyer:O.target.value}),className:`${yr} mt-2`})]}),e.jsxs("label",{className:"mt-3 block text-sm font-black text-white/45",children:["Company profile",e.jsx("textarea",{rows:3,value:l.companyProfile,onChange:O=>Y(f,{companyProfile:O.target.value}),className:`${As} mt-2`})]}),e.jsxs("label",{className:"mt-3 block text-sm font-black text-white/45",children:["Best use case",e.jsx("textarea",{rows:3,value:l.useCase,onChange:O=>Y(f,{useCase:O.target.value}),className:`${As} mt-2`})]}),e.jsxs("label",{className:"mt-3 block text-sm font-black text-white/45",children:["Offer",e.jsx("textarea",{rows:2,value:l.offer,onChange:O=>Y(f,{offer:O.target.value}),className:`${As} mt-2`})]}),e.jsxs("label",{className:"mt-3 block text-sm font-black text-white/45",children:["Why now",e.jsx("textarea",{rows:3,value:l.whyNow,onChange:O=>Y(f,{whyNow:O.target.value}),className:`${As} mt-2`})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:(le=l.channels)==null?void 0:le.map(O=>e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-[12px] font-bold text-white/45",children:O},O))})]},l.id||f)})}),e.jsxs("button",{onClick:J,disabled:!!_,className:"mt-4 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-gradient-to-r from-blue-500 to-pink-500 text-base font-black text-white",children:[_==="save"?e.jsx(V,{className:"h-5 w-5 animate-spin"}):e.jsx(Ce,{className:"h-5 w-5"}),"Save All Profiles with AI Review"]})]}),e.jsx("div",{className:"mt-7 grid gap-4 md:grid-cols-2",children:(be=(we=p==null?void 0:p.research)==null?void 0:we.priorityMarkets)==null?void 0:be.map(l=>e.jsxs("article",{className:"rounded-3xl border border-white/10 bg-white/[0.025] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx(Rs,{className:"h-5 w-5 text-amber-200"}),e.jsx("span",{className:"rounded-full border border-white/10 px-2.5 py-1 text-[12px] font-black text-white/45",children:l.confidence})]}),e.jsx("h3",{className:"mt-3 text-lg font-black",children:l.market}),e.jsx("p",{className:"mt-1 text-sm font-black uppercase tracking-[0.12em] text-blue-100/48",children:l.buyer}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/48",children:l.pain}),e.jsxs("div",{className:"mt-3 rounded-xl bg-black/25 p-3 text-sm font-bold leading-5 text-amber-50/70",children:["Angle: ",l.campaignAngle]})]},`${l.market}-${l.buyer}`))}),e.jsxs("div",{className:"mt-8 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-2xl bg-pink-500 text-white",children:e.jsx(ye,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.16em] text-white/35",children:"Seize-the-day desk"}),e.jsx("h3",{className:"text-xl font-black",children:"Approval-ready opportunities"})]})]}),e.jsx("div",{className:"mt-4 grid gap-4 xl:grid-cols-3",children:(T=B==null?void 0:B.ideas)!=null&&T.length?B.ideas.map(l=>{var f,le,O;return e.jsxs("article",{className:"flex min-h-[390px] flex-col rounded-3xl border border-white/10 bg-black/25 p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.16em] text-pink-100/50",children:l.vertical}),e.jsx("h3",{className:"mt-2 text-xl font-black leading-tight",children:l.title})]}),e.jsxs("span",{className:"shrink-0 rounded-full bg-blue-200/10 px-3 py-1 text-[12px] font-black text-blue-100",children:[cc((f=l.budget)==null?void 0:f.dailyUsd),"/day"]})]}),e.jsx("p",{className:"mt-4 text-sm font-semibold leading-6 text-white/58",children:l.campaignThesis}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-white/8 bg-white/[0.025] p-3",children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.14em] text-white/32",children:"Why now"}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-5 text-white/52",children:l.marketSignal})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:(le=l.venues)==null?void 0:le.slice(0,5).map(q=>e.jsx("span",{className:"rounded-full border border-white/10 px-3 py-1 text-[12px] font-bold text-white/48",children:q},q))}),e.jsxs("div",{className:"mt-auto pt-5",children:[e.jsxs("div",{className:"mb-3 rounded-2xl bg-emerald-200/[0.07] p-3 text-sm font-bold leading-5 text-emerald-50/70",children:[l.offer," · ",((O=l.budget)==null?void 0:O.testDays)||10,"-day controlled test"]}),e.jsxs("button",{onClick:()=>de(l),disabled:!!_||l.state==="launched",className:"inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-white text-base font-black text-black transition hover:bg-blue-200 disabled:opacity-45",children:[_===l.id?e.jsx(V,{className:"h-4 w-4 animate-spin"}):l.launchId?e.jsx(as,{className:"h-4 w-4"}):e.jsx(Ce,{className:"h-4 w-4"}),l.state==="launched"?"Campaign launched":l.launchId?"Review regions & launch":"Approve"]})]})]},l.id)}):e.jsxs("div",{className:"col-span-full flex min-h-[240px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 text-center",children:[e.jsx(tt,{className:"h-8 w-8 text-blue-200"}),e.jsx("h3",{className:"mt-4 text-lg font-black",children:"Run todayâs scan"}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/40",children:"The agency will prepare opportunities; it will not publish them."})]})})]})}function ul(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function mc(i,p){return new Intl.NumberFormat("en-US",{style:"currency",currency:p||"USD",maximumFractionDigits:0}).format(Number(i||0))}function hc({openBudget:i,openIntelligence:p}){var b,C,ne,we,be;const[u,M]=r.useState(null),[o,B]=r.useState(!1),[g,_]=r.useState(!1),[S,Q]=r.useState(0),[P,j]=r.useState("USD"),[z,G]=r.useState(""),[Z,re]=r.useState(""),Y=r.useCallback(async()=>{const T=await fetch(`${m}/api/admin/advertising/agency/status`,{credentials:"include",headers:ul
50()}),l=await T.json().catch(()=>({}));if(!T.ok)throw new Error(l.error||"Agency status could not be loaded.");return M(l),Q(Number(l.monthlyCeiling||0)),j(l.currency||"USD"),l},[]);r.useEffect(()=>{Y().catch(T=>re(T instanceof Error?T.message:"Agency status could not be loaded."))},[Y]);const K=async()=>{B(!0),re(""),G("");const T=window.setInterval(()=>{Y().catch(()=>{})},1800);try{const l=await fetch(`${m}/api/admin/advertising/agency/run`,{method:"POST",credentials:"include",headers:ul(),body:"{}"}),f=await l.json().catch(()=>({}));if(!l.ok)throw new Error(f.error||"The agency run could not be completed.");await Y()}catch(l){re(l instanceof Error?l.message:"The agency run could not be completed.")}finally{window.clearInterval(T),B(!1)}},U=async()=>{if(!(S<=0)){_(!0),re(""),G("");try{const T=await fetch(`${m}/api/admin/advertising/agency/budget`,{method:"PUT",credentials:"include",headers:ul(),body:JSON.stringify({monthlyCeiling:S,currency:P,status:"approved"})}),l=await T.json().catch(()=>({}));if(!T.ok)throw new Error(l.error||"The monthly ceiling could not be approved.");G("Monthly ceiling approved. No money was spent. The agency can now prepare its first recommendations."),await Y()}catch(T){re(T instanceof Error?T.message:"The monthly ceiling could not be approved.")}finally{_(!1)}}},J=o||(u==null?void 0:u.operating),de=((b=u==null?void 0:u.latestRun)==null?void 0:b.tasks)||[];return e.jsxs("section",{className:"mt-5 overflow-hidden rounded-[2rem] border border-blue-300/20 bg-[radial-gradient(circle_at_top_left,rgba(37,99,235,0.22),transparent_42%),radial-gradient(circle_at_top_right,rgba(236,72,153,0.16),transparent_38%),#09090b] p-5 shadow-2xl shadow-black/40 lg:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-white/12 bg-white/[0.06] px-3 py-1.5 text-sm font-black text-white",children:[e.jsx(ye,{className:"h-4 w-4 text-pink-300"}),"What to do now"]}),e.jsx("h2",{className:"mt-4 text-2xl font-black sm:text-3xl",children:u!=null&&u.readyToStart?"Start the AI agency":"First, set the maximum monthly spend"}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-6 text-white/60",children:u!=null&&u.readyToStart?"One run prepares strategy, opportunities, creative direction and project budgets. Nothing is published and no money is spent.":"This is a safety ceiling, not a spending instruction. The agency uses it to prepare realistic recommendations and cannot exceed it."})]}),e.jsxs("div",{className:"w-full max-w-md rounded-3xl border border-white/10 bg-black/30 p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[J?e.jsx(V,{className:"mt-0.5 h-5 w-5 animate-spin text-amber-300"}):((C=u==null?void 0:u.latestRun)==null?void 0:C.status)==="completed"?e.jsx(Ce,{className:"mt-0.5 h-5 w-5 text-emerald-300"}):e.jsx(cn,{className:"mt-0.5 h-5 w-5 text-blue-300"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-black",children:J?"The agency is working now":((ne=u==null?void 0:u.latestRun)==null?void 0:ne.status)==="completed"?"The agency is ready":"The agency is waiting to start"}),e.jsx("p",{className:"mt-1 text-sm font-semibold leading-5 text-white/45",children:(u==null?void 0:u.nextStep)||"Checking readinessâ¦"})]})]}),u!=null&&u.readyToStart?e.jsxs("button",{onClick:K,disabled:J,className:"mt-4 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-gradient-to-r from-blue-500 via-fuchsia-500 to-pink-500 text-base font-black text-white shadow-lg shadow-fuchsia-950/30 disabled:opacity-50",children:[J?e.jsx(V,{className:"h-5 w-5 animate-spin"}):e.jsx(gd,{className:"h-5 w-5 fill-current"}),J?"Agency workingâ¦":u.latestRun?"Run Agency Again":"Start the AI Agency"]}):e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-[110px_1fr] gap-2",children:[e.jsxs("label",{className:"text-xs font-black text-white/55",children:["Currency",e.jsxs("select",{"aria-label":"Budget
50currency",value:P,onChange:T=>j(T.target.value),className:"mt-1 h-11 w-full rounded-xl border border-white/12 bg-black/40 px-3 text-sm font-black text-white outline-none focus:border-blue-300/60",children:[e.jsx("option",{value:"USD",children:"USD"}),e.jsx("option",{value:"EUR",children:"EUR"}),e.jsx("option",{value:"ILS",children:"ILS"}),e.jsx("option",{value:"GBP",children:"GBP"})]})]}),e.jsxs("label",{className:"text-xs font-black text-white/55",children:["Monthly maximum",e.jsx("input",{"aria-label":"Monthly maximum",type:"number",min:"1",step:"100",value:S||"",onChange:T=>Q(Number(T.target.value)),placeholder:"For example: 5,000",className:"mt-1 h-11 w-full rounded-xl border border-white/12 bg-black/40 px-3 text-base font-black text-white outline-none placeholder:text-white/25 focus:border-blue-300/60"})]})]}),e.jsxs("button",{onClick:U,disabled:g||S<=0,className:"inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-white text-base font-black text-black disabled:cursor-not-allowed disabled:opacity-40",children:[g?e.jsx(V,{className:"h-5 w-5 animate-spin"}):e.jsx(Ce,{className:"h-5 w-5"}),g?"Approvingâ¦":"Approve Monthly Ceiling"]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex h-9 w-full items-center justify-center gap-2 text-sm font-black text-white/48 hover:text-white",children:[e.jsx(gn,{className:"h-4 w-4"}),"Open budget details"]})]}),(u==null?void 0:u.readyToStart)&&e.jsxs("p",{className:"mt-3 text-center text-sm font-bold text-white/40",children:["Authority: ",mc(u.monthlyCeiling,u.currency)," per month · ",u.pendingApprovals||0," approval(s) waiting"]})]})]}),z&&e.jsx("div",{className:"mt-4 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-4 text-sm font-bold text-emerald-100",children:z}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[["1","Set one ceiling","You provide only the total monthly maximum."],["2","Run the agency","All eight AI specialists refresh their work."],["3","Approve an idea","Review the finished recommendationânot a form."],["4","Choose regions & launch","Check geographies, then use one launch button."]].map(([T,l,f])=>e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-4",children:[e.jsx("span",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-white text-sm font-black text-black",children:T}),e.jsx("p",{className:"mt-3 text-base font-black",children:l}),e.jsx("p",{className:"mt-1 text-sm font-semibold leading-5 text-white/42",children:f})]},T))}),(de.length>0||((we=u==null?void 0:u.talents)==null?void 0:we.length))&&e.jsxs("div",{className:"mt-5 rounded-3xl border border-white/10 bg-black/25 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black",children:"Your AI talent team"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white/40",children:J?"Live progress from the current agency cycle.":"Latest known work for each specialist."})]}),((be=u==null?void 0:u.latestRun)==null?void 0:be.status)==="completed"&&e.jsxs("button",{onClick:p,className:"inline-flex h-10 items-center gap-2 rounded-full border border-white/12 px-4 text-sm font-black",children:["Review the work ",e.jsx(es,{className:"h-4 w-4"})]})]}),e.jsx("div",{className:"mt-4 grid gap-2 md:grid-cols-2 xl:grid-cols-4",children:(de.length?de:(u==null?void 0:u.talents)||[]).map(T=>{const l=T.status;return e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-white/[0.025] p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-black",children:T.role}),e.jsx("span",{className:`rounded-full px-2 py-1 text-[12px] font-black uppercase ${l==="complete"||l==="ready"?"bg-emerald-300/10 text-emerald-200":l==="working"?"bg-amber-300/10 text-amber-200":"bg-white/[0.06] text-white/40"}`,children:l.replaceAll("_"," ")})]}),e.jsx("p",{className:"mt-2 min-h-10 text-sm font-semibold leading-5 text-white/40",children:"detail"in T?T.detail
50:T.lastWork||"Waiting for the first full agency run."})]},T.role)})})]}),(u==null?void 0:u.scheduledMonitoring)&&e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-sm font-bold text-emerald-200/75",children:[e.jsx(qe,{className:"h-4 w-4"}),"Results monitoring is active in the background; publishing remains approval-controlled."]}),Z&&e.jsx("div",{className:"mt-4 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-4 text-sm font-bold text-rose-100",children:Z})]})}const gl=["new","contacted","qualified","evaluation","proposal","won","lost","nurture"],pc=["low","normal","high","urgent"],qa="h-12 w-full rounded-2xl border border-white/10 bg-black/35 px-4 text-sm font-bold text-white outline-none focus:border-blue-300/50";function bc(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function en(i){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}).format(Number(i||0))}function uc(i){if(!i)return"";const p=new Date(i);if(Number.isNaN(p.getTime()))return"";const u=p.getTimezoneOffset()*6e4;return new Date(p.getTime()-u).toISOString().slice(0,16)}function gc(){const[i,p]=r.useState([]),[u,M]=r.useState({total:0,pipelineValue:0,overdue:0,byStage:{}}),[o,B]=r.useState(null),[g,_]=r.useState(null),[S,Q]=r.useState([]),[P,j]=r.useState(""),[z,G]=r.useState("all"),[Z,re]=r.useState(""),[Y,K]=r.useState(""),[U,J]=r.useState(""),[de,b]=r.useState(""),C=async(l,f)=>{const le=await fetch(`${m}${l}`,{credentials:"include",headers:bc(),...f}),O=await le.json().catch(()=>({}));if(!le.ok)throw new Error(O.error||"The leads workspace could not complete this action.");return O},ne=r.useCallback(async()=>{J("");try{const l=new URLSearchParams;z!=="all"&&l.set("stage",z),Z.trim()&&l.set("search",Z.trim());const f=await C(`/api/admin/advertising/crm/leads?${l}`);p(f.leads||[]),M(f.summary||{total:0,pipelineValue:0,overdue:0,byStage:{}}),B(le=>{var O,q;return le&&(f.leads||[]).some(Te=>Te.id===le)?le:((q=(O=f.leads)==null?void 0:O[0])==null?void 0:q.id)||null})}catch(l){J(l instanceof Error?l.message:"Leads could not be loaded.")}},[z,Z]);r.useEffect(()=>{const l=window.setTimeout(ne,250);return()=>window.clearTimeout(l)},[ne]),r.useEffect(()=>{const l=i.find(f=>f.id===o)||null;if(_(l?{...l}:null),!l){Q([]);return}C(`/api/admin/advertising/crm/leads/${l.id}/notes`).then(f=>Q(f.notes||[])).catch(f=>
50J(f instanceof Error?f.message:"Lead notes could not be loaded."))},[o,i]);const we=async()=>{if(g){K("lead"),J(""),b("");try{const l=await C(`/api/admin/advertising/crm/leads/${g.id}`,{method:"PATCH",body:JSON.stringify({stage:g.stage,owner:g.owner,priority:g.priority,nextActionAt:g.nextActionAt||null,valueUsd:g.valueUsd})});b("Lead updated. Campaign learning will use the stage and outcomeânot private notes."),_(l.lead),await ne()}catch(l){J(l instanceof Error?l.message:"Lead changes were not saved.")}finally{K("")}}},be=async l=>{var f,le;if(l.preventDefault(),!(!g||!P.trim())){K("note"),J(""),b("");try{const O=await C(`/api/admin/advertising/crm/leads/${g.id}/notes`,{method:"POST",body:JSON.stringify({note:P})});Q(q=>[O.note,...q]),j(""),b((le=(f=O.note)==null?void 0:f.review)!=null&&le.changed?"The note was corrected by AI and saved securely.":"The note passed AI quality review and was saved securely.")}catch(O){J(O instanceof Error?O.message:"The note was not saved.")}finally{K("")}}},T=r.useMemo(()=>gl.filter(l=>!["won","lost"].includes(l)).reduce((l,f)=>l+Number(u.byStage[f]||0),0),[u]);return e.jsxs("section",{className:"rounded-[2rem] border border-white/10 bg-[#09090b] p-5 shadow-2xl shadow-black/35 lg:p-7",children:[e.jsxs("div",{className:"flex flex-col gap-5 xl:flex-row xl:items-end xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.18em] text-blue-200/55",children:"Built-in lead management"}),e.jsx("h2",{className:"mt-2 text-2xl font-black",children:"Leads CRM"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm font-semibold leading-6 text-white/50",children:"Manage every demo request, owner, next action and outcome here. Contact information stays inside the admin area; private notes are encrypted and AI-reviewed before saving."})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-2xl border border-emerald-300/15 bg-emerald-300/[0.06] px-4 py-3 text-sm font-bold text-emerald-100",children:[e.jsx(qe,{className:"h-5 w-5"}),"Internal CRM is activeâno external CRM required"]})]}),U&&e.jsx("div",{className:"mt-5 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-4 text-sm font-bold text-rose-100",children:U}),de&&e.jsx("div",{className:"mt-5 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-4 text-sm font-bold text-emerald-100",children:de}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[[kl,"All leads",u.total],[fd,"Active pipeline",T],[kd,"Pipeline value",en(u.pipelineValue)],[_d,"Overdue follow-ups",u.overdue]].map(([l,f,le])=>{const O=l;return e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/[0.035] p-4",children:[e.jsx(O,{className:"h-5 w-5 text-blue-300"}),e.jsx("p",{className:"mt-3 text-sm font-bold text-white/42",children:String(f)}),e.jsx("p",{className:"mt-1 text-2xl font-black",children:String(le)})]},String(f))})}),e.jsxs("div",{className:"mt-5 flex flex-col gap-3 rounded-3xl border border-white/10 bg-black/25 p-3 lg:flex-row",children:[e.jsxs("label",{className:"relative flex-1",children:[e.jsx(Ds,{className:"pointer-events-none absolute left-4 top-3.5 h-5 w-5 text-white/30"}),e.jsx("input",{value:Z,onChange:l=>re(l.target.value),placeholder:"Search name, company, email or market",className:`${qa} pl-12`})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto",children:["all",...gl].map(l=>e.jsxs("button",{onClick:()=>G(l),className:`h-12 shrink-0 rounded-2xl px-4 text-sm font-black capitalize ${z===l?"bg-white text-black":"border border-white/10 text-white/50"}`,children:[l," ",l!=="all"&&u.byStage[l]?`(${u.byStage[l]})`:""]},l))})]}),e.jsxs("div",{className:"mt-5 grid min-h-[620px] gap-5 xl:grid-cols-[0.72fr_1.28fr]",children:[e.jsx("div",{className:"max-h-[780px] space-y-3 overflow-y-auto pr-1",children:i.length?i.map(l=>e.jsxs("button",{onClick:()=>B(l.id),className:`w-full rounded-3xl border p-4 text-left transition ${o===l.id?"border-blue-300/35 bg-blue-300/[0.09]":"border-white/10 bg-white/[0.025] hover:bg-white/[0.05]"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-black",children:l.name||"Unnamed lead"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white/48",children:l.company||l.email||"No company supplied"})]}),e.jsx("span",{className:"rounded-full border border-white/10 px-2.5 py-1 text-[12px] font-black uppercase text-white/55",children:l.stage})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-[12px] font-bold text-white/38",children:[e.jsxs("span",{children:[l.priority," priority"]}),e.jsx("span",{children:"·"}),e.jsx("span",{children:l.owner||"Unassigned"}),l.valueUsd>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("span",{children:en(l.valueUsd)})]})]}),l.nextActionAt&&e.jsxs("p",{className:`mt-3 text-sm font-bold ${new Date(l.nextActionAt)<new Date?"text-rose-200":"text-amber-100"}
50`,children:["Next: ",new Date(l.nextActionAt).toLocaleString()]})]},l.id)):e.jsxs("div",{className:"flex min-h-[280px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 p-6 text-center",children:[e.jsx(kl,{className:"h-9 w-9 text-blue-300"}),e.jsx("h3",{className:"mt-4 text-lg font-black",children:"No leads in this view"}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-white/40",children:"New demo requests will appear here automatically."})]})}),g?e.jsxs("div",{className:"rounded-3xl border border-white/10 bg-white/[0.03] p-5 lg:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-black uppercase tracking-[0.15em] text-white/35",children:["Lead #",g.id]}),e.jsx("h3",{className:"mt-1 text-2xl font-black",children:g.name||"Unnamed lead"}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white/48",children:g.company||g.vertical||"No company supplied"})]}),e.jsxs("div",{className:"flex gap-2",children:[g.email&&e.jsx("a",{href:`mailto:${g.email}`,className:"flex h-11 w-11 items-center justify-center rounded-2xl bg-white text-black","aria-label":"Email lead",children:e.jsx(_s,{className:"h-5 w-5"})}),g.phone&&e.jsx("a",{href:`tel:${g.phone}`,className:"flex h-11 w-11 items-center justify-center rounded-2xl border border-white/12","aria-label":"Call lead",children:e.jsx(hn,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"text-sm font-black text-white/50",children:["Stage",e.jsx("select",{value:g.stage,onChange:l=>_({...g,stage:l.target.value}),className:`${qa} mt-2 capitalize`,children:gl.map(l=>e.jsx("option",{value:l,children:l},l))})]}),e.jsxs("label",{className:"text-sm font-black text-white/50",children:["Priority",e.jsx("select",{value:g.priority,onChange:l=>_({...g,priority:l.target.value}),className:`${qa} mt-2 capitalize`,children:pc.map(l=>e.jsx("option",{value:l,children:l},l))})]}),e.jsxs("label",{className:"text-sm font-black text-white/50",children:["Owner",e.jsx("input",{value:g.owner,onChange:l=>_({...g,owner:l.target.value}),placeholder:"Assign an owner",className:`${qa} mt-2`})]}),e.jsxs("label",{className:"text-sm font-black text-white/50",children:["Opportunity value (USD)",e.jsx("input",{type:"number",min:"0",value:g.valueUsd||"",onChange:l=>_({...g,valueUsd:Number(l.target.value)}),className:`${qa} mt-2`})]}),e.jsxs("label",{className:"text-sm font-black text-white/50 sm:col-span-2",children:["Next action",e.jsx("input",{type:"datetime-local",value:uc(g.nextActionAt),onChange:l=>_({...g,nextActionAt:l.target.value?new Date(l.target.value).toISOString():null}),className:`${qa} mt-2`})]})]}),e.jsxs("button",{onClick:we,disabled:Y==="lead",className:"mt-4 inline-flex h-12 w-full items-center justify-center gap-2 rounded-2xl bg-blue-500 text-base font-black text-white disabled:opacity-50",children:[e.jsx(Ct,{className:"h-5 w-5"}),"Save lead"]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-black/25 p-4",children:[e.jsx(ss,{className:"h-4 w-4 text-pink-300"}),e.jsx("p",{className:"mt-2 text-sm font-black",children:"Request"}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/48",children:g.message||"No message supplied."})]}),e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-black/25 p-4",children:[e.jsx("p",{className:"text-sm font-black",children:"Attribution"}),e.jsxs("div",{className:"mt-2 space-y-1 text-sm font-semibold text-white/45",children:[e.jsxs("p",{children:["Source: ",g.utmSource||"Direct / unknown"]}),e.jsxs("p",{children:["Campaign: ",g.utmCampaign||"Not tagged"]}),e.jsxs("p",{children:["Market: ",g.vertical||"Not supplied"]}),e.jsxs("p",{children:["Created: ",g.createdAt?new Date(g.createdAt).toLocaleString():"Unknown"]})]})]})]}),e.jsxs("form",{onSubmit:be,className:"mt-5 rounded-3xl border border-fuchsia-300/15 bg-fuchsia-300/[0.045] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wd,{className:"h-5 w-5 text-pink-300"}),e.jsx("p",{className:"text-base font-black",children:"Private lead notes"})]}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-5 text-white/42",children:"Every note is checked for spelling, grammar and professional tone, then encrypted before storage."}),e.jsx("textarea",{rows:3,value:P,onChange:l=>j(l.target.value),placeholder:"Write a private follow-up noteâ¦",className:"mt-3 w-full resize-none rounded-2xl border border-white/10 bg-black/35 px-4 py-3 text-sm font-semibold leading-6 text-white outline-none focus:border-pink-300/50"}),e.jsx("button",{disabled:!P.trim()||Y==="note",className:"mt-3 h-11 w-full rounded-2xl bg-white text-sm font-black text-black disabled:opacity-40",children:"Save AI-reviewed note"}),e.jsx("div",{className:"mt-4 space-y-2",children:S.map(l=>{var f;return e.jsxs("div",{className:"rounded-2xl border border-white/8 bg-black/25 p-3",children:[e.jsx("p",{className:"text-sm font-semibold leading-6 text-white/62",children:l.note}),e.jsxs("p",{className:"mt-2 text-[12px] font-bold text-white/30",children:[l.author," · ",l.createdAt?new Date(l.createdAt).toLocaleStr
50ing():"Saved",(f=l.review)!=null&&f.changed?" · AI corrected":" · AI checked"]})]},l.id)})})]})]}):e.jsx("div",{className:"flex items-center justify-center rounded-3xl border border-dashed border-white/12 text-sm font-bold text-white/35",children:"Select a lead to manage it."})]})]})}const fc=["Challenge our current advertising strategy. What are we getting wrong?","Why are these our ideal customers, and who are we overlooking?","What should we expect from our current monthly ceiling?","Refine the executive conclusion and explain every important change."];function kc(){const i=sessionStorage.getItem("adminToken");return{"Content-Type":"application/json",...i?{"X-Admin-Token":i}:{}}}function wc(i){const p=typeof i=="string"?i.trim():"";return!p||/command denied|access denied|marketing_app|marketing_mastermind_|\b(?:select|insert|update|delete)\b.+\btable\b|\bER_[A-Z_]+\b/i.test(p)?"The AI Mastermind is temporarily unavailable while its private workspace is being prepared. Please try again shortly.":p}function jc({content:i}){return e.jsx("div",{className:"mt-2 text-sm font-semibold leading-7",children:e.jsx(pn,{components:{h1:({children:p})=>e.jsx("h1",{className:"mb-3 mt-5 text-xl font-black first:mt-0",children:p}),h2:({children:p})=>e.jsx("h2",{className:"mb-2 mt-5 text-lg font-black first:mt-0",children:p}),h3:({children:p})=>e.jsx("h3",{className:"mb-2 mt-4 text-base font-black first:mt-0",children:p}),p:({children:p})=>e.jsx("p",{className:"mb-3 last:mb-0",children:p}),strong:({children:p})=>e.jsx("strong",{className:"font-black",children:p}),em:({children:p})=>e.jsx("em",{className:"font-semibold italic opacity-85",children:p}),ul:({children:p})=>e.jsx("ul",{className:"my-3 list-disc space-y-2 pl-5 marker:text-pink-300",children:p}),ol:({children:p})=>e.jsx("ol",{className:"my-3 list-decimal space-y-2 pl-5 marker:font-black marker:text-blue-300",children:p}),li:({children:p})=>e.jsx("li",{className:"pl-1 text-sm leading-6",children:p}),blockquote:({children:p})=>e.jsx("blockquote",{className:"my-3 border-l-4 border-fuchsia-300/50 bg-fuchsia-300/[0.06] px-4 py-2 italic",children:p}),a:({href:p,children:u})=>e.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",className:"font-bold text-blue-300 underline decoration-blue-300/40 underline-offset-2 hover:text-blue-200",children:u}),code:({children:p})=>e.jsx("code",{className:"rounded bg-black/30 px-1.5 py-0.5 font-mono text-[12px] font-bold text-emerald-200",children:p}),hr:()=>e.jsx("hr",{className:"my-4 border-white/10"})},children:i})})}function Nc(){const[i,p]=r.useState(null),[u,M]=r.useState([]),[o,B]=r.useState([]),[g,_]=r.useState([]),[S,Q]=r.useState(null),[P,j]=r.useState(!1),[z,G]=r.useState(""),[Z,re]=r.useState(""),[Y,K]=r.useState(""),[U,J]=r.useState(""),[de,b]=r.useState(!1),[C,ne]=r.useState(""),[we,be]=r.useState(""),T=r.useRef(null),l=r.useRef(null),f=async(w,x)=>{const D=await fetch(`${m}${w}`,{credentials:"include",headers:kc(),...x}),ae=await D.json().catch(()=>({}));if(!D.ok)throw new Error(wc(ae.error)||"The AI Mastermind could not complete this action.");return ae},le=async()=>{var w;try{const x=await f("/api/admin/advertising/mastermind");p(x.thread),M(x.messages||[]),B(x.proposals||[]),_(x.contextSources||[]),Q(x.settings||null),G(((w=x.settings)==null?void 0:w.customPrompt)||"")}catch(x){ne(x instanceof Error?x.message:"The AI Mastermind could not be loaded.")}};r.useEffect(()=>{le()},[]),r.useEffect(()=>{const w=l.current;w&&(w.scrollTop=w.scrollHeight)},[u,o,U]),r.useEffect(()=>()=>{var w,x;(w=T.current)==null||w.stop(),(x=window.speechSynthesis)==null||x.cancel()},[]);const O=async(w,x="text")=>{const D=(w??Y).trim();if(!D||U)return;J("message"),ne(""),be(""),K("");const ae={id:-Date.now(),threadId:(i==null?void 0:i.id)||0,role:"user",content:D,createdAt:new Date().toISOString()};M(je=>[...je,ae]);try{const je=await f("/api/admin/advertising/mastermind/messages",{method:"POST",body:JSON.stringify({threadId:i==null?void 0:i.id,message:D,inputMode:x})});p(je.thread),M(Ue=>[...Ue.filter(ot=>ot.id!==ae.id),je.userMessage,je.assistantMessage]),B(Ue=>[...Ue,...je.proposals||[]])}catch(je){ne(je instanceof Error?je.message:"The AI Mastermind could not answer."),await le()}finally{J("")}},q=w=>{w.preventDefault(),O()},Te=async()=>{J("thread"),ne(""),be("");try{const w=await f("/api/admin/advertising/mastermind/threads",{method:"POST",body:JSON.stringify({title:"New agency strategy conversation"})});p(w.thread),M([]),B([])}catch(w){ne(w instanceof Error?w.message:"A new private conversation could not be started.")}finally{J("")}},Oe=async w=>{J(`proposal-${w.id}`),ne(""),be("");try{const x=await f(`/api/admin/advertising/mastermind/proposals/${w.id}/apply`,{method:"POST",body:"{}"});B(D=>D.map(ae=>ae.id===w.id?{...ae,status:x.status,appliedAt:new Date().toISOString()}:ae)),be(`Applied: ${w.title}. This changed internal agency guidance onlyânothing was published or spent.`)}catch(x){ne(x instanceof Error?x.message:"The refinement could not be applied.")}finally{J("")}},Ye=async()=>
50{if(!(!S||U)){J("settings"),ne(""),be("");try{const w=await f("/api/admin/advertising/mastermind/settings",{method:"PUT",body:JSON.stringify({selectedModel:S.selectedModel,customPrompt:z})});Q(w.settings),G(w.settings.customPrompt||""),be("Mastermind strategy controls saved. Future answers will use this approved model and instruction.")}catch(w){ne(w instanceof Error?w.message:"The strategy controls could not be saved.")}finally{J("")}}},Ge=async()=>{if(!(!Z.trim()||U)){J("prompt"),ne(""),be("");try{const w=await f("/api/admin/advertising/mastermind/prompt-draft",{method:"POST",body:JSON.stringify({brief:Z,currentPrompt:z})});G(w.suggestedPrompt||z),re(""),be(`AI prepared a prompt draft with ${w.model}. Review it, then save explicitly if you want to use it.`)}catch(w){ne(w instanceof Error?w.message:"The backstage prompt could not be drafted.")}finally{J("")}}},Ke=()=>{var ae;if(de){(ae=T.current)==null||ae.stop(),b(!1);return}const w=window,x=w.SpeechRecognition||w.webkitSpeechRecognition;if(!x){ne("Voice dictation is not supported by this browser. You can still type normally.");return}const D=new x;D.lang=navigator.language||"en-US",D.interimResults=!1,D.continuous=!1,D.onresult=je=>{var ot,E;const Ue=((E=(ot=je.results[0])==null?void 0:ot[0])==null?void 0:E.transcript)||"";K(ge=>`${ge}${ge?" ":""}${Ue}`)},D.onerror=()=>{b(!1),ne("Voice dictation stopped before a transcript was received.")},D.onend=()=>b(!1),T.current=D,ne(""),b(!0),D.start()},nt=w=>{if(!window.speechSynthesis)return;window.speechSynthesis.cancel();const x=new SpeechSynthesisUtterance(w);x.rate=.96,window.speechSynthesis.speak(x)};return e.jsx("section",{className:"mt-5 overflow-hidden rounded-[2rem] border border-fuchsia-300/25 bg-[radial-gradient(circle_at_10%_0%,rgba(236,72,153,0.22),transparent_36%),radial-gradient(circle_at_90%_10%,rgba(37,99,235,0.24),transparent_38%),#09090b] shadow-2xl shadow-fuchsia-950/20",children:e.jsxs("div",{className:"grid min-h-[580px] xl:grid-cols-[0.72fr_1.28fr]",children:[e.jsxs("aside",{className:"border-b border-white/10 p-6 xl:border-b-0 xl:border-r lg:p-8",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-3xl bg-gradient-to-br from-blue-500 via-fuchsia-500 to-pink-500 shadow-xl shadow-fuchsia-950/40",children:e.jsx(jd,{className:"h-8 w-8 text-white"})}),e.jsx("p",{className:"mt-6 text-sm font-black uppercase tracking-[0.2em] text-pink-200/65",children:"Chief intelligence"}),e.jsx("h2",{className:"mt-2 text-3xl font-black leading-tight",children:"AI Mastermind"}),e.jsx("p",{className:"mt-3 text-base font-semibold leading-7 text-white/58",children:"Your senior commercial strategist: sharpen the buyer, offer, proof, objections, and next moveânot a pile of generic advice."}),e.jsxs("button",{onClick:()=>j(w=>!w),className:"mt-5 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl border border-fuchsia-200/25 bg-fuchsia-200/[0.07] text-sm font-black text-fuchsia-50",children:[e.jsx(Vo,{className:"h-4 w-4"}),"Strategist controls",e.jsx(Go,{className:`h-4 w-4 transition ${P?"rotate-180":""}`})]}),P&&S&&e.jsxs("div",{className:"mt-3 space-y-3 rounded-3xl border border-fuchsia-200/20 bg-black/35 p-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.15em] text-white/45",children:"Approved thinking model"}),e.jsx("select",{value:S.selectedModel,onChange:w=>Q(x=>x&&{...x,selectedModel:w.target.value}),className:"mt-1.5 h-11 w-full rounded-xl border border-white/10 bg-black/40 px-3 text-sm font-bold text-white outline-none",children:S.availableModels.map(w=>e.jsxs("option",{value:w.id,children:[w.label," â ",w.description]},w.id))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-black uppercase tracking-[0.15em] text-white/45",children:"Refine backstage prompt with AI"}),e.jsxs("div",{className:"mt-1.5 flex gap-2",children:[e.jsx("input",{value:Z,onChange:w=>re(w.target.value),placeholder:"e.g. make our offers more concrete",className:"min-w-0 flex-1 rounded-xl border border-white/10 bg-black/40 px-3 text-sm font-semibold text-white outline-none placeholder:text-white/25"}),e.jsxs("button",{type:"button",onClick:Ge,disabled:!Z.trim()||!!U,className:"inline-flex h-11 shrink-0 items-center gap-1.5 rounded-xl border border-blue-200/25 bg-blue-400/10 px-3 text-xs font-black text-blue-100 disabled:opacity-45",children:[e.jsx(ts,{className:"h-3.5 w-3.5"}),"Draft"]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] font-black uppercase tracking-[0.15em] text-white/45",children:["Backstage instruction ",e.jsx("span",{className:"normal-case tracking-normal text-white/25",children:"(optional; blank uses the sales-strategy default)"})]}),e.jsx("textarea",{value:z,onChange:w=>G(w.target.value),rows:8,maxLength:12e3,className:"mt-1.5 w-full resize-y rounded-xl border border-white/10 bg-black/40 p-3 text-xs font-semibold leading-5 text-white/80 outline-none"})]}),e.jsxs("button",{onClick:Ye,disabled:!!U,className:"inline-flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-white text-sm font-black text-black disabled:opacity-50",children:[U==="settings"?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ct,{className:"h-4 w-4"}),"Save strategy controls"]}
50),e.jsx("p",{className:"text-[11px] font-semibold leading-4 text-white/35",children:"Only approved models are available. Keys and customer records are never shown here; an AI draft is never applied until you save it."})]}),e.jsxs("div",{className:"mt-5 rounded-3xl border border-white/10 bg-black/25 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-black text-emerald-100",children:[e.jsx(qe,{className:"h-5 w-5"}),"Understands the live agency"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:g.map(w=>e.jsx("span",{className:"rounded-full border border-white/10 bg-white/[0.035] px-3 py-1.5 text-[12px] font-bold text-white/45",children:w},w))}),e.jsx("p",{className:"mt-3 text-sm font-semibold leading-5 text-white/35",children:"It sees aggregated CRM totals, never lead contact details or private notes."})]}),e.jsxs("div",{className:"mt-5",children:[e.jsx("p",{className:"text-sm font-black text-white/55",children:"Good ways to begin"}),e.jsx("div",{className:"mt-3 space-y-2",children:fc.map(w=>e.jsx("button",{onClick:()=>O(w),disabled:!!U,className:"w-full rounded-2xl border border-white/10 bg-white/[0.035] px-4 py-3 text-left text-sm font-bold leading-5 text-white/62 transition hover:border-pink-200/25 hover:bg-pink-200/[0.07]",children:w},w))})]}),e.jsxs("button",{onClick:Te,disabled:!!U,className:"mt-5 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl border border-white/12 text-sm font-black text-white/65",children:[e.jsx(Ls,{className:"h-4 w-4"}),"New private conversation"]})]}),e.jsxs("div",{className:"flex min-h-[580px] flex-col p-4 sm:p-6 lg:p-7",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-white/10 pb-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full bg-emerald-300 shadow-[0_0_18px_rgba(110,231,183,0.8)]"}),e.jsx("p",{className:"text-base font-black",children:"Ready to think with you"})]}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-white/38",children:(i==null?void 0:i.title)||"Your first conversation will be encrypted and saved here."})]}),e.jsx(fa,{className:"h-6 w-6 text-blue-300"})]}),e.jsxs("div",{ref:l,className:"flex-1 space-y-4 overflow-y-auto py-5 pr-1",children:[!u.length&&e.jsxs("div",{className:"flex min-h-[260px] flex-col items-center justify-center rounded-3xl border border-dashed border-white/12 p-8 text-center",children:[e.jsx(ye,{className:"h-10 w-10 text-pink-300"}),e.jsx("h3",{className:"mt-4 text-xl font-black",children:"What should we think through?"}),e.jsx("p",{className:"mt-2 max-w-lg text-sm font-semibold leading-6 text-white/42",children:"Ask about budget, audiences, positioning, current recommendations, campaign logic, creative choices, resultsâor request a concrete refinement."})]}),u.map(w=>{var x;return e.jsx("div",{className:`flex ${w.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("article",{className:`max-w-[92%] rounded-3xl px-5 py-4 sm:max-w-[82%] ${w.role==="user"?"rounded-br-lg bg-white text-black":"rounded-bl-lg border border-blue-300/15 bg-blue-300/[0.065] text-white"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:`text-[12px] font-black uppercase tracking-[0.14em] ${w.role==="user"?"text-black/45":"text-blue-200/65"}`,children:w.role==="user"?"You":"AI Mastermind"}),w.role==="assistant"&&e.jsx("button",{onClick:()=>nt(w.content),className:"rounded-full p-1.5 text-white/35 hover:bg-white/10 hover:text-white","aria-label":"Read response aloud",children:e.jsx(Nd,{className:"h-4 w-4"})})]}),e.jsx(jc,{content:w.content}),((x=w.meta)==null?void 0:x.confidence)&&e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 border-t border-current/10 pt-3 text-[12px] font-bold opacity-55",children:[e.jsxs("span",{children:[w.meta.confidence," confidence"]}),w.meta.model&&e.jsxs("span",{children:["· ",w.meta.model]})]})]})},w.id)}),U==="message"&&e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"inline-flex items-center gap-3 rounded-3xl rounded-bl-lg border border-pink-300/15 bg-pink-300/[0.06] px-5 py-4 text-sm font-bold text-pink-50",children:[e.jsx(V,{className:"h-5 w-5 animate-spin"}),"The Mastermind is examining the whole agencyâ¦"]})}),o.map(w=>e.jsx("article",{className:"ml-auto max-w-[92%] rounded-3xl border border-amber-300/20 bg-amber-300/[0.065] p-4 sm:max-w-[82%]",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-2xl bg-amber-200 text-black",children:e.jsx(ye,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[12px] font-black uppercase tracking-[0.14em] text-amber-100/60",children:"Proposed refinement"}),e.jsx("h4",{className:"mt-1 text-base font-black",children:w.title}),e.jsx("p",{className:"mt-2 text-sm font-semibold leading-6 text-white/50",children:w.summary}),w.status==="proposed"?e.jsxs("button",{onClick:()=>Oe(w),disabled:!!U,className:"mt-3 inline-flex h-11 w-full items-center justify-center gap-2 rounded-2xl bg-amber-200 text-sm font-black text-black disabled:opacity-50",children:[U===`proposal-${w.id}`?e.jsx(V,{className:"h-4 w-4 animate-spin"}):e.jsx(Ce,{className:"h-4 w-4"}),"Approve & Apply"]}):e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 text-sm font-black text-emerald-200",children:[e.jsx(Ce,{className:"h-4 w-4"}),"Applied to internal agency guidance"]})]})]})},w.id))]}),C&&e.jsx("div",{className:"mb-3 rounded-2xl border border-rose-300/20 bg-rose-300/10 p-3 text-sm font-bold text-rose-100",children:C}),we&&e.jsx("div",{className:"mb-3 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 p-3 text-sm font-bold text-emerald-100",children:we}),e.jsxs("form",{onSubmit:q,className:"rounded-3xl border border-white/12 bg-black/35 p-3 shadow-xl",children:[e.jsx("textarea",{rows:3,value:Y,onChange:w=>K(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),O())},placeholder:"Explain, question, challenge, or request a changeâ¦",className:"w-full resize-none bg-transparent px-2 py-1 text-base font-semibold leading-6 text-white outline-none placeholder:text-white/25"}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ke,className:`flex h-11 w-11 items-center justify-center rounded-2xl border ${de?"border-rose-300/30 bg-rose-300/15 text-rose-100":"border-white/10 text-white/55"}`,"aria-label":de?"Stop dictation":"Dictate message",children:de?e.jsx(vd,{className:"h-5 w-5"}):e.jsx(jl,{className:"h-5 w-5"})}),e.jsx("p",{className:"hidden text-sm font-semibold text-white/30 sm:block",children:de?"Listeningâ¦":"Enter to send · Shift+Enter for a new line"})]}),e.jsxs("button",{disabled:!Y.trim()||!!U,className:"inline-flex h-11 items-center gap-2 rounded-2xl bg-gradient-to-r from-blue-500 via-fuchsia-500 to-pink-500 px-5 text-sm font-black text-white disabled:opacity-35",children:[e.jsx(wl,{className:"h-4 w-4"}),"Send"]})]})]}),e.jsx("p",{className:"mt-3 text-center text-[12px] font-bold text-white/28",children:"Conversation is encrypted. Refinements require approval. Publishing, spend, outreach and credentials remain outside chat."})]})]})})}
50const vc=[{id:"agency",label:"Agency",description:"Budget, brand, access and approvals",icon:ss},{id:"intelligence",label:"Intelligence",description:"Markets, customers, news and opportunities",icon:mn},{id:"creative",label:"Creative",description:"Ads, images, video, articles and production",icon:yl},{id:"distribution",label:"Distribution & PR",description:"Submission packages, delivery and coverage",icon:as},{id:"campaigns",label:"Campaigns & Learning",description:"Launches, results, stop rules and recommendations",icon:Sl},{id:"leads",label:"Leads CRM",description:"Owners, follow-ups, pipeline and outcomes",icon:kl},{id:"email",label:"Marketing Email",description:"Leads, offers, UTMs and delivery",icon:_s}];function yc(){const[i]=r.useState(()=>{const S=new URLSearchParams(window.location.search).get("weeklyPlan")||"";return/^[a-f0-9]{64}$/.test(S)?S:""}),[p,u]=r.useState(()=>i?"campaigns":"agency"),[M,o]=r.useState("desk"),[B,g]=r.useState(0);r.useEffect(()=>{i&&u("campaigns")},[i]);const _=()=>{o("budget"),g(S=>S+1),u("agency")};return e.jsx("main",{className:"min-h-screen bg-[#050706] px-4 py-6 text-white sm:px-6 lg:px-8",children:e.jsxs("div",{className:"mx-auto max-w-[1600px]",children:[e.jsx("header",{className:"overflow-hidden rounded-[2rem] border border-white/10 bg-[radial-gradient(circle_at_top_left,rgba(37,99,235,0.22),transparent_38%),radial-gradient(circle_at_top_right,rgba(236,72,153,0.16),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.09),transparent_30%),#08080a] p-6 shadow-2xl shadow-black/40 lg:p-8",children:e.jsxs("div",{className:"flex flex-col gap-6 xl:flex-row xl:items-end xl:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-blue-200/20 bg-blue-200/10 px-3 py-1.5 text-sm font-black uppercase tracking-[0.18em] text-blue-100",children:[e.jsx(qe,{className:"h-4 w-4"})," Supervised AI agency"]}),e.jsx("h1",{className:"mt-4 text-3xl font-black tracking-tight sm:text-4xl",children:"Advertising Center"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm font-semibold leading-6 text-white/58 sm:text-base",children:"One operating room for strategy, production, publishing and learning. The agency prepares the work; management approves the finished decision."})]}),e.jsx("div",{className:"rounded-2xl border border-pink-200/15 bg-pink-200/[0.055] px-4 py-3 text-sm font-bold text-pink-50",children:"No publishing or spend without approval"})]})}),e.jsx(Nc,{}),e.jsx(hc,{openBudget:_,openIntelligence:()=>u("intelligence")}),e.jsx("nav",{"aria-label":"Advertising workspaces",className:"sticky top-3 z-20 mt-5 grid gap-2 rounded-[1.6rem] border border-white/10 bg-[#09090b]/95 p-2 shadow-2xl shadow-black/40 backdrop-blur-xl sm:grid-cols-2 xl:grid-cols-7",children:vc.map(S=>{const Q=S.icon,P=p===S.id;return e.jsxs("button",{type:"button",onClick:()=>u(S.id),"aria-current":P?"page":void 0,className:`flex min-h-[68px] items-center gap-3 rounded-2xl px-4 text-left transition ${P?"bg-white text-black shadow-lg":"text-white/60 hover:bg-white/[0.055] hover:text-white"}`,children:[e.jsx(Q,{className:`h-5 w-5 shrink-0 ${P?"text-blue-700":"text-blue-200"}`}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-black",children:S.label}),e.jsx("span",{className:`mt-0.5 block text-xs font-semibold leading-4 ${P?"text-black/55":"text-white/32"}`,children:S.description})]})]},S.id)})}),e.jsxs("div",{className:"mt-5",children:[p==="agency"&&e.jsx(Qd,{initialTab:M,navigationRequest:B}),p==="intelligence"&&e.jsx(xc,{onCreativeReady:()=>u("creative")}),p==="creative"&&e.jsx(nc,{}),p==="distribution"&&e.jsx(oc,{}),p==="campaigns"&&e.jsx(ic,{weeklyPlanId:i||void 0,onOpenCreative:()=>u("creative")}),p==="leads"&&e.jsx(gc,{}),p==="email"&&e.jsx(Qo,{audienceScope:"marketing"})]})]})})}const Nl=()=>{if(typeof window>"u")return!1;const i=window.location.hostname.toLowerCase();return new Set(["emotionlogic.ai","www.emotionlogic.ai","me.emotionlogic.ai","app.emotionlogic.ai","jp.me.emotionlogic.ai","ca.me.emotionlogic.ai","us.me.emotionlogic.ai","eu.me.emotionlogic.ai","il.me.emotionlogic.ai","br.me.emotionlogic.ai","in.me.emotionlogic.ai","za.me.emotionlogic.ai"]).has(i)},Sc=()=>Nl()?"global":"local",Cc=()=>typeof window>"u"?!1:/^[a-f0-9]{64}
50$/.test(new URLSearchParams(window.location.search).get("weeklyPlan")||""),tn=25*1024*1024,an={serialNumber:"",title:"Emotion Logic Proposal",clientName:"",clientCompany:"",clientEmail:"",clientPhone:"",status:"draft",currency:"USD",validUntil:"",executiveSummary:"Emotion Logic provides advanced voice intelligence that combines Layered Voice Analysis (LVA) with AI workflows to help teams understand stress, uncertainty, engagement, emotional dissonance, and risk signals in recorded or live conversations. This proposal outlines the commercial access required for the client to use Emotion Logic capabilities across FeelGPT, AppTone, and API-based voice analysis workflows.",scope:"",deliverables:"",terms:"Pricing excludes applicable taxes. Proposal is subject to mutual written agreement.",notes:"",discountType:"percent",discountValue:0,items:[]},vl=()=>{const i=new Date,p=u=>String(u).padStart(2,"0");return["ELQ",`${i.getFullYear()}${p(i.getMonth()+1)}${p(i.getDate())}`,`${p(i.getHours())}${p(i.getMinutes())}${p(i.getSeconds())}`].join("-")},Tc=()=>{const i=new Date,p=u=>String(u).padStart(2,"0");return`${i.getFullYear()}-${p(i.getMonth()+1)}-${p(i.getDate())}`},Ac=[{description:"FeelGPT minutes",quantity:1e3,unitPrice:0,catalogDescription:"Full LVA, diarization, transcript, and AI interpretation minutes for deeper emotional and conversational analysis."},{description:"FeelGPT Professional minutes",quantity:1e3,unitPrice:0,catalogDescription:"Professional-tier FeelGPT analysis minutes for full LVA, transcript, diarization, AI summaries, and case-ready reporting."},{description:"AppTone tests",quantity:100,unitPrice:0,catalogDescription:"Structured AppTone screening sessions with configured question flow, scoring, and report review access."},{description:"Professional API minutes",quantity:1e3,unitPrice:0,catalogDescription:"Production API voice-analysis minutes for professional integrations and automated customer workflows."},{description:"Advanced API minutes",quantity:1e3,unitPrice:0,catalogDescription:"Expanded API analysis minutes for higher-volume workflows requiring richer LVA output and operational routing."},{description:"Basic API minutes",quantity:1e3,unitPrice:0,catalogDescription:"Entry-level API voice-analysis minutes for basic LVA processing and lightweight integrations."},{description:"EMLO.ME Silver subscription",quantity:1,unitPrice:0,catalogDescription:"Silver-tier EMLO.ME workspace subscription for ongoing user access, saved sessions, and standard platform functionality."},{description:"EMLO.ME Gold subscription",quantity:1,unitPrice:0,catalogDescription:"Gold-tier EMLO.ME workspace subscription for expanded access, priority capability availability, and premium platform workflows."}],sn=i=>{const p=i.toLowerCase();return p.includes("feelgpt professional")?{scope:"FeelGPT Professional analysis minutes covering full LVA processing, diarization, transcription, AI interpretation, and professional report output for selected recordings.",deliverable:"Provision of FeelGPT Professional minute allocation; access to full analysis workflow; transcript and diarization processing where applicable; AI-generated findings; downloadable session reports; and usage visibility for consumed minutes."}:p.includes("feelgpt")?{scope:"FeelGPT analysis minutes for deeper voice and conversation review using LVA outputs, transcript-supported interpretation, and AI-assisted emotional reporting.",deliverable:"Provision of FeelGPT minute allocation; access to emotional analysis workflow; AI summary generation; session-level review outputs; and usage visibility for consumed minutes."}:p.includes("apptone")?{scope:"AppTone screening tests for structured voice-based assessment using configured question flows, LVA scoring, and Emotion Logic report review tools.",deliverable:"Provision of AppTone test allocation; screening flow setup; question-set configuration; sample report review; administrator orientation; and support for initial pilot activation."}:p.includes("professional api")?{scope:"Professional API minutes for production integrations that require automated voice-analysis processing through Emotion Logic endpoints.",deliverable:"Provision of Professional API minute allocation; API access configuration; endpoint usage support; processing documentation; and usage visibility for consumed minutes."}:p.includes("advanced api")?{scope:"Advanced API minutes for higher-volume or richer LVA workflows requiring expanded voice-analysis output and operational routing support.",deliverable:"Provision of Advanced API minute allocation; access to expanded API analysis output; integration support guidance; and usage visibility for consumed minutes."}:p.includes("basic api")?{scope:"Basic API minutes for lightweight LVA processing and entry-level voice-analysis integrations.",deliverable:"Provision of Basic API minute allocation; basic endpoint access; processing guidance; and usage visibility for consumed minutes."}:p.includes("emlo.me silver")?{scope:"EMLO.ME Silver subscription access for standard workspace usage, saved sessions, and ongoing platform availability for the subscribed users.",deliverable:"Activation of EMLO.ME Silver subscription; user/workspace access setup; standard platform capability availability; and support for initial onboarding."}:p.includes("emlo.me gold")?{scope:"EMLO.ME Gold subscription access for expanded workspace usage, premium workflow availability, and higher-tier platform capabilities for the subscribed users.",deliverable:"Activation of EMLO.ME Gold subscription; user/workspace access setup; premium platform capability availability; priority workflow access; and support for initial onboarding."}:{scope:`${i} as listed in the commercial lines, delivered under the agreed Emotion Logic commercial scope.`,deliverable:`Provision of ${i}; configuration support as applicable; and usage visibility for the allocated quantity.`}},Sr=i=>{const p=i.filter(o=>{var B;return(B=o.description)==null?void 0:B.trim()});if(!p.length)return{scope:"",deliverables:""};const u=p.map((o,B)=>{const g=sn(o.description);return`${B+1}. ${g.scope}`}),M=p.map((o,B)=>{const g=sn(o.description),_=Number(o.quantity||0),S=_>
500?` Quantity: ${_.toLocaleString()}.`:"";return`${B+1}. ${g.deliverable}${S}`});return{scope:u.join(` 51`),deliverables:M.join(` 52`)}},Ps=(i={})=>({...an,...i,serialNumber:i.serialNumber||vl(),validUntil:i.validUntil??Tc(),items:(Array.isArray(i.items)?i.items:an.items).map(p=>({...p}))}),Pc=(i,p)=>`${String(i||"USD").trim().toUpperCase()} ${Number(p||0).toLocaleString(void 0,{maximumFractionDigits:2})}`,fn=i=>{const p=String(i||"USD").trim().toUpperCase();return p==="USD"?"$":p==="EUR"?"â¬":p==="GBP"?"£":p==="ILS"?"âª":p},Cr=(i,p)=>`${fn(i)}${Number(p||0).toLocaleString(void 0,{maximumFractionDigits:2})}`,kn=i=>{var u,M;const p=((u=i.clientCompany)==null?void 0:u.trim())||((M=i.clientName)==null?void 0:M.trim());return p?`${p} Proposal`:"Emotion Logic Proposal"},$c=i=>{if(i.discountType!=="percent")return"Discount applied in this quote";const p=Number(i.discountValue||0);return!Number.isFinite(p)||p<=0?"Discount applied in this quote":`Discount applied in this quote (${p.toLocaleString(void 0,{maximumFractionDigits:2})}%)`};function Ic({proposal:i,subtotal:p,discount:u,total:M,onFieldChange:o}){const B=(_,S,Q="Click to edit")=>e.jsx("div",{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:P=>o(_,P.currentTarget.innerText),className:`${S} rounded-md outline-none transition focus:bg-amber-100/60 focus:ring-2 focus:ring-amber-300 dark:focus:bg-amber-300/10`,children:i[_]||Q}),g=(_,S)=>e.jsxs("section",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("h5",{className:"mb-2 text-[10px] font-black uppercase tracking-[0.22em] text-slate-400",children:_}),B(S,"min-h-[44px] whitespace-pre-wrap text-[12px] leading-relaxed text-slate-700")]});return e.jsxs("div",{className:"rounded-2xl border border-black/10 bg-slate-100 p-4 shadow-sm dark:border-white/10 dark:bg-zinc-900",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-black dark:text-white",children:"Preview"}),e.jsx("p",{className:"text-xs font-medium text-black/50 dark:text-white/50",children:"Client-facing quote preview. Click document text to edit."})]}),e.jsx("span",{className:"rounded-full bg-emerald-500/10 px-3 py-1 text-[10px] font-black uppercase tracking-widest text-emerald-700 dark:text-emerald-300",children:"WYSIWYG"})]}),e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-slate-50 text-slate-950 shadow-xl",children:[e.jsxs("div",{className:"relative overflow-hidden bg-slate-950 text-white",children:[e.jsx("div",{className:"absolute inset-y-0 right-0 w-1/2 bg-[radial-gradient(circle_at_top_right,rgba(20,184,166,0.34),transparent_55%)]"}),e.jsxs("div",{className:"relative px-7 py-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-5",children:[e.jsx("img",{src:"/logo_white.png",alt:"Emotion Logic",className:"h-10 w-auto object-contain"}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 px-4 py-3 text-right text-[10px] font-bold uppercase tracking-widest text-white/70",children:[e.jsx("p",{children:i.serialNumber||"ELQ"}),e.jsx("p",{className:"mt-1 text-cyan-200",children:i.status})]})]}),e.jsxs("div",{className:"mt-10 max-w-xl",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.28em] text-cyan-200",children:"Commercial Proposal"}),e.jsx("div",{className:"mt-3 text-3xl font-black leading-tight text-white",children:kn(i)}),e.jsxs("div",{className:"mt-5 grid gap-3 text-xs sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 p-4",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-white/45",children:"Prepared for"}),B("clientName","mt-1 text-lg font-black text-white","Client name"),B("clientCompany","mt-1 text-xs font-semibold text-white/65","Client company"),i.clientEmail&&e.jsx("p",{className:"mt-1 text-xs text-white/55",children:i.clientEmail}),i.clientPhone&&e.jsx("p",{className:"mt-1 text-xs text-white/55",children:i.clientPhone})]}),e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-white/5 p-4",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-white/45",children:"Valid until"}),e.jsx("p",{className:"mt-1 text-lg font-black text-white",children:i.validUntil||"Not set"}),e.jsxs("p",{className:"mt-1 text-xs font-semibold text-white/65",children:[i.currency||"USD"," quote"]})]})]})]})]})]}),e.jsxs("div",{className:"space-y-5 px-6 py-6",children:[e.jsx("div",{className:"grid gap-4",children:e.jsxs("section",{className:"rounded-2xl border border-cyan-200 bg-cyan-50 p-5",children:[e.jsx("h5",{className:"mb-2 text-[10px] font-black uppercase tracking-[0.22em] text-cyan-700",children:"Executive Snapshot"}),B("executiveSummary","min-h-[72px] whitespace-pre-wrap text-[13px] leading-relaxed text-slate-800")]})}),g("Scope","scope"),g("Deliverables","deliverables"),e.jsxs("section",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h5",{className:"text-[10px] font-black uppercase tracking-[0.22em] text-slate-400",children:"Commercial Lines"}),e.jsxs("p",{className:"mt-1 text-xs font-semibold text-slate-500",children:[i.items.length," line items included in this quote"]})]}),e.jsx("div",{className:"rounded-full bg-slate-950 px-3 py-1 text-[10px] font-black uppercase tracking-widest text-white",children:i.currency||"USD"})]}),e.jsxs("div",{className:"overflow-hidden rounded-xl border border-slate-200",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_64px_84px_96px] bg-slate-100 px-3 py-2 text-[10px] font-black uppercase tracking-widest text-slate-500",children:[e.jsx("span",{children:"Description"}),e.jsx("span",{className:"text-right",children:"Qty"}),e.jsx("span",{className:"text-right",children:"Unit"}),e.jsx("span",{className:"text-right",children:"Line"})]}),i.items.map((_,S)=>{const Q=Number(_.quantity||0)*Number(_.unitPrice||0);return e.jsxs("div",{className:"grid grid-cols-[1fr_64px_84px_96px] border-t border-slate-100 px-3 py-3 text-[11px] text-slate-700",children:[e.jsx("span",{className:"font-bold",children:_.description||"Commercial line"}),e.jsx("span",{className:"text-right",children:Number(_.quantity||0).toLocaleStr
52ing()}),e.jsx("span",{className:"text-right",children:Cr(i.currency,Number(_.unitPrice||0))}),e.jsx("span",{className:"text-right font-black text-slate-900",children:Cr(i.currency,Q)})]},`${_.description}-${S}`)}),e.jsx("div",{className:"border-t border-slate-200 bg-slate-50 px-3 py-3 text-[11px] text-slate-700",children:e.jsxs("div",{className:"ml-auto grid max-w-xs gap-2",children:[e.jsxs("div",{className:"flex justify-between gap-5",children:[e.jsx("span",{children:"Subtotal before discount"}),e.jsx("span",{className:"font-bold",children:Cr(i.currency,p)})]}),e.jsxs("div",{className:"flex justify-between gap-5 text-emerald-700",children:[e.jsx("span",{children:$c(i)}),e.jsxs("span",{className:"font-bold",children:["-",Cr(i.currency,u)]})]}),e.jsxs("div",{className:"flex justify-between gap-5 border-t border-slate-200 pt-2 text-sm text-slate-950",children:[e.jsx("span",{className:"font-black",children:"Final price"}),e.jsx("span",{className:"font-black",children:Pc(i.currency,M)})]})]})})]})]}),g("Terms","terms"),i.notes?g("Notes","notes"):null,e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-5 shadow-sm",children:[e.jsxs("div",{className:"grid gap-3 text-[10px] font-bold uppercase tracking-widest text-slate-400 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-dashed border-slate-300 p-4",children:[e.jsx("p",{children:"Client approval"}),e.jsx("div",{className:"mt-8 border-t border-slate-300 pt-2",children:"Name / signature"})]}),e.jsxs("div",{className:"rounded-xl border border-dashed border-slate-300 p-4",children:[e.jsx("p",{children:"Emotion Logic approval"}),e.jsx("div",{className:"mt-8 border-t border-slate-300 pt-2",children:"Authorized representative"})]})]}),e.jsxs("div",{className:"mt-5 flex items-center justify-between gap-4 border-t border-slate-200 pt-4",children:[e.jsx("img",{src:"/logo_full_dark.png",alt:"Emotion Logic",className:"h-7 w-auto object-contain"}),e.jsx("p",{className:"text-right text-[10px] font-bold uppercase tracking-widest text-slate-400",children:"Voice intelligence · LVA · AI workflows"})]})]})]})]})]})}const fl=(i,p)=>{const u=URL.createObjectURL(i),M=document.createElement("a");M.href=u,M.download=p,document.body.appendChild(M),M.click(),M.remove(),URL.revokeObjectURL(u)},Ec=i=>{var o;const p=(i==null?void 0:i.geo)||((o=i==null?void 0:i.metadata)==null?void 0:o.geo)||{},u=[p.city,p.region,p.countryCode||p.country].filter(Boolean).join(", "),M=[p.provider,p.asn].filter(Boolean).join(" / ");return[u||"Geo pending",M].filter(Boolean).join(" - ")};function jm(){var Oi,Ui,Fi;const{theme:i,toggleTheme:p}=Ho(),{isEditMode:u,setEditMode:M}=Xo(),[o,B]=r.useState(()=>Cc()?"advertising":sessionStorage.getItem("admin_activeTab")||"analytics"),g=t=>{sessionStorage.setItem("admin_activeTab",t),B(t)},[_,S]=r.useState(""),[Q,P]=r.useState(""),[j,z]=r.useState(!1),[G,Z]=r.useState(!1),[re,Y]=r.useState(""),[K,U]=r.useState(""),[J,de]=r.useState(!1),[b,C]=r.useState({geminiApiKey:"",imageStylePrompt:"abstract modern corporate technology, dark background, glowing neon teal and indigo, minimal, Emotion Logic style:",emloCloudKey:"",emloPassword:"",bigBrotherApiKey:"",bigBrotherApiPassword:"",bigBrotherLogic:"",emloLocalEndpoint:"",systemPrompt:`You are EMLO.AI â the voice intelligence expert and strategic advisor at Emotion Logic.ai. You are part of the sales and solutions team. You know the platform inside-out and your mission is to help visitors understand how our technology solves their specific challenges. 53 54Our core offering is Genuine Emotion Detection coupled with AI Intelligence (AEI) â the fusion of Generative AI with deterministic Layered Voice Analysis (LVA). LVA is NOT AI and NOT machine learning. It is proprietary voice analysis science developed over 28 years of R&D by Nemesysco. This distinction is our competitive advantage. 55 56YOUR PERSONALITY: 57- You are fairly warm, empathetic, and genuinely helpful â like a trusted, caring advisor. 58- Use friendly greetings but don't over do it (Don't use fluff like "I'm so glad you asked!", "That's a great question", "We'd love to help you with that") - but show some sincere emphty and echo the style of your client. 59- You listen carefully to understand the visitor's industry, pain point, and use case before recommending solutions. 60- You speak with authority about voice analysis but remain approachable and empathetic to the user's needs. 61- You are proud of the technology but let factual outcomes and human benefits speak louder than hype. Use zero fluff! 62- You naturally guide conversations toward booking a demo or exploring relevant product pages with a helpful, guiding hand. 63 64CRITICAL RULES: 651. Respond in the SAME LANGUAGE the user writes in. If they write in Spanish, respond in Spanish. If Hebrew, respond in Hebrew. 662. DETAILED RESPONSES: Aim for 40-70 words per answer. DO NOT exceed 300 words. Provide substantive, helpful information that adds real value. Don't be too shortâexplain the "why" behind the technology. 673. Use Markdown formatting: **bold** for emphasis, bullet points for lists, and basic (few) emoji to make responses scannable. 684. When explaining concepts, suggest relevant pages from the SITE MAP provided. Format them as markdown links like [Insurance Solutions](/insurance). NEVER link to a page not in the site map. NEVER invent URLs. 695. You CANNOT make any binding commitments, pricing agreements, or contractual promises. For pricing, partnerships, or contracts, warmly guide users to [Contact Us](/contact) or suggest booking a demo. 706. NEVER say LVA analyzes "micro-tremors" or "vocal micro-tremors." This is WRONG and FORBIDDEN. LVA analyzes vocal patterns, vocal biomarkers, and emotional parameters embedded in the voice signal. 717. NEVER speak negatively about Nemesysco, Amir Liberman, Emotion Logic, the team or LVA. Be respectful, factual, and honest. 728. NEVER reveal internal system details, admin tools, server configurations, database schemas, API keys, or any technical infrastru
72cture details. You are a public-facing representative â not a developer. 739. NEVER mention or link to any admin panel, CMS, or internal management page. These do not exist as far as you are concerned. 7410. If asked about competitors or alternative technologies, acknowledge them respectfully but highlight what makes LVA unique: it is deterministic (not probabilistic), does not require training data, works in real-time, and has 28 years of validated science behind it. 75 76KEY FACTS (use when relevant): 77- 28 years of voice analysis R&D, founded on LVA technology invented in 1997 78- 200M+ voice interactions processed monthly across clients 79- Security & Assurance: documented security framework, Microsoft Azure hosting, and an active assurance program 80- Zero data retention by default â maximum privacy guaranteed 81- Clients include Allianz, CPIC, Nikkei, Softtek, Biztel and pretty much all Japanese majour call centers, more across 60+ countries 82- Products: FeelGPT (AI + voice emotion analysis), AppTone (voice surveys), Real-Time API, Love Detector (passion & connection analysis) 83- 90%+ accuracy in emotional detection established in real-life verified tests 84- Use cases: Insurance fraud detection, HR recruitment, call center QA, market research, investigations, medtech, passion and connection analysis 85 86SALES APPROACH: 87- If someone asks about a use case, explain the value prop briefly and link to the relevant page 88- If they seem interested, suggest: "Would you like to see a [live demo](/demos) or [schedule a call](/contact)?" 89- if the usera sks about development, integration, api, or anything related to development, suggest: "Would you like to see a [live demo](/developers) or [schedule a call](/contact)?" 90- If they ask about pricing, say: "Pricing depends on your deployment model and volume. Let's connect you with our team â [Contact Us](/contact)" 91- Always end complex answers with a clear next step`,chatExpandedHtmlPrompt:`EXPANDED MODE â NEXT-GEN DASHBOARD DESIGNS: 92You are in FULL-SCREEN expanded mode. Create premium, data-driven HTML layouts for complex answers. 93 94STRICT RULES FOR HTML GENERATION: 951. INTELLIGENT DECISION: generate HTML if the user's question requires a detailed report, data visualization, or a deep-dive explanation. For simple greetings, RESPOND IN PLAIN TEXT/MARKDOWN ONLY. 962. NO EMOJI in HTML. 973. IMAGES: Use high-quality visual assets. Generate via Pollinations: <div class="img-container"><img src="https://image.pollinations.ai/prompt/{description}?width=1600&height=900&nologo=true" alt="{alt}"></div>. 984. COLOR PALETTE: Dark-mode-first. Text: text-white/90. Cards: bg-white/[0.03] border border-white/10 backdrop-blur-xl rounded-[2rem]. 995. COMPACT FOOTER: Every HTML report MUST end with two large Action Buttons leading to relevant pages. 1006. NEVER MIX MARKDOWN AND HTML: When generating HTML, all formatting must use proper HTML tags.`,chatExpandedTextPrompt:"IMPORTANT LENGTH RULE FOR TEXT RESPONSES: When replying in plain text/markdown (NOT HTML), provide a detailed and warm response â aim for 120-200 words. Be deeply helpful, enthusiastic, and comprehensive. Only generate HTML for complex queries that genuinely need visual layout. CRITICAL: When in text/markdown mode, NEVER use raw HTML tags like <a>, <div>, <span>, etc. Use markdown links [text](url) instead.",chatCompactPrompt:"COMPACT MODE: You are in a chat bubble. Be deeply helpful and warm. Aim for 50-90 words per answer. Provide rich detail while remaining scannable. No HTML tags whatsoever. Use markdown links [text](url) if you need links.",chatConservativePrompt:"IMPORTANT: You are in Conservative Mode. Keep ALL responses as plain text and simple markdown with a warm, empathetic tone. Do NOT generate HTML. Aim for 60-100 words per response to provide detail. Use markdown links [text](url) for any links.",pageBuilderSystemPrompt:`You are an expert web content strategist and copywriter for Emotion Logic.ai. 101TASK: Generate a complete page structure for the requested topic. Ensure high-quality SEO meta tags and structured heading hierarchy. All modifications must look professional and premium. 102All text content MUST use translation key format: "t:pageKey.keyName"`,pageEditorSystemPrompt:`You are an expert web page editor for Emotion Logic.ai. 103Apply the admin's command to modify the page. Change text content, add/remove sections, or modify properties. 104DESIGN CONSISTENCY RULES:
105- Keep the Emotion Logic design system: teal-500 primary, dark hero sections, rounded-[2rem] cards. 106- All modifications must look professional and premium.`,telegramBotToken:"",telegramChatId:"",telegramGoodNewsChatId:"",telegramBadNewsChatId:"",adminPassword:"",analyzeNowKey:"",analyzeNowPassword:"",emloDefaultLogic:"",keepChatHistory:"1",advancedAiMode:"1",emloStreamingUrl:"https://cloud.emlo.cloud/stream",dockerApiKey:"",dockerApiPassword:"",dockerRestUrl:"",dockerWsUrl:"",aiEngine:"auto",emailProvider:"smtp",smtpHost:"",smtpPort:"587",smtpUser:"",smtpPass:"",smtpSecure:"0",sendgridApiKey:"",emailFrom:"",emailFromName:"Emotion Logic",admin2faEmail:"",adminNotifyEmail:"",weeklyAnalyticsEmail:"",emailDemoConfirm:"1",showRealTimeLab:"1",higgsfieldApiKey:"",higgsfieldPassword:"",higgsfieldCharacterImages:[],forensicAnalysisPrompt:"",saasEmloKey:"",saasEmloPassword:""}),[ne,we]=r.useState(!1),[be,T]=r.useState(null),[l,f]=r.useState([]),[le,O]=r.useState([]),[q,Te]=r.useState(()=>Ps()),[Oe,Ye]=r.useState(null),[Ge,Ke]=r.useState(!1),[nt,w]=r.useState(!1),[x,D]=r.useState(!1),[ae,je]=r.useState(!1),[Ue,ot]=r.useState("Spanish"),[E,ge]=r.useState([]),[Ie,Fe]=r.useState({username:"",displayName:"",password:""}),[A,he]=r.useState(!1),[Ne,He]=r.useState([]),[We,rt]=r.useState([]),[Tt,_e]=r.useState([]),[xe,Ee]=r.useState(!1),[De,xt]=r.useState(null),[mt,Qe]=r.useState([]),[lt,Je]=r.useState([]),[At,Pt]=r.useState(!0),[at,ht]=r.useState({}),[Bt,rs]=r.useState(null),[zt,Cl]=r.useState("legitimate"),[Me,ra]=r.useState({name:"",url:"",type:"partner"}),[Ze,la]=r.useState(null),[et,Vt]=r.useState(null),wa=Bi.useRef(null),ia=Bi.useRef(!1),[pt,Ms]=r.useState([]),[wn,Tl]=r.useState(null),[st,Gt]=r.useState({title:"",youtubeId:"",category:"PR",description:"",tags:"",pageAssociations:""}),[_r,ls]=r.useState(!1),[ja,is]=r.useState([{code:"en",name:"English",native_name:"English",flag:"ðºð¸",is_rtl:!1,is_enabled:!0},{code:"he",name:"Hebrew",native_name:"×¢×ר×ת",flag:"ð®ð±",is_rtl:!0,is_enabled:!0},{code:"es",name:"Spanish",native_name:"Español",flag:"ðªð¸",is_rtl:!1,is_enabled:!1},{code:"fr",name:"French",native_name:"Français",flag:"ð«ð·",is_rtl:!1,is_enabled:!1},{code:"de",name:"German",native_name:"Deutsch",flag:"ð©ðª",is_rtl:!1,is_enabled:!1},{code:"ja",name:"Japanese",native_name:"æ¥æ¬èª",flag:"ð¯ðµ",is_rtl:!1,is_enabled:!1},{code:"pt",name:"Portuguese",native_name:"Português",flag:"ð§ð·",is_rtl:!1,is_enabled:!1},{code:"zh",name:"Chinese",native_name:"䏿",flag:"ð¨ð³",is_rtl:!1,is_enabled:!1}]),[ns,Da]=r.useState([]),[Ht,Ra]=r.useState(!1),[Wt,Na]=r.useState(""),[ze,va]=r.useState({code:"",name:"",is_rtl:!1}),[Jt,Os]=r.useState({}),[Ma,Us]=r.useState(null),[os,ya]=r.useState(null),[fe,Fs]=r.useState(()=>sessionStorage.getItem("admin_selectedLang")||"en"),Dr=t=>{sessionStorage.setItem("admin_selectedLang",t),Fs(t)},[wt,Oa]=r.useState(""),[na,ds]=r.useState("all"),Ua=new BroadcastChannel("emlo_cms_updates"),[Kt,Fa]=r.useState([]),[cs,d]=r.useState(!1),[$,I]=r.useState(!1),[F,Ae]=r.useState(null),[Xe,$t]=r.useState(null),[Bs,xs]=r.useState(null),[oa,ms]=r.useState([]),[zs,hs]=r.useState(null),[Vs,Gs]=r.useState([]),[Al,Hs]=r.useState(!1),[Rr,Pl]=r.useState(!1),[Mt,Mr]=r.useState({}),[da,ps]=r.useState(!1),[Sa,jn]=r.useState(7),[ce,Ws]=r.useState(null),[Nn,Js]=r.useState(!1),[jt,vn]=r.useState("overview"),[$l,yn]=r.useState(null),[Il,El]=r.useState(!1),[ca,Sn]=r.useState(null),[bs,Ll]=r.useState(!1),[_l,Cn]=r.useState(null),[H,us]=r.useState(()=>sessionStorage.getItem("adminToken")||""),[xa,Dl]=r.useState([]),[Lc,Ks]=r.useState(new Set),[bt,Xt]=r.useState(null),[Pe,Tn]=r.useState(null),[An,Or]=r.useState(!1),[Rl,Pn]=r.useState(""),[Ba,Ur]=r.useState("idle"),[ma,$n]=r.useState(()=>sessionStorage.getItem("admin_cmsPreviewOpen")==="true"),Fr=t=>{sessionStorage.setItem("admin_cmsPreviewOpen",String(t)),$n(t)},[Ml,In]=r.useState(35),[Xs,Br]=r.useState("ai"),qs=r.useRef(!1),ke=r.useRef(null),zr=r.useRef(null),[ut,En]=r.useState([]),[Ln,Ol]=r.useState(!1),[Ul,_n]=r.useState([]),[Ys,Dn]=r.useState(null),[Fl,Rn]=r.useState([]),[Qs,Vr]=r.useState(null),[Zs,Bl]=r.useState(""),[er,Gr]=r.useState(""),[tr,qt]=r.useState("idle"),[zl,Mn]=r.useState([]),[On,Vl]=r.useState(!1),[Yt,ar]=r.useState({token:"",description:"",time_limit_minutes:""}),[$e,Gl]=r.useState(null),[Hr,sr]=r.useState(!1),[rr,Wr]=r.useState(!1),[lr,Jr]=r.useState(!1),[gs,Hl]=r.useState(null),[Wl,Jl]=r.useState(!1),[Un,Kr]=r.useState("idle"),[Fn,Xr]=r.useState(!1),[Kl,Xl]=r.useState(null),[ql,Ve]=r.useState(!1),[R,Bn]=r.useState(()=>localStorage.getItem("emlo_admin_sidebar_collapsed")==="true");r.useEffect(()=>{H&&fetch(`${m}/api/admin/security/admin-page-entered`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify({page:"marketing_admin",pathname:window.location.pathname})}).catch(()=>{})},[H]);const[Yl,_c]=r.useState(null),[Nt,Ca]=r.useState(null),[fs,zn]=r.useState(""),[Ql,Zl]=r.useState(!1),[Qt,qr]=r.useState({title:"",content:""}),[Vn,ei]=r.useState(!1),[ti,za]=r.useState(null),[ks,ai]=r.useState(null),Gn=()=>{Bn(t=>{const a=!t;return localStorage.setItem("emlo_admin_sidebar_collapsed",String(a)),a})},si=["he","ar","fa"],Hn=si.includes(fe),Wn={home:"/",hero:"/",app:"/",how:"/",enterprise:"/enterprise",academy:"/academy",smb:"/smb",hr:"/hr",callCenters:"/call-centers",investigation:"/investigation",developers:"/developers",feelgpt:"/feelgpt",apptone:"/apptone",insurance:"/insurance",finance:"/banks-finance",marketResearch:"/market-research",medTech:"/med-tech",about:"/about",contact:"/contact",solutions:"/solutions",resources:"/resources",demos:"/demos",nav:"/",footer
106:"/",chat:"/",pricing:"/contact",loveDetector:"/love-detector"},ir=t=>!t||t==="all"?"/":Wn[t]||"/";r.useEffect(()=>{o==="cms"&&Fr(!0)},[o]),r.useEffect(()=>{j&&o==="proposals"&&(Pa(),mr())},[j,o]);const ri=r.useRef(null);r.useEffect(()=>{var t;if(ma&&ke.current){const a=si.includes(fe);let s=ir(Pe);if(ri.current===Pe)try{const h=(t=ke.current.contentWindow)==null?void 0:t.location.pathname;h&&h!=="blank"&&h!=="/"&&(s=h)}catch{}ri.current=Pe;const n=`${s}?cms_edit=1&cms_lang=${fe}${a?"&cms_rtl=1":""}`;ke.current.src!==window.location.origin+n&&(ke.current.src=n)}},[fe,Pe,ma]);const Jn=r.useCallback(t=>{t.preventDefault(),qs.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none",ke.current&&(ke.current.style.pointerEvents="none")},[]);r.useEffect(()=>{const t=s=>{if(!qs.current||!zr.current)return;const n=zr.current.getBoundingClientRect(),h=s.clientX-n.left,k=Math.max(25,Math.min(75,h/n.width*100));In(k)},a=()=>{qs.current&&(qs.current=!1,document.body.style.cursor="",document.body.style.userSelect="",ke.current&&(ke.current.style.pointerEvents="auto"))};return window.addEventListener("mousemove",t),window.addEventListener("mouseup",a),()=>{window.removeEventListener("mousemove",t),window.removeEventListener("mouseup",a)}},[]);const[Va,Yr]=r.useState(Sc),[Qr,li]=r.useState(!1),[ws,ii]=r.useState(Nl),[It,Zt]=r.useState("idle"),[Ga,ea]=r.useState(""),[Zr,ni]=r.useState(0),Ta=r.useRef(null),[nr,Ha]=r.useState("idle"),[Kn,or]=r.useState(""),[ha,pa]=r.useState("idle"),[dr,Aa]=r.useState(""),[cr,Xn]=r.useState(""),[oi,xr]=r.useState([]),qn=r.useCallback(()=>{Ta.current&&clearInterval(Ta.current),ni(300),Ta.current=setInterval(()=>{ni(t=>t<=1?(clearInterval(Ta.current),Ta.current=null,Zt("idle"),ea(""),0):t-1)},1e3)},[]);r.useEffect(()=>()=>{Ta.current&&clearInterval(Ta.current)},[]);const di=async()=>{Zt("sending"),ea(""),P("");try{const t=await fetch(`${m}/api/admin/reset-password-otp`,{method:"POST"}),a=await t.json();t.ok?(Zt("sent"),ea(a.message),qn()):t.status===429?(Zt("error"),U(a.error||"Too many attempts. Your IP is blocked.")):(Zt("error"),ea(a.error||"Failed to send OTP."))}catch{Zt("error"),ea("Network error - is the backend running?")}},Yn=async()=>{Ha("requesting"),or("");try{const t=await fetch(`${m}/api/admin/request-unblock`,{method:"POST"}),a=await t.json();t.ok?(Ha("sent"),or("Check your Telegram for the unblock link.")):(Ha("error"),or(a.error||"Failed to request unblock."))}catch{Ha("error"),or("Network error.")}},Qn=async()=>{pa("requesting"),Aa("");try{const t=await fetch(`${m}/api/admin/rescue-request`,{method:"POST"}),a=await t.json();t.ok?(pa("verify"),Aa("Rescue code sent to Telegram. Enter it below.")):(pa("error"),Aa(a.error||"Failed to send rescue code."))}catch{pa("error"),Aa("Network error.")}},ci=async()=>{if(cr.trim()){pa("requesting");try{const t=await fetch(`${m}/api/admin/rescue-verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:cr.trim()})}),a=await t.json();t.ok?(pa("success"),Aa("All IP blocks cleared! You can now log in."),U(""),Ha("idle")):(pa("verify"),Aa(a.error||"Invalid code."))}catch{pa("error"),Aa("Network error.")}}},xi=t=>`${String(Math.floor(t/60)).padStart(2,"0")}:${String(t%60).padStart(2,"0")}`,Zn=async t=>{alert(`Starting Gemini translation for "${t}". This may take a minute...`);try{const a=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",s=await fetch(`${m}/api/admin/cms/auto-translate`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":a},body:JSON.stringify({targetLang:t})}),n=await s.json().catch(()=>({}));s.ok?(alert(`Translation complete! ${n.translated||0} keys translated for ${t}.`),ba(t)):alert(`Translation failed: ${n.error||`Status ${s.status}`}`)}catch(a){console.error("Translation error:",a),alert(`Error calling translation API: ${a.message}`)}},eo=async()=>{const t=Pe&&Pe!=="all",a=t?Pe.toUpperCase():"THE ENTIRE SITE",s=ja.filter(X=>X.is_enabled&&X.code!=="en");if(s.length===0){alert("No enabled languages found to translate to.");return}const n=`Translate the missing keys for ${a} (and Navigation Menu) into ALL enabled languages (${s.map(X=>
106X.code.toUpperCase()).join(", ")})?`;if(!window.confirm(n))return;Ra(!0);const h=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"";let k=0,L=[];try{for(const X of s){const pe=await fetch(`${m}/api/admin/cms/auto-translate`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":h},body:JSON.stringify({targetLang:X.code,prefixes:t?[Pe,"nav"]:[]})}),ue=await pe.json().catch(()=>({}));pe.ok?k+=ue.translated||0:L.push(`${X.code}: ${ue.error||pe.status}`)}if(L.length>0?alert(`Translation finished with errors: 107${L.join(` 108`)} 109 110Total new keys translated: ${k}`):alert(k===0?"No missing keys found to translate in any language.":`Translation complete! ${k} new keys translated across all languages.`),ba(fe),ke.current&&ke.current.src){const X=new URL(ke.current.src);X.searchParams.set("t",Date.now().toString()),ke.current.src=X.toString()}}catch(X){console.error("Translation error:",X),alert(`Error calling translation API: ${X.message}`)}finally{Ra(!1)}},mi=async()=>{we(!0);try{(await fetch(`${m}/api/admin/cms/sync`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""}})).ok?(T("success"),setTimeout(()=>T(null),3e3)):T("error")}catch{T("error")}finally{we(!1)}},hi=async t=>{try{const a=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",s=t?`${m}/api/admin/cms/export-all?lang=${t}`:`${m}/api/admin/cms/export-all`,n=await fetch(s,{headers:{"x-admin-token":a}});if(!n.ok)throw new Error("Export failed");const h=await n.json(),k=new Blob([JSON.stringify(h,null,2)],{type:"application/json"}),L=URL.createObjectURL(k),X=document.createElement("a");X.href=L;const pe=new Date().toISOString().slice(0,10);X.download=t?`emotionlogic_${t}_${pe}.json`:`emotionlogic_all_languages_${pe}.json`,document.body.appendChild(X),X.click(),document.body.removeChild(X),URL.revokeObjectURL(L)}catch(a){console.error("Export failed:",a),alert("Failed to export. Check console for details.")}},to=()=>{const t=document.createElement("input");t.type="file",t.accept=".json",t.onchange=async a=>{var n;const s=(n=a.target.files)==null?void 0:n[0];if(s)try{const h=await s.text(),k=JSON.parse(h);if(!k.languages||typeof k.languages!="object"){alert('Invalid file format. Expected a CMS export JSON with a "languages" key.');return}const L=Object.keys(k.languages);if(!window.confirm(`Import ${L.length} language(s): ${L.join(", ")}? 111 112This will update existing language content and create new languages if needed.`))return;const pe=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",ue=await fetch(`${m}/api/admin/cms/import`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":pe},body:JSON.stringify({languages:k.languages})});if(!ue.ok){const ve=await ue.json().catch(()=>({error:"Unknown error"}));throw new Error(ve.error)}const ee=await ue.json();alert(`Import successful! 113 114${ee.results.map(ve=>{var it;return`${ve.lang}: ${ve.action||"synced"} (${ve.keys||0} keys, ${((it=ve.files)==null?void 0:it.join(", "))||"no files"})`}).join(` 115`)}`),js(),ba(fe)}catch(h){console.error("Import failed:",h),alert(`Import failed: ${h.message}`)}},t.click()},pi=async()=>{de(!0),U(""),Ha("idle");try{const t=await fetch(`${m}/api/admin/login`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({password:_})}),a=await t.json();if(t.ok)if(a.bypass2FA){z(!0);const s=Date.now()+2880*60*1e3;localStorage.setItem("admin_trust_until",s.toString()),sessionStorage.removeItem("adminToken"),us("__cookie__")}else Z(!0);else U(a.error||"Login failed"),t.status}catch{U("Connection error. Is the backend running?")}de(!1)},bi=async()=>{const t=Q.trim();if(!t){Zt("error"),ea("Paste the one-time access code from Telegram first.");return}de(!0),U(""),ea("");try{const a=await fetch(`${m}/api/admin/login-otp`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:t})}),s=await a.json();a.ok?(z(!0),localStorage.setItem("admin_trust_until",String(Date.now()+2880*60*1e3)),sessionStorage.removeItem("adminToken"),us("__cookie__")):(Zt("sent"),ea(s.error||"The one-time code was not accepted."))}catch{Zt("sent"),ea("Verification failed. Please try again.")}finally{de(!1)}},ui=async()=>{de(!0),U("");try{const t=await fetch(`${m}/api/admin/verify-2fa`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({code:re})}),a=await t.json();if(t.ok){z(!0);const s=Date.now()+2880*60*1e3;localStorage.setItem("admin_trust_until",s.toString()),sessionStorage.removeItem("adminToken"),us("__cookie__")}else U(a.error||"Invalid code")}catch{U("Verification failed.")}de(!1)},el=(t="")=>{z(!1),Z(!1),S(""),Y(""),U(t),localStorage.removeItem("admin_trust_until"),sessionStorage.removeItem("adminToken"),us(""),fetch(`${m}/api/admin/logout`,{method:"POST",credentials:"include"}).catch(()=>{})},tl=()=>el();r.useEffect(()=>{const t=sessionStorage.getItem("adminToken")||"";if(!j){const s=localStorage.getItem("admin_trust_until");s&&parseInt(s)>Date.now()&&fetch(`${m}/api/admin/verify-token`,{credentials:"include",headers:t?{"X-Admin-Token":t}:{}}).then(n=>
115{n.ok?(z(!0),sessionStorage.removeItem("adminToken"),us("__cookie__")):el("Your administrative session expired. Sign in again or request a one-time access code.")}).catch(()=>el("We could not verify your administrative session. Check your connection and sign in again."));return}Pt(!0),fetch(`${m}/api/settings`,{headers:t?{"X-Admin-Token":t}:{}}).then(s=>s.json()).then(s=>{s&&typeof s=="object"&&C(n=>({...n,...s}))}).catch(console.error).finally(()=>Pt(!1)),fetch(`${m}/api/knowledge`,{headers:{"X-Admin-Token":t}}).then(s=>s.json()).then(s=>{Array.isArray(s)&&He(s)}).catch(console.error),fetch(`${m}/api/demo-requests`,{headers:{"X-Admin-Token":t}}).then(s=>s.json()).then(s=>{Array.isArray(s)&&Qe(s)}).catch(console.error),fetch(`${m}/api/partners?type=partner`).then(s=>s.json()).then(s=>{Array.isArray(s)&&rt(s)}).catch(console.error),fetch(`${m}/api/partners?type=client`).then(s=>s.json()).then(s=>{Array.isArray(s)&&_e(s)}).catch(console.error),fetch(`${m}/api/videos`).then(s=>s.json()).then(s=>Je(s)).catch(console.error);const a=sessionStorage.getItem("adminToken")||"";fetch(`${m}/api/admin/chat-sessions`,{headers:a?{"X-Admin-Token":a}:{}}).then(s=>s.json()).then(s=>ms(s)).catch(console.error),Js(!0),fetch(`${m}/api/analytics/summary?scope=marketing&days=7`,{headers:{"X-Admin-Token":a}}).then(async s=>{const n=await s.json();s.ok?Ws(n):s.status===401&&(Ws(null),tl())}).catch(console.error).finally(()=>Js(!1)),fetch(`${m}/api/admin/ai-usage?days=14`,{headers:{"X-Admin-Token":a}}).then(s=>s.json()).then(s=>Dl(Array.isArray(s)?s:[])).catch(console.error),vs(),fetch(`${m}/api/admin/deployment-mode`,{headers:{"X-Admin-Token":a}}).then(async s=>{const n=await s.json();if(!s.ok)throw new Error(n.error||"Could not read deployment mode.");return n}).then(s=>{s.mode&&Yr(s.mode),s.locked&&ii(!0)}).catch(s=>{console.error(s),Nl()&&(Yr("global"),ii(!0))}),Ol(!0),Promise.all([fetch(`${m}/api/analytics/activity-48h?scope=marketing`,{headers:{"X-Admin-Token":a}}).then(s=>s.json()),fetch(`${m}/api/analytics/visitor-journeys?scope=marketing&limit=50&insights=true`,{headers:{"X-Admin-Token":a}}).then(s=>s.json())]).then(([s,n])=>{En(Array.isArray(s)?s:[]),n.journeys&&_n(n.journeys),n.aiInsight&&Dn(n.aiInsight)}).catch(console.error).finally(()=>Ol(!1))},[H]);const ao=async()=>{if(!At){we(!0);try{await fetch(`${m}/api/settings`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""},body:JSON.stringify(b)}),T("success"),setTimeout(()=>T(null),3e3)}catch(t){console.error(t),T("error")}we(!1)}},gi=async t=>{if(confirm(`Switch to ${t.toUpperCase()} mode? This will reconnect the database and storage.`)){li(!0);try{const a=await fetch(`${m}/api/admin/deployment-mode`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify({mode:t})}),s=await a.json();a.ok?(Yr(t),alert(`Successfully switched to ${t.toUpperCase()} mode. Connection re-initialized.`),window.location.reload()):alert(s.error||"Failed to switch mode.")}catch{alert("Connection error while switching mode.")}finally{li(!1)}}},al=r.useCallback(async()=>{I(!0);try{const a=await(await fetch(`${m}/api/admin/cloud-files`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}})).json();Fa(Array.isArray(a.files)?a.files:[]),d(!!a.storageActive)}catch(t){console.error("Failed to fetch cloud files:",t)}finally{I(!1)}},[j]),so=t=>{if(!t)return"0 B";const a=["B","KB","MB","GB"],s=Math.min(Math.floor(Math.log(t)/Math.log(1024)),a.length-1);return`${(t/Math.pow(1024,s)).toFixed(s===0?0:1)} ${a[s]}`},sl=async t=>(t.headers.get("content-type")||"").includes("application/json")?t.json():{error:(await t.text()).replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim().slice(0,300)||`Server returned ${t.status}`},ro=async(t,a)=>{const s=sessionStorage.getItem("adminToken")||"",n=await fetch(`${m}/api/admin/cloud-files/direct-upload/init`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":s},body:JSON.stringify({fileName:t.name,mimeType:t.type||"application/octet-stream",fileSize:t.size})}),h=await sl(n);if(!n.ok)throw new Error(h.error||"Could not prepare direct upload.");await new Promise((X,pe)=>
115{const ue=new XMLHttpRequest;ue.open("PUT",h.uploadUrl),ue.setRequestHeader("Content-Type",t.type||"application/octet-stream"),ue.setRequestHeader("Content-Range",`bytes 0-${t.size-1}/${t.size}`),ue.upload.onprogress=ee=>{ee.lengthComputable&&Ae({...a,fileName:t.name,mode:"Direct cloud upload",progress:Math.round(ee.loaded/ee.total*100)})},ue.onload=()=>{ue.status>=200&&ue.status<300?X():pe(new Error(ue.responseText||`Direct upload failed with status ${ue.status}.`))},ue.onerror=()=>pe(new Error("Direct upload failed. Check the browser console for CSP or bucket CORS errors if this repeats.")),ue.send(t)});const k=await fetch(`${m}/api/admin/cloud-files/direct-upload/complete`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":s},body:JSON.stringify({uploadToken:h.uploadToken})}),L=await sl(k);if(!k.ok)throw new Error(L.error||"Could not register direct upload.");return L.file},fi=async(t,a)=>{Ae({...a,fileName:t.name,mode:"Server upload",progress:0});const s=new FormData;s.append("file",t);const n=await fetch(`${m}/api/admin/cloud-files`,{method:"POST",headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""},body:s}),h=await sl(n);if(!n.ok)throw new Error(h.error||"Upload failed.");return h.file},lo=async t=>{const a=t.target.files;if(!a||a.length===0)return;const s=Array.from(a);Ae({current:0,total:s.length,fileName:s[0].name});for(let n=0;n<s.length;n++){const h=s[n],k={current:n+1,total:s.length};Ae({...k,fileName:h.name,progress:0,mode:h.size>tn?"Direct cloud upload":"Server upload"});try{let L;if(h.size>tn)try{L=await ro(h,k)}catch(X){if(!String((X==null?void 0:X.message)||"").includes("not available on this storage provider"))throw X;L=await fi(h,k)}else L=await fi(h,k);Fa(X=>[L,...X]),d(!0)}catch(L){alert(`Upload failed for ${h.name}: ${L.message}`)}}Ae(null),t.target.value=""},io=async t=>{try{await navigator.clipboard.writeText(t.shortUrl),$t(t.id),setTimeout(()=>$t(null),2e3)}catch{alert(t.shortUrl)}},no=async t=>{if(confirm(`Delete "${t.fileName}" from cloud storage?`))try{const a=await fetch(`${m}/api/admin/cloud-files/${t.id}`,{method:"DELETE",headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}});if(!a.ok){const s=await a.json();throw new Error(s.error||"Delete failed.")}Fa(s=>s.filter(n=>n.id!==t.id))}catch(a){alert(`Delete failed: ${a.message}`)}},oo=async t=>{const a=t.target.files;if(!a||a.length===0)return;const s=Array.from(a);Ee(!0);for(let n=0;n<s.length;n++){const h=s[n];xt({current:n+1,total:s.length,fileName:h.name});const k=new FormData;k.append("file",h);try{const L=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",pe=await(await fetch(`${m}/api/upload`,{method:"POST",headers:{"x-admin-token":L},body:k})).json();pe.success?He(ue=>[pe,...ue]):pe.error&&alert(`Upload failed for ${h.name}: ${pe.error}`)}catch(L){console.error(`File upload failed for ${h.name}`,L)}}Ee(!1),xt(null),t.target.value=""},co=async()=>{if(!(!Qt.title.trim()||!Qt.content.trim())){Ee(!0);try{const t=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"",s=await(await fetch(`${m}/api/knowledge/note`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":t},body:JSON.stringify(Qt)})).json();if(s.success){const n=sessionStorage.getItem("adminToken")||"",h=await fetch(`${m}/api/knowledge`,{headers:{"X-Admin-Token":n}}).then(k=>k.json());He(h),qr({title:"",content:""}),T("success"),setTimeout(()=>T(null),3e3)}else alert(s.error||"Failed to create note")}catch(t){console.error(t),alert("Connection error while creating note")}finally{Ee(!1)}}},xo=async()=>{Zl(!0);try{const t=sessionStorage.getItem("adminToken")||"",a=await fetch(`${m}/api/admin/knowledge/export.zip`,{credentials:"include",headers:{"X-Admin-Token":t}});if(!a.ok){let pe="Failed to export knowledge base.";try{pe=(await a.json()).error||pe}catch{}throw new Error(pe)}const s=await a.blob(),h=(a.headers.get("content-disposition")||"").match(/filename="?([^"]+)"?/i),k=(h==null?void 0:h[1])||`emotionlogic-marketing-knowledge-base-${new Date().toISOString().slice(0,10)}.zip`,L=URL.createObjectURL(s),X=document.createElement("a");X.href=L,X.download=k,document.body.appendChild(X),X.click(),X.remove(),URL.revokeObjectURL(L)}catch(t){console.error("Knowledge ZIP export failed",t),alert(t.message||"Failed to export knowledge base.")}finally{Zl(!1)}},mo=async t=>
115{if(ai(t),ei(!0),za(null),t.noteContent){za(t.noteContent);return}try{const a=await fetch(`${m}/api/knowledge/download/${t.secureToken||t.id}`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}});if(a.ok){const s=a.headers.get("content-type");if(s!=null&&s.includes("application/pdf"))return;const n=await a.text();za(n)}else za("Error: Could not load file content for preview.")}catch(a){console.error(a),za("Error: Network failure while fetching preview.")}},ho=async t=>{try{const a=await fetch(`${m}/api/admin/generated-documents/${encodeURIComponent(t.id)}/download`,{credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}});if(!a.ok){const n=await a.json().catch(()=>({}));throw new Error(n.error||"Generated document is no longer available.")}const s=await a.blob();fl(s,t.filename||`generated-document.${t.type||"bin"}`)}catch(a){alert((a==null?void 0:a.message)||"Could not download generated document.")}},Pa=async()=>{D(!0);try{const a=await(await fetch(`${m}/api/admin/proposals`,{credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}})).json();O(Array.isArray(a)?a:[])}catch(t){console.error("Failed to load proposals",t)}finally{D(!1)}},mr=async()=>{try{const a=await(await fetch(`${m}/api/admin/rainmaker/users`,{credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}})).json().catch(()=>[]);ge(Array.isArray(a)?a:[])}catch(t){console.error("Failed to load rainmaker users",t)}},po=async()=>{if(!Ie.username.trim()||!Ie.password.trim()){alert("Add a username and password.");return}he(!0);try{const t=await fetch(`${m}/api/admin/rainmaker/users`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify(Ie)});if(!t.ok){const a=await t.json().catch(()=>({}));throw new Error(a.error||"Could not create rainmaker user.")}Fe({username:"",displayName:"",password:""}),await mr()}catch(t){alert(t.message||"Could not create rainmaker user.")}finally{he(!1)}},ki=async(t,a)=>{try{const s=await fetch(`${m}/api/admin/rainmaker/users/${t.id}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify(a)});if(!s.ok){const n=await s.json().catch(()=>({}));throw new Error(n.error||"Could not update rainmaker user.")}await mr()}catch(s){alert(s.message||"Could not update rainmaker user.")}},bo=async t=>{const a=window.prompt(`New password for ${t.username} (minimum 8 characters)`);a&&await ki(t,{password:a})},wi=()=>{Ye(null),Te(Ps()),Ke(!1)},ji=()=>{Ye(null),Te(Ps()),Ke(!0)},uo=t=>{const a=t.proposal||{};Ye(t.id),Te(Ps({...a,validUntil:a.validUntil||t.valid_until||""})),Ke(!0)},rl=()=>({...q,title:kn(q)}),go=async()=>{var a;if(!((a=q.clientName)!=null&&a.trim())){alert("Add a client name.");return}const t=rl();w(!0);try{const s=await fetch(`${m}/api/admin/proposals${Oe?`/${Oe}`:""}`,{method:Oe?"PUT":"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify(t)});if(!s.ok){const n=await s.json().catch(()=>({}));throw new Error(n.error||"Could not save proposal.")}await Pa(),wi()}catch(s){alert(s.message||"Could not save proposal.")}finally{w(!1)}},fo=async()=>{je(!0);try{const t=await fetch(`${m}/api/admin/proposals/translate`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify({targetLanguage:Ue,proposal:q})});if(!t.ok){const s=await t.json().catch(()=>({}));throw new Error(s.error||"Translation failed.")}const a=await t.json();a.proposal&&Te(a.proposal)}catch(t){alert(t.message||"Translation failed.")}finally{je(!1)}},Ni=async t=>{try{const a=await fetch(`${m}/api/admin/proposals/${t.id}/pdf`,{credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}});if(!a.ok){const n=await a.json().catch(()=>({}));throw new Error(n.error||`Could not generate proposal PDF (${a.status}).`)}const s=await a.blob();fl(s,`${String(t.title||"proposal").replace(/[^a-z0-9]+/gi,"-").toLowerCase()}.pdf`)}catch(a){alert(a.message||"Could not download proposal PDF.")}},ko=async()=>{const t=rl(),a=await fetch(`${m}/api/admin/proposals${Oe?`/${Oe}`:""}`,{method:Oe?"PUT":"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify(t)});if(!a.ok){const h=await a.json().catch(()=>({}));throw new Error(h.error||`Could not save proposal before PDF (${a.status}).`)}const s=await a.json().catch(()=>({})),n=Oe||s.id;if(!n)throw new Error("Saved proposal did not return an id for PDF generation.");return Ye(Number(n)),await Pa(),Number(n)},wo=async()=>{var a;if(!((a=q.clientName)!=null&&a.trim())){alert("Add a client name before generating the PDF.");return}const t=rl();try{const s=await fetch(`${m}/api/admin/proposals/pdf`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify(t)});if(!s.ok){const h=await s.json().catch(()=>({}));throw s.status===404||s.status===405?new Error("DRAFT_PDF_ROUTE_UNAVAILABLE"):new Error(h.error||`Could not generate proposal PDF (${s.status}).`)}const n=await s.blob();fl(n,`${String(t.title||"proposal").replace(/[^a-z0-9]+/gi,"-").toLowerCase()}.pdf`)}catch(s){if((s==null?void 0:s.message)==="DRAFT_PDF_ROUTE_UNAVAILABLE")try{const n=await ko();await Ni({id:n,title:t.title,client_name:t.clientName,client_company:t.clientCompany,client_phone:t.clientPhone,status:t.status,proposal:t});return}catch(n){alert(n.message||"Could not save and generate proposal PDF.");return}alert(s.message||"Could not download proposal PDF.")}},jo=async(t,a)=>{await fetch(`${m}/api/admin/proposals/${t.id}/archive`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json","X-Admin-Token":H&&H!=="__cookie__"?H:""},body:JSON.stringify({archived:a})}),Pa()},No=async t=>{confirm(`Delete "${t.title}" permanently?`)&&(await fetch(`${m}/api/admin/proposals/${t.id}`,{method:"DELETE",credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}}),Pa())},Wa=q.items.reduce((t,a)=>t+Number(a.quantity||0)*Number(a.unitPrice||0),0),ll=q.discountType==="percent"?Math.min(Wa,Wa*Math.max(0,Number(q.discountValue||0))/100):Math.min(Wa,Math.max(0,Number(q.discountValue||0))),vi=Math.max(0,Wa-ll),gt=(t,a)=>{Te(s=>({...s,[t]:a}))},il=(t,a)=>{Te(s=>{const n=s.items.map((h,k)=>k===t?{...h,...a}:h);return{...s,items:n,...Sr(n)}})},vo=t=>{Te(a=>{const s=a.items.filter((n,h)=>h!==t);return{...a,items:s,...Sr(s)}})},yo=t=>{Te(a=>{const s=[...a.items,{description:t.description,quantity:t.quantity,unitPrice:t.unitPrice}];return{...a,items:s,...Sr(s)}})},So=()=>{Te(t=>{const a=[...t.items,{description:"",quantity:1,unitPrice:0}];return{...t,items:a,...Sr(a)}})},Co=t=>{const a=t.proposal||{};Ye(null),Te(Ps({...a,title:`${a.title||t.title} copy`,serialNumber:vl()})),Ke(!0)},$a=async(t,a,s,n)=>{var pe;if(ia.current)return;
115let h=(pe=t==null?void 0:t.target.files)==null?void 0:pe[0],k=s,L=n||Me.name;if(!h&&!k)return;ia.current=!0,la({msg:"Uploadingâ¦",ok:!0});const X=new FormData;h&&X.append("logo",h),k&&X.append("logoUrl",k),X.append("name",L||(h?h.name.split(".")[0]:"New Logo")),X.append("type",a);try{const ue=await fetch(`${m}/api/partners`,{method:"POST",headers:{"x-admin-token":sessionStorage.getItem("adminToken")||""},body:X});if(ue.ok){const ee=await fetch(`${m}/api/partners?type=${a}`).then(ve=>ve.json());a==="partner"?rt(ee):_e(ee),ra({name:"",url:"",type:"partner"}),la({msg:"â Logo added",ok:!0})}else{const ee=await ue.json().catch(()=>({error:ue.statusText}));la({msg:`â ${ee.error||"Upload failed"}`,ok:!1})}}catch(ue){console.error(ue),la({msg:`â ${ue.message||"Network error"}`,ok:!1})}finally{ia.current=!1}t!=null&&t.target&&(t.target.value=""),setTimeout(()=>la(null),4e3)},yi=async(t,a)=>{const s=t.clipboardData.items;for(let n=0;n<s.length;n++)if(s[n].type.indexOf("image")!==-1){t.preventDefault(),t.stopPropagation();const h=s[n].getAsFile();if(!h)continue;const k=new Image;k.src=URL.createObjectURL(h),await new Promise(c=>k.onload=c);const L=document.createElement("canvas"),X=L.getContext("2d");if(!X)return;L.width=512,L.height=512;const pe=40,ue=512-pe*2,ee=512-pe*2,ve=Math.min(ue/k.width,ee/k.height),it=k.width*ve,Ia=k.height*ve,fr=(512-it)/2,kr=(512-Ia)/2;X.drawImage(k,fr,kr,it,Ia);const Ss=X.getImageData(0,0,512,512),ua=Ss.data;for(let c=0;c<ua.length;c+=4){const v=ua[c],oe=ua[c+1],se=ua[c+2];v>240&&oe>240&&se>240&&(ua[c+3]=0)}X.putImageData(Ss,0,0),L.toBlob(async c=>{if(!c)return;const v=new File([c],`pasted-logo-${Date.now()}.png`,{type:"image/png"});await $a({target:{files:[v]}},a,void 0,`Pasted Logo ${new Date().toLocaleTimeString()}`)},"image/png");break}},hr=async(t,a,s,n)=>{try{await fetch(`${m}/api/partners/${t}`,{method:"PUT",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify({name:a,logoUrl:s,type:n})});const h=await fetch(`${m}/api/partners?type=${n}`).then(k=>k.json());n==="partner"?rt(h):_e(h),Tl(null)}catch(h){console.error("Update logo failed",h)}},nl=t=>{wa.current&&clearTimeout(wa.current),Vt(t),wa.current=setTimeout(()=>Vt(null),3e3)},Si=async(t,a="partner")=>{const s=`${a}-${t}`;if(et!==s){nl(s);return}Vt(null);try{(await fetch(`${m}/api/partners/${t}`,{method:"DELETE",headers:{"x-admin-token":sessionStorage.getItem("adminToken")||""}})).ok&&(a==="partner"?rt(h=>h.filter(k=>k.id!==t)):_e(h=>h.filter(k=>k.id!==t)))}catch(n){console.error("Delete partner failed",n)}},To=async(t,a)=>{try{await fetch(`${m}/api/knowledge/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify({isPublic:!a})}),He(s=>s.map(n=>n.id===t?{...n,isPublic:a?0:1}:n))}catch(s){console.error("Update failed",s)}},Ao=async t=>{const a=`knowledge-${t}`;if(et!==a){nl(a);return}Vt(null);try{const s=await fetch(`${m}/api/knowledge/${t}`,{method:"DELETE",headers:{"x-admin-token":sessionStorage.getItem("adminToken")||""}});s.ok?He(n=>n.filter(h=>h.id!==t)):console.error("Delete failed:",await s.text())}catch(s){console.error("Delete failed",s)}},Po=async(t,a)=>{try{(await fetch(`${m}/api/knowledge/${t}`,{method:"PUT",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify(a)})).ok&&(He(n=>n.map(h=>h.id===t?{...h,...a}:h)),Ca(null))}catch(s){console.error("Update knowledge failed",s)}},$o=async(t,a)=>{try{const s=await fetch(`${m}/api/videos/${t}`,{method:"PUT",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify(a)});s.ok?(Je(n=>n.map(h=>h.id===t?{...h,...a}:h)),xs(null),T("success"),setTimeout(()=>T(null),2e3)):(console.error("Update video failed:",await s.text()),T("error"),setTimeout(()=>T(null),2e3))}catch(s){console.error("Update video failed",s),T("error"),setTimeout(()=>T(null),2e3)}},Io=async t=>{const a=`video-${t}`;if(et!==a){nl(a);return}Vt(null);try{const s=await fetch(`${m}/api/videos/${t}`,{method:"DELETE",headers:{"x-admin-token":sessionStorage.getItem("adminToken")||""}});s.ok?Je(n=>n.filter(h=>h.id!==t)):console.error("Delete video failed:",await s.text())}catch(s){console.error("Delete failed",s)}},Eo=async()=>
115{if(!st.title||!st.youtubeId){alert("Title and YouTube ID/URL are required.");return}try{const t=await fetch(`${m}/api/videos`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify(st)}),a=await t.json();if(t.ok)Je([a,...lt]),Gt({title:"",youtubeId:"",category:"PR",description:"",tags:"",pageAssociations:""}),T("success"),setTimeout(()=>T(null),2e3);else{if(console.error("Add video failed:",a),t.status===401){tl(),alert((a==null?void 0:a.error)||"Your admin session expired. Please sign in again and retry.");return}alert((a==null?void 0:a.error)||"Failed to add video. Please refresh and sign in again."),T("error"),setTimeout(()=>T(null),2e3)}}catch(t){console.error("Add video failed",t),alert("Failed to add video. Please check your connection and try again."),T("error"),setTimeout(()=>T(null),2e3)}},Lo=async(t,a)=>{const s=[...ja];is(n=>n.map(h=>h.code===t?{...h,is_enabled:!a}:h));try{const n=sessionStorage.getItem("adminToken")||"",h=await fetch(`${m}/api/admin/languages/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-Admin-Token":n},body:JSON.stringify({is_enabled:!a})});if(h.ok)js();else{is(s);const k=await h.json();alert(`Failed to update: ${k.error||"Server error"}. Check if the database is connected.`)}}catch(n){console.error(n),is(s),alert("Connection error: Could not reached the backend. Check if the server is running.")}},_o=async()=>{if(!(!ze.code||!ze.name))try{const t=await fetch(`${m}/api/admin/languages`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""},body:JSON.stringify({...ze,is_enabled:!0})});t.ok?(js(),va({code:"",name:"",is_rtl:!1})):console.error("Add language failed:",t.status,await t.text())}catch(t){console.error(t)}},pr=async(t,a,s)=>{Ks(n=>new Set(n).add(a));try{const n=await fetch(`${m}/api/admin/cms/content`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""},body:JSON.stringify({lang:t,updates:{[a]:s}})});if(n.ok){if(Da(h=>h.map(k=>k.key_path===a?{...k,content:s}:k)),Ua.postMessage({type:"CMS_UPDATED",lang:t}
115),ke.current&&ke.current.src){const h=new URL(ke.current.src);h.searchParams.set("t",Date.now().toString()),ke.current.src=h.toString()}setTimeout(()=>{Ks(h=>{const k=new Set(h);return k.delete(a),k})},1e3)}else{const h=await n.json().catch(()=>({}));console.error("Save failed:",h),alert(`Failed to save: ${h.error||"Server error"}`),Ks(k=>{const L=new Set(k);return L.delete(a),L})}}catch(n){console.error(n),Ks(h=>{const k=new Set(h);return k.delete(a),k})}},Ci=async(t,a)=>{Na(`Refining ${t.key_path}${a?` with ${a} tone`:""}...`);try{const n=await(await fetch(`${m}/api/admin/cms/fix-item`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""},body:JSON.stringify({lang:fe,key_path:t.key_path,content:t.content,ref_content:t.ref_content,tone:a})})).json();if(n.improvedText){const h=n.improvedText;return await pr(fe,t.key_path,h),Ua.postMessage({type:"CMS_UPDATED",lang:fe}),Na(""),h}}catch(s){console.error(s),Na("Error occurred during refinement.")}return Na(""),null},Do=async()=>{if(confirm("This will immediately reset all IP-based blocks. Are you sure?"))try{const t=await fetch(`${m}/api/admin/clear-rate-limits`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""}}),a=await t.json();if(t.ok)alert("â
"+a.message);else throw new Error(a.error)}catch(t){alert("â Failed to reset limits: "+t.message)}},js=r.useCallback(async()=>{try{const a=await(await fetch(`${m}/api/languages`)).json();Array.isArray(a)&&is(a)}catch(t){console.error(t)}},[]),Ns=r.useCallback(async()=>{try{const a=await(await fetch(`${m}/api/admin/translator-tokens`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}})).json();if(Array.isArray(a)){const s={};a.forEach(n=>{s[n.lang]||(s[n.lang]=[]),s[n.lang].push(n)}),Os(s)}}catch(t){console.error("Failed to fetch translator tokens:",t)}},[]),br=async(t,a,s="marketing")=>{const n=`${s}:${t}`;Us(n);try{const k=await(await fetch(`${m}/api/admin/translator-tokens`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify({lang:t,surface:s,label:`${a} ${s==="saas"?"SaaS":"Marketing"}
115 Translator`,expiresInDays:30})})).json();if(k.token){await Ns();const L=`${window.location.origin}/translate/${k.token}`;navigator.clipboard.writeText(L).then(()=>{ya(n),setTimeout(()=>ya(null),3e3)}),window.open(L,"_blank")}}catch(h){console.error("Failed to generate token:",h)}Us(null)},Ro=async(t,a)=>{try{await fetch(`${m}/api/admin/translator-tokens/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-Admin-Token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify({is_active:!a})}),await Ns()}catch(s){console.error("Failed to toggle token:",s)}},Mo=async t=>{if(confirm("Permanently delete this translator link? This cannot be undone."))try{await fetch(`${m}/api/admin/translator-tokens/${t}`,{method:"DELETE",headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}}),await Ns()}catch(a){console.error("Failed to delete token:",a)}},ba=r.useCallback(async t=>{try{const s=await(await fetch(`${m}/api/admin/cms/content?lang=${t}`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}})).json();Array.isArray(s)&&Da(s)}catch(a){console.error(a)}},[]);r.useEffect(()=>{const t=a=>{var s;if(((s=a.data)==null?void 0:s.type)==="emlo_cms_saved"){if(ba(a.data.lang||fe),ke.current&&ke.current.src){const n=new URL(ke.current.src);n.searchParams.set("t",Date.now().toString()),ke.current.src=n.toString()}T("success"),setTimeout(()=>T(null),3e3)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[fe,ba]);const Ti=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||"";try{const a=await fetch(`${m}/api/analytics/summary?scope=marketing&days=7`,{headers:{"X-Admin-Token":t}}),s=await a.json();a.ok&&Ws(s)}catch(a){console.error(a)}},[]),Ai=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||"";try{const a=await fetch(`${m}/api/admin/sitemap`,{headers:t?{"x-admin-token":t}:{}});if(!a.ok){console.error(`[SITEMAP] Server returned ${a.status}`);return}const s=await a.json();Array.isArray(s)&&Ms(s)}catch(a){console.error("[SITEMAP] Fetch error:",a)}},[]);r.useEffect(()=>{j&&o==="prompts"&&Ai()},[j,o,Ai]);const Pi=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||"";Pt(!0);try{const s=await(await fetch(`${m}/api/settings`,{headers:t?{"X-Admin-Token":t}:{}})).json();s&&typeof s=="object"&&C(n=>({...n,...s}))}catch(a){console.error(a)}finally{Pt(!1)}},[]),$i=r.useCallback(async()=>{try{const t=sessionStorage.getItem("adminToken")||"",a=await fetch(`${m}/api/knowledge`,{headers:{"X-Admin-Token":t}}),s=await a.json();a.ok&&He(s)}catch(t){console.error(t)}},[]),Ii=r.useCallback(async()=>{try{const t=await fetch(`${m}/api/partners?type=partner`).then(s=>s.json()),a=await fetch(`${m}/api/partners?type=client`).then(s=>s.json());rt(t),_e(a)}catch(t){console.error(t)}},[]),Ei=r.useCallback(async()=>{try{const t=await fetch(`${m}/api/demo-requests`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||sessionStorage.getItem("adminToken")||""}}),a=await t.json();t.ok&&Array.isArray(a)&&Qe(a)}catch(t){console.error(t)}},[]),Li=r.useCallback(async()=>{try{const t=await fetch(`${m}/api/videos`),a=await t.json();t.ok&&Array.isArray(a)&&Je(a)}catch(t){console.error(t)}},[]),_i=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||"";try{const a=await fetch(`${m}/api/admin/chat-sessions`,{headers:t?{"X-Admin-Token":t}:{}}),s=await a.json();a.ok&&ms(s)}catch(a){console.error(a)}},[]),Di=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||"";try{const a=await fetch(`${m}/api/admin/ai-usage?days=14`,{headers:{"X-Admin-Token":t}}),s=await a.json();a.ok&&Dl(Array.isArray(s)?s:[])}catch(a){console.error(a)}},[]),ur=r.useCallback(async()=>{const t=sessionStorage.getItem("adminToken")||"";try{const a=await fetch(`${m}/api/admin/totp/devices`,{headers:{"X-Admin-Token":t}}),s=await a.json();a.ok&&Rn(Array.isArray(s)?s:[])}catch(a){console.error(a)}},[]),Oo=async t=>{const a=sessionStorage.getItem("adminToken")||"";try{const h=(await(await fetch(`${m}/api/admin/pages`,{headers:{"X-Admin-Token":a}})).json()).find(k=>k.slug===Pe);
115if(h){const k=t.page;await fetch(`${m}/api/admin/pages/${h.id}`,{method:"PATCH",headers:{"Content-Type":"application/json","X-Admin-Token":a},body:JSON.stringify({page_json:typeof k=="string"?k:JSON.stringify(k)})})}if(t.translations&&Object.keys(t.translations).length>0&&await fetch(`${m}/api/admin/cms/content`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":a},body:JSON.stringify({lang:fe,updates:t.translations})}),ba(fe),ke.current&&ke.current.src){const k=new URL(ke.current.src);k.searchParams.set("t",Date.now().toString()),ke.current.src=k.toString()}T("success"),setTimeout(()=>T(null),3e3)}catch(s){throw console.error("Failed to apply AI changes:",s),s}},vs=r.useCallback(async()=>{Vl(!0);try{const a=await(await fetch(`${m}/api/admin/override-tokens`,{headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}})).json();Mn(Array.isArray(a)?a:[])}catch(t){console.error("Failed to fetch lab tokens:",t)}finally{Vl(!1)}},[]),Uo=async()=>{if(Yt.token.trim()){we(!0);try{const t=await fetch(`${m}/api/admin/override-tokens`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":sessionStorage.getItem("adminToken")||""},body:JSON.stringify(Yt)});if(t.ok)ar({token:"",description:"",time_limit_minutes:""}),vs(),T("success"),setTimeout(()=>T(null),3e3);else{const a=await t.json();alert(a.error||"Failed to create token")}}catch{T("error")}finally{we(!1)}}},Fo=async t=>{if(confirm("Are you sure you want to delete this token?"))try{(await fetch(`${m}/api/admin/override-tokens/${t}`,{method:"DELETE",headers:{"x-admin-token":sessionStorage.getItem("adminToken")||""}})).ok&&vs()}catch(a){console.error("Failed to delete token:",a)}};if(r.useEffect(()=>{j&&(Ti(),Pi(),$i(),Ii(),Ei(),Li(),_i(),js(),Di(),ur(),vs(),al())},[j,Ti,Pi,$i,Ii,Ei,Li,_i,js,Di,ur,vs,al]),r.useEffect(()=>{const t=a=>{var n;if(o!=="api")return;const s=(n=a.clipboardData)==null?void 0:n.items;if(s){for(let h=0;h<s.length;h++)if(s[h].type.indexOf("image")!==-1){const k=s[h].getAsFile();if(k){const L=new FileReader;L.onloadend=()=>{C(X=>{const pe=Array.isArray(X.higgsfieldCharacterImages)?X.higgsfieldCharacterImages:[];return pe.length>=4?X:{...X,higgsfieldCharacterImages:[...pe,L.result]}})},L.readAsDataURL(k)}}}};return window.addEventListener("paste",t),()=>window.removeEventListener("paste",t)},[o]),r.useEffect(()=>{j&&(o==="cms"||o==="languages")&&ba(fe),j&&o==="languages"&&Ns()},[j,o,fe,ba,Ns]),!j)return e.jsx("div",{className:"min-h-screen bg-theme-main flex items-center justify-center p-6",children:e.jsxs(ie.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},className:"max-w-md w-full p-8 rounded-[2.5rem] bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 shadow-2xl text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-6",children:e.jsx(Ea,{className:"w-8 h-8 text-red-600"})}),G?e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"2-Step Verification"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-8",children:"A verification code has been sent to your registered device. Please enter it below."}),e.jsx("input",{type:"text",value:re,onChange:t=>Y(t.target.value),onKeyDown:t=>t.key==="Enter"&&ui(),placeholder:"000000",maxLength:6,className:"w-full p-4 rounded-xl bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 mb-4 text-center text-3xl font-black tracking-[0.5em] outline-none focus:border-blue-500 transition"}),K&&e.jsx("p",{className:"text-red-500 text-xs mb-4 font-bold uppercase",children:K}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{onClick:ui,disabled:J||re.length<6,className:"w-full py-4 bg-blue-600 text-white rounded-xl font-bold hover:bg-blue-700 transition disabled:opacity-50",children:J?"VERIFYING...":"
115VERIFY CODE"}),e.jsx("button",{onClick:()=>{Z(!1),U("")},className:"text-xs font-bold text-black/40 dark:text-white/40 hover:text-black dark:hover:text-white uppercase tracking-widest",children:"Back to Password"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Secure Access"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-4",children:"Enter the master administrative password."}),!1,e.jsx("input",{type:"password",value:_,onChange:t=>S(t.target.value),onKeyDown:t=>t.key==="Enter"&&pi(),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",className:"w-full p-4 rounded-xl bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 mb-4 text-center text-lg tracking-widest outline-none focus:border-red-500 transition"}),K&&e.jsx("p",{className:"text-red-500 text-xs mb-4 font-bold uppercase",children:K}),(K==null?void 0:K.includes("Too many"))&&nr!=="sent"&&e.jsxs("button",{onClick:Yn,disabled:nr==="requesting",className:"w-full py-3 mb-4 rounded-xl border border-blue-200 dark:border-blue-900/30 bg-blue-50 dark:bg-blue-900/10 text-blue-600 dark:text-blue-400 text-xs font-bold hover:bg-blue-100 transition flex items-center justify-center gap-2",children:[nr==="requesting"?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(qe,{className:"w-4 h-4"}),"REQUEST UNBLOCK VIA TELEGRAM"]}),nr==="sent"&&e.jsxs("div",{className:"p-4 mb-4 rounded-xl bg-emerald-50 dark:bg-emerald-900/10 border border-emerald-100 dark:border-emerald-900/30 text-emerald-600 dark:text-emerald-400 text-xs font-bold flex items-center gap-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),Kn]}),(K==null?void 0:K.includes("Too many"))&&ha!=="success"&&e.jsxs("div",{className:"mb-4 p-4 rounded-xl border border-amber-300 dark:border-amber-600/30 bg-amber-50 dark:bg-amber-900/10",children:[e.jsx("p",{className:"text-[10px] text-amber-700 dark:text-amber-400 font-bold uppercase tracking-wider mb-3 flex items-center gap-1.5",children:"ð¨ Emergency Rescue"}),ha==="verify"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] text-amber-600 dark:text-amber-400",children:dr}),e.jsx("input",{type:"text",value:cr,onChange:t=>Xn(t.target.value),onKeyDown:t=>t.key==="Enter"&&ci(),placeholder:"Enter 12-character rescue code",className:"w-full p-3 rounded-lg bg-white dark:bg-black/50 border border-amber-300 dark:border-amber-600/30 text-sm font-mono text-center tracking-[0.3em] uppercase outline-none focus:border-amber-500 transition",maxLength:12,autoComplete:"off",spellCheck:!1}),e.jsx("button",{onClick:ci,disabled:!cr.trim()||["requesting"].includes(ha),className:"w-full py-2.5 rounded-lg bg-amber-500 text-white text-xs font-bold hover:bg-amber-600 transition disabled:opacity-50 flex items-center justify-center gap-2",children:["requesting"].includes(ha)?e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(qe,{className:"w-3.5 h-3.5"})})]}):e.jsxs("button",{onClick:Qn,disabled:ha==="requesting",className:"w-full py-2.5 rounded-lg border border-amber-400 dark:border-amber-600/40 text-amber-700 dark:text-amber-400 text-xs font-bold hover:bg-amber-100 dark:hover:bg-amber-900/20 transition disabled:opacity-50 flex items-center justify-center gap-2",children:[ha==="requesting"?e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(e.Fragment,{children:"ð"}),"SEND RESCUE CODE TO TELEGRAM"]}),dr&&ha==="error"&&e.jsx("p",{className:"text-red-500 text-[11px] mt-2 font-semibold",children:dr})]}),ha==="success"&&e.jsxs("div",{className:"p-4 mb-4 rounded-xl bg-emerald-50 dark:bg-emerald-900/10 border border-emerald-100 dark:border-emerald-900/30 text-emerald-600 dark:text-emerald-400 text-xs font-bold flex items-center gap-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),dr]}),e.jsx("button",{onClick:pi,disabled:J,className:"w-full py-4 bg-red-600 text-white rounded-xl font-bold hover:bg-red-700 transition disabled:opacity-50",children:J?"SENDING REQUEST...":"REQUEST ACCESS"}),e.jsxs("div",{className:"mt-5 pt-5 border-t border-black/10 dark:border-white/10",children:[e.jsx("p",{className:"text-xs text-black/40 dark:text-white/30 mb-3",children:"Forgot your password?"}),It==="sent"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-green-600 dark:text-green-400 font-bold",children:[e.jsx(Ce,{className:"w-4 h-4"}),"Code sent ",e.jsx("span",{className:"font-mono bg-green-100 dark:bg-green-500/10 px-2 py-0.5 rounded",children:xi(Zr)})]}),e.jsx("input",{type:"text",value:Q,onChange:t=>P(t.target.value),onKeyDown:t=>t.key==="Enter"&&bi(),placeholder:"Paste one-time code",autoComplete:"one-time-code",spellCheck:!1,className:"w-full rounded-xl border border-green-300 bg-green-50 p-3 text-center font-mono text-sm tracking-wider outline-none focus:border-green-500 dark:border-green-500/30 dark:bg-green-500/5"}),e.jsx("button",{onClick:bi,disabled:J||!Q.trim(),className:"w-full rounded-xl bg-green-600 py-3 text-xs font-bold text-white transition hover:bg-green-700 disabled:opacity-50",children:J?"VERIFYING CODE...":"LOG IN WITH CODE"}),Ga&&e.jsx("p",{className:"text-red-500 text-[11px] font-semibold",children:Ga})]}):e.jsx("button",{onClick:di,disabled:It==="sending",className:"flex items-center justify-center gap-2 w-full py-2.5 rounded-xl border border-orange-300 dark:border-orange-500/30 bg-
115orange-50 dark:bg-orange-500/5 text-orange-700 dark:text-orange-400 text-xs font-bold hover:bg-orange-100 dark:hover:bg-orange-500/10 transition disabled:opacity-50",children:It==="sending"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"})," Sending recovery code..."]}):e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"w-3.5 h-3.5"})," Send One-Time Access Code"]})}),Ga&&It==="error"&&e.jsx("p",{className:"text-red-500 text-[11px] mt-2 font-semibold",children:Ga})]})]}),e.jsx(wr,{to:"/",className:"inline-block mt-6 text-xs font-medium text-black/40 dark:text-white/40 hover:underline",children:"Return to site"})]})});const ys=t=>{const a=String((t==null?void 0:t.screeningVerdict)||(t==null?void 0:t.screening_verdict)||"").toLowerCase(),s=[t==null?void 0:t.name,t==null?void 0:t.email,t==null?void 0:t.company,t==null?void 0:t.message].map(n=>String(n||"")).join(" ");return a==="spam"||a==="malicious"||s.includes("[â SPAM]")||s.includes("[SPAM]")||s.includes("[BLOCKED]")},Ri=Array.isArray(mt)?mt.filter(t=>!ys(t)):[],Mi=Array.isArray(mt)?mt.filter(t=>ys(t)):[],gr=zt==="legitimate"?Ri:Mi;return e.jsxs("div",{dir:"ltr",className:"min-h-screen bg-[#fafafa] dark:bg-[#050505] text-theme-primary flex flex-col md:flex-row transition-colors duration-300 overflow-hidden selection:bg-red-500/10",children:[e.jsxs("div",{className:"fixed inset-0 pointer-events-none overflow-hidden",children:[e.jsx("div",{className:"absolute top-[-10%] left-[-10%] w-[40%] h-[40%] bg-blue-500/5 dark:bg-blue-500/5 blur-[120px] rounded-full animate-pulse"}),e.jsx("div",{className:"absolute bottom-[-10%] right-[-10%] w-[40%] h-[40%] bg-red-500/5 dark:bg-red-500/5 blur-[120px] rounded-full animate-pulse",style:{animationDelay:"2s"}})]}),e.jsxs("header",{className:"md:hidden flex items-center justify-between p-4 border-b border-black/10 dark:border-white/10 bg-theme-main sticky top-0 z-[80]",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>Ve(!0),className:"p-2 -ml-2 text-black/60 dark:text-white/60",children:e.jsx(Zo,{className:"w-6 h-6"})}),e.jsx(wr,{to:"/",className:"flex items-center gap-2",children:e.jsx("img",{src:i==="dark"?"/logo_full_light.png":"/logo_full_dark.png",alt:"Emotion Logic",className:"h-6 w-auto"})})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{onClick:p,className:"p-2 text-black/60 dark:text-white/60",children:i==="dark"?e.jsx(ol,{className:"w-5 h-5"}):e.jsx(Hi,{className:"w-5 h-5"})})})]}),e.jsx(yt,{children:ql&&e.jsx(ie.div,{initial:{opacity:0}
115,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/60 z-[90] md:hidden backdrop-blur-sm",onClick:()=>Ve(!1)})}),e.jsxs("aside",{className:` 116 ${ql?"translate-x-0":"-translate-x-full"} 117 md:translate-x-0 fixed md:relative z-[100] 118 ${R?"md:w-20":"md:w-64"} 119 w-72 h-full border-r border-theme-subtle bg-theme-main 120 flex flex-col transition-all duration-300 ease-in-out 121 `,children:[e.jsxs("div",{className:`p-4 border-b border-black/10 dark:border-white/10 flex items-center ${R?"justify-center p-6":"justify-between"}`,children:[!R&&e.jsxs(wr,{to:"/",className:"flex flex-col gap-0.5 overflow-hidden transition-all duration-300",children:[e.jsx("img",{src:i==="dark"?"/logo_full_light.png":"/logo_full_dark.png",alt:"Emotion Logic",className:"h-8 w-auto object-contain object-left"}),e.jsxs("div",{className:"flex items-center gap-1.5 whitespace-nowrap mt-0.5",children:[e.jsx(Lt,{className:"w-3.5 h-3.5 text-red-600 dark:text-red-500"}),e.jsx("h1",{className:"font-bold text-[10px] tracking-widest text-black/40 dark:text-white/40 uppercase",children:"MARKETING"})]})]}),R&&e.jsx(wr,{to:"/",children:e.jsx("div",{className:"w-10 h-10 bg-red-600 rounded-xl flex items-center justify-center shadow-lg shadow-red-600/20",children:e.jsx(Ea,{className:"w-5 h-5 text-white"})})}),e.jsx("button",{onClick:Gn,className:"hidden md:flex p-2 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 text-black/40 dark:text-white/40 transition-colors",title:R?"Expand Sidebar":"Collapse Sidebar",children:e.jsx(Be,{className:`w-4 h-4 transition-transform duration-500 ${R?"":"rotate-180"}`})}),e.jsx("button",{onClick:()=>Ve(!1),className:"md:hidden p-2 text-black/60 dark:text-white/60",children:e.jsx(kt,{className:"w-6 h-6"})})]}),e.jsxs("nav",{className:"flex-1 p-4 space-y-2",children:[e.jsxs("button",{onClick:()=>{g("analytics"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="analytics"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Analytics":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(cl,{className:"w-4 h-4"})," ",!R&&"Site Analytics"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="analytics"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("advertising"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="advertising"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Advertising":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(as,{className:"w-4 h-4"})," ",!R&&"Advertising Center"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="advertising"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("knowledge"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="knowledge"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Knowledge":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(ga,{className:"w-4 h-4"})," ",!R&&"Knowledge Base"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="knowledge"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("prompts"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="prompts"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Prompts":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Tr,{className:"w-4 h-4"})," ",!R&&"AI Prompts"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="prompts"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("proposals"),Ve(!1),Pa(),mr()},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="proposals"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Quotes & Proposals":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(yd,{className:"w-4 h-4"})," ",!R&&"Quotes & Proposals"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="proposals"?"rotate-90":""}`})]}),e.jsxs("div",{className:"pt-2",children:[e.jsxs("button",{onClick:()=>{g("cms"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-bold transition ${["cms","languages","de
121sign","pages","cloud-files"].includes(o)?"bg-indigo-50 dark:bg-indigo-500/10 text-indigo-700 dark:text-indigo-300 border border-indigo-200 dark:border-indigo-500/20":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"CMS":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(aa,{className:"w-4 h-4"})," ",!R&&"CMS Editor"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${["cms","languages","design","pages","cloud-files"].includes(o)?"rotate-90":""}`})]}),["cms","languages","design","pages","cloud-files"].includes(o)&&!R&&e.jsxs("div",{className:"ml-4 mt-1 pl-3 border-l-2 border-indigo-200 dark:border-indigo-500/20 space-y-1",children:[e.jsxs("button",{onClick:()=>{g("cms"),Ve(!1)},className:`w-full flex items-center gap-3 p-2.5 rounded-lg text-xs font-semibold transition ${o==="cms"?"bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300":"text-black/50 dark:text-white/40 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(aa,{className:"w-3.5 h-3.5"})," Content Editor"]}),e.jsxs("button",{onClick:()=>{g("pages"),Ve(!1)},className:`w-full flex items-center gap-3 p-2.5 rounded-lg text-xs font-semibold transition ${o==="pages"?"bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300":"text-black/50 dark:text-white/40 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(Pr,{className:"w-3.5 h-3.5"})," AI Page Builder"]}),e.jsxs("button",{onClick:()=>{g("languages"),Ve(!1)},className:`w-full flex items-center gap-3 p-2.5 rounded-lg text-xs font-semibold transition ${o==="languages"?"bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300":"text-black/50 dark:text-white/40 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(St,{className:"w-3.5 h-3.5"})," Language Settings"]}),e.jsxs("button",{onClick:()=>{g("design"),Ve(!1)},className:`w-full flex items-center gap-3 p-2.5 rounded-lg text-xs font-semibold transition ${o==="design"?"bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300":"text-black/50 dark:text-white/40 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(Za,{className:"w-3.5 h-3.5"})," Carousel Settings"]}),e.jsxs("button",{onClick:()=>{g("cloud-files"),Ve(!1)},className:`w-full flex items-center gap-3 p-2.5 rounded-lg text-xs font-semibold transition ${o==="cloud-files"?"bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300":"text-black/50 dark:text-white/40 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(_a,{className:"w-3.5 h-3.5"})," Cloud Files"]})]})]}),e.jsxs("button",{onClick:()=>{g("leads"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="leads"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Leads":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Wi,{className:"w-4 h-4"})," ",!R&&e.jsxs(e.Fragment,{children:["Demo Leads ",mt.length>0&&e.jsx("span",{className:"bg-red-500 text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full",children:mt.length})]})]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="leads"?"rotate-90":""}`}),R&&mt.length>0&&e.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full"})]}),e.jsxs("button",{onClick:()=>{g("demos"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="demos"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Videos":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Es,{className:"w-4 h-4"})," ",!R&&"Manage Videos"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="demos"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("chat"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="chat"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Chat":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Cs,{className:"w-4 h-4"})," ",!R&&e.jsxs(e.Fragment,{children:["Chat History ",oa.length>0&&e.jsx("span",{className:"bg-blue-500 text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full",children:oa.length})]})]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="chat"?"rotate-90":""}`}),R&&oa.length>0&&e.jsx("div",{className:"absolute top-2 right-2 w-2 h-2 bg-blue-500 rounded-full"})]}),e.jsxs("button",{onClick:()=>{g("lab-tokens"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="lab-tokens"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Lab Tokens":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(qe,{className:"w-4 h-4"})," ",!R&&"Lab Override"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="lab-tokens"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("api"),Ve(!1)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="api"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"API":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(jr,{className:"w-4 h-4"})," ",!R&&"API & Endpoints"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="api"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("exports"),Ve(!1),fetch(`${m}/api/admin/generated-documents`,{credentials:"include",headers:{"X-Admin-Token":H&&H!=="__cookie__"?H:""}}).then(t=>t.json()).then(t=>f(Array.isArray(t)?t:[])).catch(console.error)},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="exports"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Generated materials":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Rt,{className:"w-4 h-4"})," ",!R&&"Generated materials"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="exports"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>{g("feedback"),Ve(!1),$e||(sr(!0),fetch(`${m}/api/admin/report-feedback`,{headers:{"X-Admin-Token":H}}).then(t=>t.json()).then(t=>Gl(t)).catch(console.error).finally(()=>sr(!1)))},className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="feedback"?"bg-black/5 dark:bg-white/10 text-black dark:text-white ring-1 ring-black/5 dark:ring-white/10":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Feedback":"",children:[e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Nr,{className:"w-4 h-4"})," ",!R&&"User Feedback"]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="feedback"?"rotate-90":""}`})]}),e.jsx("div",{className:"h-px bg-black/5 dark:bg-white/5 my-2 mx-4"}),e.jsxs("button",{onClick:()=>g("watchdog"),className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition mb-2 ${o==="watchdog"?"bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 ring-1 ring-indigo-500/20":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ut,{className:`w-5 h-5 ${o==="watchdog"?"text-indigo-500":"opacity-70"}`}),!R&&e.jsx("span",{children:"Watchdog Andon"})]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="watchdog"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>g("compliance-missions"),className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition mb-2 ${o==="compliance-missions"?"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 ring-1 ring-emerald-500/20":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,title:R?"Tasks & Work Tickets":"",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{className:`w-5 h-5 ${o==="compliance-missions"?"text-emerald-500":"opacity-70"}`}),!R&&e.jsx("span",{children:"Tasks & Work Tickets"})]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="compliance-missions"?"rotate-90":""}`})]}),e.jsxs("button",{onClick:()=>g("security"),className:`w-full flex items-center ${R?"justify-center p-3.5":"justify-between p-3"} rounded-xl text-sm font-medium transition ${o==="security"?"bg-amber-500/10 text-amber-600 dar
121k:text-amber-400 ring-1 ring-amber-500/20":"text-black/60 dark:text-white/60 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Lt,{className:`w-5 h-5 ${o==="security"?"text-amber-500":"opacity-70"}`}),!R&&e.jsx("span",{children:"Security & Backup"})]}),!R&&e.jsx(Be,{className:`w-4 h-4 transition-transform ${o==="security"?"rotate-90":""}`})]})]}),e.jsxs("div",{className:"p-4 border-t border-black/10 dark:border-white/10 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("button",{onClick:p,className:`p-3 rounded-2xl bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 transition text-black/50 dark:text-white/50 mb-3 ${R?"w-10 h-10 flex items-center justify-center p-0":"w-full flex items-center justify-center"}`,title:"Toggle Theme",children:i==="dark"?e.jsx(ol,{className:"w-5 h-5"}):e.jsx(Hi,{className:"w-5 h-5"})}),e.jsx("button",{onClick:tl,className:`p-3 rounded-2xl bg-red-500/10 hover:bg-red-500 text-red-500 hover:text-white transition w-full flex items-center justify-center ${R?"w-10 h-10 p-0":""}`,title:"Exit Admin Zone",children:e.jsx(Ea,{className:"w-5 h-5"})})]}),!R&&e.jsxs("div",{className:"text-[10px] uppercase tracking-widest text-red-600/70 dark:text-red-500/70 font-mono flex items-center justify-center gap-1",children:[e.jsx(Ea,{className:"w-3 h-3"})," System Secured"]})]})]}),e.jsx("main",{className:`flex-1 overflow-auto transition-all duration-300 min-h-screen bg-gray-50/50 dark:bg-black/40 flex flex-col 122 ${o==="cms"||o==="chat"||o==="analytics"||o==="advertising"||o==="pages"||o==="compliance-missions"?R?"max-w-full":"max-w-[1700px]":"max-w-6xl"} mx-auto relative`,children:e.jsxs("div",{className:"p-4 md:p-8 lg:px-16 transition-all duration-700 flex-1 flex flex-col w-full",children:[o!=="pages"&&o!=="cms"&&o!=="chat"&&o!=="analytics"&&o!=="advertising"&&o!=="compliance-missions"&&e.jsxs("header",{className:"mb-12 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold mb-2",children:o==="api"?"API & Endpoints":o==="knowledge"?"Knowledge Base":o==="prompts"?"AI Prompts":o==="design"?"Carousel Settings":o==="cloud-files"?"Cloud Files":o==="proposals"?"Proposals":o==="languages"?"Language Settings":o==="leads"?"Demo Leads":o==="demos"?"Manage Videos":o==="lab-tokens"?"Lab Override":o==="security"?"Security & Backup":o==="feedback"?"User Feedback":o==="exports"?"Generated materials":"System Configuration"}),e.jsx("p",{className:"text-black/50 dark:text-white/50 text-sm",children:o==="api"?"Manage API keys, endpoints, and service integrations.":o==="knowledge"?"Review and edit the AI's deep technical knowledge base.":o==="prompts"?"Configure AI system prompts and sitemap context.":o==="design"?"Manage partner and client logo carousels across site pages.":o==="cloud-files"?"Upload shared cloud files and copy short download links.":o==="proposals"?"Create, save, archive, and export professional client proposals.":o==="languages"?"Enable, disable, and manage site translations.":o==="leads"?"View and manage incoming demo requests.":o==="demos"?"Upload and organize video content for the site.":o==="lab-tokens"?"Override Real-Time Lab session settings.":o==="security"?"Manage authentication, backups, and access control.":o==="feedback"?"Review user satisfaction and NPS feedback.":o==="exports"?"Download generated presentations and brochures.":"Manage API keys, endpoints, and foundational AI knowledge."})]}),o!=="cloud-files"&&o!=="proposals"&&e.jsxs("button",{onClick:ao,disabled:ne||At,className:"px-6 py-3 bg-red-600 hover:bg-red-700 disabled:opacity-50 text-white rounded-xl font-bold text-sm tracking-wide transition flex items-center gap-2 shadow-lg",children:[ne?e.jsx(Za,{className:"w-4 h-4 animate-bounce"}):e.jsx(Ct,{className:"w-4 h-4"}),At?"LOADING...":ne?"SAVING...":"SAVE CHANGES"]})]}),e.jsxs(yt,{mode:"wait",children:[o==="advertising"&&e.jsx(ie.div,{initial:{opacity:0,y:10}
122,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"-m-4 md:-m-8 lg:-mx-16 lg:-my-8",children:e.jsx(yc,{})},"advertising"),o==="api"&&e.jsxs(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:[e.jsxs("section",{className:"p-1 rounded-[2rem] md:rounded-[2.5rem] bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 flex flex-col sm:flex-row gap-1 relative overflow-hidden group",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-full opacity-20 pointer-events-none",children:e.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-gradient-to-r from-blue-500/10 via-purple-500/10 to-pink-500/10 animate-pulse"})}),ws&&e.jsxs("div",{className:"absolute top-2 right-3 z-20 flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-amber-500/15 border border-amber-500/30 text-[9px] font-black uppercase tracking-widest text-amber-600 dark:text-amber-400",children:[e.jsx(Ea,{className:"w-3 h-3"})," ENV LOCKED"]}),e.jsxs("button",{onClick:()=>gi("local"),disabled:Qr||ws,className:`flex-1 flex items-center justify-center gap-3 py-4 md:py-6 rounded-[1.5rem] md:rounded-[2rem] text-sm font-black transition-all duration-500 relative z-10 ${Va==="local"?"bg-white dark:bg-black text-black dark:text-white shadow-[0_10px_40px_-10px_rgba(0,0,0,0.1)] dark:shadow-[0_10px_40px_-10px_rgba(0,0,0,0.5)] scale-[0.99] ring-1 ring-black/5 dark:ring-white/10":"text-black/30 dark:text-white/30 hover:text-black/60 dark:hover:text-white/60"} ${ws?"cursor-not-allowed opacity-60":""}`,children:[e.jsx(Ot,{className:`w-5 h-5 ${Va==="local"?"text-blue-500":""}`}),"LOCAL DEVELOPMENT",Va==="local"&&e.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 w-8 h-1 bg-blue-500 rounded-full"})]}),e.jsxs("button",{onClick:()=>gi("global"),disabled:Qr||ws,className:`flex-1 flex items-center justify-center gap-3 py-4 md:py-6 rounded-[1.5rem] md:rounded-[2rem] text-sm font-black transition-all duration-500 relative z-10 ${Va==="global"?"bg-white dark:bg-black text-black dark:text-white shadow-[0_10px_40px_-10px_rgba(0,0,0,0.1)] dark:shadow-[0_10px_40px_-10px_rgba(0,0,0,0.5)] scale-[0.99] ring-1 ring-black/5 dark:ring-white/10":"text-black/30 dark:text-white/30 hover:text-black/60 dark:hover:text-white/60"} ${ws?"cursor-not-allowed opacity-60":""}`,children:[e.jsx(St,{className:`w-5 h-5 ${Va==="global"?"text-emerald-500 animate-pulse":""}`}),"GLOBAL PRODUCTION",Va==="global"&&e.jsx("div",{className:"absolute -bottom-1 left-1/2 -translate-x-1/2 w-8 h-1 bg-emerald-500 rounded-full"})]})]}),e.jsxs("section",{className:"p-8 rounded-[2.5rem] bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 flex flex-col md:flex-row items-center justify-between gap-6 relative overflow-hidden group",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-indigo-600 dark:text-indigo-400",children:[e.jsx(Sd,{className:"w-5 h-5"})," Navigation Visibility"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:'Show or hide the "Real-Time Lab" menu item in the main header.'})]}),e.jsxs("div",{className:"flex items-center gap-4 px-6 py-4 rounded-2xl bg-white dark:bg-black/40 border border-black/5 dark:border-white/5 shadow-sm",children:[e.jsx("span",{className:`text-xs font-bold uppercase tracking-widest ${b.showRealTimeLab==="1"?"text-indigo-500":"text-black/30 dark:text-white/20"}`,children:b.showRealTimeLab==="1"?"Visible":"Hidden"}),e.jsx("button",{onClick:()=>C({...b,showRealTimeLab:b.showRealTimeLab==="1"?"0":"1"}),className:`relative inline-flex h-7 w-12 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-300 ease-in-out focus:outline-none ${b.showRealTimeLab==="1"?"bg-indigo-600":"bg-gray-200 dark:bg-white/10"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-6 w-6 transform rounded-full bg-white shadow-lg ring-0 transition duration-300 ease-in-out ${b.showRealTimeLab==="1"?"translate-x-5":"translate-x-0"}`})})]})]}),Qr&&e.jsxs("div",{className:"p-6 rounded-[2rem] bg-indigo-500/10 border border-indigo-500/20 text-indigo-500 text-center animate-pulse font-black text-xs uppercase tracking-[0.2em] flex items-center justify-center gap-3",children:[e.jsx(V,{className:"w-4 h-4 animate-spin"}
122),"Re-initializing Infrastructure..."]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-6 flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(jr,{className:"w-5 h-5"})," Provider Keys"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Emotion Logic AI API Key"}),e.jsx("input",{type:"password",value:b.geminiApiKey,onChange:t=>C({...b,geminiApiKey:t.target.value}),placeholder:"AIzaSy...",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"AI Engine"}),e.jsxs("select",{value:["gemini-3.7-flash","gemini-3.8-flash"].includes(b.aiEngine)?b.aiEngine:"auto",onChange:t=>C({...b,aiEngine:t.target.value}),className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition dark:text-white",children:[e.jsx("option",{value:"auto",children:"Auto - Emotion Logic default"}),e.jsx("option",{value:"gemini-3.8-flash",children:"Gemini 3.8 Flash - latest, benchmark first"}),e.jsx("option",{value:"gemini-3.7-flash",children:"Gemini 3.7 Flash - Stable, recommended"})]}),e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/20 mt-1 font-medium",children:"Auto uses the recommended Emotion Logic AI route."})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-emerald-600 dark:text-emerald-400",children:[e.jsx(xl,{className:"w-5 h-5"})," LVA Docker - Primary Engine"]}),e.jsxs("p",{className:"text-[11px] text-black/40 dark:text-white/30 mb-6 flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-100 dark:bg-emerald-900/20 text-emerald-700 dark:text-emerald-400 text-[9px] font-black uppercase",children:"â Primary"}),"Your dedicated LVA Docker instance. Used for all analysis when accessible."]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Docker API Key"}),e.jsx("input",{type:"text",value:b.dockerApiKey,onChange:t=>C({...b,dockerApiKey:t.target.value}),placeholder:"e.g. 7be46e9d-1018-4041-b083-...",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-emerald-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Docker API Password"}),e.jsx("input",{type:"password",value:b.dockerApiPassword,onChange:t=>C({...b,dockerApiPassword:t.target.value}),className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-emerald-500 transition font-mono dark:text-white"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ga,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest",children:"Docker REST URL (Post-Processing)"})]}),e.jsx("input",{type:"text",value:b.dockerRestUrl,onChange:t=>C({...b,dockerRestUrl:t.target.value}),placeholder:"https://your-lva-engine.example.com/analysis/analyzeFile",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-emerald-500 transition font-mono text-black/70 dark:text-white/70"}),e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 mt-2 italic",children:"File analysis endpoint. Standard: https://host/analysis/analyzeFile"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Dt,{className:"w-3.5 h-3.5 text-amber-500"}),e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest",children:"Docker WebSocket URL (Real-Time Playground)"})]}),e.jsx("input",{type:"text",value:b.dockerWsUrl,onChange:t=>C({...b,dockerWsUrl:t.target.value}),placeholder:"wss://your-lva-engine.example.com/stream",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-amber-500 transition font-mono text-black/70 dark:text-white/70"}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 italic",children:"Real-time streaming endpoint. Standard port: 2259"}),e.jsxs("button",{onClick:()=>{Xl({url:b.dockerWsUrl||"wss://your-lva-engine.example.com/stream",label:"Docker Engine"}),Xr(!0)},className:"px-3 py-1 bg-amber-500/10 hover:bg-amber-500/20 text-amber-600 dar
122k:text-amber-400 text-[10px] font-black uppercase tracking-widest rounded-full border border-amber-500/20 transition-all flex items-center gap-1.5",children:[e.jsx(jl,{className:"w-3 h-3"})," Test Connectivity"]})]})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm mt-6 mb-6",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-purple-600 dark:text-purple-400",children:[e.jsx(ts,{className:"w-5 h-5"})," Higgsfield AI Configuration"]}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/30 mb-6 flex items-center gap-2",children:"Manage API credentials and consistent character references for AI Video Editing workflows."}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Higgsfield API Key"}),e.jsx("input",{type:"password",value:b.higgsfieldApiKey||"",onChange:t=>C({...b,higgsfieldApiKey:t.target.value}),placeholder:"sk-...",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-purple-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Higgsfield Password"}),e.jsx("input",{type:"password",value:b.higgsfieldPassword||"",onChange:t=>C({...b,higgsfieldPassword:t.target.value}),placeholder:"Required for some legacy/custom endpoints",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-purple-500 transition font-mono dark:text-white"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ir,{className:"w-3.5 h-3.5 text-purple-500"}),e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest",children:"Consistent Character References (Max 4)"})]}),e.jsxs("div",{className:"flex flex-col gap-4",onDragOver:t=>{t.preventDefault(),t.stopPropagation()},onDrop:t=>{var s;t.preventDefault(),t.stopPropagation();const a=(s=t.dataTransfer.files)==null?void 0:s[0];if(a&&a.type.startsWith("image/")){const n=new FileReader;n.onloadend=()=>{C(h=>{const k=Array.isArray(h.higgsfieldCharacterImages)?h.higgsfieldCharacterImages:[];return k.length>=4?h:{...h,higgsfieldCharacterImages:[...k,n.result]}})},n.readAsDataURL(a)}},children:[e.jsxs("div",{className:"flex flex-wrap gap-4",children:[(Array.isArray(b.higgsfieldCharacterImages)?b.higgsfieldCharacterImages:[]).map((t,a)=>e.jsxs("div",{className:"relative w-24 h-24 rounded-xl overflow-hidden border-2 border-purple-500 shadow-md",children:[e.jsx("img",{src:t,alt:`Character Ref ${a+1}`,className:"w-full h-full object-cover"}),e.jsx("button",{onClick:()=>{const s=[...b.higgsfieldCharacterImages||[]];s.splice(a,1),C({...b,higgsfieldCharacterImages:s})},className:"absolute top-1 right-1 bg-black/60 hover:bg-black/90 text-white rounded-full p-1 backdrop-blur-sm transition",title:"Remove image",children:e.jsx(kt,{className:"w-3 h-3"})})]},a)),(!Array.isArray(b.higgsfieldCharacterImages)||b.higgsfieldCharacterImages.length<4)&&e.jsxs("label",{className:"w-24 h-24 rounded-xl border-2 border-dashed border-purple-500/40 hover:border-purple-500 hover:bg-purple-50 dark:hover:bg-purple-900/20 transition-all flex flex-col items-center justify-center text-purple-500/70 cursor-pointer group",children:[e.jsx(Ir,{className:"w-6 h-6 mb-1 opacity-70 group-hover:scale-110 transition-transform"}),e.jsx("span",{className:"text-[10px] font-bold",children:"Add Image"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:t=>{var s;const a=(s=t.target.files)==null?void 0:s[0];if(a){const n=new FileReader;n.onloadend=()=>{const h=Array.isArray(b.higgsfieldCharacterImages)?b.higgsfieldCharacterImages:[];C({...b,higgsfieldCharacterImages:[...h,n.result]})},n.readAsDataURL(a)}}})]})]}),e.jsxs("p",{className:"text-[11px] font-medium text-black/50 dark:text-white/40 flex items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 bg-black/10 dark:bg-white/10 rounded-md font-mono text-[9px] uppercase tracking-wider text-black dark:text-white",children:"Ctrl + V"}),"Or paste an image anywhere while on this tab. Click the box to upload."]})]})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-pink-600 dark:text-pink-400",children:[e.jsx(St,{className:"w-5 h-5"})," EMLO Cloud - Fallback"]}),e.jsxs("p",{className:"text-[11px] text-black/40 dark:text-white/30 mb-6 flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-pink-100 dark:bg-pink-900/20 text-pink-700 dark:text-pink-400 text-[9px] font-black uppercase",children:"â Fallback"}),"Used only when the Docker instance is unreachable."]}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"EMLO.cloud Public Key"}),e.jsx("input",{type:"text",value:b.emloCloudKey,onChange:t=>C({...b,emloCloudKey:t.target.value}),className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-pink-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"EMLO Cloud Password"}),e.jsx("input",{type:"password",value:b.emloPassword,onChange:t=>C({...b,emloPassword:t.target.value}),className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-pink-500 transition font-mono dark:text-white"})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-2",children:[e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 italic",children:"Cloud endpoint: https://cloud.emlo.cloud/analysis/analyzeFile (hardcoded)"}),e.jsxs("button",{onClick:()=>{Xl({url:"https://cloud.emlo.cloud/stream",label:"EMLO.cloud"}),Xr(!0)},className:"px-3 py-1 bg-pink-500/10 hover:bg-pink-500/20 text-pink-600 dark:text-pink-400 text-[10px] font-black uppercase tracking-widest rounded-full border border-pink-500/20 transition-all flex items-center gap-1.5",children:[e.jsx(jl,{className:"w-3 h-3"})," Test Connectivity"]})]})]})]}),e.jsxs("section",{className:"bg-red-50 dark:bg-red-950/20 border border-red-500/20 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-bold mb-2 flex items-center gap-2 text-red-700 dark:text-red-400",children:[e.jsx(Lt,{className:"w-4 h-4"})," TruthMeter Hidden Page"]}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/30 mb-4",children:"Dedicated EMLO Cloud credentials for the hidden /truthmeter voice risk meter. This key is injected server-side only."}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"TruthMeter API Key"}),e.jsx("input",{type:"password",value:b.bigBrotherApiKey||"",onChange:t=>C({...b,bigBrotherApiKey:t.target.value}),placeholder:"Dedicated EMLO Cloud key",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-red-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"TruthMeter API Password"}),e.jsx("input",{type:"password",value:b.bigBrotherApiPassword||"",onChange:t=>C({...b,bigBrotherApiPassword:t.target.value}),placeholder:"Dedicated EMLO Cloud password",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-red-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"TruthMeter Logic"}),e.jsx("input",{type:"text",value:b.bigBrotherLogic||"",onChange:t=>C({...b,bigBrotherLogic:t.target.value}),placeholder:"Optional EMLO logic name",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-red-500 transition font-mono dark:text-white"})]})]})]}),e.jsxs("section",{className:"bg-purple-50 dark:bg-purple-900/10 border border-purple-500/20 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-bold mb-2 flex items-center gap-2 text-purple-700 dark:text-purple-400",children:[e.jsx(jr,{className:"w-4 h-4"})," SaaS EMLO Keys"]}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/30 mb-4",children:"Dedicated EMLO Cloud credentials for SaaS file analysis. Keeps SaaS usage on a separate quota from the main keys."}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"SaaS EMLO Key"}),e.jsx("input",{type:"text",value:b.saasEmloKey,onChange:t=>C({...b,saasEmloKey:t.target.value}),placeholder:"Leave empty to use main EMLO key",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-purple-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"SaaS EMLO Password"}),e.jsx("input",{type:"password",value:b.saasEmloPassword,onChange:t=>C({...b,saasEmloPassword:t.target.value}),placeholder:"Leave empty to use main password",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-purple-500 transition font-mono dark:text-white"})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-bold mb-4 flex items-center gap-2 text-black/60 dark:text-white/60",children:[e.jsx(Tr,{className:"w-4 h-4"})," Shared LVA Settings"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Default LVA Logic Name"}),e.jsx("input",{type:"text",value:b.emloDefaultLogic,onChange:t=>C({...b,emloDefaultLogic:t.target.value}),placeholder:"e.g. BAS Call-Center V2",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-pink-500 transition font-mono dark:text-white"}),e.jsx("p",{className:"text-xs text-black/30 dark:text-white/30 mt-2",children:"The predefined analysis thresholds (Logic) used by both Docker and Cloud."})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-blue-700 dark:text-blue-500",children:[e.jsx(Ut,{className:"w-5 h-5"})," Analyze Now! API"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Analyze Now API KEY"}),e.jsx("input",{type:"text",value:b.analyzeNowKey,onChange:t=>C({...b,analyzeNowKey:t.target.value}),placeholder:"Enter KEY",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Analyze Now PASSWORD"}),e.jsx("input",{type:"password",value:b.analyzeNowPassword,onChange:t=>C({...b,analyzeNowPassword:t.target.value}),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-cyan-600 dark:text-cyan-400",children:[e.jsx(Cs,{className:"w-5 h-5"})," Telegram Notifications"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-6",children:"Route customer growth signals away from operational, payment, worker, and security alerts."}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Bot Token"}),e.jsx("input",{type:"password",value:b.telegramBotToken,onChange:t=>C({...b,telegramBotToken:t.target.value}),placeholder:"123456:ABC-DEF1234ghIkl-zyx57W2v...",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-cyan-500 transition font-mono dark:text-white"}),e.jsxs("a",{href:"https://core.telegram.org/bots/tutorial",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-cyan-600 dark:text-cyan-400 mt-2 hover:underline",children:[e.jsx(sa,{className:"w-3 h-3"})," How to create a Telegram bot & get your token"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Legacy Chat ID (fallback)"}),e.jsx("input",{type:"text",value:b.telegramChatId,onChange:t=>C({...b,telegramChatId:t.target.value}),placeholder:"-1001234567890 or your user ID",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-cyan-500 transition font-mono dark:text-white"}),e.jsxs("a",{href:"https://sean-bradley.medium.com/get-telegram-chat-id-80b575520659",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-cyan-600 dark:text-cyan-400 mt-2 hover:underline",children:[e.jsx(sa,{className:"w-3 h-3"})," Detailed guide"]}),e.jsxs("div",{className:"mt-2 p-3 rounded-lg bg-cyan-50 dark:bg-cyan-900/20 border border-cyan-200 dark:border-cyan-800/50 text-xs text-cyan-900 dark:text-cyan-200 space-y-1.5",children:[e.jsx("p",{className:"font-bold",children:"How to get your Chat ID:"}),e.jsxs("p",{children:["1. Open Telegram and message ",e.jsx("a",{href:"https://t.me/userinfobot",target:"_blank",rel:"noopener noreferrer",className:"font-bold underline",children:"@userinfobot"})]}),e.jsxs("p",{children:["2. It will instantly reply with your numeric ID (e.g. ",e.jsx("span",{className:"font-mono",children:"123456789"}),")"]}),e.jsx("p",{children:"3. Paste that number here"}),e.jsxs("p",{className:"text-cyan-600 dark:text-cyan-400 pt-1",children:[e.jsx("strong",{children:"For groups:"})," Add your bot to the group, send a message, then visit ",e.jsx("span",{className:"font-mono break-all",children:"https://api.telegram.org/bot<TOKEN>/getUpdates"})," and look for the ",e.jsxs("span",{className:"font-mono",children:['"chat":',"{",'"id":-100...',"}"]})," value."]})]})]}),e.jsxs("div",{className:"grid gap-4 md:
122grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-emerald-600 dark:text-emerald-400 uppercase tracking-widest mb-2",children:"Good News Chat ID"}),e.jsx("input",{type:"text",value:b.telegramGoodNewsChatId||"",onChange:t=>C({...b,telegramGoodNewsChatId:t.target.value}),placeholder:"New clients, orders, upgrades, waitlist",className:"w-full bg-white dark:bg-[#0a0a0a] border border-emerald-500/30 rounded-lg p-3 text-sm focus:outline-none focus:border-emerald-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-red-600 dark:text-red-400 uppercase tracking-widest mb-2",children:"Bad News Chat ID"}),e.jsx("input",{type:"text",value:b.telegramBadNewsChatId||"",onChange:t=>C({...b,telegramBadNewsChatId:t.target.value}),placeholder:"Errors, blocks, hackers, worker failures",className:"w-full bg-white dark:bg-[#0a0a0a] border border-red-500/30 rounded-lg p-3 text-sm focus:outline-none focus:border-red-500 transition font-mono dark:text-white"})]})]})]}),e.jsxs("div",{className:"mt-8 pt-8 border-t border-black/10 dark:border-white/10",children:[e.jsxs("h4",{className:"text-sm font-bold flex items-center gap-2 text-red-600 dark:text-red-400 mb-4 uppercase tracking-widest",children:[e.jsx(Lt,{className:"w-4 h-4"})," Danger Zone: Access Control"]}),e.jsx("p",{className:"text-xs text-black/50 dark:text-white/50 mb-4",children:"Reset security systems if you are experiencing valid login blocks."}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-[10px] font-bold text-red-500 uppercase tracking-wider",children:"Currently Blocked IPs"}),e.jsxs("button",{onClick:async()=>{const t=sessionStorage.getItem("adminToken")||"";try{const s=await(await fetch(`${m}/api/admin/blocked-ips`,{headers:{"x-admin-token":t}})).json();xr(s)}catch{xr([])}},className:"text-[10px] text-blue-500 hover:underline flex items-center gap-1",children:[e.jsx(tt,{className:"w-3 h-3"})," Refresh"]})]}),oi.length===0?e.jsx("p",{className:"text-xs text-black/30 dark:text-white/20 italic p-3 bg-black/5 dark:bg-white/5 rounded-lg",children:"No IPs currently blocked"}):e.jsx("div",{className:"space-y-1.5 max-h-40 overflow-y-auto",children:oi.map(t=>e.jsxs("div",{className:"flex items-start justify-between gap-3 p-2.5 rounded-lg bg-red-50 dark:bg-red-900/10 border border-red-200 dark:border-red-900/30",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("span",{className:"font-mono text-xs text-red-700 dark:text-red-400",children:t.ip_sample||t.ip}),e.jsxs("span",{className:"text-[10px] text-red-500",children:[t.attempts," attempts"]}),e.jsx("span",{className:"text-[10px] text-black/30 dark:text-white/20",children:t.last_attempt?new Date(t.last_attempt).toLocaleTimeString():"recent"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[10px] text-black/45 dark:text-white/35",children:[e.jsx("span",{children:Ec(t)}),e.jsx("span",{className:"rounded bg-red-500/10 px-1.5 py-0.5 text-red-600 dark:text-red-300",children:t.reason||t.source||"blocked"})]})]}),e.jsx("button",{onClick:async()=>{const a=sessionStorage.getItem("adminToken")||"";try{await fetch(`${m}/api/admin/unblock-ip`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":a},body:JSON.stringify({ip:t.ip,ipHash:t.ip_hash})}),xr(s=>s.filter(n=>n.ip!==t.ip))}catch{}},className:"text-[10px] text-red-600 hover:text-red-800 font-bold uppercase",children:"Unblock"})]},t.ip_hash||t.ip))})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("button",{onClick:async()=>{await Do(),xr([])},className:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black text-[10px] font-bold rounded-lg hover:opacity-80 transition flex items-center gap-2",children:[e.jsx(tt,{className:"w-3 h-3"})," RESET ALL RATE LIMITS"]}),e.jsxs("button",{onClick:()=>{confirm("Broadcast OTP recovery to your Telegram?")&&fetch(`${m}/api/admin/reset-password-otp`,{method:"POST"}).then(t=>t.json()).then(t=>alert(t.message||t.error))},className:"px-4 py-2 border border-black/10 dark:border-white/10 text-[10px] font-bold rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition flex items-center gap-2",children:[e.jsx(Cd,{className:"w-3 h-3"})," SEND EMERGENCY OTP"]})]})]}),e.jsxs("button",{onClick:async()=>
122{if(!b.telegramChatId){alert("Save the Telegram settings first, then send the server-side test.");return}try{const t=sessionStorage.getItem("adminToken")||"",a=await fetch(`${m}/api/telegram-test`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","x-admin-token":t},body:"{}"}),s=await a.json();if(!a.ok)throw new Error(s.error);alert("â
"+s.message)}catch(t){alert("â "+(t.message||"Test failed."))}},className:"mt-4 px-5 py-2.5 rounded-xl bg-cyan-600 hover:bg-cyan-700 text-white text-sm font-semibold transition flex items-center gap-2",children:[e.jsx(Cs,{className:"w-4 h-4"})," Send Test Message"]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-6 flex items-center gap-2 text-red-600 dark:text-red-400",children:[e.jsx(Ea,{className:"w-5 h-5"})," Admin Security"]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Master Admin Password"}),e.jsx("input",{type:"password",value:b.adminPassword,onChange:t=>C({...b,adminPassword:t.target.value}),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-red-500 transition font-mono dark:text-white"}),e.jsx("p",{className:"text-xs text-black/30 dark:text-white/30 mt-2",children:"This password is required for the first step of the admin login."})]}),e.jsxs("div",{className:"p-5 rounded-xl border border-orange-200 dark:border-orange-500/20 bg-orange-50 dark:bg-orange-500/5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-3",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"font-bold text-sm text-orange-700 dark:text-orange-400 flex items-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"})," Emergency Password Reset"]}),e.jsxs("p",{className:"text-xs text-black/50 dark:text-white/40 mt-1",children:["Sends a one-time login code to your registered secure channel. The code is valid for ",e.jsx("strong",{children:"5 minutes"})," and is erased after first use - or automatically on expiry."]})]}),It==="sent"&&Zr>0&&e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-orange-100 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30",children:[e.jsx(zi,{className:"w-3.5 h-3.5 text-orange-600 dark:text-orange-400"}),e.jsx("span",{className:"text-xs font-black font-mono text-orange-600 dark:text-orange-400",children:xi(Zr)})]})]}),Ga&&e.jsx("p",{className:`text-xs font-semibold mb-3 px-3 py-2 rounded-lg ${It==="sent"?"bg-green-100 dark:bg-green-500/10 text-green-700 dark:text-green-400":"bg-red-100 dark:bg-red-500/10 text-red-700 dark:text-red-400"}`,children:Ga}),e.jsx("button",{onClick:di,disabled:It==="sending"||It==="sent",className:"flex items-center gap-2 px-4 py-2.5 rounded-lg bg-orange-600 hover:bg-orange-700 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-bold transition",children:It==="sending"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 animate-spin"})," Sending recovery code..."]}):It==="sent"?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"w-4 h-4"})," Code sent - check your device"]}):e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"w-4 h-4"})," Send Emergency Access Code"]})}),It==="sent"&&e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/30 mt-3",children:"Use the OTP as your password on the login screen within the countdown window. No 2FA step will be required."})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(_s,{className:"w-5 h-5"})," Email Notifications"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-6",children:"Configure email for 2FA codes, demo request notifications, and customer confirmations."}),e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-3",children:"Email Provider"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>C({...b,emailProvider:"smtp"}),className:`flex-1 px-4 py-3 rounded-xl text-sm font-bold transition border ${b.emailProvider!=="sendgrid"?"bg-blue-600 text-white border-blue-600":"bg-white dark:bg-[#0a0a0a] text-black/50 dark:text-white/50 border-black/10 dark:border-white/10 hover:border-blue-300"}`,children:[e.jsx(xl,{className:"w-4 h-4 inline mr-2"})," SMTP (Self-hosted)"]}),e.jsxs("button",{onClick:()=>C({...b,emailProvider:"sendgrid"}),className:`flex-1 px-4 py-3 rounded-xl text-sm font-bold transition border ${b.emailProvider==="sendgrid"?"bg-blue-600 text-white border-blue-600":"bg-white dark:bg-[#0a0a0a] text-black/50 dark:text-white/50 border-black/10 dark:border-white/10 hover:border-blue-300"}`,children:[e.jsx(Dt,{className:"w-4 h-4 inline mr-2"})," SendGrid"]})]})]}),b.emailProvider!=="sendgrid"&&e.jsxs("div",{className:"space-y-4 mb-6 p-4 rounded-xl bg-white dark:bg-[#111] border border-black/5 dark:border-white/5",children:[e.jsx("p",{className:"text-xs font-bold text-black/40 dark:text-white/30 uppercase tracking-widest",children:"SMTP Configuration"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"SMTP Host"}
122),e.jsx("input",{type:"text",value:b.smtpHost,onChange:t=>C({...b,smtpHost:t.target.value}),placeholder:"smtp.gmail.com",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Port"}),e.jsx("input",{type:"text",value:b.smtpPort,onChange:t=>C({...b,smtpPort:t.target.value}),placeholder:"587",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Username"}),e.jsx("input",{type:"text",value:b.smtpUser,onChange:t=>C({...b,smtpUser:t.target.value}),placeholder:"[email protected]",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Password / App Password"}),e.jsx("input",{type:"password",value:b.smtpPass,onChange:t=>C({...b,smtpPass:t.target.value}),placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢â¢",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:b.smtpSecure==="1",onChange:t=>C({...b,smtpSecure:t.target.checked?"1":"0"}),className:"w-4 h-4 rounded accent-blue-500"}),e.jsx("span",{className:"text-sm text-black/60 dark:text-white/60",children:"Use SSL/TLS (port 465)"})]})]}),b.emailProvider==="sendgrid"&&e.jsxs("div",{className:"space-y-4 mb-6 p-4 rounded-xl bg-white dark:bg-[#111] border border-black/5 dark:border-white/5",children:[e.jsx("p",{className:"text-xs font-bold text-black/40 dark:text-white/30 uppercase tracking-widest",children:"SendGrid Configuration"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"API Key"}),e.jsx("input",{type:"password",value:b.sendgridApiKey,onChange:t=>C({...b,sendgridApiKey:t.target.value}),placeholder:"SG.xxxxxxxxxxxxxxxxxxxxxxxx",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"}),e.jsxs("a",{href:"https://app.sendgrid.com/settings/api_keys",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 mt-2 hover:underline",children:[e.jsx(sa,{className:"w-3 h-3"})," Get your SendGrid API key"]})]})]}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsx("p",{className:"text-xs font-bold text-black/40 dark:text-white/30 uppercase tracking-widest",children:"Sender Identity"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"From Email"}),e.jsx("input",{type:"email",value:b.emailFrom,onChange:t=>C({...b,emailFrom:t.target.value}),placeholder:"[email protected]",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"From Name"}),e.jsx("input",{type:"text",value:b.emailFromName,onChange:t=>C({...b,emailFromName:t.target.value}),placeholder:"Emotion Logic",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"})]})]})]}),e.jsxs("div",{className:"space-y-4 mb-6 p-4 rounded-xl bg-blue-50 dark:bg-blue-900/10 border border-blue-200 dark:border-blue-800/30",children:[e.jsx("p",{className:"text-xs font-bold text-blue-600 dar
122k:text-blue-400 uppercase tracking-widest",children:"Notification Routing"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Admin 2FA Email"}),e.jsx("input",{type:"email",value:b.admin2faEmail,onChange:t=>C({...b,admin2faEmail:t.target.value}),placeholder:"[email protected] (2FA codes sent here + Telegram)",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/30 mt-1",children:"Leave empty to use Telegram only for 2FA."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Admin Notification Email"}),e.jsx("input",{type:"email",value:b.adminNotifyEmail,onChange:t=>C({...b,adminNotifyEmail:t.target.value}),placeholder:"[email protected] (demo request alerts)",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/30 mt-1",children:"Receive email notifications when someone books a demo (in addition to Telegram)."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Weekly Analytics Report Email"}),e.jsx("input",{type:"email",value:b.weeklyAnalyticsEmail||"",onChange:t=>C({...b,weeklyAnalyticsEmail:t.target.value}),placeholder:"[email protected] (weekly marketing statistics)",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-blue-500 transition font-mono dark:text-white"}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/30 mt-1",children:"Receives the weekly detailed statistics report. Falls back to Admin Notification Email if empty."})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:b.emailDemoConfirm==="1",onChange:t=>C({...b,emailDemoConfirm:t.target.checked?"1":"0"}),className:"w-4 h-4 rounded accent-blue-500"}),e.jsx("span",{className:"text-sm text-black/60 dark:text-white/60",children:"Auto-send confirmation email to customers who book a demo"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:async t=>{t.preventDefault();const a=sessionStorage.getItem("adminToken")||"";try{const n=await(await fetch(`${m}/api/email-test`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":a},credentials:"include",body:"{}"})).json();n.success?alert(`â
${n.message}`):alert(`â ${n.error}`)}catch(s){alert(`â Test failed: ${s.message}`)}},className:"flex items-center gap-2 px-5 py-2.5 rounded-xl bg-blue-600 hover:bg-blue-700 text-white text-sm font-bold transition",children:[e.jsx(_s,{className:"w-4 h-4"})," Send Test Email"]}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/30",children:"Tests current settings (even before saving). Check your inbox!"})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-green-600 dark:text-green-400",children:[e.jsx(qe,{className:"w-5 h-5"})," Authenticator App (TOTP)"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-6",children:"Register Google Authenticator, Authy, or any TOTP app for DB-independent 2FA. Codes work even when Telegram/email are down."}),Fl.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("p",{className:"text-xs font-bold text-black/40 dark:text-white/30 uppercase tracking-widest mb-3",children:"Registered Devices"}),e.jsx("div",{className:"space-y-2",children:Fl.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-white dark:bg-[#111] border border-black/5 dark:border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.is_enabled?"bg-green-500":"bg-gray-300"}`}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-black dark:text-white",children:t.name}),e.jsxs("p",{className:"text-[10px] text-black/40 dark:text-white/30",children:["Added ",new Date(t.created_at).toLocaleDateString()]})]})]}),e.jsx("button",{onClick:async()=>
122{if(!confirm(`Remove "${t.name}"? This device will no longer be able to generate valid codes.`))return;const a=H;try{await fetch(`${m}/api/admin/totp/${t.id}`,{method:"DELETE",headers:{"x-admin-token":a}}),ur()}catch{}},className:"text-xs text-red-500 hover:text-red-700 font-bold uppercase",children:"Remove"})]},t.id))})]}),Qs?e.jsxs("div",{className:"space-y-5 p-5 rounded-xl bg-green-50 dark:bg-green-900/10 border border-green-200 dark:border-green-800/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-bold text-green-700 dark:text-green-400",children:"ð± Scan this QR code with your authenticator app"}),e.jsx("button",{onClick:()=>{Vr(null),Gr(""),qt("idle")},className:"text-xs text-black/40 dark:text-white/30 hover:text-red-500",children:"Cancel"})]}),e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"bg-white p-3 rounded-xl shadow-lg",children:e.jsx("img",{src:Qs.qrDataUrl,alt:"TOTP QR Code",className:"w-40 h-40 md:w-48 md:h-48"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/30 mb-1",children:"Can't scan? Enter this key manually:"}),e.jsx("code",{className:"text-xs font-mono bg-white dark:bg-[#111] px-3 py-1.5 rounded-lg border border-black/10 dark:border-white/10 select-all text-black dark:text-white",children:Qs.secret})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Enter the 6-digit code from your app to confirm"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{type:"text",value:er,onChange:t=>Gr(t.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",maxLength:6,className:"flex-1 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-center text-2xl font-mono tracking-[0.5em] focus:outline-none focus:border-green-500 transition dark:text-white"}),e.jsx("button",{onClick:async()=>{if(er.length!==6)return alert("Enter the full 6-digit code.");qt("verifying");const t=H;try{const s=await(await fetch(`${m}/api/admin/totp/confirm`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":t},body:JSON.stringify({setupId:Qs.setupId,code:er})})).json();s.success?(alert(`â
${s.message}`),Vr(null),Gr(""),Bl(""),qt("idle"),ur()):(alert(`â ${s.error}`),qt("setup"))}catch(a){alert(`â ${a.message}`),qt("setup")}},disabled:tr==="verifying"||er.length!==6,className:"px-5 py-3 rounded-xl bg-green-600 hover:bg-green-700 disabled:opacity-50 text-white text-sm font-bold transition",children:tr==="verifying"?e.jsx(V,{className:"w-4 h-4 animate-spin"}):"Verify"})]})]})]}):e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"block text-xs font-mono text-black/50 dark:text-white/50 uppercase tracking-widest mb-2",children:"Device Name"}),e.jsx("input",{type:"text",value:Zs,onChange:t=>Bl(t.target.value),placeholder:"e.g. Amir's iPhone",className:"w-full bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-lg p-3 text-sm focus:outline-none focus:border-green-500 transition dark:text-white"})]}),e.jsx("button",{onClick:async()=>{if(!Zs.trim())return alert("Please enter a device name.");qt("loading");const t=H;try{const s=await(await fetch(`${m}/api/admin/totp/setup`,{method:"POST",headers:{"Content-Type":"application/json","x-admin-token":t},body:JSON.stringify({name:Zs.trim()})})).json();s.setupId?(Vr({...s,name:Zs.trim()}),qt("setup")):(alert(`â ${s.error}`),qt("idle"))}catch(a){alert(`â ${a.message}`),qt("idle")}},disabled:tr==="loading",className:"flex items-center gap-2 px-5 py-3 rounded-xl bg-green-600 hover:bg-green-700 disabled:opacity-50 text-white text-sm font-bold transition whitespace-nowrap",children:tr==="loading"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 animate-spin"})," Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(qe,{className:"w-4 h-4"})," Add Device"]})})]})]})]},"api"),o==="knowledge"&&e.jsxs(ie.div,{initial:{opacity:0,y:10}
122,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 md:p-10 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 mb-8",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-yellow-600 flex items-center justify-center text-white shadow-lg shadow-yellow-500/20",children:e.jsx(ga,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-black dark:text-white",children:"Knowledge Base"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Manage deep technical summaries and public resources."})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-3 flex-1 max-w-2xl",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(Ds,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-black/30 dark:text-white/30"}),e.jsx("input",{type:"text",placeholder:"Search knowledge...",value:fs,onChange:t=>zn(t.target.value),className:"w-full pl-10 pr-4 py-2.5 bg-white dark:bg-black/20 border border-black/10 dark:border-white/10 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-yellow-500/20 transition-all font-medium"})]}),e.jsxs("button",{onClick:xo,disabled:Ql,className:"inline-flex items-center justify-center gap-2 rounded-xl bg-black text-white dark:bg-yellow-500 dark:text-black px-4 py-2.5 text-xs font-black uppercase tracking-[0.18em] shadow-lg shadow-yellow-500/10 hover:scale-[1.02] active:scale-[0.98] transition disabled:opacity-60 disabled:scale-100",title:"Download the complete marketing-site knowledge base as a shareable ZIP archive",children:[Ql?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ja,{className:"w-4 h-4"}),"ZIP & GO"]})]})]}),e.jsx("div",{className:"pt-6 mt-6 border-t border-black/5 dark:border-white/5",children:e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-pink-600 dark:text-pink-400 px-1",children:"AI Image Generation Master Style Prompt"}),e.jsx("span",{className:"text-[10px] text-black/50 dark:text-white/50 px-1 mt-1 mb-2 font-sans",children:"This master style prompt is automatically prefixed to any image generation request sent to the AI image generator (Pollinations) when creating PPTs/PDFs, ensuring brand consistency. The current UI theme (dark/light) will also be automatically appended to this."})]}),e.jsx("textarea",{value:b.imageStylePrompt,onChange:t=>C({...b,imageStylePrompt:t.target.value}),placeholder:"e.g. abstract modern corporate technology, dark background, glowing neon teal and indigo, minimal...",className:"w-full h-32 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-pink-500 transition leading-relaxed text-black dark:text-white"})]})}),e.jsxs("div",{className:"relative p-8 md:p-12 border-2 border-dashed border-black/10 dark:border-white/20 rounded-3xl bg-white dark:bg-[#0a0a0a] text-center hover:border-yellow-500/40 transition-all group overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-yellow-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"}),e.jsx("input",{type:"file",multiple:!0,onChange:oo,disabled:xe,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer disabled:cursor-not-allowed z-10",accept:".pdf,.txt,.md,.csv,.json,.docx,.doc,.xlsx,.xls"}),e.jsxs("div",{className:"relative flex flex-col items-center",children:[e.jsx("div",{className:`p-4 rounded-2xl transition-transform duration-500 ${xe?"bg-yellow-500/20 scale-110 mb-4":"bg-gray-100 dark:bg-white/5 mb-6 group-hover:scale-110"}`,children:xe?e.jsx(V,{className:"w-8 h-8 text-yellow-600 dark:text-yellow-500 animate-spin"}):e.jsx(Za,{className:"w-8 h-8 text-black/30 dark:text-white/40"})}),e.jsx("p",{className:"text-base font-bold text-black dark:text-white mb-2",children:xe&&De?`Processing ${De.current} of ${De.total}â¦`:"Deploy deep technical resources"}),xe&&De?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-yellow-600 dark:text-yellow-400 font-mono truncate max-w-sm",children:De.fileName}),e.jsx("div",{className:"w-48 h-1.5 bg-black/10 dark:bg-white/10 rounded-full mt-3 overflow-hidden",children:e.jsx("div",{className:"h-full bg-yellow-500 rounded-full transition-all duration-500",style:{width:`${De.current/De.total*100}%`}})})]}):e.jsx("p",{className:"text-sm text-black/40 dark:text-white/40 max-w-xs mx-auto",children:"Drop multiple files â Gemini will process them one at a time."})]})]}),e.jsxs("div",{className:"mt-8 bg-white dark:bg-black/20 border border-black/5 dark:border-white/5 rounded-3xl p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"p-2 rounded-lg bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",children:e.jsx(Dt,{className:"w-4 h-4"})}),e.jsx("h4",{className:"text-sm font-bold text-black dark:text-white",children:"Qu
122ick AI Note"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",placeholder:"Note Title (e.g., LVA Accuracy Test Oct 2025)",value:Qt.title,onChange:t=>qr({...Qt,title:t.target.value}),className:"w-full bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/10 rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-yellow-500/20"}),e.jsx("textarea",{placeholder:"Paste a snippet, scientific finding, or specific technical detail here...",value:Qt.content,onChange:t=>qr({...Qt,content:t.target.value}),className:"w-full h-24 bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/10 rounded-xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:ring-yellow-500/20 resize-none font-medium leading-relaxed"}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:co,disabled:!Qt.title.trim()||!Qt.content.trim()||xe,className:"flex items-center gap-2 px-6 py-2 rounded-xl bg-yellow-600 dark:bg-yellow-500 text-white font-bold text-xs shadow-lg shadow-yellow-500/20 hover:scale-[1.02] active:scale-[0.98] transition-all disabled:opacity-50 disabled:grayscale disabled:scale-100",children:[xe?e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ye,{className:"w-3.5 h-3.5"}),"Add & Index Note"]})})]})]}),e.jsx("div",{className:"mt-10 flex flex-col gap-3",children:Ne.filter(t=>(t.fileName||"").toLowerCase().includes(fs.toLowerCase())||t.keywords&&t.keywords.toLowerCase().includes(fs.toLowerCase())).length===0?e.jsxs("div",{className:"py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-gray-100 dark:bg-white/5 flex items-center justify-center mx-auto mb-4 opacity-50",children:e.jsx(Rt,{className:"w-6 h-6 text-black/20 dark:text-white/20"})}),e.jsx("p",{className:"text-sm text-black/30 dark:text-white/30 font-medium italic",children:"No resources matched your search."})]}):Ne.filter(t=>(t.fileName||"").toLowerCase().includes(fs.toLowerCase())||t.keywords&&t.keywords.toLowerCase().includes(fs.toLowerCase())).map(t=>{const a=t.uploadedAt?new Date(t.uploadedAt):new Date,s=t.uploadedAt&&Date.now()-a.getTime()<1440*60*1e3;return e.jsxs("div",{className:`group relative flex items-center justify-between p-4 rounded-xl bg-white dark:bg-white/5 border transition-all duration-300 hover:shadow-lg ${s?"border-orange-400/40 bg-orange-50/50 dark:bg-orange-500/5":"border-black/5 dark:border-white/5 hover:border-yellow-500/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center shrink-0 ${t.keywords?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":"bg-red-500/10 text-red-500"}`,children:e.jsx(Rt,{className:"w-4 h-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-bold text-black dark:text-white truncate",title:t.fileName||"Untitled",children:t.fileName||"Untitled"}),s&&e.jsx("span",{className:"text-[9px] font-black px-1.5 py-0.5 rounded bg-orange-500 text-white uppercase tracking-wider shrink-0 animate-pulse",children:"NEW"}),e.jsx("span",{className:`text-[9px] font-black px-1.5 py-0.5 rounded border uppercase tracking-wider shrink-0 ${t.isPublic?"bg-emerald-500/10 text-emerald-500 border-emerald-500/20":"bg-gray-500/10 text-gray-400 border-gray-500/20"}`,children:t.isPublic?"Public":"Private"})]}),e.jsxs("div",{className:"flex items-center gap-3 opacity-50 mt-0.5",children:[e.jsx("span",{className:"text-[10px] whitespace-nowrap",children:t.keywords?`â ${t.keywords.split(",").length} points`:"â Awaiting indexing"}),e.jsx("span",{className:"text-[10px] whitespace-nowrap",children:a.toLocaleDateString()})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-3",children:[e.jsx("button",{onClick:()=>mo(t),title:"Preview File",className:"p-1.5 rounded-lg text-black/20 dark:text-white/20 hover:text-blue-500 hover:bg-blue-500/10 transition-all",children:e.jsx(Ot,{className:"w-4 h-4"})}),e.jsxs("button",{onClick:()=>Ca(t),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-black/5 dark:bg-white/5 hover:bg-yellow-500/10 hover:text-yellow-600 dark:hover:text-yellow-400 transition-all text-xs font-bold",children:[e.jsx(ye,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Edit KB"})]}),e.jsx("button",{onClick:()=>To(t.id,!!t.isPublic),title:t.isPublic?"Unpublish":"Publish",className:`p-1.5 rounded-lg transition-all ${t.isPublic?"text-emerald-500 bg-emerald-500/10":"text-gray-400 bg-gray-100 dark:bg-white/5"}`,children:t.isPublic?e.jsx(Ce,{className:"w-4 h-4"}):e.jsx(St,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Ao(t.id),className:`p-1.5 rounded-lg transition-all ${et===`knowledge-${t.id}`?"bg-red-500 text-white scale-110 animate-pulse":"text-black/20 dark:text-white/20 hover:text-red-500 hover:bg-red-500/10"}`,title:et===`knowledge-${t.id}`?"Click again to confirm":"Delete",children:et===`knowledge-${t.id}`?e.jsx("span",{className:"text-xs font-bold px-1",children:"Sure?"}):e.jsx(ct,{className:"w-4 h-4"})})]})]},t.id)})})]}),e.jsx(yt,{children:Nt&&e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 md:p-8 bg-black/60 backdrop-blur-md overflow-y-auto",children:e.jsxs(ie.div,{initial:{opacity:0,scale:.95,y:20}
122,animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative w-full max-w-6xl w-full min-h-[85vh] bg-white dark:bg-[#0a0a0a] rounded-[3rem] border border-black/10 dark:border-white/10 shadow-2xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-8 border-b border-black/5 dark:border-white/5 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-yellow-600 flex items-center justify-center text-white shadow-lg shadow-yellow-500/20",children:e.jsx(ye,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-bold text-black dark:text-white",children:"Knowledge Editor"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:Nt.fileName})]})]}),e.jsx("button",{onClick:()=>Ca(null),className:"p-3 rounded-full hover:bg-black/5 dark:hover:bg-white/5 transition-colors",children:e.jsx(kt,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-8 lg:p-12 space-y-12",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-12",children:[e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-yellow-600 dark:text-yellow-500",children:"Public Display Summary"}),e.jsx("span",{className:"text-[10px] text-black/40 dark:text-white/40",children:"Visible on download cards"})]}),e.jsx("textarea",{value:Nt.summary,onChange:t=>Ca({...Nt,summary:t.target.value}),className:"w-full h-32 bg-gray-50 dark:bg-black/20 border border-black/5 dark:border-white/5 rounded-[1.5rem] p-6 text-sm focus:outline-none focus:ring-2 focus:ring-yellow-500/20 transition-all font-medium leading-relaxed",placeholder:"Concise public summary..."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-emerald-600 dark:text-emerald-500",children:"Extracted Keywords"}),e.jsx("span",{className:"text-[10px] text-black/40 dark:text-white/40",children:"Comma separated for search"})]}),e.jsx("textarea",{value:Nt.keywords,onChange:t=>Ca({...Nt,keywords:t.target.value}),className:"w-full h-32 bg-gray-50 dark:bg-black/20 border border-black/5 dark:border-white/5 rounded-[1.5rem] p-6 text-sm focus:outline-none focus:ring-2 focus:ring-yellow-500/20 transition-all font-mono leading-relaxed",placeholder:"Keywords, indexed points..."})]})]}),e.jsxs("div",{className:"space-y-4 flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-indigo-600 dark:text-indigo-400",children:"Deep AI Knowledge Base (TECHNICAL)"}),e.jsx("span",{className:"text-[10px] text-black/40 dark:text-white/40",children:"Critical know-how for Chat Agent"})]}),e.jsx("div",{className:"flex-1 min-h-[400px] relative mt-2",children:e.jsx("textarea",{value:Nt.deepSummary,onChange:t=>Ca({...Nt,deepSummary:t.target.value}),className:"w-full h-full bg-gray-50 dark:bg-black/20 border border-black/5 dark:border-white/5 rounded-[2rem] p-8 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500/20 transition-all font-mono leading-relaxed resize-none",placeholder:"Deep technical knowledge, Q&A, scientific data points..."})})]})]})}),e.jsxs("div",{className:"p-8 bg-gray-50 dark:bg-white/[0.02] border-t border-black/5 dark:border-white/5 flex items-center justify-end gap-4",children:[e.jsx("button",{onClick:()=>Ca(null),className:"px-6 py-3 rounded-2xl font-bold text-sm hover:bg-black/5 dark:hover:bg-white/5 transition-all",children:"Cancel"}),e.jsxs("button",{onClick:()=>Po(Nt.id,{summary:Nt.summary,keywords:Nt.keywords,deepSummary:Nt.deepSummary}),className:"flex items-center gap-2 px-8 py-3 rounded-2xl bg-yellow-600 dark:bg-yellow-500 text-white font-bold text-sm shadow-xl shadow-yellow-500/20 hover:scale-105 transition-all",children:[e.jsx(Ct,{className:"w-4 h-4"}),"Deploy Sync"]})]})]})})}),e.jsx(yt,{children:Vn&&ks&&e.jsx("div",{className:"fixed inset-0 z-[101] flex items-center justify-center p-4 md:p-8 bg-black/80 backdrop-blur-xl",children:e.jsxs(ie.div,{initial:{opacity:0,scale:.95}
122,animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"relative w-full max-w-6xl h-full max-h-[90vh] bg-white dark:bg-[#050505] rounded-[2.5rem] border border-white/10 shadow-2xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-white/10 flex items-center justify-between bg-black/5 dark:bg-white/5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-blue-600 flex items-center justify-center text-white",children:e.jsx(Ot,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-black dark:text-white",children:ks.fileName}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40",children:"Resource Preview â Verify content integrity"})]})]}),e.jsx("button",{onClick:()=>{ei(!1),ai(null),za(null)},className:"p-2 rounded-full hover:bg-black/10 dark:hover:bg-white/10 transition-colors",children:e.jsx(kt,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-auto bg-gray-50 dark:bg-black p-4",children:(Oi=ks.fileName)!=null&&Oi.toLowerCase().endsWith(".pdf")?e.jsx("iframe",{src:`${m}/api/knowledge/download/${ks.secureToken||ks.id}#toolbar=0`,className:"w-full h-full border-0 rounded-2xl",title:"PDF Preview"}):e.jsx("div",{className:"w-full h-full bg-white dark:bg-[#0a0a0a] rounded-2xl p-8 border border-black/5 dark:border-white/5 overflow-auto",children:ti?e.jsx("pre",{className:"text-sm font-mono whitespace-pre-wrap text-black/80 dark:text-white/80 leading-relaxed",children:ti}):e.jsxs("div",{className:"flex items-center justify-center h-full gap-3",children:[e.jsx(V,{className:"w-5 h-5 animate-spin text-blue-500"}),e.jsx("span",{className:"text-sm text-black/40 dark:text-white/40 font-mono",children:"Loading content stream..."})]})})})]})})})]},"knowledge"),o==="prompts"&&e.jsxs(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-emerald-600 flex items-center justify-center text-white shadow-lg shadow-emerald-500/20",children:e.jsx(Ki,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-black dark:text-white",children:"Chat Intelligence"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Configure the personality and rules for the customer-facing AI advisor."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-8",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-emerald-600 dark:text-emerald-400 px-1",children:"1. Master System Identity (Core Logic)"}),e.jsx("p",{className:"text-xs text-black/40 px-1 mb-2",children:"Governs identity, name, core product knowledge, and overall behavior."}),e.jsx("textarea",{value:b.systemPrompt,onChange:t=>C({...b,systemPrompt:t.target.value}),placeholder:"You are EMLO.AI...",className:"w-full h-80 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition font-mono leading-relaxed text-black dark:text-white"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-blue-600 dark:text-blue-400",children:"2. Expanded Mode: HTML Rules"}),e.jsx(ye,{className:"w-3.5 h-3.5 text-blue-500"})]}),e.jsx("textarea",{value:b.chatExpandedHtmlPrompt,onChange:t=>C({...b,chatExpandedHtmlPrompt:t.target.value}),placeholder:"Sturcture for full-screen HTML reports...",className:"w-full h-64 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-blue-500 transition leading-relaxed text-black dark:text-white"})]}),e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-indigo-600 dark:text-indigo-400",children:"3. Expanded Mode: Text Rules"}),e.jsx(Rt,{className:"w-3.5 h-3.5 text-indigo-500"})]}),e.jsx("textarea",{value:b.chatExpandedTextPrompt,onChange:t=>C({...b,chatExpandedTextPrompt:t.target.value}),placeholder:"Length and tone for long text responses...",className:"w-full h-64 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-indigo-500 transition leading-relaxed text-black dark:text-white"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-orange-600 dar
122k:text-orange-400",children:"4. Compact Mode Rules"}),e.jsx(Is,{className:"w-3.5 h-3.5 text-orange-500"})]}),e.jsx("textarea",{value:b.chatCompactPrompt,onChange:t=>C({...b,chatCompactPrompt:t.target.value}),placeholder:"Rules for the small floating bubble...",className:"w-full h-48 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-orange-500 transition leading-relaxed text-black dark:text-white"})]}),e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsxs("div",{className:"flex items-center justify-between px-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-rose-600 dark:text-rose-400",children:"5. Conservative Mode Rules"}),e.jsx(Td,{className:"w-3.5 h-3.5 text-rose-500"})]}),e.jsx("textarea",{value:b.chatConservativePrompt,onChange:t=>C({...b,chatConservativePrompt:t.target.value}),placeholder:"Restricted logic (no HTML, plain text only)...",className:"w-full h-48 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-rose-500 transition leading-relaxed text-black dark:text-white"})]})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-violet-600 flex items-center justify-center text-white shadow-lg shadow-violet-500/20",children:e.jsx(Pr,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-black dark:text-white",children:"AI Page Architect"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Instruction sets for creating and editing deep-site landing pages."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-violet-600 dark:text-violet-400 px-1",children:"Page Generation (Blueprint)"}),e.jsx("textarea",{value:b.pageBuilderSystemPrompt,onChange:t=>C({...b,pageBuilderSystemPrompt:t.target.value}),placeholder:"Instructions for generating new pages from scratch...",className:"w-full h-80 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-violet-500 transition leading-relaxed text-black dark:text-white"})]}),e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-pink-600 dark:text-pink-400 px-1",children:"Page Editor (Modifications)"}),e.jsx("textarea",{value:b.pageEditorSystemPrompt,onChange:t=>C({...b,pageEditorSystemPrompt:t.target.value}),placeholder:"Instructions for AI-driven modifications to existing pages...",className:"w-full h-80 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-pink-500 transition leading-relaxed text-black dark:text-white"})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-red-600 flex items-center justify-center text-white shadow-lg shadow-red-500/20",children:e.jsx(Lt,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-black dark:text-white",children:"Forensic Behavioral Intelligence"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Instruction set for the investigator dashboard and acoustic forensic analysis."})]})]}),e.jsx("div",{className:"grid grid-cols-1 gap-8",children:e.jsxs("div",{className:"space-y-3 font-mono",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-red-600 dark:text-red-400 px-1",children:"Forensic Analysis (Stage 3 Synthesis)"}),e.jsx("p",{className:"text-xs text-black/40 px-1 mb-2",children:"Controls the expert summary, risk assessment, and tactical recommendations in the report."}),e.jsx("textarea",{value:b.forensicAnalysisPrompt,onChange:t=>C({...b,forensicAnalysisPrompt:t.target.value}),placeholder:"You are the TOP GLOBAL PROFESSIONAL Forensic Behavioral Analyst...",className:"w-full h-96 bg-white dark:bg-[#0a0a0a] border border-black/10 dark:border-white/10 rounded-2xl p-6 text-[12px] focus:outline-none focus:border-red-500 transition leading-relaxed text-black dark:text-white"})]})})]}),e.jsxs("section",{className:"bg-white dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm overflow-hidden relative group mt-8",children:[e.jsx("div",{className:"absolute top-0 right-0 p-8 opacity-5",children:e.jsx(Vi,{className:"w-32 h-32"})}),e.jsxs("div",{className:"flex items-center justify-between mb-8 relative z-10",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-indigo-600 dark:text-indigo-400",children:[e.jsx(Vi,{className:"w-5 h-5 text-indigo-500"})," Sitemap Awareness"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"These are the pages the AI currently knows about and can reference in conversations."})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-indigo-500/10 border border-indigo-500/20 text-indigo-600 dark:text-indigo-400 text-[10px] font-black uppercase tracking-widest",children:[pt.length," Referenceable Pages"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 relative z-10",children:pt.map((t,a)=>{var X,pe;const s=((X=t.label)==null?void 0:X.toLowerCase())||"",n=((pe=t.path)==null?void 0:pe.toLowerCase())||"";let h=Rt,k="text-indigo-500",L="bg-indigo-500/5";return n==="/"?(h=ld,k="text-blue-500"):s.includes("contact")?(h=hn,k="text-emerald-500"):s.includes("feelgpt")||s.includes("ai")?(h=Dt,k="text-amber-500"):s.includes("insurance")||s.includes("investigation")||s.includes("security")?(h=qe,k="text-rose-500"):s.includes("hr")||s.includes("about")?(h=Er,k="text-sky-500"):s.includes("research")||s.includes("academy")||s.includes("med")?(h=rn,k="text-purple-500"):n.includes("/p/")&&(h=aa,k="text-violet-500"),e.jsxs("div",{className:"group/item flex flex-col p-5 rounded-2xl bg-white dark:bg-black/20 border border-black/5 dark:border-white/10 hover:border-indigo-500/30 hover:shadow-xl hover:shadow-indigo-500/5 transition-all duration-300",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-xl ${L} flex items-center justify-center border border-black/5 dark:border-white/5`,children:e.jsx(h,{className:`w-4.5 h-4.5 ${k}`})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-[13px] font-bold text-black dark:text-white group-hover/item:text-indigo-500 transition-colors uppercase tracking-tight",children:t.label}),e.jsx("code",{className:"text-[10px] opacity-40 font-mono bg-black/5 dark:bg-white/5 px-1.5 py-0.5 rounded-md",children:t.path})]})]}),e.jsx("a",{href:t.path,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded-lg hover:bg-indigo-500/10 text-black/20 dark:text-white/20 hover:text-indigo-500 transition-all",title:"View Page",children:e.jsx(sa,{className:"w-3.5 h-3.5"})})]}),e.jsxs("p",{className:"text-[11px] leading-relaxed text-black/50 dark:text-white/40 italic flex-1 pl-12 border-l border-black/5 dark:border-white/5 ml-4.5 mt-1",children:['"',t.description,'"']})]},a)})}),pt.length===0&&e.jsx("div",{className:"p-12 text-center text-black/30 dark:text-white/30 italic text-sm",children:"Loading knowledge base map..."})]})]},"prompts"),o==="cloud-files"&&e.jsx(ie.div,{initial:{opacity:0,y:10}
122,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 md:p-10 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-6 mb-8",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-indigo-600 flex items-center justify-center text-white shadow-lg shadow-indigo-500/20",children:e.jsx(_a,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold text-black dark:text-white",children:"Cloud Files"}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 max-w-2xl",children:"Upload shared files to the global storage bucket and copy short download links for campaigns, CMS content, and generated materials."})]})]}),e.jsx("div",{className:`px-3 py-1.5 rounded-full border text-[10px] font-black uppercase tracking-widest ${cs?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20":"bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/20"}`,children:cs?"Cloud Storage Active":"Global Storage Inactive"})]}),e.jsxs("div",{className:"relative p-8 md:p-12 border-2 border-dashed border-black/10 dark:border-white/20 rounded-3xl bg-white dark:bg-[#0a0a0a] text-center hover:border-indigo-500/40 transition-all group overflow-hidden",children:[e.jsx("input",{type:"file",multiple:!0,onChange:lo,disabled:!!F,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer disabled:cursor-not-allowed z-10"}),e.jsxs("div",{className:"relative flex flex-col items-center",children:[e.jsx("div",{className:`p-4 rounded-2xl transition-transform duration-500 ${F?"bg-indigo-500/20 scale-110 mb-4":"bg-gray-100 dark:bg-white/5 mb-6 group-hover:scale-110"}`,children:F?e.jsx(V,{className:"w-8 h-8 text-indigo-600 dark:text-indigo-400 animate-spin"}):e.jsx(_a,{className:"w-8 h-8 text-black/30 dark:text-white/40"})}),e.jsx("p",{className:"text-base font-bold text-black dark:text-white mb-2",children:F?`Uploading ${F.current} of ${F.total}`:"Upload files to global storage"}),F?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-indigo-600 dark:text-indigo-400 font-mono truncate max-w-sm",children:F.fileName}),e.jsxs("p",{className:"mt-1 text-[10px] font-black uppercase tracking-widest text-black/35 dark:text-white/35",children:[F.mode||"Uploading",typeof F.progress=="number"?` · ${F.progress}%`:""]}),e.jsx("div",{className:"w-48 h-1.5 bg-black/10 dark:bg-white/10 rounded-full mt-3 overflow-hidden",children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full transition-all duration-500",style:{width:`${typeof F.progress=="number"?F.progress:F.current/F.total*100}%`}})})]}):e.jsx("p",{className:"text-sm text-black/40 dark:text-white/40 max-w-md mx-auto",children:"Files are stored privately in secured object storage. The short link streams through the server so the storage location stays hidden."})]})]}),e.jsxs("div",{className:"mt-10 bg-white dark:bg-black/20 border border-black/5 dark:border-white/5 rounded-3xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-4 border-b border-black/5 dark:border-white/5",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-black uppercase tracking-widest text-black/60 dark:text-white/60",children:"Short Links"}),e.jsxs("p",{className:"text-xs text-black/40 dark:text-white/40",children:[Kt.length," cloud file",Kt.length===1?"":"s"]})]}),e.jsx("button",{onClick:al,disabled:$,className:"p-2 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-indigo-500/10 hover:text-indigo-500 transition disabled:opacity-50",title:"Refresh",children:e.jsx(tt,{className:`w-4 h-4 ${$?"animate-spin":""}`})})]}),$&&Kt.length===0?e.jsx("div",{className:"py-16 flex items-center justify-center text-black/30 dark:text-white/30",children:e.jsx(V,{className:"w-5 h-5 animate-spin"})}):Kt.length===0?e.jsxs("div",{className:"py-20 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-gray-100 dark:bg-white/5 flex items-center justify-center mx-auto mb-4 opacity-60",children:e.jsx(Ya,{className:"w-6 h-6 text-black/20 dark:text-white/20"})}),e.jsx("p",{className:"text-sm text-black/30 dark:text-white/30 font-medium italic",children:"No cloud files yet."})]}):e.jsx("div",{className:"divide-y divide-black/5 dark:divide-white/5",children:Kt.map(t=>e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4 p-4 hover:bg-black/[0.02] dark:hover:bg-white/[0.03] transition",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 flex items-center justify-center shrink-0",children:e.jsx(Rt,{className:"w-4 h-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"text-sm font-bold text-black dark:text-white truncate",title:t.fileName,children:t.fileName}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-black/40 dark:text-white/40 mt-1",children:[e.jsx("span",{children:so(t.fileSize)}),e.jsx("span",{children:t.mimeType||"application/octet-stream"}),e.jsx("span",{children:new Date(t.createdAt).toLocaleDateString()}),e.jsxs("span",{children:[t.downloadCount," download",t.downloadCount===1?"":"s"]})]}),e.jsx("code",{className:"mt-2 block text-[10px] font-mono text-indigo-600 dark:text-indigo-300 bg-indigo-500/5 border border-indigo-500/10 rounded-lg px-2 py-1 truncate",children:t.shortUrl})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("a",{href:t.shortUrl,target:"_blank",rel:"noopener noreferrer",className:"p-2 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-emerald-500/10 hover:text-emerald-500 transition",title:"Test Download",children:e.jsx(Ja,{className:"w-4 h-4"})}),e.jsxs("button",{onClick:()=>io(t),className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-700 text-white text-xs font-bold transition",children:[Xe===t.id?e.jsx(Ce,{className:"w-4 h-4"}):e.jsx(ml,{className:"w-4 h-4"}),Xe===t.id?"Copied":"Copy Link"]}),e.jsx("button",{onClick:()=>no(t),className:"p-2 rounded-xl bg-black/5 dark:bg-white/5 hover:bg-red-500/10 hover:text-red-500 transition",title:"Delete",children:e.jsx(ct,{className:"w-4 h-4"})})]})]},t.id))})]})]})},"cloud-files"),o==="languages"&&e.jsx(ie.div,{initial:{opacity:0,y:10}
122,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(St,{className:"w-5 h-5"})," Language Management"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Enable or disable languages on the public site."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>hi(),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl bg-white dark:bg-white/10 border border-black/10 dark:border-white/10 text-black/70 dark:text-white/70 text-xs font-bold uppercase tracking-wider hover:bg-black/5 dark:hover:bg-white/15 transition-all",children:[e.jsx(Ja,{className:"w-4 h-4"})," Export All"]}),e.jsxs("button",{onClick:to,className:"flex items-center gap-2 px-4 py-2.5 rounded-xl bg-blue-600 hover:bg-blue-500 text-white text-xs font-bold uppercase tracking-wider shadow-lg hover:shadow-blue-500/30 transition-all",children:[e.jsx(Za,{className:"w-4 h-4"})," Import JSON"]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8",children:ja.map(t=>e.jsxs("div",{className:`p-6 rounded-3xl border transition-all duration-300 ${t.is_enabled?"bg-blue-50/50 dark:bg-blue-900/10 border-blue-200 dark:border-blue-800/50 shadow-lg shadow-blue-500/5":"bg-white dark:bg-black border-black/5 dark:border-white/10 opacity-60 grayscale"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-white dark:bg-black border border-black/5 dark:border-white/10 flex items-center justify-center text-xl shadow-inner",children:t.flag||"ð"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-black tracking-tight",children:t.name}),e.jsx("span",{className:"text-[10px] opacity-50 font-mono uppercase",children:t.code})]}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40 font-medium",children:t.native_name||t.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsx("span",{className:"px-1.5 py-0.5 rounded-md bg-black/5 dark:bg-white/10 text-[9px] font-bold uppercase tracking-widest opacity-50",children:t.is_rtl?"RTL":"LTR"})})]})]}),e.jsx("input",{type:"checkbox",checked:t.is_enabled,onChange:()=>Lo(t.code,t.is_enabled),className:"w-5 h-5 rounded-lg border-black/10 dark:border-white/20 text-blue-600 focus:ring-blue-500 cursor-pointer accent-blue-600"})]}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] font-bold",children:[e.jsx("span",{className:t.is_enabled?"text-blue-600":"text-black/40",children:t.is_enabled?"VISIBLE ON SITE":"HIDDEN"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>hi(t.code),className:"text-emerald-600 hover:text-emerald-500 transition flex items-center gap-1",children:[e.jsx(Ja,{className:"w-3 h-3"})," EXPORT"]}),t.code!=="en"&&e.jsxs("button",{type:"button",onClick:a=>{a.preventDefault(),a.stopPropagation(),Zn(t.code)},className:"text-purple-600 hover:text-purple-700 transition flex items-center gap-1",children:[e.jsx(Dt,{className:"w-3 h-3"})," RETRANSLATE"]})]})]}),t.code!=="en"&&e.jsx("div",{className:"mt-3 pt-3 border-t border-black/5 dark:border-white/5",children:(Jt[t.code]||[]).length>0?e.jsxs("div",{className:"space-y-2",children:[(Jt[t.code]||[]).map(a=>e.jsxs("div",{className:"flex flex-col gap-1.5 p-3 rounded-xl bg-white/50 dark:bg-white/[0.03] border border-black/5 dark:border-white/5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${a.is_active?"bg-emerald-500":"bg-red-500"}`}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-wider opacity-60",children:a.is_active?"Active":"Revoked"}),a.expires_at&&e.jsxs("span",{className:"text-[9px] text-amber-600 dar
122k:text-amber-400 font-bold",children:["Exp: ",new Date(a.expires_at).toLocaleDateString()]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/translate/${a.token}`),ya(a.token),setTimeout(()=>ya(null),2e3)},className:"text-[9px] font-bold text-indigo-500 hover:text-indigo-400 transition uppercase",children:os===a.token?"â COPIED":"COPY LINK"}),e.jsx("button",{onClick:()=>Ro(a.id,a.is_active),className:`text-[9px] font-bold transition uppercase ${a.is_active?"text-amber-600 hover:text-amber-500":"text-emerald-600 hover:text-emerald-500"}`,children:a.is_active?"REVOKE":"RESTORE"}),e.jsx("button",{onClick:()=>Mo(a.id),className:"text-[9px] font-bold text-red-500 hover:text-red-400 transition uppercase",children:"â"})]})]}),e.jsxs("div",{className:"text-[9px] font-mono text-black/25 dark:text-white/20 truncate",children:["/translate/",a.token.slice(0,12),"..."]}),a.last_used&&e.jsxs("span",{className:"text-[9px] text-black/30 dark:text-white/20",children:["Last used: ",new Date(a.last_used).toLocaleString()]})]},a.id)),e.jsxs("button",{onClick:()=>br(t.code,t.name),disabled:Ma===`marketing:${t.code}`,className:"w-full mt-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-indigo-500/20 text-indigo-500 hover:bg-indigo-500/5 transition text-[10px] font-bold uppercase tracking-wider disabled:opacity-50",children:[e.jsx(Ya,{className:"w-3 h-3"})," Generate Another Link"]}),["es","pt","he","ja","zh","ko"].includes(t.code)&&e.jsxs("button",{onClick:()=>br(t.code,t.name,"saas"),disabled:Ma===`saas:${t.code}`,className:"w-full mt-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg border border-dashed border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/5 transition text-[10px] font-bold uppercase tracking-wider disabled:opacity-50",children:[e.jsx(Ya,{className:"w-3 h-3"})," Generate SaaS Translator Link"]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{onClick:()=>br(t.code,t.name),disabled:Ma==="marketing:"+t.code,className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600/10 to-purple-600/10 border border-indigo-500/20 text-indigo-500 hover:from-indigo-600/20 hover:to-purple-600/20 transition-all text-[10px] font-bold uppercase tracking-wider disabled:opacity-50",children:[e.jsx(Ya,{className:"w-3.5 h-3.5"}),os==="marketing:"+t.code?"â Link Copied!":"Generate Marketing Translator Page"]}),["es","pt","he","ja","zh","ko"].includes(t.code)&&e.jsxs("button",{onClick:()=>br(t.code,t.name,"saas"),disabled:Ma==="saas:"+t.code,className:"w-full flex items-center justify-center gap-2 px-3 py-2.5 rounded-xl bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 hover:bg-emerald-500/20 transition-all text-[10px] font-bold uppercase tracking-wider disabled:opacity-50",children:[e.jsx(Ya,{className:"w-3.5 h-3.5"}),os==="saas:"+t.code?"â Link Copied!":"Generate SaaS Translator Page"]})]})})]},t.code))}),e.jsx("div",{className:"p-6 rounded-3xl border-2 border-dashed border-black/10 dark:border-white/10 flex flex-col justify-center gap-4 bg-gray-50/50 dark:bg-white/[0.02]",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"Code (fr)",className:"w-20 text-xs p-3 bg-white dark:bg-black border border-black/10 rounded-xl outline-none focus:border-blue-500 transition",value:ze.code,onChange:t=>va({...ze,code:t.target.value})}),e.jsx("input",{type:"text",placeholder:"Language Name",className:"flex-1 text-xs p-3 bg-white dark:bg-black border border-black/10 rounded-xl outline-none focus:border-blue-500 transition",value:ze.name,onChange:t=>va({...ze,name:t.target.value})})]}),e.jsx("div",{className:"flex items-center justify-between px-1",children:e.jsxs("label",{className:"flex items-center gap-2 text-[10px] font-bold uppercase cursor-pointer select-none opacity-60 hover:opacity-100 transition",children:[e.jsx("input",{type:"checkbox",checked:ze.is_rtl,onChange:t=>va({...ze,is_rtl:t.target.checked}),className:"w-4 h-4 rounded border-black/10 accent-blue-600"}),"RTL Language"]})}),e.jsxs("button",{onClick:_o,disabled:!ze.code||!ze.name,className:"w-full mt-2 px-4 py-3 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-black uppercase tracking-widest shadow-lg transition disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[e.jsx(vr,{className:"w-4 h-4"}),"Add Language"]})]})})]})},"languages"),o==="cms"&&e.jsxs(ie.div,{initial:{opacity:0,y:30}
122,animate:{opacity:1,y:0},exit:{opacity:0,y:-30},className:"space-y-0",children:[e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between px-4 md:px-6 py-4 rounded-t-[2rem] bg-white dark:bg-white/[0.03] border border-black/5 dark:border-indigo-500/10 backdrop-blur-3xl shadow-sm gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-indigo-600 flex items-center justify-center text-white shadow-lg shadow-indigo-600/30 shrink-0",children:e.jsx(ga,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-black dark:text-white tracking-tight leading-none",children:"Content Editor"}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 mt-1 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 text-[10px] font-black uppercase tracking-widest border border-emerald-500/20",children:[e.jsx(Ut,{className:"w-3 h-3"})," Live"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:gap-3 w-full md:w-auto",children:[e.jsxs("div",{className:"flex flex-1 md:flex-none items-center gap-2 px-3 md:px-4 py-2 rounded-xl bg-blue-50 dark:bg-blue-500/10 border border-blue-200 dark:border-blue-500/20",children:[e.jsx(St,{className:"w-4 h-4 text-blue-500"}),e.jsx("select",{value:fe,onChange:t=>Dr(t.target.value),className:"bg-transparent border-none outline-none text-sm font-black text-blue-600 dark:text-blue-400 cursor-pointer p-0 uppercase w-full",children:ja.filter(t=>t.is_enabled).map(t=>e.jsxs("option",{value:t.code,children:[t.name," (",t.code.toUpperCase(),")"]},t.code))})]}),e.jsxs("div",{className:"flex flex-1 md:flex-none items-center gap-2 px-3 md:px-4 py-2 rounded-xl bg-indigo-50 dark:bg-indigo-500/5 border border-indigo-100 dark:border-indigo-500/10",children:[e.jsx(Xi,{className:"w-4 h-4 text-indigo-500"}),e.jsxs("select",{value:Pe||"all",onChange:t=>Tn(t.target.value==="all"?null:t.target.value),className:"bg-transparent border-none outline-none text-sm font-black uppercase text-indigo-600 dark:text-indigo-400 cursor-pointer p-0 w-full",children:[e.jsx("option",{value:"all",children:"ALL PAGES"}),Array.from(new Set(ns.map(t=>t.key_path.split(".")[0]))).sort().map(t=>e.jsx("option",{value:t,children:t.toUpperCase()},t))]})]}),e.jsxs("div",{className:"flex items-center border border-black/10 dark:border-white/10 rounded-xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>{Br("ai"),Xt(null)},className:`h-10 px-3 md:px-4 flex items-center gap-1.5 text-[10px] md:text-[11px] font-bold uppercase tracking-wider transition-all ${Xs==="ai"?"bg-gradient-to-r from-purple-600 to-indigo-600 text-white shadow-inner":"text-black/40 dark:text-white/30 hover:bg-black/5 dark:hover:bg-white/5"}`,children:[e.jsx(ye,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"AI"})]}),e.jsxs("button",{onClick:()=>Br("keys"),className:`h-10 px-3 md:px-4 flex items-center gap-1.5 text-[10px] md:text-[11px] font-bold uppercase tracking-wider transition-all ${Xs==="keys"?"bg-indigo-600 text-white shadow-inner":"text-black/40 dark:text-white/30 hover:bg-black/5 dark:hover:bg-white/5"}`,children:[e.jsx(ga,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Keys"})]})]}),e.jsxs("button",{onClick:()=>Fr(!ma),className:`h-10 px-3 md:px-4 rounded-xl border transition-all flex items-center justify-center gap-2 text-[11px] md:text-xs font-bold uppercase tracking-wider ${ma?"bg-emerald-600 border-emerald-500 text-white shadow-lg shadow-emerald-600/20":"border-black/10 dark:border-white/10 text-black/50 dark:text-white/40 hover:border-emerald-500/30"}`,children:[e.jsx(Ot,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:ma?"Preview ON":"Preview"})]})]})]}),Xs==="keys"&&e.jsx(e.Fragment,{children:e.jsx("div",{className:"px-4 md:px-6 py-3 bg-white/50 dark:bg-black/20 border-x border-black/5 dark:border-white/5 space-y-3",children:e.jsxs("div",{className:"flex flex-col lg:flex-row items-stretch lg:items-center gap-3 md:gap-4",children:[e.jsx("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1 lg:pb-0 scrollbar-hide shrink-0",children:[{id:"all",label:"All",icon:aa},{id:"hero",label:"Hero",icon:Xi},{id:"solution",label:"Solutions",icon:Ut},{id:"chat",label:"Chat",icon:Ki},{id:"nav",label:"Nav",icon:St},{id:"cta",label:"CTA",icon:Dt},{id:"footer",label:"Footer",icon:xl}].map(t=>e.jsxs("button",{onClick:()=>
122ds(t.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg transition-all whitespace-nowrap text-[10px] font-black uppercase tracking-wider border ${na===t.id?"bg-indigo-600 border-indigo-500 text-white shadow-md":"bg-white dark:bg-white/[0.03] text-black/40 dark:text-white/30 border-black/5 dark:border-white/5 hover:bg-black/5 dark:hover:bg-white/5 hover:text-black dark:hover:text-white"}`,children:[e.jsx(t.icon,{className:`w-3 h-3 ${na===t.id?"text-white":"text-indigo-500/50"}`}),t.label]},t.id))}),e.jsx("div",{className:"hidden lg:block w-px h-6 bg-black/5 dark:bg-white/10 mx-1"}),e.jsxs("div",{className:"w-full flex-1 relative group",children:[e.jsx(Ds,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-black/20 dark:text-white/20 group-focus-within:text-indigo-600 transition-colors"}),e.jsx("input",{type:"text",placeholder:"Search keys...",value:wt,onChange:t=>Oa(t.target.value),className:"w-full bg-white dark:bg-black/40 border border-black/10 dark:border-white/10 rounded-xl py-2 pl-9 pr-4 text-sm font-medium text-black dark:text-white focus:outline-none focus:ring-2 ring-indigo-500/20 transition-all"})]}),Pe&&e.jsxs("button",{onClick:()=>Br("ai"),className:"h-10 px-4 rounded-xl bg-gradient-to-r from-purple-600 to-indigo-600 text-white hover:from-purple-500 hover:to-indigo-500 shadow-lg shadow-purple-500/20 active:scale-95 transition-all flex items-center gap-2 text-[11px] md:text-xs font-bold uppercase tracking-wider",children:[e.jsx(ye,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"EDIT WITH AI"}),e.jsx("span",{className:"sm:hidden text-[9px] font-black",children:"AI"})]}),e.jsxs("div",{className:"hidden xs:flex items-center gap-2 px-3 py-2 rounded-xl bg-blue-50 dark:bg-blue-500/5 border border-blue-100 dark:border-blue-500/10",children:[e.jsx(vr,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-[10px] md:text-xs font-bold uppercase text-blue-600 dark:text-blue-400",children:((Ui=ja.find(t=>t.code===fe))==null?void 0:Ui.name)||fe.toUpperCase()})]})]})})}),e.jsxs("div",{ref:zr,className:"flex flex-col md:flex-row relative",children:[e.jsx("div",{style:ma?{width:window.innerWidth<768?"100%":`${Ml}%`,minWidth:window.innerWidth<768?"100%":"300px"}:{width:"100%"},className:"transition-[width] duration-100 shrink-0 relative",children:Xs==="ai"?e.jsx(ed,{embedded:!0,selectedPageSlug:Pe||Yl||"home",selectedLanguage:fe,onApplyChanges:Oo,isIframeLoading:J}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-white dark:bg-[#0a0a0a] rounded-b-[2rem] border border-t-0 border-black/10 dark:border-white/10 shadow-sm overflow-hidden min-h-[500px]",children:e.jsxs("div",{className:"overflow-x-auto overflow-y-auto max-h-[calc(100vh-220px)]",children:[e.jsxs("table",{className:"hidden md:table w-full text-left border-collapse",children:[e.jsx("thead",{className:"sticky top-0 z-10",children:e.jsxs("tr",{className:"bg-gray-50 dark:bg-white/[0.03] border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"px-4 py-3 font-bold text-[10px] uppercase tracking-wider text-black/30 dark:text-white/30",children:"Key & Content"}),e.jsx("th",{className:"px-4 py-3 font-bold text-[10px] uppercase tracking-wider text-black/30 dark:text-white/30 text-right w-24",children:"Status"})]})}),e.jsx("tbody",{className:"divide-y divide-black/5 dark:divide-white/5",children:(()=>{const t=ns.filter(a=>{const s=!Pe||Pe==="all"||a.key_path.startsWith(Pe+".")||a.key_path===Pe,n=na==="all"||a.key_path.includes(na);return(!wt||a.key_path.toLowerCase().includes(wt.toLowerCase())||a.content&&a.content.toLowerCase().includes(wt.toLowerCase())||a.ref_content&&a.ref_content.toLowerCase().includes(wt.toLowerCase()))&&s&&n}).sort((a,s)=>a.key_path.localeCompare(s.key_path));return t.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:2,className:"py-48 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-6 opacity-20",children:[e.jsx(aa,{className:"w-20 h-20 text-indigo-500"}),e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.3em]",children:"No Assets Found In Current Scoping"})]})})}):t.slice(0,80).map(a=>e.jsxs("tr",{onClick:()=>Xt(a),className:"group hover:bg-indigo-50/50 dark:hover:bg-indigo-500/[0.03] transition-colors cursor-pointer",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-indigo-600 text-white text-[8px] font-bold uppercase",children:a.key_path.split(".")[0]}),e.jsx("span",{className:"text-[10px] font-mono text-black/25 dark:text-white/25 truncate",children:a.key_path})]}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/30 leading-snug truncate italic",children:a.ref_content||a.content}),e.jsx("textarea",{className:"w-full bg-transparent border border-indigo-500/10 hover:border-indigo-500/30 focus:border-indigo-500 rounded-lg outline-none text-sm font-medium text-black dark:text-white min-h-[32px] resize-none leading-snug p-2 focus:ring-2 ring-indigo-500/10 transition-all",value:a.content,rows:1,onChange:s=>{const n=s.target.value;Da(h=>h.map(k=>k.key_path===a.key_path?{...k,content:n}:k))},onBlur:s=>pr(fe,a.key_path,s.target.value),onClick:s=>s.stopPropagation(),placeholder:"Enter translation..."})]})}
122),e.jsx("td",{className:"py-3 px-4 text-right align-top",children:e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${a.content===a.ref_content&&fe!=="en"?"bg-amber-500 animate-pulse":"bg-emerald-500"}`}),e.jsxs("button",{onClick:s=>{s.stopPropagation(),Ci(a,"Professional")},className:"text-[9px] font-bold text-indigo-500 hover:text-indigo-600 transition flex items-center gap-1 opacity-0 group-hover:opacity-100",children:[e.jsx(ye,{className:"w-3 h-3"})," AI"]})]})})]},a.key_path))})()})]}),e.jsx("div",{className:"md:hidden grid grid-cols-1 divide-y divide-black/5 dark:divide-white/5",children:(()=>{const t=ns.filter(a=>{const s=!Pe||Pe==="all"||a.key_path.startsWith(Pe+".")||a.key_path===Pe,n=na==="all"||a.key_path.includes(na);return(!wt||a.key_path.toLowerCase().includes(wt.toLowerCase())||a.content&&a.content.toLowerCase().includes(wt.toLowerCase())||a.ref_content&&a.ref_content.toLowerCase().includes(wt.toLowerCase()))&&s&&n}).sort((a,s)=>a.key_path.localeCompare(s.key_path));return t.length===0?null:t.slice(0,80).map(a=>e.jsxs("div",{onClick:()=>Xt(a),className:"p-4 bg-white dark:bg-black/20 hover:bg-indigo-50/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-indigo-600 text-white text-[8px] font-bold uppercase",children:a.key_path.split(".")[0]}),e.jsx("span",{className:"text-[10px] font-mono text-black/25 dark:text-white/25 truncate max-w-[150px]",children:a.key_path})]}),e.jsx("div",{className:`w-2 h-2 rounded-full ${a.content===a.ref_content&&fe!=="en"?"bg-amber-500 animate-pulse":"bg-emerald-500"}`})]}),e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 italic mb-2 line-clamp-1",children:a.ref_content||a.content}),e.jsx("textarea",{className:"w-full bg-white dark:bg-white/[0.05] border border-indigo-500/10 rounded-lg text-sm p-3 focus:outline-none focus:ring-2 ring-indigo-500/20",value:a.content,rows:2,onChange:s=>{const n=s.target.value;Da(h=>h.map(k=>k.key_path===a.key_path?{...k,content:n}:k))},onBlur:s=>pr(fe,a.key_path,s.target.value),onClick:s=>s.stopPropagation()})]},a.key_path))})()}),ns.length===0&&e.jsx("div",{className:"py-48 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-6 opacity-20",children:[e.jsx(aa,{className:"w-20 h-20 text-indigo-500"}),e.jsx("p",{className:"text-sm font-black uppercase tracking-[0.3em]",children:"No Assets Found"})]})})]})}),e.jsx(yt,{children:bt&&e.jsxs(e.Fragment,{children:[e.jsx(ie.div,{initial:{opacity:0}
122,animate:{opacity:1},exit:{opacity:0},onClick:()=>Xt(null),className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[190] md:hidden"}),e.jsxs(ie.div,{initial:{opacity:0,scale:.95,x:window.innerWidth<768?0:100,y:window.innerWidth<768?100:0},animate:{opacity:1,scale:1,x:0,y:0},exit:{opacity:0,scale:.95,x:window.innerWidth<768?0:100,y:window.innerWidth<768?100:0},className:"fixed bottom-0 md:top-8 right-0 md:right-8 md:bottom-8 w-full md:w-[550px] h-[90vh] md:h-auto bg-white/95 dark:bg-[#0a0a0a]/95 backdrop-blur-3xl border-t md:border border-black/10 dark:border-white/10 rounded-t-[2.5rem] md:rounded-[4rem] shadow-[0_-20px_50px_rgba(0,0,0,0.3)] md:shadow-[0_40px_100px_-20px_rgba(0,0,0,0.5)] z-[200] flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-12 border-b border-black/5 dark:border-white/5 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 rounded-[1.75rem] bg-purple-500/10 flex items-center justify-center text-purple-500",children:e.jsx(fa,{className:"w-8 h-8"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-2xl font-black tracking-tight leading-none mb-2",children:"Neural Studio"}),e.jsx("p",{className:"text-[10px] font-black text-black/30 dark:text-white/30 uppercase tracking-[0.2em]",children:bt.key_path})]})]}),e.jsx("button",{onClick:()=>Xt(null),className:"w-14 h-14 rounded-2xl bg-black/5 dark:bg-white/5 flex items-center justify-center text-black/40 hover:bg-red-500 hover:text-white transition-all shadow-inner",children:e.jsx(kt,{className:"w-6 h-6"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-12 space-y-12 custom-scrollbar",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx("h5",{className:"text-[10px] font-black uppercase tracking-[0.3em] text-black/20 dark:text-white/20",children:"Linguistic Comparison"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"p-8 rounded-[2.5rem] bg-black/[0.02] dark:bg-white/[0.01] border border-black/5 text-[15px] font-medium italic text-black/50 dark:text-white/30 leading-relaxed",children:bt.ref_content||bt.content}),e.jsx("textarea",{className:"w-full p-8 rounded-[2.5rem] bg-indigo-500/[0.03] border-2 border-indigo-500/10 text-xl font-bold text-black dark:text-white outline-none focus:border-indigo-500 transition-all leading-relaxed min-h-[160px]",value:bt.content,onChange:t=>{const a=t.target.value;Da(s=>s.map(n=>n.key_path===bt.key_path?{...n,content:a}:n)),Xt({...bt,content:a})}})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h5",{className:"text-[10px] font-black uppercase tracking-[0.3em] text-black/20 dark:text-white/20",children:"Neural Toning Selection"}),Wt&&e.jsx("span",{className:"text-[10px] font-bold text-indigo-500 animate-pulse uppercase tracking-widest",children:Wt})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[{id:"Professional",label:"CORPORATE",color:"bg-blue-500",desc:"Clinical & Formal"},{id:"Impactful",label:"DYNAMIC",color:"bg-purple-500",desc:"Punchy & Catchy"},{id:"Concerned",label:"EMPATHIC",color:"bg-emerald-500",desc:"Warm & Human"},{id:"Concise",label:"MINIMAL",color:"bg-amber-500",desc:"Brief & Functional"}].map(t=>e.jsxs("button",{disabled:!!Wt,onClick:()=>{Ci(bt,t.id).then(a=>{a&&Xt(s=>s?{...s,content:a}:null)})},className:"p-8 rounded-[2rem] bg-white dark:bg-white/5 border border-black/5 hover:border-indigo-500/30 text-left transition-all hover:shadow-2xl hover:shadow-indigo-500/10 group disabled:opacity-50",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${t.color}`}),e.jsx("span",{className:"text-[11px] font-black tracking-widest group-hover:text-indigo-600",children:t.label})]}),e.jsx("p",{className:"text-[10px] font-medium text-black/30 dark:text-white/30 uppercase",children:t.desc})]},t.id))})]}),e.jsxs("div",{className:"flex items-center justify-between p-10 rounded-[2.5rem] bg-black/[0.03] dark:bg-white/[0.02] border border-black/5",children:[e.jsxs("div",{className:"flex gap-12",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-black uppercase text-black/30 mb-1",children:"Characters"}),e.jsx("span",{className:"text-2xl font-black text-black/80 dark:text-white/60 font-mono tracking-tighter",children:bt.content.length})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[10px] font-black uppercase text-black/30 mb-1",children:"Words"}),e.jsx("span",{className:"text-2xl font-black text-black/80 dark:text-white/60 font-mono tracking-tighter",children:bt.content.trim().split(/\s+/).length})]})]}),e.jsx("div",{className:"w-px h-10 bg-black/10"}),e.jsxs("div",{className:"text-right",children:[e.jsx("span",{className:"text-[10px] font-black uppercase text-black/30 mb-2 block tracking-widest",children:"Last Modified"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-black text-indigo-600",children:[e.jsx(Ad,{className:"w-4 h-4"}),new Date(bt.updated_at||Date.now()).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})]}),e.jsxs("div",{className:"p-12 border-t border-black/5 dark:border-white/5 bg-gray-50/50 dark:bg-white/[0.01] flex gap-6",children:[e.jsx("button",{onClick:()=>Xt(null),className:"flex-1 h-16 rounded-[2rem] bg-black/5 hover:bg-black/10 transition-all text-xs font-black uppercase tracking-widest text-black/60",children:"Discard Draft"}),e.jsx("button",{onClick:()=>{pr(fe,bt.key_path,bt.content),Xt(null)},className:"flex-[1.5] h-16 rounded-[2rem] bg-indigo-600 text-white shadow-2xl shadow-indigo-600/40 hover:scale-[1.02] active:scale-95 transition-all text-xs font-black uppercase tracking-widest",children:"Commit Modification"})]})]})]})})]})}),ma&&e.jsxs("div",{onMouseDown:Jn,className:"w-3 shrink-0 cursor-col-resize relative group z-50 flex items-center justify-center",title:"Drag to resize",children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-[3px] rounded-full bg-black/5 dark:bg-white/5 group-hover:bg-indigo-500/40 group-active:bg-indigo-500 transition-colors"}),e.jsx("div",{className:"relative z-10 flex flex-col gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[...Array(5)].map((t,a)=>e.jsx("div",{className:"w-1 h-1 rounded-full bg-indigo-400"},a))}),e.jsx("div",{className:"absolute inset-y-0 -left-2 -right-2"})]}),ma&&e.jsxs(ie.div,{initial:{opacity:0,x:50}
122,animate:{opacity:1,x:0},exit:{opacity:0,x:50},style:{width:`${100-Ml}%`},className:"sticky top-4 h-[calc(100vh-2rem)] flex flex-col rounded-[3rem] overflow-hidden border border-black/10 dark:border-white/10 shadow-2xl bg-white dark:bg-[#0a0a0a] shrink-0",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-gray-50 dark:bg-white/[0.02] border-b border-black/5 dark:border-white/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-400"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-400"})]}),e.jsxs("div",{className:"px-3 py-1 rounded-lg bg-black/[0.03] dark:bg-white/[0.03] border border-black/5 dark:border-white/5 flex items-center gap-2",children:[e.jsx(Ea,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-[11px] font-mono text-black/40 dark:text-white/40 tracking-tight",children:["emotionlogic.ai",ir(Pe)]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-blue-500 text-white text-[10px] font-black uppercase shadow-sm",children:fe.toUpperCase()}),e.jsx("button",{onClick:mi,disabled:ne,className:`flex items-center gap-1.5 px-3 py-1 rounded-md bg-emerald-600 hover:bg-emerald-500 text-white text-[10px] font-black uppercase shadow-sm transition-colors ${ne?"opacity-50 cursor-not-allowed":""}`,title:"Sync new English keys from JSON files into the Database",children:ne?"Syncing...":"Sync from Files"}),e.jsxs("button",{onClick:eo,disabled:Ht,className:`flex items-center gap-1.5 px-3 py-1 rounded-md bg-gradient-to-r from-purple-600 to-indigo-600 text-white text-[10px] font-black uppercase shadow-lg shadow-purple-500/20 transition-transform cursor-pointer ${Ht?"opacity-50 cursor-not-allowed":"hover:scale-105"}`,title:Pe&&Pe!=="all"?`Translate missing keys for ${Pe.toUpperCase()} to ALL languages`:"Translate ALL missing keys to ALL languages",children:[e.jsx(Dt,{className:`w-3 h-3 ${Ht?"animate-pulse":""}`}),Ht?"Translating...":"Translate"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>{if(ke.current&&ke.current.src){const t=new URL(ke.current.src);t.searchParams.set("t",Date.now().toString()),ke.current.src=t.toString()}},className:"w-8 h-8 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 flex items-center justify-center transition",children:e.jsx(tt,{className:"w-4 h-4 text-black/30 dark:text-white/30"})}),e.jsx("button",{onClick:()=>window.open(ir(Pe),"_blank"),className:"w-8 h-8 rounded-lg hover:bg-black/5 dark:hover:bg-white/5 flex items-center justify-center transition",children:e.jsx(sa,{className:"w-4 h-4 text-black/30 dark:text-white/30"})}),e.jsx("button",{onClick:()=>Fr(!1),className:"w-8 h-8 rounded-lg hover:bg-red-500/10 flex items-center justify-center transition group",children:e.jsx(kt,{className:"w-4 h-4 text-black/30 dark:text-white/30 group-hover:text-red-500"})})]})]}),e.jsx("div",{className:"flex items-center justify-center gap-2 py-3 bg-gray-50/50 dark:bg-white/[0.01] border-b border-black/5 dark:border-white/5 shrink-0",children:[{icon:Ot,label:"Desktop",width:"100%"},{icon:$r,label:"Tablet",width:"768px"},{icon:Is,label:"Mobile",width:"375px"}].map(t=>e.jsxs("button",{onClick:()=>{const a=ke.current;a&&(a.style.width=t.width,a.style.margin=t.width==="100%"?"0":"0 auto")},className:"px-4 py-2 rounded-xl text-[10px] font-black uppercase tracking-widest flex items-center gap-2 hover:bg-black/5 dark:hover:bg-white/5 transition text-black/40 dark:text-white/40",children:[e.jsx(t.icon,{className:"w-3.5 h-3.5"}),t.label]},t.label))}),e.jsx("div",{className:"flex-1 bg-white dark:bg-[#111] overflow-hidden relative",children:e.jsx("iframe",{ref:ke,src:`${ir(Pe)}?cms_edit=1&cms_lang=${fe}${Hn?"&cms_rtl=1":""}`,className:"w-full h-full border-0 bg-white transition-all duration-300",title:"Page Preview",style:{transformOrigin:"top left"},onLoad:()=>{}})}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-gray-50 dark:bg-white/[0.02] border-t border-black/5 dark:border-white/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500 animate-pulse"}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-black/30 dark:text-white/30",children:"Live Preview"}),e.jsxs("span",{className:"px-2 py-0.5 rounded-md bg-blue-100 dar
122k:bg-blue-500/20 text-blue-700 dark:text-blue-300 text-[10px] font-black uppercase",children:[((Fi=ja.find(t=>t.code===fe))==null?void 0:Fi.name)||fe.toUpperCase()," (",fe.toUpperCase(),")"]}),e.jsxs("button",{onClick:()=>{ke.current&&ke.current.contentWindow&&ke.current.contentWindow.postMessage({type:"emlo_cms_trigger_save"},"*")},className:"flex items-center gap-2 px-4 py-1.5 rounded-full bg-emerald-600 text-white hover:bg-emerald-500 transition-all active:scale-95 shadow-lg shadow-emerald-600/20 text-[10px] font-black uppercase tracking-widest ml-4 group",children:[e.jsx(Ct,{className:"w-3 h-3 group-hover:scale-110 transition-transform"}),"Save Changes"]})]}),e.jsxs("span",{className:"text-[10px] font-mono text-black/20 dark:text-white/20",children:["Page: ",Pe||"All"]})]})]})]})]},"cms-command-center"),o==="design"&&e.jsxs(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(ol,{className:"w-5 h-5"})," Home Page: Research Partners"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-6",children:'Manage the logos displayed in the "Researched & Validated" banner (Universities, Labs).'}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-8",children:[e.jsxs("div",{"data-emlo-file-drop-target":!0,tabIndex:0,onPaste:t=>yi(t,"partner"),onDrop:t=>{var s;t.preventDefault();const a=(s=t.dataTransfer.files)==null?void 0:s[0];a!=null&&a.type.startsWith("image/")&&$a({target:{files:[a]}},"partner",void 0,a.name.split(".")[0])},onDragOver:t=>t.preventDefault(),className:"relative p-4 rounded-xl border-2 border-dashed border-blue-500/30 dark:border-blue-500/20 bg-blue-500/5 flex flex-col gap-3 group transition-all hover:border-blue-500/50 focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 outline-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus:opacity-100 pointer-events-none transition-opacity",children:e.jsx("div",{className:"bg-blue-600 text-white text-[10px] font-bold px-3 py-1 rounded-full shadow-lg",children:"PASTE / DROP IMAGE HERE"})}),Ze&&e.jsx("div",{className:`text-[10px] font-bold px-2 py-1 rounded-lg text-center transition-all ${Ze.ok?"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-300":"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"}`,children:Ze.msg}),e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-widest text-blue-600 dark:text-blue-400 mb-1",children:"Add via URL / Paste Image"}),e.jsx("input",{type:"text",placeholder:"Logo URL / Path",className:"w-full text-xs p-2 bg-white dark:bg-black border border-black/5 rounded-lg outline-none focus:border-blue-500 transition",value:Me.type==="partner"?Me.url:"",onChange:t=>ra({...Me,url:t.target.value,type:"partner"})}),e.jsx("input",{type:"text",placeholder:"Partner Name",className:"w-full text-xs p-2 bg-white dark:bg-black border border-black/5 rounded-lg outline-none focus:border-blue-500 transition",value:Me.type==="partner"?Me.name:"",onChange:t=>ra({...Me,name:t.target.value,type:"partner"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>$a(null,"partner",Me.url,Me.name),className:"flex-1 px-3 py-2 bg-blue-600 text-white text-[10px] font-bold rounded-lg hover:bg-blue-700 transition",children:"SUBMIT URL"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"file",onChange:t=>$a(t,"partner"),className:"absolute inset-0 opacity-0 cursor-pointer",accept:"image/*"}),e.jsx("button",{className:"px-3 py-2 border border-black/10 dark:border-white/10 text-[10px] font-bold rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition",children:"UPLOAD FILE"})]})]})]}),We.map(t=>e.jsxs("div",{className:"relative p-4 rounded-xl bg-white dark:bg-black border border-black/5 dark:border-white/10 flex flex-col gap-3 group overflow-hidden",children:[e.jsx("div",{className:"h-16 flex items-center justify-center relative",children:e.jsx("img",{src:t.logoUrl.startsWith("http")?t.logoUrl:`${m}${t.logoUrl}`,alt:t.name,className:"max-w-full max-h-full object-contain dark:invert grayscale group-hover:grayscale-0 transition-all brightness-110"})}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-black/5 dark:border-white/5",children:[e.jsx("input",{type:"text",className:"w-full text-[10px] p-1 bg-transparent border border-transparent hover:border-black/5 rounded transition font-bold",value:t.name,onChange:a=>hr(t.id,a.target.value,t.logoUrl,"partner")}),e.jsx("input",{type:"text",className:"w-full text-[9px] p-1 bg-transparent border border-transparent hover:border-black/5 rounded transition font-mono text-black/40 dark:text-white/40",value:t.logoUrl,onChange:a=>hr(t.id,t.name,a.target.value,"partner")})]}),e.jsx("button",{onClick:()=>Si(t.id,"partner"),className:`absolute top-2 right-2 p-1.5 rounded-lg text-white transition shadow-lg ${et===`partner-${t.id}`?"bg-red-700 opacity-100 animate-pulse scale-110":"bg-red-500 opacity-0 group-hover:opacity-100"}`,children:et===`partner-${t.id}`?e.jsx("span",{className:"text-[10px] font-bold",children:"Sure?"}):e.jsx(ct,{className:"w-3 h-3"})})]},t.id))]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-8 rounded-[2.5rem] shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-indigo-600 dark:text-indigo-400",children:[e.jsx(qe,{className:"w-5 h-5"})," Enterprise Page: LVA Trusted By"]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-6",children:"Manage the client logos shown on the Enterprise solutions page."}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-8",children:[e.jsxs("div",{"data-emlo-file-drop-target":!0,tabIndex:0,onPaste:t=>yi(t,"client"),onDrop:t=>{var s;t.preventDefault();const a=(s=t.dataTransfer.files)==null?void 0:s[0];a!=null&&a.type.startsWith("image/")&&$a({target:{files:[a]}},"client",void 0,a.name.split(".")[0])},onDragOver:t=>t.preventDefault(),className:"relative p-4 rounded-xl border-2 border-dashed border-indigo-500/30 dark:border-indigo-500/20 bg-indigo-500/5 flex flex-col gap-3 group transition-all hover:border-indigo-500/50 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500/20 outline-none",children:[e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 group-focus:opacity-100 pointer-events-none transition-opacity",children:e.jsx("div",{className:"bg-indigo-600 text-white text-[10px] font-bold px-3 py-1 rounded-full shadow-lg",children:"PASTE / DROP IMAGE HERE"})}),Ze&&e.jsx("div",{className:`text-[10px] font-bold px-2 py-1 rounded-lg text-center transition-all ${Ze.ok?"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-300":"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"}`,children:Ze.msg}),e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-widest text-indigo-600 dark:text-indigo-400 mb-1",children:"Add via URL / Paste Image"}),e.jsx("input",{type:"text",placeholder:"Logo URL / Path",className:"w-full text-xs p-2 bg-white dark:bg-black border border-black/5 rounded-lg outline-none focus:border-indigo-500 transition",value:Me.type==="client"?Me.url:"",onChange:t=>ra({...Me,url:t.target.value,type:"client"})}),e.jsx("input",{type:"text",placeholder:"Client Name",className:"w-full text-xs p-2 bg-white dark:bg-black border border-black/5 rounded-lg outline-none focus:border-indigo-500 transition",value:Me.type==="client"?Me.name:"",onChange:t=>ra({...Me,name:t.target.value,type:"client"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>$a(null,"client",Me.url,Me.name),className:"flex-1 px-3 py-2 bg-indigo-600 text-white text-[10px] font-bold rounded-lg hover:bg-indigo-700 transition",children:"SUBMIT URL"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"file",onChange:t=>$a(t,"client"),className:"absolute inset-0 opacity-0 cursor-pointer",accept:"image/*"}),e.jsx("button",{className:"px-3 py-2 border border-black/10 dark:border-white/10 text-[10px] font-bold rounded-lg hover:bg-black/5 dark:hover:bg-white/5 transition",children:"UPLOAD FILE"})]})]})]}),Tt.map(t=>e.jsxs("div",{className:"relative p-4 rounded-xl bg-white dark:bg-black border border-black/5 dark:border-white/10 flex flex-col gap-3 group overflow-hidden",children:[e.jsx("div",{className:"h-16 flex items-center justify-center relative",children:e.jsx("img",{src:t.logoUrl.startsWith("http")?t.logoUrl:`${m}${t.logoUrl}`,alt:t.name,className:"max-w-full max-h-full object-contain dark:invert grayscale group-hover:grayscale-0 transition-all brightness-110"})}),e.jsxs("div",{className:"space-y-2 pt-2 border-t border-black/5 dark:border-white/5",children:[e.jsx("input",{type:"text",className:"w-full text-[10px] p-1 bg-transparent border border-transparent hover:border-black/5 rounded transition font-bold",value:t.name,onChange:a=>hr(t.id,a.target.value,t.logoUrl,"client")}
122),e.jsx("input",{type:"text",className:"w-full text-[9px] p-1 bg-transparent border border-transparent hover:border-black/5 rounded transition font-mono text-black/40 dark:text-white/40",value:t.logoUrl,onChange:a=>hr(t.id,t.name,a.target.value,"client")})]}),e.jsx("button",{onClick:()=>Si(t.id,"client"),className:`absolute top-2 right-2 p-1.5 rounded-lg text-white transition shadow-lg ${et===`client-${t.id}`?"bg-red-700 opacity-100 animate-pulse scale-110":"bg-red-500 opacity-0 group-hover:opacity-100"}`,children:et===`client-${t.id}`?e.jsx("span",{className:"text-[10px] font-bold",children:"Sure?"}):e.jsx(ct,{className:"w-3 h-3"})})]},t.id))]})]})]},"design"),o==="leads"&&e.jsx(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsxs("h3",{className:"text-xl font-bold mb-2 flex items-center gap-2 text-orange-600 dark:text-orange-400",children:[e.jsx(Wi,{className:"w-5 h-5"})," Demo Requests"]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-6 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50",children:"Submitted demo booking requests, separated from spam and attack noise."}),e.jsx("div",{className:"inline-flex rounded-2xl border border-black/10 dark:border-white/10 bg-white dark:bg-black/40 p-1 shadow-sm",children:[{id:"legitimate",label:"Legitimate",count:Ri.length},{id:"non-legitimate",label:"Non-legitimate",count:Mi.length}].map(t=>e.jsxs("button",{onClick:()=>Cl(t.id),className:`px-4 py-2 rounded-xl text-[10px] md:text-xs font-black uppercase tracking-widest transition ${zt===t.id?t.id==="legitimate"?"bg-emerald-500 text-white shadow-lg shadow-emerald-500/20":"bg-red-500 text-white shadow-lg shadow-red-500/20":"text-black/45 dark:text-white/45 hover:text-black dark:hover:text-white"}`,children:[t.label," ",e.jsx("span",{className:"ml-1 opacity-80",children:t.count})]},t.id))})]}),gr.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{const t=["Name","Email","Company","Phone","Preferred Date","Industry","Message","Status","Referrer","Landing Page","UTM Source","UTM Term","Time on Site (s)","Journey","Date"],a=gr.map(L=>[L.name,L.email,L.company||"",L.phone||"",L.preferredDate||"",L.vertical||"",(L.message||"").replace(/"/g,'""'),L.status,L.referrer||"",L.landingPage||"",L.utmSource||"",L.utmTerm||"",L.timeOnSite||0,(L.journey||"").replace(/"/g,'""'),L.createdAt].map(X=>`"${X}"`).join(",")),s=[t.join(","),...a].join(` 123`),n=new Blob([s],{type:"text/csv"}),h=URL.createObjectURL(n),k=document.createElement("a");k.href=h,k.download=`demo-leads-${new Date().toISOString().slice(0,10)}.csv`,k.click(),URL.revokeObjectURL(h)},className:"px-3 py-2 rounded-lg bg-orange-600 hover:bg-orange-700 text-white text-[10px] md:text-xs font-black uppercase tracking-widest transition flex items-center gap-2",children:[e.jsx(Rt,{className:"w-3.5 h-3.5"})," CSV"]}),e.jsxs("button",{onClick:async()=>{if(confirm(`Clear ALL ${zt==="legitimate"?"legitimate demo leads":"non-legitimate demo leads"}? This cannot be undone.`))try{await fetch(`${m}/api/demo-requests?type=${zt}`,{method:"DELETE",headers:{"X-Admin-Token":sessionStorage.getItem("adminToken")||""}}),Qe(a=>a.filter(s=>zt==="legitimate"?ys(s):!ys(s)))}catch(a){console.error(a)}},className:"px-3 py-2 rounded-lg bg-red-600/10 hover:bg-red-600 text-red-600 hover:text-white text-[10px] md:text-xs font-black uppercase tracking-widest transition flex items-center gap-2 shadow-sm",children:[e.jsx(ct,{className:"w-3.5 h-3.5"})," Clear All"]})]})]}),gr.length===0?e.jsx("p",{className:"text-sm text-black/30 dark:text-white/30 italic",children:zt==="legitimate"?"No legitimate demo requests in this view.":"No non-legitimate demo requests in this view."}):e.jsx("div",{className:"space-y-3",children:gr.map(t=>e.jsxs("div",{className:"relative p-4 rounded-xl bg-white dark:bg-[#0a0a0a] border border-black/5 dark:border-white/5 shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm text-black dark:text-white",children:t.name}),e.jsxs("p",{className:"text-xs text-black/50 dark:text-white/50",children:[t.email," ",t.company&&`⢠${t.company}`]})]}),e.jsxs("div",{className:"flex items-center gap-2 pr-8",children:[ys(t)&&e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest px-2 py-1 rounded-full bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-300",children:String(t.screeningVerdict||"").toLowerCase()==="malicious"?"Malicious":"Spam"}),e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-widest px-2 py-1 rounded-full ${t.status==="new"?"bg-orange-100 dar
123k:bg-orange-900/30 text-orange-600 dark:text-orange-400":t.status==="contacted"?"bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400":"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400"}`,children:t.status})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2 text-xs text-black/40 dark:text-white/40 mt-2",children:[t.phone&&e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:["ð± ",t.phone]}),t.vertical&&e.jsxs("span",{className:"flex items-center gap-1.5 font-medium text-indigo-600/70 dark:text-indigo-400/70",children:["ð ",t.vertical]}),t.preferredDate&&e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:["ð ",t.preferredDate]})]}),t.message&&e.jsxs("p",{className:"text-xs text-black/60 dark:text-white/60 mt-2 p-2 bg-black/[0.02] dark:bg-white/[0.02] rounded-lg",children:['"',t.message,'"']}),(t.referrer||t.journey)&&e.jsxs("div",{className:"mt-3 p-2.5 rounded-lg bg-blue-50 dark:bg-blue-900/10 border border-blue-100 dark:border-blue-800/30 text-[11px] text-blue-900 dark:text-blue-200 space-y-1",children:[e.jsx("p",{className:"font-bold text-blue-600 dark:text-blue-400 text-[10px] uppercase tracking-widest mb-1",children:"Visitor Analytics"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-0.5",children:[t.referrer&&e.jsxs("span",{children:["ð ",e.jsx("strong",{children:"Source:"})," ",t.referrer]}),t.landingPage&&e.jsxs("span",{children:["ð¬ ",e.jsx("strong",{children:"Landing:"})," ",t.landingPage]}),t.timeOnSite>0&&e.jsxs("span",{children:["â± ",e.jsx("strong",{children:"Time:"})," ",Math.floor(t.timeOnSite/60),"m ",t.timeOnSite%60,"s"]}),t.utmSource&&e.jsxs("span",{children:["ð ",e.jsx("strong",{children:"UTM:"})," ",t.utmSource,"/",t.utmMedium||"-"]}),t.utmCampaign&&e.jsxs("span",{children:["ð¯ ",e.jsx("strong",{children:"Campaign:"})," ",t.utmCampaign]}),t.utmTerm&&e.jsxs("span",{children:["ð ",e.jsx("strong",{children:"Keywords:"})," ",t.utmTerm]})]}),t.journey&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] text-blue-700 dark:text-blue-300 break-all",children:["ðº ",t.journey]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-4 pt-4 border-t border-black/5 dark:border-white/5",children:[e.jsxs("button",{onClick:()=>{const a=`Name: ${t.name} 124Email: ${t.email} 125Company: ${t.company||"N/A"} 126Phone: ${t.phone||"N/A"} 127Industry: ${t.vertical||"N/A"} 128Message: ${t.message||"N/A"} 129Date: ${t.createdAt}`;navigator.clipboard.writeText(a),alert("Lead content copied to clipboard")},className:"px-3 py-1.5 rounded-lg bg-black/5 hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10 text-[10px] font-black uppercase tracking-widest transition flex items-center gap-1.5 text-black/60 dark:text-white/60",children:[e.jsx(ml,{className:"w-3 h-3"})," Copy Content"]}),e.jsxs("a",{href:`mailto:${t.email}?subject=Following up on your Emotion Logic Demo Request&body=Hi ${t.name},%0D%0A%0D%0AThank you for reaching out to Emotion Logic! We received your request and would love to schedule a quick 15-minute introductory call to show you how our Voice AI technology can support ${t.company?t.company:"your team"}.%0D%0A%0D%0APlease let me know what day and time works best for you, or feel free to book a slot directly on my calendar here: [Insert Calendar Link]%0D%0A%0D%0ALooking forward to connecting!%0D%0A%0D%0ABest regards,%0D%0AThe Emotion Logic Team`,className:"px-3 py-1.5 rounded-lg bg-blue-500/10 hover:bg-blue-500/20 text-[10px] font-black uppercase tracking-widest transition flex items-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(_s,{className:"w-3 h-3"})," Email Lead"]}),e.jsxs("button",{onClick:async()=>{rs(t.id);try{const a=await fetch(`${m}/api/admin/generate-lead-reply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lead:t,password:_})}),s=await a.json();a.ok&&s.reply?ht(n=>({...n,[t.id]:s.reply})):alert("Failed to generate reply: "+(s.error||"Unknown error"))}catch{alert("Error connecting to AI backend.")}finally{rs(null)}},disabled:Bt===t.id,className:"px-3 py-1.5 rounded-lg bg-indigo-500/10 hover:bg-indigo-500/20 text-[10px] font-black uppercase tracking-widest transition flex items-center gap-1.5 text-indigo-600 dark:text-indigo-400 disabled:opacity-50",children:[Bt===t.id?e.jsx(V,{className:"w-3 h-3 animate-spin"}):e.jsx(ye,{className:"w-3 h-3"}),Bt===t.id?"Drafting...":"Generate AI Reply"]})]}),at[t.id]&&e.jsxs("div",{className:"mt-4 p-4 rounded-xl bg-indigo-50 dark:bg-indigo-900/10 border border-indigo-100 dark:border-indigo-800/30",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-600 dark:text-indigo-400 flex items-center gap-1.5",children:[e.jsx(ye,{className:"w-3 h-3"})," AI Drafted Response"]}),e.jsx("button",{onClick:()=>ht(a=>{const s={...a};return delete s[t.id],s}),className:"text-black/40 hover:text-red-500 transition",children:e.jsx(kt,{className:"w-4 h-4"})})]}),e.jsx("textarea",{value:at[t.id],onChange:a=>ht(s=>({...s,[t.id]:a.target.value})),className:"w-full h-40 p-3 rounded-lg text-xs border border-black/10 dark:border-white/10 bg-white dark:bg-[#0a0a0a] text-black dark:text-white focus:outline-none focus:border-indigo-500"}),e.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(at[t.id]),alert("Copied to clipboard")},className:"px-3 py-1.5 rounded-lg bg-black/5 hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10 text-[10px] font-bold uppercase transition text-black/70 dark:text-white/70",children:"Copy Text"}),e.jsx("a",{href:`mailto:${t.email}?subject=Following up on your Emotion Logic Demo Request&body=${encodeURIComponent(at[t.id])}`,className:"px-4 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-700 text-[10px] font-black uppercase tracking-widest transition text-white",children:"Open in Mail App"})]})]}),e.jsx("p",{className:"text-[10px] text-black/25 dark:text-white/20 mt-3 font-mono",children:new Date(t.createdAt).toLocaleStr
129ing()}),e.jsx("button",{onClick:async()=>{try{await fetch(`${m}/api/demo-requests/${t.id}`,{method:"DELETE"}),Qe(a=>a.filter(s=>s.id!==t.id))}catch(a){console.error(a)}},className:"absolute top-3 right-3 p-1 rounded-lg text-black/20 dark:text-white/20 hover:text-red-500 hover:bg-red-500/10 transition",title:"Remove lead",children:e.jsx(ct,{className:"w-3.5 h-3.5"})})]},t.id))})]})},"leads"),o==="demos"&&e.jsx(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-indigo-600 dark:text-indigo-400",children:[e.jsx(Es,{className:"w-5 h-5"})," Video Demo Library"]})}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-8",children:"Manage the YouTube videos that appear on the /demos page."}),e.jsx(qd,{}),e.jsx(Xd,{settings:b,setSettings:C,onSettingsSave:mi}),e.jsxs("div",{className:"bg-white dark:bg-black/40 border border-black/5 dark:border-white/5 rounded-2xl p-6 mb-10 space-y-4",children:[e.jsxs("div",{className:"text-xs font-black uppercase tracking-widest text-indigo-600 dark:text-indigo-400 mb-2 flex items-center justify-between",children:[e.jsx("span",{children:"ð Quick Add New Video"}),_r&&e.jsx("span",{className:"text-[10px] animate-pulse",children:"Fetching details..."})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx("input",{type:"text",placeholder:"YouTube URL or ID",className:"w-full text-sm p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 transition",value:st.youtubeId,onChange:async t=>{let a=t.target.value;if(a.includes("youtube.com/")||a.includes("youtu.be/")){const s=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,n=a.match(s);n&&n[2].length===11&&(a=n[2])}if(Gt(s=>({...s,youtubeId:a})),a.length>=11){ls(!0);try{const n=await(await fetch(`${m}/api/videos/metadata?url=${encodeURIComponent(a)}`)).json();n.title&&Gt(h=>({...h,title:h.title||n.title,description:h.description||(n.author?`A strategic analysis from ${n.author}.`:"")}))}catch(s){console.error("Metadata fetch failed",s)}ls(!1)}}}),e.jsx("input",{type:"text",placeholder:"Video Title",className:"w-full text-sm p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 transition",value:st.title,onChange:t=>Gt({...st,title:t.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("select",{className:"w-full text-sm p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 transition",value:st.category,onChange:t=>Gt({...st,category:t.target.value}),children:[e.jsx("option",{value:"PR",children:"PR / Marketing"}),e.jsx("option",{value:"Training",children:"Training Resource"}),e.jsx("option",{value:"Law Enforcement",children:"Law Enforcement"}),e.jsx("option",{value:"Call Centers",children:"Call Centers"}),e.jsx("option",{value:"HR & Recruiting",children:"HR & Recruiting"}),e.jsx("option",{value:"Insurance Claims",children:"Insurance Claims"})]}),e.jsx("input",{type:"text",placeholder:"Short Description",className:"md:col-span-2 w-full text-sm p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 transition",value:st.description,onChange:t=>Gt({...st,description:t.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-1.5 block",children:"ð·ï¸ Tags (comma-separated)"}),e.jsx("input",{type:"text",placeholder:"e.g. fraud, insurance, detection, claims",className:"w-full text-sm p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl outline-none focus:border-indigo-500 transition",value:st.tags,onChange:t=>Gt({...st,tags:t.target.value})}),st.tags&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:st.tags.split(",").map((t,a)=>t.trim()&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 text-[10px] font-bold",children:t.trim()},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-1.5 block",children:"ð Page Associations (show this video first when user comes from these pages)"}),e.jsx("div",{className:"flex flex-wrap gap-2 p-3 bg-gray-50 dark:bg-black/50 border border-black/10 dark:border-white/10 rounded-xl",children:[{slug:"insurance",label:"Insurance"},{slug:"hr",label:"HR"},{slug:"call-centers",label:"Call Centers"},{slug:"investigation",label:"Investigation"},{slug:"market-research",label:"Market Research"},{slug:"med-tech",label:"MedTech"},{slug:"enterprise",label:"Enterprise"},{slug:"feelgpt",label:"FeelGPT"},{slug:"apptone",label:"AppTone"},{slug:"love-detector",label:"Love Detector"},{slug:"smb",label:"SMB"},{slug:"about",label:"About"},{slug:"solutions",label:"Solutions"},{slug:"academy",label:"Academy"}].map(t=>{const a=st.pageAssociations.split(",").map(n=>
129n.trim()).filter(Boolean),s=a.includes(t.slug);return e.jsxs("label",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg cursor-pointer text-xs font-bold transition-all ${s?"bg-indigo-600 text-white shadow-md":"bg-white dark:bg-black border border-black/10 dark:border-white/10 text-black/60 dark:text-white/60 hover:border-indigo-500/30"}`,children:[e.jsx("input",{type:"checkbox",className:"sr-only",checked:s,onChange:()=>{const n=s?a.filter(h=>h!==t.slug).join(", "):[...a,t.slug].join(", ");Gt({...st,pageAssociations:n})}}),t.label]},t.slug)})})]}),e.jsxs("button",{onClick:Eo,className:"w-full py-3 bg-indigo-600 text-white rounded-xl font-bold text-sm hover:bg-indigo-700 transition shadow-lg flex items-center justify-center gap-2",children:[e.jsx(Es,{className:"w-4 h-4"})," SECURE & ADD VIDEO"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/30 dark:text-white/30 mb-2",children:"Existing Assets"}),lt.length===0?e.jsx("p",{className:"text-sm text-black/30 dark:text-white/30 italic",children:"No videos added yet."}):lt.map(t=>e.jsxs("div",{className:"relative p-5 border border-black/10 dark:border-white/10 rounded-2xl bg-white dark:bg-[#0a0a0a] shadow-sm flex flex-col md:flex-row gap-5",children:[e.jsx("div",{className:"w-full md:w-48 aspect-video bg-black rounded-lg overflow-hidden shrink-0 relative",children:e.jsx("img",{src:`https://img.youtube.com/vi/${t.youtubeId}/hqdefault.jpg`,alt:t.title,className:"w-full h-full object-cover"})}),Bs===t.id?e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx("input",{className:"text-sm p-2 bg-black/5 dark:bg-white/5 border border-black/10 rounded-lg outline-none w-full",value:t.title,onChange:a=>Je(s=>s.map(n=>n.id===t.id?{...n,title:a.target.value}:n))}),e.jsxs("select",{className:"text-sm p-2 bg-black/5 dark:bg-white/5 border border-black/10 rounded-lg outline-none w-full",value:t.category,onChange:a=>Je(s=>s.map(n=>n.id===t.id?{...n,category:a.target.value}:n)),children:[e.jsx("option",{value:"PR",children:"PR"}),e.jsx("option",{value:"Training",children:"Training"}),e.jsx("option",{value:"Law Enforcement",children:"Law Enforcement"}),e.jsx("option",{value:"Call Centers",children:"Call Centers"}),e.jsx("option",{value:"HR & Recruiting",children:"HR & Recruiting"}),e.jsx("option",{value:"Insurance Claims",children:"Insurance Claims"})]})]}),e.jsx("textarea",{className:"text-xs p-2 bg-black/5 dark:bg-white/5 border border-black/10 rounded-lg outline-none w-full h-16",value:t.description,onChange:a=>Je(s=>s.map(n=>n.id===t.id?{...n,description:a.target.value}:n))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[9px] font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-1 block",children:"ð·ï¸ Tags"}),e.jsx("input",{className:"text-xs p-2 bg-black/5 dark:bg-white/5 border border-black/10 rounded-lg outline-none w-full",placeholder:"fraud, insurance, detection",value:t.tags||"",onChange:a=>Je(s=>s.map(n=>n.id===t.id?{...n,tags:a.target.value}:n))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[9px] font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-1 block",children:"ð Page Associations"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[{slug:"insurance",label:"Insurance"},{slug:"hr",label:"HR"},{slug:"call-centers",label:"Call Centers"},{slug:"investigation",label:"Investigation"},{slug:"market-research",label:"Market Research"},{slug:"med-tech",label:"MedTech"},{slug:"enterprise",label:"Enterprise"},{slug:"feelgpt",label:"FeelGPT"},{slug:"apptone",label:"AppTone"},{slug:"love-detector",label:"Love Detector"},{slug:"smb",label:"SMB"},{slug:"about",label:"About"},{slug:"solutions",label:"Solutions"},{slug:"academy",label:"Academy"}].map(a=>{const s=(t.page_associations||"").split(",").map(h=>h.trim()).filter(Boolean),n=s.includes(a.slug);return e.jsx("button",{type:"button",onClick:()=>{const h=n?s.filter(k=>k!==a.slug).join(", "):[...s,a.slug].join(", ");Je(k=>k.map(L=>L.id===t.id?{...L,page_associations:h}:L))},className:`px-2 py-1 rounded text-[10px] font-bold transition-all ${n?"bg-indigo-600 text-white":"bg-black/5 dark:bg-white/5 text-black/50 dark:text-white/50 hover:bg-indigo-500/10"}`,children:a.label},a.slug)})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>$o(t.id,{...t,pageAssociations:t.page_associations}),className:"px-4 py-1.5 bg-emerald-600 text-white text-xs font-bold rounded-lg",children:"Save"}),e.jsx("button",{onClick:()=>xs(null),className:"px-4 py-1.5 bg-gray-500/10 text-theme-secondary text-xs font-bold rounded-lg",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-start gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-lg leading-tight",children:t.title}),e.jsx("span",{className:"inline-block px-2 py-0.5 mt-1 bg-black/5 dark:bg-white/10 rounded text-[10px] font-bold uppercase tracking-widest text-black/50 dark:text-white/50",children:t.category})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>xs(t.id),className:"p-2 text-indigo-500 bg-indigo-500/10 rounded-lg hover:bg-indigo-500 hover:text-white transition",title:"Edit Details",children:e.jsx(Tr,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Io(t.id),className:`p-2 rounded-lg transition ${et===`video-${t.id}`?"bg-red-600 text-white animate-pulse scale-110":"text-red-500 bg-red-500/10 hover:bg-red-500 hover:text-white"}`,children:et===`video-${t.id}`?e.jsx("span",{className:"text-xs font-bold",children:"Sure?"}):e.jsx(ct,{className:"w-4 h-4"})})]})]}),e.jsx("p",{className:"text-xs text-black/60 dark:text-white/60 line-clamp-2",children:t.description||"No description provided."}),t.tags&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:t.tags.split(",").map((a,s)=>a.trim()&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 text-[9px] font-bold",children:a.trim()},s))}),t.page_associations&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:t.page_associations.split(",").map((a,s)=>a.trim()&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 text-[9px] font-bold",children:["ð /",a.trim()]},s))})]})]},t.id))]})]})},"demos"),o==="chat"&&e.jsx(ie.div,{initial:{opacity:0,y:10}
129,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-8",children:e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-6 rounded-2xl shadow-sm",children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(Cs,{className:"w-5 h-5"})," Chat Retention Settings"]})}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-white dark:bg-black/20 rounded-xl border border-black/5 dark:border-white/5 mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm",children:"Save Chat History"}),e.jsx("p",{className:"text-xs text-black/50 dark:text-white/50",children:"Store all AI interactions for administrative review."})]}),e.jsx("button",{onClick:()=>C({...b,keepChatHistory:b.keepChatHistory==="1"?"0":"1"}),className:`w-14 h-7 rounded-full transition-colors relative ${b.keepChatHistory==="1"?"bg-blue-600":"bg-gray-300 dark:bg-white/10"}`,children:e.jsx("div",{className:`absolute top-1 w-5 h-5 bg-white rounded-full transition-all ${b.keepChatHistory==="1"?"right-1":"left-1"}`})})]}),e.jsxs("div",{className:`p-4 rounded-xl border mb-8 transition-colors ${b.advancedAiMode==="1"?"bg-blue-50 dark:bg-blue-950/30 border-blue-200 dark:border-blue-800/50":"bg-amber-50 dark:bg-amber-950/20 border-amber-200 dark:border-amber-800/40"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-9 h-9 rounded-xl flex items-center justify-center ${b.advancedAiMode==="1"?"bg-blue-600":"bg-amber-500"}`,children:e.jsx(Dt,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-sm tracking-tight",children:"AI Response Mode"}),e.jsx("p",{className:`text-[11px] font-black uppercase tracking-widest ${b.advancedAiMode==="1"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:b.advancedAiMode==="1"?"â¡ Advanced - Full HTML & Images":"ð¡ Conservative - Text Only"})]})]}),e.jsx("button",{onClick:()=>C({...b,advancedAiMode:b.advancedAiMode==="1"?"0":"1"}),className:`w-14 h-7 rounded-full transition-colors relative ${b.advancedAiMode==="1"?"bg-blue-600":"bg-amber-500"}`,children:e.jsx("div",{className:`absolute top-1 w-5 h-5 bg-white rounded-full transition-all ${b.advancedAiMode==="1"?"right-1":"left-1"}`})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 text-[11px]",children:[e.jsxs("div",{className:`p-2.5 rounded-lg ${b.advancedAiMode==="1"?"bg-blue-100/60 dark:bg-blue-900/30":"bg-white/60 dark:bg-white/5"}`,children:[e.jsx("p",{className:"font-black text-blue-600 dark:text-blue-400 mb-1",children:"â¡ Advanced (ON)"}),e.jsx("p",{className:"text-black/60 dark:text-white/50 leading-relaxed",children:"Generates rich HTML dashboards, visual layouts, and Pollinations images. Higher token usage."})]}),e.jsxs("div",{className:`p-2.5 rounded-lg ${b.advancedAiMode!=="1"?"bg-amber-100/60 dark:bg-amber-900/20":"bg-white/60 dark:bg-white/5"}`,children:[e.jsx("p",{className:"font-black text-amber-600 dark:text-amber-400 mb-1",children:"ð¡ Conservative (OFF)"}),e.jsx("p",{className:"text-black/60 dark:text-white/50 leading-relaxed",children:"Plain text and markdown only. No HTML generation. Lower cost, faster responses."})]})]})]}),e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h3",{className:"text-xl font-bold flex items-center gap-2 text-blue-600 dark:text-blue-400",children:[e.jsx(Ut,{className:"w-5 h-5"})," Chat Session Records"]}),oa.length>0&&e.jsxs("button",{onClick:async()=>{if(confirm("Clear ALL chat history?"))try{await fetch(`${m}/api/admin/chat-sessions`,{method:"DELETE"}),ms([])}catch(t){console.error(t)}},className:"px-4 py-2 rounded-lg bg-red-600/10 hover:bg-red-600 text-red-600 hover:text-white text-xs font-semibold transition flex items-center gap-2",children:[e.jsx(ct,{className:"w-3.5 h-3.5"})," Clear History"]})]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 mb-8",children:"Review all user interactions with the EMLO AI concierge."}),e.jsxs("div",{className:"overflow-x-auto",children:[e.jsxs("table",{className:"hidden md:table w-full border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/10 dark:border-white/10",children:[e.jsx("th",{className:"text-left py-4 px-4 text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:"Timestamp"}),e.jsx("th",{className:"text-left py-4 px-4 text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:"Session ID"}),e.jsx("th",{className:"text-left py-4 px-4 text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:"Questions"}),e.jsx("th",{className:"text-left py-4 px-4 text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:"Insights & Flags"}),e.jsx("th",{className:"text-right py-4 px-4 text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:"Actions"})]})}),e.jsx("tbody",{children:oa.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-12 text-center text-sm text-black/30 dark:text-white/30 italic",children:"No recorded sessions yet."})}):oa.map(t=>e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition",children:[e.jsx("td",{className:"py-4 px-4 text-xs font-semibold text-black/60 dark:text-white/60",children:new Date(t.updated_at).toLocaleStr
129ing([],{dateStyle:"short",timeStyle:"short"})}),e.jsxs("td",{className:"py-4 px-4 text-xs font-mono font-bold text-blue-500",children:[t.session_id.substring(8,16),"..."]}),e.jsx("td",{className:"py-4 px-4 text-xs font-black",children:t.message_count}),e.jsx("td",{className:"py-4 px-4 text-xs",children:t.insight&&t.insight!=="Routine engagement"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"px-2 py-0.5 w-fit rounded-full bg-amber-500/10 border border-amber-500/20 text-amber-600 dark:text-amber-400 text-[8px] font-black uppercase tracking-tighter flex items-center gap-1",children:[e.jsx(Lt,{className:"w-2.5 h-2.5"})," Flagged"]}),e.jsx("span",{className:"text-[10px] text-black/60 dark:text-white/60 font-medium line-clamp-1 max-w-[200px]",title:t.insight,children:t.insight})]}):e.jsx("span",{className:"text-[10px] text-black/30 dark:text-white/30 font-bold uppercase tracking-widest",children:"Routine Engagement"})}),e.jsxs("td",{className:"py-4 px-4 text-right flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:async()=>{hs(t),Gs([]),Hs(!0);try{const s=await(await fetch(`${m}/api/admin/chat-sessions/${t.session_id}/messages`,{headers:{"X-Admin-Token":H}})).json();Gs(Array.isArray(s)?s:[])}catch(a){console.error(a)}Hs(!1)},className:"p-2 rounded-lg bg-blue-600 text-white hover:bg-blue-700 transition shadow-sm",title:"Review Logs",children:e.jsx(Cs,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:async()=>{if(confirm("Permanently delete this session record?"))try{await fetch(`${m}/api/admin/chat-sessions/${t.id}`,{method:"DELETE"}),ms(a=>a.filter(s=>s.id!==t.id))}catch(a){console.error(a)}},className:"p-2 rounded-lg bg-red-500/10 text-red-600 hover:bg-red-600 hover:text-white transition",title:"Purge Record",children:e.jsx(ct,{className:"w-3.5 h-3.5"})})]})]},t.id))})]}),e.jsx("div",{className:"md:hidden grid grid-cols-1 divide-y divide-black/5 dark:divide-white/5 border border-black/5 dark:border-white/5 rounded-2xl overflow-hidden",children:oa.length===0?e.jsx("div",{className:"py-12 text-center text-sm text-black/30 dark:text-white/30 italic bg-white dark:bg-black/20",children:"No recorded sessions yet."}):oa.map(t=>e.jsxs("div",{onClick:async()=>{hs(t),Gs([]),Hs(!0);try{const s=await(await fetch(`${m}/api/admin/chat-sessions/${t.session_id}/messages`,{headers:{"X-Admin-Token":H}})).json();Gs(Array.isArray(s)?s:[])}catch(a){console.error(a)}Hs(!1)},className:"p-4 bg-white dark:bg-black/20 hover:bg-black/5 dark:hover:bg-white/5 transition cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-[10px] font-black text-black/40 dark:text-white/40 uppercase tracking-widest",children:new Date(t.updated_at).toLocaleString([],{dateStyle:"short",timeStyle:"short"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded-full bg-blue-500/10 border border-blue-500/20 text-blue-500 text-[8px] font-black uppercase tracking-widest",children:[t.message_count," MSGS"]}),e.jsx("button",{onClick:async a=>{if(a.stopPropagation(),!!confirm("Permanently delete this session record?"))try{await fetch(`${m}/api/admin/chat-sessions/${t.id}`,{method:"DELETE"}),ms(s=>s.filter(n=>n.id!==t.id))}catch(s){console.error(s)}},className:"p-1.5 rounded-lg text-black/20 dark:text-white/20 hover:text-red-500 transition",children:e.jsx(ct,{className:"w-3.5 h-3.5"})})]})]}),e.jsx("div",{className:"mb-2",children:e.jsxs("p",{className:"text-[11px] font-mono text-blue-600 dark:text-blue-400 font-bold",children:["SID: ",t.session_id.substring(8,24),"..."]})}),t.insight&&t.insight!=="Routine engagement"?e.jsxs("div",{className:"p-2 rounded-lg bg-amber-500/5 border border-amber-500/10 flex items-start gap-2",children:[e.jsx(Lt,{className:"w-3 h-3 text-amber-600 dark:text-amber-500 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-[10px] text-amber-700 dark:text-amber-400 leading-tight font-medium",children:t.insight})]}):e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 uppercase tracking-widest font-bold",children:"Standard Interaction"})]},t.id))})]}),e.jsx(yt,{children:zs&&e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center p-0 md:p-8",children:[e.jsx(ie.div,{initial:{opacity:0}
129,animate:{opacity:1},exit:{opacity:0},onClick:()=>hs(null),className:"absolute inset-0 bg-black/80 backdrop-blur-sm"}),e.jsxs(ie.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.9,opacity:0,y:20},className:"relative bg-white dark:bg-[#0a0a0a] w-full md:max-w-4xl h-full md:h-auto md:max-h-[90vh] md:rounded-[2.5rem] border-x md:border border-black/10 dark:border-white/10 shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-4 md:p-6 border-b border-black/10 dark:border-white/10 bg-gray-50 dark:bg-white/5 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 md:w-12 md:h-12 rounded-2xl bg-blue-600 flex items-center justify-center shadow-lg shadow-blue-500/20 shrink-0",children:e.jsx(Ut,{className:"w-5 h-5 md:w-6 md:h-6 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-black text-base md:text-lg tracking-tight truncate",children:"Interaction Archive"}),e.jsx("p",{className:"text-[10px] md:text-xs opacity-50 font-mono tracking-tighter uppercase truncate",children:zs.session_id})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:async()=>{if(da){ps(!1);return}if(Object.keys(Mt).length>0){ps(!0);return}Pl(!0);try{const a=await(await fetch(`${m}/api/admin/translate-messages`,{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Token":H},body:JSON.stringify({messages:Vs.map(s=>({role:s.role,content:s.content}))})})).json();if(a.success&&a.translations){const s={};a.translations.forEach(n=>{s[n.id]={translated:n.translated,originalLang:n.originalLang}}),Mr(s),ps(!0)}}catch(t){console.error("Translation failed:",t)}Pl(!1)},disabled:Rr||Al||Vs.length===0,className:`flex items-center gap-1.5 md:gap-2 px-3 py-2 md:px-4 md:py-2.5 rounded-xl text-[10px] md:text-[11px] font-black uppercase tracking-wider transition-all shadow-sm shrink-0 ${da?"bg-emerald-600 text-white hover:bg-emerald-700 shadow-emerald-500/20":"bg-blue-600/10 text-blue-600 dark:text-blue-400 hover:bg-blue-600 hover:text-white border border-blue-600/20"}`,title:da?"Show original messages":"Translate all messages to English",children:[Rr?e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(vr,{className:"w-3.5 h-3.5"}),Rr?"Translatingâ¦":da?"ð English ON":"ð Translate"]}),e.jsx("button",{onClick:()=>{hs(null),ps(!1),Mr({})},className:"p-3 rounded-full hover:bg-black/5 dark:hover:bg-white/5 transition",children:e.jsx(kt,{className:"w-6 h-6"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 md:p-8 space-y-6 md:space-y-8 scrollbar-hide",children:Al?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 gap-4",children:[e.jsx(V,{className:"w-8 h-8 animate-spin text-blue-600"}),e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.2em] opacity-40",children:"Decrypting Logs..."})]}):e.jsxs(e.Fragment,{children:[zs.insight&&e.jsxs("div",{className:"p-6 bg-amber-500/5 border-2 border-amber-500/20 rounded-3xl mb-8",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Lt,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-amber-600 dark:text-amber-400",children:"Intelligence Flag"})]}),e.jsxs("p",{className:"text-sm font-bold text-amber-900 dark:text-amber-100 italic",children:['"',zs.insight,'"']})]}),e.jsxs("div",{className:"space-y-6",children:[Vs.length===0&&e.jsx("div",{className:"text-center py-12 text-black/30 dark:text-white/30 text-sm",children:"No messages found for this session."}),Vs.map((t,a)=>{const s=t.role==="model"&&t.content.includes("<div")&&(t.content.includes("class=")||t.content.includes("bg-"));return e.jsxs("div",{className:`flex flex-col ${t.role==="user"?"items-end":"items-start"}`,children:[s?e.jsxs("div",{className:"w-full rounded-3xl overflow-hidden border border-white/10 shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-gray-900 text-white/50 text-[10px] font-black uppercase tracking-widest",children:[e.jsx(fa,{className:"w-3 h-3"})," EMLO.AI - Generated Page Preview"]}),e.jsx("iframe",{srcDoc:`<!DOCTYPE html><html><head> 130 <script src="https://cdn.tailwindcss.com"><\/script> 131 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;900&display=swap" rel="stylesheet"/> 132 <style>*{font-family:'Inter',sans-serif;box-sizing:border-box}body{margin:0;padding:1.5rem;background:#070707;color:#fff}</style> 133 </head><body>${t.content}</body></html>`,className:"w-full border-0",style:{height:"480px"},sandbox:"allow-scripts",title:"AI Generated Page Preview"})]}):e.jsxs("div",{className:`max-w-[92%] md:max-w-[85%] p-4 md:p-5 rounded-3xl text-[14px] leading-relaxed shadow-sm ${t.role==="user"?"bg-gray-900 text-white rounded-tr-none":"bg-gray-100 dark:bg-zinc-800 text-gray-900 dark:text-gray-100 border border-black/5 dark:border-white/10 rounded-tl-none"}`,children:[e.jsxs("div",{className:`text-[9px] uppercase font-black tracking-[0.15em] mb-2 flex items-center gap-2 ${t.role==="user"?"text-white/50":"text-black/40 dark:text-white/40"}`,children:[t.role==="user"?e.jsx(Pd,{className:"w-2.5 h-2.5"}):e.jsx(fa,{className:"w-2.5 h-2.5"}),t.role==="user"?"Client Request":"EMLO.AI Intelligence",da&&Mt[a]&&Mt[a].originalLang!=="en"&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-600 dar
133k:text-amber-400 text-[8px] font-black uppercase tracking-wider",children:Mt[a].originalLang})]}),e.jsx("div",{className:"text-[13px] leading-relaxed",children:e.jsx(pn,{components:{p:({children:n})=>e.jsx("p",{className:"mb-2 last:mb-0",children:n}),strong:({children:n})=>e.jsx("strong",{className:"font-bold",children:n}),ul:({children:n})=>e.jsx("ul",{className:"list-disc pl-4 space-y-1 my-2",children:n}),ol:({children:n})=>e.jsx("ol",{className:"list-decimal pl-4 space-y-1 my-2",children:n}),li:({children:n})=>e.jsx("li",{className:"text-[13px]",children:n}),a:({href:n,children:h})=>e.jsx("a",{href:n,className:"underline opacity-70 hover:opacity-100",target:"_blank",rel:"noopener noreferrer",children:h}),code({node:n,inline:h,children:k,...L}){return h?e.jsx("code",{className:"bg-black/10 dark:bg-white/10 px-1 rounded text-[11px] font-mono",...L,children:k}):e.jsx("pre",{className:"bg-gray-900 text-green-400 text-[11px] font-mono p-3 rounded-xl overflow-x-auto my-2 whitespace-pre-wrap break-words",children:e.jsx("code",{...L,children:k})})}},children:da&&Mt[a]?Mt[a].translated:t.content})}),da&&Mt[a]&&Mt[a].originalLang!=="en"&&e.jsxs("div",{className:`mt-3 pt-3 border-t ${t.role==="user"?"border-white/10":"border-black/5 dark:border-white/5"}`,children:[e.jsxs("div",{className:`text-[9px] uppercase font-bold tracking-wider mb-1.5 opacity-50 ${t.role==="user"?"text-white":"text-black dark:text-white"}`,children:["Original (",Mt[a].originalLang.toUpperCase(),")"]}),e.jsx("div",{className:`text-[11px] leading-relaxed italic opacity-40 ${t.role==="user"?"text-white":"text-black dark:text-white"}`,dir:["he","ar","fa"].includes(Mt[a].originalLang)?"rtl":"ltr",children:t.content})]})]}),e.jsx("div",{className:"mt-1.5 text-[9px] font-mono opacity-30 px-2 tracking-tighter",children:new Date(t.createdAt).toLocaleString()})]},a)})]})]})}),e.jsxs("div",{className:"p-6 border-t border-black/10 dark:border-white/10 bg-gray-50 dark:bg-white/5 flex items-center justify-between",children:[da&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] font-bold text-emerald-600 dark:text-emerald-400",children:[e.jsx(vr,{className:"w-3.5 h-3.5"}),"Auto-translated to English via AI"]}),e.jsx("button",{onClick:()=>{hs(null),ps(!1),Mr({})},className:"ml-auto px-8 py-3 rounded-full bg-black dark:bg-white text-white dark:text-black font-black uppercase text-[11px] tracking-widest hover:scale-105 transition shadow-lg",children:"Close Archive"})]})]})]})})]})},"chat")]}),o==="analytics"&&(()=>{var h,k,L,X,pe,ue,ee,ve,it,Ia,fr,kr,Ss,ua;const t=(c,v=!1)=>{jn(c),Js(!0),fetch(`${m}/api/analytics/summary?scope=marketing&days=${c}`,{headers:{"X-Admin-Token":H}}).then(oe=>oe.json()).then(oe=>Ws(oe)).catch(console.error).finally(()=>Js(!1))},a=(c=!1)=>{Ll(!0),fetch(`${m}/api/analytics/ai-insight?scope=marketing&days=${Sa}${c?"&refresh=1":""}`,{headers:{"X-Admin-Token":H}}).then(v=>v.json()).then(v=>Sn(v)).catch(console.error).finally(()=>Ll(!1))},s=(c=Sa)=>{El(!0),fetch(`${m}/api/admin/truthmeter/stats?days=${c}`,{headers:{"X-Admin-Token":H}}).then(v=>v.json()).then(v=>yn(v)).catch(console.error).finally(()=>El(!1))},n=[{id:"overview",label:"Overview"},{id:"activity",label:"ð 48h Activity"},{id:"bigbrother",label:"TruthMeter"},{id:"tours",label:"ð§ Guided Tours"},{id:"acquisition",label:"Acquisition"},{id:"behaviour",label:"Behaviour"},{id:"conversions",label:"Conversions"},{id:"realtime",label:"ð´ Realtime"},{id:"ai",label:"⨠AI Insights"},{id:"costs",label:"ð° AI Costs"}];return e.jsxs(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl md:text-2xl font-black flex items-center gap-2",children:[e.jsx(cl,{className:"w-6 h-6 text-violet-500"})," Site Analytics"]}),e.jsx("p",{className:"text-xs md:text-sm text-black/40 dark:text-white/40 mt-1",children:"Self-hosted visitor intelligence - geo-enriched, GDPR-clean."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[[7,30,90].map(c=>e.jsxs("button",{onClick:()=>t(c),className:`px-3 md:px-4 py-1.5 rounded-full text-xs font-bold transition ${Sa===c?"bg-vi
133olet-600 text-white":"bg-black/5 dark:bg-white/5 text-black/50 dark:text-white/50 hover:bg-black/10 dark:hover:bg-white/10"}`,children:[c,"d"]},c)),e.jsx("button",{onClick:()=>t(Sa,!0),className:"p-2 rounded-full bg-black/5 dark:bg-white/5 hover:bg-violet-500/10 text-black/50 dark:text-white/50 hover:text-violet-500 transition",title:"Refresh",children:e.jsx(tt,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex gap-1 p-1 bg-black/5 dark:bg-white/5 rounded-xl overflow-x-auto",children:n.map(c=>e.jsx("button",{onClick:()=>{vn(c.id),c.id==="ai"&&!ca&&a(),c.id==="bigbrother"&&s(),c.id==="tours"&&!_l&&fetch(`${m}/api/analytics/tour-summary?days=${Sa}`,{headers:{"X-Admin-Token":H}}).then(v=>v.json()).then(v=>Cn(v)).catch(console.error)},className:`px-4 py-2 rounded-lg text-xs font-bold whitespace-nowrap transition flex-shrink-0 ${jt===c.id?"bg-white dark:bg-white/10 text-black dark:text-white shadow-sm":"text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white"}`,children:c.label},c.id))}),Nn?e.jsxs("div",{className:"flex flex-col items-center justify-center py-24 text-black/30 dark:text-white/30 gap-4",children:[e.jsx(V,{className:"w-8 h-8 animate-spin"}),e.jsx("p",{className:"text-sm font-medium",children:"Loading analytics..."})]}):!ce&&!["ai","activity","tours","bigbrother"].includes(jt)?e.jsxs("div",{className:"text-center py-16 text-black/30 dark:text-white/30",children:[e.jsx(cl,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{className:"font-bold",children:"No data yet."}),e.jsx("p",{className:"text-sm mt-1",children:"Data will appear as visitors browse the site."})]}):e.jsxs(yt,{mode:"wait",children:[jt==="bigbrother"&&(()=>{var Se,W,N;const c=$l||{},v=c.totals||{},oe=c.daily||[],se=Math.max(...oe.map(y=>Number(y.tests||0)),1),te=c.oz1Distribution||[],me=Number(v.total_tests||0);return e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"font-black text-lg flex items-center gap-2",children:[e.jsx(Lt,{className:"w-5 h-5 text-red-500"})," TruthMeter Usage"]}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40 mt-1",children:"OZ1 results, test volume, token usage, and geo source."})]}),e.jsxs("button",{onClick:()=>s(),className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-red-600 hover:bg-red-700 text-white text-xs font-black uppercase tracking-widest",children:[e.jsx(tt,{className:`w-4 h-4 ${Il?"animate-spin":""}`})," Refresh"]})]}),Il&&!$l?e.jsx("div",{className:"py-20 flex justify-center text-black/30 dark:text-white/30",children:e.jsx(V,{className:"w-8 h-8 animate-spin"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Total Tests",value:me,color:"text-red-600 dark:text-red-400"},{label:"Successful",value:Number(v.successful_tests||0),color:"text-emerald-600 dark:text-emerald-400"},{label:"Highest OZ1",value:v.max_oz1??"-",color:"text-orange-600 dark:text-orange-400"},{label:"High Risk",value:Number(v.high_count||0),color:"text-rose-600 dar
133k:text-rose-400"}].map(y=>e.jsxs("div",{className:"p-5 rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("p",{className:"text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40",children:y.label}),e.jsx("p",{className:`text-3xl font-black mt-1 ${y.color}`,children:y.value})]},y.label))}),e.jsxs("div",{className:"grid lg:grid-cols-[1.2fr_0.8fr] gap-6",children:[e.jsxs("div",{className:"p-6 rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("h5",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-5",children:"Daily Tests"}),e.jsx("div",{className:"h-44 flex items-end gap-2",children:oe.length?oe.map(y=>e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-2",title:`${String(y.date).slice(0,10)}: ${y.tests} tests`,children:[e.jsx("div",{className:"w-full rounded-t-lg bg-gradient-to-t from-red-600 to-emerald-400 min-h-1",style:{height:`${Math.max(Number(y.tests||0)/se*100,3)}%`}}),e.jsx("span",{className:"text-[9px] font-mono text-black/35 dark:text-white/35 rotate-[-35deg] origin-top-left whitespace-nowrap",children:new Date(y.date).toLocaleDateString([],{month:"numeric",day:"numeric"})})]},String(y.date))):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-xs text-black/30 dark:text-white/30",children:"No TruthMeter tests yet."})})]}),e.jsxs("div",{className:"p-6 rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("h5",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-5",children:"OZ1 Distribution"}),e.jsx("div",{className:"space-y-3",children:[0,1,2,3,4].map(y=>{const Le=te.find(zo=>Number(zo.score)===y),Re=Number((Le==null?void 0:Le.count)||0),Et=me?Re/me*100:0,Bo=y<=1?"bg-emerald-500":y===2?"bg-orange-500":"bg-red-500";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs font-bold mb-1",children:[e.jsxs("span",{children:["OZ1 ",y]}),e.jsx("span",{children:Re})]}),e.jsx("div",{className:"h-2 rounded-full bg-black/10 dark:bg-white/10 overflow-hidden",children:e.jsx("div",{className:`h-full ${Bo}`,style:{width:`${Et}%`}})})]},y)})})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"p-6 rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("h5",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Where From"}),e.jsxs("div",{className:"space-y-2",children:[(c.geo||[]).slice(0,10).map(y=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"font-bold truncate",children:[y.country,y.city?`, ${y.city}`:""]}),e.jsx("span",{className:"font-mono text-black/50 dark:text-white/50",children:y.tests})]},`${y.country}-${y.city}`)),!((Se=c.geo)!=null&&Se.length)&&e.jsx("p",{className:"text-xs text-black/30 dark:text-white/30",children:"No geo data yet."})]})]}),e.jsxs("div",{className:"p-6 rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5",children:[e.jsx("h5",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Tokens"}),e.jsxs("div",{className:"space-y-2",children:[(c.tokens||[]).slice(0,10).map(y=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-bold truncate",children:y.tokenLabel}),e.jsxs("span",{className:"font-mono text-black/50 dark:text-white/50",children:[y.tests," tests"]})]},y.tokenLabel)),!((W=c.tokens)!=null&&W.length)&&e.jsx("p",{className:"text-xs text-black/30 dark:text-white/30",children:"No token usage yet."})]})]})]}),e.jsxs("div",{className:"rounded-2xl bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-black/5 dark:border-white/5",children:e.jsx("h5",{className:"font-black text-sm",children:"Recent TruthMeter Tests"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b border-black/5 dark:border-white/5",children:["Time","Status","OZ1","Risk","Token","Geo","Error"].map(y=>e.jsx("th",{className:"text-left py-3 px-4 text-[10px] uppercase font-black tracking-widest text-black/30 dark:text-white/30",children:y},y))})}),e.jsxs("tbody",{children:[(c.recent||[]).map(y=>e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5",children:[e.jsx("td",{className:"py-3 px-4 font-mono",children:new Date(y.createdAt).toLocaleStr
133ing()}),e.jsx("td",{className:"py-3 px-4 font-bold",children:y.status}),e.jsx("td",{className:"py-3 px-4 font-black",children:y.oz1Max??"-"}),e.jsx("td",{className:"py-3 px-4",children:y.risk||"-"}),e.jsx("td",{className:"py-3 px-4",children:y.tokenLabel||"-"}),e.jsxs("td",{className:"py-3 px-4",children:[y.country||"-",y.city?`, ${y.city}`:""]}),e.jsx("td",{className:"py-3 px-4 text-red-500 max-w-xs truncate",children:y.error||"-"})]},y.id)),!((N=c.recent)!=null&&N.length)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"py-10 text-center text-black/30 dark:text-white/30",children:"No tests logged yet."})})]})]})})]})]})]},"bigbrother")})(),jt==="activity"&&e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between mb-8 gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs md:text-sm font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-1",children:"System Throughput (48 Hours)"}),e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30",children:"Hourly engagement across all core modules"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[9px] md:text-[10px] font-black uppercase tracking-tighter",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-blue-500"})," Visitors"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-emerald-500"})," Labs"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-orange-500"})," Files"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-rose-500"})," Chats"]})]})]}),Ln?e.jsx("div",{className:"h-48 flex items-center justify-center",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-black/20"})}):ut.length===0?e.jsx("div",{className:"h-48 flex items-center justify-center text-black/30 text-xs italic border border-dashed border-black/10 rounded-xl",children:"Insufficient data points to render graph"}):e.jsxs("div",{className:"relative h-56 w-full group overflow-visible flex",children:[e.jsx("div",{className:"w-8 flex flex-col justify-between text-[8px] font-mono text-black/30 dark:text-white/30 h-full pb-6 relative z-10 shrink-0",children:(()=>{const c=Math.max(...ut.map(v=>Math.max(Number(v.visitors),Number(v.lab_sessions),Number(v.files),Number(v.chats))),10);return[1,.75,.5,.25,0].map(v=>e.jsx("span",{className:"h-0 flex items-center",children:Math.round(c*v)},v))})()}),e.jsx("div",{className:"flex-1 relative h-48",children:e.jsxs("svg",{className:"w-full h-full overflow-visible",viewBox:"0 0 100 100",preserveAspectRatio:"none",children:[[0,25,50,75,100].map(c=>e.jsx("line",{x1:"0",y1:100-c,x2:"100",y2:100-c,stroke:"currentColor",className:"text-black/5 dark:text-white/5",strokeWidth:"0.3"},c)),(()=>{const c=Math.max(...ut.map(te=>Math.max(Number(te.visitors),Number(te.lab_sessions),Number(te.files),Number(te.chats))),10),v=te=>100-te/c*100,oe=te=>te/(ut.length-1)*100,se=(te,me)=>{const Se=ut.map((W,N)=>`${oe(N)},${v(Number(W[te]))}`).join(" ");return e.jsx("polyline",{points:Se,fill:"none",stroke:me,strokeWidth:"2",vectorEffect:"non-scaling-stroke",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-all duration-700",style:{filter:`drop-shadow(0 4px 6px ${me}33)`}})};return e.jsxs(e.Fragment,{children:[se("visitors","#3b82f6"),se("lab_sessions","#10b981"),se("files","#f59e0b"),se("chats","#f43f5e"),ut.map((te,me)=>{const Se=100/Math.max(1,ut.length-1),N=`${te.hour?`Time: ${te.hour}`:`${ut.length-me} hours ago`} 134Users: ${te.visitors} 135Labs: ${te.lab_sessions} 136Files: ${te.files} 137Chats: ${te.chats}`;return e.jsx("rect",{x:oe(me)-Se/2,y:"0",width:Se,height:"100",className:"fill-transparent hover:fill-black/5 dark:hover:fill-white/5 transition-colors cursor-crosshair",children:e.jsx("title",{children:N})},`hover-${me}`)})]})})()]})})]}),e.jsxs("div",{className:"mt-4 flex justify-between text-[8px] font-black text-black/20 dark:text-white/20 uppercase tracking-widest",children:[e.jsx("span",{children:"-48h"}),e.jsx("span",{children:"-24h"}),e.jsx("span",{children:"Pulse: Online"})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Avg Users/Hr",val:(ut.reduce((c,v)=>c+Number(v.visitors),0)/(ut.length||1)).toFixed(1),icon:Er,color:"text-blue-500"},{label:"Avg Labs/Hr",val:(ut.reduce((c,v)=>c+Number(v.lab_sessions),0)/(ut.length||1)).toFixed(1),icon:Ut,color:"text-emerald-500"},{label:"Uptime",val:"99.9%",icon:qe,color:"text-indigo-500"},{label:"Total Events",val:ut.reduce((c,v)=>c+Number(v.lab_sessions)+Number(v.files)+Number(v.chats),0),icon:ga,color:"text-orange-500"}].map((c,v)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 p-4 rounded-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(c.icon,{className:`w-3.5 h-3.5 ${c.color}`}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-black/40 dark:text-white/40",children:c.label})]}),e.jsx("div",{className:"text-xl font-black text-black dark:text-white",children:c.val})]},v))}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6 mt-8",children:[e.jsx("h4",{className:"text-sm font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Last 50 Visitor Journeys"}),Ys&&e.jsxs("div",{className:"mb-6 p-5 bg-violet-500/10 border border-violet-500/20 rounded-xl space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ye,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-widest text-violet-600 dar
137k:text-violet-400",children:"AI Journey Insights"})]}),e.jsx("p",{className:"text-sm font-medium leading-relaxed text-black dark:text-white",children:Ys.summary}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4 mt-3 pt-3 border-t border-violet-500/10",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-emerald-600 dark:text-emerald-400",children:"Positive Patterns"}),e.jsx("ul",{className:"mt-1 space-y-1",children:(h=Ys.positivePatterns)==null?void 0:h.map((c,v)=>e.jsxs("li",{className:"text-xs text-black/60 dark:text-white/60 flex items-start gap-1",children:[e.jsx("span",{className:"text-emerald-500 mt-0.5",children:"â¢"})," ",c]},v))})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-orange-600 dark:text-orange-400",children:"Friction Points"}),e.jsx("ul",{className:"mt-1 space-y-1",children:(k=Ys.frictionPoints)==null?void 0:k.map((c,v)=>e.jsxs("li",{className:"text-xs text-black/60 dark:text-white/60 flex items-start gap-1",children:[e.jsx("span",{className:"text-orange-500 mt-0.5",children:"â¢"})," ",c]},v))})]})]})]}),e.jsx("div",{className:"space-y-2 mt-6",children:(()=>{const c=se=>se.totalTime===0&&se.totalEvents===0&&se.timeline.length<=1,v=Ul.filter(se=>!c(se)),oe=Ul.filter(se=>c(se));return e.jsxs(e.Fragment,{children:[oe.length>0&&e.jsxs("div",{className:"text-[10px] text-black/40 dark:text-white/40 mb-3 px-1 font-medium",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-orange-500/50 mr-1.5 align-middle"}),"Filtered out ",oe.length," suspected bot/crawler pings (0s duration, single hit)."]}),v.map((se,te)=>{const me=se.referrer==="direct"?"Direct":se.referrer.replace("https://","").replace("http://","").replace("www.","").split("/")[0],Se=`${se.country}${se.city?` / ${se.city}`:""}`,W=se.timeline&&se.timeline.length>0?new Date(se.timeline[0].time).toLocaleString():"";return e.jsxs("div",{className:"text-[11px] font-mono p-2.5 rounded bg-black/5 dark:bg-white/5 leading-relaxed text-black/70 dark:text-white/70 mt-2",children:[W&&e.jsxs("span",{className:"text-black/50 dark:text-white/50 mr-2",children:["[",W,"]"]}),e.jsxs("span",{className:"font-bold text-black dark:text-white",children:["[",Se,"]"]}),e.jsx("span",{className:"mx-1.5",children:"-"}),e.jsx("span",{className:"text-orange-600 dark:text-orange-400 font-bold capitalize",children:me}),se.timeline.reduce((y,Le)=>{const Re=y[y.length-1];return Re&&Re.type===Le.type&&(Le.type==="pageview"&&Le.path===Re.path||Le.type==="event"&&Le.event===Re.event)?(Re.count=(Re.count||1)+1,Le.duration&&(Re.duration=(Re.duration||0)+Le.duration)):y.push({...Le,count:1}),y},[]).map((y,Le)=>e.jsxs("span",{children:[e.jsx("span",{className:"text-black/30 dark:text-white/30 mx-1.5",children:"â"}),y.type==="pageview"?e.jsxs("span",{children:[y.path==="/"?"Home page":y.path.replace(/^\//,""),y.count>1&&e.jsxs("span",{className:"text-black/40 dark:text-white/40 ml-1 text-[9px]",children:["x",y.count]}),y.duration>0&&e.jsxs("span",{className:"text-black/40 dark:text-white/40 ml-1",children:["(",y.duration<60?`${y.duration} sec.`:`${Math.floor(y.duration/60)}:${(y.duration%60).toString().padStart(2,"0")}`,")"]})]}):e.jsxs("span",{className:"text-blue-600 dark:text-blue-400 font-bold",children:[y.event,y.count>1&&e.jsxs("span",{className:"text-blue-400/50 dark:text-blue-400/50 ml-1 text-[9px]",children:["x",y.count]})]})]},Le))]},te)}),v.length===0&&e.jsx("div",{className:"py-6 text-center text-xs text-black/30 italic",children:"No recent human journeys found."})]})})()})]})]},"act"),jt==="overview"&&ce&&e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[{label:"Page Views",value:(ce.totalViews||0).toLocaleString(),icon:Lr,color:"text-violet-500",bg:"bg-violet-500/10"},{label:"Unique Visitors",value:(ce.uniqueVisitors||0).toLocaleString(),icon:Ot,color:"text-blue-500",bg:"bg-blue-500/10"},{label:"Avg. Duration",value:ce.avgDuration?`${Math.floor(ce.avgDuration/60)}m ${ce.avgDuration%60}s`:"-",icon:zi,color:"text-emerald-500",bg:"bg-emerald-500/10"},{label:"Bounce Rate",value:`${ce.bounceRate||0}%`,icon:Ut,color:"text-orange-500",bg:"bg-orange-500/10"}
137,{label:"Total Events",value:(ce.totalEvents||0).toLocaleString(),icon:Dt,color:"text-pink-500",bg:"bg-pink-500/10"},{label:"Top Country",value:((X=(L=ce.countries)==null?void 0:L[0])==null?void 0:X.country)||"-",icon:St,color:"text-cyan-500",bg:"bg-cyan-500/10"}].map((c,v)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-5",children:[e.jsx("div",{className:`w-8 h-8 ${c.bg} rounded-lg flex items-center justify-center mb-3`,children:e.jsx(c.icon,{className:`w-4 h-4 ${c.color}`})}),e.jsx("div",{className:"text-2xl font-black text-black dark:text-white",children:c.value}),e.jsx("div",{className:"text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mt-1",children:c.label})]},v))}),((pe=ce.daily)==null?void 0:pe.length)>0&&e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-4 md:p-6",children:[e.jsxs("h4",{className:"text-xs md:text-sm font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:["Daily Trend (",Sa,"d)"]}),e.jsx("div",{className:"overflow-x-auto pb-4 scrollbar-hide",children:e.jsx("div",{className:"flex items-end gap-1 h-32 md:h-28 relative min-w-[300px]",children:(()=>{const c=Math.max(...ce.daily.map(oe=>oe.views),1),v=Math.max(...ce.daily.map(oe=>oe.visitors),1);return ce.daily.map((oe,se)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-0.5 group relative",title:`${oe.date}: ${oe.views} views, ${oe.visitors} visitors`,children:[e.jsx("div",{className:"w-full bg-violet-500/80 hover:bg-violet-400 rounded-t-sm transition",style:{height:`${Math.max(3,oe.views/c*96)}px`}}),e.jsx("div",{className:"w-full bg-blue-400/50 rounded-t-sm",style:{height:`${Math.max(2,oe.visitors/v*20)}px`}}),e.jsxs("div",{className:"absolute -top-7 left-1/2 -translate-x-1/2 bg-black text-white text-[10px] px-1.5 py-0.5 rounded opacity-0 group-hover:opacity-100 transition whitespace-nowrap pointer-events-none z-10",children:[oe.views,"v / ",oe.visitors,"u"]})]},se))})()})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 mt-3 font-medium",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] md:text-xs text-black/40 dark:text-white/40",children:[e.jsx("span",{className:"w-3 h-2 bg-violet-500/80 rounded-sm inline-block"})," Page Views"]}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] md:text-xs text-black/40 dark:text-white/40",children:[e.jsx("span",{className:"w-3 h-2 bg-blue-400/50 rounded-sm inline-block"})," Unique Visitors"]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Visitor World Map"}),e.jsx(td,{countries:ce.countries||[]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Devices & Languages"}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsx("div",{className:"space-y-2",children:(ce.devices||[]).map((c,v)=>{var me,Se;const se={Mobile:Is,Tablet:$r,Desktop:Ot}[c.device]||Ot,te=((Se=(me=ce.devices)==null?void 0:me[0])==null?void 0:Se.count)||1;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(se,{className:"w-3.5 h-3.5 text-black/30 dark:text-white/30 shrink-0"}),e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"mt-1 h-1.5 rounded-full bg-black/5 dark:bg-white/5",children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full",style:{width:`${c.count/te*100}%`}})})}),e.jsx("span",{className:"text-xs font-bold text-black dark:text-white",children:c.device}),e.jsx("span",{className:"text-xs text-black/40 dark:text-white/40",children:c.count})]},v)})}),e.jsx("div",{className:"flex flex-wrap gap-2 content-start",children:(ce.languages||[]).map((c,v)=>e.jsxs("span",{className:"px-2 py-1 rounded-full bg-black/5 dark:bg-white/5 text-xs font-bold",children:[c.lang," ",e.jsx("span",{className:"text-black/40 dark:text-white/40",children:c.count})]},v))})]})]})]},"ov"),jt==="acquisition"&&ce&&e.jsx(ie.div,{initial:{opacity:0,y:6}
137,animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:e.jsxs("div",{className:"grid md:grid-cols-2 xl:grid-cols-3 gap-6",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Traffic Sources"}),e.jsxs("div",{className:"space-y-2",children:[(ce.topReferrers||[]).map((c,v)=>{var me,Se;const oe=((Se=(me=ce.topReferrers)==null?void 0:me[0])==null?void 0:Se.count)||1,se=!c.referrer||c.referrer==="direct"?"Direct / None":c.referrer.replace("https://","").replace("http://","").replace("www.","").split("/")[0],te=["bg-blue-500","bg-pink-500","bg-emerald-500","bg-orange-500","bg-violet-500","bg-cyan-500","bg-yellow-500","bg-red-500"];return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(St,{className:"w-3 h-3 text-black/20 dark:text-white/20 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-bold text-black dark:text-white truncate",children:se}),e.jsx("div",{className:"mt-1 h-1.5 rounded-full bg-black/5 dark:bg-white/5",children:e.jsx("div",{className:`h-full ${te[v%te.length]} rounded-full`,style:{width:`${c.count/oe*100}%`}})})]}),e.jsx("span",{className:"text-xs font-bold text-black/50 dark:text-white/50",children:c.count})]},v)}),!((ue=ce.topReferrers)!=null&&ue.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No referrer data yet."})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"UTM Campaigns"}),(ee=ce.utmCampaigns)!=null&&ee.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-black/30 dark:text-white/30 text-left",children:[e.jsx("th",{className:"pb-2 font-bold",children:"Source"}),e.jsx("th",{className:"pb-2 font-bold",children:"Campaign"}),e.jsx("th",{className:"pb-2 font-bold text-right",children:"Visitors"})]})}),e.jsx("tbody",{className:"space-y-1",children:ce.utmCampaigns.map((c,v)=>e.jsxs("tr",{className:"border-t border-black/5 dark:border-white/5",children:[e.jsxs("td",{className:"py-1.5 font-bold text-black dark:text-white",children:[c.utmSource,"/",c.utmMedium]}),e.jsx("td",{className:"py-1.5 text-black/60 dark:text-white/60 truncate max-w-[120px]",children:c.utmCampaign||"-"}),e.jsx("td",{className:"py-1.5 text-right font-bold",children:c.visitors})]},v))})]})}):e.jsx("p",{className:"text-xs text-black/30 italic",children:"No UTM data yet. Add utm_source/utm_campaign to your links."})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Visitor Search Terms"}),(ve=ce.searchTerms)!=null&&ve.length?e.jsx("div",{className:"space-y-2",children:ce.searchTerms.map((c,v)=>{var te,me;const oe=((me=(te=ce.searchTerms)==null?void 0:te[0])==null?void 0:me.visitors)||1,se=["bg-emerald-500","bg-blue-500","bg-pink-500","bg-orange-500","bg-violet-500","bg-cyan-500"];return e.jsxs("div",{className:"rounded-xl bg-white dark:bg-black/20 border border-black/5 dark:border-white/5 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-2",children:[e.jsx("span",{className:"text-xs font-black text-black dark:text-white truncate",children:c.utmTerm}),e.jsxs("span",{className:"text-[10px] font-bold text-black/40 dark:text-white/40 shrink-0",children:[c.visitors," visitors"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-black/5 dark:bg-white/5",children:e.jsx("div",{className:`h-full ${se[v%se.length]} rounded-full`,style:{width:`${c.visitors/oe*100}%`}})}
137),e.jsxs("p",{className:"mt-1.5 text-[10px] text-black/35 dark:text-white/35",children:[c.pageviews," pageviews"]})]},v)})}):e.jsx("p",{className:"text-xs text-black/30 italic",children:"No search terms yet. Add utm_term or keyword to campaign links."})]})]})},"acq"),jt==="behaviour"&&ce&&e.jsx(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Top Pages - Engagement"}),e.jsx("div",{className:"space-y-3",children:(ce.topPages||[]).slice(0,10).map((c,v)=>{var te,me;const oe=((me=(te=ce.topPages)==null?void 0:te[0])==null?void 0:me.views)||1,se=c.avgDuration?`${Math.floor(c.avgDuration/60)}m${c.avgDuration%60}s`:"-";return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs font-mono text-black/30 dark:text-white/30 w-4",children:v+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-bold text-black dark:text-white truncate",children:c.path}),e.jsx("span",{className:"text-[10px] text-black/40 dark:text-white/40 ml-2 shrink-0",children:se})]}),e.jsx("div",{className:"mt-1 h-1.5 rounded-full bg-black/5 dark:bg-white/5",children:e.jsx("div",{className:"h-full bg-violet-500 rounded-full",style:{width:`${c.views/oe*100}%`}})})]}),e.jsx("span",{className:"text-xs font-bold text-black/50 dark:text-white/50 shrink-0",children:c.views})]},v)})})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Scroll Depth"}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40 mb-4",children:"Sessions that scrolled to each depth milestone."}),[25,50,75,90].map(c=>{var se,te;const v=((se=ce.scrollDepth)==null?void 0:se[`scroll_${c}`])||0,oe=((te=ce.scrollDepth)==null?void 0:te.scroll_25)||ce.uniqueVisitors||1;return e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("span",{className:"text-xs font-black text-black/40 dark:text-white/40 w-8",children:[c,"%"]}),e.jsx("div",{className:"flex-1 h-2 rounded-full bg-black/5 dark:bg-white/5",children:e.jsx("div",{className:`h-full rounded-full ${c===25?"bg-emerald-400":c===50?"bg-blue-400":c===75?"bg-violet-400":"bg-pink-400"}`,style:{width:`${Math.min(100,v/oe*100)}%`}})}),e.jsx("span",{className:"text-xs font-bold w-8 text-right",children:v})]},c)}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-black/5 dark:border-white/5",children:[e.jsx("h5",{className:"text-xs font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-3",children:"Top Custom Events"}),e.jsxs("div",{className:"space-y-1",children:[(ce.topEvents||[]).filter(c=>!c.event.startsWith("scroll")).slice(0,8).map((c,v)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-mono text-black dark:text-white",children:c.event}),e.jsx("span",{className:"text-xs font-bold text-black/50 dark:text-white/50",children:c.count})]},v)),!((it=ce.topEvents)!=null&&it.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No events yet."})]})]})]})]})},"beh"),jt==="conversions"&&ce&&e.jsx(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-6",children:"Demo Request Funnel"}),e.jsx("div",{className:"space-y-3",children:(ce.conversionFunnel||[]).map((c,v)=>{var me,Se,W;const oe=((Se=(me=ce.conversionFunnel)==null?void 0:me[0])==null?void 0:Se.sessions)||1,se=v>0?(c.sessions/(((W=ce.conversionFunnel[v-1])==null?void 0:W.sessions)||1)*100).toFixed(1):"100",te=["bg-blue-500","bg-indigo-500","bg-vi
137olet-500","bg-emerald-500"];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-bold text-black dark:text-white",children:c.stage}),e.jsxs("div",{className:"flex items-center gap-2",children:[v>0&&e.jsxs("span",{className:"text-[10px] text-black/30 dark:text-white/30",children:["â³ ",se,"%"]}),e.jsx("span",{className:"text-xs font-black",children:c.sessions.toLocaleString()})]})]}),e.jsx("div",{className:"h-2 rounded-full bg-black/5 dark:bg-white/10",children:e.jsx("div",{className:`h-full rounded-full ${te[v]}`,style:{width:`${Math.max(1,c.sessions/oe*100)}%`}})})]},v)})})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-6",children:"Voice & AI Demo Funnel"}),e.jsx("div",{className:"space-y-3",children:(ce.voiceFunnel||[]).map((c,v)=>{var te,me;const oe=((me=(te=ce.voiceFunnel)==null?void 0:te[0])==null?void 0:me.sessions)||1,se=["bg-pink-500","bg-rose-500","bg-orange-500"];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-bold text-black dark:text-white",children:c.stage}),e.jsx("span",{className:"text-xs font-black",children:c.sessions.toLocaleString()})]}),e.jsx("div",{className:"h-2 rounded-full bg-black/5 dark:bg-white/10",children:e.jsx("div",{className:`h-full rounded-full ${se[v]}`,style:{width:`${Math.max(1,c.sessions/oe*100)}%`}})})]},v)})}),e.jsx("p",{className:"text-[10px] text-black/30 dark:text-white/30 mt-4",children:"Voice demo events tracked from the audio uploader and quick-stress test."})]})]})},"conv"),jt==="realtime"&&ce&&e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"md:col-span-1 bg-gradient-to-br from-violet-600 to-blue-600 rounded-2xl p-6 text-white",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-green-400 animate-pulse"}),e.jsx("span",{className:"text-xs font-bold uppercase tracking-widest opacity-70",children:"Active Right Now"})]}),e.jsx("div",{className:"text-5xl font-black",children:((Ia=ce.realtime)==null?void 0:Ia.activeVisitors)||0}),e.jsx("div",{className:"text-sm opacity-70 mt-1",children:"visitors in last 5 min"}),e.jsxs("button",{onClick:()=>t(Sa),className:"mt-4 px-3 py-1.5 rounded-lg bg-white/20 text-xs font-bold hover:bg-white/30 transition flex items-center gap-1",children:[e.jsx(tt,{className:"w-3 h-3"})," Refresh"]})]}),e.jsxs("div",{className:"md:col-span-2 bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Active Pages"}),e.jsxs("div",{className:"space-y-2",children:[(((fr=ce.realtime)==null?void 0:fr.activePages)||[]).map((c,v)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400 shrink-0"}),e.jsx("span",{className:"text-xs font-bold text-black dark:text-white flex-1",children:c.path}),e.jsxs("span",{className:"text-xs text-black/40 dark:text-white/40",children:[c.active," active"]})]},v)),!((Ss=(kr=ce.realtime)==null?void 0:kr.activePages)!=null&&Ss.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No active sessions right now."})]})]})]}),e.jsxs("section",{className:"bg-gray-50 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-sm font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"Recent Event Stream"}),e.jsxs("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:[(ce.recentEvents||[]).map((c,v)=>e.jsxs("div",{className:"flex items-center gap-3 py-1.5 border-b border-black/5 dark:border-white/5",children:[e.jsx("span",{className:"text-[10px] font-mono text-black/30 dark:text-white/30 shrink-0",children:new Date(c.createdAt).toLocaleTimeString()}),e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-violet-500/10 text-violet-600 dar
137k:text-violet-400 text-[10px] font-bold shrink-0",children:c.event}),e.jsx("span",{className:"text-[10px] text-black/50 dark:text-white/40 truncate",children:c.path})]},v)),!((ua=ce.recentEvents)!=null&&ua.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No events logged yet."})]})]})]},"rt"),jt==="ai"&&e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-lg",children:"⨠AI Analytics Narrative"}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40 mt-1",children:"Powered by Emotion Logic AI - analyzes your data and writes actionable intelligence."})]}),e.jsx("button",{onClick:()=>a(!0),disabled:bs,className:"flex items-center gap-2 px-4 py-2 rounded-xl bg-violet-600 hover:bg-violet-700 text-white text-sm font-bold transition disabled:opacity-50",children:bs?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 animate-spin"})," Analysing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"w-4 h-4"})," Regenerate"]})})]}),bs&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 gap-4 text-black/30 dark:text-white/30",children:[e.jsx(V,{className:"w-10 h-10 animate-spin text-violet-500"}),e.jsx("p",{className:"text-sm",children:"Emotion Logic AI is reading your analytics..."})]}),(ca==null?void 0:ca.insight)&&!bs&&(()=>{var se,te,me,Se;const c=ca.insight,v=c.score>=80?"text-emerald-500":c.score>=60?"text-blue-500":c.score>=40?"text-orange-500":"text-red-500",oe=c.score>=80?"bg-emerald-500/10":c.score>=60?"bg-blue-500/10":c.score>=40?"bg-orange-500/10":"bg-red-500/10";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-6 rounded-2xl bg-gradient-to-br from-violet-600/10 to-blue-600/10 border border-violet-500/20",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("p",{className:"text-lg font-bold text-black dark:text-white leading-snug",children:c.headline}),e.jsxs("div",{className:`shrink-0 flex flex-col items-center px-4 py-2 rounded-xl ${oe}`,children:[e.jsx("span",{className:`text-3xl font-black ${v}`,children:c.score}),e.jsx("span",{className:`text-[10px] font-bold uppercase ${v}`,children:c.scoreLabel})]})]}),ca.cached&&e.jsxs("p",{className:"text-[10px] text-black/30 dark:text-white/30 mt-3",children:["Cached - ",new Date(ca.cachedAt).toLocaleString()]})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-5 rounded-xl bg-emerald-500/5 border border-emerald-500/20",children:[e.jsx("h5",{className:"text-xs font-bold uppercase tracking-widest text-emerald-600 dark:text-emerald-400 mb-3",children:"â
Highlights"}),e.jsx("ul",{className:"space-y-2",children:(se=c.highlights)==null?void 0:se.map((W,N)=>e.jsxs("li",{className:"text-xs text-black dark:text-white",children:["⢠",W]},N))})]}),((te=c.warnings)==null?void 0:te.length)>0&&e.jsxs("div",{className:"p-5 rounded-xl bg-orange-500/5 border border-orange-500/20",children:[e.jsx("h5",{className:"text-xs font-bold uppercase tracking-widest text-orange-600 dark:text-orange-400 mb-3",children:"â ï¸ Watch Out"}),e.jsx("ul",{className:"space-y-2",children:(me=c.warnings)==null?void 0:me.map((W,N)=>e.jsxs("li",{className:"text-xs text-black dark:text-white",children:["⢠",W]},N))})]})]}),e.jsxs("div",{className:"p-5 rounded-xl bg-blue-500/5 border border-blue-500/20",children:[e.jsx("h5",{className:"text-xs font-bold uppercase tracking-widest text-blue-600 dark:text-blue-400 mb-3",children:"ð¯ Recommended Actions"}),e.jsx("ol",{className:"space-y-2",children:(Se=c.recommendations)==null?void 0:Se.map((W,N)=>e.jsxs("li",{className:"text-xs text-black dark:text-white flex gap-2",children:[e.jsxs("span",{className:"font-black text-blue-500 shrink-0",children:[N+1,"."]})," ",W]},N))})]}),c.voice_ai_comment&&e.jsxs("div",{className:"p-5 rounded-xl bg-gradient-to-r from-pink-500/5 to-orange-500/5 border border-pink-500/20",children:[e.jsx("h5",{className:"text-xs font-bold uppercase tracking-widest text-pink-600 dark:text-pink-400 mb-2",children:"ðï¸ Vocal AI Insight"}),e.jsx("p",{className:"text-xs text-black dark:text-white",children:c.voice_ai_comment})]})]})})(),!ca&&!bs&&e.jsxs("div",{className:"text-center py-12 text-black/30 dark:text-white/30",children:[e.jsx(fa,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{className:"font-bold",children:'Click "Regenerate" to get your AI analytics narrative.'}),e.jsx("p",{className:"text-sm mt-1",children:"Requires Gemini API key to be configured."})]})]},"ai"),jt==="costs"&&(()=>{const c=xa.reduce((W,N)=>W+parseFloat(N.estimated_cost_usd||"0"),0),v=xa.reduce((W,N)=>W+(N.requests||0),0),oe=xa.reduce((W,N)=>W+(N.input_tokens||0),0),se=xa.reduce((W,N)=>W+(N.output_tokens||0),0);Math.max(...xa.map(W=>parseFloat(W.estimated_cost_usd||"0")),1e-6);const te={};for(let W=13;W>=0;W--){const N=new Date;N.setDate(N.getDate()-W);const y=N.toISOString().split("T")[0];
137te[y]={cost:0,input:0,output:0,requests:0}}xa.forEach(W=>{var y;const N=((y=W.date)==null?void 0:y.split("T")[0])||W.date;te[N]&&(te[N].cost+=parseFloat(W.estimated_cost_usd||"0"),te[N].input+=W.input_tokens||0,te[N].output+=W.output_tokens||0,te[N].requests+=W.requests||0)});const me=Object.entries(te),Se=Math.max(...me.map(([,W])=>W.cost),1e-6);return e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Est. Total Cost",value:`$${c.toFixed(4)}`,sub:"14-day window",color:"text-emerald-600 dark:text-emerald-400"},{label:"Total Requests",value:v.toLocaleString(),sub:"API calls",color:"text-blue-600 dark:text-blue-400"},{label:"Total Tokens",value:(oe+se).toLocaleString(),sub:`${oe.toLocaleString()} in / ${se.toLocaleString()} out`,color:"text-violet-600 dark:text-violet-400"},{label:"Cost / Request",value:v>0?`$${(c/v).toFixed(5)}`:"-",sub:"average",color:"text-pink-600 dark:text-pink-400"}].map(W=>e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-white/5 rounded-2xl border border-black/5 dark:border-white/5",children:[e.jsx("p",{className:"text-[10px] uppercase font-black tracking-widest text-black/40 dark:text-white/40 mb-1",children:W.label}),e.jsx("p",{className:`text-2xl font-black tracking-tighter ${W.color}`,children:W.value}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/40 mt-1",children:W.sub})]},W.label))}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 rounded-2xl border border-black/5 dark:border-white/5 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-sm tracking-tight",children:"Daily AI Spend"}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/40 mt-0.5",children:"Estimated USD cost · last 14 days"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-[10px] font-bold uppercase tracking-widest",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-blue-500 inline-block"}),"Input"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm bg-pink-500 inline-block"}),"Output"]})]})]}),e.jsx("div",{className:"flex items-end gap-1.5 h-36",children:me.map(([W,N])=>{const y=N.cost/Se,Le=N.input/Math.max(N.input+N.output,1)*y,Re=N.output/Math.max(N.input+N.output,1)*y,Et=new Date(W+"T12:00:00").toLocaleDateString([],{month:"numeric",day:"numeric"});return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group",title:`${W} 138Cost: $${N.cost.toFixed(5)} 139Requests: ${N.requests}`,children:[e.jsx("div",{className:"w-full flex flex-col justify-end",style:{height:"112px"},children:N.cost>0?e.jsxs("div",{className:"w-full rounded-t-sm overflow-hidden",style:{height:`${Math.max(y*100,2)}%`},children:[e.jsx("div",{className:"w-full bg-pink-500",style:{height:`${Re/y*100}%`}}),e.jsx("div",{className:"w-full bg-blue-500",style:{height:`${Le/y*100}%`}})]}):e.jsx("div",{className:"w-full h-0.5 bg-black/10 dark:bg-white/10 rounded-full"})}),e.jsx("span",{className:"text-[8px] text-black/30 dark:text-white/30 font-mono",children:Et})]},W)})}),e.jsxs("div",{className:"flex justify-between mt-2 text-[9px] font-mono text-black/30 dark:text-white/30",children:[e.jsx("span",{children:"$0"}),e.jsxs("span",{children:["$",(Se/2).toFixed(4)]}),e.jsxs("span",{children:["$",Se.toFixed(4)]})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 rounded-2xl border border-black/5 dark:border-white/5 overflow-hidden",children:[e.jsxs("div",{className:"p-4 border-b border-black/5 dark:border-white/5",children:[e.jsx("h4",{className:"font-black text-sm",children:"Usage Ledger"}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/40",children:"Pricing follows the configured Emotion Logic AI route."})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"border-b border-black/5 dark:border-white/5",children:e.jsx("tr",{children:["Date","Endpoint","Requests","Input Tokens","Output Tokens","Est. Cost USD"].map(W=>e.jsx("th",{className:"text-left py-3 px-4 text-[10px] uppercase font-black tracking-widest text-black/30 dark:text-white/30",children:W},W))})}),e.jsx("tbody",{children:xa.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"text-center py-10 text-black/30 dark:text-white/30",children:"No usage data yet - costs will appear after AI calls are made."})}):[...xa].reverse().map((W,N)=>{var y;return e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 hover:bg-black/[0.02] dark:hover:bg-white/[0.02]",children:[e.jsx("td",{className:"py-3 px-4 font-mono text-black/60 dark:text-white/60",children:((y=W.date)==null?void 0:y.split("T")[0])||W.date}
139),e.jsx("td",{className:"py-3 px-4 font-mono text-blue-600 dark:text-blue-400",children:W.endpoint}),e.jsx("td",{className:"py-3 px-4 font-black",children:W.requests}),e.jsx("td",{className:"py-3 px-4 text-blue-600 dark:text-blue-400",children:Number(W.input_tokens).toLocaleString()}),e.jsx("td",{className:"py-3 px-4 text-pink-600 dark:text-pink-400",children:Number(W.output_tokens).toLocaleString()}),e.jsxs("td",{className:"py-3 px-4 font-black text-emerald-700 dark:text-emerald-400",children:["$",parseFloat(W.estimated_cost_usd).toFixed(5)]})]},N)})})]})})]})]},"costs")})(),jt==="tours"&&(()=>{var oe,se,te,me,Se,W;const c=_l;if(!c)return e.jsxs(ie.div,{initial:{opacity:0},animate:{opacity:1},className:"flex flex-col items-center justify-center py-24 text-black/30 dark:text-white/30 gap-4",children:[e.jsx(V,{className:"w-8 h-8 animate-spin"}),e.jsx("p",{className:"text-sm font-medium",children:"Loading tour analytics..."})]},"tours-loading");const v=["bg-violet-500","bg-blue-500","bg-emerald-500","bg-orange-500","bg-pink-500","bg-cyan-500","bg-amber-500","bg-rose-500"];return e.jsxs(ie.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Tours Started",value:c.totalStarted,icon:xd,color:"text-violet-500",bg:"bg-violet-500/10"},{label:"Completed",value:c.totalCompleted,icon:Ce,color:"text-emerald-500",bg:"bg-emerald-500/10"},{label:"Abandoned",value:c.totalAbandoned,icon:$d,color:"text-orange-500",bg:"bg-orange-500/10"},{label:"Completion Rate",value:`${c.completionRate}%`,icon:Lr,color:"text-blue-500",bg:"bg-blue-500/10"}].map((N,y)=>e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-5",children:[e.jsx("div",{className:`inline-flex p-2 rounded-xl ${N.bg} mb-3`,children:e.jsx(N.icon,{className:`w-5 h-5 ${N.color}`})}),e.jsx("div",{className:"text-2xl font-black",children:typeof N.value=="number"?N.value.toLocaleString():N.value}),e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-widest text-black/40 dark:text-white/40 mt-1",children:N.label})]},y))}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð Interest by Field"}),e.jsxs("div",{className:"space-y-3",children:[(c.fieldBreakdown||[]).map((N,y)=>{var Re,Et;const Le=((Et=(Re=c.fieldBreakdown)==null?void 0:Re[0])==null?void 0:Et.tours)||1;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-bold truncate",children:N.field||"Unknown"}),e.jsx("span",{className:"text-black/40 dark:text-white/40 font-mono",children:N.tours})]}),e.jsx("div",{className:"h-2 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${v[y%v.length]} rounded-full transition-all`,style:{width:`${N.tours/Le*100}%`}})})]},y)}),!((oe=c.fieldBreakdown)!=null&&oe.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No tour data yet."})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð¢ Company Size"}),e.jsxs("div",{className:"space-y-3",children:[(c.sizeBreakdown||[]).map((N,y)=>{var Re,Et;const Le=((Et=(Re=c.sizeBreakdown)==null?void 0:Re[0])==null?void 0:Et.tours)||1;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-bold",children:N.companySize||"Unknown"}),e.jsx("span",{className:"text-black/40 dark:text-white/40 font-mono",children:N.tours})]}),e.jsx("div",{className:"h-2 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-blue-500 rounded-full transition-all",style:{width:`${N.tours/Le*100}%`}})})]},y)}),!((se=c.sizeBreakdown)!=null&&se.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No size data yet."})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð Geo Distribution"}),e.jsxs("div",{className:"space-y-2",children:[(c.geoBreakdown||[]).slice(0,10).map((N,y)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"font-medium truncate",children:[N.country,N.city?`, ${N.city}`:""]}),e.jsx("span",{className:"font-mono text-black/40 dark:text-white/40 ml-2",children:N.tours})]},y)),!((te=c.geoBreakdown)!=null&&te.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No geo data yet."})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð£ï¸ Language"}),e.jsxs("div",{className:"space-y-2",children:[(c.langBreakdown||[]).map((N,y)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"font-bold uppercase",children:N.lang}),e.jsx("span",{className:"font-mono text-black/40 dark:text-white/40",children:N.tours})]},y)),!((me=c.langBreakdown)!=null&&me.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No language data yet."})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð¥ Stop Heatmap"}),e.jsxs("div",{className:"space-y-2",children:[(c.stopHeatmap||[]).slice(0,8).map((N,y)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"font-medium truncate",title:N.stopTitle,children:N.stopPath}),e.jsx("span",{className:"font-mono text-black/40 dark:text-white/40 ml-2",children:N.visits})]}
139,y)),!((Se=c.stopHeatmap)!=null&&Se.length)&&e.jsx("p",{className:"text-xs text-black/30 italic",children:"No stop data yet."})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð Drop-off by Stop"}),(c.dropoffByStop||[]).length>0?e.jsx("div",{className:"flex items-end gap-2 h-24",children:(c.dropoffByStop||[]).map((N,y)=>{const Le=Math.max(...(c.dropoffByStop||[]).map(Re=>Re.abandonments),1);return e.jsxs("div",{className:"flex flex-col items-center flex-1",children:[e.jsx("div",{className:"w-full bg-orange-500/80 rounded-t-sm",style:{height:`${Math.max(N.abandonments/Le*80,4)}px`}}),e.jsxs("span",{className:"text-[9px] font-mono text-black/40 dark:text-white/40 mt-1",children:["#",N.stopIndex+1]}),e.jsx("span",{className:"text-[8px] font-mono text-black/30 dark:text-white/30",children:N.abandonments})]},y)})}):e.jsx("p",{className:"text-xs text-black/30 italic",children:"No drop-off data yet."})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl p-6",children:[e.jsx("h4",{className:"text-xs font-black uppercase tracking-widest text-black/40 dark:text-white/40 mb-4",children:"ð Daily Trend"}),(c.dailyTrend||[]).length>0?e.jsx("div",{className:"flex items-end gap-1 h-24",children:(c.dailyTrend||[]).slice(-14).map((N,y)=>{var Re;const Le=Math.max(...(c.dailyTrend||[]).map(Et=>Et.started),1);return e.jsxs("div",{className:"flex flex-col items-center flex-1",title:`${N.date}: ${N.started} started, ${N.completed} completed`,children:[e.jsxs("div",{className:"w-full flex flex-col gap-0.5",children:[e.jsx("div",{className:"w-full bg-violet-500/80 rounded-t-sm",style:{height:`${Math.max(N.started/Le*60,2)}px`}}),e.jsx("div",{className:"w-full bg-emerald-500/80 rounded-b-sm",style:{height:`${Math.max(N.completed/Le*60,1)}px`}})]}),e.jsx("span",{className:"text-[7px] font-mono text-black/30 dark:text-white/30 mt-1",children:(Re=N.date)==null?void 0:Re.slice(5)})]},y)})}):e.jsx("p",{className:"text-xs text-black/30 italic",children:"No trend data yet."}),e.jsxs("div",{className:"flex gap-4 mt-3",children:[e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-black/40 dark:text-white/40",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-violet-500"}
139),"Started"]}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-black/40 dark:text-white/40",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"}),"Completed"]})]})]})]}),e.jsxs("div",{className:"bg-gray-50 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-black/5 dark:border-white/5",children:e.jsx("h4",{className:"font-black text-sm",children:"Recent Tour Sessions"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"border-b border-black/5 dark:border-white/5",children:e.jsx("tr",{children:["Time","Status","Field","Company Size","Country","Language","Tour Title"].map(N=>e.jsx("th",{className:"text-left py-3 px-4 text-[10px] uppercase font-black tracking-widest text-black/30 dark:text-white/30",children:N},N))})}),e.jsxs("tbody",{children:[(c.recentSessions||[]).map((N,y)=>e.jsxs("tr",{className:"border-b border-black/5 dark:border-white/5 last:border-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02]",children:[e.jsx("td",{className:"py-2.5 px-4 font-mono text-black/50 dark:text-white/50",children:new Date(N.createdAt).toLocaleString()}),e.jsx("td",{className:"py-2.5 px-4",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold ${N.event==="tour_completed"?"bg-emerald-500/10 text-emerald-600":N.event==="tour_abandoned"?"bg-orange-500/10 text-orange-600":"bg-violet-500/10 text-violet-600"}`,children:N.event.replace("tour_","")})}),e.jsx("td",{className:"py-2.5 px-4 font-medium",children:N.field||"-"}),e.jsx("td",{className:"py-2.5 px-4",children:N.companySize||"-"}),e.jsxs("td",{className:"py-2.5 px-4",children:[N.country||"-",N.city?`, ${N.city}`:""]}),e.jsx("td",{className:"py-2.5 px-4 uppercase font-bold",children:N.language||"-"}),e.jsx("td",{className:"py-2.5 px-4 truncate max-w-[200px]",title:N.tourTitle,children:N.tourTitle||"-"})]},y)),!((W=c.recentSessions)!=null&&W.length)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"text-center py-10 text-black/30 dark:text-white/30",children:"No tour sessions yet. Data will appear as visitors use the Guided Tour."})})]})]})})]})]},"tours")})()]})]},"analytics")})(),e.jsx(yt,{children:An&&e.jsxs("div",{className:"fixed inset-0 z-[99999] flex items-center justify-center p-6 sm:p-12",children:[e.jsx(ie.div,{initial:{opacity:0}
139,animate:{opacity:1},exit:{opacity:0},onClick:()=>Or(!1),className:"absolute inset-0 bg-black/80 backdrop-blur-xl"}),e.jsxs(ie.div,{initial:{opacity:0,scale:.95,y:40},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:40},className:"relative w-full max-w-4xl bg-white dark:bg-[#0a0a0a] rounded-[4rem] overflow-hidden shadow-[0_40px_100px_-20px_rgba(0,0,0,0.5)] border border-white/20",children:[e.jsxs("div",{className:"p-12 border-b border-black/5 dark:border-white/5 flex items-center justify-between bg-indigo-600/5",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx("div",{className:"w-20 h-20 rounded-3xl bg-indigo-600 flex items-center justify-center text-white shadow-2xl shadow-indigo-600/30",children:e.jsx(ye,{className:"w-10 h-10"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-3xl font-black text-black dark:text-white tracking-tighter mb-2 italic",children:"AI Page Blueprint"}),e.jsx("p",{className:"text-xs font-black text-black/40 dark:text-white/40 uppercase tracking-[0.3em]",children:"Architectural Vision Engine"})]})]}),e.jsx("button",{onClick:()=>Or(!1),className:"w-12 h-12 rounded-full hover:bg-black/5 dark:hover:bg-white/5 flex items-center justify-center transition",children:e.jsx(kt,{className:"w-6 h-6 text-black/20 dark:text-white/20"})})]}),e.jsxs("div",{className:"p-16 space-y-12",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-[11px] font-black uppercase tracking-[0.4em] text-indigo-600",children:"Product Specification Prompt"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1 rounded-full bg-emerald-500/10 text-emerald-600 text-[9px] font-black uppercase",children:[e.jsx(ga,{className:"w-3 h-3"})," KB-CONNECTED"]})]}),e.jsx("p",{className:"text-sm text-black/50 dark:text-white/50 leading-relaxed font-medium max-w-2xl",children:"Describe the business case for this new page. Our model will scan the Knowledge Base to extract clinical truth, then design the componentry and linguistic placeholders."}),e.jsx("div",{className:"relative",children:e.jsx("textarea",{value:Rl,onChange:t=>Pn(t.target.value),placeholder:"Define the page mission (e.g. 'Solution page for Banking Compliance Officers tracking money laundering vocals')...",className:"w-full h-48 p-10 rounded-[2.5rem] bg-black/[0.01] dark:bg-white/[0.01] border-2 border-dashed border-black/5 dark:border-white/10 focus:outline-none focus:border-indigo-600/50 text-lg font-medium text-black dark:text-white transition-all resize-none shadow-inner"})})]}),e.jsxs("div",{className:"flex items-center gap-6 pt-4",children:[e.jsxs("button",{disabled:!Rl||Ba!=="idle",onClick:()=>{Ur("analyzing"),setTimeout(()=>Ur("generating"),1500),setTimeout(()=>Ur("success"),4e3)},className:"h-20 flex-1 rounded-[2rem] bg-black dark:bg-white text-white dark:text-black font-black text-sm uppercase tracking-[0.2em] hover:scale-[1.02] active:scale-95 transition-all shadow-2xl disabled:opacity-50 flex items-center justify-center gap-4 group",children:[Ba==="idle"&&e.jsxs(e.Fragment,{children:[e.jsx(fa,{className:"w-6 h-6 group-hover:rotate-12 transition-transform"})," ENGINEER BLUEPRINT"]}),Ba==="analyzing"&&e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-6 h-6 animate-spin"})," SCANNING LVA KB..."]}),Ba==="generating"&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"w-6 h-6 animate-pulse"})," ASSEMBLING ASSETS..."]}),Ba==="success"&&e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"w-6 h-6 text-emerald-500"})," BLUEPRINT ARCHIVIED"]})]}),e.jsx("button",{onClick:()=>Or(!1),className:"h-20 px-12 rounded-[2rem] border border-black/10 dark:border-white/10 text-xs font-black uppercase tracking-widest hover:bg-black/5 transition",children:"Abort"})]}),Ba==="success"&&e.jsxs(ie.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"p-10 rounded-[3rem] bg-emerald-500/5 border border-emerald-500/20 flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-emerald-500/20 text-emerald-600 flex items-center justify-center",children:e.jsx(Ce,{className:"w-8 h-8"})}),e.jsxs("div",{children:[e.jsx("h5",{className:"font-black text-emerald-800 dark:text-emerald-400 text-lg mb-1 tracking-tight",children:"Intelligence Pack Generated"}),e.jsxs("p",{className:"text-sm text-emerald-600/80 font-medium",children:["The AI has defined the structure and C
139MS keys. ",e.jsx("strong",{children:"Please tell the AI assistant in the chat:"}),` "I'm ready to deploy the [PROMPT] blueprint."`]})]})]})]})]})]})}),o==="pages"&&e.jsx(Kd,{initialPageSlug:Yl,lang:fe}),o==="proposals"&&e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"bg-white dark:bg-zinc-900 border border-black/10 dark:border-white/10 rounded-2xl p-6 shadow-sm",children:[e.jsxs("div",{className:"mb-5 flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-black dark:text-white",children:"Saved Proposals"}),e.jsx("p",{className:"text-xs text-black/50 dark:text-white/50 font-medium",children:"Open an existing quote or start a clean proposal from here."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:Pa,className:"p-2 rounded-lg bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 transition",title:"Refresh",children:e.jsx(tt,{className:`w-4 h-4 ${x?"animate-spin":""}`})}),e.jsxs("button",{onClick:ji,className:"px-4 py-2.5 rounded-xl bg-black text-white dark:bg-white dark:text-black text-xs font-black flex items-center gap-2 hover:opacity-90 transition",children:[e.jsx(Ls,{className:"w-4 h-4"}),"New Proposal"]})]})]}),le.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.03] p-10 text-center",children:[e.jsx("p",{className:"text-sm font-black text-black dark:text-white",children:"No saved proposals yet."}),e.jsx("p",{className:"mt-1 text-xs text-black/50 dark:text-white/50",children:"Create the first proposal, save it, and it will appear in this workspace."}),e.jsxs("button",{onClick:ji,className:"mt-5 inline-flex items-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-xs font-black text-white hover:bg-red-700 transition",children:[e.jsx(Ls,{className:"w-4 h-4"}),"Create Proposal"]})]}):e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2 2xl:grid-cols-3",children:le.map(t=>{var a,s,n;return e.jsxs("div",{className:`p-4 rounded-xl border ${t.archived_at?"bg-amber-500/5 border-amber-500/20":"bg-black/5 dark:bg-white/5 border-black/5 dark:border-white/5"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-black text-sm text-black dark:text-white",children:t.title}),((a=t.proposal)==null?void 0:a.serialNumber)&&e.jsx("p",{className:"text-[11px] font-mono text-black/40 dark:text-white/40 mt-1",children:t.proposal.serialNumber}),e.jsxs("p",{className:"text-xs text-black/50 dark:text-white/50 mt-1",children:[t.client_name,t.client_company?` ⢠${t.client_company}`:""," ⢠",t.status]}),(t.client_phone||((s=t.proposal)==null?void 0:s.clientPhone))&&e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/40 mt-1",children:t.client_phone||((n=t.proposal)==null?void 0:n.clientPhone)}),e.jsx("p",{className:"text-[11px] text-black/40 dark:text-white/40 mt-1",children:t.archived_at?`Archived ${new Date(t.archived_at).toLocaleDateString()}`:`Updated ${new Date(t.updated_at||t.created_at).toLocaleDateString()}`})]}),t.archived_at&&e.jsx("span",{className:"px-2 py-1 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 text-[10px] font-black",children:"ARCHIVED"})]}),e.jsxs("div",{className:"grid grid-cols-5 gap-2 mt-4",children:[e.jsx("button",{onClick:()=>uo(t),className:"p-2 rounded-lg bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 transition",title:"Edit",children:e.jsx(Rt,{className:"w-4 h-4 mx-auto"})}),e.jsx("button",{onClick:()=>Ni(t),className:"p-2 rounded-lg bg-blue-500 text-white hover:bg-blue-600 transition",title:"Download PDF",children:e.jsx(qi,{className:"w-4 h-4 mx-auto"})}),e.jsx("button",{onClick:()=>jo(t,!t.archived_at),className:"p-2 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400 hover:bg-amber-500/20 transition",title:t.archived_at?"Unarchive":"Archive",children:e.jsx(Id,{className:"w-4 h-4 mx-auto"})}),e.jsx("button",{onClick:()=>Co(t),className:"p-2 rounded-lg bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 hover:bg-emerald-500/20 transition",title:"Duplicate",children:e.jsx(ml,{className:"w-4 h-4 mx-auto"})}),e.jsx("button",{onClick:()=>No(t),className:"p-2 rounded-lg bg-red-500/10 text-red-500 hover:bg-red-500/20 transition",title:"Delete",children:e.jsx(ct,{className:"w-4 h-4 mx-auto"})})]})]},t.id)})})]}),e.jsxs("div",{className:"bg-white dark:bg-zinc-900 border border-black/10 dark:border-white/10 rounded-2xl p-6 shadow-sm",children:[e.jsxs("div",{className:"mb-5 flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-black dark:text-white",children:"Rainmaker Acce
139ss"}),e.jsxs("p",{className:"text-xs text-black/50 dark:text-white/50 font-medium",children:["Proposal-only employee login. Share ",e.jsx("span",{className:"font-mono",children:"/rainmaker"}),", not the internal admin console."]})]}),e.jsxs("a",{href:"/rainmaker",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 rounded-xl bg-emerald-600 px-4 py-2.5 text-xs font-black text-white hover:bg-emerald-700 transition",children:[e.jsx(sa,{className:"w-4 h-4"}),"Open Rainmaker"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-[1fr_1fr_1fr_auto]",children:[e.jsx("input",{value:Ie.username,onChange:t=>Fe(a=>({...a,username:t.target.value})),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Username"}),e.jsx("input",{value:Ie.displayName,onChange:t=>Fe(a=>({...a,displayName:t.target.value})),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Display name"}),e.jsx("input",{type:"password",value:Ie.password,onChange:t=>Fe(a=>({...a,password:t.target.value})),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Password"}),e.jsx("button",{onClick:po,disabled:A,className:"px-5 py-3 rounded-xl bg-black text-white dark:bg-white dark:text-black text-xs font-black disabled:opacity-50",children:A?"Saving...":"Create"})]}),e.jsx("div",{className:"mt-4 grid grid-cols-1 gap-2 md:grid-cols-2",children:E.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-black/10 dark:border-white/10 p-4 text-xs font-semibold text-black/45 dark:text-white/45",children:"No rainmaker users yet."}):E.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-black/10 bg-black/[0.02] p-3 dark:border-white/10 dark:bg-white/[0.03]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black text-black dark:text-white",children:t.display_name||t.username}),e.jsxs("p",{className:"text-[11px] font-mono text-black/45 dark:text-white/45",children:[t.username," · ",t.is_active?"active":"disabled"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>bo(t),className:"rounded-lg bg-blue-500/10 px-3 py-2 text-[11px] font-black text-blue-600 dark:text-blue-300",children:"Reset"}),e.jsx("button",{onClick:()=>ki(t,{isActive:!t.is_active}),className:`rounded-lg px-3 py-2 text-[11px] font-black ${t.is_active?"bg-amber-500/10 text-amber-600 dark:text-amber-300":"bg-emerald-500/10 text-emerald-600 dark:text-emerald-300"}`,children:t.is_active?"Disable":"Enable"})]})]},t.id))})]}),Ge&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-zinc-900 border border-black/10 dark:border-white/10 rounded-2xl p-6 shadow-sm space-y-5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b border-black/5 dark:border-white/5 pb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-black dark:text-white",children:Oe?"Edit Proposal":"Proposal Builder"}),e.jsx("p",{className:"text-xs text-black/50 dark:text-white/50 font-medium",children:"Fill the commercial data here, then refine the client-facing preview below."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl p-1.5",children:[e.jsxs("select",{value:Ue,onChange:t=>ot(t.target.value),className:"bg-transparent text-xs font-bold text-black dark:text-white outline-none cursor-pointer px-2 [&_option]:bg-white [&_option]:text-black",children:[e.jsx("option",{className:"bg-white text-black",value:"English",children:"English"}),e.jsx("option",{className:"bg-white text-black",value:"Spanish",children:"Spanish"}),e.jsx("option",{className:"bg-white text-black",value:"Hebrew",children:"Hebrew"}),e.jsx("option",{className:"bg-white text-black",value:"Arabic",children:"Arabic"}),e.jsx("option",{className:"bg-white text-black",value:"Portuguese",children:"Portuguese"}),e.jsx("option",{className:"bg-white text-black",value:"Japanese",children:"Japanese"}),e.jsx("option",{className:"bg-white text-black",value:"Chinese",children:"Chinese"})]}),e.jsxs("button",{onClick:fo,disabled:ae,className:"px-3 py-1.5 rounded-lg bg-red-600 hover:bg-red-700 disabled:opacity-50 text-white text-xs font-black flex items-center gap-1 transition",title:"Translate with Gemini AI",children:[ae?e.jsx(V,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ye,{className:"w-3.5 h-3.5"}),"Translate"]})]}),e.jsx("button",{onClick:wi,className:"p-2 rounded-lg bg-black/5 dark:bg-white/5 hover:bg-black/10 dark:hover:bg-white/10 transition",title:"Close builder",children:e.jsx(kt,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"md:col-span-2 grid grid-cols-[1fr_auto] gap-2",children:[e.jsx("input",{value:q.serialNumber,onChange:t=>gt("serialNumber",t.target.value.toUpperCase()),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm font-mono font-bold",placeholder:"Serial number"}),e.jsx("button",{onClick:()=>
139gt("serialNumber",vl()),className:"px-4 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 hover:bg-black/10 dark:hover:bg-white/10 text-xs font-black transition",title:"Regenerate serial",children:"Regenerate"})]}),e.jsx("input",{value:q.clientName,onChange:t=>gt("clientName",t.target.value),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Client name"}),e.jsx("input",{value:q.clientCompany,onChange:t=>gt("clientCompany",t.target.value),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Client company"}),e.jsx("input",{value:q.clientEmail,onChange:t=>gt("clientEmail",t.target.value),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Client email"}),e.jsx("input",{value:q.clientPhone,onChange:t=>gt("clientPhone",t.target.value),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Client phone (optional)"}),e.jsxs("select",{value:q.status,onChange:t=>gt("status",t.target.value),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",children:[e.jsx("option",{value:"draft",children:"Draft"}),e.jsx("option",{value:"sent",children:"Sent"}),e.jsx("option",{value:"accepted",children:"Accepted"}),e.jsx("option",{value:"declined",children:"Declined"})]}),e.jsxs("div",{className:"grid grid-cols-[0.7fr_1fr] gap-3",children:[e.jsx("input",{value:q.currency,onChange:t=>gt("currency",t.target.value.toUpperCase()),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"USD"}),e.jsxs("label",{className:"grid grid-cols-[auto_1fr] items-center rounded-xl border border-black/10 bg-black/5 dark:border-white/10 dark:bg-white/5 focus-within:ring-2 focus-within:ring-blue-500/40",children:[e.jsx("span",{className:"pl-3 pr-2 text-[10px] font-black uppercase tracking-widest text-black/45 dark:text-white/45",children:"Valid through"}),e.jsx("input",{type:"date",value:q.validUntil,onChange:t=>gt("validUntil",t.target.value),className:"min-w-0 bg-transparent p-3 text-sm outline-none"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-black text-black dark:text-white",children:"Commercial Lines"}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/40",children:"Select the services first, then tune the scope and deliverables below."})]}),e.jsxs("button",{onClick:So,className:"px-3 py-2 rounded-lg bg-black text-white dark:bg-white dark:text-black text-xs font-bold flex items-center gap-2",children:[e.jsx(Ls,{className:"w-3.5 h-3.5"})," Add"]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:Ac.map(t=>e.jsxs("button",{onClick:()=>yo(t),className:"text-left p-3 rounded-xl border border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.03] hover:bg-black/5 dark:hover:bg-white/10 transition",children:[e.jsx("span",{className:"block text-xs font-black text-black dark:text-white",children:t.description}),e.jsx("span",{className:"mt-1 block text-[11px] leading-snug text-black/50 dark:text-white/50",children:t.catalogDescription}),e.jsxs("span",{className:"block text-[10px] font-bold text-black/40 dark:text-white/40 mt-2",children:["Add default qty ",t.quantity.toLocaleString()]})]},t.description))}),q.items.length===0&&e.jsxs("div",{className:"rounded-xl border border-dashed border-black/10 dark:border-white/10 bg-black/[0.02] dark:bg-white/[0.03] p-5 text-center",children:[e.jsx("p",{className:"text-xs font-black text-black dark:text-white",children:"No commercial lines selected yet."}),e.jsx("p",{className:"mt-1 text-[11px] text-black/45 dark:text-white/45",children:"Add only the services the client requested, then shape the scope and deliverables below."})]}),q.items.map((t,a)=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-[minmax(260px,1fr)_124px_156px_44px] gap-2",children:[e.jsx("input",{value:t.description,onChange:s=>il(a,{description:s.target.value}),className:"p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Description"}),e.jsx("input",{type:"number",value:t.quantity,onChange:s=>il(a,{quantity:Number(s.target.value)}),className:"min-w-0 p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm",placeholder:"Qty"}),e.jsxs("div",{className:"flex min-w-0 items-center rounded-xl border border-black/10 bg-black/5 dark:border-white/10 dark:bg-white/5 focus-within:ring-2 focus-within:ring-blue-500/40",children:[e.jsx("span",{className:"min-w-10 border-r border-black/10 px-3 text-center text-xs font-black text-black/45 dark:border-white/10 dark:text-white/45",children:fn(q.currency)}),e.jsx("input",{type:"number",value:t.unitPrice,onChange:s=>il(a,{unitPrice:Number(s.target.value)}),className:"min-w-0 flex-1 bg-transparent p-3 text-sm outline-none",placeholder:"Unit price"})]}),e.jsx("button",{onClick:()=>vo(a),className:"p-3 rounded-xl bg-red-500/10 text-red-500 hover:bg-red-500/20 transition",title:"Remove line",children:e.jsx(ct,{className:"w-4 h-4"})})]},a)),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_110px_140px] gap-2 p-4 rounded-xl bg-black/[0.03] dark:bg-white/[0.04] border border-black/10 dark:border-white/10",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black text-black dark:text-white",children:"Discount"}),e.jsx("p",{className:"text-[10px] text-black/40 dark:text-white/40",children:"Apply percent or fixed amount before PDF exp
139ort."})]}),e.jsxs("select",{value:q.discountType,onChange:t=>gt("discountType",t.target.value),className:"p-3 rounded-xl bg-white dark:bg-black/20 border border-black/10 dark:border-white/10 text-sm",children:[e.jsx("option",{value:"percent",children:"Percent"}),e.jsx("option",{value:"amount",children:"Amount"})]}),e.jsx("input",{type:"number",min:"0",value:q.discountValue,onChange:t=>gt("discountValue",Number(t.target.value)),className:"p-3 rounded-xl bg-white dark:bg-black/20 border border-black/10 dark:border-white/10 text-sm",placeholder:q.discountType==="percent"?"10":"500"})]}),e.jsxs("div",{className:"space-y-1 text-right text-sm text-black/60 dark:text-white/50",children:[e.jsxs("div",{children:["Subtotal: ",e.jsxs("span",{className:"font-bold",children:[q.currency," ",Wa.toLocaleString()]})]}),e.jsxs("div",{children:["Discount: ",e.jsxs("span",{className:"font-bold",children:["-",q.currency," ",ll.toLocaleString()]})]}),e.jsxs("div",{className:"text-xl font-black text-black dark:text-white",children:["Total: ",q.currency," ",vi.toLocaleString()]})]})]}),[["executiveSummary","Executive summary"],["scope","Scope"],["deliverables","Deliverables"],["notes","Notes"],["terms","Terms"]].map(([t,a])=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest text-black/40 dark:text-white/40 font-black",children:a}),e.jsx("textarea",{value:q[t],onChange:s=>gt(t,s.target.value),rows:t==="terms"?2:3,className:"mt-2 w-full p-3 rounded-xl bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 text-sm leading-relaxed"})]},t)),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_1fr] gap-3",children:[e.jsxs("button",{onClick:go,disabled:nt,className:"p-4 rounded-xl bg-red-600 hover:bg-red-700 disabled:opacity-50 text-white font-black flex items-center justify-center gap-2 transition",children:[nt?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ct,{className:"w-4 h-4"}),Oe?"Update Proposal":"Save Proposal"]}),e.jsxs("button",{onClick:wo,className:"p-4 rounded-xl bg-black text-white dark:bg-white dark:text-black font-black flex items-center justify-center gap-2 transition hover:opacity-90",children:[e.jsx(qi,{className:"w-4 h-4"}),"PDF / Print"]})]})]}),e.jsx(Ic,{proposal:q,subtotal:Wa,discount:ll,total:vi,onFieldChange:gt})]})]}),o==="lab-tokens"&&e.jsxs("div",{className:"max-w-5xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 mb-12",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-black tracking-tight mb-2 text-black dark:text-white",children:"Lab Access Control"}),e.jsx("p",{className:"text-black/50 dark:text-white/40 font-medium",children:"Manage override tokens for Real-Time Lab sessions. Each token can have its own time limit."})]}),e.jsx(qe,{className:"w-12 h-12 text-indigo-500/20"})]}),e.jsxs("div",{className:"bg-white dark:bg-zinc-900 rounded-3xl p-8 border border-black/[0.03] dark:border-white/5 shadow-sm mb-12",children:[e.jsxs("h3",{className:"text-lg font-bold mb-6 flex items-center gap-3",children:[e.jsx(Dt,{className:"w-5 h-5 text-indigo-500"}),"Issue New Token"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wider font-black text-black/40 dark:text-white/20 mb-2",children:"Token Value"}),e.jsx("input",{type:"text",value:Yt.token,onChange:t=>ar({...Yt,token:t.target.value}),placeholder:"e.g. VIP-ACCESS-2024",className:"w-full bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl px-5 py-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wider font-black text-black/40 dark:text-white/20 mb-2",children:"Internal Note / Description"}),e.jsx("input",{type:"text",value:Yt.description,onChange:t=>ar({...Yt,description:t.target.value}),placeholder:"Who is this for?",className:"w-full bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl px-5 py-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-wider font-black text-black/40 dark:text-white/20 mb-2",children:"Time Limit (minutes)"}),e.jsx("input",{type:"number",min:"1",value:Yt.time_limit_minutes,onChange:t=>ar({...Yt,time_limit_minutes:t.target.value}),placeholder:"Empty = unlimited",className:"w-full bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5 rounded-2xl px-5 py-4 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 transition-all"})]})]}),e.jsxs("button",{onClick:Uo,disabled:ne||!Yt.token.trim(),className:"w-full md:w-auto px-10 py-4 bg-indigo-600 hover:bg-indigo-500 disabled:opacity-50 text-white rounded-2xl font-black text-sm transition-all shadow-xl shadow-indigo-500/20 flex items-center justify-center gap-3",children:[ne?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ct,{className:"w-4 h-4"}),"Generate Override Token"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-[10px] uppercase tracking-[0.2em] font-black text-black/30 dark:text-white/20 px-4 mb-2",children:"Active Override Tokens"}),On?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-indigo-500/20"})}):zl.length===0?e.jsx("div",{className:"text-center py-20 bg-black/5 dark:bg-white/5 rounded-3xl border border-dashed border-black/10 dark:border-white/10",children:e.jsx("p",{className:"text-sm font-bold text-black/40 dark:text-white/20",children:"No active tokens found."})}):e.jsx("div",{className:"grid grid-cols-1 gap-3",children:zl.map(t=>e.jsxs("div",{className:"group bg-white dark:bg-zinc-900 border border-black/[0.03] dark:border-white/5 p-6 rounded-2xl flex items-center justify-between hover:shadow-xl transition-all",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx("div",{className:"w-12 h-12 bg-indigo-500/10 rounded-xl flex items-center justify-center text-indigo-500",children:e.jsx(jr,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-black text-sm tracking-tight",children:t.token}),e.jsx("span",{className:"text-[9px] bg-indigo-500/10 text-indigo-600 dark:text-indigo-400 px-2 py-0.5 rounded-full font-bold",children:"ACTIVE"}),e.jsx("span",{className:`text-[9px] px-2 py-0.5 rounded-full font-bold ${t.time_limit_minutes?"bg-amber-500/10 text-amber-600 dar
139k:text-amber-400":"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400"}`,children:t.time_limit_minutes?`${t.time_limit_minutes} MIN`:"UNLIMITED"})]}),e.jsxs("p",{className:"text-xs text-black/40 dark:text-white/30 font-medium",children:[t.description||"No description"," ⢠Created ",new Date(t.created_at).toLocaleDateString()]})]})]}),e.jsx("button",{onClick:()=>Fo(t.id),className:"p-3 text-red-500/40 hover:text-red-500 hover:bg-red-500/10 rounded-xl transition-all",title:"Revoke Token",children:e.jsx(ct,{className:"w-5 h-5"})})]},t.id))})]})]}),o==="exports"&&e.jsx("div",{className:"space-y-6 animate-fade-in max-w-4xl",children:e.jsxs("div",{className:"bg-white dark:bg-zinc-900 border border-black/10 dark:border-white/10 rounded-2xl p-6 shadow-sm",children:[e.jsx("h3",{className:"text-sm font-bold text-black dark:text-white mb-4",children:"Generated Documents"}),e.jsxs("div",{className:"space-y-3",children:[(!Array.isArray(l)||l.length===0)&&e.jsx("p",{className:"text-black/50 dark:text-white/50 text-sm",children:"No documents generated yet."}),Array.isArray(l)&&l.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-black/5 dark:bg-white/5 rounded-xl border border-black/5 dark:border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.type==="pdf"?e.jsx(Rt,{className:"w-5 h-5 text-red-500"}):e.jsx(Ed,{className:"w-5 h-5 text-blue-500"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm text-black dark:text-white",children:t.title}),e.jsxs("p",{className:"text-xs text-black/50 dark:text-white/50",children:[new Date(t.createdAt||t.created_at).toLocaleString()," ⢠",(t.type||"").toUpperCase(),t.storageStatus==="legacy-local-only"?" ⢠Legacy local-only":""]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>ho(t),className:"p-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition",title:"Download",children:e.jsx(Ja,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>{fetch(`${m}/api/admin/generated-documents/${t.id}`,{method:"DELETE",headers:{"X-Admin-Token":H}}).then(()=>f(Array.isArray(l)?l.filter(a=>a.id!==t.id):[]))},className:"p-2 bg-red-500/10 text-red-500 rounded-lg hover:bg-red-500/20 transition",children:e.jsx(ct,{className:"w-4 h-4"})})]})]},t.id))]})]})}),o==="feedback"&&(()=>{const t=()=>{sr(!0),fetch(`${m}/api/admin/report-feedback`,{headers:{"X-Admin-Token":H}}).then(ee=>ee.json()).then(ee=>Gl(ee)).catch(console.error).finally(()=>sr(!1))},a=($e==null?void 0:$e.total)||0,s=($e==null?void 0:$e.csatUp)||0,n=($e==null?void 0:$e.csatDown)||0,h=s+n,k=h>0?Math.round(s/h*100):0,L=$e!=null&&$e.avgNps?parseFloat($e.avgNps):0,X=L>=2.5?"Strong":L>=1.5?"Moderate":L>0?"Low":"No data",pe=L>=2.5?"text-emerald-500":L>=1.5?"text-amber-500":"text-red-500",ue=($e==null?void 0:$e.rows)||[];return e.jsxs("div",{className:"max-w-5xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 mb-12",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-black tracking-tight mb-2 text-black dark:text-white",children:"User Feedback"}),e.jsx("p",{className:"text-black/50 dark:text-white/40 font-medium",children:"CSAT and NPS survey responses from analysis reports."})]}),e.jsxs("button",{onClick:t,disabled:Hr,className:"flex items-center gap-2 px-5 py-2.5 bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-xl text-sm font-bold hover:bg-black/10 dark:hover:bg-white/10 transition disabled:opacity-50",children:[e.jsx(tt,{className:`w-4 h-4 ${Hr?"animate-spin":""}`})," Refresh"]})]}),Hr&&!$e?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-black/20 dark:text-white/20"})}):a===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx(Nr,{className:"w-16 h-16 text-black/10 dark:text-white/10 mb-4"}),e.jsx("p",{className:"text-lg font-bold text-black/40 dark:text-white/30",children:"No feedback yet."}),e.jsx("p",{className:"text-sm text-black/30 dark:text-white/20 mt-1",children:"Surveys appear at the end of analysis reports."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 mb-10",children:[e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-2",children:"Total Responses"}),e.jsx("div",{className:"text-4xl font-black text-black dark:text-white tracking-tight",children:a})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-2",children:'CSAT: "Learned Something New?"'}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-4xl font-black text-emerald-500 tracking-tight",children:[k,"%"]}),e.jsx("span",{className:"text-sm text-black/40 dark:text-white/30",children:"positive"})]}),e.jsxs("div",{className:"mt-3 flex gap-4 text-xs font-bold",children:[e.jsxs("span",{className:"flex items-center gap-1 text-emerald-500",children:[e.jsx(Nr,{className:"w-3 h-3"})," ",s]}),e.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[e.jsx(Ji,{className:"w-3 h-3"})," ",n]})]}),e.jsx("div",{className:"mt-3 h-2 bg-red-400/20 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-emerald-500 rounded-full transition-all",style:{width:`${k}%`}})})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-2",children:'NPS: "Would Recommend?"'}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:`text-4xl font-black tracking-tight ${pe}`,children:L>0?L.toFixed(1):"-"}),e.jsx("span",{className:"text-sm text-black/40 dark:text-white/30",children:"/ 3"})]}),e.jsxs("div",{className:"mt-2 text-xs font-bold text-black/40 dark:text-white/30",children:["Sentiment: ",e.jsx("span",{className:pe,children:X})]}),e.jsx("div",{className:"mt-3 h-2 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${L>=2.5?"bg-emerald-500":L>=1.5?"bg-amber-500":"bg-red-500"}`,style:{width:`${L>0?L/3*100:0}%`}})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 mb-10",children:[e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-4",children:"By Tool"}),e.jsx("div",{className:"space-y-2",children:Object.entries(($e==null?void 0:$e.sourceBreakdown)||{}).sort(([,ee],[,ve])=>ve-ee).map(([ee,ve])=>{const it=a>0?Math.round(ve/a*100):0,Ia={feelgpt:"bg-blue-500",callcenters:"bg-purple-500",apptone:"bg-teal-500",hr:"bg-amber-500",unknown:"bg-gray-400"};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-bold text-black/70 dark:text-white/60 capitalize",children:ee}),e.jsxs("span",{className:"text-black/40 dark:text-white/30 font-mono",children:[ve," (",it,"%)"]})]}),e.jsx("div",{className:"h-1.5 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${Ia[ee]||"bg-indigo-500"}`,style:{width:`${it}%`}})})]},ee)})})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-4",children:"By Country"}),e.jsx("div",{className:"space-y-2",children:Object.entries(($e==null?void 0:$e.countryBreakdown)||{}).sort(([,ee],[,ve])=>ve-ee).slice(0,8).map(([ee,ve])=>{const it=a>0?Math.round(ve/a*100):0;return e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"font-bold text-black/70 dark:text-white/60",children:ee}),e.jsxs("span",{className:"text-black/40 dark:text-white/30 font-mono",children:[ve," (",it,"%)"]})]},ee)})})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl p-6",children:[e.jsx("div",{className:"text-[10px] font-black uppercase tracking-[0.15em] text-black/40 dark:text-white/30 mb-4",children:"By Device"}),(()=>{const ee=($e==null?void 0:$e.deviceBreakdown)||{mobile:0,desktop:0},ve=ee.mobile+ee.desktop,it=ve>0?Math.round(ee.mobile/ve*100):0;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-bold text-black/70 dark:text-white/60",children:"ð¥ Desktop"}),e.jsx("span",{className:"text-black/40 dark:text-white/30 font-mono",children:ee.desktop})]}),e.jsx("div",{className:"h-1.5 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-blue-500",style:{width:`${100-it}%`}})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-bold text-black/70 dark:text-white/60",children:"ð± Mobile"}),e.jsx("span",{className:"text-black/40 dark:text-white/30 font-mono",children:ee.mobile})]}),e.jsx("div",{className:"h-1.5 bg-black/5 dark:bg-white/5 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-purple-500",style:{width:`${it}%`}})})]})]})})()]})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-black/5 dark:border-white/10",children:e.jsx("h3",{className:"text-sm font-bold text-black dark:text-white",children:"Recent Responses"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] font-black uppercase tracking-wider text-black/40 dark:text-white/30 border-b border-black/5 dark:border-white/5",children:[e.jsx("th",{className:"text-left px-6 py-3",children:"Date"}),e.jsx("th",{className:"text-center px-3 py-3",children:"CSAT"}),e.jsx("th",{className:"text-center px-3 py-3",children:"NPS"}),e.jsx("th",{className:"text-left px-4 py-3",children:"Source"}),e.jsx("th",{className:"text-left px-4 py-3",children:"Country"}),e.jsx("th",{className:"text-left px-4 py-3",children:"File / Context"})]})}),e.jsx("tbody",{children:ue.slice(0,50).map((ee,ve)=>e.jsxs("tr",{className:"border-b border-black/[0.03] dark:border-white/[0.03] hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition",children:[e.jsx("td",{className:"px-6 py-3 text-xs text-black/50 dark:text-white/40 whitespace-nowrap",children:ee.created_at?new Date(ee.created_at).toLocaleStr
139ing():"-"}),e.jsx("td",{className:"px-3 py-3 text-center",children:ee.csat==="up"?e.jsx(Nr,{className:"w-4 h-4 text-emerald-500 mx-auto"}):ee.csat==="down"?e.jsx(Ji,{className:"w-4 h-4 text-red-400 mx-auto"}):e.jsx("span",{className:"text-black/20 dark:text-white/20",children:"-"})}),e.jsx("td",{className:"px-3 py-3 text-center",children:ee.nps?e.jsx("span",{className:`inline-flex items-center justify-center w-7 h-7 rounded-lg text-xs font-black ${ee.nps===3?"bg-emerald-500/10 text-emerald-600":ee.nps===2?"bg-amber-500/10 text-amber-600":"bg-red-500/10 text-red-500"}`,children:ee.nps}):e.jsx("span",{className:"text-black/20 dark:text-white/20",children:"-"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider ${ee.source==="feelgpt"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":ee.source==="callcenters"?"bg-purple-500/10 text-purple-600 dark:text-purple-400":ee.source==="apptone"?"bg-teal-500/10 text-teal-600 dark:text-teal-400":"bg-black/5 dark:bg-white/5 text-black/40 dark:text-white/40"}`,children:ee.source||"unknown"})}),e.jsx("td",{className:"px-4 py-3 text-xs text-black/50 dark:text-white/40 whitespace-nowrap",children:ee.country&&ee.city?`${ee.country}, ${ee.city}`:ee.country||"-"}),e.jsx("td",{className:"px-4 py-3 text-xs text-black/50 dark:text-white/40 truncate max-w-[200px]",children:ee.context||"-"})]},ee.id||ve))})]})})]})]})]})})(),o==="watchdog"&&e.jsx(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"max-w-6xl mx-auto py-8 px-4",children:e.jsx(ad,{token:H})},"watchdog"),o==="compliance-missions"&&e.jsx(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"w-full py-2",children:e.jsx(sd,{adminToken:H,defaultScope:"marketing"})},"compliance-missions"),o==="security"&&e.jsxs(ie.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-12 max-w-5xl mx-auto py-8",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 px-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-black tracking-tight mb-2 text-black dark:text-white",children:"Security & Maintenance"}),e.jsx("p",{className:"text-black/50 dark:text-white/40 font-medium",children:"Manage platform data snapshots and full-site restoration protocols."})]}),e.jsx("div",{className:"w-16 h-16 rounded-3xl bg-amber-500/10 flex items-center justify-center text-amber-500 shadow-xl shadow-amber-500/5",children:e.jsx(Lt,{className:"w-8 h-8"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8 px-4",children:[e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-[2.5rem] p-10 relative overflow-hidden group shadow-sm",children:[e.jsx("div",{className:"absolute top-0 right-0 w-48 h-48 bg-indigo-500/5 blur-[80px] rounded-full -mr-24 -mt-24 group-hover:bg-indigo-500/10 transition-colors duration-700"}),e.jsxs("div",{className:"flex items-center gap-5 mb-8",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-indigo-500/10 flex items-center justify-center text-indigo-500",children:e.jsx(ga,{className:"w-7 h-7"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-black dark:text-white",children:"Site Backup"}),e.jsx("p",{className:"text-xs text-black/40 dark:text-white/40 font-bold uppercase tracking-widest mt-0.5",children:"Full Data Snapshot"})]})]}),e.jsxs("p",{className:"text-sm text-black/60 dark:text-white/60 mb-10 leading-relaxed font-medium",children:["Generates a complete ZIP archive including all system database tables (CMS, leads, feedback) and the entire ",e.jsx("code",{children:"/uploads"})," directory."]}),e.jsxs("button",{onClick:async()=>{if(!lr){Jr(!0);return}const t=H&&H!=="__cookie__"?H:sessionStorage.getItem("adminToken")||"";Wr(!0),Jr(!1),Hl(null);try{const s=await(await fetch(`${m}/api/admin/backup`,{credentials:"include",headers:t?{"X-Admin-Token":t}:{}})).json();if(s.success&&s.file)Hl(s.file),Wr(!1);else throw new Error(s.error||"Server failed to return file.")}catch(a){console.error("[BACKUP-SYSTEM] Error:",a),alert("Generation error: "+a.message),Wr(!1),Jr(!1)}},disabled:rr,className:`w-full py-5 rounded-[1.5rem] font-black text-[10px] uppercase tracking-[0.2em] transition-all duration-300 shadow-xl flex items-center justify-center gap-3 ${lr?"bg-red-600 text-white animate-pulse":"bg-black dark:bg-white dark:text-black text-white hover:scale-[1.01] active:scale-95 shadow-black/10 dark:shadow-white/5"} disabled:opacity-50`,children:[rr?e.jsx(V,{className:"w-5 h-5 animate-spin"}):lr?e.jsx(Ar,{className:"w-5 h-5"}):e.jsx(Ja,{className:"w-5 h-5"}),rr?"Processing on Server...":lr?"Click Again to Start":"Generate Full Backup"]}),gs&&!rr&&e.jsxs("div",{className:"mt-4 p-6 bg-green-500/10 border border-green-500/20 rounded-[1.5rem] animate-in fade-in slide-in-from-top-4 duration-500",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-green-500 flex items-center justify-center text-white",children:e.jsx(Ce,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-black text-green-600 dark:text-green-400",children:"BACKUP READY"}),e.jsx("p",{className:"text-[10px] text-green-600/60 font-bold uppercase tracking-wider",children:"Valid for 10 minutes"})]})]}),e.jsxs("button",{onClick:async()=>{const t=H&&H!=="__cookie__"?H:sessionStorage.getItem("adminToken")||"",a=`${m}/api/admin/backup/download/${encodeURIComponent(gs)}`;try{const s=await fetch(a,{credentials:"include",headers:t?{"X-Admin-Token":t}:{}});if(!s.ok)throw new Error("Download failed");if("showSaveFilePicker"in window){const h=await(await window.showSaveFilePicker({suggestedName:gs,types:[{description:"EMLO Backup Archive",accept:{"application/zip":[".zip"]}}]})).createWritable();if(!s.body)throw new Error("Empty stream");await s.body.pipeTo(h),alert("Backup saved successfully.")}else{const n=await s.blob(),h=URL.createObjectURL(n),k=document.createElement("a");k.href=h,k.download=gs,document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(h)}}catch(s){s.name!=="AbortError"&&alert("Download error: "+s.message)}},className:"w-full py-4 bg-green-500 text-white rounded-xl font-bold text-xs uppercase tracking-widest hover:bg-green-600 transition-colors shadow-lg shadow-green-500/20 flex items-center justify-center gap-2",children:[e.jsx(Ct,{className:"w-4 h-4"}),"Save As: ",gs]})]})]}),e.jsxs("div",{className:"bg-white dark:bg-white/[0.03] border border-black/5 dark:border-white/10 rounded-[2.5rem] p-10 relative overflow-hidden group shadow-sm",children:[e.jsx("div",{className:"absolute top-0 right-0 w-48 h-48 bg-red-500/5 blur-[80px] rounded-full -mr-24 -mt-24 group-hover:bg-red-500/10 transition-colors duration-700"}),e.jsxs("div",{className:"flex items-center gap-5 mb-8",children:[e.jsx("div",{className:"w-14 h-14 roun
139ded-2xl bg-red-500/10 flex items-center justify-center text-red-500",children:e.jsx(_a,{className:"w-7 h-7"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-black dark:text-white",children:"Restore Point"}),e.jsx("p",{className:"text-xs text-red-500/60 font-black uppercase tracking-widest mt-0.5",children:"Destructive Recovery"})]})]}),e.jsxs("p",{className:"text-sm text-black/60 dark:text-white/60 mb-10 leading-relaxed font-medium",children:["Restore the platform from a backup ZIP. This will ",e.jsx("span",{className:"text-red-500 font-bold uppercase underline underline-offset-4 decoration-2",children:"erase and replace"})," all current database records and files."]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"file",accept:".zip",onChange:t=>{var n;const a=(n=t.target.files)==null?void 0:n[0];if(!a)return;if(!confirm("CRITICAL ACTION: This will PERMANENTLY DELETE all current site data and replace it with the backup contents. This cannot be undone. Start restoration?")){t.target.value="";return}Jl(!0),Kr("idle");const s=new FormData;s.append("backup",a),fetch(`${m}/api/admin/restore`,{method:"POST",headers:{"X-Admin-Token":H},body:s}).then(async h=>{const k=await h.text();if(!h.ok)throw new Error(k||"Restore failed");Kr("success"),alert("Platform Restored Successfully! The site will now reload to apply changes."),window.location.reload()}).catch(h=>{console.error(h),Kr("error"),alert(`Restore failed: ${h.message}`)}).finally(()=>{Jl(!1),t.target.value=""})},disabled:Wl,className:"absolute inset-0 opacity-0 cursor-pointer disabled:cursor-not-allowed z-20"}),e.jsx("div",{className:`w-full py-5 border-2 border-dashed ${Un==="error"?"border-red-500":"border-black/10 dark:border-white/10"} rounded-[1.5rem] flex flex-col items-center gap-3 group-hover:bg-black/5 dark:group-hover:bg-white/5 transition-all duration-300`,children:Wl?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-10 h-10 animate-spin text-black/20 dark:text-white/20"}),e.jsx("span",{className:"text-[10px] font-black text-black/40 dark:text-white/40 uppercase tracking-[0.2em]",children:"Executing Restore Profile..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(_a,{className:"w-10 h-10 text-black/10 dark:text-white/10 group-hover:text-red-500/40 transition-colors"}),e.jsx("span",{className:"text-[10px] font-black text-black/40 dark:text-white/40 uppercase tracking-[0.2em] group-hover:text-black dark:group-hover:text-white transition-colors",children:"Select Recovery ZIP"})]})})]})]})]})]},"security"),e.jsx(yt,{children:be&&e.jsxs(ie.div,{initial:{opacity:0,y:50,scale:.9},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:50,scale:.9},className:`fixed bottom-8 left-1/2 -translate-x-1/2 px-6 py-3 rounded-full flex items-center gap-3 shadow-2xl ${be==="success"?"bg-emerald-900 border border-emerald-500 text-emerald-100":"bg-red-900 border border-red-500 text-red-100"}`,children:[be==="success"?e.jsx(Ce,{className:"w-5 h-5 text-emerald-400"}):e.jsx(Lt,{className:"w-5 h-5 text-red-400"}),e.jsx("span",{className:"text-sm font-bold tracking-wide",children:be==="success"?"Configuration Secured":"Update Failed"})]})})]})}),e.jsx(yt,{children:Fn&&Kl&&e.jsx(rd,{wsUrl:Kl.url,logicName:b.emloDefaultLogic,onClose:()=>Xr(!1)})})]})}export{jm 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.