1import{aZ as x,b0 as R,bd as M,aQ as l,be as D,b7 as o,b8 as u,aT as e,bA as F,aX as w,c1 as q,bJ as L,bH as K,a_ as A,aR as r,aS as m,bg as U,bh as j,aY as d,aV as k}from"./CN4ZE-vz.js";import{_ as G}from"./Cam2duvV.js";import{u as E,B as N,G as H}from"./D9TP0lxc.js";import{_ as O}from"./Ppiahs0P.js";import{_ as $}from"./B5m8rn9-.js";import{c as Y}from"./BX4B6Lv2.js";import{T as Z}from"./CjQD3EYF.js";import"./DQfWpKHy.js";import"./Duduxpha.js";import"./C12XAJdh.js";import"./BNXvtYLC.js";import"./PnwMnPXZ.js";import"./DwFc3Pcp.js";import"./ElNFAgva.js";import"./CC0q4xU1.js";import"./CfbobgoO.js";const J=Y("SquarePenIcon",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a2.121 2.121 0 1 1 3 3L12 15l-4 1 1-4Z",key:"1lpok0"}]]),Q={class:"bg-gray-100 rounded-t-2xl p-4 px-6 flex items-center justify-between"},X={class:"p-6 space-y-4"},W={class:"p-4 px-6 flex items-center justify-between border-t border-gray-200"},ee={__name:"EditTemplateModal",props:{open:{type:Boolean,default:!1},template:{type:Object,default:null}},emits:["close","updated"],setup(C,{emit:_}){const i=C,b=_,h=L(),S=E(),a=x({name:"",description:"",category:""}),y=x(!1),f=[{value:"",label:"No category"},{value:"domestic",label:"Domestic"},{value:"regional",label:"Regional"},{value:"international",label:"International"},{value:"special",label:"Special"}],g=()=>{a.value={name:"",description:"",category:""},b("close")},V=async()=>{if(!(!a.value.name?.trim()||!i.template?.id)){y.value=!0;try{const p={name:a.value.name.trim(),description:a.value.description?.trim()||null,category:a.value.category||null};await S.updateTemplate(i.template.id,p),h.success("Template updated successfully"),b("updated"),g()}catch(p){h.error(p?.data?.message||p?.message||"Failed to update template")}finally{y.value=!1}}};return R(()=>i.open,p=>{p&&i.template?a.value={name:i.template.name||"",description:i.template.description||"",category:i.template.category||""}:a.value={name:"",description:"",category:""}}),(p,n)=>{const z=M("font-awesome-icon"),v=M("FormKit"),T=F,c=O;return l(),D(q,{to:"body"},[o(c,{open:C.open,size:"lg","no-padding":!0,onClose:g},{default:u(()=>[o(v,{type:"form",actions:!1,onSubmit:V},{default:u(()=>[e("div",Q,[n[3]||(n[3]=e("div",null,[e("div",{class:"text-sm font-semibold text-gray-900"},"Edit Template"),e("p",{class:"text-xs text-gray-500 mt-0.5"}," Update the template details. ")],-1)),e("button",{type:"button",class:"text-gray-400 hover:text-gray-900 transition-colors",onClick:g},[o(z,{icon:"fal fa-times"})])]),e("div",X,[o(v,{type:"text",name:"name",label:"Template Name",validation:"required|length:3,255",placeholder:"e.g., UK & Europe Shipping",modelValue:a.value.name,"onUpdate:modelValue":n[0]||(n[0]=t=>a.value.name=t)},null,8,["modelValue"]),o(v,{type:"textarea",name:"description",label:"Description (optional)",placeholder:"Describe when to use this template...",modelValue:a.value.description,"onUpdate:modelValue":n[1]||(n[1]=t=>a.value.description=t)},null,8,["modelValue"]),o(v,{type:"select",name:"category",label:"Category (optional)",options:f,modelValue:a.value.category,"onUpdate:modelValue":n[2]||(n[2]=t=>a.value.category=t)},null,8,["modelValue"])]),e("div",W,[o(T,{type:"button","btn-style":"secondary",size:"sm",onClick:g},{default:u(()=>[...n[4]||(n[4]=[w("Cancel",-1)])]),_:1}),o(T,{type:"submit","btn-style":"primary",size:"sm",loading:y.value},{default:u(()=>[...n[5]||(n[5]=[w(" Save Changes ",-1)])]),_:1},8,["loading"])])]),_:1})]),_:1},8,["open"])])}}},te={class:"max-w-4xl mx-auto px-4 pb-12"},se={key:0,class:"bg-white rounded-2xl border border-gray-200/80 shadow-sm p-8"},ae={key:1,class:"space-y-6"},oe={class:"bg-white rounded-2xl border border-gray-200/80 shadow-sm overflow-hidden"},le={class:"px-6 py-5 border-b border-gray-100"},ne={class:"flex items-center gap-3"},re={class:"w-10 h-10 rounded-xl bg-gray-100 flex items-center justify-center"},ie={key:0,class:"p-12 text-center"},de={key:1,class:"divide-y divide-gray-100"},ce={class:"flex-1 min-w-0"},me={class:"flex items-center gap-2"},pe={class:"font-medium text-gray-900"},ue={key:0,class:"text-sm text-gray-500 mt-1"},ye={class:"flex gap-4 mt-2 text-xs text-gray-400"},ge={class:"flex items-center gap-2"},fe={class:"bg-white rounded-2xl border border-gray-200/80 shadow-sm overflow-hidden"},ve={class:"px-6 py-5 border-b border-gray-100"},xe={class:"flex items-center gap-3"},_e={class:"w-10 h-10 rounded-xl bg-gray-100 flex items-center justify-center"},be={class:"p-6"},he={key:0,class:"text-center py-6 text-gray-400 text-sm"},we={key:1,class:"grid grid-cols-1 md:grid-cols-2 gap-3"},Te={class:"font-medium text-sm text-gray-900"},ke={key:0,class:"text-xs text-gray-500 mt-0.5"},Ce={class:"flex gap-2 mt-2"},qe={__name:"shipping-templates",setup(C){const _=L(),i=E(),{userTemplates:b,platformTemplates:h,isLoading:S}=K(i),a=x(null),y=x(!1),f=x(!1),g=x(!1),V=async()=>{try{await i.fetchTemplates()}catch{_.error("Failed to load templates")}
1},p=c=>{a.value=c,y.value=!0},n=c=>{a.value=c,f.value=!0},z=async()=>{if(a.value?.id){g.value=!0;try{await i.deleteTemplate(a.value.id),_.success("Template deleted"),f.value=!1,a.value=null}catch(c){_.error(c?.data?.message||c?.message||"Failed to delete template")}finally{g.value=!1}}},v=()=>{y.value=!1,a.value=null},T={domestic:"Domestic",regional:"Regional",international:"International",special:"Special"};return A(V),(c,t)=>{const B=F,P=G;return l(),r("div",te,[t[8]||(t[8]=e("div",{class:"mb-8"},[e("h1",{class:"text-2xl font-semibold text-gray-900 tracking-tight"},"Shipping Templates"),e("p",{class:"text-gray-500 mt-1"},"Manage your saved shipping configurations")],-1)),m(S)?(l(),r("div",se,[...t[2]||(t[2]=[e("div",{class:"flex justify-center items-center py-12"},[e("div",{class:"flex flex-col items-center gap-3"},[e("div",{class:"w-8 h-8 border-2 border-gray-200 border-t-gray-900 rounded-full animate-spin"}),e("span",{class:"text-sm text-gray-500"},"Loading templates...")])],-1)])])):(l(),r("div",ae,[e("div",oe,[e("div",le,[e("div",ne,[e("div",re,[o(m(N),{class:"h-5 w-5 text-gray-600"})]),t[3]||(t[3]=e("div",null,[e("h2",{class:"font-semibold text-gray-900"},"My Templates"),e("p",{class:"text-sm text-gray-500"},"Templates you've saved from your order forms")],-1))])]),m(b).length===0?(l(),r("div",ie,[o(m(N),{class:"h-12 w-12 mx-auto text-gray-300 mb-4"}),t[4]||(t[4]=e("p",{class:"text-gray-500 mb-2"},"You haven't saved any templates yet.",-1)),t[5]||(t[5]=e("p",{class:"text-sm text-gray-400"}," Save shipping configurations from your order forms to reuse them later. ",-1))])):(l(),r("div",de,[(l(!0),r(U,null,j(m(b),s=>(l(),r("div",{key:s.id,class:"px-6 py-4 flex items-start justify-between gap-4"},[e("div",ce,[e("div",me,[e("h4",pe,d(s.name),1),s.category?(l(),D($,{key:0,size:"xs",color:"gray",rounded:""},{default:u(()=>[w(d(T[s.category]||s.category),1)]),_:2},1024)):k("",!0)]),s.description?(l(),r("p",ue,d(s.description),1)):k("",!0),e("div",ye,[e("span",null,d(s.summary?.profiles_count||0)+" profile(s)",1),e("span",null,d(s.summary?.zones_count||0)+" zone(s)",1),e("span",null,d(s.summary?.rates_count||0)+" rate(s)",1),e("span",null,"Used "+d(s.usage_count||0)+" time(s)",1)])]),e("div",ge,[o(B,{"btn-style":"ghost",size:"sm",onClick:I=>p(s)},{default:u(()=>[o(m(J),{class:"h-4 w-4"})]),_:2},1032,["onClick"]),o(B,{"btn-style":"ghost",size:"sm",class:"text-red-600 hover:text-red-700 hover:bg-red-50",onClick:I=>n(s)},{default:u(()=>[o(m(Z),{class:"h-4 w-4"})]),_:2},1032,["onClick"])])]))),128))]))]),e("div",fe,[e("div",ve,[e("div",xe,[e("div",_e,[o(m(H),{class:"h-5 w-5 text-gray-600"})]),t[6]||(t[6]=e("div",null,[e("h2",{class:"font-semibold text-gray-900"},"Platform Templates"),e("p",{class:"text-sm text-gray-500"},"Pre-built templates provided by Beventi")],-1))])]),e("div",be,[t[7]||(t[7]=e("p",{class:"text-sm text-gray-500 mb-4"}," Platform templates are available when you apply a template to any order form. They provide common shipping configurations for different regions. ",-1)),m(h).length===0?(l(),r("div",he," No platform templates available. ")):(l(),r("div",we,[(l(!0),r(U,null,j(m(h),s=>(l(),r("div",{key:s.id,class:"border border-gray-200 rounded-lg p-3"},[e("p",Te,d(s.name),1),s.description?(l(),r("p",ke,d(s.description),1)):k("",!0),e("div",Ce,[o($,{size:"xs",color:"gray",rounded:""},{default:u(()=>[w(d(s.summary?.zones_count||0)+" zones ",1)]),_:2},1024),s.summary?.currency?(l(),D($,{key:0,size:"xs",color:"gray",rounded:""},{default:u(()=>[w(d(s.summary.currency),1)]),_:2},1024)):k("",!0)])]))),128))]))])])])),o(ee,{open:y.value,template:a.value,onClose:t[0]||(t[0]=s=>y.value=!1),onUpdated:v},null,8,["open","template"]),o(P,{open:f.value,title:"Delete Template",text:`Are you sure you want to delete '${a.value?.name}'? This action cannot be undone.`,"confirm-text":"Delete",loading:g.value,onClose:t[1]||(t[1]=s=>f.value=!1),onConfirm:z},null,8,["open","text","loading"])])}}};export{qe 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.