import{t as re,at as $,aq as z,aY as ee,av as se,W as le,w as de,x as ue,aZ as ce,aw as te,z as m,az as pe,aA as he,aB as oe,aC as fe,G,H as V,ax as ge,Y as W,a4 as Q,aD as Y,aI as ve,aJ as ye,a_ as J,a$ as me,l as P,J as be,L as Te,am as ae,aE as Pe,aQ as Fe,aK as Ce,v as Se,b0 as Ae,D as C,Q as S,T as h,U as Oe,E as Ie,aR as Qe,b1 as Re,aL as De}from"./index-CEmnTf-r.js";import{o as xe}from"./omitBy-CdFgv6uo.js";var ke=["selectedChange","columnSort","columnFilter","columnSearch","columnToggled","orderChange","rowClick","rowDbClick","rowMouseEnter","rowMouseLeave","selected"],Ne=function(R){re(d,R);function d(t){var e=R.call(this,t)||this;e.stopingAutoRefresh=!1;var a=t.location,r=t.store,s=t.syncLocation,n=t.pageField,l=t.perPageField;t.parsePrimitiveQuery;var o=e.getParseQueryOptions(t);e.mounted=!0,s&&a&&(a.query||a.search)?r.updateQuery($(a,o),void 0,n,l):s&&!a&&window.location.search&&r.updateQuery($(window.location,o),void 0,n,l),e.props.api&&e.props.store.updateData({items:[]});var i=t.mode,p=t.columns;return i==="table2"&&p&&r.updateColumns(p),e}return d.prototype.componentDidMount=function(){var t=this.props,e=t.store,a=t.pickerMode,r=t.loadType,s=t.loadDataOnce,n=t.maxLoadNum,l=r&&!s;if(l){var o=r==="more"?this.props.perPage||10:this.getPaginationPerPage();e.changePage(e.page,o)}else r||e.changePage(1,n||500);if(this.initQuery({}),a){var i=z(this.props);i&&e.setSelectedItems(i)}},d.prototype.componentDidUpdate=function(t){var e,a=this.props,r=t.store;a.parsePrimitiveQuery,t.columns!==a.columns&&r.updateColumns(a.columns);var s;this.props.pickerMode&&ee(s=z(this.props),z(t))&&r.setSelectedItems(s);var n=!1;if(t.syncLocation&&t.location&&t.location.search!==a.location.search&&(r.updateQuery($(a.location,this.getParseQueryOptions(a)),void 0,a.pageField,a.perPageField),n=!!(a.api&&se(r.query,this.lastQuery,!1))),!n){if(t.api&&a.api&&le(t.api,a.api,r.fetchCtxOf(t.data,{pageField:t.pageField,perPageField:t.perPageField}),r.fetchCtxOf(a.data,{pageField:a.pageField,perPageField:a.perPageField})))n=!0;else if(!a.api&&de(a.source)){var l=ue(a.source,a.data,"| raw");(!this.lastData||this.lastData!==l)&&(r.initFromScope(a.data,a.source,{columns:(e=r.columns)!==null&&e!==void 0?e:a.columns}),this.lastData=l)}}n&&this.getData()},d.prototype.componentWillUnmount=function(){this.mounted=!1,clearTimeout(this.timer)},d.prototype.getPaginationPerPage=function(){var t=10,e=this.props,a=e.headerToolbar,r=e.footerToolbar;return ce({headerToolbar:a,footerToolbar:r},function(s,n,l){n==="type"&&s==="pagination"&&!isNaN(l==null?void 0:l.perPage)&&(t=+l.perPage)}),t},d.prototype.getParseQueryOptions=function(t){var e,a=t.parsePrimitiveQuery,r={parsePrimitive:!!(te(a)?a!=null&&a.enable:a),primitiveTypes:(e=a==null?void 0:a.types)!==null&&e!==void 0?e:["boolean"]};return r},d.prototype.controlRef=function(t){for(;t&&t.getWrappedInstance;)t=t.getWrappedInstance();this.control=t},d.prototype.initQuery=function(t){var e=this.props,a=e.store,r=e.orderBy,s=e.orderDir,n=e.loadType,l={};r&&(l.orderBy=r,l.orderDir=s||"asc"),this.handleSearch({query:m(m(m({},l),t),a.query),replaceQuery:this.props.initFetch!==!1,loadMore:n==="more",resetPage:!1}),a.setPristineQuery()},d.prototype.handleLoadMore=function(){var t=this.props,e=t.store,a=t.perPage,r=a===void 0?10:a;e.changePage(e.page+1,r),this.getData(void 0,void 0,void 0,!0)},d.prototype.handleSearch=function(t){var e,a,r=this.props,s=r.store,n=r.syncLocation,l=r.env,o=r.pageField,i=r.perPageField,p=r.parsePrimitiveQuery,c=this.getParseQueryOptions(this.props),g=t||{},u=g.query,f=g.resetQuery,y=g.replaceQuery,b=g.loadMore,v=g.resetPage;u=m(m({},u),pe((a=(e=u==null?void 0:u.__super)===null||e===void 0?void 0:e.diff)!==null&&a!==void 0?a:{},function(F){return F===void 0})),u=n?he(oe(u,void 0,!0)):u,p&&(u=fe(u,c)),s.updateQuery(f?m(m({},u),this.props.store.pristineQuery):u,n&&l&&l.updateLocation?function(F){return l.updateLocation(F,!0)}:void 0,o,i,y),v&&s.changePage(1),this.lastQuery=s.query,this.getData(void 0,void 0,void 0,b??!1)},d.prototype.handleStopAutoRefresh=function(){this.timer&&clearTimeout(this.timer),this.stopingAutoRefresh=!0},d.prototype.handleStartAutoRefresh=function(){this.stopingAutoRefresh=!1,this.reload()},d.prototype.reloadTarget=function(t,e){},d.prototype.closeTarget=function(t){},d.prototype.updateQuery=function(t){this.props.store},d.prototype.getData=function(t,e,a,r){var s,n,l;return a===void 0&&(a=!1),G(this,void 0,void 0,function(){var o,i,p,c,g,u,f,y,b,v,F,D,T,A,O,_,B,w,I,U,M,E;return V(this,function(L){switch(L.label){case 0:return o=this.props,i=o.store,p=o.api,c=o.messages,g=o.pageField,u=o.perPageField,f=o.interval,y=o.stopAutoRefreshWhen,b=o.silentPolling,o.syncLocation,v=o.syncResponse2Query,F=o.keepItemSelectionOnPageChange,D=o.stopAutoRefreshWhenModalIsOpen,T=o.pickerMode,o.env,A=o.loadType,O=o.loadDataOnce,_=o.source,B=o.columns,w=o.perPage,I=o.pullRefresh,!r&&F&&e&&!T&&(i.setSelectedItems([]),i.setUnSelectedItems([])),clearTimeout(this.timer),this.lastQuery=i.query,U=r??A==="more",M=Q(i.data,i.query),U&&w&&i.changePerPage(w),W(p,M)?[4,i.fetchInitData(p,M,{successMessage:c&&c.fetchSuccess,errorMessage:c&&c.fetchFailed,autoAppend:!0,forceReload:a,loadDataOnce:O,source:_,silent:t,pageField:g,perPageField:u,loadDataMode:U,dataAppendTo:(I==null?void 0:I.dataAppendTo)||"bottom",syncResponse2Query:v,columns:(s=i.columns)!==null&&s!==void 0?s:B,isTable2:!0,minLoadingTime:I==null?void 0:I.minLoadingTime})]:[3,2];case 1:return E=L.sent(),E!=null&&E.ok&&f&&!this.stopingAutoRefresh&&this.mounted&&(!y||!(y&&De(y,Q(i.data,i.query))))&&(!D||!i.dialogOpen&&!(!((n=i==null?void 0:i.parentStore)===null||n===void 0)&&n.dialogOpen))&&(this.timer=setTimeout(this.getData.bind(this,b,void 0,!0),Math.max(f,1e3))),[3,3];case 2:_&&i.initFromScope(M,_,{columns:(l=i.columns)!==null&&l!==void 0?l:B}),L.label=3;case 3:return[2,i.data]}})})},d.prototype.handleChangePage=function(t,e){var a,r=this.props,s=r.store,n=r.syncLocation,l=r.env,o=r.pageField,i=r.perPageField,p=r.autoJumpToTopOnPagerChange,c=(a={},a[o||"page"]=t,a);if(e&&(c[i||"perPage"]=e),s.updateQuery(c,n&&(l!=null&&l.updateLocation)?l.updateLocation:void 0,o,i),s.changePage(t,e),this.getData(),p&&this.control){ge.findDOMNode(this.control).scrollIntoView();var g=window.scrollY;g&&window.scroll(0,g)}},d.prototype.handleSave=function(t,e,a,r,s,n){var l=this,o=this.props,i=o.store,p=o.quickSaveApi,c=o.quickSaveItemApi,g=o.primaryField,u=o.env,f=o.messages,y=o.reload;if(Array.isArray(t)){if(!W(p)){u&&u.alert("CRUD quickSaveApi is required");return}var b=Q(i.data,{rows:t,rowsDiff:e,indexes:a,rowsOrigin:s});t.length&&t[0].hasOwnProperty(g||"id")&&(b.ids=t.map(function(D){return D[g||"id"]}).join(",")),r&&(b.unModifiedItems=r),i.saveRemote(p,b,{successMessage:f&&f.saveFailed,errorMessage:f&&f.saveSuccess}).then(function(){y&&l.reloadTarget(Y(y,b),b),l.getData(void 0,void 0,!0)}).catch(function(){})}else{if(!W(c)){u&&u.alert("CRUD quickSaveItemApi is required!");return}var v=Q(i.data,{item:t,modified:e,origin:s}),F=Q(v,t);i.saveRemote(c,F).then(function(){y&&l.reloadTarget(Y(y,v),v),l.getData(void 0,void 0,!0)}).catch(function(){n!=null&&n.resetOnFailed&&l.control.reset()})}},d.prototype.handleSaveOrder=function(t,e){var a=this,r=this.props,s=r.store,n=r.saveOrderApi,l=r.orderField,o=r.primaryField,i=r.env,p=r.reload;if(!n){i&&i.alert("CRUD saveOrderApi is required!");return}var c=Q(s.data),g,u,f=[],y=o&&e[0]&&e[0].hasOwnProperty(o);if(y||(c.idMap={}),c.insertAfter={},e.forEach(function(T){if(~t.indexOf(T))if(g){var A=y?g[o]:e.indexOf(g);c.insertAfter[A]=c.insertAfter[A]||[],y||(c.idMap[A]=g),c.insertAfter[A].push(y?T[o]:T)}else f.push(T);else g=T,u=u||T}),u&&f.length){var b=y?u[o]:e.indexOf(u);y||(c.idMap[b]=u),c.insertBefore={},c.insertBefore[b]=f.map(function(T){return y?T[o]:T})}else if(f.length){var v=f[0],F=y?v[o]:e.indexOf(v);y||(c.idMap[F]=v),c.insertAfter[F]=f.slice(1).map(function(T){return y?T[o]:T})}if(l){var D=(s.page-1)*s.perPage||0;e=e.map(function(T,A){var O;return ve(T,(O={},O[l]=D+A+1,O))})}c.rows=e.concat(),y&&(c.ids=e.map(function(T){return T[o]}).join(",")),y&&l&&(c.order=e.map(function(T){return ye(T,[o,l])})),W(n,c)&&s.saveRemote(n,c).then(function(){p&&a.reloadTarget(Y(p,c),c),a.getData(void 0,void 0,!0)}).catch(function(){})},d.prototype.handleSelect=function(t,e){var a=this.props,r=a.store,s=a.keepItemSelectionOnPageChange,n=a.primaryField,l=a.multiple,o=a.pickerMode,i=a.onSelect,p=t,c=e;if(ee(r.selectedItemsAsArray,p)){if(s&&r.selectedItems.length){var g=r.selectedItems.concat(),u=r.unSelectedItems.concat();t.forEach(function(f){var y=J(g,function(v){return v===f||v[n||"id"]&&v[n||"id"]==f[n||"id"]});~y?g[y]=f:g.push(f);var b=J(u,function(v){return v===f||v[n||"id"]&&v[n||"id"]==f[n||"id"]});~b&&u.splice(b,1)}),e.forEach(function(f){var y=J(u,function(v){return v===f||v[n||"id"]&&v[n||"id"]==f[n||"id"]}),b=J(g,function(v){return v===f||v[n||"id"]&&v[n||"id"]==f[n||"id"]});~y?u[y]=f:u.push(f),!~y&&~b&&g.splice(b,1)}),p=g,c=u}o&&l===!1&&p.length>1&&c.push.apply(c,p.splice(0,p.length-1)),r.setSelectedItems(p),r.setUnSelectedItems(c),i&&i(p)}},d.prototype.handleQuerySearch=function(t,e){var a;e===void 0&&(e=!1);var r=this.props,s=r.store,n=r.syncLocation,l=r.env,o=r.pageField,i=r.perPageField;return s.updateQuery(m(m({},t),(a={},a[o||"page"]=1,a)),n&&l&&l.updateLocation?l.updateLocation:void 0,o,i),this.getData(void 0,void 0,e)},d.prototype.reload=function(t,e){return e?this.receive(e):this.getData(void 0,void 0,!0)},d.prototype.receive=function(t){return this.handleQuerySearch(t,!0)},d.prototype.doAction=function(t,e,a){if(t.actionType&&["stopAutoRefresh","reload","search","startAutoRefresh","loadMore"].includes(t.actionType))return this["handle".concat(me(t.actionType))](e)},d.prototype.handleAction=function(t,e,a,r,s){return r===void 0&&(r=!1),["stopAutoRefresh","reload","search","startAutoRefresh","loadMore"].includes(e.actionType)?this.doAction(e,a,r):this.props.onAction(t,e,a,r,s||this.context)},d.prototype.dispatchEvent=function(t,e,a,r){if(t==="selectedChange"&&this.control===a){var s=this.props.store;e.selectedItems=s.selectedItems.concat(),e.unSelectedItems=s.unSelectedItems.concat()}return this.props.dispatchEvent(t,e,a,r)},d.prototype.unSelectItem=function(t,e){var a=this.props.store,r=a.selectedItems.concat(),s=a.unSelectedItems.concat(),n=r.indexOf(t);~n&&s.push.apply(s,r.splice(n,1)),a.setSelectedItems(r),a.setUnSelectedItems(s)},d.prototype.clearSelection=function(){var t=this.props.store,e=t.selectedItems.concat(),a=t.unSelectedItems.concat();t.setSelectedItems([]),t.setUnSelectedItems(a.concat(e))},d.prototype.toggleAllColumns=function(t){var e=this.props.store;e.updateColumns(e.columns.map(function(a){return m(m({},a),{toggled:t})}))},d.prototype.toggleToggle=function(t){var e=this.props.store,a=e.columns[t],r=a.toggled;e.updateColumns(e.columns.map(function(s,n){return m(m({},s),{toggled:t===n?!r:s.toggled!==!1})}))},d.prototype.handlePullRefresh=function(){return G(this,void 0,void 0,function(){var t,e,a,r;return V(this,function(s){switch(s.label){case 0:return t=this.props,e=t.dispatchEvent,a=t.data,[4,e("pullRefresh",a)];case 1:return r=s.sent(),r!=null&&r.prevented?[2]:(this.handleLoadMore(),[2])}})})},d.prototype.renderChild=function(t,e,a){a===void 0&&(a={});var r=this.props,s=r.render,n=r.store,l=r.primaryField,o=l===void 0?"id":l,i,p=n.selectedItems,c=n.unSelectedItems,g=n.items;/^filter/.test(t)?i=Q(Q(n.filterData,n.getData(this.props.data)),{}):i=Q(n.mergedData,{items:g.concat(),selectedItems:p.concat(),unSelectedItems:c.concat(),ids:p.map(function(f){return f.hasOwnProperty(o)?f[o]:null}).filter(function(f){return f}).join(",")});var u={activePage:n.page,lastPage:n.lastPage,perPage:n.perPage,total:n.total,onPageChange:this.handleChangePage,cols:n.columns,toggleAllColumns:this.toggleAllColumns,toggleToggle:this.toggleToggle,onQuery:this.handleQuerySearch};return e.type,s(t,e,m(m({data:i},a),u))},d.prototype.renderToolbar=function(t,e){var a=this;return e?(e=[].concat(e),e.map(function(r,s){return a.renderChild("".concat(t,"/").concat(s),r,{key:s+""})})):null},d.prototype.renderFilter=function(t){var e=this;if(!t||Array.isArray(t)&&t.length===0)return null;var a=Array.isArray(t)?t:te(t)&&t.type!=null?[t]:[];return a.length<1?null:a.map(function(r,s){return e.renderChild("filter/".concat(s),r,m({key:s+"filter",data:e.props.store.filterData,onSubmit:function(n){return e.handleSearch({query:n,resetPage:!0})},onReset:function(n){var l={};Object.keys(n).forEach(function(o){return l[o]=""}),e.handleSearch({query:l,resetQuery:!0,replaceQuery:!0,resetPage:!0})}},e.props.mobileUI?{columnCount:1,mode:"normal",collapsible:!0,title:{type:"container",body:[{type:"icon",icon:"column-filter",className:"icon mr-2"},r.title||""]}}:{}))})},d.prototype.renderSelection=function(){var t=this,e=this.props,a=e.store,r=e.classnames,s=e.labelField,n=e.labelTpl,l=e.primaryField,o=e.translate,i=e.env;return a.selectedItems.length?P.createElement("div",{className:r("Crud-selection")},P.createElement("div",{className:r("Crud-selectionLabel")},o("CRUD.selected",{total:a.selectedItems.length})),a.selectedItems.map(function(p,c){return P.createElement("div",{key:c,className:r("Crud-value")},P.createElement("span",{"data-tooltip":o("delete"),"data-position":"bottom",className:r("Crud-valueIcon"),onClick:t.unSelectItem.bind(t,p,c)},"×"),P.createElement("span",{className:r("Crud-valueLabel")},n?P.createElement(be,{html:Te(n,p),filterHtml:i.filterHtml}):ae(p,s||"label")||ae(p,l||"id")))}),P.createElement("a",{onClick:this.clearSelection.bind(this),className:r("Crud-selectionClear")},o("clear"))):null},d.prototype.transformTable2cards=function(){for(var t,e=this.props,a=e.store,r=e.columns,s=e.card,n=e.mobileMode,l=[],o=n.fieldCount||4,i=[],p="",c=((t=a.columns)!==null&&t!==void 0?t:r)||[],g=0;g0&&i.page>=i.lastPage,completedText:i.total>0?void 0:""}),X):P.createElement(P.Fragment,null,X,P.createElement("div",{className:v("Crud2-toolbar","Crud2-footer-toolbar",E)},this.renderToolbar("footerToolbar",U))))},d.propsList=["mode","syncLocation","value","multiple","valueField","pageField","perPageField","hideQuickSaveBtn","autoJumpToTopOnPagerChange","interval","silentPolling","stopAutoRefreshWhen","stopAutoRefreshWhenModalIsOpen","api","headerToolbar","footerToolbar","autoGenerateFilter","syncResponse2Query","keepItemSelectionOnPageChange","source","onChange","onInit","onSaved","onQuery","autoFillHeight","showSelection","headerToolbarClassName","footerToolbarClassName","primaryField","parsePrimitiveQuery","pullRefresh"],d.defaultProps={toolbarInline:!0,syncLocation:!0,hideQuickSaveBtn:!1,autoJumpToTopOnPagerChange:!0,silentPolling:!1,autoFillHeight:!1,showSelection:!0,primaryField:"id",parsePrimitiveQuery:!0,pullRefresh:{disabled:!1,showIcon:!0,showText:!0,iconType:"auto",color:"#777777",dataAppendTo:"bottom",gestureDirection:"up",minLoadingTime:0,contentText:{normalText:"点击加载更多",pullingText:"加载中...",loosingText:"释放立即刷新",loadingText:"加载中...",successText:"加载成功",completedText:"没有更多数据了"}}},C([S,h("design:type",Function),h("design:paramtypes",[]),h("design:returntype",void 0)],d.prototype,"getPaginationPerPage",null),C([S,h("design:type",Function),h("design:paramtypes",[Object]),h("design:returntype",void 0)],d.prototype,"controlRef",null),C([S,h("design:type",Function),h("design:paramtypes",[Number,Number]),h("design:returntype",void 0)],d.prototype,"handleChangePage",null),C([S,h("design:type",Function),h("design:paramtypes",[Array,Array]),h("design:returntype",void 0)],d.prototype,"handleSaveOrder",null),C([S,h("design:type",Function),h("design:paramtypes",[Array,Array]),h("design:returntype",void 0)],d.prototype,"handleSelect",null),C([S,h("design:type",Function),h("design:paramtypes",[Object,Boolean]),h("design:returntype",void 0)],d.prototype,"handleQuerySearch",null),C([S,h("design:type",Function),h("design:paramtypes",[Object,Object,Boolean]),h("design:returntype",void 0)],d.prototype,"doAction",null),C([S,h("design:type",Function),h("design:paramtypes",[Object,Object,Object,Boolean,Object]),h("design:returntype",void 0)],d.prototype,"handleAction",null),C([S,h("design:type",Function),h("design:paramtypes",[Object,Object,P.Component,Object]),h("design:returntype",void 0)],d.prototype,"dispatchEvent",null),C([S,h("design:type",Function),h("design:paramtypes",[Boolean]),h("design:returntype",void 0)],d.prototype,"toggleAllColumns",null),C([S,h("design:type",Function),h("design:paramtypes",[Number]),h("design:returntype",void 0)],d.prototype,"toggleToggle",null),C([S,h("design:type",Function),h("design:paramtypes",[]),h("design:returntype",Promise)],d.prototype,"handlePullRefresh",null),C([S,h("design:type",Function),h("design:paramtypes",[String,Object,Object]),h("design:returntype",void 0)],d.prototype,"renderChild",null),d}(P.Component),Le=function(R){re(d,R);function d(t,e){var a=R.call(this,t)||this,r=e;return r.registerComponent(a),a}return d.prototype.componentWillUnmount=function(){R.prototype.componentWillUnmount.call(this);var t=this.context;t.unRegisterComponent(this)},d.prototype.reload=function(t,e,a){return G(this,void 0,void 0,function(){var r;return V(this,function(s){return r=this.context,t?[2,r.reload(e?"".concat(t,"?").concat(oe(e)):t,a)]:[2,R.prototype.reload.call(this,t,e)]})})},d.prototype.receive=function(t,e){return G(this,void 0,void 0,function(){var a;return V(this,function(r){return a=this.context,e?[2,a.send(e,t)]:[2,R.prototype.receive.call(this,t)]})})},d.prototype.reloadTarget=function(t,e){var a=this.context;a.reload(t,e)},d.prototype.closeTarget=function(t){var e=this.context;e.close(t)},d.contextType=Oe,d=C([Ie({type:"crud2",storeType:Qe.name,isolateScope:!0}),h("design:paramtypes",[Object,Object])],d),d}(Ne);export{Le as CRUD2Renderer,Ne as default};