1import{r as d,j as e}from"./framer-motion-CQxuJa5n.js";import{a as z,b as O,j as c,I as u,B as g,p as J,s as p,u as ie,an as G,q as $,C as B,o as V}from"./index-CSx7K-7R.js";import{A as le,a as ae}from"./alert-DDlZdiu2.js";import{l as ne}from"./agento-danmark-logo-BIsXcNuL.js";import{D as Q,a as X,b as Y,c as Z,d as oe}from"./dialog-RiETlj4q.js";import{T as W}from"./textarea-BFuIyuCd.js";import{S as E,a as I,b as P,c as T,d as a}from"./select-BP_Q7Vjk.js";import{A as de,S as ce}from"./AdminChat-Ct7oDrxj.js";import{W as me}from"./wifi-off-DVcDTjyV.js";import{C as xe}from"./chart-no-axes-column-increasing-B7OAg__b.js";import{P as H}from"./plus-t8RS0EeL.js";import{E as ge}from"./external-link-VZCHNZAP.js";import{S as ue}from"./share-2-oHd1C7_0.js";import{C as he}from"./copy-B5YKNs8h.js";import{T as pe}from"./trash-2-DxlklYFw.js";import"./recharts-CFjfazL9.js";import"./index-BdQq_4o_.js";import"./index-CwKDC_mg.js";import"./index-srxnih4L.js";import"./chevron-down-DvU9LH4D.js";import"./check-BKeeD-3t.js";import"./chevron-up-fhR0nOsN.js";import"./tabs-sn5fbWIA.js";import"./index-CVOcPLpq.js";import"./index-CVRrCO-_.js";import"./link-PqJR2IMo.js";import"./qr-code-C2UmXzIs.js";import"./file-code-D5VLKqx7.js";import"./scroll-area-THRv4UVm.js";import"./badge-Yar_qzGV.js";import"./message-square-CQ8acRkB.js";import"./coins-DZzBRUaF.js";import"./circle-check-big-BvOaTfBT.js";import"./circle-x-Bjw_qpIQ.js";import"./circle-help-Bky_gBt3.js";import"./user-DwnLXD35.js";import"./send-DOJcdEwD.js";import"./settings-ClDRCqQC.js";const fe=({open:f,onOpenChange:j,onSuccess:n})=>{const{user:h}=z(),{toast:x}=O(),[N,C]=d.useState(!1),[_,y]=d.useState(null),[v,D]=d.useState(""),[s,o]=d.useState({name:"",website_url:"",rules:"",start_message:"",notification_email:"",notification_email_2:"",notification_email_3:"",size:"medium",position:"bottom-right",color:"#84CC16",bot_name:"AI Assistent",voice_enabled:!1,ai_provider:"openai",ai_model:"gpt-5-mini-2025-08-07",ai_temperature:.7,email_from_name:"",email_reply_to:"",email_subject:"Ny besked fra din chatbot"}),w=t=>{const i=t.target.files?.[0];if(i){y(i);const m=new FileReader;m.onloadend=()=>{D(m.result)},m.readAsDataURL(i)}},A=async t=>{if(t.preventDefault(),!!h){if(!s.name||!s.website_url||!s.rules){x({title:"Mangler information",description:"Udfyld venligst alle felter",variant:"destructive"});return}C(!0);try{let i="";if(_){const M=_.name.split(".").pop(),b=`${h.id}/${Date.now()}.${M}`,{error:F}=await p.storage.from("chatbot-logos").upload(b,_);if(F)throw F;const{data:{publicUrl:S}}=p.storage.from("chatbot-logos").getPublicUrl(b);i=S}const{error:m}=await p.from("chatbots").insert({user_id:h.id,name:s.name,website_url:s.website_url,rules:s.rules,start_message:s.start_message,notification_email:s.notification_email,notification_email_2:s.notification_email_2,notification_email_3:s.notification_email_3,size:s.size,position:s.position,color:s.color,bot_name:s.bot_name,voice_enabled:s.voice_enabled,ai_model:s.ai_model,ai_temperature:s.ai_temperature,email_from_name:s.email_from_name,email_reply_to:s.email_reply_to,email_subject:s.email_subject,logo_url:i||null});if(m)throw m;x({title:"Success!",description:"Din chatbot er oprettet"}),j(!1),n(),o({name:"",website_url:"",rules:"",start_message:"",notification_email:"",notification_email_2:"",notification_email_3:"",size:"medium",position:"bottom-right",color:"#84CC16",bot_name:"AI Assistent",voice_enabled:!1,ai_provider:"openai",ai_model:"gpt-5-mini-2025-08-07",ai_temperature:.7,email_from_name:"",email_reply_to:"",email_subject:"Ny besked fra din chatbot"}),y(null),D("")}catch(i){console.error("Error:",i),x({title:"Fejl",description:i.message||"Kunne ikke oprette chatbot",variant:"destructive"})}finally{C(!1)}}};return e.jsx(Q,{open:f,onOpenChange:j,children:e.jsxs(X,{className:"max-w-2xl max-h-[90vh] overflow-y-auto sm:max-w-[95vw] sm:max-h-[95vh]",children:[e.jsx(Y,{children:e.jsx(Z,{children:"Opret Ny Chatbot"})}),e.jsxs("form",{onSubmit:A,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{htmlFor:"name",children:"Chatbot Navn *"}),e.jsx(u,{id:"name",value:s.name,onChange:t=>o({...s,name:t.target.value}),placeholder:"Min AI Chatbot",required:!0})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"website_url",children:"Hjemmeside URL *"}),e.jsx(u,{id:"website_url",value:s.website_url,onChange:t=>o({...s,website_url:t.target.value}),placeholder:"https://example.com",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"rule-template",children:"Regel Template (Valgfrit)"}),e.jsxs(E,{onValueChange:t=>{const i={professional:`Du er en professionel kundeservice-assistent. 2 3VIGTIGE REGLER: 4 51. Ekspert-rolle: Du skal optræde som ekspert og vide alt om virksomheden. Giv altid relevante og korrekte informationer baseret pÃ¥ videnbasen. 6 72. Letlæselige beskeder: Del automatisk lange beskeder op i mindre, overskuelige stykker. Brug max 3-4 sætninger pr. afsnit. 8 93. Flot formatering: 10 ⢠Opdel svar i klare afsnit med dobbelt linjeskift 11 ⢠Brug bulletpoints (â¢) til lister 12 ⢠Fremhæv vigtige informationer tydeligt 13 ⢠Præsenter priser og tal overskueligt 14 154. Professionalisme: Hold sproget professionelt, præcist og let at læse. Vær altid hjælpsom og serviceminded. 16 175. Mobilvenligt: Svar skal være nemme at læse pÃ¥ bÃ¥de desktop og mobil. Hold sætninger korte og præcise. 18 196. Datakontrol: Brug KUN information fra videnbasen. Hvis du ikke ved noget, sig det ærligt og tilbyd at hjælpe pÃ¥ anden vis. 20 217. Aktivt respons: Reagér hurtigt og relevant pÃ¥ alt brugerinput. Vis at du lytter ved at referere til deres spørgsmÃ¥l.`,customer_service:`Du er en venlig kundeservice-assistent. 22 23KUNDESERVICE REGLER: 24 251. Vær serviceminded: Altid venlig, hjælpsom og imødekommende. Kundens behov kommer først. 26
272. Hurtige svar: Giv korte, præcise svar der kommer direkte til pointen. Del lange svar op i mindre bidder. 28 293. Læsbarhed: 30 ⢠Brug korte afsnit (2-3 linjer max) 31 ⢠Lister med bulletpoints (â¢) til flere punkter 32 ⢠Dobbelt linjeskift mellem emner 33 344. Problemløsning: Fokuser pÃ¥ at løse kundens problem. Hvis du ikke kan hjælpe, forklar tydeligt hvordan de kan fÃ¥ hjælp. 35 365. Personlig tone: Vær varm og personlig, men stadig professionel. Brug kundens navn hvis det er opgivet. 37 386. Mobiloptimeret: Hold svar korte og scanbare. Perfekt til mobile enheder. 39 407. Kun facts: Brug KUN information fra videnbasen. Gæt aldrig - vær ærlig hvis du ikke ved noget.`,sales:`Du er en professionel sælger og rÃ¥dgiver. 41 42SALGS REGLER: 43 441. RÃ¥dgivende rolle: Du er ekspert-rÃ¥dgiver. Hjælp kunden med at finde den bedste løsning baseret pÃ¥ deres behov. 45 462. Strukturerede svar: 47 ⢠Start med hovedpointer 48 ⢠Brug bulletpoints (â¢) til fordele/features 49 ⢠Del lange beskrivelser op i afsnit 50 ⢠Fremhæv vigtige fordele og priser 51 523. Engagerende sprog: Vær entusiastisk og positiv, men ikke pÃ¥trængende. Fokuser pÃ¥ værdi og løsninger. 53 544. Call-to-action: Guid kunden mod næste skridt - kontakt, køb, demo osv. 55 565. Produktviden: Vis dyb forstÃ¥else for produkter/services. Brug videnbasen til præcise facts. 57 586. Læsevenlighed: 59 ⢠Korte, slagkraftige afsnit 60 ⢠Tydelige overskrifter med dobbelt linjeskift 61 ⢠Mobiloptimeret præsentation 62 637. Troværdighed: Brug KUN verificeret information fra videnbasen. UndgÃ¥ overdrivelser.`,support:`Du er en teknisk support-assistent. 64 65SUPPORT REGLER: 66 671. Teknisk ekspert: Du har dyb teknisk viden. Forklar ting klart og grundigt, men ikke for teknisk. 68 692. Step-by-step guide: 70 ⢠Brug nummererede lister til guides (1., 2., 3.) 71 ⢠Bulletpoints (â¢) til forudsætninger 72 ⢠Opdel lange processer i trin 73 ⢠Dobbelt linjeskift mellem sektioner 74 753. Pædagogisk: Forklar ikke bare "hvordan" men ogsÃ¥ "hvorfor". Hjælp brugeren med at forstÃ¥. 76 774. Fejlfinding: NÃ¥r der er problemer, guide systematisk igennem løsning: 78 â Identificer problemet 79 â Tjek almindelige Ã¥rsager 80 â Test løsninger en ad gangen 81 â Bekræft nÃ¥r det virker 82 835. TÃ¥lmodighed: Nogle brugere har brug for mere hjælp end andre. Tag dig tid og vær tÃ¥lmodig. 84 856. Dokumentation: Referer til relevante guides og dokumentation fra videnbasen. 86 877. Kun facts: Brug KUN information fra videnbasen. Vær ærlig hvis du ikke ved noget.`,simple:`GRUNDLÃGGENDE REGLER: 88 89⢠Giv korte, præcise svar 90⢠Brug kun information fra videnbasen 91⢠Del lange svar op i mindre stykker (max 3 linjer pr. afsnit) 92⢠Brug bulletpoints (â¢) til lister 93⢠Hold sproget klart og professionelt 94⢠Vær ærlig hvis du ikke ved noget`};t!=="custom"&&i[t]&&o({...s,rules:i[t]})},children:[e.jsx(I,{children:e.jsx(P,{placeholder:"Vælg en regel-template for at komme hurtigt i gang"})}),e.jsxs(T,{children:[e.jsx(a,{value:"custom",children:"ð¨ Brugerdefineret"}),e.jsx(a,{value:"professional",children:"ð¼ Professionel - Komplet og pÃ¥lidelig"}),e.jsx(a,{value:"customer_service",children:"ð¤ Kundeservice - Venlig og løsningsorienteret"}),e.jsx(a,{value:"sales",children:"ð° Salg - RÃ¥dgivende og engagerende"}),e.jsx(a,{value:"support",children:"ð§ Support - Teknisk og pædagogisk"}),e.jsx(a,{value:"simple",children:"⨠Simpel - Korte og præcise regler"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Vælg en template eller skriv dine egne regler nedenfor"})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"rules",children:"Chatbot Regler *"}),e.jsx(W,{id:"rules",value:s.rules,onChange:t=>o({...s,rules:t.target.value}),placeholder:"Disse regler fortæller chatbotten hvordan den skal opføre sig og svare",rows:6,required:!0})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"bot_name",children:"Bot Navn"}),e.jsx(u,{id:"bot_name",value:s.bot_name,onChange:t=>o({...s,bot_name:t.target.value}),placeholder:"AI Assistent"})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"start_message",children:"Velkomstbesked"}),e.jsx(W,{id:"start_message",value:s.start_message,onChange:t=>o({...s,start_message:t.target.value}),placeholder:"Hej! Hvordan kan jeg hjælpe dig i dag?",rows:3})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(c,{children:"E-mail
94s for notifikationer"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tilføj op til 3 email-adresser der modtager beskeder"}),e.jsx(u,{id:"notification_email",type:"email",value:s.notification_email,onChange:t=>o({...s,notification_email:t.target.value}),placeholder:"fø[email protected]",maxLength:255}),e.jsx(u,{id:"notification_email_2",type:"email",value:s.notification_email_2,onChange:t=>o({...s,notification_email_2:t.target.value}),placeholder:"[email protected] (valgfri)",maxLength:255}),e.jsx(u,{id:"notification_email_3",type:"email",value:s.notification_email_3,onChange:t=>o({...s,notification_email_3:t.target.value}),placeholder:"[email protected] (valgfri)",maxLength:255})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"logo",children:"Upload Logo"}),e.jsx(u,{id:"logo",type:"file",accept:"image/*",onChange:w}),v&&e.jsx("img",{src:v,alt:"Logo preview",className:"mt-2 h-16 w-16 object-contain"})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{htmlFor:"size",children:"Størrelse"}),e.jsxs(E,{value:s.size,onValueChange:t=>o({...s,size:t}),children:[e.jsx(I,{children:e.jsx(P,{})}),e.jsxs(T,{children:[e.jsx(a,{value:"small",children:"Lille"}),e.jsx(a,{value:"medium",children:"Mellem"}),e.jsx(a,{value:"large",children:"Stor"})]})]})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"position",children:"Position"}),e.jsxs(E,{value:s.position,onValueChange:t=>o({...s,position:t}),children:[e.jsx(I,{children:e.jsx(P,{})}),e.jsxs(T,{children:[e.jsx(a,{value:"bottom-right",children:"Nederst til højre"}),e.jsx(a,{value:"bottom-left",children:"Nederst til venstre"}),e.jsx(a,{value:"top-right",children:"Ãverst til højre"}),e.jsx(a,{value:"top-left",children:"Ãverst til venstre"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"color",children:"Primær farve"}),e.jsx(u,{id:"color",type:"color",value:s.color,onChange:t=>o({...s,color:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"ai_provider",children:"AI Provider"}),e.jsxs(E,{value:s.ai_provider,onValueChange:t=>{const i={...s,ai_provider:t};t==="openai"&&(!s.ai_model||!s.ai_model.startsWith("gpt-"))&&(i.ai_model="gpt-5-mini-2025-08-07"),o(i)},children:[e.jsx(I,{children:e.jsx(P,{})}),e.jsxs(T,{children:[e.jsx(a,{value:"openai",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Kevin OpenAI"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"GPT-5 modeller"})]})}),e.jsx(a,{value:"lovable",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Lovable AI"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Google Gemini 2.5 & GPT-5"})]})}),e.jsx(a,{value:"puter",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Puter.js"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"100% gratis - GPT-5.1, o4, o3-mini"})]})}),e.jsx(a,{value:"huggingface",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Hugging Face"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Gratis tier - open source modeller"})]})})]})]})]}),s.ai_provider==="huggingface"&&e.jsxs("div",{children:[e.jsx(c,{htmlFor:"ai_model",children:"Hugging Face Model"}),e.jsxs(E,{value:s.ai_model,onValueChange:t=>o({...s,ai_model:t}),children:[e.jsx(I,{children:e.jsx(P,{})}),e.jsxs(T,{children:[e.jsx(a,{value:"meta-llama/Llama-3.2-3B-Instruct",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Llama 3.2 3B Instruct"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Hurtig og effektiv"})]})}),e.jsx(a,{value:"meta-llama/Llama-3.2-1B-Instruct",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Llama 3.2 1B Instruct"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Meget hurtig, kompakt"})]})}),e.jsx(a,{value:"mistralai/Mistral-7B-Instruct-v0.3",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Mistral 7B Instruct v0.3"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Stærk allround model"})]})}),e.jsx(a,{value:"mistralai/Mistral-Nemo-Instruct-2407",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Mistral Nemo Instru
94ct"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Nyeste Mistral model"})]})}),e.jsx(a,{value:"tiiuae/falcon-7b-instruct",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Falcon 7B Instruct"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Open source, kraftfuld"})]})}),e.jsx(a,{value:"microsoft/Phi-3.5-mini-instruct",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Phi-3.5 Mini Instruct"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Kompakt Microsoft model"})]})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Vælg den Hugging Face model der passer bedst til dine behov"})]}),s.ai_provider==="openai"&&e.jsxs("div",{children:[e.jsx(c,{htmlFor:"ai_model",children:"OpenAI Model"}),e.jsxs(E,{value:s.ai_model,onValueChange:t=>o({...s,ai_model:t}),children:[e.jsx(I,{children:e.jsx(P,{})}),e.jsxs(T,{children:[e.jsx(a,{value:"gpt-5-2025-08-07",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"GPT-5"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Flagship model - Bedste kvalitet"})]})}),e.jsx(a,{value:"gpt-5-mini-2025-08-07",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"GPT-5 Mini"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Hurtig og omkostningseffektiv"})]})}),e.jsx(a,{value:"gpt-5-nano-2025-08-07",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"GPT-5 Nano"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Hurtigst og billigst"})]})}),e.jsx(a,{value:"gpt-4.1-2025-04-14",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"GPT-4.1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Pålidelig GPT-4 model"})]})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Vælg GPT model - GPT-5 Mini anbefales til de fleste formål"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row justify-end gap-2 pt-4",children:[e.jsx(g,{type:"button",variant:"outline",onClick:()=>j(!1),className:"w-full sm:w-auto",children:"Annuller"}),e.jsxs(g,{type:"submit",disabled:N,className:"w-full sm:w-auto",children:[N&&e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Opret Chatbot"]})]})]})]})})};function je({open:f,onOpenChange:j,sourceChatbot:n,onSuccess:h}){const{user:x}=z(),{toast:N}=O(),[C,_]=d.useState(!1),[y,v]=d.useState(""),[D,s]=d.useState(null),[o,w]=d.useState("#84CC16");d.useEffect(()=>{n&&(v(`${n.name} (Kopi)`),w(n.color))},[n]);const A=i=>{const m=i.target.files?.[0];m&&s(m)},t=async()=>{if(!x||!y.trim()){N({title:"Fejl",description:"Bot-navn er påkrævet",variant:"destructive"});return}_(!0);try{let i=null;if(D){const M=D.name.split(".").pop(),b=`${x.id}/${Date.now()}.${M}`,{error:F}=await p.storage.from("chatbot-logos").upload(b,D);if(F)throw F;const{data:S}=p.storage.from("chatbot-logos").getPublicUrl(b);i=S.publicUrl}else n.logo_url&&(i=n.logo_url);const{error:m}=await p.from("chatbots").insert({user_id:x.id,name:y.trim(),website_url:n.website_url,rules:n.rules,size:n.size,position:n.position,color:o,bot_name:n.bot_name,voice_enabled:n.voice_enabled,start_message:n.start_message,logo_url:i,ai_provider:n.ai_provider,ai_model:n.ai_model,ai_temperature:n.ai_temperature,response_tone:n.response_tone,response_length:n.response_length,response_personality:n.response_personality,total_messages:0,total_sessions:0,is_active:!1});if(m)throw m;N({title:"Bot kopieret!",description:"Din nye bot er oprettet. Husk at tilføje videnbase manuelt."}),h(),j(!1),v(""),s(null),w("#84CC16")}catch(i){console.error("Duplicate error:",i),N({title:"Fejl",description:i.message||"Kunne ikke kopiere bot",variant:"destructive"})}finally{_(!1)}};return e.jsx(Q,{open:f,onOpenChange:j,children:e.jsxs(X,{className:"sm:max-w-[500px]",children:[e.jsxs(Y,{children:[e.jsx(Z,{children:"Kopiér Chatbot"}),e.jsx(oe,{children:"Kopierer kun navn, logo og farver. Du skal selv tilføje videnbase til den nye bot."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"name",children:"Bot Navn *"}),e.jsx(u,{id:"name",value:y,onChange:i=>v(i.target.value),placeholder:"Min nye bot"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"logo",children:"Logo (valgfrit)"}),e.jsx(u,{id:"logo",type:"file",accept:"image/*",onChange:A}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lad feltet være tomt for at beholde originalt logo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"color",children:"Farve"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u,{id:"color",type:"color",value:o,onChange:i=>w(i.target.value),className:"w-20 h-10"}),e.jsx(u,{type:"text",value:o,onChange:i=>w(i.target.value),className:"flex-1"})]})]}),e.jsxs("div",{className:"bg-muted p-3 rounded-lg text-sm",children:[e.jsx("p",{className:"font-medium mb-2",children:"Hvad kopieres:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"Navn, logo og farver"}),e.jsx("li",{children:"Regler, beskeder og AI-indstillinger"})]}
94),e.jsx("p",{className:"font-medium mt-3 mb-2",children:"Hvad kopieres IKKE:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"Videnbase (skal tilføjes manuelt)"}),e.jsx("li",{children:"Beskeder, sessioner og statistik"}),e.jsx("li",{children:"Notifikations-emails"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{variant:"outline",onClick:()=>j(!1),disabled:C,children:"Annuller"}),e.jsx(g,{onClick:t,disabled:C||!y.trim(),children:C?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"mr-2 h-4 w-4 animate-spin"}),"Kopierer..."]}):"Kopiér Bot"})]})]})})}const rs=()=>{const{user:f,signOut:j}=z(),n=ie(),{toast:h}=O(),[x,N]=d.useState([]),[C,_]=d.useState(!0),[y,v]=d.useState(null),[D,s]=d.useState(!1),[o,w]=d.useState(!1),[A,t]=d.useState(!1),[i,m]=d.useState(null),[M,b]=d.useState(0),[F,S]=d.useState(0),[ee,K]=d.useState("checking");d.useEffect(()=>{L(),se();const r=async()=>{try{const{error:k}=await p.from("voice_agents").select("id").limit(1);if(k&&G(k)){K("disconnected");return}K(k?"disconnected":"connected")}catch{K("disconnected")}};r();const l=setInterval(r,3e4);return()=>clearInterval(l)},[f]);const L=async()=>{if(f){v(null),_(!0);try{const{data:r,error:l}=await p.from("chatbots").select("*").eq("user_id",f.id).order("created_at",{ascending:!1});if(l){if(G(l)){N([]),v(null);return}throw l}N(r||[]),console.log("â Chatbots loaded successfully:",r?.length||0)}catch(r){console.error("â Error fetching chatbots:",r);const l=r.message||"Ukendt fejl";v(l),!l.includes("Failed to fetch")&&!G(r)&&h({title:"Fejl",description:l,variant:"destructive"})}finally{_(!1)}}},se=async()=>{if(f)try{const{data:r,error:l}=await p.from("chatbot_usage").select("estimated_cost_usd, message_count").eq("user_id",f.id);if(l){if(G(l)){b(0),S(0);return}throw console.error("â Usage fetch error:",l),l}if(r&&r.length>0){const k=r.reduce((R,U)=>R+Number(U.estimated_cost_usd||0),0),q=r.reduce((R,U)=>R+Number(U.message_count||0),0);console.log("â Total usage loaded:",{cost:k,messages:q,records:r.length}),b(k),S(q)}else console.log("â¹ï¸ No usage data found yet"),b(0),S(0)}catch(r){console.error("â Usage fetch error:",r),b(0),S(0)}},te=async(r,l)=>{try{const{error:k}=await p.from("chatbots").update({is_active:!l}).eq("id",r);if(k)throw k;h({title:l?"Bot deaktiveret":"Bot udgivet",description:l?"Din bot er nu inaktiv":"Din bot er nu online og aktiv"}),L()}catch{h({title:"Fejl",description:"Kunne ikke opdatere status",variant:"destructive"})}},re=async r=>{if(confirm("Er du sikker pÃ¥ du vil slette denne chatbot?"))try{const{error:l}=await p.from("chatbots").delete().eq("id",r);if(l)throw l;h({title:"Slettet",description:"Chatbot blev slettet"}),L()}catch{h({title:"Fejl",description:"Kunne ikke slette chatbot",variant:"destructive"})}};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b border-border bg-card",children:e.jsx("div",{className:"container mx-auto px-3 sm:px-4 py-3 sm:py-4 max-w-7xl",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 min-w-0",children:[e.jsx("img",{src:ne,alt:"Agento Danmark",className:"h-8 sm:h-10 w-auto flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-lg sm:text-2xl font-bold truncate",children:"Agento Danmark"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"by DreamitAI"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 flex-wrap flex-shrink-0",children:[e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground hidden md:inline truncate max-w-[150px]",children:f?.email}),e.jsxs(g,{variant:"outline",onClick:()=>j(),className:"gap-2 h-9 sm:h-10",size:"sm",children:[e.jsx($,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Log Ud"}),e.jsx("span",{className:"sm:hidden",children:"Ud"})]})]})]})})}),e.jsxs("div",{className:"container mx-auto px-3 sm:px-4 py-4 sm:py-8 max-w-7xl",children:[ee==="disconnected"&&e.jsxs(le,{className:"mb-6 border-yellow-500/50 bg-yellow-500/10",children:[e.jsx(me,{className:"w-4 h-4 text-yellow-500"}),e.jsx(ae,{className:"text-sm",children:"Forbindelsesproblemer opdaget. Prøver at genoprette forbindelsen..."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4 mb-6 sm:mb-8",children:[e.jsxs(B,{className:"p-4 sm:p-6 bg-card border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 mb-2",children:[e.jsx("div",{className:"p-1.5 sm:p-2 rounded-lg bg-primary/10 flex-shrink-0",children:e.jsx(V,{className:"w-4 h-4 sm:w-5 sm:h-5 text-primary"})}),e.jsx("h3",{className:"font-semibold text-sm sm:text-base",children:"Total Bots"})]}),e.jsx("p",{className:"text-2xl sm:text-3xl font-bold text-primary",children:x.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Aktive chatbots"})]}),e.jsxs(B,{className:"p-4 sm:p-6 bg-card border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 mb-2",children:[e.jsx("div",{className:"p-1.5 sm:p-2 rounded-lg bg-primary/10 flex-shrink-0",children:e.jsx(xe,{className:"w-4 h-4 sm:w-5 sm:h-5 text-primary"})}),e.jsx("h3",{className:"font-semibold text-sm sm:text-base",children:"AI Omkostninger"})]}),e.jsxs("p",{className:"text-2xl sm:text-3xl font-bold text-primary",children:[(M*7).toFixed(2)," kr"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Rigtige tal pÃ¥ tværs af alle bots"})]}),e.jsxs(B,{className:"p-4 sm:p-6 bg-card border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 mb-2",children:[e.jsx("div",{className:"p-1.5 sm:p-2 rounded-lg bg-primary/10 flex-shrink-0",children:e.jsx("svg",{className:"w-4 h-4 sm:w-5 sm:h-5 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})})}),e.jsx("h3",{className:"font-semibold text-sm sm:text-base",children:"Total Beskeder"})]}),e.jsx("p",{className:"text-2xl sm:text-3xl font-bold text-primary",children:F.toLocaleStr
94ing("da-DK")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Sendt gennem alle bots"})]})]}),e.jsx("div",{className:"mb-6 sm:mb-8",children:e.jsx(de,{})}),C?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary"})}):y?e.jsxs(B,{className:"p-12 text-center bg-card border-border border-destructive/50",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-destructive/10 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("h2",{className:"text-2xl font-bold mb-2",children:"Session Problem"}),e.jsx("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:"Dine bots er IKKE slettet! Efter domæneskiftet til agentodanmark.com skal du logge ud og ind igen for at genopfriske din session."}),e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsxs(g,{onClick:()=>j(),className:"bg-primary hover:bg-primary/90 text-primary-foreground gap-2",children:[e.jsx($,{className:"w-4 h-4"}),"Log Ud og Log Ind Igen"]}),e.jsxs(g,{onClick:L,variant:"outline",className:"gap-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Eller Forsøg Igen"]}),e.jsxs("p",{className:"text-xs text-muted-foreground max-w-sm",children:[e.jsx("strong",{children:"Alle dine bots og data er sikre."})," Dette er kun et session-problem efter domæneskiftet."]})]})]}):x.length===0?e.jsxs(B,{className:"p-12 text-center bg-card border-border",children:[e.jsx(V,{className:"w-16 h-16 mx-auto mb-4 text-muted-foreground"}),e.jsx("h2",{className:"text-2xl font-bold mb-2",children:"Ingen Chatbots Endnu"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Opret din første AI chatbot og begynd at hjælpe dine besøgende"}),e.jsxs(g,{onClick:()=>s(!0),className:"bg-primary hover:bg-primary/90 text-primary-foreground gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),"Opret Min Første Chatbot"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4",children:[e.jsxs("h2",{className:"text-xl font-semibold",children:[x.length," ",x.length===1?"Chatbot":"Chatbots"]}),e.jsxs(g,{onClick:()=>s(!0),className:"bg-primary hover:bg-primary/90 text-primary-foreground gap-2 w-full sm:w-auto",children:[e.jsx(H,{className:"w-4 h-4"}),"Ny Chatbot"]})]}),e.jsx("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:x.map(r=>e.jsxs(B,{className:"p-4 sm:p-6 bg-card border-border hover:border-primary/50 transition-all cursor-pointer hover:shadow-lg active:scale-[0.98]",onClick:()=>n(`/chatbot/${r.id}`),children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center",style:{backgroundColor:r.color},children:e.jsx(V,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:r.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.bot_name})]})]}),r.is_active?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-primary/10 text-primary border border-primary/20",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary animate-pulse"}),"Online"]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-muted text-muted-foreground border border-border",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground"}),"Inaktiv"]})]}),e.jsxs("div",{className:"mb-4 text-sm text-muted-foreground",children:[e.jsx(ge,{className:"w-3 h-3 inline mr-1"}),r.website_url]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-4 py-4 border-y border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.total_messages}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Beskeder"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r.total_sessions}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sessioner"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{onClick:l=>{l.stopPropagation(),te(r.id,r.is_active)},variant:r.is_active?"outline":"default",size:"sm",className:"flex-1 gap-2 h-10 sm:h-9 text-sm",children:r.is_active?"Deaktiver":"Udgiv"}),e.jsx(g,{variant:"outline",size:"sm",onClick:l=>{l.stopPropagation(),m(r),w(!0)},title:"Del bot",className:"h-10 w-10 sm:h-9 sm:w-9 p-0",children:e.jsx(ue,{className:"w-4 h-4"})}),e.jsx(g,{variant:"outline",size:"sm",onClick:l=>{l.stopPropagation(),m(r),t(!0)},title:"Kopiér bot",className:"h-10 w-10 sm:h-9 sm:w-9 p-0",children:e.jsx(he,{className:"w-4 h-4"})}),e.jsx(g,{variant:"outline",size:"sm",onClick:l=>{l.stopPropagation(),re(r.id)},title:"Slet bot",className:"h-10 w-10 sm:h-9 sm:w-9 p-0",children:e.jsx(pe,{className:"w-4 h-4"})})]})]},r.id))})]})]}),x.length>0&&e.jsx(g,{onClick:()=>s(!0),className:"fixed bottom-6 right-6 sm:hidden h-14 w-14 roun
94ded-full shadow-lg bg-primary hover:bg-primary/90 text-primary-foreground z-50",size:"icon",children:e.jsx(H,{className:"w-6 h-6"})}),e.jsx(fe,{open:D,onOpenChange:s,onSuccess:L}),i&&e.jsxs(e.Fragment,{children:[e.jsx(ce,{open:o,onOpenChange:w,chatbotId:i.id,chatbotName:i.name}),e.jsx(je,{open:A,onOpenChange:t,sourceChatbot:i,onSuccess:L})]})]})};export{rs 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.