import{e as f}from"./iframe-Cf-Lpz6Y.js";import{r as O,e as u}from"./index-NdkWRN8K.js";const{STORY_CHANGED:E,SELECT_STORY:k}=__STORYBOOK_MODULE_CORE_EVENTS__,{makeDecorator:L,addons:_}=__STORYBOOK_MODULE_PREVIEW_API__,{global:v}=__STORYBOOK_MODULE_GLOBAL__;var T=Object.defineProperty,y=(e,t)=>{for(var n in t)T(e,n,{get:t[n],enumerable:!0})},C="links",{document:c,HTMLElement:R}=v;function D(e){let t={},n=(e[0]==="?"?e.substring(1):e).split("&").filter(Boolean);for(let r=0;r<n.length;r++){let i=n[r].split("=");t[decodeURIComponent(i[0])]=decodeURIComponent(i[1]||"")}return t}var p=e=>_.getChannel().emit(k,e),K=(e,t)=>new Promise(n=>{let{location:r}=c,i=D(r.search).id,s=e||i.split("--",2)[0],o=`/story/${f(s,t)}`,l=r.pathname.replace(/iframe\.html$/,""),m=`${r.origin+l}?${Object.entries({path:o}).map(d=>`${d[0]}=${d[1]}`).join("&")}`;n(m)}),h=e=>{let{target:t}=e;if(!(t instanceof R))return;let n=t,{sbKind:r,sbStory:i}=n.dataset;(r||i)&&(e.preventDefault(),p({kind:r,story:i}))},a=!1,P=()=>{a||(a=!0,c.addEventListener("click",h))},b=()=>{a&&(a=!1,c.removeEventListener("click",h))},g=L({name:"withLinks",parameterName:C,wrapper:(e,t)=>(P(),_.getChannel().once(E,b),e(t))});const{definePreview:$}=__STORYBOOK_MODULE_PREVIEW_API__;var S={};y(S,{decorators:()=>U});var U=[g],w=0,B=e=>e.button===w&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey,I=(e,t=n=>{})=>{B(e)&&(e.preventDefault(),t(e))},M=class extends O.PureComponent{constructor(){super(...arguments),this.state={href:"/"},this.updateHref=async()=>{let{kind:e,title:t=e,story:n,name:r=n}=this.props;if(t&&r){let i=await K(t,r);this.setState({href:i})}},this.handleClick=()=>{let{kind:e,title:t=e,story:n,name:r=n}=this.props;t&&r&&p({title:t,name:r})}}componentDidMount(){this.updateHref()}componentDidUpdate(e){let{kind:t,title:n,story:r,name:i}=this.props;(e.kind!==t||e.story!==r||e.title!==n||e.name!==i)&&this.updateHref()}render(){let{kind:e,title:t=e,story:n,name:r=n,children:i,...s}=this.props,{href:o}=this.state;return u.createElement("a",{href:o,onClick:l=>I(l,this.handleClick),...s},i)}};M.defaultProps={children:void 0};
