import React from "react";
import { Sheet, WholeWord, Search } from "lucide-react";
import { useState } from "react";
import ImportGUI from "./ImportGUI";
import { removeSelection } from "../utils/tableActions";

type SubHeaderAdminProps = {
  setFiles: (files: File[]) => void;
  files?: File[];
  search: string;
  setSearch: (value: string) => void;
};

// Sub navigation bar for admin views: provides import + clear selection actions
const SubHeaderAdmin: React.FC<SubHeaderAdminProps> = ({
  setFiles,
  files,
  search,
  setSearch,
}) => {
  const [showImport, setShowImport] = useState(false);

  return (
    <>
      <header className="sticky top-0 z-30 w-full border-b border-gray-200/70 bg-white/90 backdrop-blur supports-[backdrop-filter]:bg-white/60">
        <div className="mx-auto flex max-w-7xl items-center justify-between gap-4 px-4 py-2.5 md:px-6">
          <div className="flex items-center gap-3">
            <h2 className="text-base font-semibold tracking-tight text-gray-800 sm:text-lg">
              Verwaltung
            </h2>
            <span
              className="hidden h-5 w-px bg-gray-300 sm:inline-block"
              aria-hidden="true"
            />
            <p className="hidden text-sm text-gray-500 md:block">
              Aktionen für Daten in der Datenbank
            </p>
          </div>
          <div className="flex items-center gap-2">
            {/* Search */}
            <div className="relative hidden sm:block">
              <Search className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
              <input
                type="text"
                value={search}
                onChange={(e) => setSearch(e.target.value)}
                placeholder="Suchen… (Losnummer, Name, Adresse, PLZ, Email)"
                className="w-72 rounded-md border border-gray-300 bg-white pl-9 pr-3 py-2 text-sm text-gray-900 placeholder-gray-400 shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
              />
            </div>
            <button
              onClick={() => setShowImport(true)}
              type="button"
              className="group inline-flex items-center gap-2 rounded-md border border-gray-300 bg-white px-3.5 py-2 text-sm font-medium text-gray-700 shadow-sm transition hover:bg-gray-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
            >
              <Sheet
                className="h-4 w-4 shrink-0 text-gray-500 transition group-hover:text-gray-600"
                strokeWidth={1.75}
              />
              <span className="whitespace-nowrap">Losnummern importieren</span>
            </button>
            <button
              onClick={() => {
                removeSelection();
              }}
              type="button"
              className="group inline-flex items-center gap-2 rounded-md bg-rose-600 px-3.5 py-2 text-sm font-medium text-white shadow-sm transition hover:bg-rose-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-rose-500/60 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60"
            >
              <WholeWord
                className="h-4 w-4 shrink-0 text-white/90 transition group-hover:text-white"
                strokeWidth={1.75}
              />
              <span className="whitespace-nowrap">Auswahl löschen</span>
            </button>
          </div>
        </div>
      </header>
      {showImport && (
        <ImportGUI
          onClose={() => setShowImport(false)}
          setFiles={setFiles}
          files={files}
        />
      )}
    </>
  );
};

export default SubHeaderAdmin;
