"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),u=require("@aplus-frontend/antdv"),q=require("dayjs"),v=require("lodash-unified");require("../../../ap-button/index.js");const D=require("../../../ap-field/index.js");require("../../../ap-form/ap-form.vue.js");require("../../../config-provider/index.js");const S=require("../hooks/use-view-provide.js"),b=require("../icons/line-eye.vue.js"),F=require("../style/index.js"),z=require("../utils/uuid.js"),T=require("../../../config-provider/hooks/use-locale.js"),k=require("../../../config-provider/hooks/use-namespace.js"),p=require("../../../ap-form/ap-form.vue2.js"),w=require("../../../ap-button/ap-button.vue.js"),I=e.defineComponent({__name:"main-button-content",props:{maxViewNum:{}},setup(V){const s=V,{t}=T.useLocale(),{b:a}=k.useNamespace("ap-view"),i=F.default("ap-view"),f=e.ref(),{tableKey:h,popoverOpen:o,viewList:l,saveDataSource:d,viewListCRUD:N}=S.useViewInject(),m=e.computed({get:()=>o.value&&l.value.length<s.maxViewNum+1,set:r=>{l.value.length<s.maxViewNum+1&&(o.value=r)}});e.watch(o,r=>{r&&(f.value?.resetFields(),setTimeout(()=>{f.value?.setFieldsValue({isDefault:!l.value.some(n=>n.isDefault)})}))});const x=async r=>{const{viewName:n,isDefault:c}=r,_=z.generateUniqueKey(),g=v.cloneDeep(d?.getSearchFormValues?.(!!d?.searchFormTransform)),y=v.cloneDeep(d?.getSearchFormSorterItems?.()),C={searchForm:g,sorterItems:y};await N.addView?.({tableKey:h.value,viewKey:_,viewName:n,isDefault:c,viewConfig:C}),o.value=!1};return(r,n)=>(e.openBlock(),e.createBlock(e.unref(u.Popover),{open:m.value,"onUpdate:open":n[1]||(n[1]=c=>m.value=c),placement:"bottom",trigger:"click",arrow:!1,"overlay-inner-style":{padding:"12px 16px"}},{content:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass([e.unref(a)(),e.unref(a)("main-content-popover"),e.unref(i)])},[e.createVNode(p.default,{ref_key:"formRef",ref:f,layout:"vertical","initial-values":{viewName:`${e.unref(t)("ap.apView.newView")} ${e.unref(q)().format("YYYY-MM-DD").toString()}`},onFinish:x},{default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass([e.unref(a)("main-content-popover-title-content"),e.unref(i)])},[e.createElementVNode("div",{class:e.normalizeClass([e.unref(a)("main-content-popover-title-content-title")])},e.toDisplayString(e.unref(t)("ap.apView.saveNewView")),3),e.createVNode(p.default.FormItem,{name:"isDefault","value-prop-name":"checked"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Checkbox),null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(t)("ap.apView.setDefault")),1)]),_:1})]),_:1})],2),e.createVNode(p.default.FormItem,{label:e.unref(t)("ap.apView.viewName"),name:"viewName",rules:[{required:!0,message:e.unref(t)("ap.apView.notEmpty")}]},{default:e.withCtx(()=>[e.createVNode(e.unref(D.ApField).Text,{placeholder:e.unref(t)("ap.apView.viewName"),maxlength:20,"show-count":""},null,8,["placeholder"])]),_:1},8,["label","rules"]),e.createVNode(p.default.FormItem,{class:e.normalizeClass([e.unref(a)("main-content-popover-btn"),e.unref(i)])},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Space),{size:8},{default:e.withCtx(()=>[e.createVNode(e.unref(w.default),{size:"small",onClick:n[0]||(n[0]=c=>o.value=!1)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(t)("ap.apView.cancel")),1)]),_:1}),e.createVNode(e.unref(w.default),{type:"primary",size:"small","html-type":"submit"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(t)("ap.apView.save")),1)]),_:1})]),_:1})]),_:1},8,["class"])]),_:1},8,["initial-values"])],2)]),default:e.withCtx(()=>[e.createElementVNode("div",{class:e.normalizeClass({[e.unref(a)("main-content")]:!0,[e.unref(a)("main-content-disabled")]:e.unref(l).length>=s.maxViewNum+1,hashId:e.unref(i)})},[e.createVNode(e.unref(u.Tooltip),{placement:"bottom"},e.createSlots({default:e.withCtx(()=>[e.createVNode(e.unref(u.Space),{size:4},{default:e.withCtx(()=>[e.createVNode(b.default,{class:e.normalizeClass([e.unref(a)("icon"),e.unref(i)])},null,8,["class"]),e.createElementVNode("div",null,e.toDisplayString(e.unref(t)("ap.apView.saveView")),1)]),_:1})]),_:2},[e.unref(l).length>=s.maxViewNum+1?{name:"title",fn:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(e.unref(t)("ap.apView.maxTip")),1)]),key:"0"}:void 0]),1024)],2)]),_:1},8,["open"]))}});exports.default=I;
