import{af as $,ag as m,ah as w,ai as A,h as I,aj as j,ak as H,al as z,i as G,m as n,am as b,a1 as l,an as R,ao as P,ap as U,aq as S,ar as X,as as J,at as Q,au as V,av as W,aw as Y,ax as Z,ay as ee,az as te,X as re,aA as ne,n as oe,aB as C,aC as ae,aD as se,aE as ce,S as D}from"./index-Cl9Gy4vs.js";var ie={};ce(ie,{Control:()=>O,Description:()=>_,ErrorMessage:()=>E,Input:()=>M,Label:()=>B,Root:()=>T,Switch:()=>i,Thumb:()=>q,useSwitchContext:()=>f});var L=ee();function f(){const r=ae(L);if(r===void 0)throw new Error("[kobalte]: `useSwitchContext` must be used within a `Switch` component");return r}function O(r){const e=S(),t=f(),d=m({id:t.generateId("control")},r),[o,u]=w(d,["onClick","onKeyDown"]);return n(b,l({as:"div",onClick:g=>{C(g,o.onClick),t.toggle(),t.inputRef()?.focus()},onKeyDown:g=>{C(g,o.onKeyDown),g.key===se.Space&&(t.toggle(),t.inputRef()?.focus())}},()=>e.dataset(),()=>t.dataset(),u))}function _(r){const e=f();return n(Z,l(()=>e.dataset(),r))}function E(r){const e=f();return n(Y,l(()=>e.dataset(),r))}function M(r){const e=S(),t=f(),d=m({id:t.generateId("input")},r),[o,u,p]=w(d,["ref","style","onChange","onFocus","onBlur"],J),{fieldProps:h}=Q(u);return n(b,l({as:"input",ref(a){var s=P(t.setInputRef,o.ref);typeof s=="function"&&s(a)},type:"checkbox",role:"switch",get id(){return h.id()},get name(){return e.name()},get value(){return t.value()},get checked(){return t.checked()},get required(){return e.isRequired()},get disabled(){return e.isDisabled()},get readonly(){return e.isReadOnly()},get style(){return V({...W},o.style)},get"aria-checked"(){return t.checked()},get"aria-label"(){return h.ariaLabel()},get"aria-labelledby"(){return h.ariaLabelledBy()},get"aria-describedby"(){return h.ariaDescribedBy()},get"aria-invalid"(){return e.validationState()==="invalid"||void 0},get"aria-required"(){return e.isRequired()||void 0},get"aria-disabled"(){return e.isDisabled()||void 0},get"aria-readonly"(){return e.isReadOnly()||void 0},onChange:a=>{C(a,o.onChange),a.stopPropagation();const s=a.target;t.setIsChecked(s.checked),s.checked=t.checked()},onFocus:a=>{C(a,o.onFocus),t.setIsFocused(!0)},onBlur:a=>{C(a,o.onBlur),t.setIsFocused(!1)}},()=>e.dataset(),()=>t.dataset(),p))}function B(r){const e=f();return n(X,l(()=>e.dataset(),r))}function T(r){let e;const t=`switch-${$()}`,d=m({value:"on",id:t},r),[o,u,p]=w(d,["ref","children","value","checked","defaultChecked","onChange","onPointerDown"],A),[h,g]=I(),[v,y]=I(!1),{formControlContext:a}=j(u),s=H({isSelected:()=>o.checked,defaultIsSelected:()=>o.defaultChecked,onSelectedChange:c=>o.onChange?.(c),isDisabled:()=>a.isDisabled(),isReadOnly:()=>a.isReadOnly()});z(()=>e,()=>s.setIsSelected(o.defaultChecked??!1));const K=c=>{C(c,o.onPointerDown),v()&&c.preventDefault()},x=G(()=>({"data-checked":s.isSelected()?"":void 0})),k={value:()=>o.value,dataset:x,checked:()=>s.isSelected(),inputRef:h,generateId:te(()=>R(u.id)),toggle:()=>s.toggle(),setIsChecked:c=>s.setIsSelected(c),setIsFocused:y,setInputRef:g};return n(U.Provider,{value:a,get children(){return n(L.Provider,{value:k,get children(){return n(b,l({as:"div",ref(c){var F=P(N=>e=N,o.ref);typeof F=="function"&&F(c)},role:"group",get id(){return R(u.id)},onPointerDown:K},()=>a.dataset(),x,p,{get children(){return n(le,{state:k,get children(){return o.children}})}}))}})}})}function le(r){const e=re(()=>{const t=r.children;return ne(t)?t(r.state):t});return oe(e)}function q(r){const e=S(),t=f(),d=m({id:t.generateId("thumb")},r);return n(b,l({as:"div"},()=>e.dataset(),()=>t.dataset(),d))}var i=Object.assign(T,{Control:O,Description:_,ErrorMessage:E,Input:M,Label:B,Thumb:q});function ue(r){const[e,t]=w(r,["children","class","hideLabel","description"]);return n(i,l(t,{get class(){return e.class},"data-component":"switch",get children(){return[n(i.Input,{"data-slot":"switch-input"}),n(D,{get when(){return e.children},get children(){return n(i.Label,{"data-slot":"switch-label",get classList(){return{"sr-only":e.hideLabel}},get children(){return e.children}})}}),n(D,{get when(){return e.description},get children(){return n(i.Description,{"data-slot":"switch-description",get children(){return e.description}})}}),n(i.ErrorMessage,{"data-slot":"switch-error"}),n(i.Control,{"data-slot":"switch-control",get children(){return n(i.Thumb,{"data-slot":"switch-thumb"})}})]}}))}export{ue as S};
