import { useRef, useState } from "react";

export default function useAppUiState() {
  const [notificationsOpen, setNotificationsOpen] = useState(false);
  const notificationsModalRef = useRef(null);
  const [importModalOpen, setImportModalOpen] = useState(false);
  const [nowExpanded, setNowExpanded] = useState(false);
  const [moreActionsOpen, setMoreActionsOpen] = useState(false);
  const moreActionsRef = useRef(null);
  const [checklistOpen, setChecklistOpen] = useState(true);
  const [manualLoginOpen, setManualLoginOpen] = useState(false);
  const [taskSearch, setTaskSearch] = useState("");
  const [taskFilter, setTaskFilter] = useState("all");
  const [infoOpen, setInfoOpen] = useState(false);
  const [infoTab, setInfoTab] = useState("usage");
  const [activeTab, setActiveTab] = useState("events");
  const [logsTab, setLogsTab] = useState("logs");
  const [taskSort, setTaskSort] = useState("activity");
  const [expandedInviteId, setExpandedInviteId] = useState(null);
  const [liveConfirmOpen, setLiveConfirmOpen] = useState(false);
  const [liveConfirmContext, setLiveConfirmContext] = useState(null);
  const [now, setNow] = useState(Date.now());
  const [isVisible, setIsVisible] = useState(!document.hidden);
  const bellRef = useRef(null);
  const settingsAutosaveReady = useRef(false);
  const taskAutosaveReady = useRef(false);
  const taskAutosaveTimer = useRef(null);
  const autosaveNoteTimer = useRef(null);
  const tasksPollInFlight = useRef(false);
  const accountsPollInFlight = useRef(false);
  const logsPollInFlight = useRef(false);
  const eventsPollInFlight = useRef(false);

  return {
    notificationsOpen,
    setNotificationsOpen,
    notificationsModalRef,
    importModalOpen,
    setImportModalOpen,
    nowExpanded,
    setNowExpanded,
    moreActionsOpen,
    setMoreActionsOpen,
    moreActionsRef,
    checklistOpen,
    setChecklistOpen,
    manualLoginOpen,
    setManualLoginOpen,
    taskSearch,
    setTaskSearch,
    taskFilter,
    setTaskFilter,
    infoOpen,
    setInfoOpen,
    infoTab,
    setInfoTab,
    activeTab,
    setActiveTab,
    logsTab,
    setLogsTab,
    taskSort,
    setTaskSort,
    expandedInviteId,
    setExpandedInviteId,
    liveConfirmOpen,
    setLiveConfirmOpen,
    liveConfirmContext,
    setLiveConfirmContext,
    now,
    setNow,
    isVisible,
    setIsVisible,
    bellRef,
    settingsAutosaveReady,
    taskAutosaveReady,
    taskAutosaveTimer,
    autosaveNoteTimer,
    tasksPollInFlight,
    accountsPollInFlight,
    logsPollInFlight,
    eventsPollInFlight
  };
}
