ruạṛ
import{u as S,aj as E,b3 as V,p as h,j as b,H as F,c as l,bv as D,I as P,b5 as $,b6 as k,b9 as H,J as M,eb as N,g0 as R,bb as o,g1 as v,be as T}from"./bundle.9abe88c8.js";function z(i){const[p]=S(),r=E(),g=V(),{disabled:d}=i,u=i.defaultVariables,[x,C]=h.useState(u);h.useEffect(()=>{var e,s;const a=((s=(e=r==null?void 0:r.settings)==null?void 0:e.pdf_variables)==null?void 0:s[i.for])??[];C(u.filter(t=>!a.includes(t.value)))},[r]);const _=a=>u.find(e=>e.value===a),j=a=>{var t,n,f,c;const e=a.target.options[a.target.selectedIndex];if(e.value==="")return;const s=o.cloneDeep(r);s.settings.pdf_variables||(o.set(s,"settings.pdf_variables",{}),(n=(t=s.settings)==null?void 0:t.pdf_variables)!=null&&n[i.for]||o.set(s,`settings.pdf_variables.${i.for}`,[])),(c=(f=s.settings.pdf_variables)==null?void 0:f[i.for])==null||c.push(e.value),g(v({object:"company",data:s})),a.target.value=""},y=a=>{var t;const e=o.cloneDeep(r),s=(t=e.settings.pdf_variables)==null?void 0:t[i.for].filter(n=>n!==a);o.set(e,`settings.pdf_variables.${i.for}`,s),g(v({object:"company",data:e}))},I=a=>{var t,n;const e=o.cloneDeep(r),s=T((t=e.settings.pdf_variables)==null?void 0:t[i.for],a.source.index,(n=a.destination)==null?void 0:n.index);o.set(e,`settings.pdf_variables.${i.for}`,s),g(v({object:"company",data:e}))};return b(F,{children:[l(D,{leftSide:p("fields"),children:b(P,{onChange:j,disabled:d,children:[l("option",{}),x.map((a,e)=>l("option",{value:a.value,children:a.label},e))]})}),l(D,{leftSide:p("variables"),children:l($,{onDragEnd:I,children:l(k,{droppableId:i.for,isDropDisabled:d,children:a=>{var e,s,t;return b("div",{...a.droppableProps,ref:a.innerRef,children:[(t=(s=(e=r==null?void 0:r.settings)==null?void 0:e.pdf_variables)==null?void 0:s[i.for])==null?void 0:t.map((n,f)=>l(H,{draggableId:n,index:f,isDragDisabled:d,children:c=>{var m;return h.createElement("div",{...c.draggableProps,...c.dragHandleProps,ref:c.innerRef,className:"flex items-center justify-between space-y-6",key:n},b("div",{className:"flex items-center space-x-2",children:[l(M,{type:"minimal",onClick:()=>y(n),behavior:"button",disableWithoutIcon:d,disabled:d,children:l(N,{})}),l("span",{children:(m=_(n))==null?void 0:m.label})]}),l(R,{size:16}))}},n)),a.placeholder]})}})})})]})}export{z as S};
cải xoăn