import Moon from '@components/atoms/icons/moon';
import Sun from '@components/atoms/icons/sun';
import Toggle, {
  type ToggleChoices,
  type ToggleProps,
} from '@components/molecules/forms/toggle';
import { useTheme } from 'next-themes';
import { FC } from 'react';
import { useIntl } from 'react-intl';

export type ThemeToggleProps = Pick<
  ToggleProps,
  'className' | 'labelClassName'
>;

/**
 * ThemeToggle component
 *
 * Render a Toggle component to set theme.
 */
const ThemeToggle: FC<ThemeToggleProps> = ({ ...props }) => {
  const intl = useIntl();
  const { resolvedTheme, setTheme } = useTheme();
  const isDarkTheme = resolvedTheme === 'dark';

  /**
   * Update the theme.
   */
  const updateTheme = () => {
    setTheme(isDarkTheme ? 'light' : 'dark');
  };

  const themeLabel = intl.formatMessage({
    defaultMessage: 'Theme:',
    description: 'ThemeToggle: theme label',
    id: 'suXOBu',
  });
  const lightThemeLabel = intl.formatMessage({
    defaultMessage: 'Light theme',
    description: 'ThemeToggle: light theme label',
    id: 'Ygea7s',
  });
  const darkThemeLabel = intl.formatMessage({
    defaultMessage: 'Dark theme',
    description: 'ThemeToggle: dark theme label',
    id: '2QwvtS',
  });
  const themeChoices: ToggleChoices = {
    left: <Sun title={lightThemeLabel} />,
    right: <Moon title={darkThemeLabel} />,
  };

  return (
    <Toggle
      id="theme-settings"
      name="theme-settings"
      label={themeLabel}
      labelSize="medium"
      choices={themeChoices}
      value={isDarkTheme}
      setValue={updateTheme}
      {...props}
    />
  );
};

export default ThemeToggle;
graphql/comments.mutation.ts?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>tree</a><a href='/www.armandphilippot.com/commit/src/services/graphql/comments.mutation.ts?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>commit</a><a href='/www.armandphilippot.com/diff/src/services/graphql/comments.mutation.ts?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>diff</a><a href='/www.armandphilippot.com/stats/src/services/graphql/comments.mutation.ts?h=v2.0.0'>stats</a></td><td class='form'><form class='right' method='get' action='/www.armandphilippot.com/log/src/services/graphql/comments.mutation.ts'>
<input type='hidden' name='h' value='v2.0.0'/><input type='hidden' name='id' value='baac7d6eeaf522ff5faa28906cb1200e60a19c07'/><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/?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>root</a>/<a href='/www.armandphilippot.com/tree/src?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>src</a>/<a href='/www.armandphilippot.com/tree/src/services?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>services</a>/<a href='/www.armandphilippot.com/tree/src/services/graphql?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>graphql</a>/<a href='/www.armandphilippot.com/tree/src/services/graphql/comments.mutation.ts?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>comments.mutation.ts</a></div><div class='content'>blob: f52c7e9fc0b015ff69963fb3e34e8d9b3d7ad490 (<a href='/www.armandphilippot.com/plain/src/services/graphql/comments.mutation.ts?h=v2.0.0&amp;id=baac7d6eeaf522ff5faa28906cb1200e60a19c07'>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>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
<a id='n29' href='#n29'>29</a>
<a id='n30' href='#n30'>30</a>
</pre></td>
<td class='lines'><pre><code>