import { useState } from "react";
import { Button } from "@mui/material";
import { TestTaskButton } from "./TestTaskButton";
import { OpenTestTaskButtonProps } from "types/TestTaskTypes";
import { RocketLaunch } from "@mui/icons-material";

export const OpenTestTaskButton = ({
  task,
  maxHeight,
  disabled = false,
  showForm = true,
  tasksList = [],
}: OpenTestTaskButtonProps) => {
  const [open, setOpen] = useState(false);
  return open ? (
    <TestTaskButton
      onDismiss={() => setOpen(false)}
      task={task}
      showForm={showForm}
      maxHeight={maxHeight}
      tasksList={tasksList}
    />
  ) : (
    <Button
      id="test-test-button"
      variant="contained"
      disabled={disabled}
      size="small"
      startIcon={<RocketLaunch />}
      onClick={() => (disabled ? {} : setOpen(true))}
    >
      Test Task
    </Button>
  );
};
