import React from 'react';
import CustomDialog from '@/components/CustomDialog';
import { Task, TaskCreateRequest } from "@/services/tasksApi";
import { TaskForm } from "./TaskForm";

interface TaskDialogProps {
  task?: Task;
  open: boolean;
  onOpenChange: (open: boolean) => void;
  onSubmit: (data: TaskCreateRequest) => Promise<void>;
  isLoading?: boolean;
}

export function TaskDialog({
  task,
  open,
  onOpenChange,
  onSubmit,
  isLoading,
}: TaskDialogProps) {
  // Handle dialog closing
  const handleClose = () => {
    console.log('Closing task dialog');
    onOpenChange(false);
  };

  return (
    <CustomDialog
      isOpen={open}
      onClose={handleClose}
      title={task ? "Edit Task" : "Create New Task"}
      allowClose={!isLoading}
      isPending={isLoading}
    >
      <TaskForm
        task={task}
        onSubmit={onSubmit}
        onCancel={handleClose}
        isLoading={isLoading}
      />
    </CustomDialog>
  );
} 