import { ScanMainSection } from "./ScanMainSection";
import { ScanModalsSection } from "./ScanModalsSection";
import { ScanTopControlsSection } from "./ScanTopControlsSection";
import type { ScanViewLayoutProps } from "./types";

export function ScanViewLayout({
  captureSources,
  selectedSourceId,
  setSelectedSourceId,
  latestCapture,
  captureStatus,
  refreshCaptureSources,
  captureSelectedSource,
  bridgeReady,
  controller,
  isScanning,
}: ScanViewLayoutProps) {
  const {
    setDetailsOpen,
    setDiagnosticsOpen,
    setSettingsOpen,
    setReviewQueueOpen,
    setScanSummary,
    reviewSampleTotal,
    autoScanRunning,
    storedTotal,
    learningRulesLoaded,
    parsedArtifact,
    learningRuleCount,
    activeTargetCount,
    canReadReviewQueue,
    sourceLabel,
    gridLabel,
    inventoryLabel,
    openReviewQueue,
  } = controller;

  return (
    <section className="scanner-workbench">
      <ScanTopControlsSection
        captureSources={captureSources}
        selectedSourceId={selectedSourceId}
        setSelectedSourceId={setSelectedSourceId}
        refreshCaptureSources={refreshCaptureSources}
        captureSelectedSource={captureSelectedSource}
        bridgeReady={bridgeReady}
        isScanning={isScanning}
        controller={controller}
      />

      <ScanMainSection
        latestCapture={latestCapture}
        captureStatus={captureStatus}
        parsedArtifact={parsedArtifact}
        sourceLabel={sourceLabel}
        gridLabel={gridLabel}
        inventoryLabel={inventoryLabel}
        activeTargetCount={activeTargetCount}
        storedTotal={storedTotal}
        reviewSampleTotal={reviewSampleTotal}
        learningRulesLoaded={learningRulesLoaded}
        learningRuleCount={learningRuleCount}
        canOpenReviewQueue={!autoScanRunning && canReadReviewQueue}
        openReviewQueue={openReviewQueue}
        autoScanRunning={autoScanRunning}
        setDetailsOpen={setDetailsOpen}
      />

      <ScanModalsSection
        captureStatus={captureStatus}
        latestCapture={latestCapture}
        diagnosticsOpen={Boolean(controller.diagnosticsOpen)}
        settingsOpen={Boolean(controller.settingsOpen)}
        detailsOpen={Boolean(controller.detailsOpen)}
        reviewQueueOpen={Boolean(controller.reviewQueueOpen)}
        controller={controller}
        setDiagnosticsOpen={setDiagnosticsOpen}
        setSettingsOpen={setSettingsOpen}
        setDetailsOpen={setDetailsOpen}
        setReviewQueueOpen={setReviewQueueOpen}
        setScanSummary={setScanSummary}
      />
    </section>
  );
}
