import{h as k,ax as Z,d as K,ar as ee,A as m,bn as i,bq as A,bu as w,bo as u,bp as b,aa as O,a9 as l,a4 as _,N as te,br as V,bs as D,bw as ae,r as ne}from"./preload-helper.BAt0wiQU.js";import{p as M,s as N}from"../apps/settings/index.DetZ7Cvo.js";import{_ as se}from"./GroupEditFields.vue_vue_type_script_setup_true_lang.DMTRA1Ra.js";import{A as z}from"./index.D7cceZEv.js";import{E as oe}from"./EditOutlined.BkDHNOZt.js";import{D as ie}from"./DeleteOutlined.zUdmm4WX.js";import{A as le}from"./index.D6Cza-ao.js";var re={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184zm456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840zM512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144zm0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z"}}]},name:"save",theme:"outlined"};function L(c){for(var o=1;o<arguments.length;o++){var r=arguments[o]!=null?Object(arguments[o]):{},p=Object.keys(r);typeof Object.getOwnPropertySymbols=="function"&&(p=p.concat(Object.getOwnPropertySymbols(r).filter(function(v){return Object.getOwnPropertyDescriptor(r,v).enumerable}))),p.forEach(function(v){ce(c,v,r[v])})}return c}function ce(c,o,r){return o in c?Object.defineProperty(c,o,{value:r,enumerable:!0,configurable:!0,writable:!0}):c[o]=r,c}var x=function(o,r){var p=L({},o,r.attrs);return k(Z,L({},p,{icon:re}),null)};x.displayName="SaveOutlined";x.inheritAttrs=!1;const de={key:0,class:"editable-row-operations"},ue={class:"editable-cell"},fe=["loading","onClick"],pe=["onClick"],ve={key:0},ye=["innerHTML"],me={key:1},be=["innerHTML"],je=K({__name:"DataTableControl",props:{params:{type:Object,required:!0},data:{type:Object,required:!0},editFields:{type:Object,required:!1,default:()=>({})}},emits:["fieldData","fieldUpdatedData","fieldUpdatedPopupData","fieldDeletedData"],setup(c,{emit:o}){var P,T;const r=c,{params:p,data:v,editFields:U}=ee(r),f=p.value,$=m((P=f.paginated)!=null?P:!1),q=f.fields,B=m(f.classes),g=m(v),E=f.editable,F=f.can_delete,I=f.edit_action,R=f.delete_action,C=m((T=f.inline_edit)!=null?T:!0),j=m(!1),d=ne([]),h=o,S=m([]),J=e=>{for(const[a,n]of Object.entries(e))S.value[a]=n},G=e=>{d[e]=window.lodash.cloneDeep(g.value.filter(a=>e===a.key)[0]),S.value=d[e],C.value===!1?h("fieldUpdatedPopupData",d[e]):h("fieldUpdatedData",d[e])},Q=async e=>{const a=[{key:"action",value:I}],n={};n.key=e;for(const[t,s]of Object.entries(S.value)){let y=s;typeof s=="object"&&s!==null&&(y=JSON.stringify(s)),a.push({key:t,value:y}),n[t]=s}try{await N(a)==="success"&&h("fieldUpdatedData",n)}catch(t){console.error(t)}finally{j.value=!1}delete d[e]},W=async e=>{const a=g.value.filter(t=>e===t.key)[0],n=[{key:"action",value:R}];for(const[t,s]of Object.entries(a))n.push({key:t,value:s});try{await N(n)==="success"&&h("fieldDeletedData",e)}catch(t){console.error(t)}finally{j.value=!1}},X=e=>{delete d[e]},Y=e=>{const a=[];for(const[n,t]of Object.entries(U.value))a[t.id]=t;return typeof a[e]<"u"?a[e]:{}},H=e=>Array.isArray(e)?e.join(", "):e;return(e,a)=>(i(),A(l(le),{class:ae(B.value),"data-source":g.value,columns:l(q),pagination:$.value,bordered:""},{bodyCell:w(({column:n,text:t,record:s})=>[n.key==="operation"?(i(),u("div",de,[b("div",ue,[d[s.key]&&C.value?(i(),u(O,{key:0},[b("a",{loading:j.value,onClick:y=>Q(s.key)},[k(l(x))],8,fe),a[0]||(a[0]=_("   ",-1)),k(l(z),{title:"Sure to cancel?",onConfirm:y=>X(s.key)},{default:w(()=>[b("a",null,[k(l(te))])]),_:1},8,["onConfirm"])],64)):(i(),u(O,{key:1},[l(E)?(i(),u("a",{key:0,onClick:y=>G(s.key)},[k(l(oe))],8,pe)):V("",!0),a[1]||(a[1]=_("   ",-1)),l(F)?(i(),u(O,{key:1},[g.value.length?(i(),A(l(z),{key:0,title:"Sure to delete?",onConfirm:y=>W(s.key)},{default:w(()=>[b("a",null,[k(l(ie))])]),_:1},8,["onConfirm"])):V("",!0)],64)):V("",!0)],64))])])):(i(),u(O,{key:1},[C.value?(i(),u("div",ve,[d[s.key]?(i(),A(se,{key:0,"editable-data":d[s.key],"field-value":d[s.key][n.dataIndex],"field-data":Y(n.field),onFieldUpdatedData:J},null,8,["editable-data","field-value","field-data"])):(i(),u(O,{key:1},[_(D(n.prefix)+" ",1),b("span",{innerHTML:l(M)(H(t))},null,8,ye),_(" "+D(n.suffix),1)],64))])):(i(),u("div",me,[_(D(n.prefix)+" ",1),b("span",{innerHTML:l(M)(H(t))},null,8,be),_(" "+D(n.suffix),1)]))],64))]),_:1},8,["class","data-source","columns","pagination"]))}});export{je as _};
