import { CloseIcon, CogIcon, SearchIcon } from '@components/Icons';
import { ForwardedRef, forwardRef, SetStateAction } from 'react';
import { useIntl } from 'react-intl';
import styles from '../Buttons.module.scss';

type ButtonType = 'search' | 'settings';

const ButtonToolbar = (
  {
    type,
    isActivated,
    setIsActivated,
  }: {
    type: ButtonType;
    isActivated: boolean;
    setIsActivated: (value: SetStateAction<boolean>) => void;
  },
  ref: ForwardedRef<HTMLButtonElement>
) => {
  const intl = useIntl();
  const ButtonIcon = () => (type === 'search' ? <SearchIcon /> : <CogIcon />);
  const btnClasses = isActivated
    ? `${styles.toolbar} ${styles['toolbar--activated']}`
    : styles.toolbar;

  return (
    <button
      ref={ref}
      className={btnClasses}
      type="button"
      onClick={() => setIsActivated(!isActivated)}
    >
      <span className={styles.icon}>
        <span className={styles.front}>
          <ButtonIcon />
        </span>
        <span className={styles.back}>
          <CloseIcon />
        </span>
      </span>
      {isActivated ? (
        <span className="screen-reader-text">
          {intl.formatMessage(
            {
              defaultMessage: 'Close {type}',
              description: 'ButtonToolbar: Close button',
            },
            {
              type,
            }
          )}
        </span>
      ) : (
        <span className="screen-reader-text">
          {intl.formatMessage(
            {
              defaultMessage: 'Open {type}',
              description: 'ButtonToolbar: Open button',
            },
            {
              type,
            }
          )}
        </span>
      )}
    </button>
  );
};

export default forwardRef(ButtonToolbar);
id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>commit</a><a href='/www.armandphilippot.com/diff/public/prism/prism-basic.min.js?id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>diff</a><a href='/www.armandphilippot.com/stats/public/prism/prism-basic.min.js'>stats</a></td><td class='form'><form class='right' method='get' action='/www.armandphilippot.com/log/public/prism/prism-basic.min.js'>
<input type='hidden' name='id' value='85c4c42bd601270d7be0f34a0767a34bb85e29bb'/><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=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>root</a>/<a href='/www.armandphilippot.com/tree/public?id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>public</a>/<a href='/www.armandphilippot.com/tree/public/prism?id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>prism</a>/<a href='/www.armandphilippot.com/tree/public/prism/prism-basic.min.js?id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>prism-basic.min.js</a></div><div class='content'>blob: 86c9354aeb579ad8f8f7dfd179f0e983fb6df7ad (<a href='/www.armandphilippot.com/plain/public/prism/prism-basic.min.js?id=85c4c42bd601270d7be0f34a0767a34bb85e29bb'>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>
</pre></td>
<td class='lines'><pre><code>