import { normalizeIntervals, sanitizeTaskForm } from "../appDefaults.js";

export default function useTaskFormActions({ taskForm, setTaskForm }) {
  const updateIntervals = (nextMin, nextMax) => {
    const updated = normalizeIntervals({
      ...taskForm,
      minIntervalMinutes: nextMin,
      maxIntervalMinutes: nextMax
    });
    setTaskForm(updated);
  };

  const applyRoleMode = (mode) => {
    if (mode === "same") {
      setTaskForm(sanitizeTaskForm({ ...taskForm, requireSameBotInBoth: true, separateBotRoles: false }));
      return;
    }
    if (mode === "split") {
      setTaskForm({ ...taskForm, requireSameBotInBoth: false, separateBotRoles: true });
    }
  };

  return { updateIntervals, applyRoleMode };
}
