PageSourceSearch

https://agentoai.dk/assets/CustomerPortal-DDkda8xa.js

js agentoai.dk collected 2026-10-02 01:53:51 UTC 187,301 bytes, 31 lines download raw bytes

1import{r as s,j as e}from"./framer-motion-CQxuJa5n.js";import{g as R}from"./portal-api-WAZs3yxA.js";import{E as Ve,o as at,B as D,Y as ye,p as V,t as $,b as Ws,C as w,i as k,j as L,I as X,f as W,g as q,h as ee,R as qs,Z as _s,w as de,as as Ss,bp as Ut,U as He,v as zs,T as ns,ak as Ge,e as Ot,G as ze,F as rt,ac as nt,z as Jt,s as Gs,al as Us,K as Vt,M as Fs,r as Ht,u as Zt,n as Wt,D as lt,q as qt}from"./index-CSx7K-7R.js";import{B as F}from"./badge-Yar_qzGV.js";import{S as Oe}from"./scroll-area-THRv4UVm.js";import{A as it,b as ct}from"./avatar-Zr31dW4K.js";import{U as Me}from"./user-DwnLXD35.js";import{M as At}from"./index-LVhgA_5_.js";import{C as Ue}from"./check-BKeeD-3t.js";import{C as Pt}from"./copy-B5YKNs8h.js";import{S as hs}from"./send-DOJcdEwD.js";import{T as Ze}from"./textarea-BFuIyuCd.js";import{D as ls,a as is,b as cs,c as ds,d as os,e as Js}from"./dialog-RiETlj4q.js";import{S as pe,a as je,b as fe,c as Ne,d as H}from"./select-BP_Q7Vjk.js";import{S as ve}from"./switch-GLkYldml.js";import{A as Mt,a as It,b as Et,c as Ft}from"./accordion-C7k9loTv.js";import{C as ts}from"./circle-check-B_lwCfqV.js";import{G as Be}from"./globe-B3q7zUSQ.js";import{S as Ks}from"./scan-line-BP_Dvodz.js";import{U as dt}from"./upload-BiTZNTHj.js";import{P as Ee}from"./plus-t8RS0EeL.js";import{F as Ae}from"./file-text-CQNieni0.js";import{S as ms}from"./square-pen-BvxvHUSl.js";import{E as We}from"./external-link-VZCHNZAP.js";import{F as Vs,a as Qt,b as Yt,c as Xt}from"./file-CYKxk_xM.js";import{S as Qs}from"./search-CTXuE0h0.js";import{F as ea}from"./folder-open-vQr_yKOg.js";import{S as Cs}from"./save-DeKktgg2.js";import{L as Hs}from"./lock-CwA9FnEu.js";import{K as ot}from"./key-C6ae3JZp.js";import{T as qe}from"./trash-2-DxlklYFw.js";import{H as sa}from"./hash-CkSgRGoX.js";import{S as Ys}from"./settings-2-Dm1YmtG3.js";import{C as Q}from"./circle-check-big-BvOaTfBT.js";import{C as xs}from"./circle-alert-BTQs6TYB.js";import{F as Kt}from"./filter-DI5DJYUW.js";import{C as Ds}from"./circle-help-Bky_gBt3.js";import{I as mt}from"./info-DiVwxUCE.js";import{S as as}from"./shopping-bag-GeG4M_PB.js";import{C as he}from"./clock-x2s7C7KC.js";import{T as $s}from"./tag-B5g2csum.js";import{P as we}from"./phone-DfeYL_-y.js";import{M as ke}from"./message-square-CQ8acRkB.js";import{C as ta}from"./chevron-up-fhR0nOsN.js";import{C as Xs}from"./chevron-down-DvU9LH4D.js";import{C as _e}from"./circle-x-Bjw_qpIQ.js";import{P as Qe}from"./progress-xZI-P8gz.js";import{S as Zs}from"./shopping-cart-BCwNokFb.js";import{C as Je}from"./calendar-check-DNMgFdaV.js";import{H as aa}from"./headphones-vVl7wEkJ.js";import{M as rs}from"./mail-CQVr-2Yp.js";import{L as ra}from"./link-PqJR2IMo.js";import{P as na}from"./package-D4vF-nAG.js";import{T as Ts,a as Os,b as oe,c as me}from"./tabs-sn5fbWIA.js";import{R as es,P as la,b as ia,c as ca,T as ss,L as Ls,B as fs,C as Ns,X as vs,Y as bs,a as Te}from"./recharts-CFjfazL9.js";import{A as xt}from"./arrow-up-right-BTSeIG-b.js";import{T as da}from"./timer-Cey6-5SR.js";import{C as oa}from"./calendar-days-lRrNvhmZ.js";import{e as ma,s as xa}from"./subMonths-BEEdw389.js";import{t as $t}from"./en-US-Bs6ECJID.js";import{C as ha}from"./chevron-left-DeVGDa0x.js";import{i as ua}from"./isToday-nda2vmij.js";import{C as Lt}from"./calendar-x-DuyPE7JQ.js";import{M as ga}from"./map-pin-VF3CoZYr.js";import{s as pa,a as ja,i as ht}from"./startOfMonth-Bg4Tn_dk.js";import{e as fa}from"./endOfMonth-CbBpMaqD.js";import{f as Pe}from"./format-CUd6TPP6.js";import{d as Ie}from"./da-D_Ezdzgg.js";import{B as ut}from"./bell-BSbCUHyG.js";import{M as Na}from"./message-circle-C_UnzPr5.js";import{S as va}from"./smartphone-Pu_ALQBu.js";import{D as ba}from"./download-B29izdwZ.js";import{C as Rt,a as Bt,b as zt}from"./collapsible-VrVLN1fc.js";import{A as gt,h as pt,a as jt,b as ft,c as Nt,d as vt,e as bt,f as yt,g as kt}from"./alert-dialog-DED_7G_3.js";import{C as ws}from"./checkbox-vurG2JZY.js";import{S as Fe}from"./shield-check-BcKgGayo.js";import{L as ya}from"./link-2-rJ7tgC6B.js";import{M as wt}from"./mouse-pointer-click-uQfHAPlc.js";import{S as ka}from"./settings-ClDRCqQC.js";import{M as _t,S as wa}from"./sun-C0DotSac.js";import{M as _a}from"./monitor-DNcgCq9F.js";import{C as Sa}from"./crown-BJhum9o3.js";import{S as Ca}from"./star-CU4ID_rj.js";import{E as Da}from"./ellipsis-BJpaEW0x.js";import"./index-CwKDC_mg.js";import"./index-BdQq_4o_.js";import"./index-srxnih4L.js";import"./index-oMQApiRp.js";import"./index-CVOcPLpq.js";import"./constructNow-BhFeEnPH.js";function Ta(x){return+$t(x)>Date.now()}function Oa(x){return+$t(x)<Date.now()}const Rs="Hvad skal vi optimere?";function Aa({token:x,agentName:y,onKnowledgeChange:E}){const[v,d]=s.useState([]),[_,p]=s.useState(""),[h,T]=s.useState(!1),[r,m]=s.useState(null),i=s.useRef(null),t=s.useRef(null);s.useEffect(()=>{v.length===0&&d([{id:"0",role:"assistant",content:`Hej! 👋 Jeg er din AI-assistent for **${y}** kundeportalen.
2
3${Rs}`}])},[y]),s.useEffect(()=>{i.current?.scrollIntoView({behavior:"smooth"})},[v]);const I=(f,j)=>{navigator.clipboard.writeText(f),m(j),$.success("Kopieret!"),setTimeout(()=>m(null),2e3)},S=async f=>{const j=f||_.trim();if(!j||h)return;const a=Date.now().toString();f||p(""),d(N=>
3[...N,{id:a,role:"user",content:j}]),T(!0),t.current&&(t.current.style.height="auto");try{const N=await fetch("/api/fn/portal-ai-chat",{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({message:j,conversationHistory:v.slice(-10).map(C=>({role:C.role,content:C.content}))})}),c=await N.json();if(!N.ok)throw new Error(c.error||"Kunne ikke få svar");const n={id:(Date.now()+1).toString(),role:"assistant",content:c.message,pending_action:c.pending_action,needs_confirmation:c.needs_confirmation,action_status:c.needs_confirmation?"pending":void 0};d(C=>[...C,n])}catch(N){const c=N instanceof Error?N.message:"Fejl ved chat";$.error(c),d(n=>[...n,{id:(Date.now()+1).toString(),role:"assistant",content:"Beklager, jeg kunne ikke behandle din besked lige nu. Prøv igen senere."}])}finally{T(!1)}},B=async(f,j)=>{const a=v.find(N=>N.id===f);if(a?.pending_action){if(d(N=>N.map(c=>c.id===f?{...c,action_status:j?"confirmed":"rejected"}:c)),!j){d(N=>[...N,{id:Date.now().toString(),role:"assistant",content:"Ok, handlingen er annulleret. Hvad kan jeg ellers hjælpe dig med?"}]);return}T(!0);try{const N=await fetch("/api/fn/portal-ai-chat",{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({confirmAction:a.pending_action})}),c=await N.json();if(!N.ok)throw new Error(c.error||"Kunne ikke udføre handling");d(n=>n.map(C=>C.id===f?{...C,action_status:"executed"}:C)),d(n=>[...n,{id:Date.now().toString(),role:"assistant",content:c.message||"✅ Handlingen er udført og videnbasen er opdateret!"}]),E?.(),$.success("Gemt!",{description:"Ændringen er blevet gemt."})}catch(N){const c=N instanceof Error?N.message:"Fejl";$.error(c),d(n=>n.map(C=>C.id===f?{...C,action_status:"rejected"}:C))}finally{T(!1)}}},b=f=>{f.key==="Enter"&&!f.shiftKey&&(f.preventDefault(),S())},O=f=>{f.style.height="auto",f.style.height=Math.min(f.scrollHeight,160)+"px"};return e.jsxs("div",{className:"flex flex-col h-[calc(100vh-200px)] min-h-[500px] bg-card rounded-2xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-border flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(Ve,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold text-foreground",children:"AI Assistent"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Kan redigere videnbasen og administrere agenten"})]})]}),e.jsx(Oe,{className:"flex-1",children:e.jsxs("div",{className:"px-6 py-4 space-y-5",children:[v.map(f=>e.jsxs("div",{children:[e.jsxs("div",{className:`flex gap-3 ${f.role==="user"?"flex-row-reverse":""}`,children:[e.jsx(it,{className:"w-8 h-8 shrink-0 mt-0.5",children:e.jsx(ct,{className:f.role==="user"?"bg-primary text-primary-foreground":"bg-muted",children:f.role==="user"?e.jsx(Me,{className:"w-4 h-4"}):e.jsx(at,{className:"w-4 h-4"})})}),e.jsxs("div",{className:`group relative rounded-2xl px-4 py-3 max-w-[80%] ${f.role==="user"?"bg-primary text-primary-foreground rounded-br-md":"bg-muted rounded-bl-md"}`,children:[e.jsx("div",{className:"text-sm leading-relaxed",children:f.role==="assistant"?e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none [&>p]:m-0 [&>p]:mb-1.5 [&>p:last-child]:mb-0 [&>ul]:my-1 [&>ol]:my-1 [&>li]:my-0",children:e.jsx(At,{children:f.content})}):f.content}),f.role==="assistant"&&f.content.length>30&&e.jsx("button",{onClick:()=>I(f.content,f.id),className:"absolute -bottom-7 right-1 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground p-1 rounded",title:"Kopiér",children:r===f.id?e.jsx(Ue,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(Pt,{className:"h-3.5 w-3.5"})})]})]}),f.needs_confirmation&&f.action_status==="pending"&&e.jsxs("div",{className:"ml-11 mt-3 flex gap-2",children:[e.jsxs(D,{size:"sm",onClick:()=>B(f.id,!0),disabled:h,className:"gap-1.5 rounded-xl",children:[e.jsx(Ue,{className:"w-4 h-4"}),"Ja, gem"]}),e.jsxs(D,{size:"sm",variant:"outline",onClick:()=>B(f.id,!1),disabled:h,className:"gap-1.5 rounded-xl",children:[e.jsx(ye,{className:"w-4 h-4"}),"Nej, annuller"]})]}),f.action_status==="executed"&&e.jsx("div",{className:"ml-11 mt-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-primary bg-primary/10 px-2.5 py-1 rounded-full",children:[e.jsx(Ue,{className:"w-3 h-3"}),"Gemt"]})}),f.action_status==="rejected"&&e.jsx("div",{className:"ml-11 mt-2",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground bg-muted px-2.5 py-1 rounded-full",children:[e.jsx(ye,{className:"w-3 h-3"}),"Annulleret"]})})]},f.id)),h&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx(it,{className:"w-8 h-8 shrink-0",children:e.jsx(ct,{className:"bg-muted",children:e.jsx(at,{className:"w-4 h-4"})})}),e.jsxs("div",{className:"bg-muted rounded-2xl rounded-bl-md px-4 py-3 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 bg-muted-foreground
3/40 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]}),e.jsx("div",{ref:i})]})}),v.length<=1&&e.jsx("div",{className:"px-6 py-3 border-t border-border",children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>S(Rs),children:Rs})}),e.jsx("div",{className:"px-6 py-4 border-t border-border",children:e.jsxs("div",{className:"flex items-end gap-3 bg-muted/50 rounded-xl border border-border focus-within:border-primary/50 focus-within:ring-1 focus-within:ring-primary/20 transition-all px-4 py-3",children:[e.jsx("textarea",{ref:t,value:_,onChange:f=>{p(f.target.value),O(f.target)},onKeyDown:b,placeholder:"Skriv din besked...",disabled:h,className:"flex-1 bg-transparent text-sm resize-none outline-none placeholder:text-muted-foreground/60 min-h-[24px] max-h-[160px] leading-6",rows:1}),e.jsx(D,{onClick:()=>S(),disabled:!_.trim()||h,size:"icon",className:"h-9 w-9 rounded-lg shrink-0",children:h?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(hs,{className:"w-4 h-4"})})]})})]})}const St={image:Xt,video:Yt,audio:Qt,"application/pdf":Ae,text:Ae,default:Vs},ys=[{value:"general",label:"Generelt",color:"bg-blue-500"},{value:"prices",label:"Priser",color:"bg-green-500"},{value:"hours",label:"Åbningstider",color:"bg-yellow-500"},{value:"contact",label:"Kontakt",color:"bg-purple-500"},{value:"products",label:"Produkter",color:"bg-orange-500"},{value:"services",label:"Services",color:"bg-pink-500"},{value:"faq",label:"FAQ",color:"bg-cyan-500"},{value:"internal",label:"Intern",color:"bg-red-500"}];function Pa({token:x,canEdit:y,knowledge:E,onRefresh:v,agentId:d}){const{toast:_}=Ws(),p=s.useRef(null),[h,T]=s.useState(""),[r,m]=s.useState("all"),[i,t]=s.useState("all"),[I,S]=s.useState(!1),[B,b]=s.useState(!1),[O,f]=s.useState(!1),[j,a]=s.useState(null),[N,c]=s.useState({}),[n,C]=s.useState(!1),[u,A]=s.useState(!1),[P,z]=s.useState(!1),[se,le]=s.useState(null),[g,G]=s.useState(""),[te,ce]=s.useState("idle");s.useEffect(()=>{if(te==="synced"){const l=setTimeout(()=>ce("idle"),3e3);return()=>clearTimeout(l)}},[te]);const[Y,xe]=s.useState({key:"",value:"",category:"general",is_sensitive:!1,generate_code:!1}),[re,o]=s.useState(""),[Z,ue]=s.useState(null),Se=l=>{a(l.id),c({key:l.key,value:l.value,category:l.category,is_sensitive:l.is_sensitive})},Ke=()=>{a(null),c({})},us=()=>{const l="ABCDEFGHJKLMNPQRSTUVWXYZ23456789";let J="";for(let ae=0;ae<8;ae++)J+=l.charAt(Math.floor(Math.random()*l.length));return J},Ce=E.filter(l=>{const J=h===""||l.key.toLowerCase().includes(h.toLowerCase())||l.value.toLowerCase().includes(h.toLowerCase()),ae=r==="all"||l.category===r,K=i==="all"||l.source_type===i;return J&&ae&&K}),gs=Ce.reduce((l,J)=>{const ae=J.category||"uncategorized";return l[ae]||(l[ae]=[]),l[ae].push(J),l},{}),$e={file:E.filter(l=>l.source_type==="file").length,url:E.filter(l=>l.source_type==="url").length,manual:E.filter(l=>l.source_type==="manual"||!l.source_type).length},De=[...new Set(E.filter(l=>l.source_url).map(l=>l.source_url))],Le=[...new Set(E.filter(l=>l.file_name).map(l=>l.file_name))],Ye=async()=>{g&&(o(g),b(!0),G(""))},M=async()=>{if(!Y.key||!Y.value){_({title:"Udfyld nøgle og værdi",variant:"destructive"});return}C(!0);try{const l=Y.generate_code?us():null,ae=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_knowledge",key:Y.key,value:Y.value,category:Y.category,is_sensitive:Y.is_sensitive,secret_code:l,source_type:"manual"})})).json();if(ae.error)throw new Error(ae.error);ae.synced&&(ce("syncing"),setTimeout(()=>ce("synced"),500)),_({title:"Tilføjet!",description:l?`Hemmelig kode: ${l}`:"Videnbasen er opdateret og synkroniseret til agenten."}),S(!1),xe({key:"",value:"",category:"general",is_sensitive:!1,generate_code:!1}),v()}catch(l){_({title:"Fejl",description:l instanceof Error?l.message:"Kunne ikke tilføje",variant:"destructive"}),ce("idle")}finally{C(!1)}},U=async l=>{const J=l.target.files;if(!J||J.length===0)return;z(!0);let ae=0;try{for(const K of Array.from(J)){const Ms=K.type.startsWith("text/")||K.name.endsWith(".txt")||K.name.endsWith(".md")||K.name.endsWith(".csv"),ps=K.type==="application/pdf"||K.name.endsWith(".pdf");let ne="";if(Ms)ne=await new Promise((Es,js)=>{const Re=new FileReader;Re.onload=Xe=>Es(Xe.target?.result),Re.onerror=js,Re.readAsText(K)});else if(ps){const Es=await new Promise((js,Re)=>{const Xe=new FileReader;Xe.onload=Gt=>{const tt=Gt.target?.result;js(tt.split(",")[1]||tt)}
3,Xe.onerror=Re,Xe.readAsDataURL(K)});try{ne=(await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"extract_pdf_text",file_name:K.name,file_base64:Es})})).json()).text||`[PDF fil: ${K.name} - kunne ikke udtrække tekst]`}catch{ne=`[PDF fil: ${K.name} - uploadet men tekst ikke udtrukket]`}}else ne=`[Fil uploadet: ${K.name}]`;const Is=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"upload_knowledge_file",file_name:K.name,file_type:K.type,file_content:ne,category:"general"})})).json();if(Is.error)throw new Error(Is.error);ae++,_({title:"Fil uploadet",description:`${K.name} (${Is.count||1} elementer tilføjet)`})}v()}catch(K){_({title:"Fejl ved upload",description:K instanceof Error?K.message:"Kunne ikke uploade fil",variant:"destructive"})}finally{z(!1),p.current&&(p.current.value="")}},ie=async()=>{if(!re){_({title:"Indtast en URL",variant:"destructive"});return}A(!0),ue(null);try{const J=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"scan_url",url:re})})).json();if(J.error)throw new Error(J.error);ue(J.results),_({title:"Scanning fuldført!"})}catch(l){_({title:"Fejl ved scanning",description:l instanceof Error?l.message:"Kunne ikke scanne URL",variant:"destructive"})}finally{A(!1)}},be=async()=>{if(Z){C(!0);try{for(const l of Z.items||[])await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_knowledge",key:l.key,value:l.value,category:l.category||"general",source_type:"url",source_url:re})});_({title:"Gemt!",description:`${Z.items?.length||0} elementer tilføjet`}),b(!1),o(""),ue(null),v()}catch(l){_({title:"Fejl",description:l instanceof Error?l.message:"Kunne ikke gemme",variant:"destructive"})}finally{C(!1)}}},ge=async()=>{if(!j||!N.key||!N.value){_({title:"Udfyld nøgle og værdi",variant:"destructive"});return}C(!0);try{const l=await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_knowledge",knowledgeId:j,key:N.key,value:N.value,category:N.category||"general",is_sensitive:N.is_sensitive||!1})}),J=await l.json();if(!l.ok||J.error)throw new Error(J.error||"Kunne ikke gemme");J.synced&&(ce("syncing"),setTimeout(()=>ce("synced"),500)),_({title:"Gemt!",description:"Videnbasen er opdateret og synkroniseret til agenten."}),Ke(),v()}catch(l){_({title:"Fejl",description:l instanceof Error?l.message:"Kunne ikke gemme",variant:"destructive"}),ce("idle")}finally{C(!1)}},et=async l=>{if(confirm("Er du sikker på du vil slette dette?"))try{const ae=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"delete_knowledge",knowledgeId:l})})).json();if(ae.error)throw new Error(ae.error);_({title:"Slettet"}),v()}catch(J){_({title:"Fejl",description:J instanceof Error?J.message:"Kunne ikke slette",variant:"destructive"})}},st=l=>{navigator.clipboard.writeText(l),le(l),setTimeout(()=>le(null),2e3)},As=l=>{if(!l)return Vs;for(const[J,ae]of Object.entries(St))if(l.startsWith(J))return ae;return St.default},Ps=l=>ys.find(J=>J.value===l)||{label:l||"Andet",color:"bg-muted"};return e.jsxs("div",{className:"space-y-4",children:[te!=="idle"&&e.jsx("div",{className:`flex items-center gap-2 p-3 rounded-lg text-sm ${te==="syncing"?"bg-yellow-50 dark:bg-yellow-950/30 text-yellow-700 dark:text-yellow-400 border border-yellow-200 dark:border-yellow-800":"bg-green-50 dark:bg-green-950/30 text-green-700 dark:text-green-400 border border-green-200 dark:border-green-800"}`,children:te==="syncing"?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{children:"Synkroniserer videnbase til agenten..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(ts,{className:"w-4 h-4"}),e.jsx("span",{children:"✓ Agent opdateret med ny videnbase"})]})}),y&&e.jsx(w,{className:"border-primary/20 bg-gradient-to-r from-primary/5 to-transparent",children:e.jsx(k,{className:"pt-6",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(L,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Be,{className:"w-4 h-4 text-primary"}),"Scan website direkte"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(X,{placeholder:"https://dinhjemmeside.dk",value:g,onChange:l=>G(l.target.value),onKeyDown:l=>l.key==="Enter"&&Ye()}),e.jsx(D,{onClick:Ye,disabled:!g||u,children:u?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ks,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(L,{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(dt,{className:"w-4 h-4 text-primary"}),"Upload filer direkte"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:p,type:"file",multiple:!0,accept:".txt,.md,.pdf,.doc,.docx,.csv,.json",className:"hidden",onChange:U}),e.jsx(D,{variant:"outline",className:"flex-1",onClick:()=>p.current?.click(),disabled:P,children:P?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}),"Uploader..."]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"w-4 h-4 mr-2"}),"Vælg filer (.txt, .md, .pdf, .csv)"]})}),e.jsx(D,{variant:"default",onClick:()=>S(!0),children:e.jsx(Ee,{className:"w-4 h-4"})})]})]})]})})}),e.jsxs(w,{children:[e.jsx(W,{className:"pb-3",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(q,{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"w-5 h-5 text-primary"}),"Smart Videnbase"]}),e.jsx(ee,{children:y?"Tilføj, rediger og organiser viden til din agent":"Se information agenten bruger"})]}),e.jsx(D,{variant:"ghost",size:"icon",onClick:v,children:e.jsx(qs,{className:"w-4 h-4"})})]})}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("button",{onClick:()=>t("all"),className:`p-3 rounded-lg transition-colors text-left ${i==="all"?"bg-primary/10 border border-primary":"bg-muted/50 hover:bg-muted"}`,children:[e.jsx("div",{className:"text-2xl font-bold",children:E.length}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Total viden"})]}),e.jsxs("button",{onClick:()=>t("url"),className:`p-3 rounded-lg transition-colors text-left ${i==="url"?"bg-primary/10 border border-primary":"bg-muted/50 hover:bg-muted"}`,children:[e.jsxs("div",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(Be,{className:"w-5 h-5 text-blue-500"}),$e.url]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Fra websites"})]}),e.jsxs("button",{onClick:()=>t("file"),className:`p-3 rounded-lg transition-colors text-left ${i==="file"?"bg-primary/10 border border-primary":"bg-muted/50 hover:bg-muted"}`,children:[e.jsxs("div",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(Ae,{className:"w-5 h-5 text-orange-500"}),$e.file]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Fra filer"})]}),e.jsxs("button",{onClick:()=>t("manual"),className:`p-3 rounded-lg transition-colors text-left ${i==="manual"?"bg-primary/10 border border-primary":"bg-muted/50 hover:bg-muted"}`,children:[e.jsxs("div",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(ms,{className:"w-5 h-5 text-green-500"}),$e.manual]}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Manuelt tilføjet"})]})]}),(De.length>0||Le.length>0)&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[De.length>0&&e.jsxs("div",{className:"p-3 rounded-lg border bg-card",children:[e.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Be,{className:"w-4 h-4 text-blue-500"}
3),"Scannede websites (",De.length,")"]}),e.jsx("div",{className:"space-y-1 max-h-24 overflow-y-auto",children:De.map((l,J)=>e.jsxs("a",{href:l||"#",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline flex items-center gap-1 truncate",children:[e.jsx(We,{className:"w-3 h-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:l})]},J))})]}),Le.length>0&&e.jsxs("div",{className:"p-3 rounded-lg border bg-card",children:[e.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Ae,{className:"w-4 h-4 text-orange-500"}),"Uploadede filer (",Le.length,")"]}),e.jsx("div",{className:"space-y-1 max-h-24 overflow-y-auto",children:Le.map((l,J)=>e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(Vs,{className:"w-3 h-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:l})]},J))})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Qs,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{placeholder:"Søg i videnbasen...",value:h,onChange:l=>T(l.target.value),className:"pl-9"})]}),e.jsxs(pe,{value:r,onValueChange:m,children:[e.jsxs(je,{className:"w-full sm:w-48",children:[e.jsx(ea,{className:"w-4 h-4 mr-2"}),e.jsx(fe,{placeholder:"Alle kategorier"})]}),e.jsxs(Ne,{children:[e.jsx(H,{value:"all",children:"Alle kategorier"}),ys.map(l=>e.jsx(H,{value:l.value,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${l.color}`}),l.label]})},l.value))]})]}),i!=="all"&&e.jsxs(D,{variant:"ghost",size:"sm",onClick:()=>t("all"),children:[e.jsx(ye,{className:"w-4 h-4 mr-1"}),"Nulstil filter"]})]})]})]}),Ce.length===0?e.jsx(w,{children:e.jsxs(k,{className:"py-12 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted mx-auto mb-4 flex items-center justify-center",children:e.jsx(Ae,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"Ingen viden fundet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:h||r!=="all"?"Prøv at ændre din søgning eller filter":"Start med at tilføje viden til din agent"}),y&&e.jsxs(D,{onClick:()=>S(!0),children:[e.jsx(Ee,{className:"w-4 h-4 mr-2"}),"Tilføj din første viden"]})]})}):e.jsx(Mt,{type:"multiple",defaultValue:Object.keys(gs),className:"space-y-2",children:Object.entries(gs).map(([l,J])=>{const ae=Ps(l);return e.jsxs(It,{value:l,className:"border rounded-lg overflow-hidden",children:[e.jsx(Et,{className:"px-4 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-3 h-3 rounded-full ${ae.color}`}),e.jsx("span",{className:"font-medium",children:ae.label}),e.jsx(F,{variant:"secondary",children:J.length})]})}),e.jsx(Ft,{className:"px-4 pb-4",children:e.jsx("div",{className:"space-y-2",children:J.map(K=>{const Ms=As(K.file_type),ps=j===K.id;return e.jsx("div",{className:`p-4 rounded-lg border transition-colors ${ps?"bg-muted border-primary":"bg-card hover:bg-muted/50"}`,children:ps&&y?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(X,{placeholder:"Nøgle",value:N.key||"",onChange:ne=>c({...N,key:ne.target.value})}),e.jsxs(pe,{value:N.category||"general",onValueChange:ne=>c({...N,category:ne}),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsx(Ne,{children:ys.map(ne=>e.jsx(H,{value:ne.value,children:ne.label},ne.value))})]})]}),e.jsx(Ze,{placeholder:"Værdi",value:N.value||"",onChange:ne=>c({...N,value:ne.target.value}),rows:4}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{id:`sensitive-${K.id}`,checked:N.is_sensitive||!1,onCheckedChange:ne=>c({...N,is_sensitive:ne})}),e.jsx(L,{htmlFor:`sensitive-${K.id}`,className:"text-sm",children:"Følsom data"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{size:"sm",onClick:ge,disabled:n,children:[n?e.jsx(V,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Cs,{className:"w-4 h-4 mr-1"}),"Gem"]}),e.jsx(D,{size:"sm",variant:"ghost",onClick:Ke,children:e.jsx(ye,{className:"w-4 h-4"})})]})]}):e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[K.source_type==="file"&&e.jsx(Ms,{className:"w-4 h-4 text-muted-foreground"}),K.source_type==="url"&&e.jsx(Be,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:K.key}),K.is_sensitive&&e.jsxs(F,{variant:"outline",className:"gap-1",children:[e.jsx(Hs,{className:"w-3 h-3"}),"Følsom"]}),K.secret_code&&e.jsxs(F,{variant:"secondary",className:"gap-1 cursor-pointer",onClick:()=>st(K.secret_code),children:[e.jsx(ot,{className:"w-3 h-3"}),se===K.secret_code?e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"w-3 h-3"})," Kopieret"]}):K.secret_code]})]}),e.jsx("p",{className:"text-muted-foreground whitespace-pre-wrap",children:K.value}),K.source_url&&e.jsxs("a",{href:K.source_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline flex items-center gap-1 mt-1",children:[e.jsx(We,{className:"w-3 h-3"}),K.source_url]}
3),K.file_name&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 flex items-center gap-1",children:[e.jsx(Ae,{className:"w-3 h-3"}),K.file_name]})]}),y&&e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsx(D,{size:"icon",variant:"ghost",onClick:()=>Se(K),children:e.jsx(ms,{className:"w-4 h-4"})}),e.jsx(D,{size:"icon",variant:"ghost",onClick:()=>et(K.id),children:e.jsx(qe,{className:"w-4 h-4 text-destructive"})})]})]})},K.id)})})})]},l)})}),e.jsx(ls,{open:I,onOpenChange:S,children:e.jsxs(is,{className:"max-w-lg",children:[e.jsxs(cs,{children:[e.jsxs(ds,{className:"flex items-center gap-2",children:[e.jsx(Ve,{className:"w-5 h-5 text-primary"}),"Tilføj stemmekode"]}),e.jsx(os,{children:"Tilføj information som kunden kan få ved at sige en bestemt kode under opkaldet"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Kategori"}),e.jsxs(pe,{value:Y.category,onValueChange:l=>xe({...Y,category:l}),children:[e.jsx(je,{className:"mt-1",children:e.jsx(fe,{})}),e.jsx(Ne,{children:ys.map(l=>e.jsx(H,{value:l.value,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${l.color}`}),l.label]})},l.value))})]})]}),e.jsxs("div",{children:[e.jsxs(L,{className:"flex items-center gap-2",children:[e.jsx(sa,{className:"w-4 h-4 text-muted-foreground"}),"Stemmekode (det kunden siger)"]}),e.jsx(X,{placeholder:"Fx '1030' eller 'min ordre'",value:Y.key,onChange:l=>xe({...Y,key:l.target.value}),className:"mt-1"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Kunden siger denne kode i telefonen for at få informationen"})]}),e.jsxs("div",{children:[e.jsxs(L,{className:"flex items-center gap-2",children:[e.jsx(_s,{className:"w-4 h-4 text-muted-foreground"}),"Svar (det agenten giver)"]}),e.jsx(Ze,{placeholder:"Det agenten skal svare når koden siges...",value:Y.value,onChange:l=>xe({...Y,value:l.target.value}),rows:4,className:"mt-1"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Denne besked gives til kunden når de siger koden"})]}),e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Hs,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(L,{htmlFor:"sensitive",children:"Følsom data"})]}),e.jsx(ve,{id:"sensitive",checked:Y.is_sensitive,onCheckedChange:l=>xe({...Y,is_sensitive:l})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ot,{className:"w-4 h-4 text-muted-foreground"}),e.jsx(L,{htmlFor:"code",children:"Generer hemmelig kode"})]}),e.jsx(ve,{id:"code",checked:Y.generate_code,onCheckedChange:l=>xe({...Y,generate_code:l})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(D,{variant:"outline",onClick:()=>S(!1),children:"Annuller"}),e.jsxs(D,{onClick:M,disabled:n,children:[n?e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Ee,{className:"w-4 h-4 mr-2"}),"Tilføj"]})]})]})]})}),e.jsx(ls,{open:B,onOpenChange:b,children:e.jsxs(is,{className:"max-w-2xl",children:[e.jsxs(cs,{children:[e.jsxs(ds,{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"w-5 h-5"}),"Scan website for viden"]}),e.jsx(os,{children:"Indtast en URL for at automatisk hente relevant information til videnbasen"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{placeholder:"https://example.com",value:re,onChange:l=>o(l.target.value),className:"pl-9"})]}),e.jsx(D,{onClick:ie,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}),"Scanner..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ks,{className:"w-4 h-4 mr-2"}),"Scan"]})})]}),Z&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-500",children:[e.jsx(ts,{className:"w-4 h-4"}),e.jsxs("span",{className:"font-medium",children:["Fundet ",Z.items?.length||0," elementer"]})]}),e.jsx(Oe,{className:"h-64 border rounded-lg p-3",children:e.jsx("div",{className:"space-y-2",children:Z.items?.map((l,J)=>e.jsxs("div",{className:"p-3 bg-muted rounded",children:[e.jsx("div",{className:"font-medium text-sm",children:l.key}),e.jsx("div",{className:"text-sm text-muted-foreground line-clamp-2",children:l.value})]},J))})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{variant:"outline",onClick:()=>{b(!1),ue(null)},children:"Annuller"}),e.jsxs(D,{onClick:be,disabled:n,children:[n?e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Cs,{className:"w-4 h-4 mr-2"}),"Gem alle (",Z.items?.length||0,")"]})]})]})]})]})})]})}const Ma=({token:x,agentId:y})=>{const[E,v]=s.useState([]),[d,_]=s.useState(!0),[p,h]=s.useState(null),[T,r]=s.useState(null),[m,i]=s.useState(""),[t,I]=s.useState(!1),[S,B]=s.useState(!1);s.useEffect(()=>{b();const u=A=>{const P=(()=>
3{if(typeof A.data=="string")try{return JSON.parse(A.data)}catch{return null}return A.data})();P?.type==="oauth-success"&&($.success(`${P.provider==="google"?"Google":"Outlook"} Calendar tilsluttet!`),b(),h(null)),P?.type==="oauth-error"&&($.error(P.error||"Kalender-tilkobling fejlede"),h(null))};return window.addEventListener("message",u),()=>window.removeEventListener("message",u)},[x,y]);const b=async()=>{try{const P=(await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_integrations"})})).json()).integrations||[];return v(P),P}catch(u){return console.error("Error loading integrations:",u),[]}finally{_(!1)}},O=async u=>{try{h(u),$.info(`Starter ${u==="google"?"Google":"Outlook"} Calendar tilkobling...`);const A=await fetch("/api/fn/start-oauth",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u,agent_id:y,origin:window.location.origin})});let P=null;try{P=await A.json()}catch{P=null}if(P?.error||P?.success===!1)throw Object.assign(new Error(String(P.error||"OAuth start fejlede")),{code:P.code,status:A.status});if(!A.ok)throw Object.assign(new Error(P?.error||`HTTP ${A.status}`),{status:A.status});if(!P?.auth_url)throw new Error("Ingen auth URL modtaget");const z=600,se=700,le=window.screenX+(window.outerWidth-z)/2,g=window.screenY+(window.outerHeight-se)/2,G=window.open(P.auth_url,`${u}-oauth`,`width=${z},height=${se},left=${le},top=${g},popup=1`);if(!G){$.error("Popup blev blokeret. Tillad popups for denne side."),h(null);return}const te=window.setInterval(async()=>{if((await b()).some(re=>re.provider===u&&re.status==="connected")){window.clearInterval(te),h(re=>re===u?null:re);try{G.close()}catch{}}},1200),ce=window.setInterval(async()=>{if(!G.closed)return;window.clearInterval(ce),window.clearInterval(te),(await b()).some(re=>re.provider===u&&re.status==="connected")||$.error("Tilkobling blev ikke gennemført",{description:u==="google"?"Tjek Google OAuth secrets og redirect URI.":"Tjek Microsoft App Registration, secret og admin consent."}),h(re=>re===u?null:re)},800);setTimeout(()=>{window.clearInterval(ce),window.clearInterval(te),h(Y=>Y===u?null:Y)},3e5),setTimeout(()=>{window.clearInterval(te)},3e4)}catch(A){console.error(`${u} connect error:`,A),$.error(Ut(A,u),{description:"Hvis problemet fortsætter, mangler OAuth-secrets sandsynligvis i Vercel/Supabase."}),h(null)}},f=async()=>{if(!m){$.error("Indtast din Zapier webhook URL");return}try{I(!0);const A=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"save_zapier_webhook",webhook_url:m})})).json();if(A.error)throw new Error(A.error);$.success("Zapier webhook gemt!"),i(""),b()}catch(u){console.error("Zapier save error:",u),$.error("Kunne ikke gemme Zapier webhook")}finally{I(!1)}},j=async()=>{try{B(!0);const A=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"test_zapier"})})).json();if(A.error)throw new Error(A.error);$.success("Zapier test event sendt! Tjek dit Zap.")}catch(u){console.error("Zapier test error:",u),$.error(u instanceof Error?u.message:"Kunne ikke teste Zapier")}finally{B(!1)}},a=async(u,A)=>{if(confirm(`Vil du frakoble ${A}?`))try{const z=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"disconnect_integration",integration_id:u})})).json();if(z.error)throw new Error(z.error);$.success("Integration frakoblet"),b()}catch(P){console.error("Disconnect error:",P),$.error("Kunne ikke frakoble integration")}},N=async(u,A)=>{try{r(u),$.info("Synkroniserer aftaler...");const z=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"sync_integration",integration_id:u})})).json();if(z.error)throw new Error(z.error);const se=z.synced||0;$.success(se>0?`${se} aftale(r) synkroniseret til ${A}!`:"Alle aftaler er allerede synkroniseret"),b()}catch(P){console.error("Sync error:",P),$.error("Synkronisering fejlede")}finally{r(null)}},c=u=>E.find(A=>A.provider===u),n=[{id:"google",name:"Google Calendar",description:"Synkroniser aftaler med Google",icon:e.jsxs("svg",{className:"w-6 h-6",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),color:"bg-card",activeColor:"bg-blue-950/30",borderActive:"border-blue-700"},{id:"outlook",name:"Outlook Calendar",description:"Microsoft 365 kalender",icon:e.jsxs("svg",{className:"w-6 h-6",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#0078D4",d:"M24 7.387v10.478c0 .23-.08.424-.238.576-.
316.154-.353.23-.578.23h-8.592v-6.062l1.47 1.078c.098.054.204.08.32.08.12 0 .23-.03.334-.09l6.96-4.46c.06-.04.11-.09.15-.15.04-.06.06-.12.06-.19 0-.1-.04-.18-.12-.24-.08-.06-.18-.1-.3-.1h-.06l-7.02 4.52-2.18-1.6V5.25h8.592c.225 0 .418.077.578.23.158.152.238.346.238.576v1.33z"}),e.jsx("path",{fill:"#0078D4",d:"M7.875 14.062c-.72 0-1.305-.218-1.752-.656-.448-.437-.672-1.03-.672-1.78 0-.76.227-1.367.68-1.82.453-.453 1.04-.68 1.76-.68.702 0 1.273.22 1.71.66.437.44.656 1.038.656 1.795 0 .774-.218 1.383-.652 1.828-.435.444-1.02.668-1.758.668l.028-.015z"}),e.jsx("path",{fill:"#0078D4",d:"M14.592 5.25v12.423c0 .218-.077.404-.232.558-.155.155-.342.232-.56.232H1.776c-.21 0-.39-.075-.54-.224-.15-.15-.225-.33-.225-.54V6.3c0-.21.075-.388.225-.535.15-.147.33-.22.54-.22h12.024c.218 0 .405.077.56.232.155.155.232.342.232.56V5.25zm-6.72 9.766c.962 0 1.717-.302 2.266-.905.55-.603.824-1.434.824-2.492 0-1.038-.272-1.86-.816-2.465-.543-.605-1.292-.908-2.246-.908-.968 0-1.73.302-2.285.905-.556.604-.834 1.43-.834 2.48 0 1.063.275 1.897.824 2.5.55.605 1.308.907 2.274.907l-.007-.022z"})]}),color:"bg-[#0078D4]/5",activeColor:"bg-[#0078D4]/10",borderActive:"border-[#0078D4]/40"}],C=c("zapier");return d?e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(V,{className:"w-8 h-8 animate-spin text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Indlæser integrationer..."})]})}):e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(Ys,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"Integrationer"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Forbind dine kalendere og automatiseringsværktøjer"})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b border-border",children:[e.jsx(de,{className:"w-5 h-5 text-primary"}),e.jsx("h3",{className:"font-semibold text-foreground",children:"Kalender integrationer"})]}),e.jsx("div",{className:"grid gap-4",children:n.map(u=>{const A=c(u.id),P=A?.status==="connected",z=p===u.id,se=T===A?.id;return e.jsxs("div",{className:`group relative flex flex-col sm:flex-row sm:items-center justify-between gap-4 p-5 rounded-2xl border-2 transition-all duration-300 ${P?`${u.activeColor} ${u.borderActive}`:`${u.color} border-border hover:border-primary/30 hover:shadow-lg`}`,children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-14 h-14 rounded-xl flex items-center justify-center transition-all ${P?"bg-card shadow-md border border-border":"bg-card shadow-sm group-hover:shadow-md border border-border"}`,children:u.icon}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-foreground",children:u.name}),P&&e.jsxs(F,{className:"bg-primary/10 text-primary border-0 text-xs font-medium",children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"Forbundet"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:P?A?.settings?.email||"Kalender forbundet":u.description}),P&&A?.last_synced_at&&e.jsxs("p",{className:"text-xs text-muted-foreground/70",children:["Sidst synk: ",new Date(A.last_synced_at).toLocaleString("da-DK")]}),P&&A?.error_message&&e.jsxs("div",{className:"text-xs text-destructive flex items-start gap-1 mt-1",children:[e.jsx(xs,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{children:A.error_message}),A.error_message.includes("admin")||A.error_message.includes("consent")?e.jsx("p",{className:"mt-1 text-muted-foreground",children:"Din IT-administrator skal godkende appen. Bed dem om at besøge admin consent URL."}):A.error_message.includes("refresh")||A.error_message.includes("invalid_grant")?e.jsx("p",{className:"mt-1 text-muted-foreground",children:'Token er udløbet. Klik "Tilslut" igen for at forny forbindelsen.'}):null]})]})]})]}),e.jsx("div",{className:"flex items-center gap-2 sm:flex-shrink-0",children:P?e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>N(A.id,u.name),disabled:se,className:"gap-2",children:[se?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(qs,{className:"w-4 h-4"}),"Synk"]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>a(A.id,u.name),className:"text-muted-foreground hover:text-destructive hover:bg-destructive/10",children:e.jsx(qe,{className:"w-4 h-4"})})]}):e.jsxs(D,{onClick:()=>{O(u.id)},disabled:z,className:"gap-2 min-w-[120px]",children:[z?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ss,{className:"w-4 h-4"}),z?"Tilslutter...":"Tilslut"]})})]},u.id)})}),e.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-muted/50 border border-border",children:[e.jsx(xs,{className:"w-5 h-5 text-primary flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Sådan virker kalenderintegrationen"}),e.jsx("p",{children:"Nye aftaler fra voice agenten oprettes automatisk i din valgte kalender. AI'en tjekker også din tilgængelighed for at undgå dobbeltbookinger."})]})]})]}),e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b border-border",children:[e.jsx(_s,{className:"w-5 h-5 text-orange-500"}),e.jsx("h3",{className:"font-semibold text-foreground",children:"Automatisering"})]}),e.jsx("div",{className:`p-5 rounded-2xl border-2 transition-all duration-300 ${C?.status==="connected"?"bg-orange-500/5 border-orange-500/30":"bg-secondary/30 border-border hover:border-orange-500/30 hover:shadow-lg"}`,children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-14 h-14 roun
3ded-xl bg-gradient-to-br from-orange-500 to-orange-600 flex items-center justify-center shadow-lg flex-shrink-0",children:e.jsx(_s,{className:"w-7 h-7 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Zapier"}),C?.status==="connected"&&e.jsxs(F,{className:"bg-orange-500/10 text-orange-600 border-0 text-xs font-medium",children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"Aktiv"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Forbind med 5000+ apps og automatiser dine workflows"})]})]}),C?.status==="connected"?e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-3 p-3 rounded-xl bg-background/50 border border-border",children:[e.jsxs("code",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0 font-mono bg-muted/50 px-2 py-1 rounded",children:[C.webhook_url?.substring(0,50),"..."]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:j,disabled:S,className:"gap-2 border-orange-300 text-orange-600 hover:bg-orange-50 dark:hover:bg-orange-950/30",children:[S?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(hs,{className:"w-4 h-4"}),"Test"]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>a(C.id,"Zapier"),className:"text-muted-foreground hover:text-destructive hover:bg-destructive/10",children:e.jsx(qe,{className:"w-4 h-4"})})]})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx(X,{placeholder:"https://hooks.zapier.com/hooks/catch/...",value:m,onChange:u=>i(u.target.value),className:"flex-1"}),e.jsxs(D,{onClick:f,disabled:t||!m,className:"gap-2 bg-orange-500 hover:bg-orange-600 text-white min-w-[100px]",children:[t?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Ss,{className:"w-4 h-4"}),"Forbind"]})]}),e.jsxs("a",{href:"https://zapier.com/apps/webhooks/integrations",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-sm text-orange-600 hover:text-orange-700 hover:underline transition-colors",children:[e.jsx(We,{className:"w-4 h-4"}),"Lær at oprette en Zapier webhook"]})]})})]})]})},Ct={Salg:zs,Priser:zs,Booking:de,Åbningstider:he,Ordre:as,Produktinfo:mt,Kontakt:He,Generelt:mt,Support:Ds},Ia={Salg:"bg-green-500/10 text-green-600 border-green-200",Priser:"bg-green-500/10 text-green-600 border-green-200",Booking:"bg-blue-500/10 text-blue-600 border-blue-200",Åbningstider:"bg-amber-500/10 text-amber-600 border-amber-200",Ordre:"bg-purple-500/10 text-purple-600 border-purple-200",Produktinfo:"bg-indigo-500/10 text-indigo-600 border-indigo-200",Kontakt:"bg-cyan-500/10 text-cyan-600 border-cyan-200",Generelt:"bg-slate-500/10 text-slate-600 border-slate-200",Support:"bg-rose-500/10 text-rose-600 border-rose-200"};function Ea({calls:x,token:y,loading:E}){const[v,d]=s.useState(null),[_,p]=s.useState({}),[h,T]=s.useState(null),[r,m]=s.useState(null),i=b=>{if(!b)return"-";const O=Math.floor(b/60),f=b%60;return`${O}:${f.toString().padStart(2,"0")}`},t=b=>b||"Ukendt nummer",I=async b=>{if(_[b]){d(v===b?null:b);return}T(b);try{const f=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":y},body:JSON.stringify({action:"get_call_topics",callId:b})})).json();f.topics&&p(j=>({...j,[b]:f.topics})),d(b)}catch(O){console.error("Error loading topics:",O)}finally{T(null)}},S=Object.values(_).flat().reduce((b,O)=>(b.includes(O.topic_category)||b.push(O.topic_category),b),[]),B=r?x.filter(b=>_[b.id]?.some(f=>f.topic_category===r)):x;return E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(w,{className:"bg-green-500/5 border-green-200",children:e.jsx(k,{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Q,{className:"w-5 h-5 text-green-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-green-800",children:"GDPR-kompatibel visning"}),e.jsx("p",{className:"text-xs text-green-700/80",children:"Vi gemmer kun anonymiserede emner – ingen optagelser eller transskriptioner af samtaler."})]})]})})}),e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Opkald"}),e.jsx("p",{className:"text-muted-foreground",children:"Se hvad dine kunder har spurgt om"})]}),e.jsx(F,{variant:"secondary",className:"text-lg px-4 py-2",children:x.length})]}),S.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(D,{variant:r===null?"default":"outline",size:"sm",onClick:()=>m(null),className:"gap-1.5",children:[e.jsx(Kt,{className:"w-3.5 h-3.5"}),"Alle"]}),S.map(b=>{const O=Ct[b]||$s;return e.jsxs(D,{variant:r===b?"default":"outline",size:"sm",onClick:()=>m(b),className:"gap-1.5",children:[e.jsx(O,{className:"w-3.5 h-3.5"}),b]},b)})]}),x.length===0?e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(we,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("p",{className:"text-muted-foreground",children:"Ingen opkald endnu"})]})}):e.jsx("div",{className:"grid gap-3",children:(r?B:x).map(b=>{const O=v===b.id,f=_[b.id]||[],j=h===b.id;return e.jsx(w,{className:"hover:shadow-md transition-all overflow-hidden",children:e.jsxs(k,{className:"p-0",children:[e.jsxs("button",{onClick:()=>I(b.id),className:"w-full p-4 flex items-center justify-between hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(we,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-mono font-medium",children:t(b.from_number)}),e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(he,{className:"w-3 h-3"}),i(b.duration)]}
3),e.jsx("span",{children:new Date(b.created_at).toLocaleString("da-DK")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{variant:b.status==="completed"?"default":"secondary",children:b.status==="completed"?"Gennemført":b.status}),b.topics_count&&b.topics_count>0&&e.jsxs(F,{variant:"outline",className:"gap-1",children:[e.jsx(ke,{className:"w-3 h-3"}),b.topics_count]}),j?e.jsx(V,{className:"w-5 h-5 animate-spin text-muted-foreground"}):O?e.jsx(ta,{className:"w-5 h-5 text-muted-foreground"}):e.jsx(Xs,{className:"w-5 h-5 text-muted-foreground"})]})]}),O&&e.jsx("div",{className:"border-t bg-muted/20 p-4",children:f.length===0?e.jsxs("div",{className:"text-center py-4 text-muted-foreground",children:[e.jsx(Ds,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Ingen emner registreret for dette opkald"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx($s,{className:"w-4 h-4"}),"Emner diskuteret:"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(a=>{const N=Ct[a.topic_category]||$s,c=Ia[a.topic_category]||"bg-slate-100 text-slate-600";return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg border ${c}`,children:[e.jsx(N,{className:"w-4 h-4"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:a.topic_category}),a.topic_summary&&e.jsx("p",{className:"text-xs opacity-80",children:a.topic_summary})]}),a.is_answered?e.jsx(Q,{className:"w-4 h-4 text-green-500"}):e.jsx(_e,{className:"w-4 h-4 text-red-500"})]},a.id)})}),f.some(a=>!a.is_answered)&&e.jsx("div",{className:"mt-3 p-3 bg-amber-500/10 rounded-lg border border-amber-200",children:e.jsxs("p",{className:"text-sm text-amber-800",children:[e.jsx("strong",{children:"Tip:"})," Nogle spørgsmål kunne ikke besvares. Overvej at tilføje mere viden til din videnbase."]})})]})})]})},b.id)})})]})}function Fa({calls:x,planName:y="Starter",includedMinutes:E=100,topicStats:v}){const[d,_]=s.useState({totalCalls:0,completedCalls:0,totalMinutes:0,avgDuration:0,callsThisMonth:0,minutesThisMonth:0,usagePercentage:0});s.useEffect(()=>{p()},[x,E]);const p=()=>{if(!x.length){_({totalCalls:0,completedCalls:0,totalMinutes:0,avgDuration:0,callsThisMonth:0,minutesThisMonth:0,usagePercentage:0});return}const r=new Date,m=new Date(r.getFullYear(),r.getMonth(),1),i=x.length,t=x.filter(a=>a.status==="completed").length,I=x.reduce((a,N)=>a+(N.duration||0),0),S=Math.ceil(I/60),B=t>0?I/t:0,b=x.filter(a=>new Date(a.created_at)>=m),O=b.length,f=Math.ceil(b.reduce((a,N)=>a+(N.duration||0),0)/60),j=f/E*100;_({totalCalls:i,completedCalls:t,totalMinutes:S,avgDuration:B,callsThisMonth:O,minutesThisMonth:f,usagePercentage:j})},h=r=>{const m=Math.floor(r/60),i=Math.round(r%60);return`${m}:${i.toString().padStart(2,"0")}`},T=new Date().toLocaleString("da-DK",{month:"long",year:"numeric"});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(w,{children:[e.jsx(W,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-5 h-5"}),"Dit forbrug - ",T]}),e.jsxs(ee,{children:["Din plan: ",e.jsx(F,{variant:"secondary",children:y})]})]})})}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-2",children:[e.jsx("span",{children:"Minutforbrug denne måned"}),e.jsxs("span",{className:d.usagePercentage>100?"text-amber-600 font-medium":"",children:[d.minutesThisMonth," / ",E," minutter"]})]}),e.jsx(Qe,{value:Math.min(100,d.usagePercentage),className:`h-3 ${d.usagePercentage>100?"[&>div]:bg-amber-500":d.usagePercentage>80?"[&>div]:bg-yellow-500":""}`}),d.usagePercentage>80&&d.usagePercentage<=100&&e.jsx("p",{className:"text-xs text-yellow-600 mt-1",children:"⚠️ Du nærmer dig din månedlige grænse"}),d.usagePercentage>100&&e.jsx("p",{className:"text-xs text-amber-600 mt-1",children:"⚠️ Du har overskredet dine inkluderede minutter"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 pt-4",children:[e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(we,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Opkald"})]}),e.jsx("p",{className:"text-2xl font-bold",children:d.callsThisMonth}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"denne måned"})]}),e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(he,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Minutter"})]}),e.jsx("p",{className:"text-2xl font-bold",children:d.minutesThisMonth}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"denne måned"})]}),e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ns,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Gns. varighed"})]}),e.jsx("p",{className:"text-2xl font-bold",children:h(d.avgDuration)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"pr. opkald"})]}),e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Q,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Succesrate"})]}),e.jsxs("p",{className:"text-2xl font-bold",children:[d.callsThisMonth>0?Math.round(x.filter(r=>r.status==="completed"&&new Date(r.created_at)>=new Date(new Date().getFullYear(),new Date().getMonth(),1)).length/d.callsThisMonth*100):0,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"gennemførte"})]})]})]})]}),v&&e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"w-5 h-5"}),"Hvad kunder spørger om"]}),e.jsx(ee,{children:"Emnefordeling baseret på opkald"})]}),e.jsx(k,{children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-green-500/10 rounded-lg",children:[e.jsx(Zs,{className:"w-5 h-5 text-green-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:v.sales}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Salg"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-blue-500/10 rounded-lg",children:[e.jsx(Je,{className:"w-5 h-5 text-blue-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:v.booking}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Booking"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-amber-500/10 rounded-lg",children:[e.jsx(aa,{className:"w-5 h-5 text-amber-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:v.support}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Support"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-purple-500/10 rounded-lg",children:[e.jsx(he,{className:"w-5 h-5 text-purple-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:v.opening_hours}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Åbningstider"})]})]})]})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Samlet historik"}),e.jsx(ee,{children:"Alt-tid statistik for din voice agent"})]}),e.jsx(k,{children:e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center p-4 bg-muted/30 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-primary",children:d.totalCalls}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total opkald"})]}),e.jsxs("div",{className:"text-center p-4 bg-muted/30 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-primary",children:d.totalMinutes}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total minutter"})]}),e.jsxs("div",{className:"text-center p-4 bg-muted/30 rounded-lg",children:[e.jsx("p",{className:"text-3xl font-bold text-primary",children:d.completedCalls}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Gennemførte"})]})]})})]})]})}const Ka=["Søndag","Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag"],$a=["Søn","Man","Tir","Ons","Tor","Fre","Lør"];function La({token:x,staff:y,onRefresh:E}){const{toast:v}=Ws(),[d,_]=s.useState(!1),[p,h]=s.useState(null),[T,r]=s.useState(!1),[m,i]=s.useState({name:"",email:"",ph
3one:"",role_title:"",notes:"",is_active:!0,is_primary:!1,google_calendar_id:"",microsoft_calendar_id:"",availability:[]}),t=()=>{i({name:"",email:"",phone:"",role_title:"",notes:"",is_active:!0,is_primary:!1,google_calendar_id:"",microsoft_calendar_id:"",availability:[]})},I=async()=>{if(!m.name||!m.email){v({title:"Udfyld navn og email",variant:"destructive"});return}r(!0);try{const N=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"add_staff",...m})})).json();if(N.error)throw new Error(N.error);v({title:"Medarbejder tilføjet!"}),_(!1),t(),E()}catch(a){v({title:"Fejl",description:a instanceof Error?a.message:"Kunne ikke tilføje",variant:"destructive"})}finally{r(!1)}},S=async a=>{r(!0);try{const c=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_staff",staffId:a,...m})})).json();if(c.error)throw new Error(c.error);v({title:"Opdateret!"}),h(null),t(),E()}catch(N){v({title:"Fejl",description:N instanceof Error?N.message:"Kunne ikke opdatere",variant:"destructive"})}finally{r(!1)}},B=async a=>{if(confirm("Er du sikker på du vil fjerne denne medarbejder?"))try{const c=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"delete_staff",staffId:a})})).json();if(c.error)throw new Error(c.error);v({title:"Medarbejder fjernet"}),E()}catch(N){v({title:"Fejl",description:N instanceof Error?N.message:"Kunne ikke fjerne",variant:"destructive"})}},b=a=>{h(a.id),i({name:a.name,email:a.email,phone:a.phone||"",role_title:a.role_title||"",notes:a.notes||"",is_active:a.is_active,is_primary:a.is_primary,google_calendar_id:a.google_calendar_id||"",microsoft_calendar_id:a.microsoft_calendar_id||"",availability:a.availability||[]})},O=()=>{i(a=>({...a,availability:[...a.availability,{day_of_week:1,start_time:"09:00",end_time:"17:00"}]}))},f=a=>{i(N=>({...N,availability:N.availability.filter((c,n)=>n!==a)}))}
3,j=(a,N,c)=>{i(n=>({...n,availability:n.availability.map((C,u)=>u===a?{...C,[N]:c}:C)}))};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Personale"}),e.jsx("p",{className:"text-muted-foreground",children:"Administrer medarbejdere og tilgængelighed"})]}),e.jsxs(D,{onClick:()=>_(!0),className:"gap-2",children:[e.jsx(Ee,{className:"w-4 h-4"}),"Tilføj medarbejder"]})]}),y.length===0?e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(He,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Ingen personale tilknyttet endnu"}),e.jsxs(D,{onClick:()=>_(!0),children:[e.jsx(Ee,{className:"w-4 h-4 mr-2"}),"Tilføj din første medarbejder"]})]})}):e.jsx("div",{className:"grid md:grid-cols-2 gap-4",children:y.map(a=>{const N=p===a.id;return e.jsx(w,{className:"hover:shadow-md transition-shadow",children:e.jsx(k,{className:"p-5",children:N?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Navn"}),e.jsx(X,{value:m.name,onChange:c=>i({...m,name:c.target.value})})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Rolle"}),e.jsx(X,{value:m.role_title,onChange:c=>i({...m,role_title:c.target.value}),placeholder:"Fx Konsulent"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Email"}),e.jsx(X,{type:"email",value:m.email,onChange:c=>i({...m,email:c.target.value})})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Telefon"}),e.jsx(X,{value:m.phone,onChange:c=>i({...m,phone:c.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Noter (viden til agenten)"}),e.jsx(Ze,{value:m.notes,onChange:c=>i({...m,notes:c.target.value}),placeholder:"Fx specialer, ansvarsomrÃ¥der...",rows:2})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{checked:m.is_active,onCheckedChange:c=>i({...m,is_active:c})}),e.jsx(L,{children:"Aktiv"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{checked:m.is_primary,onCheckedChange:c=>i({...m,is_primary:c})}),e.jsx(L,{children:"Primær kontakt"})]})]}),e.jsx(Mt,{type:"single",collapsible:!0,className:"border rounded-lg",children:e.jsxs(It,{value:"calendar",className:"border-0",children:[e.jsx(Et,{className:"px-3 py-2 text-sm hover:no-underline",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),"Kalender-integration",(m.google_calendar_id||m.microsoft_calendar_id)&&e.jsx(ts,{className:"w-4 h-4 text-primary"})]})}),e.jsxs(Ft,{className:"px-3 pb-3 space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Forbind medarbejderens kalender sÃ¥ voice agenten kan se deres ledige tider."}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xs",children:"Google Calendar ID"}),e.jsx(X,{value:m.google_calendar_id,onChange:c=>i({...m,google_calendar_id:c.target.value}),placeholder:"[email protected] eller calendar ID",className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Typisk medarbejderens email. Find ID i Google Calendar indstillinger."})]}),e.jsxs("div",{children:[e.jsx(L,{className:"text-xs",children:"Microsoft/Outlook Calendar"}),e.jsx(X,{value:m.microsoft_calendar_id,onChange:c=>i({...m,microsoft_calendar_id:c.target.value}),placeholder:"[email protected]",className:"text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Medarbejderens arbejdsmail forbundet til Outlook."})]})]})]})}),e.jsxs("div",{children:[e.jsxs(L,{className:"flex items-center gap-2 mb-2",children:[e.jsx(de,{className:"w-4 h-4"}),"Manuel tilgængelighed"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Bruges hvis ingen kalender er forbundet"}),m.availability.map((c,n)=>e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsxs(pe,{value:c.day_of_week.toString(),onValueChange:C=>j(n,"day_of_week",parseInt(C)),children:[e.jsx(je,{className:"w-28",children:e.jsx(fe,{})}),e.jsx(Ne,{children:Ka.map((C,u)=>e.jsx(H,{value:u.toString(),children:C},u))})]}),e.jsx(X,{type:"time",value:c.start_time,onChange:C=>j(n,"start_time",C.target.value),className:"w-24"}),e.jsx("span",{className:"self-center",children:"-"}),e.jsx(X,{type:"time",value:c.end_time,onChange:C=>j(n,"end_time",C.target.value),className:"w-24"}),e.jsx(D,{size:"icon",variant:"ghost",onClick:()=>f(n),children:e.jsx(ye,{className:"w-4 h-4"})})]},n)),e.jsxs(D,{variant:"outline",size:"sm",onClick:O,children:[e.jsx(Ee,{className:"w-3 h-3 mr-1"}),"Tilføj tid"]}
3)]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{size:"sm",onClick:()=>S(a.id),disabled:T,children:[T?e.jsx(V,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Cs,{className:"w-4 h-4 mr-1"}),"Gem"]}),e.jsx(D,{size:"sm",variant:"ghost",onClick:()=>{h(null),t()},children:e.jsx(ye,{className:"w-4 h-4"})})]})]}):e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-14 w-14 rounded-xl bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Me,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold truncate",children:a.name}),a.is_primary&&e.jsx(F,{className:"bg-primary/20 text-primary border-0 text-xs",children:"Primær"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:a.role_title||"Medarbejder"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("p",{className:"flex items-center gap-1",children:[e.jsx(rs,{className:"w-3 h-3"}),a.email]}),a.phone&&e.jsxs("p",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"w-3 h-3"}),a.phone]})]}),(a.google_calendar_id||a.microsoft_calendar_id)&&e.jsxs("div",{className:"mt-3 pt-3 border-t",children:[e.jsxs("p",{className:"text-xs font-medium mb-2 flex items-center gap-1",children:[e.jsx(ra,{className:"w-3 h-3"}),"Kalender forbundet"]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.google_calendar_id&&e.jsxs("span",{className:"text-xs bg-green-100 text-green-700 dark:bg-green-950 dark:text-green-400 px-2 py-1 rounded flex items-center gap-1",children:[e.jsx(ts,{className:"w-3 h-3"}),"Google"]}),a.microsoft_calendar_id&&e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-400 px-2 py-1 rounded flex items-center gap-1",children:[e.jsx(ts,{className:"w-3 h-3"}),"Outlook"]})]})]}),a.availability&&a.availability.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t",children:[e.jsxs("p",{className:"text-xs font-medium mb-2 flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3"}),"Manuel tilgængelighed"]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:a.availability.map((c,n)=>e.jsxs("span",{className:"text-xs bg-muted px-2 py-1 rounded",children:[$a[c.day_of_week]," ",c.start_time.slice(0,5),"-",c.end_time.slice(0,5)]},n))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(F,{variant:a.is_active?"default":"secondary",className:"shrink-0",children:a.is_active?"Aktiv":"Inaktiv"}),e.jsxs("div",{className:"flex gap-1 mt-2",children:[e.jsx(D,{size:"icon",variant:"ghost",onClick:()=>b(a),children:e.jsx(ms,{className:"w-4 h-4"})}),e.jsx(D,{size:"icon",variant:"ghost",onClick:()=>B(a.id),children:e.jsx(qe,{className:"w-4 h-4 text-destructive"})})]})]})]})})},a.id)})}),e.jsx(ls,{open:d,onOpenChange:_,children:e.jsxs(is,{className:"max-w-lg",children:[e.jsxs(cs,{children:[e.jsx(ds,{children:"Tilføj medarbejder"}),e.jsx(os,{children:"Tilføj en ny medarbejder til din voice agent"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Navn *"}),e.jsx(X,{value:m.name,onChange:a=>i({...m,name:a.target.value}),placeholder:"Fuldt navn"})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Rolle"}),e.jsx(X,{value:m.role_title,onChange:a=>i({...m,role_title:a.target.value}),placeholder:"Fx Konsulent"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Email *"}),e.jsx(X,{type:"email",value:m.email,onChange:a=>i({...m,email:a.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Telefon"}),e.jsx(X,{value:m.phone,onChange:a=>i({...m,phone:a.target.value}),placeholder:"+45 12 34 56 78"})]})]}),e.jsxs("div",{children:[e.jsx(L,{children:"Noter (viden til agenten)"}),e.jsx(Ze,{value:m.notes,onChange:a=>i({...m,notes:a.target.value}),placeholder:"Beskriv ansvarsomrÃ¥der, specialer osv. som agenten kan bruge...",rows:3})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{checked:m.is_active,onCheckedChange:a=>i({...m,is_active:a})}),e.jsx(L,{children:"Aktiv"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{checked:m.is_primary,onCheckedChange:a=>i({...m,is_primary:a})}),e.jsx(L,{children:"Primær kontakt"})]})]})]}),e.jsxs(Js,{children:[e.jsx(D,{variant:"outline",onClick:()=>{_(!1),t()},children:"Annuller"}),e.jsxs(D,{onClick:I,disabled:T,children:[T&&e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}),"Tilføj medarbejder"]})]})]})})]})}function Ra({orders:x,token:y,loading:E,onRefresh:v}){const[d,_]=s.useState(""),[p,h]=s.useState(null),[T,r]=s.useState(!1),m=x.filter(S=>S.order_id.toLowerCase().includes(d.toLowerCase())||S.customer_name.toLowerCase().includes(d.toLowerCase())||S.customer_email&&S.customer_email.toLowerCase().includes(d.toLowerCase())),i=async()=>{r(!0);try{const B=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":y},body:JSON.stringify({action:"get_ecommerce_status"})})).json();B.connection&&h(B.connection)}catch(S){console.error("Error checking e-commerce connection:",S)}finally{r(!1)}};s.useState(()=>{i()});const t=S=>{switch(S?.toLowerCase()){case"completed":case"delivered":return"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200";case"processing":case"pending":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";case"shipped":return"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";case"cancelled":case"refunded":return"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200";default:return"bg-muted text-muted-foreground"}},I=x.filter(S=>S.notes?.includes("AI")).length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Ordrer"}),e.jsx("p",{className:"text-muted-foreground",children:"Ordrer din AI kan give information om"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v&&e.jsx(D,{variant:"outline",size:"icon",onClick:v,children:e.jsx(qs,{className:"w-4 h-4"})}),e.jsx(F,{variant:"secondary",className:"text-lg px-4 py-2",children:x.length})]})]}),e.jsx(w,{className:p?.status==="connected"?"border-green-200 bg-green-50/50 dark:border-green-800 dark:bg-green-950/30":"border-dashed",children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-lg flex items-center justify-center ${p?.status==="connected"?"bg-green-100 dark:bg-green-900":"bg-muted"}`,children:e.jsx(Ss,{className:`w-5 h-5 ${p?.status==="connected"?"text-green-600 dark:text-green-400":"text-muted-foreground"}`})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:"E-commerce integration"}),p?.status==="connected"?e.jsxs(F,{className:"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300 border-0 gap-1",children:[e.jsx(Q,{className:"w-3 h-3"}),"Forbundet"]}):e.jsxs(F,{variant:"secondary",className:"gap-1",children:[e.jsx(xs,{className:"w-3 h-3"}),"Ikke forbundet"]})]}),p?.provider&&e.jsx("p",{className:"text-sm text-muted-foreground",children:p.provider}),p?.last_synced_at&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sidst synk: ",new Date(p.last_synced_at).toLocaleStr
3ing("da-DK")]})]})]}),e.jsx(D,{variant:"outline",size:"sm",onClick:i,disabled:T,children:T?e.jsx(V,{className:"w-4 h-4 animate-spin"}):"Tjek forbindelse"})]})})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(w,{children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(na,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:x.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total ordrer"})]})]})})}),e.jsx(w,{children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-500/10 rounded-lg",children:e.jsx(Q,{className:"w-5 h-5 text-green-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:x.filter(S=>S.order_status?.toLowerCase()==="completed"||S.order_status?.toLowerCase()==="delivered").length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Gennemførte"})]})]})})}),e.jsx(w,{children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-500/10 rounded-lg",children:e.jsx(as,{className:"w-5 h-5 text-blue-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:I}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"AI-assisteret"})]})]})})}),e.jsx(w,{children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-yellow-500/10 rounded-lg",children:e.jsx(de,{className:"w-5 h-5 text-yellow-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:x.filter(S=>{const B=new Date;return new Date(S.created_at).toDateString()===B.toDateString()}).length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"I dag"})]})]})})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Qs,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{placeholder:"Søg i ordrer (ordre-id, kundenavn, email)...",value:d,onChange:S=>_(S.target.value),className:"pl-10"})]}),E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):m.length===0?e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(as,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("p",{className:"text-muted-foreground",children:d?"Ingen ordrer matcher din 
3søgning":"Ingen ordrer registreret"})]})}):e.jsx("div",{className:"grid gap-3",children:m.map(S=>e.jsx(w,{className:"hover:shadow-md transition-shadow",children:e.jsx(k,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-amber-500/10 flex items-center justify-center shrink-0",children:e.jsx(as,{className:"w-5 h-5 text-amber-500"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("p",{className:"font-semibold",children:["Ordre #",S.order_id]}),S.notes?.includes("AI")&&e.jsx(F,{variant:"outline",className:"gap-1 text-xs",children:"✨ AI-assisteret"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Me,{className:"w-3 h-3"}),S.customer_name]}),e.jsx("span",{children:new Date(S.created_at).toLocaleDateString("da-DK")})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{className:t(S.order_status),children:S.order_status||"Ukendt"}),S.order_total!=null&&e.jsxs("span",{className:"font-medium text-lg",children:[S.order_total.toLocaleString("da-DK")," kr"]})]})]})})},S.id))})]})}function Ba({sessions:x}){const[y,E]=s.useState({total:0,purchased:0,pending:0,expired:0,conversionRate:0,totalRevenue:0});s.useEffect(()=>{v()},[x]);const v=()=>{const p=x.length,h=x.filter(t=>t.status==="purchased").length,T=x.filter(t=>["pending","sent","opened"].includes(t.status)).length,r=x.filter(t=>t.status==="expired").length,m=p>0?h/p*100:0,i=x.filter(t=>t.status==="purchased").reduce((t,I)=>t+(I.purchase_amount||0),0);E({total:p,purchased:h,pending:T,expired:r,conversionRate:m,totalRevenue:i})},d=p=>{const T={pending:{variant:"secondary",label:"Afventer",icon:he},sent:{variant:"secondary",label:"Sendt",icon:We},opened:{variant:"outline",label:"Åbnet",icon:We},purchased:{variant:"default",label:"Købt",icon:Q},expired:{variant:"destructive",label:"Udløbet",icon:_e}}[p],r=T.icon;return e.jsxs(F,{variant:T.variant,className:"gap-1",children:[e.jsx(r,{className:"w-3 h-3"}),T.label]})},_=p=>{if(!p)return"Ukendt";const h=p.replace(/\D/g,"");return h.length<4?"••••":`••• ••• ${h.slice(-4)}`};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(w,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Zs,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Total sessioner"})]}),e.jsx("p",{className:"text-2xl font-bold",children:y.total})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Q,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Gennemført"})]}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:y.purchased})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(he,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Afventer"})]}),e.jsx("p",{className:"text-2xl font-bold text-amber-600",children:y.pending})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ns,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Konvertering"})]}),e.jsxs("p",{className:"text-2xl font-bold",children:[y.conversionRate.toFixed(1),"%"]})]})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Salgstragt"}),e.jsx(ee,{children:"Fra samtale til køb"})]}),e.jsx(k,{className:"space-y-4",children:["sent","opened","purchased"].map((p,h)=>{const T=x.filter(i=>p==="sent"?["sent","opened","purchased"].includes(i.status):p==="opened"?["opened","purchased"].includes(i.status):i.status==="purchased").length,r=y.total>0?T/y.total*100:0,m={sent:"SMS sendt",opened:"Link åbnet",purchased:"Køb gennemført"};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{children:m[p]}),e.jsxs("span",{children:[T," (",r.toFixed(0),"%)"]})]}),e.jsx(Qe,{value:r,className:"h-2"})]},p)})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Seneste salgs-sessioner"}),e.jsx(ee,{children:"De seneste SMS-baserede salgsforløb"})]}),e.jsx(k,{children:x.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Zs,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Ingen salgs-sessioner endnu"})]}):e.jsx("div",{className:"space-y-3",children:x.slice(0,10).map(p=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:p.customer_name||"Ukendt kunde"}),d(p.status)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[_(p.customer_phone)," • ",new Date(p.created_at).toLocaleStr
3ing("da-DK",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})]})]}),p.purchase_amount&&e.jsx("div",{className:"text-right",children:e.jsxs("p",{className:"font-bold text-green-600",children:[p.purchase_amount.toLocaleString("da-DK")," kr"]})})]},p.id))})})]})]})}const ks=["hsl(var(--primary))","hsl(142, 76%, 36%)","hsl(217, 91%, 60%)","hsl(45, 93%, 47%)","hsl(262, 83%, 58%)","hsl(0, 84%, 60%)","hsl(173, 80%, 40%)","hsl(328, 85%, 70%)"];function za({token:x,calls:y}){const[E,v]=s.useState(!0),[d,_]=s.useState(null),[p,h]=s.useState(null),[T,r]=s.useState("overview");s.useEffect(()=>{m(),i()},[x]);const m=async()=>{try{const a=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_topic_analytics"})})).json();a.analytics&&_(a.analytics)}catch(j){console.error("Error loading analytics:",j)}finally{v(!1)}},i=async()=>{try{const a=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_bookings"})})).json();if(a.bookings){const N=a.bookings,c=N.length,n=N.filter(P=>P.status==="confirmed"||P.status==="completed").length,C=N.filter(P=>P.status==="cancelled").length,u={};N.forEach(P=>{const z=new Date(P.created_at),se=new Date(z);se.setDate(z.getDate()-z.getDay());const le=se.toISOString().split("T")[0];u[le]||(u[le]={bookings:0,confirmed:0,cancelled:0}),u[le].bookings++,(P.status==="confirmed"||P.status==="completed")&&u[le].confirmed++,P.status==="cancelled"&&u[le].cancelled++});const A=Object.entries(u).sort(([P],[z])=>P.localeCompare(z)).slice(-8).map(([P,z])=>({weekLabel:new Date(P).toLocaleDateString("da-DK",{day:"numeric",month:"short"}),bookings:z.bookings,confirmed:z.confirmed,cancelled:z.cancelled,conversionRate:z.bookings>0?Math.round(z.confirmed/z.bookings*100):0}));h({totalBookings:c,confirmedBookings:n,cancelledBookings:C,conversionRate:c>0?Math.round(n/c*100):0,bookingsByWeek:A})}}catch(j){console.error("Error loading booking stats:",j)}},t=y.length,I=y.filter(j=>j.status==="completed").length,S=y.reduce((j,a)=>j+(a.duration||0),0),B=t>0?Math.round(S/t):0,b=t>0?Math.round(I/t*100):0,O=y.reduce((j,a)=>{const N=new Date(a.created_at),c=new Date(N);c.setDate(N.getDate()-N.getDay());const n=c.toISOString().split("T")[0];return j[n]||(j[n]={week:n,calls:0,completed:0,duration:0}),j[n].calls++,a.status==="completed"&&j[n].completed++,j[n].duration+=a.duration||0,j},{}),f=Object.values(O).sort((j,a)=>j.week.localeCompare(a.week)).slice(-8).map(j=>({...j,weekLabel:new Date(j.week).toLocaleDateString("da-DK",{day:"numeric",month:"short"}),avgDuration:j.calls>0?Math.round(j.duration/j.calls):0}));return E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(Ge,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Avanceret Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Dybdegående indsigt i din AI-agents performance"})]})]}),e.jsxs(Ts,{value:T,onValueChange:r,children:[e.jsxs(Os,{className:"grid w-full grid-cols-4",children:[e.jsxs(oe,{value:"overview",className:"gap-2",children:[e.jsx(Ot,{className:"w-4 h-4"}),"Overblik"]}),e.jsxs(oe,{value:"conversion",className:"gap-2",children:[e.jsx(Je,{className:"w-4 h-4"}),"Konvertering"]}),e.jsxs(oe,{value:"topics",className:"gap-2",children:[e.jsx(ze,{className:"w-4 h-4"}),"Samtaleemner"]}),e.jsxs(oe,{value:"trends",className:"gap-2",children:[e.jsx(ns,{className:"w-4 h-4"}),"Tendenser"]})]}),e.jsxs(me,{value:"overview",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(w,{className:"bg-gradient-to-br from-primary/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(we,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Opkald i alt"})]}),e.jsx("p",{className:"text-3xl font-bold",children:t})]})}),e.jsx(w,{className:"bg-gradient-to-br from-green-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Q,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Fuldførte"})]}),e.jsxs("p",{className:"text-3xl font-bold text-green-600",children:[b,"%"]})]})}),e.jsx(w,{className:"bg-gradient-to-br from-blue-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(he,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Gns. varighed"})]}),e.jsxs("p",{className:"text-3xl font-bold text-blue-600",children:[Math.floor(B/60),":",(B%60).toString().padStart(2,"0")]})]})}),e.jsx(w,{className:"bg-gradient-to-br from-purple-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ze,{className:"w-4 h-4 text-purple-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Besvaret rate"})]}),e.jsxs("p",{className:"text-3xl font-bold text-purple-600",children:[d?.answerRate||0,"%"]})]})})]}),d&&e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"w-5 h-5 text-primary"}),"AI Performance"]}),e.jsx(ee,{children:"Hvordan AI'en håndterer kundespørgsmål"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Spørgsmål besvaret fra videnbase"}),e.jsxs("span",{className:"font-semibold",children:[d.answeredTopics," / ",d.totalTopics]})]}),e.jsx(Qe,{value:d.answerRate,className:"h-3"}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:d.answerRate>=80?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{children:"Fremragende - Din videnbase dækker de fleste spørgsmål"})]}):d.answerRate>=60?e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"w-4 h-4 text-amber-600"}),e.jsx("span",{children:"God - Overvej at tilføje mere viden om hyppige emner"})]}):e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{children:"Behov for forbedring - Tilføj mere viden til din videnbase"})]})})]})]})]}),e.jsx(me,{value:"topics",className:"space-y-6 mt-6",children:d&&d.topicDistribution.length>0?e.jsxs(e.Fragment,{children:[e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Emnefordeling"}),e.jsx(ee,{children:"Hvad dine kunder spørger om mest"})]}),e.jsx(k,{children:e.jsx("div",{className:"h-[300px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(la,{children:[e.jsx(ia,{data:d.topicDistribution,dataKey:"count",nameKey:"category",cx:"50%",cy:"50%",outerRadius:100,label:({category:j,percentage:a})=>`${j} (${a}%)`,children:d.topicDistribution.map((j,a)=>e.jsx(ca,{fill:ks[a%ks.length]},`cell-${a}`))}),e.jsx(ss,{}),e.jsx(Ls,{})]})})})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Besvaret vs. Ikke besvaret"}),e.jsx(ee,{children:"Hvor godt videnbasen dækker hvert emne"})]}),e.jsx(k,{children:e.jsx("div",{className:"h-[300px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(fs,{data:d.topicDistribution,children:[e.jsx(Ns,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(vs,{dataKey:"category",className:"text-xs"}),e.jsx(bs,{className:"text-xs"}),e.jsx(ss,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))"}}),e.jsx(Ls,{}),e.jsx(Te,{dataKey:"count",name:"Besvaret",fill:"hsl(142, 76%, 36%)",radius:[4,4,0,0]}),e.jsx(Te,{dataKey:"unanswered",name:"Ikke besvaret",fill:"hsl(0, 84%, 60%)",radius:[4,4,0,0]})]})})})})]}),e.jsxs(w,{children:[e.jsx(W,{children:e.jsx(q,{children:"Detaljeret emneoversigt"})}),e.jsx(k,{children:e.jsx("div",{className:"space-y-3",children:d.topicDistribution.map((j,a)=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/50",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:ks[a%ks.length]}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"font-medium",children:j.category}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[j.count," spørgsmål"]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[e.jsx(Q,{className:"w-3 h-3 text-green-600"}),e.jsxs("span",{className:"text-green-600",children:[j.count-j.unanswered," besvaret"]})]}),j.unanswered>0&&e.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[e.jsx(_e,{className:"w-3 h-3 text-red-600"}),e.jsxs("span",{className:"text-red-600",children:[j.unanswered," ikke besvaret"]})]})]})]}),e.jsxs(F,{variant:j.unanswered===0?"default":"secondary",children:[Math.round((j.count-j.unanswered)/j.count*100),"%"]})]},j.category))})})]})]}):e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(ze,{className:"w-8 h-8 text-muted-foreground"})}),e.jsxs("p",{className:"text-muted-foreground text-center",children:["Ingen emnedata tilgængelig endnu.",e.jsx("br",{}),"Emner registreres automatisk fra samtaler."]})]})})}),e.jsx(me,{value:"trends",className:"space-y-6 mt-6",children:f.length>0?e.jsxs(e.Fragment,{children:[e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-5 h-5 text-primary"}),"Ugentlig opkaldsvolumen"]}),e.jsx(ee,{children:"Antal opkald per uge"})]}),e.jsx(k,{children:e.jsx("div",{className:"h-[300px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(fs,{data:f,children:[e.jsx(Ns,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(vs,{dataKey:"weekLabel",className:"text-xs"}),e.jsx(bs,{className:"text-xs"}),e.jsx(ss,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))"}}),e.jsx(Te,{dataKey:"calls",name:"Opkald",fill:"hsl(var(--primary))",radius:[4,4,0,0]}),e.jsx(Te,{dataKey:"completed",name:"Fuldført",fill:"hsl(142, 76%, 36%)",radius:[4,4,0,0]})]})})})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:f.slice(-3).reverse().map(j=>e.jsx(w,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Uge fra ",j.weekLabel]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm",children:"Opkald"}),e.jsx("span",{className:"font-medium",children:j.calls})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm",children:"Fuldført"}),e.jsx("span",{className:"font-medium text-green-600",children:j.completed})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm",children:"Gns. varighed"}),e.jsxs("span",{className:"font-medium",children:[Math.floor(j.avgDuration/60),":",(j.avgDuration%60).toString().padStart(2,"0")]})]})]})]})},j.week))})]}):e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(ns,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("p",{className:"text-muted-foreground",children:"Ikke nok data til tendensanalyse"})]})})}),e.jsxs(me,{value:"conversion",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(w,{className:"bg-gradient-to-br from-primary/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Je,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Bookinger i alt"})]}),e.jsx("p",{className:"text-3xl font-bold",children:p?.totalBookings||0})]})}),e.jsx(w,{className:"bg-gradient-to-br from-green-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Q,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Bekræftede"})]}),e.jsx("p",{className:"text-3xl font-bold text-green-600",children:p?.confirmedBookings||0})]})}),e.jsx(w,{className:"bg-gradient-to-br from-red-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(_e,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Aflyste"})]}),e.jsx("p",{className:"text-3xl font-bold text-red-600",children:p?.cancelledBookings||0})]})}),e.jsx(w,{className:"bg-gradient-to-br from-emerald-500/5 to-background",children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(xt,{className:"w-4 h-4 text-emerald-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Konverteringsrate"})]}),e.jsxs("p",{className:"text-3xl font-bold text-emerald-600",children:[p?.conversionRate||0,"%"]})]})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"w-5 h-5 text-primary"}),"Booking Konverteringsrate"]}),e.jsx(ee,{children:"Andel af bookinger der blev bekræftet/gennemført"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Bekræftet / Total"}),e.jsxs("span",{className:"font-semibold",children:[p?.confirmedBookings||0," / ",p?.totalBookings||0]})]}),e.jsx(Qe,{value:p?.conversionRate||0,className:"h-3"}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(p?.conversionRate||0)>=70?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{children:"Fremragende konverteringsrate"})]}):(p?.conversionRate||0)>=40?e.jsxs(e.Fragment,{children:[e.jsx(rt,{className:"w-4 h-4 text-amber-600"}),e.jsx("span",{children:"God rate — overvej opfølgning på ubekræftede bookinger"})]}):e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"w-4 h-4 text-red-600"}),e.jsx("span",{children:"Lav konvertering — tjek booking-flow og opfølgning"})]})})]})]}),p&&p.bookingsByWeek.length>0?e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Bookinger per uge"}),e.jsx(ee,{children:"Ugentlig booking-aktivitet og konvertering"})]}),e.jsx(k,{children:e.jsx("div",{className:"h-[300px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(fs,{data:p.bookingsByWeek,children:[e.jsx(Ns,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(vs,{dataKey:"weekLabel",className:"text-xs"}),e.jsx(bs,{className:"text-xs"}),e.jsx(ss,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))"}}),e.jsx(Ls,{}),e.jsx(Te,{dataKey:"bookings",name:"Bookinger",fill:"hsl(var(--primary))",radius:[4,4,0,0]}),e.jsx(Te,{dataKey:"confirmed",name:"Bekræftet",fill:"hsl(142, 76%, 36%)",radius:[4,4,0,0]}),e.jsx(Te,{dataKey:"cancelled",name:"Aflyst",fill:"hsl(0, 84%, 60%)",radius:[4,4,0,0]})]})})})})]}):e.jsx(w,{className:"border-dashed",children:e.jsxs(k,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(Je,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("p",{className:"t
3ext-muted-foreground",children:"Ingen booking-data endnu"})]})}),p&&p.bookingsByWeek.length>1&&e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsx(q,{children:"Konverteringsrate over tid"}),e.jsx(ee,{children:"Ugentlig konverteringsrate (%)"})]}),e.jsx(k,{children:e.jsx("div",{className:"h-[250px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(fs,{data:p.bookingsByWeek,children:[e.jsx(Ns,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(vs,{dataKey:"weekLabel",className:"text-xs"}),e.jsx(bs,{className:"text-xs",domain:[0,100]}),e.jsx(ss,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))"},formatter:j=>[`${j}%`,"Konverteringsrate"]}),e.jsx(Te,{dataKey:"conversionRate",name:"Konverteringsrate",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})})]})]})]})]})}const Dt={slot_duration_minutes:30,search_days:7,preferred_time_start:"09:00",preferred_time_end:"17:00",allow_weekends:!1,buffer_minutes:0,max_bookings_per_day:null,auto_send_calendar_link:!0,auto_send_sms_confirmation:!0,booking_notice_minutes:60};function Ga({token:x}){const[y,E]=s.useState(Dt),[v,d]=s.useState(!0),[_,p]=s.useState(!1),[h,T]=s.useState(!1);s.useEffect(()=>{r()},[x]);const r=async()=>{try{const I=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_booking_config"})})).json();I.config&&E({...Dt,...I.config})}catch(t){console.error("Error loading booking config:",t)}finally{d(!1)}},m=async()=>{p(!0),T(!1);try{(await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"save_booking_config",config:y})})).json()).success?(T(!0),$.success("Booking-indstillinger gemt"),setTimeout(()=>T(!1),3e3)):$.error("Kunne ikke gemme indstillinger")}catch(t){console.error("Error saving booking config:",t),$.error("Fejl ved gemning")}finally{p(!1)}},i=(t,I)=>{E(S=>({...S,[t]:I})),T(!1)};return v?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(Ys,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Booking-indstillinger"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Styr hvornår og hvordan AI-agenten finder ledige tider"})]})]}),e.jsxs(D,{onClick:m,disabled:_,children:[_?e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}):h?e.jsx(Q,{className:"w-4 h-4 mr-2"}):e.jsx(Cs,{className:"w-4 h-4 mr-2"}),_?"Gemmer...":h?"Gemt!":"Gem indstillinger"]})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{className:"w-5 h-5 text-primary"}),e.jsx(q,{className:"text-lg",children:"Åbningstider for booking"})]}),e.jsx(ee,{children:"Angiv tidsrummet hvor agenten må foreslå og booke tider"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Tidligste tid"}),e.jsxs(pe,{value:y.preferred_time_start,onValueChange:t=>i("preferred_time_start",t),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsx(Ne,{children:Array.from({length:15},(t,I)=>I+6).map(t=>e.jsxs(H,{value:`${String(t).padStart(2,"0")}:00`,children:["Kl. ",String(t).padStart(2,"0"),":00"]},t))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Seneste tid"}),e.jsxs(pe,{value:y.preferred_time_end,onValueChange:t=>i("preferred_time_end",t),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsx(Ne,{children:Array.from({length:15},(t,I)=>I+8).map(t=>e.jsxs(H,{value:`${String(t).padStart(2,"0")}:00`,children:["Kl. ",String(t).padStart(2,"0"),":00"]},t))})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Tillad weekender"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Lad agenten booke tider i weekenden"})]}),e.jsx(ve,{checked:y.allow_weekends,onCheckedChange:t=>i("allow_weekends",t)})]})]})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(da,{className:"w-5 h-5 text-primary"}),e.jsx(q,{className:"text-lg",children:"Tidsintervaller"})]}),e.jsx(ee,{children:"Konfigurer varighed og buffer mellem aftaler"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Varighed per booking"}),e.jsxs(pe,{value:String(y.slot_duration_minutes),onValueChange:t=>i("slot_duration_minutes",parseInt(t)),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"15",children:"15 minutter"}),e.jsx(H,{value:"30",children:"30 minutter"}),e.jsx(H,{value:"45",children:"45 minutter"}),e.jsx(H,{value:"60",children:"60 minutter"}),e.jsx(H,{value:"90",children:"90 minutter"}),e.jsx(H,{value:"120",children:"2 timer"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Buffer mellem aftaler"}),e.jsxs(pe,{value:String(y.buffer_minutes),onValueChange:t=>i("buffer_minutes",parseInt(t)),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"0",children:"Ingen buffer"}),e.jsx(H,{value:"5",children:"5 minutter"}),e.jsx(H,{value:"10",children:"10 minutter"}),e.jsx(H,{value:"15",children:"15 minutter"}),e.jsx(H,{value:"30",children:"30 minutter"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Minimum varsel"}),e.jsxs(pe,{value:String(y.booking_notice_minutes),onValueChange:t=>i("booking_notice_minutes",parseInt(t)),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"0",children:"Ingen krav"}),e.jsx(H,{value:"30",children:"30 minutter"}),e.jsx(H,{value:"60",children:"1 time"}),e.jsx(H,{value:"120",children:"2 timer"}),e.jsx(H,{value:"240",children:"4 timer"}),e.jsx(H,{value:"1440",children:"24 timer"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Hvor lang tid i forvejen der mindst skal bookes"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Max bookinger per dag"}),e.jsx(X,{type:"number",min:0,placeholder:"Ubegrænset",value:y.max_bookings_per_day??"",onChange:t=>i("max_bookings_per_day",t.target.value?parseInt(t.target.value):null)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lad stå tomt for ubegrænset"})]})]})]})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hs,{className:"w-5 h-5 text-primary"}),e.jsx(q,{className:"text-lg",children:"Søgning & Notifikationer"})]}),e.jsx(ee,{children:"Styr hvor langt frem agenten søger og hvad der sendes automatisk"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{children:"Søgevindue"}),e.jsxs(pe,{value:String(y.search_days),onValueChange:t=>i("search_days",parseInt(t)),children:[e.jsx(je,{children:e.jsx(fe,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"3",children:"3 dage frem"}),e.jsx(H,{value:"5",children:"5 dage frem"}),e.jsx(H,{value:"7",children:"7 dage frem"}),e.jsx(H,{value:"14",children:"14 dage frem"}),e.jsx(H,{value:"30",children:"30 dage frem"})]})]})]}),e.jsx(Jt,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Send kalenderlink via SMS"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'Send automatisk et "Tilføj til kalender"-link'})]}),e.jsx(ve,{checked:y.auto_send_calendar_link,onCheckedChange:t=>i("auto_send_calendar_link",t)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(L,{children:"Send SMS-bekræftelse"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Send automatisk en bekræftelses-SMS ved booking"})]}),e.jsx(ve,{checked:y.auto_send_sms_confirmation,onCheckedChange:t=>i("auto_send_sms_confirmation",t)})]})]})]}),e.jsx(w,{className:"border-primary/20 bg-primary/5",children:e.jsx(k,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(oa,{className:"w-5 h-5 text-primary mt-0.5"}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Aktive indstillinger"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(F,{variant:"secondary",children:["Kl. ",y.preferred_time_start," - ",y.preferred_time_end]}),e.jsxs(F,{variant:"secondary",children:[y.slot_duration_minutes," min aftaler"]}),e.jsxs(F,{variant:"secondary",children:[y.search_days," dage frem"]}),y.buffer_minutes>0&&e.jsxs(F,{variant:"secondary",children:[y.buffer_minutes," min buffer"]}),y.allow_weekends&&e.jsx(F,{variant:"secondary",children:"Inkl. weekender"}),y.max_bookings_per_day&&e.jsxs(F,{variant:"secondary",children:["Max ",y.max_bookings_per_day,"/dag"]}),y.auto_send_calendar_link&&e.jsx(F,{variant:"outline",children:"📅 Kalenderlink"}),y.auto_send_sms_confirmation&&e.jsx(F,{variant:"outline",children:"📱 SMS-bekræftelse"})]})]})]})})})]})}const Bs={scheduled:{label:"Planlagt",color:"bg-blue-500/10 text-blue-600 border-blue-200",icon:he},confirmed:{label:"Bekræftet",color:"bg-green-500/10 text-green-600 border-green-200",icon:Q},completed:{label:"Gennemført",color:"bg-emerald-500/10 text-emerald-600 border-emerald-200",icon:Je},cancelled:{label:"Aflyst",color:"bg-red-500/10 text-red-600 border-red-200",icon:_e}
3,no_show:{label:"Udeblevet",color:"bg-amber-500/10 text-amber-600 border-amber-200",icon:Lt}};function Ua({token:x}){const[y,E]=s.useState(!0),[v,d]=s.useState([]),[_,p]=s.useState(new Date),[h,T]=s.useState(null),[r,m]=s.useState(null),i=s.useCallback(async()=>{try{const C=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_bookings"})})).json();C.bookings&&d(C.bookings)}catch(n){console.error("Error loading bookings:",n)}finally{E(!1)}},[x]);s.useEffect(()=>{i();const n=Gs.channel("portal-bookings-realtime").on("postgres_changes",{event:"*",schema:"public",table:"voice_agent_bookings"},()=>{console.log("Booking updated via realtime, refreshing..."),i()}).on("postgres_changes",{event:"*",schema:"public",table:"booking_sessions"},()=>{console.log("Booking session updated, refreshing..."),i()}).subscribe();return()=>{Gs.removeChannel(n)}},[x,i]);const t=async(n,C)=>{try{await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_booking_status",bookingId:n,status:C})}),i()}catch(u){console.error("Error updating booking:",u)}},I=pa(_),S=fa(_),B=ma({start:I,end:S}),b=n=>v.filter(C=>{const u=new Date(C.booking_date);return ht(u,n)}),O=r?v.filter(n=>n.status===r):v,f=h?b(h):O.sort((n,C)=>new Date(C.booking_date).getTime()-new Date(n.booking_date).getTime()),j=v.length,a=v.filter(n=>Ta(new Date(n.booking_date))&&n.status!=="cancelled").length,N=v.filter(n=>n.status==="confirmed"||n.customer_confirmed).length,c=v.filter(n=>n.google_calendar_event_id||n.outlook_calendar_event_id||n.apple_calendar_event_id).length;return y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-6",children:e.jsxs(Ts,{defaultValue:"calendar",className:"w-full",children:[e.jsxs(Os,{className:"grid w-full grid-cols-2 max-w-sm",children:[e.jsxs(oe,{value:"calendar",className:"flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4"}),"Kalender"]}),e.jsxs(oe,{value:"settings",className:"flex items-center gap-2",children:[e.jsx(Ys,{className:"w-4 h-4"}),"Indstillinger"]})]}),e.jsxs(me,{value:"calendar",className:"space-y-6 mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(de,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Kalender"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Oversigt over alle bookinger"})]})]}),e.jsxs(F,{variant:"secondary",className:"text-lg px-4 py-2",children:[j," bookinger"]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(w,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(de,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Kommende"})]}),e.jsx("p",{className:"text-2xl font-bold",children:a})]})}),e.jsx(w,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Q,{className:"w-4 h-4 text-green-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Bekræftet"})]}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:N})]})}),e.jsx(w,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(rs,{className:"w-4 h-4 text-purple-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Synkroniseret"})]}),e.jsx("p",{className:"text-2xl font-bold text-purple-600",children:c})]})}),e.jsx(w,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(he,{className:"w-4 h-4 text-amber-600"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"I dag"})]}),e.jsx("p",{className:"text-2xl font-bold text-amber-600",children:b(new Date).length})]})})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs(w,{children:[e.jsx(W,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(D,{variant:"ghost",size:"icon",onClick:()=>p(xa(_)),children:e.jsx(ha,{className:"w-4 h-4"})}),e.jsx(q,{className:"text-lg",children:Pe(_,"MMMM yyyy",{locale:Ie})}),e.jsx(D,{variant:"ghost",size:"icon",onClick:()=>p(ja(_,1)),children:e.jsx(Us,{className:"w-4 h-4"})})]})}),e.jsxs(k,{children:[e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-2",children:["Man","Tir","Ons","Tor","Fre","Lør","Søn"].map(n=>e.jsx("div",{className:"text-center text-xs font-medium text-muted-foreground py-2",children:n},n))}),e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[Array.from({length:(I.getDay()+6)%7}).map((n,C)=>e.jsx("div",{className:"aspect-square"},`empty-${C}`)),B.map(n=>{const C=b(n),u=C.length>0,A=h&&ht(n,h),P=ua(n);return e.jsxs("button",{onClick:()=>T(A?null:n),className:`aspect-square rounded-lg flex flex-col items-center justify-center text-sm transition-all relative ${A?"bg-primary text-primary-foreground":P?"bg-primary/10 text-primary font-semibold":u?"bg-muted hover:bg-muted/80":"hover:bg-muted/50"}`,children:[Pe(n,"d"),u&&e.jsx("div",{className:"absolute bottom-1 flex gap-0.5",children:C.slice(0,3).map((z,se)=>e.jsx("div",{className:`w-1 h-1 rounded-full ${A?"bg-primary-foreground":"bg-primary"}`},se))})]},n.toISOString())})]})]})]}),e.jsxs(w,{children:[e.jsxs(W,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{className:"text-lg",children:h?Pe(h,"d. MMMM yyyy",{locale:Ie}):"Alle bookinger"}),h&&e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>T(null),children:"Vis alle"})]}),!h&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[e.jsxs(D,{variant:r===null?"default":"outline",size:"sm",onClick:()=>m(null),children:[e.jsx(Kt,{className:"w-3.5 h-3.5 mr-1"}),"Alle"]}),Object.entries(Bs).map(([n,C])=>e.jsx(D,{variant:r===n?"default":"outline",size:"sm",onClick:()=>m(n),children:C.label},n))]})]}),e.jsx(k,{className:"max-h-[400px] overflow-y-auto",children:f.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(de,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsxs("p",{children:["Ingen bookinger ",h?"på denne dag":"fundet"]})]}):e.jsx("div",{className:"space-y-3",children:f.map(n=>{const C=Bs[n.status]||Bs.scheduled,u=C.icon,A=n.google_calendar_event_id||n.outlook_calendar_event_id||n.apple_calendar_event_id;return e.jsxs("div",{className:"p-4 rounded-xl border bg-card hover:shadow-md transition-all",children:[e.jsx("div",{className:"flex items-start justify-between gap-3 mb-3",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("span",{className:"font-medium",children:n.customer_name||"Ukendt kunde"}),e.jsxs(F,{className:`${C.color} border`,children:[e.jsx(u,{className:"w-3 h-3 mr-1"}),C.label]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[Pe(new Date(n.booking_date),"d. MMM yyyy",{locale:Ie}),n.booking_time&&` kl. ${n.booking_time}`]})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm mb-3",children:[n.customer_email&&e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(rs,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:n.customer_email})]}),n.customer_phone&&e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(we,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:n.customer_phone})]}),n.service_type&&e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground col-span-2",children:[e.jsx(ga,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:n.service_type})]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs mb-3",children:[A&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600",children:[e.jsx(Q,{className:"w-3 h-3"}),"Synkroniseret til kalender"]}),n.confirmation_email_sent_at&&e.jsxs("span",{className:"flex items-center gap-1 text-blue-600",children:[e.jsx(rs,{className:"w-3 h-3"}),"Mail sendt"]}),n.customer_confirmed&&e.jsxs("span",{className:"flex items-center gap-1 text-emerald-600",children:[e.jsx(Me,{className:"w-3 h-3"}),"Kunde bekræftet"]})]}),n.status==="scheduled"&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>t(n.id,"confirmed"),children:[e.jsx(Q,{className:"w-3.5 h-3.5 mr-1"}),"Bekræft"]}),e.jsxs(D,{size:"sm",variant:"outline",className:"text-red-600 hover:text-red-700",onClick:()=>t(n.id,"cancelled"),children:[e.jsx(_e,{className:"w-3.5 h-3.5 mr-1"}),"Aflys"]})]}),n.status==="confirmed"&&Oa(new Date(n.booking_date))&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{size:"sm",variant:"outline",className:"flex-1",onClick:()=>t(n.id,"completed"),children:[e.jsx(Je,{className:"w-3.5 h-3.5 mr-1"}),"Marker gennemført"]}),e.jsxs(D,{size:"sm",variant:"outline",className:"text-amber-600 hover:text-amber-700",onClick:()=>t(n.id,"no_show"),children:[e.jsx(Lt,{className:"w-3.5 h-3.5 mr-1"}),"Udeblevet"]})]})]},n.id)})})})]})]})]}),e.jsx(me,{value:"settings",className:"mt-6",children:e.jsx(Ga,{token:x})})]})})}function Ja({token:x}){const[y,E]=s.useState(!0),[v,d]=s.useState([]),[_,p]=s.useState(""),[h,T]=s.useState(null),[r,m]=s.useState(null),[i,t]=s.useState(!1),[I,S]=s.useState(!1),[B,b]=s.useState(!1),[O,f]=s.useState({date:"",time:"",reason:"",notes:""}),[j,a]=s.useState(""),[N,c]=s.useState(!1);s.useEffect(()=>{n()},[x]);const n=async()=>{try{const G=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_customers"})})).json();G.customers&&d(G.customers)}catch(g){console.error("Error loading customers:",g)}finally{E(!1)}},C=async g=>{t(!0);try{const te=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_customer_details",customerPhone:g})})).json();te.customer&&(m(te.customer),a(te.customer.notes||""))}catch(G){console.error("Error loading customer details:",G)}finally{t(!1)}},u=g=>{T(g),C(g.phone)},A=async()=>
3{if(h){c(!0);try{await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_customer_note",customerPhone:h.phone,notes:j})}),$.success("Note gemt"),b(!1),h&&C(h.phone),n()}catch(g){console.error("Error saving note:",g),$.error("Kunne ikke gemme note")}finally{c(!1)}}},P=async()=>{if(!(!h||!O.date)){c(!0);try{await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"create_follow_up",customerPhone:h.phone,followUpDate:O.date,followUpTime:O.time||null,reason:O.reason||null,notes:O.notes||null})}),$.success("Opfølgning oprettet"),S(!1),f({date:"",time:"",reason:"",notes:""}),h&&C(h.phone)}catch(g){console.error("Error creating follow-up:",g),$.error("Kunne ikke oprette opfølgning")}finally{c(!1)}}},z=async g=>{try{await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"update_follow_up",followUpId:g,status:"completed"})}),$.success("Opfølgning markeret som gennemført"),h&&C(h.phone)}catch(G){console.error("Error updating follow-up:",G),$.error("Kunne ikke opdatere opfølgning")}},se=v.filter(g=>{const G=_.toLowerCase();return g.phone.toLowerCase().includes(G)||g.name&&g.name.toLowerCase().includes(G)}),le=g=>{const G=Math.floor(g/60),te=g%60;return`${G}:${te.toString().padStart(2,"0")}`};return y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(He,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Kundedatabase"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Administrer dine kunder og opfølgninger"})]})]}),e.jsxs(F,{variant:"secondary",className:"text-lg px-4 py-2",children:[v.length," kunder"]})]}),e.jsxs("div",{className:"grid lg:grid-cols-3 gap-6",children:[e.jsxs(w,{className:"lg:col-span-1",children:[e.jsxs(W,{className:"pb-2",children:[e.jsx(q,{className:"text-lg",children:"Kunder"}),e.jsxs("div",{className:"relative mt-2",children:[e.jsx(Qs,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{placeholder:"Søg på navn eller telefon...",value:_,onChange:g=>p(g.target.value),className:"pl-9"})]})]}),e.jsx(k,{className:"p-0",children:e.jsx(Oe,{className:"h-[500px]",children:se.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground px-4",children:[e.jsx(He,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:"Ingen kunder fundet"})]}):e.jsx("div",{className:"divide-y",children:se.map(g=>e.jsx("button",{onClick:()=>u(g),className:`w-full p-4 text-left hover:bg-muted/50 transition-colors ${h?.phone===g.phone?"bg-muted":""}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Me,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:g.name||"Ukendt"}),e.jsx("p",{className:"text-sm text-muted-foreground font-mono",children:g.phone})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs(F,{variant:"outline",className:"mb-1",children:[g.callCount," opkald"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Pe(new Date(g.lastCall),"d. MMM",{locale:Ie})})]})]})},g.phone))})})})]}),e.jsx(w,{className:"lg:col-span-2",children:h?i?e.jsx(k,{className:"flex items-center justify-center h-[500px]",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):r?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"border-b",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 roun
3ded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Me,{className:"w-7 h-7 text-primary"})}),e.jsxs("div",{children:[e.jsx(q,{children:r.name||"Ukendt kunde"}),e.jsx(ee,{className:"font-mono",children:r.phone})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>b(!0),children:[e.jsx(ms,{className:"w-4 h-4 mr-1"}),"Note"]}),e.jsxs(D,{size:"sm",onClick:()=>S(!0),children:[e.jsx(ut,{className:"w-4 h-4 mr-1"}),"Opfølgning"]})]})]})}),e.jsx(k,{className:"p-0",children:e.jsxs(Ts,{defaultValue:"calls",className:"w-full",children:[e.jsxs(Os,{className:"w-full justify-start rounded-none border-b h-auto p-0",children:[e.jsxs(oe,{value:"calls",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary",children:[e.jsx(we,{className:"w-4 h-4 mr-1"}),"Opkald (",r.calls.length,")"]}),e.jsxs(oe,{value:"bookings",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary",children:[e.jsx(de,{className:"w-4 h-4 mr-1"}),"Bookinger (",r.bookings.length,")"]}),e.jsxs(oe,{value:"followups",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary",children:[e.jsx(ut,{className:"w-4 h-4 mr-1"}),"Opfølgninger (",r.followUps.length,")"]}),e.jsxs(oe,{value:"notes",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary",children:[e.jsx(Ae,{className:"w-4 h-4 mr-1"}),"Noter"]})]}),e.jsx(me,{value:"calls",className:"p-4 m-0",children:e.jsx(Oe,{className:"h-[350px]",children:r.calls.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"Ingen opkald"}):e.jsx("div",{className:"space-y-3",children:r.calls.map(g=>e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm",children:Pe(new Date(g.created_at),"d. MMMM yyyy HH:mm",{locale:Ie})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:g.status==="completed"?"default":"secondary",children:g.status==="completed"?"Gennemført":g.status}),g.duration&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx(he,{className:"w-3 h-3 inline mr-1"}),le(g.duration)]})]})]}),g.topics.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:g.topics.map((G,te)=>e.jsxs(F,{variant:"outline",className:`text-xs ${G.is_answered?"border-green-300 text-green-700":"border-red-300 text-red-700"}`,children:[G.is_answered?e.jsx(Q,{className:"w-3 h-3 mr-1"}):e.jsx(_e,{className:"w-3 h-3 mr-1"}),G.topic_category]},te))})]},g.id))})})}),e.jsx(me,{value:"bookings",className:"p-4 m-0",children:e.jsx(Oe,{className:"h-[350px]",children:r.bookings.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"Ingen bookinger"}):e.jsx("div",{className:"space-y-3",children:r.bookings.map(g=>e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[Pe(new Date(g.booking_date),"d. MMMM yyyy",{locale:Ie}),g.booking_time&&` kl. ${g.booking_time}`]}),g.service_type&&e.jsx("p",{className:"text-sm text-muted-foreground",children:g.service_type})]}),e.jsx(F,{variant:g.status==="completed"?"default":"secondary",children:g.status==="scheduled"?"Planlagt":g.status==="confirmed"?"Bekræftet":g.status==="completed"?"Gennemført":g.status==="cancelled"?"Aflyst":g.status})]},g.id))})})}),e.jsx(me,{value:"followups",className:"p-4 m-0",children:e.jsx(Oe,{className:"h-[350px]",children:r.followUps.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Ingen opfølgninger"}),e.jsxs(D,{size:"sm",onClick:()=>S(!0),children:[e.jsx(Ee,{className:"w-4 h-4 mr-1"}),"Opret opfølgning"]})]}):e.jsx("div",{className:"space-y-3",children:r.followUps.map(g=>e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"font-medium",children:[Pe(new Date(g.follow_up_date),"d. MMMM yyyy",{locale:Ie}),g.follow_up_time&&` kl. ${g.follow_up_time}`]}),e.jsx(F,{variant:g.status==="completed"?"default":g.status==="pending"?"secondary":"destructive",children:g.status==="pending"?"Afventer":g.status==="completed"?"Gennemført":"Annulleret"})]}),g.reason&&e.jsx("p",{className:"text-sm mb-2",children:g.reason}),g.notes&&e.jsx("p",{className:"text-sm text-muted-foreground",children:g.notes}),g.status==="pending"&&e.jsxs(D,{size:"sm",variant:"outline",className:"mt-2",onClick:()=>z(g.id),children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"Marker som gennemført"]})]},g.id))})})}),e.jsx(me,{value:"notes",className:"p-4 m-0",children:e.jsxs("div",{className:"space-y-4",children:[r.notes?e.jsx("div",{className:"p-4 rounded-lg bg-muted/50",children:e.jsx("p",{className:"whitespace-pre-wrap",children:r.notes})}):e.jsx("p",{className:"text-muted-foreground text-center py-4",children:"Ingen noter endnu"}),e.jsxs(D,{variant:"outline",onClick:()=>b(!0),children:[e.jsx(ms,{className:"w-4 h-4 mr-1"}),r.notes?"Rediger note":"Tilføj note"]})]})})]})})]}):null:e.jsxs(k,{className:"flex flex-col items-center justify-center h-[500px] text-muted-foreground",children:[e.jsx(Me,{className:"w-16 h-16 mb-4 opacity-30"}
3),e.jsx("p",{children:"Vælg en kunde for at se detaljer"})]})})]}),e.jsx(ls,{open:B,onOpenChange:b,children:e.jsxs(is,{children:[e.jsxs(cs,{children:[e.jsx(ds,{children:"Kundenoter"}),e.jsx(os,{children:"Tilføj noter om denne kunde"})]}),e.jsx(Ze,{placeholder:"Skriv noter her...",value:j,onChange:g=>a(g.target.value),rows:5}),e.jsxs(Js,{children:[e.jsx(D,{variant:"outline",onClick:()=>b(!1),children:"Annuller"}),e.jsxs(D,{onClick:A,disabled:N,children:[N&&e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}),"Gem"]})]})]})}),e.jsx(ls,{open:I,onOpenChange:S,children:e.jsxs(is,{children:[e.jsxs(cs,{children:[e.jsx(ds,{children:"Opret opfølgning"}),e.jsx(os,{children:"Planlæg en opfølgning for denne kunde"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Dato *"}),e.jsx(X,{type:"date",value:O.date,onChange:g=>f(G=>({...G,date:g.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Tidspunkt"}),e.jsx(X,{type:"time",value:O.time,onChange:g=>f(G=>({...G,time:g.target.value}))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Årsag"}),e.jsx(X,{placeholder:"F.eks. Opfølgning på tilbud",value:O.reason,onChange:g=>f(G=>({...G,reason:g.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Noter"}),e.jsx(Ze,{placeholder:"Yderligere noter...",value:O.notes,onChange:g=>f(G=>({...G,notes:g.target.value})),rows:3})]})]}),e.jsxs(Js,{children:[e.jsx(D,{variant:"outline",onClick:()=>S(!1),children:"Annuller"}),e.jsxs(D,{onClick:P,disabled:N||!O.date,children:[N&&e.jsx(V,{className:"w-4 h-4 mr-2 animate-spin"}),"Opret"]})]})]})})]})}const Tt="Hvad skal vi optimere?";function Va({portalToken:x,agentName:y}){const[E,v]=s.useState(!1),[d,_]=s.useState([]),[p,h]=s.useState(""),[T,r]=s.useState(!1),[m,i]=s.useState(null),[t,I]=s.useState(null),S=s.useRef(null),B=s.useRef(null);s.useEffect(()=>{E&&B.current&&B.current.focus()},[E]),s.useEffect(()=>{S.current&&(S.current.scrollTop=S.current.scrollHeight)},[d,T]);const b=(c,n)=>{navigator.clipboard.writeText(c),I(n),$.success("Kopieret!"),setTimeout(()=>I(null),2e3)},O=async(c,n)=>{const C=c||p.trim();if(!(!C&&!n||T)){C&&(_(u=>[...u,{role:"user",content:C}]),h("")),r(!0);try{const A=await(await fetch("/api/fn/portal-ai-chat",{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({message:C||void 0,conversationHistory:d.slice(-10),confirmAction:n||void 0})})).json();A.error?_(P=>[...P,{role:"assistant",content:`⚠️ ${A.error}`}]):(_(P=>[...P,{role:"assistant",content:A.message||"OK"}]),A.pending_action?i(A.pending_action):i(null))}catch{_(A=>[...A,{role:"assistant",content:"⚠️ Forbindelsesfejl. Prøv igen."}])}finally{r(!1)}}},f=async()=>{m&&(_(c=>[...c,{role:"user",content:"✅ Ja, gem det!"}]),await O(void 0,m),i(null))},j=()=>{i(null),_(c=>[...c,{role:"user",content:"❌ Nej, annuller."}]),_(c=>[...c,{role:"assistant",content:"OK, handlingen er annulleret. Hvad vil du ellers?"}])},a=c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),O())},N=c=>{c.style.height="auto",c.style.height=Math.min(c.scrollHeight,120)+"px"};return e.jsxs(e.Fragment,{children:[E&&e.jsxs("div",{className:"fixed z-50 w-[400px] max-w-[calc(100vw-2rem)] rounded-2xl border border-border bg-card shadow-2xl flex flex-col overflow-hidden right-4 bottom-[5.5rem] lg:bottom-20",style:{height:"520px",maxHeight:"calc(100dvh - 140px)"},children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 bg-gradient-to-r from-primary to-primary/80 text-primary-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"h-8 w-8 rounded-lg bg-primary-foreground/20 flex items-center justify-center",children:e.jsx(Ve,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm leading-tight",children:"AI Assistent"}),y&&e.jsx("p",{className:"text-[11px] opacity-80",children:y})]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-primary-foreground hover:bg-primary-foreground
3/20 rounded-lg",onClick:()=>v(!1),children:e.jsx(ye,{className:"h-4 w-4"})})]}),e.jsxs("div",{ref:S,className:"flex-1 overflow-y-auto px-4 py-4 space-y-4 scroll-smooth",children:[d.length===0&&e.jsxs("div",{className:"text-center py-6 space-y-4",children:[e.jsx("div",{className:"h-12 w-12 mx-auto rounded-2xl bg-primary/10 flex items-center justify-center",children:e.jsx(Ve,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-foreground",children:"Hej! 👋"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 max-w-[280px] mx-auto",children:"Jeg kan hjælpe dig med videnbase, medarbejdere, og alt omkring din agent."})]}),e.jsx("div",{className:"pt-2",children:e.jsx(D,{variant:"outline",size:"sm",onClick:()=>O(Tt),children:Tt})})]}),d.map((c,n)=>e.jsx("div",{className:`flex ${c.role==="user"?"justify-end":"justify-start"} group`,children:e.jsxs("div",{className:`relative max-w-[85%] rounded-2xl px-4 py-2.5 text-sm leading-relaxed ${c.role==="user"?"bg-primary text-primary-foreground rounded-br-md":"bg-muted text-foreground rounded-bl-md"}`,children:[c.role==="assistant"?e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none [&>p]:m-0 [&>p]:mb-1.5 [&>p:last-child]:mb-0 [&>ul]:mt-1 [&>ol]:mt-1 [&>ul]:mb-1 [&>ol]:mb-1",children:e.jsx(At,{children:c.content})}):c.content,c.role==="assistant"&&c.content.length>20&&e.jsx("button",{onClick:()=>b(c.content,n),className:"absolute -bottom-6 right-0 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground p-1",children:t===n?e.jsx(Ue,{className:"h-3 w-3"}):e.jsx(Pt,{className:"h-3 w-3"})})]})},n)),T&&e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"bg-muted rounded-2xl rounded-bl-md px-4 py-3 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-2 h-2 bg-muted-foreground/40 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})})]}),m&&!T&&e.jsxs("div",{className:"border-t border-border px-4 py-3 bg-muted/30 flex items-center gap-2",children:[e.jsxs(D,{size:"sm",onClick:f,className:"flex-1 gap-1.5 rounded-xl",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Godkend & Gem"]}),e.jsxs(D,{size:"sm",variant:"outline",onClick:j,className:"flex-1 gap-1.5 rounded-xl",children:[e.jsx(ye,{className:"h-3.5 w-3.5"}),"Afvis"]})]}),e.jsx("div",{className:"border-t border-border p-3 bg-card",children:e.jsxs("div",{className:"flex items-end gap-2 bg-muted/50 rounded-xl border border-border focus-within:border-primary/50 focus-within:ring-1 focus-within:ring-primary/20 transition-all px-3 py-2",children:[e.jsx("textarea",{ref:B,value:p,onChange:c=>{h(c.target.value),N(c.target)},onKeyDown:a,placeholder:"Skriv din besked...",className:"flex-1 bg-transparent text-sm resize-none outline-none placeholder:text-muted-foreground/60 min-h-[24px] max-h-[120px] leading-6",rows:1,disabled:T}),e.jsx(D,{size:"icon",onClick:()=>O(),disabled:T||!p.trim(),className:"h-8 w-8 rounded-lg shrink-0",children:e.jsx(hs,{className:"h-3.5 w-3.5"})})]})})]}),e.jsx("button",{onClick:()=>v(!E),className:"fixed right-4 z-50 h-14 w-14 rounded-full bg-primary text-primary-foreground shadow-lg shadow-primary/25 hover:shadow-xl hover:shadow-primary/30 hover:scale-105 active:scale-95 transition-all flex items-center justify-center bottom-[4.5rem] lg:bottom-4","aria-label":"Åbn AI chat",children:E?e.jsx(ye,{className:"h-6 w-6"}):e.jsx(Na,{className:"h-6 w-6"})})]})}function Ha(){const[x,y]=s.useState(null),[E,v]=s.useState(!1),[d,_]=s.useState(!1);s.useEffect(()=>{if(localStorage.getItem("portal-pwa-dismissed")||window.matchMedia("(display-mode: standalone)").matches)return;const T=r=>{r.preventDefault(),y(r),setTimeout(()=>v(!0),2e3)};return window.addEventListener("beforeinstallprompt",T),()=>window.removeEventListener("beforeinstallprompt",T)},[]);const p=s.useCallback(async()=>
3{if(!x)return;await x.prompt();const{outcome:T}=await x.userChoice;T==="accepted"&&v(!1),y(null)},[x]),h=()=>{v(!1),_(!0),localStorage.setItem("portal-pwa-dismissed","true")};return!E||d||!x?null:e.jsxs("div",{className:Vt("fixed bottom-4 left-4 right-4 z-50 md:left-auto md:right-4 md:max-w-sm","bg-card border border-border rounded-xl shadow-xl p-4","animate-in slide-in-from-bottom-4 fade-in duration-300"),children:[e.jsx("button",{onClick:h,className:"absolute top-3 right-3 text-muted-foreground hover:text-foreground",children:e.jsx(ye,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(va,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm",children:"Installer portalen"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Få hurtig adgang fra din hjemmeskærm"}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs(D,{onClick:p,size:"sm",className:"gap-1.5 h-8 text-xs",children:[e.jsx(ba,{className:"h-3.5 w-3.5"}),"Installer"]}),e.jsx(D,{onClick:h,variant:"ghost",size:"sm",className:"h-8 text-xs",children:"Ikke nu"})]})]})]})]})}function Za({token:x}){const[y,E]=s.useState([]),[v,d]=s.useState(!1),[_,p]=s.useState(!0),[h,T]=s.useState(null),[r,m]=s.useState(null),[i,t]=s.useState(!1),[I,S]=s.useState({terms:!1,privacy:!1,delete:!1}),[B,b]=s.useState(!1),[O,f]=s.useState(null),[j,a]=s.useState(""),[N,c]=s.useState(!1),[n,C]=s.useState(!1);s.useEffect(()=>{z(),A()},[]);const u=async(o,Z={})=>(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:o,...Z})})).json(),A=async()=>{try{const o=await u("get_notification_settings");o.success&&(a(o.notification_email||""),c(!!o.notify_on_call))}catch(o){console.error("Error loading notification settings:",o)}},P=async()=>{C(!0);try{const o=await u("save_notification_settings",{notification_email:j,notify_on_call:N});o.success?$.success("Notifikationer gemt"):$.error(o.error||"Kunne ikke gemme")}catch{$.error("Kunne ikke gemme notifikationer")}finally{C(!1)}},z=async()=>{try{const o=await u("get_conversations");o.conversations&&E(o.conversations),d(o.notes_enabled??!1)}catch(o){console.error("Error loading conversations:",o)}finally{p(!1)}},se=async()=>{if(!r){t(!0);try{const o=await u("get_conversation_analytics");o.success&&m(o)}catch(o){console.error("Error loading analytics:",o)}finally{t(!1)}}},le=async()=>{b(!0);try{(await u("enable_recording_consent",{consent_given:!0,consent_timestamp:new Date().toISOString()})).success&&(d(!0),$.success("Optagelse aktiveret",{description:"GDPR-samtykke registreret."}),S({terms:!1,privacy:!1,delete:!1}),z())}catch{$.error("Kunne ikke aktivere optagelse")}finally{b(!1)}},g=async o=>{f(o);try{(await u("delete_my_recording_data",{callId:o})).success&&(E(ue=>ue.map(Se=>Se.id===o?{...Se,transcript:null,call_notes:null,call_summary:null,sentiment_score:null}:Se)),$.success("Data slettet",{description:"Optagelsesdata er permanent slettet."}))}catch{$.error("Kunne ikke slette data")}finally{f(null)}},G=async()=>{try{(await u("disable_recording_delete_all")).success&&(d(!1),E([]),$.success("Optagelse deaktiveret",{description:"Alle optagelsesdata er slettet."}))}catch{$.error("Kunne ikke deaktivere optagelse")}},te=o=>{if(!o)return"-";const Z=Math.floor(o/60),ue=o%60;return`${Z}:${ue.toString().padStart(2,"0")}`},ce=o=>new Date(o).toLocaleDateString("da-DK",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),Y=o=>{switch(o){case"completed":return e.jsxs(F,{variant:"outline",className:"bg-emerald-500/10 text-emerald-600 border-emerald-500/30",children:[e.jsx(Q,{className:"w-3 h-3 mr-1"}),"Gennemført"]});case"failed":return e.jsxs(F,{variant:"outline",className:"bg-destructive/10 text-destructive border-destructive/30",children:[e.jsx(_e,{className:"w-3 h-3 mr-1"}),"Fejlet"]});default:return e.jsx(F,{variant:"outline",children:o})}},xe=o=>o===null?"text-muted-foreground":o>=.7?"text-emerald-500":o>=.4?"text-amber-500":"text-destructive",re=I.terms&&I.privacy&&I.delete;return _?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Samtaler"}),e.jsx("p",{className:"text-muted-foreground",children:"Opkaldsnoter, transskriberinger og optimering"})]}),v&&e.jsxs(gt,{children:[e.jsx(pt,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"text-destructive border-destructive/30 hover:bg-destructive/10",children:[e.jsx(Fs,{className:"w-4 h-4 mr-2"}),"Deaktivér optagelse"]})}),e.jsxs(jt,{children:[e.jsxs(ft,{children:[e.jsx(Nt,{children:"Deaktivér optagelse?"}),e.jsx(vt,{children:"Dette vil permanent slette ALLE optagelsesdata inkl. noter, transskriptioner og opsummeringer. Denne handling kan ikke fortrydes."})]}),e.jsxs(bt,{children:[e.jsx(yt,{children:"Annullér"}),e.jsx(kt,{onClick:G,className:"bg-destructive hover:bg-destructive/90",children:"Slet alt og deaktivér"})]})]})]})]}),e.jsxs(Ts,{defaultValue:v?"conversations":"recording",onValueChange:o=>{o==="analytics"&&se()},children:[e.jsxs(Os,{className:"grid w-full grid-cols-3",children:[e.jsxs(oe,{value:"conversations",children:[e.jsx(ke,{className:"w-4 h-4 mr-2"}),"Samtaler"]}),e.jsxs(oe,{value:"analytics",onClick:se,children:[e.jsx(Ge,{className:"w-4 h-4 mr-2"}),"Optimering"]}),e.jsxs(oe,{value:"recording",children:[e.jsx(Fs,{className:"w-4 h-4 mr-2"}),"Optagelse"]})]}),e.jsxs(me,{value:"conversations",className:"space-y-3 mt-4",children:[!v&&e.jsx(w,{className:"border-amber-500/30 bg-amber-500/5",children:e.jsxs(k,{className:"pt-4 pb-4 flex items-start gap-3 text-sm",children:[e.jsx(xs,{className:"w-5 h-5 text-amber-600 shrink-0 mt-0.5"}),e.jsx("p",{className:"text-muted-foreground",children:"Opkaldsnumre vises her til tilbagekald. Aktivér «Optagelse» for at se beskeder og fulde samtaler (GDPR-samtykke)."})]})}),y.length===0?e.jsx(w,{children:e.jsxs(k,{className:"pt-8 pb-8 text-center",children:[e.jsx(ke,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Ingen samtaler endnu"}),e.jsx("p",{className:"text-muted-foreground",children:"Når der kommer opkald, vises nummeret her, så I kan ringe tilbage."})]})}):y.map(o=>e.jsx(Rt,{open:h===o.id,onOpenChange:Z=>T(Z?o.id:null),children:e.jsxs(w,{className:"overflow-hidden",children:[e.jsx(Bt,{className:"w-full text-left",children:e.jsxs(W,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(we,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(q,{className:"text-base",children:o.from_number||"Ukendt"}),e.jsxs(ee,{className:"text-xs",children:[ce(o.created_at)," · ",te(o.duration)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o.customer_intent&&e.jsx(F,{variant:"secondary",className:"text-xs",children:o.customer_intent}),Y(o.status),e.jsx(Xs,{className:`w-4 h-4 text-muted-foreground transition-transform ${h===o.id?"rotate-180":""}`})]})]}),o.call_summary&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2 line-clamp-2",children:o.call_summary})]})}),e.jsx(zt,{children:e.jsxs(k,{className:"pt-0 space-y-4",children:[!v&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aktivér opkaldsnoter under «Optagelse» for at se besked og transskription."}),v&&o.sentiment_score!==null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Stemning:"}),e.jsxs("span",{className:`text-sm font-semibold ${xe(o.sentiment_score)}`,children:[o.sentiment_score>=.7?"😊 Positiv":o.sentiment_score>=.4?"😐 Neutral":"😟 Negativ",e.jsxs("span",{className:"text-xs text-muted-foreground ml-1",children:["(",Math.round(o.sentiment_score*100),"%)"]})]})]}),v&&o.call_summary&&e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ae,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-semibold",children:"Opsummering"})]}),e.jsx("p",{className:"text-sm",children:o.call_summary})]}),v&&o.call_notes&&e.jsxs("div",{className:"p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ke,{className:"w-4 h-4 text-amber-600"}),e.jsx("span",{className:"text-sm font-semibold",children:"Noter / besked"}),e.jsxs(F,{variant:"outline",className:"text-xs ml-auto",children:[e.jsx(Fe,{className:"w-3 h-3 mr-1"}),"Kun synlig for dig"]})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:o.call_notes})]}),v&&o.transcript&&e.jsxs("div",{className:"p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(he,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-semibold",children:"Transskription"}),e.jsxs(F,{variant:"outline",className:"text-xs ml-auto",children:[e.jsx(Fe,{className:"w-3 h-3 mr-1"}),"Kun synlig for dig"]})]}),e.jsx(Oe,{className:"max-h-48",children:e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:o.transcript})})]}),v&&o.outcome&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:"Resultat:"}),e.jsx(F,{variant:"outline",children:o.outcome}),o.confidence_score&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",Math.round(o.confidence_score*100),"% sikkerhed)"]})]}),v&&(o.transcript||o.call_notes||o.call_summary)&&e.jsxs(gt,{children:[e.jsx(pt,{asChild:!0,children:e.jsxs(D,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:[e.jsx(qe,{className:"w-4 h-4 mr-2"}),"Slet mine optagelsesdata"]})}),e.jsxs(jt,{children:[e.jsxs(ft,{children:[e.jsx(Nt,{children:"Slet optagelsesdata?"}),e.jsx(vt,{children:"Dette sletter permanent alle noter, transskription og opsummering for dette opkald. Handlingen kan ikke fortrydes."})]}),e.jsxs(bt,{children:[e.jsx(yt,{children:"Annullér"}),e.jsxs(kt,{onClick:()=>g(o.id),className:"bg-destructive hover:bg-destructive/90",disabled:O===o.id,children:[O===o.id?e.jsx(V,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(qe,{className:"w-4 h-4 mr-2"}),"Slet permanent"]})]})]})]})]})})]})},o.id))]}
3),e.jsx(me,{value:"analytics",className:"space-y-4 mt-4",children:i?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):r?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsx(w,{children:e.jsxs(k,{className:"pt-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ze,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:"Vidensbase"})]}),e.jsx("div",{className:"text-2xl font-bold",children:r.source_breakdown.knowledge_base}),e.jsx(Qe,{value:r.source_breakdown.total>0?r.source_breakdown.knowledge_base/r.source_breakdown.total*100:0,className:"mt-2 h-1.5"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[r.source_breakdown.total>0?Math.round(r.source_breakdown.knowledge_base/r.source_breakdown.total*100):0,"% fra vidensbase"]})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ot,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-sm font-medium",children:"Emner besvaret"})]}),e.jsx("div",{className:"text-2xl font-bold",children:r.topic_stats.answered}),e.jsx(Qe,{value:r.topic_stats.total>0?r.topic_stats.answered/r.topic_stats.total*100:0,className:"mt-2 h-1.5"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["af ",r.topic_stats.total," totale emner"]})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-4 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ds,{className:"w-4 h-4 text-destructive"}),e.jsx("span",{className:"text-sm font-medium",children:"Ubesvarede"})]}),e.jsx("div",{className:"text-2xl font-bold",children:r.topic_stats.unanswered}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[r.knowledge_gaps.filter(o=>o.status==="open").length," åbne videnshuller"]})]})})]}),r.top_urls.length>0&&e.jsxs(w,{children:[e.jsxs(W,{className:"pb-3",children:[e.jsxs(q,{className:"text-base flex items-center gap-2",children:[e.jsx(ya,{className:"w-4 h-4 text-primary"}),"Mest brugte videnskilder"]}),e.jsx(ee,{children:"URLs og artikler som agenten oftest refererer til"})]}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:r.top_urls.map((o,Z)=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsx("span",{className:"text-sm truncate flex-1 mr-3",children:o.url}),e.jsxs(F,{variant:"secondary",className:"shrink-0",children:[o.count,"×"]})]},Z))})})]}),r.unanswered_questions.length>0&&e.jsxs(w,{children:[e.jsxs(W,{className:"pb-3",children:[e.jsxs(q,{className:"text-base flex items-center gap-2",children:[e.jsx(Ds,{className:"w-4 h-4 text-amber-500"}),"Spørgsmål agenten ikke kunne svare på"]}),e.jsx(ee,{children:"Tilføj viden for at forbedre disse svar"})]}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:r.unanswered_questions.map((o,Z)=>e.jsxs("div",{className:"flex items-start justify-between p-2 rounded-lg bg-amber-500/5 border border-amber-500/10",children:[e.jsx("span",{className:"text-sm flex-1 mr-3",children:o.question}),e.jsxs(F,{variant:"outline",className:"shrink-0 text-amber-600 border-amber-500/30",children:[o.count,"×"]})]},Z))})})]}),r.knowledge_gaps.length>0&&e.jsxs(w,{children:[e.jsxs(W,{className:"pb-3",children:[e.jsxs(q,{className:"text-base flex items-center gap-2",children:[e.jsx(ns,{className:"w-4 h-4 text-primary"}),"Videnshuller - Optimeringsforslag"]}),e.jsx(ee,{children:"Disse emner mangler i videnbasen og bør tilføjes"})]}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:r.knowledge_gaps.map((o,Z)=>e.jsxs("div",{className:"flex items-start justify-between p-3 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"flex-1 mr-3",children:[e.jsx("p",{className:"text-sm font-medium",children:o.text}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Set ",o.frequency,"× · Sidst: ",ce(o.last_seen)]})]}),e.jsx(F,{variant:o.status==="open"?"destructive":"secondary",className:"shrink-0",children:o.status==="open"?"Åben":o.status==="addressed"?"Løst":o.status})]},Z))})})]}),r.top_urls.length===0&&r.unanswered_questions.length===0&&r.knowledge_gaps.length===0&&e.jsx(w,{children:e.jsxs(k,{className:"pt-8 pb-8 text-center",children:[e.jsx(Ge,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Ingen analysedata endnu"}),e.jsx("p",{className:"text-muted-foreground max-w-md mx-auto",children:"Analysedata vises her efterhånden som agenten håndterer opkald og samtaler."})]})})]}):e.jsx(w,{children:e.jsxs(k,{className:"pt-8 pb-8 text-center",children:[e.jsx(Ge,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Indlæser analysedata..."})]})})}
3),e.jsxs(me,{value:"recording",className:"space-y-4 mt-4",children:[e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"w-5 h-5 text-primary"}),"Optagelsesfunktion & GDPR"]}),e.jsx(ee,{children:"Aktivér optagelse af opkald for at fÃ¥ noter, transskriptioner og opsummeringer."})]}),e.jsx(k,{className:"space-y-6",children:v?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-emerald-500/10 border border-emerald-500/20 rounded-lg",children:[e.jsx(Q,{className:"w-6 h-6 text-emerald-500 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-emerald-600",children:"Optagelse er aktiveret"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Opkald optages, transskriberes og opsummeres automatisk. Kun du kan se dine optagelser og noter."})]})]}),e.jsxs("div",{className:"p-4 bg-muted/30 rounded-lg space-y-3",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"Dine rettigheder"}),e.jsxs("ul",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-500 shrink-0 mt-0.5"}),"Du kan slette enkelte optagelser nÃ¥r som helst"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-500 shrink-0 mt-0.5"}),"Du kan deaktivere optagelse og slette alle data"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-500 shrink-0 mt-0.5"}),"Kun du har adgang til noter og transskriptioner"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Q,{className:"w-4 h-4 text-emerald-500 shrink-0 mt-0.5"}),"Data opbevares i max 14 dage jf. GDPR"]})]})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"p-4 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(xs,{className:"w-5 h-5 text-amber-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"Før du aktiverer"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Ved at aktivere optagelse accepterer du, at opkald optages og transskriberes. En GDPR-disclaimer vil automatisk blive afspillet i starten af hvert opkald."})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-semibold text-sm",children:"Bekræft samtykke"}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ws,{id:"terms",checked:I.terms,onCheckedChange:o=>S(Z=>({...Z,terms:!!o}))}),e.jsxs("label",{htmlFor:"terms",className:"text-sm cursor-pointer",children:["Jeg accepterer ",e.jsx("a",{href:"/vilkaar",target:"_blank",className:"text-primary underline",children:"vilkÃ¥r og betingelser"})," for optagelsesfunktionen"]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ws,{id:"privacy",checked:I.privacy,onCheckedChange:o=>S(Z=>({...Z,privacy:!!o}))}),e.jsxs("label",{htmlFor:"privacy",className:"text-sm cursor-pointer",children:["Jeg accepterer ",e.jsx("a",{href:"/privatlivspolitik",target:"_blank",className:"text-primary underline",children:"privatlivspolitikken"})," og GDPR-reglerne for behandling af opkaldsdata"]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ws,{id:"delete",checked:I.delete,onCheckedChange:o=>S(Z=>({...Z,delete:!!o}))}),e.jsx("label",{htmlFor:"delete",className:"text-sm cursor-pointer",children:"Jeg forstÃ¥r, at jeg selv er ansvarlig for at slette optagelsesdata, og at kun jeg har adgang til mine noter og optagelser"})]})]}),e.jsxs(D,{onClick:le,disabled:!re||B,className:"w-full",children:[B?e.jsx(V,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(Fs,{className:"w-4 h-4 mr-2"}),"Aktivér optagelse"]})]})})]}),e.jsxs(w,{children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"w-5 h-5 text-primary"}),"Email ved opkald / besked"]}),e.jsx(ee,{children:"FÃ¥ besked pÃ¥ mail nÃ¥r der er nye opkald — styres kun her i kundeportalen. (Push/SMS til jer sendes ikke automatisk pÃ¥ live Telnyx i dag.)"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"notify-email",children:"Email"}),e.jsx(X,{id:"notify-email",type:"email",value:j,onChange:o=>a(o.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Notificer ved opkald"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"NÃ¥r indstillingen understøttes af pipeline"})]}),e.jsx(ve,{checked:N,onCheckedChange:c})]}),e.jsxs(D,{onClick:P,disabled:n,children:[n?e.jsx(V,{className:"w-4 h-4 animate-spin mr-2"}):null,"Gem notifikationer"]}
3)]})]})]})]})]})}function Wa({token:x}){const[y,E]=s.useState([]),[v,d]=s.useState(0),[_,p]=s.useState(!0);s.useEffect(()=>{h()},[x]);const h=async()=>{try{const I=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"get_sms_log"})})).json();I.success&&(E(I.sms_log||[]),d(I.total_sent||0))}catch(t){console.error("Error loading SMS log:",t)}finally{p(!1)}},T={links:"Links",booking:"Booking",booking_confirmation:"Bekræftelse",booking_link:"Booking-link",info:"Information",info_link:"Info",price:"Priser",follow_up:"Opfølgning"};if(_)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"w-6 h-6 animate-spin text-muted-foreground"})});const r=y.filter(t=>t.status==="sent").length,m=y.filter(t=>t.link_clicked).length,i=r>0?Math.round(m/r*100):0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"SMS-oversigt"}),e.jsx("p",{className:"text-muted-foreground",children:"Se alle SMS'er sendt af din agent"})]}),e.jsxs(F,{variant:"secondary",className:"gap-1.5 text-sm px-3 py-1.5",children:[e.jsx(ke,{className:"w-4 h-4"}),v," sendt i alt"]})]}),y.length>0&&e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(w,{children:e.jsxs(k,{className:"pt-3 pb-2 text-center",children:[e.jsx(hs,{className:"h-4 w-4 mx-auto text-primary mb-1"}),e.jsx("p",{className:"text-xl font-bold",children:r}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Sendt"})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-3 pb-2 text-center",children:[e.jsx(wt,{className:"h-4 w-4 mx-auto text-primary mb-1"}),e.jsx("p",{className:"text-xl font-bold",children:m}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Klikket"})]})}),e.jsx(w,{children:e.jsxs(k,{className:"pt-3 pb-2 text-center",children:[e.jsx(Ge,{className:"h-4 w-4 mx-auto text-primary mb-1"}),e.jsxs("p",{className:"text-xl font-bold",children:[i,"%"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Klik-rate"})]})})]}),y.length===0?e.jsx(w,{children:e.jsxs(k,{className:"py-12 text-center",children:[e.jsx(ke,{className:"w-12 h-12 mx-auto text-muted-foreground/30 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"Ingen SMS'er sendt endnu"})]})}):e.jsx("div",{className:"space-y-3",children:y.map(t=>e.jsx(w,{children:e.jsx(k,{className:"py-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.status==="sent"?e.jsx(Q,{className:"w-4 h-4 text-green-500 shrink-0"}):e.jsx(_e,{className:"w-4 h-4 text-destructive shrink-0"}),e.jsx("span",{className:"font-medium text-sm",children:t.to_number}),t.purpose&&e.jsx(F,{variant:"outline",className:"text-xs",children:T[t.purpose]||t.purpose}),t.link_clicked&&e.jsxs(F,{variant:"default",className:"text-[10px] gap-1",children:[e.jsx(wt,{className:"h-3 w-3"})," Klikket"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-line line-clamp-3",children:t.message_content})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:new Date(t.created_at).toLocaleString("da-DK",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})})]})})},t.id))})]})}const qa=[{key:"call_history",title:"Opkaldshistorik",description:"Telefonnumre, tidspunkter og opkaldsstatus",legalText:`Ved at aktivere opkaldshistorik accepterer du, at du som virksomhed er dataansvarlig (jf. GDPR Art. 4, nr. 7) for alle personoplysninger der fremgår af opkaldsloggen.
4
5Du er ansvarlig for:
6• At have lovligt grundlag for behandling af opkaldsdata (GDPR Art. 6)
7• At informere dine kunder om registrering af opkaldsdata (GDPR Art. 13)
8• At imødekomme indsigtsanmodninger og sletningsanmodninger (GDPR Art. 15 & 17)
9• At opbevare data sikkert og kun så længe det er nødvendigt`},{key:"transcriptions",title:"Transskriptioner & Samtaler",description:"Personfølsomme oplysninger fra samtaler",legalText:`Ved at aktivere transskriptioner accepterer du, at du som virksomhed er dataansvarlig for alle transskriberede samtaler — herunder personoplysninger nævnt i samtalen.
10
11Du er ansvarlig for:
12• Opbevaring og rettidig sletning af transskriptioner (GDPR Art. 5, stk. 1, litra e)
13• At informere opkaldere om, at samtalen transskriberes (GDPR Art. 13)
14• At sikre, at kun autoriserede medarbejdere har adgang til transskriptioner`},{key:"recordings",title:"Optagelser",description:"Optagelse af samtaler kræver særskilt samtykke",legalText:`Ved at aktivere optagelser accepterer du, at du som virksomhed er dataansvarlig for ALLE optagede samtaler jf. GDPR Art. 4, nr. 7.
15
16KRITISK VIGTIGT:
17• Du SKAL informere opkaldere om, at samtalen optages (GDPR Art. 13, Teleloven §4)
18• Du SKAL have lovligt grundlag — enten samtykke eller legitim interesse (GDPR Art. 6)
19• Optagelser kan indeholde særlige kategorier af persondata (sundhedsdata, etc.)`},{key:"order_management",title:"Ordrestyring",description:"Kundeoplysninger som navne, adresser og betalingsdata",legalText:`Ved at bruge ordrestyring accepterer du, at du som virksomhed er dataansvarlig for alle kundeoplysninger i ordrer — herunder navne, adresser, telefonnumre, e-mailadresser og ordredetaljer.
20
21Du er ansvarlig for:
22• At have lovligt grundlag for behandling af kundedata i ordrer (GDPR Art. 6)
23• At informere kunder om, hvordan deres data behandles (GDPR Art. 13-14)`},{key:"staff_management",title:"Personalestyring",description:"Medarbejdernes personoplysninger",legalText:`Ved at bruge personalestyring accepterer du, at du som virksomhed er dataansvarlig for alle medarbejderoplysninger — herunder navne, e-mailadresser, telefonnumre, roller og tilgængelighed.
24
25Du er ansvarlig for:
26• At have lovligt grundlag for behandling af medarbejderdata (GDPR Art. 6)
27• At slette data, når en medarbejder fratræder`},{key:"sms_log",title:"SMS-log",description:"Personfølsomme kommunikationsdata",legalText:`Ved at tilgå SMS-loggen accepterer du, at du som virksomhed er dataansvarlig for alle SMS-data — herunder telefonnumre, beskedindhold og tidspunkter.
28
29Du er ansvarlig for:
30• At have lovligt grundlag for behandling af SMS-data (GDPR Art. 6)
31• At overholde sletningsfrister for kommunikationsdata`}];function Qa({token:x,agentId:y,userName:E,userEmail:v,featureKeys:d,onAccepted:_}){const[p,h]=s.useState(!1),[T,r]=s.useState(""),[m,i]=s.useState(!1),[t,I]=s.useState(null),S=qa.filter(O=>d.includes(O.key)),B=p&&T.trim().length>=2,b=async()=>
31{if(B){i(!0);try{const O=await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":x},body:JSON.stringify({action:"save_all_feature_consents",feature_keys:d,consent_version:"1.0",consented_by_name:T,consented_by_email:v})});if(!O.ok)throw new Error("Server error");const f=await O.json();if(f.error)throw new Error(f.error);$.success("Vilkår accepteret",{description:"Alle funktioner er nu aktiveret."}),_()}catch(O){console.error("Consent error:",O),$.error("Kunne ikke gemme samtykke. Prøv igen.")}finally{i(!1)}}};return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/20 flex items-center justify-center p-4",children:e.jsx("div",{className:"w-full max-w-2xl",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl shadow-2xl overflow-hidden",children:[e.jsx("div",{className:"bg-gradient-to-r from-primary/10 to-primary/5 p-6 border-b border-border",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-14 w-14 rounded-2xl bg-primary/10 flex items-center justify-center",children:e.jsx(Fe,{className:"w-7 h-7 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-foreground",children:"Velkommen til din kundeportal"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Før du starter, skal du acceptere vilkårene for de funktioner, der er tilgængelige i din portal."})]})]})}),e.jsx(Oe,{className:"max-h-[60vh]",children:e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx("div",{className:"p-4 bg-primary/5 rounded-xl border border-primary/10",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Hs,{className:"w-5 h-5 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-sm text-foreground",children:[e.jsx("p",{className:"font-semibold mb-1",children:"Dine data er beskyttet"}),e.jsx("p",{className:"text-muted-foreground",children:"Hverken AgentoAI, admin eller din partner har adgang til at se dine optagelser, transskriptioner, ordrer eller medarbejderdata. Kun du og dine autoriserede portalbrugere kan tilgå disse oplysninger."})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-sm font-semibold text-foreground",children:["Funktioner der aktiveres (",S.length,")"]}),S.map(O=>e.jsx(Rt,{open:t===O.key,onOpenChange:f=>I(f?O.key:null),children:e.jsxs("div",{className:"border border-border rounded-xl overflow-hidden",children:[e.jsxs(Bt,{className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:O.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:O.description})]}),e.jsx(Xs,{className:`w-4 h-4 text-muted-foreground transition-transform ${t===O.key?"rotate-180":""}`})]}),e.jsx(zt,{children:e.jsx("div",{className:"px-4 pb-4 border-t border-border",children:e.jsx("p",{className:"text-xs text-muted-foreground whitespace-pre-line leading-relaxed mt-3",children:O.legalText})})})]})},O.key))]}),e.jsxs("a",{href:`/portal-datapolitik?token=${x}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-sm text-primary hover:underline",children:[e.jsx(We,{className:"w-4 h-4"}),"Læs den fulde databehandlingsaftale"]}),e.jsxs("div",{className:"space-y-4 pt-2 border-t border-border",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ws,{checked:p,onCheckedChange:O=>h(!!O),id:"consent-all"}),e.jsx(L,{htmlFor:"consent-all",className:"text-sm leading-relaxed cursor-pointer",children:"Jeg forstår og accepterer, at min virksomhed er dataansvarlig for alle personoplysninger i kundeportalen. Jeg bekræfter, at vi har lovligt grundlag for behandling af data, og at platformen IKKE har adgang til vores data."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"consent-name",className:"text-sm font-medium",children:"Bekræft med dit fulde navn"}),e.jsx(X,{id:"consent-name",placeholder:"Dit fulde navn",value:T,onChange:O=>r(O.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ved at skrive dit navn bekræfter du vilkårene på vegne af din virksomhed."})]})]})]})}),e.jsx("div",{className:"p-6 border-t border-border bg-muted/20",children:e.jsxs(D,{onClick:b,disabled:!B||m,className:"w-full gap-2 h-12 text-base",size:"lg",children:[m&&e.jsx(V,{className:"w-5 h-5 animate-spin"}),e.jsx(Fe,{className:"w-5 h-5"}),"Jeg accepterer alle vilkår og aktiverer portalen"]})})]})})})}function Ya({token:x,onThemeChange:y,onLanguageChange:E}
31){const v=`portal-settings-${x}`,[d,_]=s.useState("dark"),[p,h]=s.useState("da");s.useEffect(()=>{try{const m=localStorage.getItem(v);if(m){const i=JSON.parse(m);i.theme&&_(i.theme),i.language&&h(i.language)}}catch{}},[v]);const T=(m,i)=>{const t=m||d,I=i||p;localStorage.setItem(v,JSON.stringify({theme:t,language:I})),m&&(_(t),y?.(t)),i&&(h(I),E?.(I)),$.success("Indstillinger gemt")},r=[{value:"dark",label:"Mørk",icon:_t},{value:"light",label:"Lys",icon:wa},{value:"auto",label:"Auto",icon:_a}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/20",children:e.jsx(ka,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"Indstillinger"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Tilpas din portaloplevelse"})]})]}),e.jsxs(w,{className:"border-0 shadow-lg",children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(_t,{className:"w-5 h-5 text-primary"}),"Tema"]}),e.jsx(ee,{children:"Vælg hvordan portalen skal se ud"})]}),e.jsx(k,{children:e.jsx("div",{className:"grid grid-cols-3 gap-3",children:r.map(m=>{const i=m.icon,t=d===m.value;return e.jsxs("button",{onClick:()=>T(m.value),className:`flex flex-col items-center gap-2 p-4 rounded-xl border-2 transition-all ${t?"border-primary bg-primary/5":"border-border hover:border-primary/30"}`,children:[e.jsx(i,{className:`w-6 h-6 ${t?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:`text-sm font-medium ${t?"text-foreground":"text-muted-foreground"}`,children:m.label})]},m.value)})})})]}),e.jsxs(w,{className:"border-0 shadow-lg",children:[e.jsxs(W,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"w-5 h-5 text-primary"}),"Sprog"]}),e.jsx(ee,{children:"Vælg portalens sprog"})]}),e.jsx(k,{children:e.jsxs(pe,{value:p,onValueChange:m=>T(void 0,m),children:[e.jsx(je,{className:"w-full",children:e.jsx(fe,{})}),e.jsxs(Ne,{children:[e.jsx(H,{value:"da",children:"🇩🇰 Dansk"}),e.jsx(H,{value:"en",children:"🇬🇧 English"}),e.jsx(H,{value:"de",children:"🇩🇪 Deutsch"})]})]})})]})]})}const Xa={basic:{icon:_s,label:"Basic",color:"text-amber-500",bg:"bg-amber-500/10"},standard:{icon:Ca,label:"Standard",color:"text-blue-500",bg:"bg-blue-500/10"},enterprise:{icon:Sa,label:"Enterprise",color:"text-purple-500",bg:"bg-purple-500/10"}};function $n(){const[x]=Ht(),y=Zt(),{tab:E}=Wt(),{toast:v}=Ws(),d=x.get("token"),[_,p]=s.useState(!0),[h,T]=s.useState(null),[r,m]=s.useState(null),[i,t]=s.useState("knowledge"),[I,S]=s.useState([]),[B,b]=s.useState([]),[O,f]=s.useState([]),[j,a]=s.useState([]),[N,c]=s.useState([]),[n,C]=s.useState(!1),[u,A]=s.useState(!1),[P,z]=s.useState(null),[se,le]=s.useState([]),[g,G]=s.useState(!1);s.useEffect(()=>{if(!E)return;const M=E.toLowerCase(),ie={chat:"chat",knowledge:"knowledge",calls:"calls",conversations:"conversations",sms:"sms",analytics:"analytics",usage:"usage",orders:"orders",staff:"staff",integrations:"integrations",sales:"sales",calendar:"calendar",customers:"customers",legal:"legal",settings:"settings"}[M];ie&&t(ie)},[E]),s.useEffect(()=>{if(!d){p(!1),v({title:"Ugyldig adgang",description:"Intet adgangstoken fundet",variant:"destructive"});return}te()},[d]);const te=async()=>{try{const{data:M,error:U}=await Gs.functions.invoke("customer-portal-auth",{body:{action:"validate",token:d}});if(U||!M.success)throw new Error(M?.error||"Ugyldig adgang");T(M.access),await ce(M.access.agent.id)}catch(M){const U=M instanceof Error?M.message:"Kunne ikke validere adgang";v({title:"Adgang nægtet",description:U,variant:"destructive"})}finally{p(!1)}},ce=async M=>{try{const ie=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_config"})})).json(),be=ie.config||{tier:"basic",has_ai_chat:!1,has_call_history:!0,has_knowledge_edit:!1,has_analytics:!1,has_order_management:!1,has_staff_management:!1,has_recordings:!1,has_transcriptions:!1};m(be),ie.design&&z(ie.design),be.has_ai_chat&&!E&&t("chat");const ge=[];if(be.has_call_history&&ge.push("call_history"),be.has_transcriptions&&ge.push("transcriptions"),be.has_recordings&&ge.push("recordings"),be.has_order_management&&ge.push("order_management"),be.has_staff_management&&ge.push("staff_management"),ge.push("sms_log"),le(ge),ge.length>0)try{const As=((await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_feature_consents"})})).json()).consents||[]).filter(l=>!l.revoked_at).map(l=>l.feature_key),Ps=ge.some(l=>!As.includes(l));C(Ps)}catch{C(!0)}A(!0),await Y(be)}catch(U){console.error("Error loading portal config:",U)}},Y=async M=>{const U=[];U.push(re()),M.has_call_history&&U.push(xe()),M.has_order_management&&U.push(o()),M.has_staff_management&&U.push(Z()),U.push(ue()),await Promise.all(U)},xe=async()=>{try{const U=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_calls"})})).json();U.calls&&S(U.calls)}catch(M){console.error("Error loading calls:",M)}},re=async()=>{try{const U=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_knowledge"})})).json();U.knowledge&&b(U.knowledge)}catch(M){console.error("Error loading knowledge:",M)}},o=async()=>{try{const U=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_orders"})})).json();U.orders&&f(U.orders)}catch(M){console.error("Error loading orders:",M)}},Z=async()=>{try{const U=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_staff"})})).json();U.staff&&a(U.staff)}catch(M){console.error("Error loading staff:",M)}},ue=async()=>{try{const U=await(await fetch(`${R()}`,{method:"POST",headers:{"Content-Type":"application/json","x-portal-token":d},body:JSON.stringify({action:"get_sales_sessions"})})).json();U.sessions&&c(U.sessions)}catch(M){console.error("Error loading sales sessions:",M)}};if(_)return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto",children:e.jsx(V,{className:"w-8 h-8 animate-spin text-primary"})})}),e.jsx("p",{className:"text-muted-foreground",children:"Validerer adgang..."})]})});if(!h)return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-background via-background to-muted/30 flex items-center justify-center p-4",children:e.jsx(w,{className:"max-w-md w-full border-0 shadow-2xl",children:e.jsxs(k,{className:"pt-8 pb-8 text-center",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-destructive/10 flex items-center justify-center mx-auto mb-4",children:e.jsx("span",{className:"text-3xl",children:"🔒"})}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:"Adgang nægtet"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Dit adgangslink er ugyldigt eller udløbet."}),e.jsx(D,{onClick:()=>y("/"),className:"w-full",children:"Tilbage til forsiden"})]})})});
31if(u&&n&&h)return e.jsx(Qa,{token:d,agentId:h.agent.id,userName:h.name,userEmail:h.email,featureKeys:se,onAccepted:()=>C(!1)});const Se={};P?.background_color&&(Se.backgroundColor=P.background_color);const Ke=P?.company_name||h.agent.name,us=P?.logo_url,Ce=Xa[r?.tier||"basic"],gs=Ce.icon,$e=["chat","knowledge","calls","usage","analytics"],De=[{id:"chat",label:"AI Chat",icon:Ve,show:r?.has_ai_chat},{id:"usage",label:"Forbrug",icon:Ge,show:!0},{id:"knowledge",label:"Viden",icon:lt,show:!0},{id:"calls",label:"Opkald",icon:we,count:I.length,show:r?.has_call_history},{id:"conversations",label:"Samtaler",icon:ke,show:!0},{id:"sms",label:"SMS",icon:ke,show:!0},{id:"analytics",label:"Analytics",icon:ze,show:r?.has_analytics},{id:"calendar",label:"Kalender",icon:de,show:!0},{id:"customers",label:"Kunder",icon:He,show:!0},{id:"orders",label:"Ordrer",icon:as,count:O.length,show:r?.has_order_management},{id:"sales",label:"Salg",icon:zs,count:N.filter(M=>M.status==="purchased").length,show:!0},{id:"staff",label:"Personale",icon:He,count:j.length,show:r?.has_staff_management},{id:"integrations",label:"Integrationer",icon:Ss,show:!0},{id:"settings",label:"Indstillinger",icon:lt,show:!0},{id:"legal",label:"Juridisk",icon:Fe,show:!0}].filter(M=>M.show),Le=De.filter(M=>$e.includes(M.id)),Ye=De.filter(M=>!$e.includes(M.id));return e.jsxs("div",{className:"min-h-[100dvh] bg-gradient-to-br from-background via-background to-muted/20",style:Se,children:[e.jsx("header",{className:"sticky top-0 z-50 border-b bg-background/80 backdrop-blur-xl",children:e.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[us?e.jsx("img",{src:us,alt:Ke,className:"h-10 w-10 rounded-xl object-cover"}):e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary flex items-center justify-center",children:e.jsx("span",{className:"text-primary-foreground font-bold text-lg",children:Ke.charAt(0)})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:Ke}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Kundeportal"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(F,{variant:"outline",className:`gap-1.5 ${Ce.bg} border-0`,children:[e.jsx(gs,{className:`w-3 h-3 ${Ce.color}`}),e.jsx("span",{className:Ce.color,children:Ce.label})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 px-3 py-1.5 rounded-full bg-muted/50",children:[e.jsx(Me,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:h.name})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>{v({title:"Logget ud",description:"Du er nu logget ud af kundeportalen"}),y("/portal-login")},className:"gap-2",children:[e.jsx(qt,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Log ud"})]})]})]})})}),e.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6",children:e.jsxs("div",{className:"flex gap-6",children:[e.jsx("nav",{className:"hidden lg:flex flex-col w-64 shrink-0",children:e.jsx("div",{className:"sticky top-24 space-y-1",children:De.map(M=>{const U=M.icon,ie=i===M.id;return e.jsxs("button",{onClick:()=>t(M.id),className:`w-full flex items-center gap-3 px-4 py-3 rounded-xl text-left transition-all ${ie?"bg-primary text-primary-foreground shadow-lg shadow-primary/25":"hover:bg-muted text-muted-foreground hover:text-foreground"}`,children:[e.jsx(U,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium flex-1",children:M.label}),M.count!==void 0&&M.count>0&&e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${ie?"bg-primary-foreground/20 text-primary-foreground":"bg-muted-foreground/20"}`,children:M.count}),ie&&e.jsx(Us,{className:"w-4 h-4"})]},M.id)})})}),e.jsxs("div",{className:"lg:hidden fixed bottom-0 left-0 right-0 z-50",children:[g&&e.jsx("div",{className:"absolute bottom-full left-0 right-0 bg-background/95 backdrop-blur-xl border-t border-x rounded-t-2xl p-3 shadow-2xl",children:e.jsx("div",{className:"grid grid-cols-4 gap-2",children:Ye.map(M=>{const U=M.icon,ie=i===M.id;return e.jsxs("button",{onClick:()=>{t(M.id),G(!1)},className:`flex flex-col items-center gap-1.5 p-3 rounded-xl transition-all ${ie?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"}`,children:[e.jsx(U,{className:"w-5 h-5"}),e.jsx("span",{className:"text-[11px] font-medium leading-tight text-center",children:M.label})]},M.id)})})}),e.jsx("div",{className:"bg-background/95 backdrop-blur-xl border-t px-2 py-1.5 pb-[calc(0.375rem+env(safe-area-inset-bottom))]",children:e.jsxs("div",{className:"flex justify-around items-center",children:[Le.map(M=>{const U=M.icon,ie=i===M.id;return e.jsxs("button",{onClick:()=>{t(M.id),G(!1)},className:`flex flex-col items-center gap-0.5 py-1.5 px-3 rounded-xl transition-all min-w-[56px] ${ie?"text-primary":"text-muted-foreground"}`,children:[e.jsx(U,{className:"w-5 h-5"}),e.jsx("span",{className:"text-[10px] font-medium",children:M.label})]},M.id)}),Ye.length>0&&e.jsxs("button",{onClick:()=>G(M=>!M),className:`flex flex-col items-center gap-0.5 py-1.5 px-3 rounded-xl transition-all min-w-[56px] ${g?"text-primary":"text-muted-foreground"}`,children:[e.jsx(Da,{className:"w-5 h-5"}),e.jsx("span",{className:"text-[10px] font-medium",children:"Mere"})]})]})})]}),e.jsxs("main",{className:"flex-1 pb-24 lg:pb-0",children:[i==="chat"&&r?.has_ai_chat&&e.jsx("div",{className:"h-[calc(100vh-180px)]",children:e.jsx(Aa,{token:d,agentName:h.agent.name})}
31),i==="knowledge"&&e.jsx(Pa,{token:d,canEdit:!0,knowledge:B,onRefresh:re}),i==="calls"&&r?.has_call_history&&e.jsx(Ea,{calls:I,token:d,loading:_}),i==="conversations"&&e.jsx(Za,{token:d}),i==="sms"&&e.jsx(Wa,{token:d}),i==="usage"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Dit Forbrug"}),e.jsx("p",{className:"text-muted-foreground",children:"Se dit opkaldsforbrug denne måned"})]}),e.jsx(Fa,{calls:I,planName:r?.tier==="enterprise"?"Enterprise":r?.tier==="standard"?"Standard":"Basic",includedMinutes:r?.tier==="enterprise"?1e3:r?.tier==="standard"?300:100})]}),i==="analytics"&&r?.has_analytics&&e.jsx(za,{token:d,calls:I}),i==="calendar"&&e.jsx(Ua,{token:d}),i==="customers"&&e.jsx(Ja,{token:d}),i==="orders"&&r?.has_order_management&&e.jsx(Ra,{orders:O,token:d,onRefresh:o}),i==="staff"&&r?.has_staff_management&&e.jsx(La,{token:d,staff:j,onRefresh:Z}),i==="integrations"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Integrationer"}),e.jsx("p",{className:"text-muted-foreground",children:"Forbind din kalender og andre tjenester"})]}),e.jsx(Ma,{token:d,agentId:h.agent.id})]}),i==="sales"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Salg"}),e.jsx("p",{className:"text-muted-foreground",children:"Se SMS-baserede salgssessioner og konverteringer"})]}),e.jsx(Ba,{sessions:N,token:d})]}),i==="legal"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Juridisk & Datapolitik"}),e.jsx("p",{className:"text-muted-foreground",children:"GDPR-vilkår, dataansvar og samtykke"})]}),e.jsx(w,{className:"border-0 shadow-lg",children:e.jsxs(k,{className:"pt-6 space-y-4",children:[e.jsxs("a",{href:`/portal-datapolitik?token=${d}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-between p-4 rounded-lg border hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Fe,{className:"w-5 h-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Databehandlingsaftale — Kundeportal"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Dine rettigheder og ansvar som dataansvarlig"})]})]}),e.jsx(Us,{className:"w-4 h-4 text-muted-foreground"})]}),e.jsx("div",{className:"p-4 bg-muted/30 rounded-lg",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("strong",{children:"Vigtigt:"})," Hverken AgentoAI, admin eller din partner har adgang til at se dine transskriptioner, optagelser, ordrer eller medarbejderdata. Du er som virksomhed dataansvarlig for alle data i kundeportalen."]})})]})})]}),i==="settings"&&e.jsx(Ya,{token:d})]})]})}),r?.has_ai_chat&&d&&e.jsx(Va,{portalToken:d,agentName:h?.agent?.name}),e.jsx(Ha,{})]})}export{$n 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.