import{j as o}from"./jsx-runtime-CnH95YSl.js";import{w as it,u as O,e as ct}from"./index-BJMTVygn.js";import{r as s}from"./index-NdkWRN8K.js";import{a as st}from"./axeRun-B-LchFqf.js";import{O as lt}from"./OdysseyStorybookThemeDecorator-BuDiOG2V.js";import{f as m}from"./fieldComponentPropsMetaData-BqbNLw6V.js";import{K as ut,u as J,h as l,M as dt}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{M as ht}from"./Box-1mvP3NLW.js";import{M as pt}from"./FieldHint-B3Jif_Up.js";import{g as mt,C as bt}from"./inputUtils-Dbi8XkA6.js";import{u as ft}from"./useUniqueId-Bsgqe1tm.js";import{F as wt}from"./FormLabel-CiGre9wK.js";import{M as Ct}from"./Link-BDoLypER.js";import"./_commonjsHelpers-gnU0ypJ3.js";import"./axe-4JP0vCEZ.js";import"./index-BJTM6NaI.js";import"./OdysseyProvider-qIn9QVYS.js";import"./Box-BcMTQ_R2.js";import"./createBox-Dxawkfow.js";import"./FormHelperText-CsNAE1E3.js";import"./useFormControl-BMISTZuX.js";import"./createUniqueId-ByTaVY63.js";import"./Link-DNIf0luC.js";import"./useIsFocusVisible-DH0qxT5e.js";import"./Typography-ClQ35Rr-.js";import"./ExternalLink-D0l1c5Cz.js";/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const kt=e=>o.jsx(Ct,{...e,variant:"default"}),Q=s.memo(kt);Q.displayName="HintLink";/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const D=e=>Number(e.replace(/rem$/,"")),w=e=>e/14,{CONTROLLED:H}=bt,b=["isChecked","isDisabled","isFullWidth","isReadOnly","odysseyDesignTokens"],St=l("div",{shouldForwardProp:e=>!b.includes(e)})(({isFullWidth:e,odysseyDesignTokens:r})=>({display:"flex",alignItems:"flex-start",justifyContent:"space-between",maxWidth:e?"100%":r.TypographyLineLengthMax})),xt=l.div({position:"relative"}),gt=l(wt,{shouldForwardProp:e=>!b.includes(e)})(({isDisabled:e,isReadOnly:r,odysseyDesignTokens:a})=>({display:"block",margin:0,color:a.PaletteNeutralDark,...e&&{color:a.TypographyColorDisabled,p:{color:a.TypographyColorDisabled},a:{color:`${a.TypographyColorDisabled} !important`}},...r&&{color:a.HueNeutral700,p:{color:a.HueNeutral700},a:{color:`${a.HueNeutral700} !important`}}})),vt=l("div",{shouldForwardProp:e=>!b.includes(e)})(({isChecked:e,isDisabled:r,isReadOnly:a,odysseyDesignTokens:t})=>({position:"relative",width:t.Spacing7,height:`calc(${t.Spacing4} + ${t.Spacing1})`,borderRadius:t.BorderRadiusOuter,backgroundColor:t.HueNeutral300,transition:`background-color ${t.TransitionDurationMain}`,...r&&{backgroundColor:t.HueNeutral200},...a&&{backgroundColor:t.HueNeutral600},...e&&!r&&!a&&{backgroundColor:t.PaletteSuccessLight}})),yt=l("span",{shouldForwardProp:e=>!b.includes(e)})(({isChecked:e,isDisabled:r,isReadOnly:a,odysseyDesignTokens:t})=>{const i=w(3),c=D(t.Spacing7),u=D(t.Spacing4)-w(2),n=c-u-i*2;return{position:"absolute",top:"50%",left:`${i}rem`,width:`calc(${t.Spacing4} - ${w(2)}rem)`,height:`calc(${t.Spacing4} - ${w(2)}rem)`,borderRadius:t.BorderRadiusRound,backgroundColor:t.HueNeutralWhite,transform:"translate3d(0, -50%, 0)",transition:`transform ${t.TransitionDurationMain}`,...r&&{backgroundColor:t.HueNeutral50},...a&&{backgroundColor:t.HueNeutral400},...e&&{transform:`translate3d(${n}rem, -50%, 0)`}}}),$t=l(dt,{shouldForwardProp:e=>!b.includes(e)})(({isChecked:e,isDisabled:r,isReadOnly:a,odysseyDesignTokens:t})=>({position:"absolute",top:"50%",left:3,width:t.Spacing4,transform:"translateY(-50%)",transition:`opacity ${t.TransitionDurationMain}`,opacity:0,path:{fill:t.HueNeutralWhite},...e&&{opacity:1},...(r||a)&&{path:{fill:t.HueNeutral50}}})),Ht=l.input(({odysseyDesignTokens:e,isReadOnly:r})=>({position:"absolute",top:0,left:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:r?"default":"pointer",zIndex:2,"&:focus-visible":{"~ [data-switch-track='true']":{boxShadow:`0 0 0 2px ${e.HueNeutralWhite}, 0 0 0 4px ${e.PalettePrimaryMain}`}}})),T=({hint:e,hintId:r,HintLinkComponent:a,inputId:t,isDisabled:i,label:c,isReadOnly:u})=>{const n=J();return o.jsx(o.Fragment,{children:o.jsxs(gt,{htmlFor:t,isDisabled:i,isReadOnly:u,odysseyDesignTokens:n,children:[c,e&&o.jsx(pt,{id:r,LinkComponent:a,text:e})]})})},Lt=s.memo(T);T.displayName="SwitchLabel";const Mt=({hint:e,HintLinkComponent:r,id:a,isChecked:t,isDefaultChecked:i,isDisabled:c,isFullWidth:u=!1,isReadOnly:n=!1,label:v,name:X,onChange:f,testId:Z,value:tt})=>{const{t:M}=ut(),d=J(),y=s.useRef(mt({controlledValue:t,uncontrolledValue:i})),et=s.useMemo(()=>y.current===H?{checked:t}:{defaultChecked:i},[i,t]),[h,$]=s.useState(y.current===H?!!t:!!i);s.useEffect(()=>{y.current===H&&$(!!t)},[t]);const p=ft(a),N=e?`${p}-hint`:void 0,at=`${p}-label`,rt=s.useCallback(R=>{if(n){R.preventDefault();return}const ot=R.target,{checked:j,value:nt}=ot;$(j),f==null||f({checked:j,value:nt})},[f,$,n]);return o.jsx(ht,{sx:{marginBlockEnd:d.Spacing2,"&:last-child":{marginBlockEnd:0}},children:o.jsxs(St,{isFullWidth:u,odysseyDesignTokens:d,children:[o.jsx(Lt,{hint:e,hintId:N,HintLinkComponent:r,inputId:p,isDisabled:c,isFullWidth:u,isReadOnly:n,label:v}),o.jsxs(xt,{children:[o.jsx(Ht,{...et,"aria-checked":h,"aria-describedby":N,"aria-label":h?`${v}: ${M("switch.active")}`:`${v}: ${M("switch.inactive")}`,"aria-labelledby":at,"data-se":Z,disabled:c,id:p,isReadOnly:n,name:X??p,odysseyDesignTokens:d,onChange:rt,readOnly:n,type:"checkbox",value:tt}),o.jsxs(vt,{"data-switch-track":!0,isChecked:h,isDisabled:c,isReadOnly:n,odysseyDesignTokens:d,children:[o.jsx(yt,{isChecked:h,isDisabled:c,isReadOnly:n,odysseyDesignTokens:d}),o.jsx($t,{isChecked:h,isDisabled:c,isReadOnly:n,odysseyDesignTokens:d})]})]})]})})},L=s.memo(Mt);L.displayName="Switch";const ee={component:L,decorators:[lt],tags:["autodocs"],argTypes:{isChecked:{control:"boolean",description:"If `true`, the Switch button is checked",table:{type:{summary:"boolean"}}},isDefaultChecked:{control:"boolean",description:"If `true`, the Switch button is checked by default",table:{type:{summary:"boolean"}}},hint:m.hint,HintLinkComponent:m.HintLinkComponent,id:m.id,isDisabled:m.isDisabled,isReadOnly:{control:"boolean",description:"The value attribute of the Switch",table:{type:{summary:"boolean"},defaultValue:{summary:"false"}}},label:{control:"text",description:"The label text for the Switch button",table:{type:{summary:"string"}},type:{required:!0,name:"string"}},name:m.name,value:{control:"text",description:"The value attribute of the Switch button",table:{type:{summary:"string"}},type:{required:!0,name:"string"}}},args:{hint:"Optional hint text",label:"Switch label",value:"Switch value",HintLinkComponent:o.jsx(Q,{href:"",children:"Some hint link"})}},C={play:async({canvasElement:e,step:r})=>{await r("select the switch button",async()=>{const t=it(e).getByRole("checkbox");t&&await O.click(t),await ct(t).toBeChecked(),await st("Switch Default"),await O.tab()})}},k={args:{isDisabled:!0}},S={args:{isDisabled:!0,isDefaultChecked:!0}},x={args:{isReadOnly:!0,isDefaultChecked:!0}},g={render:function({...r}){const[a,t]=s.useState(!0),i=s.useCallback(({checked:c})=>t(c),[]);return o.jsx(L,{...r,isChecked:a,onChange:i})}};var E,F,B;C.parameters={...C.parameters,docs:{...(E=C.parameters)==null?void 0:E.docs,source:{originalSource:`{
  play: async ({
    canvasElement,
    step
  }) => {
    await step("select the switch button", async () => {
      const canvas = within(canvasElement);
      const switchCheckbox = canvas.getByRole("checkbox");
      if (switchCheckbox) {
        await userEvent.click(switchCheckbox);
      }
      await expect(switchCheckbox).toBeChecked();
      await axeRun("Switch Default");
      await userEvent.tab();
    });
  }
}`,...(B=(F=C.parameters)==null?void 0:F.docs)==null?void 0:B.source}}};var I,P,z;k.parameters={...k.parameters,docs:{...(I=k.parameters)==null?void 0:I.docs,source:{originalSource:`{
  args: {
    isDisabled: true
  }
}`,...(z=(P=k.parameters)==null?void 0:P.docs)==null?void 0:z.source}}};var W,V,q;S.parameters={...S.parameters,docs:{...(W=S.parameters)==null?void 0:W.docs,source:{originalSource:`{
  args: {
    isDisabled: true,
    isDefaultChecked: true
  }
}`,...(q=(V=S.parameters)==null?void 0:V.docs)==null?void 0:q.source}}};var _,A,K;x.parameters={...x.parameters,docs:{...(_=x.parameters)==null?void 0:_.docs,source:{originalSource:`{
  args: {
    isReadOnly: true,
    isDefaultChecked: true
  }
}`,...(K=(A=x.parameters)==null?void 0:A.docs)==null?void 0:K.source}}};var U,Y,G;g.parameters={...g.parameters,docs:{...(U=g.parameters)==null?void 0:U.docs,source:{originalSource:`{
  render: function C({
    ...props
  }) {
    const [checked, setChecked] = useState(true);
    const onChange = useCallback<NonNullable<SwitchProps["onChange"]>>(({
      checked
    }) => setChecked(checked), []);
    return <Switch {...props} isChecked={checked} onChange={onChange} />;
  }
}`,...(G=(Y=g.parameters)==null?void 0:Y.docs)==null?void 0:G.source}}};const ae=["Default","Disabled","CheckedDisabled","CheckedReadOnly","Controlled"];export{S as CheckedDisabled,x as CheckedReadOnly,g as Controlled,C as Default,k as Disabled,ae as __namedExportsOrder,ee as default};
