import{r as e,_ as o,j as t}from"./react-B_SyE9nW.js";import{aI as r,f as n,e as l,s as a,q as s,o as i}from"./index-CGGskqVP.js";import{g as c,a as u,u as d}from"./ItemLoading-DJhcWYNm.js";import{a as p}from"./styles-DR2RbDnS.js";import{_ as h}from"./history-CBi_mSPs.js";import{u as b}from"./Stack-jwZlgLcD.js";import{b as f}from"./index-CdMAEzxT.js";const m="Switch";function x(e){return u(m,e)}const k=c(m,["root","input","track","thumb","checked","disabled","focusVisible","readOnly"]),g=["checked","defaultChecked","disabled","onBlur","onChange","onFocus","onFocusVisible","readOnly","required","slotProps","slots"],y=e.forwardRef((function(a,s){var i,c,u,p;const{slotProps:m={},slots:k={}}=a,y=o(a,g),{getInputProps:w,checked:S,disabled:j,focusVisible:$,readOnly:C}=function(o){const{checked:t,defaultChecked:l,disabled:a,onBlur:s,onChange:i,onFocus:c,onFocusVisible:u,readOnly:d,required:p}=o,[f,m]=b({controlled:t,default:Boolean(l),name:"Switch",state:"checked"}),x=e=>o=>{var t;o.nativeEvent.defaultPrevented||(m(o.target.checked),null==i||i(o),null==(t=e.onChange)||t.call(e,o))},{isFocusVisibleRef:k,onBlur:g,onFocus:y,ref:w}=r(),[S,j]=e.useState(!1);a&&S&&j(!1),e.useEffect((()=>{k.current=S}),[S,k]);const $=e.useRef(null),C=e=>o=>{var t;$.current||($.current=o.currentTarget),y(o),!0===k.current&&(j(!0),null==u||u(o)),null==c||c(o),null==(t=e.onFocus)||t.call(e,o)},P=e=>o=>{var t;g(o),!1===k.current&&j(!1),null==s||s(o),null==(t=e.onBlur)||t.call(e,o)},v=n(w,$);return{checked:f,disabled:Boolean(a),focusVisible:S,getInputProps:(e={})=>h({checked:t,defaultChecked:l,disabled:a,readOnly:d,ref:v,required:p,type:"checkbox",role:"switch","aria-checked":t},e,{onChange:x(e),onFocus:C(e),onBlur:P(e)}),inputRef:v,readOnly:Boolean(d)}}(a),P=h({},a,{checked:S,disabled:j,focusVisible:$,readOnly:C}),v=(e=>{const{checked:o,disabled:t,focusVisible:r,readOnly:n}=e;return l({root:["root",o&&"checked",t&&"disabled",r&&"focusVisible",n&&"readOnly"],thumb:["thumb"],input:["input"],track:["track"]},d(x))})(P),F=null!=(i=k.root)?i:"span",V=f({elementType:F,externalSlotProps:m.root,externalForwardedProps:y,additionalProps:{ref:s},ownerState:P,className:v.root}),O=null!=(c=k.thumb)?c:"span",B=f({elementType:O,externalSlotProps:m.thumb,ownerState:P,className:v.thumb}),T=null!=(u=k.input)?u:"input",q=f({elementType:T,getSlotProps:w,externalSlotProps:m.input,ownerState:P,className:v.input}),I=null===k.track?()=>null:null!=(p=k.track)?p:"span",N=f({elementType:I,externalSlotProps:m.track,ownerState:P,className:v.track});return t.jsxs(F,h({},V,{children:[t.jsx(I,h({},N)),t.jsx(O,h({},B)),t.jsx(T,h({},q))]}))})),w=a("span")`
  font-size: 0;
  position: relative;
  display: inline-block;
  width: 40px;
  min-width: 40px;
  height: 20px;
  background: ${s.grayLighter};
  border-radius: 10px;
  margin: 10px;
  cursor: pointer;

  &.${k.disabled} {
    opacity: 0.4;
    cursor: not-allowed;
  }

  &.${k.checked} {
    background: ${s.red};
  }

  & .${k.thumb} {
    display: block;
    width: 14px;
    height: 14px;
    top: 3px;
    left: 3px;
    border-radius: 16px;
    background-color: ${s.white};
    position: relative;
    transition: all 200ms ease;
  }

  &.${k.focusVisible} .${k.thumb} {
    background-color: ${s.white};
    box-shadow: 0 0 1px 8px rgba(0, 0, 0, 0.25);
  }

  &.${k.checked} .${k.thumb} {
    left: 23px;
    top: 3px;
    background-color: ${s.white};
  }

  & .${k.input} {
    cursor: inherit;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    z-index: 1;
    margin: 0;
  }
`,S={"&.MuiFormControlLabel-root":{display:"flex",justifyContent:"space-between",flexDirection:"row",m:0,"& span.MuiTypography-root":{fontSize:"14px",fontWeight:500,ml:"5px",order:1},"& span.base-Switch-root":{order:2,m:"5px 0"}}};const j=i((function({fieldState:e,label:o,disabled:r=!1,sx:n,afterChange:l}){return t.jsx(p,{sx:{...S,...n},control:t.jsx(y,{slots:{root:w},checked:(null==e?void 0:e.value)||!1,onChange:o=>{null==e||e.onChange(o.target.checked),null==l||l()}}),label:o,disabled:r})}));export{j as F};