import{a as e,n as t}from"./chunk-BneVvdWh.js";import{t as n}from"./react-C7IZe2D1.js";import{t as r}from"./jsx-runtime-C2wGStra.js";import{t as i}from"./Button-DqcfuOFN.js";import{d as a,r as o,u as s,v as c,y as l}from"./AlertBannerAction-BKNUkKu8.js";var u,d,f,p,m,h,g,_,v,y,b,x,S,C;t((()=>{e(n(),1),a(),l(),o(),u=r(),{action:d}=__STORYBOOK_MODULE_ACTIONS__,{userEvent:f,expect:p,fn:m}=__STORYBOOK_MODULE_TEST__,h={title:`components/AlertBanner`,component:s,subcomponents:{AlertBannerProvider:c},args:{}},g={actionOnClick:m(d(`onCLicked`))},_={args:{},parameters:{chromatic:{modes:{"narrow-l":{viewport:`narrow-l`},"medium-l":{viewport:`medium-l`}}}},render:function(){return(0,u.jsxs)(c,{children:[(0,u.jsx)(s,{variant:`critical`,description:`We can't renew your subscription.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Try again`})}),(0,u.jsx)(s,{variant:`warning`,description:`Your credit card is about to expire.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Change payment method`})}),(0,u.jsx)(s,{variant:`positive`,description:`Your subscription has been renewed successfully.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Book the next lesson`})})]})},play:async({canvas:e,step:t})=>{let n=await e.findByRole(`button`,{name:/Try again/});await t(`actionOnClick is not called`,async()=>{p(g.actionOnClick).not.toBeCalled()}),await t(`actionOnClick is called`,async()=>{await f.click(n),p(g.actionOnClick).toBeCalled()})}},v={render:function(){return(0,u.jsxs)(c,{children:[(0,u.jsx)(s,{variant:`critical`,description:`We can't renew your subscription.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Try again`}),dataset:{testId:`subscriptionAlert`}}),(0,u.jsx)(s,{variant:`warning`,description:`Your credit card is about to expire.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Change payment method`}),dataset:{testid:`paymentWarning`}}),(0,u.jsx)(s,{variant:`positive`,description:`Your subscription has been renewed successfully.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Book the next lesson`}),dataset:{testid:`subscriptionRenewed`}})]})},play:async({canvas:e,step:t})=>{await t(`Alert banners are prefixed with "Alert:" to allow screen reader users to recall the alerts region`,async()=>{await p(await e.findByTestId(`subscriptionAlert`)).toHaveTextContent(`Alert: We can't renew your subscription.Try again`)}),await t(`Warning banners are prefixed with "Warning:" to allow screen reader users to recall the alerts region`,async()=>{await p(await e.findByTestId(`paymentWarning`)).toHaveTextContent(`Warning: Your credit card is about to expire.Change payment method`)}),await t(`Positive banners are prefixed with "Update:" to allow screen reader users to recall the updates region`,async()=>{await p(await e.findByTestId(`subscriptionRenewed`)).toHaveTextContent(`Update: Your subscription has been renewed successfully.Book the next lesson`)})}},y={render:function(){return(0,u.jsxs)(c,{"data-testid":`alertBannerHostId`,children:[(0,u.jsx)(`div`,{id:`pageContents`,children:`Page contents`}),(0,u.jsx)(s,{variant:`critical`,description:`We can't renew your subscription.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Try again`}),dataset:{testId:`subscriptionAlert`}})]})},play:async({canvas:e,step:t})=>{let n=e.getByTestId(`alertBannerHostId`);await t(`The host is announced as "Alerts, warnings, and updates"`,async()=>{await p(n).toHaveAccessibleName(`Alerts, warnings, and updates`)}),await t(`The host renders an aria-live region`,async()=>{await p(n).toHaveAttribute(`aria-live`),await p(n).toHaveAttribute(`aria-atomic`,`false`),await p(n).toHaveRole(`region`)}),await t(`Alert banners are rendered at the top of the page`,async()=>{let t=document.getElementById(`pageContents`);if(!t)throw Error(`Page contents element not found`);let n=await e.findByTestId(`subscriptionAlert`);p(!!(n.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)).toBe(!0)})}},b=`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,x=`Lorem ipsum dolor sit amet, consectetur adipiscing elit. sed do eiusmod tempor incididunt.`,S={render:function(){return(0,u.jsxs)(c,{children:[(0,u.jsx)(s,{variant:`warning`,description:b,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:`Try again`})}),(0,u.jsx)(s,{variant:`warning`,description:`We can't renew your subscription.`,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:x})}),(0,u.jsx)(s,{variant:`warning`,description:b,action:(0,u.jsx)(i,{onClick:g.actionOnClick,children:x})})]})}},_.parameters={..._.parameters,docs:{..._.parameters?.docs,source:{originalSource:`{
  args: {},
  parameters: {
    chromatic: {
      modes: {
        'narrow-l': {
          viewport: 'narrow-l'
        },
        'medium-l': {
          viewport: 'medium-l'
        }
      }
    }
  },
  render: function Story() {
    return <AlertBannerProvider>
                <AlertBanner variant="critical" description="We can't renew your subscription." action={<Button onClick={callback.actionOnClick}>Try again</Button>} />
                <AlertBanner variant="warning" description="Your credit card is about to expire." action={<Button onClick={callback.actionOnClick}>Change payment method</Button>} />
                <AlertBanner variant="positive" description="Your subscription has been renewed successfully." action={<Button onClick={callback.actionOnClick}>Book the next lesson</Button>} />
            </AlertBannerProvider>;
  },
  play: async ({
    canvas,
    step
  }) => {
    const tryAgain = await canvas.findByRole('button', {
      name: /Try again/
    });
    await step('actionOnClick is not called', async () => {
      expect(callback.actionOnClick).not.toBeCalled();
    });
    await step('actionOnClick is called', async () => {
      await userEvent.click(tryAgain);
      expect(callback.actionOnClick).toBeCalled();
    });
  }
}`,..._.parameters?.docs?.source}}},v.parameters={...v.parameters,docs:{...v.parameters?.docs,source:{originalSource:`{
  render: function Story() {
    return <AlertBannerProvider>
                <AlertBanner variant="critical" description="We can't renew your subscription." action={<Button onClick={callback.actionOnClick}>Try again</Button>} dataset={{
        testId: 'subscriptionAlert'
      }} />
                <AlertBanner variant="warning" description="Your credit card is about to expire." action={<Button onClick={callback.actionOnClick}>Change payment method</Button>} dataset={{
        testid: 'paymentWarning'
      }} />
                <AlertBanner variant="positive" description="Your subscription has been renewed successfully." action={<Button onClick={callback.actionOnClick}>Book the next lesson</Button>} dataset={{
        testid: 'subscriptionRenewed'
      }} />
            </AlertBannerProvider>;
  },
  play: async ({
    canvas,
    step
  }) => {
    await step('Alert banners are prefixed with "Alert:" to allow screen reader users to recall the alerts region', async () => {
      const subscriptionAlert = await canvas.findByTestId('subscriptionAlert');
      await expect(subscriptionAlert).toHaveTextContent("Alert: We can't renew your subscription.Try again");
    });
    await step('Warning banners are prefixed with "Warning:" to allow screen reader users to recall the alerts region', async () => {
      const paymentWarning = await canvas.findByTestId('paymentWarning');
      await expect(paymentWarning).toHaveTextContent('Warning: Your credit card is about to expire.Change payment method');
    });
    await step('Positive banners are prefixed with "Update:" to allow screen reader users to recall the updates region', async () => {
      const paymentWarning = await canvas.findByTestId('subscriptionRenewed');
      await expect(paymentWarning).toHaveTextContent('Update: Your subscription has been renewed successfully.Book the next lesson');
    });
  }
}`,...v.parameters?.docs?.source},description:{story:`The alert banners are announced to screen readers with a prefix depending on their type. This
allows to quickly recall the alerts region (rendered by \`AlertBannerProvider\`) that is put at the top
of the page.

@see AlertBannerProvider`,...v.parameters?.docs?.description}}},y.parameters={...y.parameters,docs:{...y.parameters?.docs,source:{originalSource:`{
  render: function Story() {
    return <AlertBannerProvider data-testid="alertBannerHostId">
                <div id="pageContents">Page contents</div>
                <AlertBanner variant="critical" description="We can't renew your subscription." action={<Button onClick={callback.actionOnClick}>Try again</Button>} dataset={{
        testId: 'subscriptionAlert'
      }} />
            </AlertBannerProvider>;
  },
  play: async ({
    canvas,
    step
  }) => {
    const host = canvas.getByTestId('alertBannerHostId');
    await step('The host is announced as "Alerts, warnings, and updates"', async () => {
      await expect(host).toHaveAccessibleName('Alerts, warnings, and updates');
    });
    await step('The host renders an aria-live region', async () => {
      await expect(host).toHaveAttribute('aria-live');
      await expect(host).toHaveAttribute('aria-atomic', 'false');
      await expect(host).toHaveRole('region');
    });
    await step('Alert banners are rendered at the top of the page', async () => {
      const pageContents = document.getElementById('pageContents');
      if (!pageContents) throw new Error('Page contents element not found');
      const subscriptionAlert = await canvas.findByTestId('subscriptionAlert');
      const pageContentsComesAfterAlertBanner = Boolean(subscriptionAlert.compareDocumentPosition(pageContents) & Node.DOCUMENT_POSITION_FOLLOWING);
      expect(pageContentsComesAfterAlertBanner).toBe(true);
    });
  }
}`,...y.parameters?.docs?.source},description:{story:`\`AlertBannerProvider\` should wrap the whole app so its DOM element is put at the top of the page,
and renders an aria-live region that will be announced as "Alerts, warnings, and updates".
Screen readers users will remind (and can navigate to) the region when alerts will be announced.`,...y.parameters?.docs?.description}}},S.parameters={...S.parameters,docs:{...S.parameters?.docs,source:{originalSource:`{
  render: function Story() {
    return <AlertBannerProvider>
                <AlertBanner variant="warning" description={LOREM_IPSUM_LONG} action={<Button onClick={callback.actionOnClick}>Try again</Button>} />
                <AlertBanner variant="warning" description={"We can't renew your subscription."} action={<Button onClick={callback.actionOnClick}>{LOREM_IPSUM_SHORT}</Button>} />
                <AlertBanner variant="warning" description={LOREM_IPSUM_LONG} action={<Button onClick={callback.actionOnClick}>{LOREM_IPSUM_SHORT}</Button>} />
            </AlertBannerProvider>;
  }
}`,...S.parameters?.docs?.source}}},C=[`Variants`,`Accessibility`,`AlertBannerProviderAccessibility`,`LongContents`]}))();export{v as Accessibility,y as AlertBannerProviderAccessibility,S as LongContents,_ as Variants,C as __namedExportsOrder,h as default};