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

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

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

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

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

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

  & .${k.input} {
    cursor: inherit;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    z-index: 1;
    margin: 0;
  }
`,j={"&.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 S=a((function({fieldState:e,label:o,disabled:r=!1,sx:n,afterChange:l}){return t.jsx(u,{sx:{...j,...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{S as F};