import{am as _,cj as L,ak as w,al as $,k as q,u as B,a as K,a9 as I,ap as C,a7 as h,af as N,aw as R}from"./app-Bei_nIK3.js";function z(p,s){var o;return _(p,function(i,A,v){return o=s(i,A,v),!o}),!!o}function D(p,s,o){var i=$(p)?L:z;return i(p,w(s))}const Q=(p="")=>{const s=q(!1),o=q({}),{t:i}=B(),{appSetting:A}=K(),v=q(p),y=r=>Array.from(r).map(l=>l.querySelector("label").getAttribute("for").replace("form_item_","").trim()),M=r=>{if(r.length===0)return"";const l=r.map(a=>a.split("-")),m=Math.min(...l.map(a=>a.length));let u=[];for(let a=0;a<m;a++){const t=l[0][a];if(l.every(e=>e[a]===t))u.push(t);else break}return u.join("-")+"-"},T=r=>{const m=document.getElementById(r).querySelectorAll(".ant-tabs-tabpane"),u=Array.from(m).filter(e=>{const c=e.querySelectorAll(".ant-form-item-label");return y(c).length>0}).map(e=>e.id),a=M(u);return Array.from(m).filter(e=>{const c=e.querySelectorAll(".ant-form-item-label");return y(c).length>0}).map(e=>{const f=!!e.getAttribute("class").includes("ant-tabs-tabpane-active"),n=e.getAttribute("id").replace(a,""),b=e.querySelectorAll(".ant-form-item-label");return{tab:n,fields:y(b),active:f}})};return{loading:s,rules:o,addEditActiveTab:v,addEditRequestAdmin:r=>{s.value=!0;const{url:l,data:m,success:u}=r;var a={};I(m,function(t,e){t==null?a[e]=null:a[e]=t}),axiosAdmin.post(l,a).then(t=>{r.successMessage&&C.success({placement:A.value.rtl?"bottomLeft":"bottomRight",message:i("common.success"),description:r.successMessage}),u(t.data),s.value=!1,o.value={}}).catch(t=>{var e=t.data;const c=t.status;var f={};if(c==422){if(e.error&&typeof e.error.details<"u")for(var d=Object.keys(e.error.details),n=0;n<d.length;n++){var b=d[n];f[b]={required:!0,message:e.error.details[d[n]][0]}}o.value=f,h.error(i("common.fix_errors"))}if(e&&e.message&&(h.error(e.message),e={error:{...e}}),r.error&&r.error(e),r.id){const E=T(r.id),x=Object.keys(o.value),F=N(E,["active",!0]),S=N(E,g=>!g.active&&D(x,P=>R(g.fields,P)));F!=null&&D(x,g=>R(F.fields,g))?v.value=F.tab:S!=null&&(v.value=S.tab)}s.value=!1})},addEditFileRequestAdmin:r=>{s.value=!0;const{url:l,data:m,success:u}=r,a=new FormData;I(m,function(t,e){t==null?a.append(e,null):e=="file"?a.append(e,t.originFileObj):a.append(e,t)}),axiosAdmin.post(l,a,{headers:{"Content-Type":"multipart/form-data"}}).then(t=>{r.successMessage&&C.success({placement:A.value.rtl?"bottomLeft":"bottomRight",message:i("common.success"),description:r.successMessage}),u(t.data),s.value=!1,o.value={}}).catch(t=>{var e=t.data;const c=t.status;var f={};if(c==422){if(e.error&&typeof e.error.details<"u")for(var d=Object.keys(e.error.details),n=0;n<d.length;n++){var b=d[n].replace(".","\\.");f[b]={required:!0,message:e.error.details[d[n]][0]}}o.value=f,h.error(i("common.fix_errors"))}e&&e.message&&(h.error(e.message),e={error:{...e}}),r.error&&r.error(e),s.value=!1})}}};export{Q as a,D as s};
