"use strict";(self.webpackChunkdotcms_ui=self.webpackChunkdotcms_ui||[]).push([[7525],{97525:(m,n,i)=>{i.r(n),i.d(n,{dot_checkbox:()=>u});var d=i(15861),e=i(55956),s=i(26184),r=i(47628),o=i(50394);const u=class{constructor(t){(0,e.r)(this,t),this.dotValueChange=(0,e.c)(this,"dotValueChange",7),this.dotStatusChange=(0,e.c)(this,"dotStatusChange",7),this.name="",this.label="",this.hint="",this.options="",this.required=!1,this.disabled=!1,this.requiredMessage="This field is required",this.value="",this._options=void 0,this.status=void 0}componentWillLoad(){this.value=this.value||"",this.validateProps(),this.emitValueChange(),this.status=(0,s.g)(this.isValid()),this.emitStatusChange()}componentDidLoad(){const t=["dottype"],h=this.el.querySelectorAll('input[type="checkbox"]');setTimeout(()=>{const l=(0,o.g)(Array.from(this.el.attributes),t);h.forEach(a=>{(0,o.s)(a,l)})},0)}optionsWatch(){const t=(0,r.c)(this,"options");this._options=(0,s.f)(t)}valueWatch(){this.value=this.value||""}reset(){var t=this;return(0,d.Z)(function*(){t.value="",t.status=(0,s.g)(t.isValid()),t.emitValueChange(),t.emitStatusChange()})()}render(){const t=(0,s.a)(this.status,this.isValid(),this.required);return(0,e.h)(e.H,{class:Object.assign({},t)},(0,e.h)("dot-label",{label:this.label,required:this.required,name:this.name},(0,e.h)("div",{"aria-describedby":(0,s.h)(this.hint),tabIndex:this.hint?0:null,class:"dot-checkbox__items"},this._options.map(h=>{const l=h.value.trim();return(0,e.h)("label",null,(0,e.h)("input",{class:(0,s.j)(this.isValid()),name:(0,s.k)(this.name),type:"checkbox",disabled:this.disabled||null,checked:this.value.indexOf(l)>=0||null,onInput:a=>this.setValue(a),value:l}),h.label)}))),(0,s.c)(this.hint),(0,s.b)(!this.isValid(),this.requiredMessage))}validateProps(){this.optionsWatch()}setValue(t){this.value=this.getValueFromCheckInputs(t.target.value.trim(),t.target.checked),this.status=(0,s.u)(this.status,{dotTouched:!0,dotPristine:!1,dotValid:this.isValid()}),this.emitValueChange(),this.emitStatusChange()}getValueFromCheckInputs(t,h){const l=this.value.trim().length?this.value.split(","):[],a=new Set(l);return h?a.add(t):a.delete(t),Array.from(a).join(",")}emitStatusChange(){this.dotStatusChange.emit({name:this.name,status:this.status})}isValid(){return!this.required||!!this.value}emitValueChange(){this.dotValueChange.emit({name:this.name,value:this.value})}get el(){return(0,e.g)(this)}static get watchers(){return{options:["optionsWatch"],value:["valueWatch"]}}};u.style=".dot-checkbox__items{display:flex;flex-direction:column}.dot-checkbox__items label{display:flex;align-items:center}.dot-checkbox__items input{margin:0 0.25rem 0 0}"}}]);