1import{aD as D,aE as C,r as n,aF as H,aG as P,aM as B,ax as R,j as e}from"./vendor-CV6Imw16.js";import{e as z,f5 as U,L as w,f6 as q,m as G,f2 as V,f3 as $,aW as T,S as K,c as a,a as E,d as O,bz as W}from"./index-PbpNv9sZ.js";import{L as X}from"./index-gjDlR0dj.js";import{A as Y}from"./index-BmviHjOP.js";import{c as J}from"./signature.selector-DvVa1gBa.js";import"./tanstack-BgljnZ7t.js";import"./motion-Dmfi_Gss.js";import"./carousel-By_Kuq55.js";const Q=D({name:C({error:"Name is required"}).nonempty({message:"Name is required"}).max(64,{message:"Name is too long"}).regex(/^[a-z0-9_-]+$/i,{message:"Invalid key format"}),content:C({error:"HTML is required"}).nonempty({message:"HTML is required"}).max(3e4,{message:"HTML is too long"})});function Z({mode:r,initialData:t,onSuccess:i}){const l=z(),[o,c]=n.useState(!1),m={name:"",content:""},u=t?{name:t.name??"",content:t.content??""}:m,p=H({resolver:P(Q),defaultValues:m,mode:"onSubmit"}),{reset:x,handleSubmit:S,formState:f}=p;n.useEffect(()=>{if(r==="edit"&&t){x(u);return}r==="create"&&x(m)},[r,t,x]);const g=n.useCallback(async d=>{var b,v,j;c(!0);try{const h={name:d.name.trim(),content:d.content};r==="create"?(await l(U(h)).unwrap(),(b=w)==null||b("Signature created.",{variant:"success"})):t&&(await l(q({id:t.id,data:h})).unwrap(),(v=w)==null||v("Signature updated.",{variant:"success"})),i==null||i()}catch{(j=w)==null||j("Failed to save signature.",{variant:"error"})}finally{c(!1)}},[l,r,t,i]);return{submitting:o,form:p,formState:f,handleSubmit:S,onSubmit:g}}const ee=`<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"> 2 <tr> 3 <td style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #111111;"> 4 <strong>Best regards,</strong><br /> 5 Your Name<br /> 6 <span style="color:#6b7280;">Customer Support</span><br /> 7 <a href="mailto:[email protected]" style="color:#2563eb; text-decoration:none;"> 8 [email protected] 9 </a> 10 </td> 11 </tr> 12</table>`;function ce(){var M,I;const{id:r}=B(),t=r?"edit":"create",i=R(),l=z(),o=G(J),[c,m]=n.useState(t==="edit"),[u,p]=n.useState(null),[x,S]=n.useState(null);n.useEffect(()=>{o&&Object.keys(o).length||l(V({page:1,per_page:25}))},[l,o]),n.useEffect(()=>{if(t==="create")return;let s=!0;return(async()=>{var y;try{m(!0),p(null);const k=Number(r),A=await l($(k)).unwrap();if(!s)return;S({id:A.id,name:A.name??"",content:A.content??""})}catch{if(!s)return;p("Failed to load signature."),(y=w)==null||y("Failed to load signature.",{variant:"error"})}finally{s&&m(!1)}})(),()=>{s=!1}},[t,r,l]);const f=t==="create"?"Create signature":"Edit signature",{submitting:g,form:d,formState:b,handleSubmit:v,onSubmit:j}=Z({mode:t,initialData:t==="edit"?x??void 0:void 0,onSuccess:()=>i(T.ADMIN_SIGNATURES)}),h=n.useMemo(()=>Object.entries(o??{}).map(([y,k])=>({value:y,label:k})),[o]),_=d.watch("content")??"",F=()=>{d.setValue("content",ee,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})};return e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx(K,{title:`${f} â Admin`,description:"Admin signature upsert",noIndex:!0}),e.jsx(Y,{title:f,backTo:-1,titlesMap:{admin:"Admin",signatures:"Signatures",upsert:f},className:"mb-3 sm:mb-6"}),t==="edit"&&c&&!u&&e.jsx(te,{}),t==="edit"&&!c&&u&&e.jsxs("div",{className:a("space-y-3 rounded-2xl border p-4 text-sm","border-red-200 bg-red-50 text-red-700","dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200"),children:[e.jsx("div",{children:u}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(E,{size:"sm",variant:"secondary",className:"!text-xs",onClick:()=>i(T.ADMIN_SIGNATURES),children:"Back to list"})})]}),(t==="create"||t==="edit"&&!c&&!u&&x)&&e.jsxs("form",{onSubmit:v(j),className:a("w-full rounded-2xl border p-3.5 shadow-sm sm:p-4","border-(--ui-border) bg-(--ui-card) text-(--ui-text)"),children:[e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,1.35fr)]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(O,{form:d,name:"name",label:"Key (name)",placeholder:h.length?"Select keyâ¦":"Loading keysâ¦",options:h,size:"sm",disabled:t==="edit",allowDeselect:!1,clearable:!1,searchable:!0,getValue:s=>s.value,getLabel:s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 min-w-0",children:[e.jsx("span",{className:"truncate",children:s.label}),e.jsx("span",{className:"text-[11px] text-(--ui-text)/45",children:s.value})]}),getSearchText:s=>`${s.value} ${s.label}`,helperText:(M=b.errors.name)==null?void 0:M.message}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-(--ui-text)/80",children:"HTML (email-safe)"}),e.jsx(E,{type:"button",size:"sm",variant:"secondary",className:"max-w-[200px] text-xs!",onClick:F,children:"Paste example"})]}),e.jsx(W,{form:d,name:"content",label:"",placeholder:`<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"> 13 <tr> 14 <td style="font-family:Arial; font-size:14px;">... 15 </td> 16 </tr> 17</table>`,uiSize:"lg",rows:20,helperText:(I=b.errors.content)==null?void 0:I.message}),e.jsxs("div",{className:"text-xs text-(--ui-text)/45",children:["Tip: use ",e.jsx("b",{children:"table/tr/td"})," + inline styles."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium text-(--ui-text)/80",children:"Preview"}),e.jsx("div",{className:"text-xs text-(--ui-text)/45",children:"Email canvas"})]}),e.jsx("div",{className:a("rounded-2xl border p-2.5 sm:p-4","border-(--ui-border) bg-(--ui-surface)","not-dark"),children:e.jsx("div",{className:"mx-auto w-full rounded-xl border border-black/10 bg-white p-2.5 shadow-sm sm:p-4",children:e.jsx("div",{className:"email-preview max-w-full overflow-auto",dangerouslySetInnerHTML:{__html:_||"â"}})})})]})]}),e.jsxs("div",{className:a("mt-5 flex items-center justify-end gap-2 border-t pt-4 sm:mt-6 [&>button]:min-w-0 [&>button]:flex-1 sm:[&>button]:flex-none","border-(--ui-border-subtle)"),children:[e.jsx(E,{type:"button",size:"md",variant:"secondary",className:"max-w-[200px] text-sm!",onClick:()=>i(T.ADMIN_SIGNATURES),disabled:g,children:"Cancel"}),e.jsx(X,{type:"submit",size:"md",disabled:g,className:"max-w-[200px]",loading:g,loadingText:t==="create"?"Creatingâ¦":"Savingâ¦",children:t==="create"?"Create signature":"Save changes"})]})]})]})}const N="animate-pulse rounded bg-[var(--ui-skeleton)]",L="animate-pulse rounded bg-[var(--ui-skeleton-soft)]",te=()=>e.jsxs("div",{className:a("w-full rounded-2xl border p-4","border-(--ui-border) bg-(--ui-card) text-(--ui-text)"),"aria-busy":"true","aria-label":"Loading",children:[e.jsx("div",{className:a("mb-4 h-4 w-44",N)}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,1.35fr)]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:a("h-3 w-24",N)}),e.jsx("div",{className:a("h-10 w-full rounded-lg",L)}),e.jsx("div",{className:a("h-72 w-full rounded-lg",L)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:a("h-3 w-32",N)}),e.jsx("div",{className:a("h-80 w-full rounded-lg",L)})]})]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx("div",{className:a("h-9 w-36 rounded-full",N)})})]});
17export{te as UpsertSkeleton,ce 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.