import{a as e,n as t}from"./chunk-BneVvdWh.js";import{t as n}from"./react-C7IZe2D1.js";import{ht as r,t as i}from"./dist-DtfJeYQK.js";import{t as a}from"./jsx-runtime-C2wGStra.js";import{n as o,t as s}from"./dist-Cc1j9Pjk.js";import{n as c,t as l}from"./Text-DO3xXyuu.js";import{n as u,t as d}from"./Heading-BfSBs5r6.js";import{n as f,t as p}from"./Button-DqcfuOFN.js";import{i as m,r as h}from"./lib-8ue2PVWI.js";import{n as g,t as _}from"./ProgressSteps-B2AXEKFJ.js";var v,y,b,x=t((()=>{v=`steps__6mN2m`,y=`header__hCorO`,b={steps:v,header:y}})),S,C,w,T,E,D,O,k,A,j=t((()=>{S=e(n(),1),f(),x(),h(),i(),s(),u(),g(),c(),C=a(),w=(0,S.createContext)(void 0),T=()=>{let e=(0,S.useContext)(w);if(e===void 0)throw Error(`Steps navigation components must be used within a Steps component`);return e||{}},E=(0,S.forwardRef)(function({onClick:e,disabled:t,variant:n=`ghost`,...r},i){let{goToPreviousStep:a,currentStep:o,isNavigating:s,contentId:c}=T();return(0,C.jsx)(p,{...r,ref:i,size:`medium`,variant:n,onClick:t=>{e?.(t),!t.defaultPrevented&&a()},disabled:o===1||s||t,"aria-controls":c,children:r.children||(0,C.jsx)(m,{id:`preply-ds.steps.previous`,defaultMessage:`Previous`,description:`Button used to navigate to the previous step`})})}),D=(0,S.forwardRef)(function({onClick:e,disabled:t,variant:n=`primary`,...r},i){let{goToNextStep:a,currentStep:o,totalSteps:s,isNavigating:c,contentId:l}=T();return(0,C.jsx)(p,{...r,ref:i,size:`medium`,variant:n,onClick:t=>{e?.(t),!t.defaultPrevented&&a()},disabled:o===s||c||t,"aria-controls":l,children:r.children||(0,C.jsx)(m,{id:`preply-ds.steps.next`,defaultMessage:`Next`,description:`Button used to navigate to the next step`})})}),O=({children:e,"aria-label":t,initialStep:n=1,onStepChange:i,dataset:a})=>{let s=(0,S.useId)(),[c,l]=(0,S.useState)(n),[u,d]=(0,S.useState)(!1),f=[],p=[];e?.forEach(e=>{(0,S.isValidElement)(e)&&e.type===k?f.push(e):p.push(e)});let m=f.length,h=r(a,{preplyDsComponent:o.Steps}),g=async e=>{let t=Math.min(Math.max(e,1),m);if(!i){l(t);return}d(!0);try{l(await i(c,t)??t)}finally{d(!1)}},v={goToPreviousStep:()=>g(c-1),goToNextStep:()=>g(c+1),goToStep:e=>g(e),currentStep:c,totalSteps:m,isNavigating:u,contentId:s};return(0,C.jsxs)(`div`,{...h,className:b.steps,id:s,"aria-live":`polite`,"aria-busy":u,children:[(0,C.jsx)(_,{currentStep:c,totalSteps:m,"aria-label":t}),(0,C.jsx)(`div`,{className:b.content,children:(0,C.jsxs)(w.Provider,{value:v,children:[f[c-1],p]})})]})},k=({title:e,description:t,children:n,hideHeader:r})=>(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(`hgroup`,{className:b.header,hidden:r,children:[(0,C.jsx)(d,{tag:`h3`,variant:{_:`medium`,"medium-l":`large`},children:e}),t&&(0,C.jsx)(l,{variant:`default-regular`,accent:`secondary`,children:t})]}),n]}),A=Object.assign(O,{Step:k,Previous:E,Next:D});try{A.displayName=`Steps`,A.__docgenInfo={description:"This component allows users to navigate through a series of steps, providing\na structured way to complete tasks or forms. It will also handle screen reader\nannouncements and progress indicators.\n\nTo create a step, wrap the content of each step in a `Steps.Step` component.\nAny non-`Steps.Step` children will be rendered outside of the steps flow,\nright after the currently active step.\n\nTo navigate between steps, use the `Steps.Previous` and `Steps.Next` components.\nAlternatively, you can use the `StepsContext` directly to call\n`goToPreviousStep`, `goToNextStep`, or `goToStep`.",displayName:`Steps`,props:{"aria-label":{defaultValue:null,description:`A description of the step flow and its content for screen readers.
@example 'Onboarding Steps', 'Checkout Steps', 'Survey Steps', etc.`,name:`aria-label`,required:!0,type:{name:`string`}},initialStep:{defaultValue:{value:`1`},description:"The initial step to start at (from `1` to `children.length`).",name:`initialStep`,required:!1,type:{name:`enum`,value:[{value:`number`}]}},onStepChange:{defaultValue:null,description:`Optional callback to control navigation between steps.

This is triggered either by using the \`Steps.Previous\` and \`Steps.Next\`
components, or by calling \`goToPreviousStep\`, \`goToNextStep\`, or
\`goToStep\` from the \`StepsContext\`.

Can be used to:
- Skip/redirect steps conditionally
- Perform async process (e.g. validation) on step changes, marking the
  element as busy/loading
@param currentStep The current step (1-based)
@param nextStep The next, incoming step
@returns Promise that resolves to:
- \`undefined\`: proceed with default navigation
- \`number\`: override the destination step
@example Add async validation
const handleStepChange = async (current, next) => {
await validateStep(current);
return next;
};
@example Skip a step
const handleStepChange = async (current, next) => {
if (next === 2) return 3; // Skip step 2
return next;
};`,name:`onStepChange`,required:!1,type:{name:`enum`,value:[{value:`(currentStep: number, nextStep: number) => number | Promise<number | undefined> | undefined`}]}},dataset:{defaultValue:null,description:``,name:`dataset`,required:!1,type:{name:`enum`,value:[{value:`Dataset`}]}}}}}catch{}}));export{j as n,T as r,A as t};