"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("@babel/runtime/helpers/defineProperty"),r=require("react"),n=require("prop-types"),i=require("lodash"),o=require("classnames"),a=require("@material-ui/core"),l=require("react/jsx-runtime");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=c(e),u=c(t),p=c(n),f=c(o);function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function h(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){u.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var m=a.makeStyles((function(e){return{root:u.default({top:70,width:175,flexShrink:0,position:"sticky",height:"calc(100vh - 70px)",overflowY:"auto",padding:e.spacing(2,0),display:"none"},e.breakpoints.up("sm"),{display:"block"}),title:{color:e.palette.primary.text8,margin:"0 0 8px 16px",lineHeight:"24px",fontSize:10,fontWeight:500,letterSpacing:1},contents:{marginTop:e.spacing(2),paddingLeft:e.spacing(1)},ul:{padding:0,margin:0,listStyle:"none",borderLeft:"1px solid ".concat(e.palette.background.b9)},li:{display:"flex","&:not(:first-of-type)":{marginTop:8}},item:{color:e.palette.primary.text6,display:"inline-block",margin:"7px 16px",fontSize:12,fontWeight:400,letter:"0.4px",lineHeight:"16px"},active:{color:e.palette.text.primary,fontWeight:500},activeItemBorder:{height:30,width:"2px",backgroundColor:"#03BCD4",borderRadius:"0 2px 2px 0",position:"absolute"}}}));function g(e){var t=e.title,n=e.items,o=m(),c=r.useRef([]);r.useEffect((function(){c.current=n.map((function(e){return h(h({},e),{},{node:document.getElementById(e.hash)})}))}),[n]);var u,p,d,g=r.useState(null),y=s.default(g,2),b=y[0],x=y[1],v=r.useRef(!1),j=r.useRef(null),O=r.useCallback((function(){if(!v.current){for(var e,t=c.current.length-1;t>=0;t-=1){if(document.documentElement.scrollTop<100){e={hash:null};break}var r=c.current[t];if(r.node&&r.node.offsetTop<document.documentElement.scrollTop+document.documentElement.clientHeight/8){e=r;break}}e&&b!==e.hash&&x(e.hash)}}),[b]);u=n.length>0?O:null,p=166,d=r.useMemo((function(){return u?i.throttle(u,p):i.noop}),[u,p]),r.useEffect((function(){if(d!==i.noop)return window.addEventListener("scroll",d),function(){window.removeEventListener("scroll",d),d.cancel()}}),[d]);return r.useEffect((function(){return function(){clearTimeout(j.current)}}),[]),r.useEffect((function(){var e=window.location.hash;if(e){var t=document.getElementById(e.substr(1));t&&setTimeout((function(){t.scrollIntoView({block:"start",inline:"nearest",behavior:"smooth"})}),50)}}),[]),l.jsx("nav",{className:o.root,"data-testid":"anchors-list",children:n.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:o.title,children:t}),l.jsx(a.Typography,{component:"ul",className:o.ul,children:n.map((function(e){var t,r=b===e.hash;return l.jsxs("li",{className:o.li,children:[r&&l.jsx("div",{className:o.activeItemBorder}),l.jsx(a.Link,{display:"block",href:"#".concat(e.hash),underline:"none",onClick:(t=e.hash,function(e){e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.altKey||e.shiftKey||(v.current=!0,j.current=setTimeout((function(){v.current=!1}),1e3),b!==t&&x(t))}),className:f.default(o.item,r&&o.active),"data-testid":"anchor-item-".concat(e.hash),children:l.jsx("span",{children:e.text})})]},e.text)}))})]})})}g.defaultProps={title:"ON THIS PAGE",items:[]},g.propTypes={title:p.default.string,items:p.default.arrayOf(p.default.shape({hash:p.default.string,text:p.default.string}))},module.exports=g;
