import{_ as __rest,a as __assign,b as __spreadArray}from"./tslib.es6-bjGg6Bxl.js";import React__default,{createContext,useState,useMemo,useEffect,useId}from"react";import{L as Label}from"./Label.component-6VRtHbKe.js";import{I as Icon}from"./Icon.component-7-ap-6Ys.js";import{F as FormHint}from"./FormHint.component-Dkh3ieaZ.js";var checkboxgroupstyles="\n  jn-mb-4\n  jn-last:mb-0\n",groupstyles="\n  jn-relative\n  jn-rounded\n  jn-border\n  jn-py-1\n",defaultgroupstyles="\n  jn-border-transparent\n",validgroupstyles="\n  jn-border-theme-success\n  jn-px-2\n",invalidgroupstyles="\n  jn-border-theme-error\n  jn-px-2\n",iconstyles="\n  jn-absolute\n  jn-right-2\n  jn-top-1.5\n",CheckboxGroupContext=createContext(void 0),CheckboxGroup=function(a){var b=a.children,c=void 0===b?null:b,d=a.className,e=void 0===d?"":d,f=a.disabled,g=void 0!==f&&f,h=a.errortext,i=void 0===h?"":h,j=a.helptext,k=void 0===j?"":j,l=a.id,m=void 0===l?"":l,n=a.invalid,o=void 0!==n&&n,p=a.label,q=a.name,r=void 0===q?"":q,s=a.onChange,t=a.required,u=a.selected,v=a.successtext,w=void 0===v?"":v,x=a.valid,y=void 0!==x&&x,z=__rest(a,["children","className","disabled","errortext","helptext","id","invalid","label","name","onChange","required","selected","successtext","valid"]),A=function(a){return"string"!=typeof a||0!==a.trim().length},B=function(){return"juno-checkboxgroup-"+useId()},C=r||B(),D=m||B(),E=useState(u),F=E[0],G=E[1],H=useState(!1),I=H[0],J=H[1],K=useState(!1),L=K[0],M=K[1],N=useMemo(function(){return y||!!(w&&w.length)},[y,w]),O=useMemo(function(){return o||!!(i&&i.length)},[o,i]);useEffect(function(){u&&G(u)},[u]),useEffect(function(){J(N)},[N]),useEffect(function(){M(O)},[O]);return React__default.createElement(CheckboxGroupContext.Provider,{value:{selectedOptions:F,name:C,disabled:g,handleCheckboxChange:function(a){var b=a;F&&F.includes(a)?G(F.filter(function(a){return a!==b})):F&&!F.includes(a)?G(function(a){return __spreadArray(__spreadArray([],a||[],!0),[b],!1)}):G([b]),s&&s(a)},updateSelectedValue:function(a){u||G(function(b){return __spreadArray(__spreadArray([],b||[],!0),[a],!1)})}}},React__default.createElement("div",__assign({className:"\n          juno-checkboxgroup \n          ".concat(I?"juno-checkboxgroup-valid":""," \n          ").concat(L?"juno-checkboxgroup-invalid":""," \n          ").concat(checkboxgroupstyles," \n          ").concat(e,"\n        "),id:D,role:"group"},z),p&&A(p)?(React__default.createElement(Label,{text:p,htmlFor:D,disabled:g,required:void 0!==t&&t})):"",React__default.createElement("div",{className:"\n            juno-checkbox-group-options \n            ".concat(groupstyles," \n            ").concat(I?validgroupstyles:""," \n            ").concat(L?invalidgroupstyles:""," \n            ").concat(I||L?"":defaultgroupstyles,"\n          ")},L?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error",className:"".concat(iconstyles)}):"",I?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success",className:"".concat(iconstyles)}):"",c),i&&A(i)?React__default.createElement(FormHint,{text:i,variant:"error"}):"",w&&A(w)?React__default.createElement(FormHint,{text:w,variant:"success"}):"",k&&A(k)?React__default.createElement(FormHint,{text:k}):""))};export{CheckboxGroup as C,CheckboxGroupContext as a};