import{d as P,ar as G,bm as H,r as D,A as m,bn as s,bo as n,bp as c,aa as u,by as k,bs as v,a9 as l,h as y,bu as g,bw as J,br as p,a4 as h,bq as Q}from"../../../../common/preload-helper.BAt0wiQU.js";import{u as W}from"../../../../common/settings-store.DAVbzJl3.js";import{d as X}from"../../../../common/DnDDataTableControl.vue_vue_type_style_index_0_scoped_0b913e4f_lang.CI1SyTf2.js";import{s as w}from"../../index.CwVZreOu.js";import{E as Y}from"../../../../common/EditOutlined.BkDHNOZt.js";import{D as Z}from"../../../../common/DeleteOutlined.zUdmm4WX.js";import{A as ee}from"../../../../common/index.D7cceZEv.js";import{_ as te}from"../../../../common/_plugin-vue_export-helper.DlAUqK2U.js";import"../../../../common/index.Bkgl5HZD.js";import"../../../../common/motion.DDNFslEg.js";import"../../../../common/index.BQlS3R_s.js";import"../../../../common/index.2Llx5d_f.js";import"../../../../common/useState.9-uUdCQD.js";import"../../../../common/warning.Dss1f44C.js";import"../../../../common/compact-item.CKdY6bQm.js";import"../../../../common/createContext.DKLY0CB7.js";import"../../../../common/useMergedState.BxRmC9rL.js";import"../../../../common/KeyCode.D63Tfrq7.js";import"../../../../common/ActionButton.8y06aWcB.js";const ae={class:"wwp-full-width-table"},oe={class:"thead-dark"},re={key:0,class:"editable-row-operations"},se={key:0,class:"editable-cell"},ne=["onClick"],ie=P({__name:"DnDDataTableControl",props:{params:{type:Object,required:!0},data:{type:Object,required:!0},editFields:{type:Object,required:!1,default:()=>({})},editedFields:{type:Number,required:!1,default:0}},emits:["fieldUpdatedData","fieldDeletedData","updateDataSource"],setup(C,{emit:A}){const S=C,{params:V,data:q,editedFields:E}=G(S),O=W(),{inlineMappingEdit:T}=H(O),d=V.value,B=d.fields,i=D({data:window.lodash.sortBy(q.value,t=>typeof t.field_order<"u"&&t.field_order!==null?t.field_order:0)}),N=d.editable,F=d.can_delete,R=d.delete_action,j=d.sort_action,x=m(d.show_in_table),U=m(!1),b=D([]),I=E,f=A,_=m([]),L=t=>{b[t]=window.lodash.cloneDeep(i.data.filter(o=>t===o.key)[0]),_.value=b[t],T.value=!1,f("fieldUpdatedData",_.value)},$=async t=>{const o=i.data.filter(a=>t===a.key)[0],e=[{key:"action",value:R}];for(const[a,r]of Object.entries(o))e.push({key:a,value:r});try{await w(e)==="success"&&(f("fieldDeletedData",t),i.data=i.data.filter(r=>r.key!==t))}catch(a){console.error(a)}finally{U.value=!1}},z=t=>Array.isArray(t)?t.join(", "):t,K=async t=>{const o=[{key:"action",value:j}],e="list",a=i.data;o.push({key:e,value:a});try{const r=await w(o,!1,!0);typeof r<"u"&&r!==null&&f("updateDataSource",r)}catch(r){console.error(r)}finally{}};return(t,o)=>(s(),n("table",ae,[c("thead",oe,[c("tr",null,[(s(!0),n(u,null,k(l(B),(e,a)=>(s(),n("th",{key:a,scope:"col"},v(e.title),1))),128))])]),y(l(X),{modelValue:i.data,"onUpdate:modelValue":o[0]||(o[0]=e=>i.data=e),tag:"tbody","item-key":"name",onEnd:K},{item:g(({element:e})=>[c("tr",{class:J({"not-draggable":!(e!=null&&e.draggable)})},[(s(!0),n(u,null,k(x.value,(a,r)=>(s(),n("td",{key:r,scope:"row"},[a==="operation"?(s(),n("div",re,[l(I)===null?(s(),n("div",se,[l(N)?(s(),n("a",{key:0,onClick:M=>L(e.key)},[y(l(Y))],8,ne)):p("",!0),o[1]||(o[1]=h("   ",-1)),l(F)&&(e==null?void 0:e.deletetable)!=="no"?(s(),n(u,{key:1},[i.data.length?(s(),Q(l(ee),{key:0,title:"Sure to delete?",onConfirm:M=>$(e.key)},{default:g(()=>[c("a",null,[y(l(Z))])]),_:1},8,["onConfirm"])):p("",!0)],64)):p("",!0)])):p("",!0)])):(s(),n(u,{key:1},[h(v(z(e[a])),1)],64))]))),128))],2)]),_:1},8,["modelValue"])]))}}),Ve=te(ie,[["__scopeId","data-v-0b913e4f"]]);export{Ve as default};
