export default function useAppTabGroups({
  selectedTaskName,
  taskForm,
  setTaskForm,
  activePreset,
  applyTaskPreset,
  formatAccountLabel,
  accountById,
  competitorText,
  setCompetitorText,
  applyRoleMode,
  normalizeIntervals,
  taskStatus,
  perAccountInviteSum,
  hasSelectedTask,
  inviteAccessStatus,
  inviteAccessCheckedAt,
  formatTimestamp,
  checkInviteAccess,
  accounts,
  showNotification,
  copyToClipboard,
  sanitizeTaskForm,
  hasPerAccountInviteLimits,
  fileImportResult,
  importInviteFile,
  fileImportForm,
  setFileImportForm,
  criticalErrorAccounts,
  accountStatsMap,
  settings,
  membershipStatus,
  assignedAccountMap,
  accountBuckets,
  filterFreeAccounts,
  selectedAccountIds,
  taskAccountRoles,
  inviteAdminMasterId,
  refreshMembership,
  refreshIdentity,
  formatAccountStatus,
  resetCooldown,
  deleteAccount,
  updateAccountRole,
  updateAccountInviteLimit,
  setAccountRolesAll,
  applyRolePreset,
  removeAccountFromTask,
  moveAccountToTask,
  logsTab,
  setLogsTab,
  exportLogs,
  clearLogs,
  exportInvites,
  exportProblemInvites,
  exportFallback,
  updateFallbackStatus,
  clearFallback,
  clearInvites,
  logSearch,
  setLogSearch,
  logPage,
  setLogPage,
  logPageCount,
  pagedLogs,
  inviteSearch,
  setInviteSearch,
  invitePage,
  setInvitePage,
  invitePageCount,
  inviteFilter,
  setInviteFilter,
  pagedInvites,
  fallbackSearch,
  setFallbackSearch,
  fallbackPage,
  setFallbackPage,
  fallbackPageCount,
  pagedFallback,
  confirmQueue,
  confirmSearch,
  setConfirmSearch,
  confirmPage,
  setConfirmPage,
  confirmPageCount,
  pagedConfirmQueue,
  queueItems,
  queueStats,
  queueSearch,
  setQueueSearch,
  queuePage,
  setQueuePage,
  queuePageCount,
  pagedQueue,
  clearConfirmQueue,
  auditSearch,
  setAuditSearch,
  auditPage,
  setAuditPage,
  auditPageCount,
  pagedAudit,
  explainInviteError,
  expandedInviteId,
  setExpandedInviteId,
  inviteStats,
  invites,
  selectedTask,
  accessStatus,
  roleSummary,
  mutualContactDiagnostics,
  accountById,
  formatAccountLabel,
  accountEvents,
  clearAccountEvents,
  onSettingsChange,
  saveSettings
}) {
  const taskSettings = {
    selectedTaskName,
    taskForm,
    setTaskForm,
    activePreset,
    applyTaskPreset,
    formatAccountLabel,
    accountById,
    competitorText,
    setCompetitorText,
    roleMode: taskForm.requireSameBotInBoth ? "same" : "split",
    applyRoleMode,
    normalizeIntervals,
    taskStatus,
    perAccountInviteSum,
    hasSelectedTask,
    inviteAccessStatus,
    inviteAccessCheckedAt,
    formatTimestamp,
    checkInviteAccess,
    accounts,
    showNotification,
    copyToClipboard,
    sanitizeTaskForm,
    hasPerAccountInviteLimits,
    fileImportResult,
    importInviteFile,
    fileImportForm,
    setFileImportForm,
    criticalErrorAccounts
  };

  const accountsTab = {
    accounts,
    accountStatsMap,
    settings,
    membershipStatus,
    assignedAccountMap,
    accountBuckets,
    filterFreeAccounts,
    selectedAccountIds,
    taskAccountRoles,
    rolesMode: taskForm.rolesMode,
    setRolesMode: (mode) => {
      setTaskForm((prev) => ({ ...prev, rolesMode: mode }));
      if (mode === "auto") {
        applyRolePreset("split");
      }
    },
    hasSelectedTask,
    inviteAdminMasterId,
    refreshMembership,
    refreshIdentity,
    formatAccountStatus,
    formatAccountLabel,
    resetCooldown,
    deleteAccount,
    updateAccountRole,
    updateAccountInviteLimit,
    setAccountRolesAll,
    applyRolePreset,
    removeAccountFromTask,
    moveAccountToTask
  };

  const logsTabGroup = {
    logsTab,
    setLogsTab,
    hasSelectedTask,
    exportLogs,
    clearLogs,
    exportInvites,
    exportProblemInvites,
    exportFallback,
    updateFallbackStatus,
    clearFallback,
    clearInvites,
    logSearch,
    setLogSearch,
    logPage,
    setLogPage,
    logPageCount,
    pagedLogs,
    inviteSearch,
    setInviteSearch,
    invitePage,
    setInvitePage,
    invitePageCount,
    inviteFilter,
    setInviteFilter,
    pagedInvites,
    fallbackSearch,
    setFallbackSearch,
    fallbackPage,
    setFallbackPage,
    fallbackPageCount,
    pagedFallback,
    confirmQueue,
    confirmSearch,
    setConfirmSearch,
    confirmPage,
    setConfirmPage,
    confirmPageCount,
    pagedConfirmQueue,
    queueItems,
    queueStats,
    queueSearch,
    setQueueSearch,
    queuePage,
    setQueuePage,
    queuePageCount,
    pagedQueue,
    clearConfirmQueue,
    auditSearch,
    setAuditSearch,
    auditPage,
    setAuditPage,
    auditPageCount,
    pagedAudit,
    explainInviteError,
    expandedInviteId,
    setExpandedInviteId,
    inviteStats,
    invites,
    selectedTask,
    accessStatus,
    inviteAccessStatus,
    selectedTaskName,
    roleSummary,
    mutualContactDiagnostics,
    accountById,
    formatAccountLabel
  };
  const queueTabGroup = {
    queueStats,
    queueSearch,
    setQueueSearch,
    queuePage,
    setQueuePage,
    queuePageCount,
    pagedQueue
  };

  const eventsTab = {
    accountEvents,
    formatTimestamp,
    onClearEvents: clearAccountEvents,
    accountById,
    formatAccountLabel
  };

  const settingsTab = {
    settings,
    onSettingsChange,
    saveSettings
  };

  return {
    taskSettings,
    accountsTab,
    logsTab: logsTabGroup,
    queueTab: queueTabGroup,
    eventsTab,
    settingsTab
  };
}
