"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),h=require("@aplus-frontend/antdv"),k=require("lodash-unified");require("../../utils/index.js");require("../../hooks/index.js");const b=require("../../hooks/useControllableValue.js"),l=require("../../utils/is.js"),w=e.defineComponent({name:"ApFieldSwitch",__name:"index",props:{mode:{},class:{},style:{},emptyText:{default:"--"},customReadMode:{},id:{},prefixCls:{},size:{default:"default"},disabled:{type:Boolean,default:void 0},checkedChildren:{},unCheckedChildren:{},tabindex:{},autofocus:{type:Boolean},loading:{type:Boolean,default:void 0},checked:{},checkedValue:{default:!0},unCheckedValue:{default:!1},onChange:{},onKeydown:{},onMouseup:{},"onUpdate:checked":{},onBlur:{},onFocus:{},onAction:{},confirm:{}},emits:["update:checked"],setup(t,{expose:g,emit:v}){const a=e.useSlots(),n=t,m=e.computed(()=>k.omit(n,["onUpdate:checked","emptyText"])),y=v,s=e.ref(),{value:c,updateValue:i}=b.useControllableValue(n,y,{valuePropName:"checked"}),r=e.ref(!1);async function C(o,d){if(!l.isDef(n.confirm)){if(!l.isDef(n.onAction)){i(o);return}r.value=!0;try{await n.onAction(o,d)&&i(o)}finally{r.value=!1}}}async function V(){const o=e.unref(c)===n.checkedValue?n.unCheckedValue:n.checkedValue;if(!l.isDef(n.onAction)){i(o);return}await n.onAction(o)&&i(o)}const B=e.computed(()=>{const o=e.unref(c);return k.isNil(o)?e.createVNode(e.Fragment,null,[n.emptyText]):o===n.checkedValue?e.createVNode(e.Fragment,null,[n.checkedChildren||a.checkedChildren?.()||`${n.checkedValue}`]):e.createVNode(e.Fragment,null,[n.unCheckedChildren||a.unCheckedChildren?.()||`${n.unCheckedValue}`])}),P=e.computed(()=>l.isDef(n.confirm)?k.isFunction(n.confirm)?n.confirm(e.unref(c)):n.confirm:{});return g({focus:()=>s.value?.focus(),blur:()=>s.value?.blur()}),(o,d)=>t.mode==="read"?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(B.value),{key:0})):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[!e.unref(l.isDef)(t.confirm)||t.disabled?(e.openBlock(),e.createBlock(e.unref(h.Switch),e.mergeProps({key:0,ref_key:"switchRef",ref:s},m.value,{checked:e.unref(c),loading:t.loading??r.value,onClick:C}),e.createSlots({_:2},[e.renderList(a,(p,u)=>({name:u,fn:e.withCtx(f=>[e.renderSlot(o.$slots,u,e.normalizeProps(e.guardReactiveProps(f||{})))])}))]),1040,["checked","loading"])):(e.openBlock(),e.createBlock(e.unref(h.Popconfirm),e.mergeProps({key:1,disabled:r.value},P.value,{onConfirm:V}),{default:e.withCtx(()=>[e.createVNode(e.unref(h.Switch),e.mergeProps(m.value,{checked:e.unref(c),loading:t.loading??r.value,onClick:C}),e.createSlots({_:2},[e.renderList(a,(p,u)=>({name:u,fn:e.withCtx(f=>[e.renderSlot(o.$slots,u,e.normalizeProps(e.guardReactiveProps(f||{})))])}))]),1040,["checked","loading"])]),_:3},16,["disabled"]))],64))}});exports.default=w;
