import { emptyTaskForm } from "../appDefaults.js";

export default function useTaskSelection({
  taskAutosaveReady,
  selectedTaskId,
  setSelectedTaskId,
  setTaskForm,
  setCompetitorText,
  setSelectedAccountIds,
  setTaskAccountRoles,
  setAccessStatus,
  setMembershipStatus
}) {
  const createTask = () => {
    taskAutosaveReady.current = false;
    setSelectedTaskId(null);
    setTaskForm(emptyTaskForm);
    setCompetitorText("");
    setSelectedAccountIds([]);
    setTaskAccountRoles({});
    setAccessStatus([]);
    setMembershipStatus({});
    taskAutosaveReady.current = true;
  };

  const selectTask = (taskId) => {
    if (taskId === selectedTaskId) return;
    setSelectedTaskId(taskId);
  };

  return { createTask, selectTask };
}
