import React from "react";
import {
  Activity,
  Plus,
  RefreshCw,
  Mail,
  Upload,
  Clock,
  Bell,
} from "lucide-react";
import { AppSettings } from "../types";

interface HeaderProps {
  settings: AppSettings;
  onOpenAddModal: () => void;
  onOpenBulkModal: () => void;
  onOpenEmailModal: () => void;
  onCheckAll: () => void;
  isCheckingAll: boolean;
  totalSites: number;
  hasErrors: boolean;
}

export const Header: React.FC<HeaderProps> = ({
  settings,
  onOpenAddModal,
  onOpenBulkModal,
  onOpenEmailModal,
  onCheckAll,
  isCheckingAll,
  totalSites,
  hasErrors,
}) => {
  return (
    <header className="bg-slate-900 border-b border-slate-800 text-white sticky top-0 z-30 shadow-md">
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3.5">
        <div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
          {/* Logo & Branding */}
          <div className="flex items-center space-x-3">
            <div className="w-10 h-10 rounded-xl bg-gradient-to-tr from-blue-600 via-indigo-600 to-cyan-400 flex items-center justify-center shadow-lg shadow-blue-500/20">
              <Activity className="w-6 h-6 text-white animate-pulse" />
            </div>
            <div>
              <div className="flex items-center space-x-2">
                <h1 className="text-xl font-bold tracking-tight bg-gradient-to-r from-white via-slate-100 to-slate-300 bg-clip-text text-transparent">
                  Alfatih Client Centre
                </h1>
                <span className="px-2 py-0.5 text-xs font-semibold rounded bg-blue-500/20 text-blue-400 border border-blue-500/30">
                  Alfatih Studio
                </span>
                {hasErrors && (
                  <span className="flex items-center px-2 py-0.5 text-xs font-medium rounded-full bg-red-500/20 text-red-400 border border-red-500/30 animate-pulse">
                    <span className="w-1.5 h-1.5 rounded-full bg-red-400 mr-1.5 animate-ping" />
                    Ralat Dikesan!
                  </span>
                )}
              </div>
              <p className="text-xs text-slate-400">
                Pemantau Kesihatan, Uptime & Ralat Laman Web WordPress Klien
              </p>
            </div>
          </div>

          {/* Quick Info & Action Buttons */}
          <div className="flex flex-wrap items-center gap-2.5">
            {/* Auto-check indicator */}
            <button
              onClick={onOpenEmailModal}
              title="Tetapan Notifikasi & Auto-Check"
              className="flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-slate-800/80 hover:bg-slate-700/80 border border-slate-700 text-xs text-slate-300 transition-colors"
            >
              <Bell className="w-3.5 h-3.5 text-blue-400" />
              <span className="hidden sm:inline">Emel:</span>
              <span className="font-mono text-cyan-300 truncate max-w-[140px]">
                {settings.adminEmail}
              </span>
            </button>

            {settings.autoCheckIntervalMinutes > 0 && (
              <div className="flex items-center space-x-1 px-2.5 py-1.5 rounded-lg bg-slate-800/60 border border-slate-700/80 text-xs text-slate-400">
                <Clock className="w-3.5 h-3.5 text-amber-400" />
                <span>Server: {settings.autoCheckIntervalMinutes}m</span>
              </div>
            )}

            {/* Check All Sites Button */}
            <button
              onClick={onCheckAll}
              disabled={isCheckingAll || totalSites === 0}
              className={`flex items-center space-x-2 px-3.5 py-1.5 rounded-lg font-medium text-xs transition-all shadow-sm ${
                isCheckingAll
                  ? "bg-blue-600/40 text-blue-200 cursor-not-allowed"
                  : "bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white active:scale-95"
              }`}
            >
              <RefreshCw
                className={`w-3.5 h-3.5 ${isCheckingAll ? "animate-spin" : ""}`}
              />
              <span>
                {isCheckingAll ? "Menyemak Semua..." : "Semak Semua Web"}
              </span>
            </button>

            {/* Bulk Import */}
            <button
              onClick={onOpenBulkModal}
              className="flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-slate-800 hover:bg-slate-700 border border-slate-700 text-xs font-medium text-slate-200 transition-colors"
              title="Import banyak web sekali gus"
            >
              <Upload className="w-3.5 h-3.5 text-slate-400" />
              <span className="hidden sm:inline">Pukal</span>
            </button>

            {/* Add Website Button */}
            <button
              onClick={onOpenAddModal}
              className="flex items-center space-x-1.5 px-3.5 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white font-medium text-xs transition-all shadow-sm active:scale-95"
            >
              <Plus className="w-4 h-4" />
              <span>Tambah Web</span>
            </button>
          </div>
        </div>
      </div>
    </header>
  );
};
