import useTaskLifecycle from "./useTaskLifecycle.js";
import useTaskStatusSync from "./useTaskStatusSync.js";
import useNotices from "./useNotices.js";
import useAutosave from "./useAutosave.js";
import useAppPolling from "./useAppPolling.js";

export default function useAppOrchestration({
  activeTab,
  selectedTaskId,
  isVisible,
  setIsVisible,
  setNow,
  tasksPollInFlight,
  accountsPollInFlight,
  logsPollInFlight,
  eventsPollInFlight,
  setTasks,
  loadTaskStatuses,
  setTaskStatus,
  setAccounts,
  setAccountAssignments,
  setAccountStats,
  setGlobalStatus,
  setLogs,
  setInvites,
  setFallbackList,
  setConfirmQueue,
  setTaskAudit,
  setAccountEvents,
  setQueueItems,
  setQueueStats,
  loadBase,
  loadSelectedTask,
  setAccessStatus,
  setInviteAccessStatus,
  setMembershipStatus,
  setTaskNotice,
  setActivePreset,
  checkAccess,
  checkInviteAccess,
  activePreset,
  taskForm,
  taskAccountRoles,
  presetSignatureRef,
  taskStatus,
  setTaskStatusMap,
  checklistStats,
  setChecklistOpen,
  hasSelectedTask,
  roleIntersectionCount,
  roleSummary,
  setTaskForm,
  sanitizeTaskForm,
  taskNotice,
  settingsNotice,
  tdataNotice,
  setSettingsNotice,
  setTdataNotice,
  showNotification,
  settings,
  settingsAutosaveReady,
  taskAutosaveReady,
  taskAutosaveTimer,
  competitorText,
  selectedAccountIds,
  canSaveTask,
  saveTask,
  setSettings
}) {
  useAppPolling({
    activeTab,
    selectedTaskId,
    isVisible,
    setIsVisible,
    setNow,
    tasksPollInFlight,
    accountsPollInFlight,
    logsPollInFlight,
    eventsPollInFlight,
    setTasks,
    loadTaskStatuses,
    setTaskStatus,
    setAccounts,
    setAccountAssignments,
    setAccountStats,
    setGlobalStatus,
    setLogs,
    setInvites,
    setFallbackList,
    setConfirmQueue,
    setTaskAudit,
    setAccountEvents,
    setQueueItems,
    setQueueStats
  });

  useTaskLifecycle({
    loadBase,
    selectedTaskId,
    loadSelectedTask,
    setAccessStatus,
    setInviteAccessStatus,
    setMembershipStatus,
    setTaskNotice,
    setActivePreset,
    checkAccess,
    checkInviteAccess,
    activePreset,
    taskForm,
    taskAccountRoles,
    presetSignatureRef
  });

  useTaskStatusSync({
    selectedTaskId,
    taskStatus,
    setTaskStatusMap,
    checklistStats,
    setChecklistOpen,
    hasSelectedTask,
    taskForm,
    roleIntersectionCount,
    roleSummary,
    setTaskForm,
    sanitizeTaskForm
  });

  useNotices({
    taskNotice,
    setTaskNotice,
    settingsNotice,
    setSettingsNotice,
    tdataNotice,
    setTdataNotice,
    showNotification
  });

  useAutosave({
    settings,
    settingsAutosaveReady,
    taskAutosaveReady,
    taskAutosaveTimer,
    taskForm,
    competitorText,
    taskAccountRoles,
    selectedAccountIds,
    canSaveTask,
    saveTask,
    setSettings,
    showNotification
  });
}
