"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),I=require("@aplus-frontend/antdv"),r=require("lodash-unified");require("../../../ag-grid/index.js");const p=require("../../../ap-modal/index.js");require("../../../config-provider/index.js");const H=require("../constants.js");require("../modal-layout/index.vue.js");const u=require("../utils.js");require("../wrapper/index.vue.js");const O=require("./use-ag-grid-instance.js"),G=require("./use-modal-title.js"),F=require("../../../config-provider/hooks/use-locale.js"),T=require("../wrapper/index.vue2.js"),j=require("../modal-layout/index.vue2.js"),N=require("../../../ag-grid/index.vue.js");function U(n){let c,m=null,y=null;const g=new u.AsyncCallback,[q,x]=G.useModalTitle(),{t:b}=F.useLocale(),[d,v]=O.useAgGridInstance({onSelectedRows(e){x.setCount(e?.length||0)}}),w=u.genRequest(n.api,n.getRowKey),h=e=>{const{title:t,width:l,modalProps:o,...a}=r.isFunction(e)?e(r.cloneDeep(n)):e;r.isEmpty(a)||y?.(a);const s=r.omitBy({title:t,width:l,modalProps:o},r.isUndefined);r.isEmpty(s)||m?.update(s)},f=r.isFunction(n.getRowKey)?n.getRowKey:e=>e[n.getRowKey],S=()=>{const e=n.mergeRule||"old",t=d.getSelectedRows()||[];return{keys:P(t),rows:t.map(a=>{const s=f(a);return e==="old"&&c?.[s]?c[s]:u.delRowKeyField(a)})}},C=async()=>{const e=S(),t=n.maxCount||1/0;return e.keys.length>t?(I.message.warning(b("ap.apTableModal.messageMaxCount",{maxCount:t})),Promise.reject()):(await n.beforeOk?.(e),n.finishCallback?.(e),g.resolve(e),e)},K=()=>{g.reject("modal is closed!")},k=i.defineComponent({name:"AgGridModalSelectContent",props:{modalConfig:{type:Object,required:!0},selectedRows:{type:Array,default:()=>[]}},setup(e){const t=i.ref(e.modalConfig);return y=l=>{t.value={...t.value,...l}},()=>{const l=e.selectedRows?.map(s=>u.addRowKeyField(s,t.value.getRowKey)),o=t.value,a=u.getModalLayoutConfig(o.modalLayout);return i.createVNode(v,null,{default:()=>[i.createVNode(T.default,{height:o.height,rowHeight:o.rowHeight,minHeight:t.value.minHeight,maxHeight:t.value.maxHeight},{default:()=>[n.renderHeader?.(r.omit(d,"setInstance"),{updateProps:h}),i.createVNode(j.default,a.props,{default:()=>[i.createVNode(N.default,i.mergeProps({ref:d.setInstance,searchForm:{sortable:!1,resize:{target:"form"}},rowKey:r.isFunction(o.getRowKey)?H.ROW_KEY:o.getRowKey,request:w.request,style:{padding:"0px"},rowHeight:o.rowHeight,columns:o.columns,rowSelection:{defaultSelectedRows:l,preserveSelectedRowKeys:!0,type:o.mode||"checkbox",fixed:"left",columnWidth:38,disabled(s){return r.isFunction(o.disabledCheckbox)?o.disabledCheckbox(s,r.omit(d,"setInstance")):o.disabledCheckbox??!1},...n.rowSelection},autoHeight:t.value.height==="auto",onModelUpdated:d.onAgGridUpdate},n.gridProps),o.gridSlots)],...a.slots})]})]})}}});function R(e){return i.createVNode(k,{modalConfig:n,selectedRows:e},null)}function M(){const e=Object.values(c||{}),t=R(e);m=p.ApModal.createModal({title:i.createVNode(q,{title:n.title,maxCount:n.maxCount||1/0,isShowDefaultSuffix:n.mode!=="radio"},n.modalTitleSlots),width:n.width,destroyOnClose:!0,maskClosable:!1,onOk:C,onCancel:K,afterOpenChange(l){l===!1&&d.setInstance(void 0)},content:t,...n.modalProps||{}})}function P(e){return e?.map(f)||[]}function _(e,t,l=!1){if(c=e?.reduce((o,a)=>{const s=f(a);return o[s]=a,o},{}),w.setExtraParams(t?.extraParams),M(),l)return g.buildPromise()}function A(e,t){return _(e,t,!0)}return i.onUnmounted(()=>{g.reject("component is Unmounted!")}),{open:_,asyncOpen:A,refresh:d.refresh,getAgGridInstance:d.getInstance,genContent:R,validate:C,updateProps:h}}exports.useAgGridSelectModal=U;
