import{_ as _extends}from"./_rollupPluginBabelHelpers-B5fk9IVe.js";import React__default,{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";const switchWrapperStyles=`
	jn-flex
	jn-flex-row
	jn-items-center
`,switchbasestyles=`
	jn-rounded-full
	jn-relative
	jn-p-0
	jn-leading-0
	jn-border
	jn-g-theme-default
	focus:jn-outline-none
	focus:jn-ring-2
	focus:jn-ring-theme-focus
	disabled:jn-opacity-50
	disabled:jn-cursor-not-allowed
`,switchsizestyles=a=>"small"===a?"jn-w-[1.75rem] jn-h-4":"large"===a?"jn-w-[3.125rem] jn-h-[1.6875rem]":"jn-w-switch-default jn-h-switch-default",handlebasestyles=`
	jn-inline-block
	jn-absolute
	jn-top-[1px]
	jn-rounded-full
	jn-bg-theme-switch-handle
	jn-border-theme-default
`,handlesizestyles=a=>"small"===a?"jn-w-[0.75rem] jn-h-[0.75rem]":"large"===a?"jn-w-[1.4375rem] jn-h-[1.4375rem]":"jn-w-switch-handle-default jn-h-switch-handle-default",defaultborderstyles=`
	jn-border-theme-switch-default
`,invalidbasestyles=`
	jn-border-theme-error
`,validbasestyles=`
	jn-border-theme-success
`,handleonstyles=`
	jn-right-[1px] 
	jn-bg-theme-switch-handle-checked
`,handleoffstyles=`
	jn-left-[1px]
`,iconstyles=`
	jn-inline-block 
	jn-ml-1 
	jn-leading-1
	jn-mt-[-.2rem]
`,hintStyles=`
	jn-mt-0
`,Switch=a=>{let{name:c="",id:d=null,label:e=void 0,required:f=!1,size:g="default",on:h=!1,disabled:i=null,invalid:j=!1,valid:k=!1,helptext:l="",errortext:m="",successtext:n="",className:o="",onChange:p=void 0,onClick:q=void 0,wrapperClassName:r="",...b}=a;const s=a=>"string"!=typeof a||0!==a.trim().length,[t,u]=useState(h),[v,w]=useState(!1),[x,y]=useState(!1);useEffect(()=>{u(h)},[h]);const z=useMemo(()=>j||!!(m&&s(m)),[j,m]),A=useMemo(()=>k||!!(n&&s(n)),[k,n]);useEffect(()=>{w(z)},[z]),useEffect(()=>{y(A)},[A]);const B=d||(()=>"juno-switch-"+useId())();return React__default.createElement("div",null,React__default.createElement("span",{className:`
				juno-switch-wrapper 
				${switchWrapperStyles}
        ${r}
				`},React__default.createElement("button",_extends({type:"button",role:"switch",name:c,id:B,"aria-checked":t,disabled:i,onClick:a=>{u(!t),q&&q(a),p&&p(a)},className:`
						juno-switch 
						juno-switch-${g} 
						${switchbasestyles} 
						${switchsizestyles(g)} 
						${v?"juno-switch-invalid "+invalidbasestyles:""} 
						${x?"juno-switch-valid "+validbasestyles:""} 
						${x||v?"":defaultborderstyles} 
						${o}`},b),React__default.createElement("span",{className:`juno-switch-handle ${handlebasestyles} ${handlesizestyles(g)} ${t?handleonstyles:handleoffstyles}`})),React__default.createElement(Label,{text:e,htmlFor:B,className:"jn-ml-2",disabled:i,required:f}),v?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error",size:"1.125rem",className:`${iconstyles} ${i?"jn-opacity-50":""}`}):"",x?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success",size:"1.125rem",className:`${iconstyles} ${i?"jn-opacity-50":""}`}):""),m&&s(m)?React__default.createElement(FormHint,{text:m,variant:"error",className:`${hintStyles}`}):"",n&&s(n)?React__default.createElement(FormHint,{text:n,variant:"success",className:`${hintStyles}`}):"",l&&s(l)?React__default.createElement(FormHint,{text:l,className:`${hintStyles}`}):"")};Switch.propTypes={name:PropTypes.string,id:PropTypes.string,label:PropTypes.string,required:PropTypes.bool,size:PropTypes.oneOf(["small","default","large"]),on:PropTypes.bool,disabled:PropTypes.bool,invalid:PropTypes.bool,valid:PropTypes.bool,helptext:PropTypes.node,errortext:PropTypes.node,successtext:PropTypes.node,className:PropTypes.string,onChange:PropTypes.func,onClick:PropTypes.func,wrapperClassName:PropTypes.string};export{Switch as S};