1import{r as h,j as e,b1 as ce,i as A,a0 as Ce,C as N,a as C,b as w,d as D,e as _,B as $,L as f,I as b,S as we,K as De,aU as Ee,cY as de,J as R}from"./index-BOi4GZy8.js";import{T as z}from"./textarea-T_vDpkyb.js";import{A as W,b as me,a as G}from"./alert-DgoHVgjN.js";import{T as Fe,a as $e,b as ue,c as E,d as Me,e as F}from"./table-CDDGvIHp.js";import{S as Y,a as Z,b as J,c as Q,d as H}from"./select-JSPdEN3s.js";import{A as qe,b as Le,c as Re,d as Ke,e as Ue,f as Be,g as Oe,h as He}from"./alert-dialog-Nz9W-KN4.js";import{c as Ie,k as Ve,m as Pe}from"./automationsService-bDEda42S.js";import{A as ze}from"./arrow-left-C5cDf6bl.js";import{T as pe}from"./trash-2-BmuIYilg.js";import{M as We,S as Ge}from"./smartphone-C4Hi1-Vh.js";import"./edgeError-DSnFxpXo.js";const I=[{key:"contact.first_name",label:"Kontaktens förnamn",description:"Förnamnet pÃ¥ personen som skrev, utläst ur avsändaren.",example:"Anna",required:!1,group:"contact"},{key:"contact.last_name",label:"Kontaktens efternamn",description:"Efternamnet, om det gick att utläsa ur avsändaren.",example:"Lindqvist",required:!1,group:"contact"},{key:"contact.company",label:"Kontaktens företag",description:"Företaget kontakten skriver frÃ¥n, om det är känt.",example:"Nordvik Bygg AB",required:!1,group:"contact"},{key:"contact.email",label:"Kontaktens e-postadress",description:"Adressen mejlet kom frÃ¥n.",example:"[email protected]",required:!1,group:"contact"},{key:"contact.phone",label:"Kontaktens telefonnummer",description:"Numret kontakten uppgett, om nÃ¥got finns.",example:"070-123 45 67",required:!1,group:"contact"},{key:"business.name",label:"Ditt företagsnamn",description:"Namnet du skickar under. Krävs â ett osignerat mejl ser ut som nätfiske.",example:"Solnahallens VVS AB",required:!0,group:"business"},{key:"business.phone",label:"Ditt telefonnummer",description:"Numret kunden kan ringa, frÃ¥n dina inställningar.",example:"08-123 45 67",required:!1,group:"business"},{key:"business.website",label:"Din webbplats",description:"Adressen till din webbplats, frÃ¥n dina inställningar.",example:"https://solnahallensvvs.se",required:!1,group:"business"},{key:"automation.name",label:"Automationens namn",description:"Namnet pÃ¥ automationen som skickar. Används mest i interna mallar.",example:"Svar pÃ¥ offertförfrÃ¥gan",required:!1,group:"automation"},{key:"email.subject",label:"Ãmnesraden",description:"Ãmnesraden i mejlet som utlöste automationen.",example:"Offert pÃ¥ badrumsrenovering",required:!1,group:"email"},{key:"email.received_at",label:"När mejlet kom in",description:"Tidpunkten mejlet togs emot.",example:"2026-07-29 08:14",required:!1,group:"email"},{key:"case.reference",label:"Ãrendenummer",description:"Referensen kunden kan hänvisa till. Finns först när ett ärende skapats.",example:"ÃR-2026-0148",required:!1,group:"case"},{key:"ai.reply",label:"AI-genererat svar",description:"Svarstexten AI:n skrev. Krävs â utan den är mejlet tomt.",example:"Tack för din förfrÃ¥gan! Vi kan komma pÃ¥ plats för besiktning redan pÃ¥ torsdag.",required:!0,group:"ai"},{key:"ai.summary",label:"AI-sammanfattning",description:"Kort sammanfattning av ärendet. Avsedd för interna mejl.",example:"Kunden vill ha offert pÃ¥ helrenovering av badrum, 6 kvm, i Solna.",required:!1,group:"ai"},{key:"current_date",label:"Dagens datum",description:"Datumet mejlet skickas, skrivet 2026-07-29.",example:"2026-07-29",required:!1,group:"system"}],V=I.reduce((t,a)=>(t[a.key]=a,t),{}),X=/^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)*$/,Ye=(t,a)=>{if(t==="")return{kind:"unsupported",reason:"empty",raw:a};if(t==="/if")return{kind:"if_close",raw:a};if(t.startsWith("#if")){const l=t.slice(3);return/^\s/.test(l)&&X.test(l.trim())?{kind:"if_open",key:l.trim(),raw:a}:{kind:"unsupported",reason:"block",raw:a}}if(t==="else"||t.startsWith("else "))return{kind:"unsupported",reason:"else",raw:a};if(t.startsWith("!"))return{kind:"unsupported",reason:"comment",raw:a};if(t.startsWith(">"))return{kind:"unsupported",reason:"partial",raw:a};if(t.startsWith("#")||t.startsWith("/")||t.startsWith("^"))return{kind:"unsupported",reason:"block",raw:a};if(t.startsWith("&"))return{kind:"unsupported",reason:"triple",raw:a};const r=t.indexOf("|");if(r!==-1){const l=t.slice(0,r).trim(),c=t.slice(r+1).trim();
1return X.test(l)?{kind:"var",key:l,fallback:c===""?null:c,raw:a}:{kind:"unsupported",reason:"expression",raw:a}}return X.test(t)?{kind:"var",key:t,fallback:null,raw:a}:{kind:"unsupported",reason:"expression",raw:a}},ae=t=>{const a=[];let r="",l=0;const c=()=>{r!==""&&(a.push({kind:"text",text:r}),r="")};for(;l<t.length;){const d=t.indexOf("{{",l);if(d===-1){r+=t.slice(l);break}if(r+=t.slice(l,d),t.startsWith("{{{",d)){const p=t.indexOf("}}}",d+3);if(p===-1){r+="{{",l=d+2;continue}c(),a.push({kind:"unsupported",reason:"triple",raw:t.slice(d,p+3)}),l=p+3;continue}const i=t.indexOf("}}",d+2);if(i===-1){c(),a.push({kind:"unsupported",reason:"unterminated",raw:t.slice(d)}),l=t.length;break}c(),a.push(Ye(t.slice(d+2,i).trim(),t.slice(d,i+2))),l=i+2}return c(),a},Ne=t=>{const a=new Array(t.length).fill(-1),r=[];let l=0;for(let c=0;c<t.length;c++){const d=t[c];if(d.kind==="if_open")r.push(c),r.length>l&&(l=r.length);else if(d.kind==="if_close"){const i=r.pop();if(i===void 0)continue;a[i]=c,a[c]=i}}return{partner:a,maxDepth:l}},Ze=new Set(["__proto__","prototype","constructor"]),xe=(t,a)=>{if(Object.prototype.hasOwnProperty.call(t,a))return t[a];let r=t;for(const l of a.split(".")){if(Ze.has(l)||r===null||typeof r!="object"||!Object.prototype.hasOwnProperty.call(r,l))return;r=r[l]}return r},he=t=>t<10?`0${t}`:String(t),_e=t=>`${t.getUTCFullYear()}-${he(t.getUTCMonth()+1)}-${he(t.getUTCDate())}`,se=t=>{if(t==null)return null;if(typeof t=="string"){const a=t.trim();return a===""?null:a}if(typeof t=="number")return Number.isFinite(t)?String(t):null;if(typeof t=="boolean")return t?"ja":null;if(t instanceof Date)return Number.isNaN(t.getTime())?null:_e(t);if(Array.isArray(t)){const a=[];for(const r of t){const l=se(r);l!==null&&a.push(l)}return a.length===0?null:a.join(", ")}return null},Je=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),y=(t,a)=>{t.includes(a)||t.push(a)},Qe=t=>{const a=[],r=new Map,l=(c,d)=>{const i=r.get(c);if(i){i.occurrences+=1,i.fallback===null&&(i.fallback=d);return}const p=V[c],n={key:c,known:p!==void 0,required:(p==null?void 0:p.required)===!0,fallback:d,occurrences:1};r.set(c,n),a.push(n)};for(const c of ae(t))c.kind==="var"?l(c.key,c.fallback):c.kind==="if_open"&&l(c.key,null);return a},ge=(t,a,r={})=>{var M;const l=r.escapeHtml!==!1,c=ae(t),{partner:d}=Ne(c);let i="";const p=[],n=[],k=[];let x=0;for(;x<c.length;){const m=c[x];if(m.kind==="text"){i+=m.text,x+=1;continue}if(m.kind==="unsupported"){i+=m.raw,x+=1;continue}if(m.kind==="if_close"){d[x]===-1&&(i+=m.raw),x+=1;continue}if(m.kind==="if_open"){if(d[x]===-1){i+=m.raw,x+=1;continue}const q=se(xe(a,m.key));q===null&&((M=V[m.key])==null?void 0:M.required)===!0&&y(p,m.key),x=q===null?d[x]+1:x+1;continue}const S=V[m.key],v=se(xe(a,m.key));if(v===null){(S==null?void 0:S.required)===!0&&y(p,m.key),m.fallback!==null?(i+=m.fallback,y(k,m.key)):y(n,m.key),x+=1;continue}i+=l?Je(v):v,x+=1}return{output:i,missingRequired:p,unresolved:n,usedFallbacks:k}},ee=t=>{const a=t.replace(/\s+/g," ").trim();return a.length>60?`${a.slice(0,59)}â¦`:a},Xe={triple:t=>`${t} stöds inte. Värden HTML-escapas alltid â skriv {{nyckel}} i stället.`,unterminated:t=>`${t} saknar avslutande }}.`,block:t=>`${t} stöds inte. Det enda blocket som finns är {{#if nyckel}} ⦠{{/if}}.`,else:t=>`${t} stöds inte. Skriv tvÃ¥ separata {{#if â¦}}-block i stället.`,partial:t=>`${t} stöds inte. Mallar kan inte inkludera andra mallar.`,comment:t=>`${t} stöds inte och skickas med i mejlet som vanlig text.`,empty:()=>"Tomma klamrar {{}} betyder ingenting. Ta bort dem eller skriv en variabel.",expression:t=>`${t} är inte en variabel. Endast {{nyckel}}, {{nyckel|reservtext}} och {{#if nyckel}} stöds.`},te=t=>{const a=[];if(t.trim()==="")return["Mallen är tom."];const r=ae(t),{partner:l,maxDepth:c}=Ne(r);for(let d=0;d<r.length;d++){const i=r[d];if(i.kind==="unsupported"){y(a,Xe[i.reason](ee(i.raw)));continue}if(i.kind==="if_open"&&l[d]===-1){y(a,`${ee(i.raw)} saknar ett avslutande {{/if}}.`);continue}if(i.kind==="if_close"&&l[d]===-1){y(a,"Det finns ett {{/if}} som inte hör till nÃ¥got {{#if â¦}}.");continue}const p=i.kind==="var"||i.kind==="if_open"?i.key:null;p!==null&&V[p]===void 0&&y(a,`Variabeln {{${p}}} finns inte. Kontrollera stavningen â annars blir den tom i utskicket.`),i.kind==="var"&&i.fallback===null&&i.raw.includes("|")&&y(a,`Reservtexten i ${ee(i.raw)} är tom. Skriv en text efter | eller ta bort tecknet.`)}return c>
12&&a.push("{{#if â¦}} fÃ¥r ligga i högst tvÃ¥ nivÃ¥er. Dela upp mallen i stället."),a},fe=(t=new Date)=>{const a={};for(const r of I)a[r.key]=r.example;return a.current_date=_e(t),a},K={draft:"Utkast",active:"Aktiv",archived:"Arkiverad"},et=["Svar pÃ¥ förfrÃ¥gan","Offert","Bokningsbekräftelse","PÃ¥minnelse","Uppföljning","FrÃ¥nvaro","Internt"],je={sv:"Svenska",en:"Engelska",no:"Norska",da:"Danska",fi:"Finska"},tt=()=>({name:"",description:"",category:"",subject:"",preview_text:"",from_name:"",reply_to:"",signature_html:"",language:"sv",tags:"",source_format:"html",body_source:"",body_text:"",status:"draft"}),ke=t=>({id:t.id,name:t.name,description:t.description??"",category:t.category??"",subject:t.subject??"",preview_text:t.preview_text??"",from_name:t.from_name??"",reply_to:t.reply_to??"",signature_html:t.signature_html??"",language:t.language||"sv",tags:(t.tags??[]).join(", "),source_format:t.source_format==="text"?"text":"html",body_source:t.body_source??"",body_text:t.body_text??"",status:t.status}),j=t=>t.trim()===""?null:t.trim(),st=t=>{const a=t.category.trim()||"Allmänt",r=t.tags.split(",").map(d=>d.trim()).filter(Boolean),l=t.body_source===""?null:t.body_source,c=t.body_text===""?null:t.body_text;return{...t.id?{id:t.id}:{},name:t.name.trim(),description:j(t.description),category:a,tags:r,language:t.language,source_format:t.source_format,sourceFormat:t.source_format,subject:j(t.subject),preview_text:j(t.preview_text),previewText:j(t.preview_text),from_name:j(t.from_name),fromName:j(t.from_name),reply_to:j(t.reply_to),replyTo:j(t.reply_to),signature_html:j(t.signature_html),signatureHtml:j(t.signature_html),body_source:l,bodySource:l,body_text:c,bodyText:c,status:t.status}},ve={removedTags:[],removedAttributes:[],blockedUrls:[],hadDangerousContent:!1},be=t=>{const a=t??{};return{removedTags:Array.isArray(a.removedTags)?a.removedTags:[],removedAttributes:Array.isArray(a.removedAttributes)?a.removedAttributes:[],blockedUrls:Array.isArray(a.blockedUrls)?a.blockedUrls:[],hadDangerousContent:a.hadDangerousContent===!0}},at=t=>t.hadDangerousContent||t.removedTags.length>0||t.removedAttributes.length>0||t.blockedUrls.length>0,nt=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),ye=({target:t,onCancel:a,onConfirm:r})=>e.jsx(qe,{open:t!==null,onOpenChange:l=>{l||a()},children:e.jsxs(Le,{children:[e.jsxs(Re,{children:[e.jsxs(Ke,{children:["Ta bort ",t==null?void 0:t.name,"?"]}),e.jsx(Ue,{children:"Mallen försvinner ur listan och arbetsflöden som använder den slutar kunna skicka med den. Det gÃ¥r inte att Ã¥ngra härifrÃ¥n."})]}),e.jsxs(Be,{children:[e.jsx(Oe,{children:"Avbryt"}),e.jsx(He,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:r,children:"Ta bort"})]})]})}),rt=t=>t==="active"?e.jsx($,{className:"bg-emerald-600 hover:bg-emerald-600",children:K.active}):t==="draft"?e.jsx($,{variant:"outline",className:"text-amber-600 border-amber-600/40",children:K.draft}):e.jsx($,{variant:"secondary",children:K.archived}),ft=()=>{const[t,a]=h.useState([]),[r,l]=h.useState(!0),[c,d]=h.useState(null),[i,p]=h.useState(""),[n,k]=h.useState(null),[x,M]=h.useState(!1),[m,S]=h.useState(ve),[v,q]=h.useState("desktop"),[U,L]=h.useState(null),ne=h.useCallback(async()=>{d(null);try{const{templates:s}=await Ie();a(s??[])}catch(s){d(s instanceof Error?s.message:"Kunde inte hämta mallarna.")}finally{l(!1)}},[]);h.useEffect(()=>{ne()},[ne]);const B=h.useMemo(()=>{const s=i.trim().toLowerCase();return s?t.filter(o=>[o.name,o.category,o.subject,o.description,...o.tags??[]].some(u=>u==null?void 0:u.toLowerCase().includes(s))):t},[t,i]),g=(s,o)=>k(u=>u&&{...u,[s]:o}),Se=()=>{k(tt()),S(ve)},Te=s=>{k(ke(s)),S(be(s.sanitize_report))},Ae=async()=>{if(n){if(n.name.trim()===""){R.error("Mallen behöver ett namn.");return}M(!0);try{const s=await Ve(st(n)),o=s.template;k(ke(o)),S(be(s.report)),a(u=>u.some(O=>O.id===o.id)?u.map(O=>O.id===o.id?o:O):[o,...u]),R.success("Mallen sparades.")}catch(s){R.error(s instanceof Error?s.message:"Kunde inte spara mallen.")}finally{M(!1)}}},re=async()=>
1{if(!U)return;const{id:s}=U;L(null);try{await Pe(s),a(o=>o.filter(u=>u.id!==s)),k(o=>(o==null?void 0:o.id)===s?null:o),R.success("Mallen togs bort.")}catch(o){R.error(o instanceof Error?o.message:"Kunde inte ta bort mallen.")}},le=n?`${n.subject} 2${n.body_source} 3${n.body_text} 4${n.signature_html}`:"",P=h.useMemo(()=>Qe(le),[le]),ie=h.useMemo(()=>{if(!n)return[];const s=[],o=n.source_format==="text"?n.body_text:n.body_source;if(o.trim()!=="")for(const u of te(o))s.push({where:"InnehÃ¥ll",text:u});if(n.subject.trim()!=="")for(const u of te(n.subject))s.push({where:"Ãmnesrad",text:u});if(n.signature_html.trim()!=="")for(const u of te(n.signature_html))s.push({where:"Signatur",text:u});return s},[n]),T=h.useMemo(()=>{if(!n)return null;if(n.source_format==="text"){const o=n.body_text||n.body_source;return ge(o,fe(),{escapeHtml:!1})}const s=n.signature_html.trim()===""?n.body_source:`${n.body_source} 5${n.signature_html}`;return ge(s,fe())},[n]),oe=h.useMemo(()=>!n||!T?"":n.source_format==="text"?`<pre style="font:14px/1.5 ui-monospace,Menlo,Consolas,monospace;white-space:pre-wrap;word-break:break-word;margin:0;padding:16px;color:#111">${nt(T.output)}</pre>`:T.output,[n,T]);return r?e.jsxs("div",{className:"space-y-3",children:[e.jsx(ce,{className:"h-16 w-full"}),e.jsx(ce,{className:"h-64 w-full"})]}):n?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>k(null),children:[e.jsx(ze,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"Tillbaka till mallarna"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.id&&e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>L({id:n.id,name:n.name}),children:[e.jsx(pe,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"Ta bort"]}),e.jsxs(A,{size:"sm",onClick:()=>void Ae(),disabled:x,children:[x&&e.jsx(Ce,{className:"h-4 w-4 mr-2 animate-spin","aria-hidden":"true"}),"Spara mall"]})]})]}),m.hadDangerousContent&&e.jsxs(W,{variant:"destructive",children:[e.jsx(me,{children:"InnehÃ¥ll som kan vara farligt togs bort"}),e.jsx(G,{className:"text-sm",children:"Servern hittade aktivt innehÃ¥ll i mallen â skript, händelseattribut eller liknande â och tog bort det innan mallen sparades. Kontrollera listan nedan och att mallen fortfarande gör det du tänkt dig."})]}),at(m)&&e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsx(w,{className:"text-base",children:"Detta togs bort ur mallen"}),e.jsx(D,{children:"Servern sanerar varje mall innan den sparas. Det som stÃ¥r här finns inte kvar i det som skickas."})]}),e.jsxs(_,{className:"space-y-3 text-sm",children:[m.removedTags.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Borttagna taggar"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.removedTags.map(s=>e.jsx($,{variant:"outline",className:"font-mono text-xs",children:s},s))})]}),m.removedAttributes.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Borttagna attribut"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:m.removedAttributes.map(s=>e.jsx($,{variant:"outline",className:"font-mono text-xs",children:s},s))})]}),m.blockedUrls.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Blockerade adresser"}),e.jsx("ul",{className:"space-y-1 text-muted-foreground break-all font-mono text-xs",children:m.blockedUrls.map(s=>e.jsx("li",{children:s},s))})]})]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsx(w,{className:"text-base",children:n.id?"Redigera mall":"Ny mall"}),e.jsx(D,{children:"Namn och kategori är till för dig, inte för mottagaren."})]}),e.jsxs(_,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-name",children:"Namn"}),e.jsx(b,{id:"tpl-name",value:n.name,onChange:s=>g("name",s.target.value),placeholder:"Svar pÃ¥ offertförfrÃ¥gan"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-description",children:"Beskrivning"}),e.jsx(b,{id:"tpl-description",value:n.description,onChange:s=>g("description",s.target.value),placeholder:"När mallen ska användas"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-category",children:"Kategori"}),e.jsx(b,{id:"tpl-category",list:"tpl-category-suggestions",value:n.category,onChange:s=>g("category",s.target.value),placeholder:"Allmänt"}),e.jsx("datalist",{id:"tpl-category-suggestions",children:et.map(s=>e.jsx("option",{value:s},s))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-language",children:"SprÃ¥k"}),e.jsxs(Y,{value:n.language,onValueChange:s=>g("language",s),children:[e.jsx(Z,{id:"tpl-language",children:e.jsx(J,{})}),e.jsx(Q,{children:Object.entries(je).map(([s,o])=>e.jsx(H,{value:s,children:o},s))})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-tags",children:"Taggar"}),e.jsx(b,{id:"tpl-tags",value:n.tags,onChange:s=>g("tags",s.target.value),placeholder:"offert, bygg, prio"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Separera med komma."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-format",children:"Format"}),e.jsxs(Y,{value:n.source_format,onValueChange:s=>g("source_format",s==="text"?"text":"html"),children:[e.jsx(Z,{id:"tpl-format",children:e.jsx(J,{})}),e.jsxs(Q,{children:[e.jsx(H,{value:"html",children:"HTML"}),e.jsx(H,{value:"text",children:"Ren text"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"MJML och ZIP-import finns inte än."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-status",children:"Status"}),e.jsxs(Y,{value:n.status,onValueChange:s=>g("status",s),children:[e.jsx(Z,{id:"tpl-status",children:e.jsx(J,{})}),e.jsx(Q,{children:Object.keys(K).map(s=>e.jsx(H,{value:s,children:K[s]},s))})]})]})]})]})]}),e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsx(w,{className:"text-base",children:"Avsändare och ämne"}),e.jsx(D,{children:"Det mottagaren ser i inkorgen innan mejlet öppnas."})]}),e.jsxs(_,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-subject",children:"Ãmnesrad"}),e.jsx(b,{id:"tpl-subject",value:n.subject,onChange:s=>g("subject",s.target.value),placeholder:"Tack för din förfrÃ¥gan, {{contact.first_name|hej}}"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-preview",children:"Preview-text"}),e.jsx(b,{id:"tpl-preview",value:n.preview_text,onChange:s=>g("preview_text",s.target.value),placeholder:"Raden som visas efter ämnet i inkorgen"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-from",children:"FrÃ¥nnamn"}),e.jsx(b,{id:"tpl-from",value:n.from_name,onChange:s=>
5g("from_name",s.target.value),placeholder:"Solnahallens VVS"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-replyto",children:"Reply-to"}),e.jsx(b,{id:"tpl-replyto",type:"email",value:n.reply_to,onChange:s=>g("reply_to",s.target.value),placeholder:"[email protected]"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-signature",children:"Signatur"}),e.jsx(z,{id:"tpl-signature",className:"font-mono text-xs min-h-[100px]",value:n.signature_html,onChange:s=>g("signature_html",s.target.value),placeholder:"<p>Med vänlig hälsning<br>{{business.name}}</p>"})]})]})]}),e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsx(w,{className:"text-base",children:"Innehåll"}),e.jsx(D,{children:"Textversionen går till mottagare som inte visar HTML. Lämnar du den tom skapar servern en ur HTML:en åt dig."})]}),e.jsxs(_,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-body",children:"HTML-innehåll"}),e.jsx(z,{id:"tpl-body",className:"font-mono text-xs min-h-[280px]",spellCheck:!1,value:n.body_source,onChange:s=>g("body_source",s.target.value),placeholder:`<p>Hej {{contact.first_name|där}},</p> 6<p>{{ai.reply}}</p>`})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(f,{htmlFor:"tpl-text",children:"Textversion"}),e.jsx(z,{id:"tpl-text",className:"font-mono text-xs min-h-[140px]",spellCheck:!1,value:n.body_text,onChange:s=>g("body_text",s.target.value),placeholder:`Hej {{contact.first_name|där}}, 7 8{{ai.reply}}`})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(N,{children:[e.jsx(C,{className:"pb-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(w,{className:"text-base",children:"Förhandsgranskning"}),e.jsx(D,{children:"Exempelvärden, inte riktiga kunduppgifter."})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(A,{variant:v==="desktop"?"secondary":"ghost",size:"sm",onClick:()=>q("desktop"),"aria-pressed":v==="desktop",children:[e.jsx(We,{className:"h-4 w-4 mr-1.5","aria-hidden":"true"}),"Desktop"]}),e.jsxs(A,{variant:v==="mobile"?"secondary":"ghost",size:"sm",onClick:()=>q("mobile"),"aria-pressed":v==="mobile",children:[e.jsx(Ge,{className:"h-4 w-4 mr-1.5","aria-hidden":"true"}),"Mobil"]})]})]})}),e.jsxs(_,{children:[oe.trim()===""?e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"Skriv något i innehållet så visas det här."}):e.jsx("div",{className:"rounded-md border bg-muted/40 p-3 dark:bg-muted/20",children:e.jsx("div",{className:"mx-auto transition-[width]",style:{width:v==="mobile"?390:"100%",maxWidth:"100%"},children:e.jsx("iframe",{sandbox:"",srcDoc:oe,title:"Förhandsgranskning",className:"w-full h-[480px] rounded border bg-white"})})}),T&&T.unresolved.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Visas tomma: ",T.unresolved.map(s=>`{{${s}}}`).join(", ")]})]})]}),ie.length>0&&e.jsxs(W,{children:[e.jsx(me,{children:"Det här stämmer inte i mallen"}),e.jsx(G,{children:e.jsx("ul",{className:"space-y-1 text-sm mt-1",children:ie.map(s=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[s.where,":"]})," ",s.text]},`${s.where}-${s.text}`))})})]}),e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsxs(w,{className:"text-base",children:["Variabler i mallen (",P.length.toLocaleString("sv-SE"),")"]}),e.jsx(D,{children:"Hittade i ämnesrad, innehåll, textversion och signatur."})]}),e.jsxs(_,{children:[P.length===0?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Inga variabler ännu. Skriv till exempel ","{{contact.first_name}}","."]}):e.jsx("ul",{className:"space-y-3",children:P.map(s=>{const o=I.find(u=>u.key===s.key);return e.jsxs("li",{className:"text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("code",{className:"font-mono text-xs bg-muted px-1.5 py-0.5 rounded dark:bg-muted/50",children:`{{${s.key}}}`}),o?e.jsx("span",{className:"font-medium",children:o.label}):e.jsx($,{variant:"destructive",children:"Okänd variabel"}),s.required&&e.jsx($,{variant:"outline",className:"text-amber-600 border-amber-600/40",children:"Krävs"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.occurrences.toLocaleStr
8ing("sv-SE")," gÃ¥nger"]})]}),o?e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[o.description," Exempel: ",o.example]}):e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Den här nyckeln finns inte i registret och blir tom i utskicket. Kontrollera stavningen."}),s.fallback!==null&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Reservtext: ",s.fallback]})]},s.key)})}),e.jsx(we,{className:"my-4"}),e.jsx("p",{className:"text-sm font-medium mb-2",children:"Alla variabler du kan använda"}),e.jsx("ul",{className:"space-y-1 text-xs",children:I.map(s=>e.jsxs("li",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("code",{className:"font-mono bg-muted px-1.5 py-0.5 rounded dark:bg-muted/50",children:`{{${s.key}}}`}),e.jsx("span",{className:"text-muted-foreground",children:s.label}),s.required&&e.jsx("span",{className:"text-amber-600 dark:text-amber-500",children:"krävs"})]},s.key))})]})]})]})]}),e.jsx(ye,{target:U,onCancel:()=>L(null),onConfirm:()=>void re()})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(N,{children:e.jsxs(_,{className:"flex flex-wrap items-center gap-3 py-4",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(De,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground","aria-hidden":"true"}),e.jsx(b,{className:"pl-9",placeholder:"Sök namn, kategori, ämneâ¦","aria-label":"Sök mallar",value:i,onChange:s=>p(s.target.value)})]}),e.jsxs(A,{onClick:Se,children:[e.jsx(Ee,{className:"h-4 w-4 mr-2","aria-hidden":"true"}),"Ny mall"]})]})}),c&&e.jsx(W,{variant:"destructive",children:e.jsx(G,{children:c})}),e.jsxs(N,{children:[e.jsxs(C,{className:"pb-3",children:[e.jsxs(w,{className:"flex items-center gap-2 text-base",children:[e.jsx(de,{className:"h-5 w-5 text-primary","aria-hidden":"true"}),B.length.toLocaleString("sv-SE")," mall",B.length===1?"":"ar"]}),e.jsx(D,{children:"Färdiga mejl med variabler. Servern sanerar varje mall innan den sparas."})]}),e.jsx(_,{children:B.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(de,{className:"h-12 w-12 mx-auto mb-3 opacity-50","aria-hidden":"true"}),e.jsx("p",{children:t.length===0?"Inga mallar ännu.":"Ingen mall matchar sökningen."}),e.jsx("p",{className:"text-sm",children:t.length===0?"Skapa en mall sÃ¥ kan arbetsflödena svara med den.":"Prova ett annat sökord."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Fe,{children:[e.jsx($e,{children:e.jsxs(ue,{children:[e.jsx(E,{children:"Namn"}),e.jsx(E,{children:"Kategori"}),e.jsx(E,{children:"Ãmnesrad"}),e.jsx(E,{children:"SprÃ¥k"}),e.jsx(E,{children:"Status"}),e.jsx(E,{children:"Uppdaterad"}),e.jsx(E,{className:"w-10",children:e.jsx("span",{className:"sr-only",children:"Ã
tgärder"})})]})}),e.jsx(Me,{children:B.map(s=>e.jsxs(ue,{className:"cursor-pointer",onClick:()=>Te(s),children:[e.jsx(F,{className:"font-medium",children:s.name}),e.jsx(F,{className:"text-xs",children:s.category||"â"}),e.jsx(F,{className:"text-xs max-w-[260px] truncate",children:s.subject??"â"}),e.jsx(F,{className:"text-xs",children:je[s.language]??s.language}),e.jsx(F,{children:rt(s.status)}),e.jsx(F,{className:"whitespace-nowrap text-xs",children:new Date(s.updated_at).toLocaleDateString("sv-SE")}),e.jsx(F,{children:e.jsx(A,{variant:"ghost",size:"icon","aria-label":`Ta bort ${s.name}`,onClick:o=>{o.stopPropagation(),L({id:s.id,name:s.name})},children:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"})})})]},s.id))})]})})})]}),e.jsx(ye,{target:U,onCancel:()=>L(null),onConfirm:()=>void re()})]})};export{ft 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.