import{d as F,i as A,D as q,o as l,a as V,w as a,c as t,f as D,n as $,M,G as j,H as I,E as w,J as c,L as R,m as O,Q as G,T as H,B as L,U as J,V as K,q as Q,j as _,k as y,b as z,x as W,e as P,F as B,t as X,at as Y,au as Z,a4 as ee,av as te}from"./index.29cf2edd.js";/* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              */import{_ as ne}from"./SingleUploader.2fcaa0e4.js";/* empty css              */const ae=D("Cancel"),oe=D("Save"),se=F({__name:"InsuranceForm",props:{visible:{type:Boolean,required:!0}},emits:["change"],setup(U,{emit:g}){const r=A(),n=q({photo:"",name:"",description:""}),o=A(""),d={photo:{required:!0,message:"Please upload photo"},name:{required:!0,message:"Please enter name"},description:{required:!0,message:"Please enter description"}},T=()=>{if(!o.value)return $.warn("Please upload photo");r.value.validateFields().then(p=>{M.confirm({title:"\u0E97\u0EC8\u0EB2\u0E99\u0E95\u0EC9\u0EAD\u0E87\u0E81\u0EB2\u0E99\u0E9A\u0EB1\u0E99\u0E97\u0EB6\u0E81\u0EC1\u0E97\u0EC9\u0E9A\u0ECD\u0EC8?",icon:t(j),content:t("div",{style:"color:red;"},"\u0E81\u0EBB\u0E94\u0E9B\u0EB8\u0EC8\u0EA1 'OK' \u0EC0\u0E9E\u0EB7\u0EC8\u0EAD\u0EA2\u0EB7\u0E99\u0EA2\u0EB1\u0E99"),onOk(){n.photo=o.value,I(),w.addInsuranceType(n).then(async u=>{c(),N(),$.success("Add new insurance success"),g("change",!0)}).catch(u=>{c()})},onCancel(){},class:""})}).catch(p=>{})},C=()=>{g("change",!1)},S=p=>{o.value=p},N=()=>{n.photo="",n.name="",n.description=""};return(p,u)=>{const e=R,s=O,m=G,v=H,k=L,x=J,b=K;return l(),V(b,{title:"Add New Insurance",width:540,visible:U.visible,"body-style":{paddingBottom:"80px"},"footer-style":{textAlign:"right"},onClose:C},{extra:a(()=>[t(x,null,{default:a(()=>[t(k,{onClick:C},{default:a(()=>[ae]),_:1}),t(k,{type:"primary",onClick:T},{default:a(()=>[oe]),_:1})]),_:1})]),default:a(()=>[t(v,{ref_key:"formRef",ref:r,model:n,rules:d,layout:"vertical"},{default:a(()=>[t(e,{label:"Photo"},{default:a(()=>[t(ne,{text:"Upload Photo",onUpload:S})]),_:1}),t(e,{label:"Name",name:"name"},{default:a(()=>[t(s,{value:n.name,"onUpdate:value":u[0]||(u[0]=f=>n.name=f)},null,8,["value"])]),_:1}),t(e,{label:"Description",name:"description"},{default:a(()=>[t(m,{value:n.description,"onUpdate:value":u[1]||(u[1]=f=>n.description=f),rows:4,placeholder:"Please enter description"},null,8,["value"])]),_:1})]),_:1},8,["model"])]),_:1},8,["visible"])}}}),ie={class:"text-right",style:{"margin-bottom":"10px"}},le=D("Add New Insurance"),ue=["src"],ce={key:1},re=D("Save"),_e=y("a",null,"Cancel",-1),pe=["onClick"],de=y("a",null,"Delete",-1),Ae=F({__name:"InsuranceType",setup(U){const g=[{title:"ID",dataIndex:"id",key:"id"},{title:"Photo",dataIndex:"photo",key:"photo"},{title:"Name",dataIndex:"name",key:"name"},{title:"Action",key:"action"}];let r=A();const n=A(!1),o=q({});Q(()=>{d()});const d=()=>{I(),w.getInstanceTypes().then(e=>{c();const s=e.data;r.value=s}).catch(e=>{c(),$.error(e.message)})},T=e=>{o[e]=Y(r.value.filter(s=>e===s.id)[0])},C=async e=>{const s={id:e,name:o[e].name};I(),await w.saveInsuranceType(s).then(m=>{c(),$.success("Saved"),Object.assign(r.value.filter(v=>e===v.id)[0],o[e]),delete o[e]}).catch(m=>{c()})},S=e=>{delete o[e]},N=async e=>{I(),await w.deleteInsuranceType(e).then(s=>{c(),d()}).catch(s=>{c()})},p=()=>{n.value=!0},u=e=>{n.value=!1,e&&d()};return(e,s)=>{const m=L,v=O,k=Z,x=ee,b=te,f=W;return l(),_("div",null,[y("div",ie,[t(m,{type:"primary",onClick:p},{default:a(()=>[le]),_:1})]),t(f,{columns:g,"data-source":z(r)},{bodyCell:a(({column:h,text:me,record:i})=>[h.key==="photo"?(l(),_("img",{key:0,src:i.photo,width:"100"},null,8,ue)):P("",!0),h.key==="name"?(l(),_(B,{key:1},[o[i.id]?(l(),V(v,{key:0,value:o[i.id][h.dataIndex],"onUpdate:value":E=>o[i.id][h.dataIndex]=E,style:{margin:"-5px 0"}},null,8,["value","onUpdate:value"])):(l(),_("span",ce,X(i.name),1))],64)):P("",!0),h.key==="action"?(l(),_(B,{key:2},[o[i.id]?(l(),_(B,{key:0},[t(k,{onClick:E=>C(i.id)},{default:a(()=>[re]),_:2},1032,["onClick"]),t(x,{type:"vertical"}),t(b,{title:"Sure to cancel?",onConfirm:E=>S(i.id)},{default:a(()=>[_e]),_:2},1032,["onConfirm"])],64)):(l(),_(B,{key:1},[y("span",null,[y("a",{onClick:E=>T(i.id)},"Edit",8,pe)]),t(x,{type:"vertical"}),t(b,{title:"Sure to delete?",onConfirm:E=>N(i.id)},{default:a(()=>[de]),_:2},1032,["onConfirm"])],64))],64)):P("",!0)]),_:1},8,["data-source"]),t(se,{visible:n.value,onChange:u},null,8,["visible"])])}}});export{Ae as default};
