"use strict";const t=require("vue");;/* empty css                        */const n=require("../Shared/base-iCmnU-fv.js"),N=require("../Web/__directive__/Tooltip.cjs"),S=["id","name","value","disabled","checked","onClick"],$=["for"],T=t.defineComponent({name:"ClCheckbox",directives:{cltooltip:N.tooltipDirectives},__name:"Index",props:{value:{type:String,required:!0},className:{type:String,default:""},name:{type:String,required:!0},list:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1},width:{type:String,default:""},isInline:{type:Boolean,default:!0},checkChangeBefore:{type:Function,default:void 0}},emits:["update:value","onChange","onInit"],setup(u,{expose:f,emit:E}){const a=u,h=E,v=`cb-${n.CommonBase.getRandom(8)}`,i=t.ref(n.CommonBase.isEmpty(a.value)?[]:a.value.split(",")),c=t.ref(!1);let m={};const C={lastValue:[]},V=t.computed(()=>{const e=a.className,l={"panel-checkbox":!0};return e&&!n.CommonBase.isEmpty(e)&&e.split(" ").forEach(o=>{n.CommonBase.isEmpty(o)||(l[o]=!0)}),l}),x=t.computed(()=>{const e={checkbox:!0,"checkbox-default":!0};return e["checkbox-inline"]=a.isInline??!0,e}),_=e=>{const l={"checkbox-icon-tip":!0};return n.CommonBase.isEmpty(e.tipIcon)?l["clIconFont clIcon-question-circle"]=!0:l[e.tipIcon]=!0,l},b=e=>{const l={},{width:o}=a;return e&&!n.CommonBase.isEmpty(e.width)?l.width=e.width:n.CommonBase.isEmpty(o)||(l.width=a.width),l},k=e=>{h("update:value",e)},I=e=>{const l=[];n.CommonBase.isEmpty(e)||e.split(",").forEach(s=>{n.CommonBase.isExistJsonKey(m,s)&&l.push(n.CommonBase.getJsonClone(m[s]))});const o=l.length>0&&l.length===a.list.length;k(e),h("onChange",e,l,o)},p=()=>{t.nextTick(()=>{h("onInit")})},y=()=>{const e=[];return i.value.forEach(l=>{n.CommonBase.isExistJsonKey(m,l)&&e.push(l)}),e},B=e=>{m=n.CommonBase.isEmpty(e)?{}:n.CommonBase.getJsonByList(e)},d=()=>{if(c.value&&!n.CommonBase.isEmpty(i.value)){const e=y();n.CommonBase.isEqualArr(i.value,e)||(i.value=e,k(e.join(",")))}},g=e=>{const l=e.split(",");let o=n.CommonBase.isEqualArr(i.value,l);o&&(o=e===i.value.join(",")),o||(i.value=l)},w=()=>{c.value=a.list.length!==0,B(a.list),d(),C.lastValue=n.CommonBase.getArrClone(i.value)};t.watch(c,e=>{e&&p()}),t.watch(()=>a.list,e=>{c.value||(c.value=!0,e.length===0&&d(),p())}),t.watch([()=>a.value,()=>a.list],([e,l])=>{const o=l;!c.value&&o.length>0&&(c.value=!0,p()),B(o),e!==a.value&&g(e),d()}),t.onMounted(()=>{t.nextTick(()=>{w()})});const D=async e=>{if(!e.isDisabled&&!a.disabled){const l=e.id.toString();let o=n.CommonBase.getArrClone(i.value);n.CommonBase.isExistValue(i.value,l)?o=n.CommonBase.getArrRemoveById(o,l):o.push(l);const s=o.join(",");let r=!0;a.checkChangeBefore&&(r=await a.checkChangeBefore(s),r=n.CommonBase.isBoolean(r)?r:!0),r?(i.value=o,C.lastValue=o,I(s)):t.nextTick(()=>{i.value=o,t.nextTick(()=>{i.value=C.lastValue})})}};return f({getValue:()=>y().join(","),getValueData:()=>{const e=[];return i.value.forEach(l=>{n.CommonBase.isExistJsonKey(m,l)&&e.push(n.CommonBase.getJsonClone(m[l]))}),e},setValue:e=>{g(e),d()},runInitComplete:()=>{c.value||(c.value=!0,B(a.list),g(a.value),d(),p())}}),(e,l)=>{const o=t.resolveDirective("cltooltip");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(V.value)},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(u.list,(s,r)=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:`${v}-${r}`},[s.isShow||s.isShow===void 0?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(x.value),style:t.normalizeStyle(b(s))},[t.createElementVNode("span",null,[t.createElementVNode("span",null,[t.createElementVNode("input",{type:"checkbox",id:`${v}_${u.name}_${s.id}`,name:u.name,value:s.id,disabled:s.isDisabled||u.disabled,checked:i.value.includes(s.id.toString()),onClick:M=>D(s)},null,8,S),t.createElementVNode("label",{for:`${v}_${u.name}_${s.id}`},[t.renderSlot(e.$slots,"default",{data:s},()=>[s.icon&&s.icon.length>0?t.withDirectives((t.openBlock(),t.createElementBlock("i",{key:0,class:t.normalizeClass(s.icon)},null,2)),[[o,{html:s.name,className:"tooltip-modal"}]]):(t.openBlock(),t.createElementBlock(t.Fragment,{key:1},[t.createTextVNode(t.toDisplayString(s.name),1)],64))])],8,$)]),s.tipMsg&&s.tipMsg.length>0?t.withDirectives((t.openBlock(),t.createElementBlock("i",{key:0,class:t.normalizeClass(_(s))},null,2)),[[o,{html:s.tipMsg,className:"tooltip-modal"}]]):t.createCommentVNode("",!0)])],6)):t.createCommentVNode("",!0)],64))),128))],2)}}});module.exports=T;
//# sourceMappingURL=ClCheckbox.cjs.map
