import { ExpandableWidget, OrderedList } from '@components/WidgetParts';
import { Heading } from '@ts/types/app';
import useHeadingsTree from '@utils/hooks/useHeadingsTree';
import { useIntl } from 'react-intl';

const ToC = () => {
  const intl = useIntl();
  const headingsTree = useHeadingsTree('article');
  const title = intl.formatMessage({
    defaultMessage: 'Table of contents',
    description: 'ToC: widget title',
  });

  const getItems = (headings: Heading[]) => {
    return headings.map((heading) => {
      return (
        <li key={heading.id}>
          <a href={`#${heading.id}`}>{heading.title}</a>
          {heading.children.length > 0 && (
            <OrderedList items={getItems(heading.children)} />
          )}
        </li>
      );
    });
  };

  return (
    <ExpandableWidget title={title} expand={true} withBorders={true}>
      <OrderedList items={getItems(headingsTree)} />
    </ExpandableWidget>
  );
};

export default ToC;
681997ef613d982bac14'/><select name='h' onchange='this.form.submit();'>
<option value='main' selected='selected'>main</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>The frontend of my personal website.</td><td class='sub right'>Armand Philippot</td></tr></table>
<table class='tabs'><tr><td>
<a href='/www.armandphilippot.com/about/'>about</a><a href='/www.armandphilippot.com/'>summary</a><a href='/www.armandphilippot.com/refs/?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>refs</a><a href='/www.armandphilippot.com/log/public/prism/prism-tsx.min.js'>log</a><a class='active' href='/www.armandphilippot.com/tree/public/prism/prism-tsx.min.js?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>tree</a><a href='/www.armandphilippot.com/commit/public/prism/prism-tsx.min.js?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>commit</a><a href='/www.armandphilippot.com/diff/public/prism/prism-tsx.min.js?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>diff</a><a href='/www.armandphilippot.com/stats/public/prism/prism-tsx.min.js'>stats</a></td><td class='form'><form class='right' method='get' action='/www.armandphilippot.com/log/public/prism/prism-tsx.min.js'>
<input type='hidden' name='id' value='c6f6f8f895e68f2d85ca681997ef613d982bac14'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/www.armandphilippot.com/tree/?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>root</a>/<a href='/www.armandphilippot.com/tree/public?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>public</a>/<a href='/www.armandphilippot.com/tree/public/prism?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>prism</a>/<a href='/www.armandphilippot.com/tree/public/prism/prism-tsx.min.js?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>prism-tsx.min.js</a></div><div class='content'>blob: 57bf2d4b125b7fe06a42d59213f6fcac0297fe72 (<a href='/www.armandphilippot.com/plain/public/prism/prism-tsx.min.js?id=c6f6f8f895e68f2d85ca681997ef613d982bac14'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
</pre></td>
<td class='lines'><pre><code>