import React from "react";
import QuickActionsBar from "./QuickActionsBar.jsx";
import NowStatusCard from "./NowStatusCard.jsx";
import ChecklistCard from "./ChecklistCard.jsx";
import MainTabs from "./MainTabs.jsx";
import TaskSettingsTab from "./TaskSettingsTab.jsx";
import MainTabContent from "./MainTabContent.jsx";
import TestRunCard from "./TestRunCard.jsx";
import useTabProps from "../hooks/useTabProps.js";

const AccountsTab = React.lazy(() => import("../tabs/AccountsTab.jsx"));
const LogsTab = React.lazy(() => import("../tabs/LogsTab.jsx"));
const QueueTab = React.lazy(() => import("../tabs/QueueTab.jsx"));
const EventsTab = React.lazy(() => import("../tabs/EventsTab.jsx"));
const ApiTraceTab = React.lazy(() => import("../tabs/ApiTraceTab.jsx"));
const SettingsTab = React.lazy(() => import("../tabs/SettingsTab.jsx"));

export default function AppMain({
  quickActions,
  nowStatus,
  testRun,
  runTestLive,
  checklist,
  tabs,
  taskSettings,
  accountsTab,
  logsTab,
  queueTab,
  apiTraceTab,
  eventsTab,
  settingsTab
}) {
  const {
    taskSettingsProps,
    accountsTabProps,
    logsTabProps,
    queueTabProps,
    apiTraceTabProps,
    eventsTabProps,
    settingsTabProps
  } = useTabProps(taskSettings, accountsTab, logsTab, queueTab, apiTraceTab, eventsTab, settingsTab);

  return (
    <div className="main">
      <QuickActionsBar
        {...quickActions}
      />
      <NowStatusCard
        {...nowStatus}
      />
      <TestRunCard
        testRun={testRun}
        onRunSafe={quickActions.runTestSafe}
        onRunLive={runTestLive}
      />
      <ChecklistCard
        {...checklist}
      />
      <MainTabs
        {...tabs}
      />
      <MainTabContent
        activeTab={tabs.activeTab}
        TaskSettingsTab={TaskSettingsTab}
        AccountsTab={AccountsTab}
        LogsTab={LogsTab}
        QueueTab={QueueTab}
        EventsTab={EventsTab}
        ApiTraceTab={ApiTraceTab}
        SettingsTab={SettingsTab}
        taskSettingsProps={taskSettingsProps}
        accountsTabProps={accountsTabProps}
        logsTabProps={logsTabProps}
        queueTabProps={queueTabProps}
        apiTraceTabProps={apiTraceTabProps}
        eventsTabProps={eventsTabProps}
        settingsTabProps={settingsTabProps}
      />
    </div>
  );
}
