import{_ as N}from"./BaseForm.vue_vue_type_script_setup_true_lang-BnxGTisD.js";import{T as g,U as R,H as k,d as h,I as j,q,f as z,h as A,v as a,i as l,c as r,x as T,V as H,y as M}from"./index-C5GbdPxY.js";import{u as P}from"./form-B2je8iBR.js";import{a as d,V as B}from"./VAvatar-RkAR0u0e.js";import{c as E,V as G,a as J}from"./VCard-DptrO3GI.js";import{V as f}from"./VTextField-DxEUpn3-.js";import{V as K}from"./VCheckbox-rNAD_QU_.js";function O(i,o=!1){return g.get(`/v1/loyalty-programs/${i}`,{params:{return_all_translations:o}})}function Q(i,o){return g.put(`/v1/loyalty-programs/${i}`,o)}function W(i){return g.post("/v1/loyalty-programs",i)}function X(){return g.get("/v1/loyalty-programs/form/meta")}function Y(){const i=R(),{t:o}=k();return{getShowData:async(V,b=!1)=>{var y,p;try{return{status:200,data:(await O(V,b)).data.body}}catch(e){return((y=e==null?void 0:e.response)==null?void 0:y.status)!==404&&i.error(o("core::errors.an_unexpected_error_occurred")),{status:(p=e==null?void 0:e.response)==null?void 0:p.status}}},update:Q,store:W,getFormMeta:X}}const Z={class:"d-flex align-center"},le=h({__name:"Form",props:{item:{},action:{}},setup(i){var v,x,w,U,C,S,$,F;const o=i,{t:u}=k(),{update:V,store:b}=Y(),y=j(),p=q(),e=P({name:((v=o.item)==null?void 0:v.name)||{},earning_rate:(w=(x=o.item)==null?void 0:x.earning_rate)==null?void 0:w.amount,redemption_rate:(C=(U=o.item)==null?void 0:U.redemption_rate)==null?void 0:C.amount,min_redeem_points:(S=o.item)==null?void 0:S.min_redeem_points,points_expire_after:($=o.item)==null?void 0:$.points_expire_after,is_active:((F=o.item)==null?void 0:F.is_active)||!1}),D=async()=>{!e.loading.value&&await e.submit(()=>{var c;return o.action=="create"?b(e.state):V((c=o.item)==null?void 0:c.id,e.state)})&&await y.push({name:"admin.loyalty_programs.index"})};return(c,n)=>{const I=N;return A(),z(I,{action:c.action,"has-multiple-language":"",loading:a(e).loading.value,resource:"loyalty_programs",onSubmit:D},{default:l(({currentLanguage:_})=>[r(B,null,{default:l(()=>[r(d,{cols:"12"},{default:l(()=>[r(E,null,{default:l(()=>[r(G,{class:"d-flex justify-space-between align-center mb-2"},{default:l(()=>[T("div",Z,[r(H,{class:"me-2",icon:"tabler-info-circle",size:"20"}),T("span",null,M(a(u)("loyalty::loyalty_programs.form.cards.loyalty_program_information")),1)])]),_:1}),r(J,null,{default:l(()=>[r(B,null,{default:l(()=>[r(d,{cols:"12",md:"6"},{default:l(()=>{var t,s;return[r(f,{modelValue:a(e).state.name[_.id],"onUpdate:modelValue":m=>a(e).state.name[_.id]=m,error:!!((t=a(e).errors.value)!=null&&t[`name.${_.id}`]),"error-messages":(s=a(e).errors.value)==null?void 0:s[`name.${_.id}`],label:a(u)("loyalty::attributes.loyalty_programs.name")+` ( ${_.name} )`},null,8,["modelValue","onUpdate:modelValue","error","error-messages","label"])]}),_:2},1024),r(d,{cols:"12",md:"6"},{default:l(()=>{var t,s;return[r(f,{modelValue:a(e).state.earning_rate,"onUpdate:modelValue":n[0]||(n[0]=m=>a(e).state.earning_rate=m),error:!!((t=a(e).errors.value)!=null&&t.earning_rate),"error-messages":(s=a(e).errors.value)==null?void 0:s.earning_rate,label:a(u)("loyalty::attributes.loyalty_programs.earning_rate"),prefix:a(p).currency},null,8,["modelValue","error","error-messages","label","prefix"])]}),_:1}),r(d,{cols:"12",md:"6"},{default:l(()=>{var t,s;return[r(f,{modelValue:a(e).state.redemption_rate,"onUpdate:modelValue":n[1]||(n[1]=m=>a(e).state.redemption_rate=m),error:!!((t=a(e).errors.value)!=null&&t.redemption_rate),"error-messages":(s=a(e).errors.value)==null?void 0:s.redemption_rate,label:a(u)("loyalty::attributes.loyalty_programs.redemption_rate"),prefix:a(p).currency},null,8,["modelValue","error","error-messages","label","prefix"])]}),_:1}),r(d,{cols:"12",md:"6"},{default:l(()=>{var t,s;return[r(f,{modelValue:a(e).state.min_redeem_points,"onUpdate:modelValue":n[2]||(n[2]=m=>a(e).state.min_redeem_points=m),error:!!((t=a(e).errors.value)!=null&&t.min_redeem_points),"error-messages":(s=a(e).errors.value)==null?void 0:s.min_redeem_points,label:a(u)("loyalty::attributes.loyalty_programs.min_redeem_points")},null,8,["modelValue","error","error-messages","label"])]}),_:1}),r(d,{cols:"12",md:"6"},{default:l(()=>{var t,s;return[r(f,{modelValue:a(e).state.points_expire_after,"onUpdate:modelValue":n[3]||(n[3]=m=>a(e).state.points_expire_after=m),error:!!((t=a(e).errors.value)!=null&&t.points_expire_after),"error-messages":(s=a(e).errors.value)==null?void 0:s.points_expire_after,label:a(u)("loyalty::attributes.loyalty_programs.points_expire_after")},null,8,["modelValue","error","error-messages","label"])]}),_:1}),r(d,{cols:"12"},{default:l(()=>[r(K,{modelValue:a(e).state.is_active,"onUpdate:modelValue":n[4]||(n[4]=t=>a(e).state.is_active=t),label:a(u)("loyalty::attributes.loyalty_programs.is_active")},null,8,["modelValue","label"])]),_:1})]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:2},1024)]),_:1},8,["action","loading"])}}});export{le as _,Y as u};
