import { type FC, useState} from "react";
import Modal from "@/components/ui/Modal";
import ScheduleRegenerateForm from "@/components/features/schedule/ScheduleRegenerateForm";
import {ArrowPathIcon} from "@heroicons/react/16/solid";

interface ScheduleRegenerateButtonProps {
    onModalClose?: () => void;
}

const ScheduleRegenerateButton: FC<ScheduleRegenerateButtonProps> = ({ onModalClose }) => {
    const [open, setOpen] = useState(false);

    const handleCloseModal = () => {
        setOpen(false)
        if (onModalClose) {
            onModalClose()
        }
    }

    const modalChildren = <ScheduleRegenerateForm closeModal={() => handleCloseModal()}/>
    const buttonChild = <div className="p-0 flex">
            <ArrowPathIcon fontSize={24} className="h-5 w-5 mt-1 mr-2" color="gray-500" aria-hidden="true" onClick={() => setOpen(true)} />
            <p>Regenerate</p>
        </div>

    return <Modal
        buttonClassName="ml-auto mr-2 py-1"
        buttonChildren={buttonChild}
        modalChildren={modalChildren}
        modalOpen={open}
        setModalOpen={setOpen}
    />
};

export default ScheduleRegenerateButton;