import React from 'react';
// import useSWR from 'swr';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
  Button,
  // Spinner
} from 'react-bootstrap';
import { FormattedMessage } from './localization';

export default function DarkToggler({
  isDarkEnabled = false,
  onChangeDarkMode = null,
  disabled = false,
  showLoading = false,
}: {
  isDarkEnabled?: boolean,
  onChangeDarkMode?: (value: boolean) => void,
  disabled?: boolean,
  showLoading?: boolean,
} = {}) {
  return (
    <Button
      onClick={() => {
        onChangeDarkMode(!isDarkEnabled);
      }}
      disabled={disabled || showLoading}
      variant="outline-secondary"
      active={!isDarkEnabled}
    >
      <FontAwesomeIcon icon={[isDarkEnabled ? 'far' : 'fas', 'lightbulb']} />
      <span className="sr-only">
        <FormattedMessage
          id="DarkToggler.screenReaderText"
          defaultMessage="Toggle dark mode"
          description="Screen reader description of the dark mode toggle button"
        />
      </span>
    </Button>
  );
}
