import { useState } from "react";
import { observer } from "mobx-react-lite";
import { useTranslation } from "react-i18next";
import {
  Dropdown,
  DropdownItem,
  DropdownMenu,
  DropdownToggle,
} from "reactstrap";
import { useNoteStore } from "src/Stores";

export default observer(() => {
  const [isSrcOpened, setSrcOpened] = useState(false);
  const { src, setSrc } = useNoteStore();
  const { t } = useTranslation();

  const onInput = (src: number) => () => {
    setSrc(src);
  };

  return (
    <Dropdown
      isOpen={isSrcOpened}
      toggle={() => {
        setSrcOpened(!isSrcOpened);
      }}
    >
      <DropdownToggle caret>{t(`toSrc${src}`)}</DropdownToggle>
      <DropdownMenu>
        <DropdownItem onClick={onInput(0)}>{t("toSrc0")}</DropdownItem>
        <DropdownItem onClick={onInput(1)}>{t("toSrc1")}</DropdownItem>
        <DropdownItem onClick={onInput(2)}>{t("toSrc2")}</DropdownItem>
        <DropdownItem onClick={onInput(3)}>{t("toSrc3")}</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  );
});
