import{a as V,o as A,h as r,i as H,j as v,m as t,p as f,k as n,F,a3 as w,Q as z,v as P,s as m,t as g,z as x,D as b,E as _}from"./index-DAvBaevK.js";import{a as Z}from"./QSelect-Bmx_AjWr.js";import{Q as j}from"./QPage-B68JuyjH.js";import{u as I}from"./use-quasar-B5tVCAcV.js";import{e as R}from"./api-RGUeM09o.js";import{_ as q}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./format-DaKpMo2W.js";import"./position-engine-BHgB6lrx.js";import"./selection-DrSF90ET.js";const O={class:"mail-debug-shell"},U={key:0,class:"error-box"},G={key:1,class:"empty-state"},J={key:2,class:"preview-grid"},K={class:"meta-column"},W={key:0,class:"meta-line"},X={key:1,class:"meta-line"},Y={class:"preview-column"},ee=["srcdoc"],ae=V({__name:"MailDebugPage",setup(le){const M=I(),p=b(!1),o=b([]),s=b(null),u=b(""),$=_(()=>o.value.map((a,e)=>({label:N(a.name||`Mail ${e+1}`).displayName,value:e}))),i=_(()=>s.value===null?null:o.value[s.value]??null),c=_(()=>i.value?N(i.value.name):{displayName:"",email:null,localDate:null}),S=_(()=>C(i.value?.content??""));function C(a){const e='<base target="_blank" rel="noopener noreferrer">';return/<base\s/i.test(a)?a:/<head[^>]*>/i.test(a)?a.replace(/<head[^>]*>/i,l=>`${l}${e}`):`${e}${a}`}function N(a){const e=a.replace(/\.eml$/i,""),l=e.match(/^(\d{10,20})_(.+)$/);let d=e,y=null;l?.[1]&&l[2]&&(y=l[1],d=l[2]);const k=d.replace(/_at_/gi,"@"),h=k.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/),E=(y?L(y):null)??Q(e);return{displayName:h?.[0]??k,email:h?h[0]:null,localDate:E}}function L(a){const e=Number(a);if(!Number.isFinite(e))return null;let l=e;a.length>=19?l=Math.floor(e/1e6):a.length>=16?l=Math.floor(e/1e3):a.length<=10&&(l=e*1e3);const d=new Date(l);return Number.isNaN(d.getTime())?null:d.toLocaleString()}function Q(a){const e=a.match(/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?)/);if(e)return D(e[0]);const l=a.match(/(\d{4}-\d{2}-\d{2}[ _]\d{2}[-:]\d{2}[-:]\d{2})/);return l?D(l[0]):null}function D(a){const e=a.replace(" ","T").replace(/(T\d{2})-(\d{2})-(\d{2})$/,"$1:$2:$3"),l=new Date(e);return Number.isNaN(l.getTime())?a:l.toLocaleString()}async function T(){p.value=!0,u.value="";try{const a=await R();if(a.error){u.value=a.error,o.value=[],s.value=null;return}o.value=Array.isArray(a.data)?a.data:[],s.value=o.value.length>0?0:null}catch(a){u.value=a instanceof Error?a.message:String(a),o.value=[],s.value=null}finally{p.value=!1}}async function B(){if(i.value)try{await navigator.clipboard.writeText(i.value.content),M.notify({type:"positive",message:"HTML copiato negli appunti",position:"top-right"})}catch{M.notify({type:"negative",message:"Copia non riuscita",position:"top-right"})}}return A(async()=>{await T()}),(a,e)=>(r(),H(j,{class:"mail-debug-page"},{default:v(()=>[t("div",O,[e[5]||(e[5]=t("header",{class:"mail-debug-header"},[t("p",{class:"eyebrow"},"Developer tools"),t("h1",null,"Mail Debug"),t("p",{class:"subtitle"},[f(" Seleziona una mail da "),t("strong",null,"/maildebug"),f(" e visualizza l'HTML renderizzato. ")])],-1)),n(F,{flat:"",bordered:"",class:"mail-debug-card"},{default:v(()=>[n(w,{class:"controls"},{default:v(()=>[n(z,{color:"primary",icon:"refresh",label:"Aggiorna lista",loading:p.value,onClick:T},null,8,["loading"]),n(Z,{modelValue:s.value,"onUpdate:modelValue":e[0]||(e[0]=l=>s.value=l),options:$.value,"option-label":"label","option-value":"value","emit-value":"","map-options":"",outlined:"",dense:"",label:"Seleziona mail",class:"mail-select",disable:p.value||o.value.length===0},null,8,["modelValue","options","disable"])]),_:1}),n(P),n(w,null,{default:v(()=>[u.value?(r(),m("div",U,g(u.value),1)):i.value?(r(),m("div",J,[t("div",K,[e[3]||(e[3]=t("p",{class:"meta-label"},"Nome mail",-1)),t("h2",null,g(c.value.displayName),1),c.value.email?(r(),m("p",W,[e[1]||(e[1]=t("strong",null,"Email:",-1)),f(" "+g(c.value.email),1)])):x("",!0),c.value.localDate?(r(),m("p",X,[e[2]||(e[2]=t("strong",null,"Data locale:",-1)),f(" "+g(c.value.localDate),1)])):x("",!0),n(z,{flat:"",color:"secondary",icon:"content_copy",label:"Copia HTML",onClick:B})]),t("div",Y,[e[4]||(e[4]=t("p",{class:"meta-label"},"Render HTML",-1)),t("iframe",{class:"preview-frame",srcdoc:S.value,sandbox:"allow-popups allow-popups-to-escape-sandbox",title:"Mail HTML preview"},null,8,ee)])])):(r(),m("div",G,"Nessuna mail selezionata."))]),_:1})]),_:1})])]),_:1}))}}),ve=q(ae,[["__scopeId","data-v-1b5b3a76"]]);export{ve as default};
