import{r,j as i}from"./iframe-p4aYZyoq.js";import{r as x}from"./index-CLmSyVZI.js";import{c as E}from"./index-Dx18ixSn.js";import{f as w}from"./timing-functions.es-CZdVE6Va.js";import{B as N}from"./button-BsNF7f-b.js";import{S as j}from"./times-DeY5Bu0x.js";const g='button:not([disabled]), [href]:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])',z=({children:p,onClose:l,position:d,size:v="medium",title:o,arrowX:u,className:_,pathname:c,...y})=>{const s=r.useRef(null),t=r.useRef(l);t.current=l,r.useEffect(()=>{var m;const e=document.activeElement;let n=null;const a=(m=s.current)==null?void 0:m.querySelector(g);return a?a.focus():(n=new MutationObserver(()=>{var h;const f=(h=s.current)==null?void 0:h.querySelector(g);f&&(f.focus(),n==null||n.disconnect())}),s.current&&(n==null||n.observe(s.current,{childList:!0,subtree:!0}))),()=>{e&&document.contains(e)&&(e==null||e.focus()),n==null||n.disconnect()}},[]),r.useEffect(()=>(t.current=l,()=>{t.current=void 0}),[l]),r.useEffect(()=>{const e=n=>{for(const a of document.querySelectorAll(".sliding-panel"))if(a.contains(n.target))return;w().then(()=>{var a;(a=t.current)==null||a.call(t,"outside")})};return document.addEventListener("click",e,!0),()=>{document.removeEventListener("click",e,!0)}},[]);const b=r.useRef(c);return r.useEffect(()=>{var e;b.current!==c&&((e=t.current)==null||e.call(t,"navigation"))},[c]),r.useEffect(()=>{const e=n=>{var a;n.key==="Escape"&&((a=t.current)==null||a.call(t,"escape"))};return document.addEventListener("keydown",e,{passive:!0}),()=>{document.removeEventListener("keydown",e)}},[]),x.createPortal(i.jsxs("aside",{"data-testid":"sliding-panel",className:E("sliding-panel",`sliding-panel--${d}`,`sliding-panel--${d}--${v}`,Number.isFinite(u)&&`sliding-panel--${d}--below-header`,_),ref:s,...y,children:[o&&i.jsxs("div",{className:"sliding-panel__header",children:[o&&i.jsx("span",{className:"small sliding-panel__header__title",children:o}),i.jsx(N,{variant:"tertiary",onClick:()=>{var e;return(e=t.current)==null?void 0:e.call(t,"x-button")},className:"sliding-panel__header__buttons",title:"Close panel",children:i.jsx(j,{})}),Number.isFinite(u)&&i.jsx("div",{className:"sliding-panel__header__arrow",style:{left:u}})]}),i.jsx("div",{className:"sliding-panel__content",children:p})]}),document.body)};try{slidingpanel.displayName="slidingpanel",slidingpanel.__docgenInfo={description:"",displayName:"slidingpanel",props:{onClose:{defaultValue:null,description:"What happens when close is triggered. Responsability of the user of the compoent",name:"onClose",required:!1,type:{name:'((reason: "navigation" | "outside" | "x-button" | "escape") => void)'}},size:{defaultValue:{value:"medium"},description:"Size of the panel once opened",name:"size",required:!1,type:{name:"enum",value:[{value:'"small"'},{value:'"medium"'},{value:'"large"'},{value:'"full-screen"'}]}},title:{defaultValue:null,description:"Title of the panel",name:"title",required:!1,type:{name:"ReactNode"}},pathname:{defaultValue:null,description:"Pathname of current location. When this changes the panel is closed.",name:"pathname",required:!0,type:{name:"string"}},position:{defaultValue:null,description:"Where the sliding panel should appear",name:"position",required:!0,type:{name:"enum",value:[{value:'"left"'},{value:'"right"'},{value:'"top"'},{value:'"bottom"'}]}},arrowX:{defaultValue:null,description:`Horizontal position of the arrow if the panel appears below the page header.
Also works as a flag to display the arrow and display below the header`,name:"arrowX",required:!1,type:{name:"number"}}}}}catch{}export{z as S};
