import {
  Modal,
  ModalDialog,
  Typography,
  ModalClose,
  Autocomplete,
} from "@mui/joy";
import { useTranslation } from "react-i18next";

interface SelectUserModalProps {
  showSelectUser: boolean;
  setShowSelectUser: (value: boolean) => void;
  info: { users: string[]; prize_draws: string[] };
  infoIsLoading: boolean;
  selectedUser: string | null;
  selectedDraw: string | null;
  handleUserSelection: (value: string | null) => void;
  handleDrawSelection: (value: string | null) => void;
}

export const SelectUserModal = (props: SelectUserModalProps) => {
  const { t } = useTranslation();
  return (
    <Modal open={props.showSelectUser}>
      <ModalDialog color="primary" layout="center" size="lg">
        <ModalClose onClick={() => props.setShowSelectUser(false)} />
        <Typography>{t("user")}</Typography>
        {/* User selection */}
        <Autocomplete
          options={props.info?.users ?? []}
          loading={props.infoIsLoading}
          loadingText={t("loading")}
          value={props.selectedUser}
          onChange={(_, value) => props.handleUserSelection(value)}
          placeholder={t("user")}
          variant="soft"
          sx={{ borderRadius: "10px" }}
        />
        {/* Prize selection */}
        <Autocomplete
          options={props.info?.prize_draws ?? []}
          loading={props.infoIsLoading}
          loadingText={t("loading")}
          value={props.selectedDraw}
          onChange={(_, value) => props.handleDrawSelection(value)}
          placeholder={t("prize_draws")}
          variant="soft"
          sx={{ borderRadius: "10px" }}
        />
      </ModalDialog>
    </Modal>
  );
};
