import{r as n}from"./vendor-react-CUXIiAnY.js";import{j as x,bg as S,W as h}from"./vendor-mui-core-BPQ6AEW_.js";import{b as k}from"./vendor-hooks-PN9SWiQm.js";import{p as z}from"./vendor-ux-r9bApERu.js";const b=(i,a=10,s=500)=>{if(typeof document>"u")return 0;const o=document.createElement("canvas").getContext("2d");return o.font=`${s} ${a}px sans-serif`,o.measureText(i).width};function M({checked:i,onChange:a,width:s=0}){const{t:e}=n.useContext(z),[o,c]=n.useState(!1),g=k(t=>{c(t.target.checked),a(t.target.checked)});n.useEffect(()=>{c(i)},[i]);const d=n.useMemo(()=>e(`webhookEndpoint.${o?"enabled":"disabled"}`),[o,e]),f=n.useMemo(()=>{const t=e("webhookEndpoint.enabled"),p=e("webhookEndpoint.disabled"),l=b(t,10,500),m=b(p,10,500),r=Math.max(l,m),w=18+3+r+6;return Math.max(Math.ceil(w/2)*2,50)},[e]),u=s||f;return x.jsx(S,{checked:o,onChange:g,sx:t=>{const r=u-18-6;return{width:u,height:24,padding:0,"& .MuiSwitch-switchBase":{padding:0,margin:"3px",transitionDuration:"300ms","&.Mui-checked":{transform:`translateX(${r}px)`,color:t.palette.common.white,"& + .MuiSwitch-track":{backgroundColor:t.palette.primary.main,opacity:1,border:0,"&:before":{content:`"${d}"`,position:"absolute",left:t.spacing(.75),top:"50%",transform:"translateY(-50%)",color:t.palette.common.white,fontSize:10,fontWeight:500}}}},"& .MuiSwitch-thumb":{width:18,height:18},"& .MuiSwitch-track":{borderRadius:24/2,backgroundColor:t.palette.grey[200],opacity:1,position:"relative","&:before":{content:`"${d}"`,position:"absolute",right:t.spacing(.75),top:"50%",transform:"translateY(-50%)",color:t.palette.text.secondary,fontSize:10,fontWeight:500}}}}})}M.propTypes={checked:h.bool.isRequired,onChange:h.func.isRequired,width:h.number};export{M as S};
