import{_ as _extends}from"./_rollupPluginBabelHelpers-B5fk9IVe.js";import React__default,{createContext,useContext,useState,useEffect,useMemo,useId}from"react";import PropTypes from"prop-types";import{L as Label,F as FormHint}from"./FormHint.component-BPhoMz7f.js";import{I as Icon}from"./Icon.component-BVkaZqpA.js";import{D as DataListCell}from"./DataListCell.component-C67qgCtq.js";const CheckboxGroupContext=createContext(),wrapperStyles=`
  jn-inline-flex
  jn-items-center
`,inputstyles=`
  jn-w-4
  jn-h-4
  jn-opacity-0
  jn-z-50
`,mockcheckboxstyles=`
  jn-relative
  jn-w-4
  jn-h-4
  jn-rounded-sm
  jn-bg-theme-checkbox
  jn-cursor-pointer
  focus:jn-outline-none
  focus:jn-ring-2
  focus:jn-ring-theme-focus
`,mockfocusstyles=`
  jn-ring-2
  jn-ring-theme-focus
`,mockcheckmarkstyles=`
  jn-absolute
  jn-top-0
  jn-left-0
  jn-text-theme-checkbox-checked
  jn-fill-current
`,mockindeterminatestyles=`
  jn-absolute
  jn-w-2
  jn-h-0.5
  jn-top-1.5
  jn-left-[.2rem]
  jn-inline-block
  jn-bg-theme-focus
`,mockdisabledstyles=`
  jn-pointer-events-none
  jn-opacity-50
  jn-cursor-not-allowed
`,noBorderStyles=`
  jn-border
  jn-border-transparent
`,errorstyles=`
  jn-border
  jn-border-theme-error
`,successstyles=`
  jn-border
  jn-border-theme-success
`,labelStyles=`
  jn-leading-0
  jn-ml-2
`,iconStyles=`
  jn-ml-1
`,hintStyles=`
  jn-mt-0
  jn-ml-6
`,Checkbox=a=>{let{checked:g=!1,className:h="",disabled:i=!1,errortext:j="",helptext:k="",id:l="",indeterminate:m=!1,invalid:n=!1,label:b,name:o="",onChange:c,onClick:d,required:p=!1,successtext:q="",valid:r=!1,value:e,...f}=a;const s=a=>"string"!=typeof a||0!==a.trim().length,t=useContext(CheckboxGroupContext),{selectedOptions:u,name:v,disabled:w,handleCheckboxChange:x,updateSelectedValue:y}=t||{},[z,A]=useState((()=>t?!!(u&&u.includes(e)):!!g)()),[B,C]=useState(!1),[D,E]=useState(!1),[F,G]=useState(!1),[H,I]=useState(!1);useEffect(()=>{g&&t&&y(e)},[]),useEffect(()=>{t||A(g)},[g]);const J=useMemo(()=>n||!!(j&&s(j)),[n,j]),K=useMemo(()=>r||!!(q&&s(q)),[r,q]);useEffect(()=>{C(m)},[m]),useEffect(()=>{G(J)},[J]),useEffect(()=>{I(K)},[K]);const L=()=>t?!!(u&&u.includes(e)):z,M=l||(()=>"juno-checkbox-"+useId())();return React__default.createElement("div",{className:"jn-checkbox-outer"},React__default.createElement("div",{className:`jn-checkbox-wrapper ${wrapperStyles}`},React__default.createElement("div",_extends({className:`
            juno-checkbox 
            ${mockcheckboxstyles} 
            ${D?mockfocusstyles:""} 
            ${w||i?mockdisabledstyles:""} 
            ${F?errorstyles:""} 
            ${H?successstyles:""} 
            ${F||H?"":noBorderStyles}
            ${h}
          `},f),L()?React__default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",className:`${mockcheckmarkstyles}`,width:"16",height:"16",viewBox:"0 0 16 16"},React__default.createElement("polygon",{points:"5.75 11.15 2.6 8 1.55 9.05 5.75 13.25 14.75 4.25 13.7 3.2"})):"",React__default.createElement("input",{checked:L(),className:`
              ${inputstyles} 
              ${F?"juno-checkbox-invalid":""} 
              ${H?"juno-checkbox-valid":""} 
              ${w||i?"jn-cursor-not-allowed":""}
            `,disabled:w||i,id:M,name:v||o,onBlur:()=>{E(!1)},onChange:a=>{A(!z),x&&"function"==typeof x&&x(e),c&&c(a)},onClick:a=>{d&&d(a)},onFocus:()=>{E(!0)},type:"checkbox",value:e}),B&&!L()?React__default.createElement("div",{className:`${mockindeterminatestyles}`}):""),b&&s(b)?React__default.createElement(React__default.Fragment,null,React__default.createElement(Label,{text:b,htmlFor:M,disabled:w||i,required:p,className:`${labelStyles}`}),F?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error",size:"1.125rem",className:`
                  ${iconStyles}
                  ${w||i?"jn-opacity-50":""}
                `}):"",H?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success",size:"1.125rem",className:`
                  ${iconStyles}
                  ${i?"jn-opacity-50":""}
                `}):""):""),j&&s(j)?React__default.createElement(FormHint,{text:j,variant:"error",className:`${hintStyles}`}):"",q&&s(q)?React__default.createElement(FormHint,{text:q,variant:"success",className:`${hintStyles}`}):"",k&&s(k)?React__default.createElement(FormHint,{text:k,className:`${hintStyles}`}):"")};Checkbox.propTypes={checked:PropTypes.bool,className:PropTypes.string,disabled:PropTypes.bool,errortext:PropTypes.node,helptext:PropTypes.node,id:PropTypes.string,indeterminate:PropTypes.bool,invalid:PropTypes.bool,label:PropTypes.string,name:PropTypes.string,onChange:PropTypes.func,onClick:PropTypes.func,required:PropTypes.bool,successtext:PropTypes.node,valid:PropTypes.bool,value:PropTypes.string};const datalistcheckboxcellbasestyles=`
	jn-flex
	jn-flex-col
	jn-justify-center
`,DataListCheckboxCell=a=>{let{selected:d=!1,disabled:e=!1,onChange:b,className:f="",...c}=a;return React__default.createElement(DataListCell,_extends({className:`juno-datalist-checkbox-cell ${datalistcheckboxcellbasestyles} ${f}`},c),React__default.createElement(Checkbox,{disabled:e,checked:d,onChange:b}))};DataListCheckboxCell.propTypes={selected:PropTypes.bool,disabled:PropTypes.bool,className:PropTypes.string,onChange:PropTypes.func};export{DataListCheckboxCell as D};