import { useCallback } from "react";

export interface AppTopbarModel {
  handleShowOverlay: () => void;
  handleExportGood: () => void;
  handleDemoScan: () => void;
  isExportDisabled: boolean;
  isDemoDisabled: boolean;
  isOverlayDisabled: boolean;
  exportButtonLabel: string;
  exportButtonTitle: string;
  overlayButtonLabel: string;
  overlayButtonTitle: string;
  demoButtonLabel: string;
  demoButtonTitle: string;
}

interface UseAppTopbarModelInput {
  onExportGood: () => Promise<void> | void;
  onShowOverlay: () => Promise<void>;
  onDemoScan: () => void;
  canExportGood: boolean;
  canShowOverlay: boolean;
  isScanning: boolean;
  artifactCount: number;
}

export function useAppTopbarModel({
  onExportGood,
  onShowOverlay,
  onDemoScan,
  canExportGood,
  canShowOverlay,
  isScanning,
  artifactCount,
}: UseAppTopbarModelInput): AppTopbarModel {
  const handleShowOverlay = useCallback(() => {
    void onShowOverlay();
  }, [onShowOverlay]);

  const handleExportGood = useCallback(() => {
    void onExportGood();
  }, [onExportGood]);

  const handleDemoScan = useCallback(() => {
    onDemoScan();
  }, [onDemoScan]);

  const isExportDisabled = !canExportGood || artifactCount === 0;
  const isDemoDisabled = isScanning;
  const isOverlayDisabled = !canShowOverlay;

  return {
    handleShowOverlay,
    handleExportGood,
    handleDemoScan,
    isExportDisabled,
    isDemoDisabled,
    isOverlayDisabled,
    exportButtonLabel: "GOOD Export",
    exportButtonTitle: canExportGood ? "GOOD-Export starten." : "GOOD-Export ist nur in der Electron-App verfuegbar.",
    overlayButtonLabel: "Overlay",
    overlayButtonTitle: canShowOverlay ? "Overlay oeffnen." : "Overlay benoetigt die Electron-Bridge.",
    demoButtonLabel: isScanning ? "Laedt..." : "Demo-Daten",
    demoButtonTitle: "Laedt Beispieldaten fuer die Triage- und Build-Ansicht.",
  };
}
