import{_ as __rest,a as __assign}from"./tslib.es6-bjGg6Bxl.js";import React__default,{useContext,useState,useMemo,useEffect,useId}from"react";import{a as RadioGroupContext}from"./RadioGroup.component-zeCkbBZU.js";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 wrapperStyles="\n  jn-inline-flex\n  jn-items-center\n",inputstyles="\n  jn-w-4\n  jn-h-4\n  jn-opacity-0\n  jn-z-50\n",mockradiostyles="\n  jn-relative\n  jn-w-4\n  jn-h-4\n  jn-rounded-full\n  jn-bg-theme-radio\n",checkedstyles="\n  jn-absolute\n  jn-block\n  jn-bg-theme-radio-checked\n  jn-rounded-full\n  jn-w-3\n  jn-h-3\n  jn-top-[1px]\n  jn-left-[1px]\n",mockfocusradiostyles="\n  jn-outline-none\n  jn-ring-2\n  jn-ring-theme-focus\n",mockdisabledradiostyles="\n  jn-opacity-50\n  jn-cursor-not-allowed\n",noBorderStyles="\n  jn-border\n  jn-border-transparent\n",errorstyles="\n  jn-border\n  jn-border-theme-error\n",successstyles="\n  jn-border\n  jn-border-theme-success\n",labelStyles="\n  jn-leading-0\n  jn-ml-2\n",iconStyles="\n  jn-ml-1\n",hintStyles="\n  jn-mt-0\n  jn-ml-6\n",Radio=function(a){var b=a.checked,c=void 0!==b&&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?void 0:l,n=a.invalid,o=void 0!==n&&n,p=a.label,q=void 0===p?void 0:p,r=a.name,s=void 0===r?void 0:r,t=a.onChange,u=void 0===t?void 0:t,v=a.onClick,w=void 0===v?void 0:v,x=a.required,y=a.successtext,z=void 0===y?"":y,A=a.valid,B=void 0!==A&&A,C=a.value,D=void 0===C?void 0:C,E=__rest(a,["checked","className","disabled","errortext","helptext","id","invalid","label","name","onChange","onClick","required","successtext","valid","value"]),F=function(a){return"string"!=typeof a||0!==a.trim().length},G=useContext(RadioGroupContext),H=G||{},I=H.selectedValue,J=H.onChange,K=H.name,L=H.updateSelectedValue,M=H.disabled,N=function(){return G?I===D:!!c},O=useState(function(){return N()}),P=O[0],Q=O[1],R=useState(!1),S=R[0],T=R[1],U=useState(!1),V=U[0],W=U[1],X=useState(!1),Y=X[0],Z=X[1],$=useMemo(function(){return o||!!(i&&F(i))},[o,i]),_=useMemo(function(){return B||!!(z&&F(z))},[B,z]);useEffect(function(){W($)},[$]),useEffect(function(){Z(_)},[_]),useEffect(function(){c&&G&&I===void 0&&L&&L(D)},[]),useEffect(function(){I||Q(c)},[c]);var aa=function(){return I?I===D:P},ba=m||function(){return"juno-radio-"+useId()}();return React__default.createElement("div",{className:"jn-radio-outer"},React__default.createElement("div",{className:"juno-radio-wrapper ".concat(wrapperStyles)},React__default.createElement("div",__assign({className:"\n             juno-radio \n             ".concat(mockradiostyles," \n             ").concat(S?mockfocusradiostyles:""," \n             ").concat(g?mockdisabledradiostyles:""," \n             ").concat(V?errorstyles:""," \n             ").concat(Y?successstyles:""," \n             ").concat(V||Y?"":noBorderStyles,"\n             ").concat(e,"\n           ")},E),React__default.createElement("input",{checked:aa(),className:"\n              ".concat(inputstyles," \n              ").concat(V?"juno-radio-invalid":""," \n              ").concat(Y?"juno-radio-valid":"","\n            "),disabled:M||g,id:ba,onBlur:function(){T(!1)},onChange:function(){Q(!P),J&&"function"==typeof J&&I!==D&&J(D),u&&u(D)},onClick:function(a){w&&w(a)},onFocus:function(){T(!0)},name:K||s,type:"radio",value:D}),aa()?React__default.createElement("span",{className:"".concat(checkedstyles)}):""),q&&F(q)?(React__default.createElement(React__default.Fragment,null,React__default.createElement(Label,{className:"".concat(labelStyles),disabled:M||g,htmlFor:ba,required:void 0!==x&&x,text:q}),V?(React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error",size:"1.125rem",className:"\n                    ".concat(iconStyles,"\n                    ").concat(g?"jn-opacity-50":"","\n                  ")})):"",Y?(React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success",size:"1.125rem",className:"\n                    ".concat(iconStyles,"\n                    ").concat(g?"jn-opacity-50":"","\n                  ")})):"")):""),i&&F(i)?(React__default.createElement(FormHint,{text:i,variant:"error",className:"".concat(hintStyles)})):"",z&&F(z)?(React__default.createElement(FormHint,{text:z,variant:"success",className:"".concat(hintStyles)})):"",k&&F(k)?React__default.createElement(FormHint,{text:k,className:"".concat(hintStyles)}):"")};export{Radio as R};