%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/
Upload File :
Create Path :
Current File : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/Header.tsx

import React, { useState } from 'react';
import { 
  Sparkles, Shield, Briefcase, Search, Plus, ChevronDown, 
  Bell, MessageSquare, Sun, Moon, Home, LogOut, UserCheck
} from 'lucide-react';
import { Role } from '../types';

interface HeaderProps {
  role: Role;
  setRole: (role: Role) => void;
  isSidebarOpen: boolean;
  setIsSidebarOpen: (open: boolean) => void;
  searchQuery: string;
  setSearchQuery: (query: string) => void;
  isDarkMode: boolean;
  setIsDarkMode: (dark: boolean) => void;
  onOpenAddModal: () => void;
  triggerToast: (msg: string) => void;
  setActiveTab: (tab: string) => void;
  onLogout?: () => void;
}

export const Header: React.FC<HeaderProps> = ({
  role,
  setRole,
  isSidebarOpen,
  setIsSidebarOpen,
  searchQuery,
  setSearchQuery,
  isDarkMode,
  setIsDarkMode,
  onOpenAddModal,
  triggerToast,
  setActiveTab,
  onLogout
}) => {
  const [showUserDropdown, setShowUserDropdown] = useState(false);

  return (
    <header className="h-14 bg-white border-b border-slate-200/80 flex items-center justify-between px-3 sm:px-5 shrink-0 z-10 sticky top-0">
      <div className="flex items-center gap-2 sm:gap-3 min-w-0">
        {/* Landing Page Button */}
        {onLogout && (
          <button
            onClick={onLogout}
            className="px-2.5 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-xl text-xs font-bold transition-colors flex items-center gap-1.5 shrink-0 cursor-pointer"
            title="Kembali ke Landing Page"
          >
            <Home className="w-3.5 h-3.5 text-[#EC167F]" />
            <span className="hidden sm:inline">Landing Page</span>
          </button>
        )}

        {/* Mobile Brand Logo & Name */}
        <div className="flex items-center gap-2 sm:hidden shrink-0">
          <div className="w-7 h-7 rounded-lg bg-[#EC167F] flex items-center justify-center text-white font-black shadow-2xs">
            <Sparkles className="w-3.5 h-3.5" />
          </div>
          <span className="font-extrabold text-sm tracking-tight text-slate-900">MuaKita</span>
        </div>

        {/* ROLE SWITCHER PILL */}
        <div className="flex items-center bg-slate-100 p-0.5 rounded-xl border border-slate-200/70 shrink-0">
          <button 
            onClick={() => { 
              setRole('superadmin'); 
              setActiveTab('dashboard'); 
              triggerToast("Role diset: Super Admin"); 
            }}
            className={`px-2 py-1 sm:px-2.5 rounded-lg text-[11px] sm:text-xs font-bold transition-all flex items-center gap-1 sm:gap-1.5 cursor-pointer ${
              role === 'superadmin' ? 'bg-white text-[#EC167F] shadow-2xs' : 'text-slate-600 hover:text-slate-900'
            }`}
          >
            <Shield className="w-3 h-3 sm:w-3.5 sm:h-3.5" />
            <span className="text-[10px] sm:text-xs">Superadmin</span>
          </button>

          <button 
            onClick={() => { 
              setRole('owner'); 
              setActiveTab('dashboard'); 
              triggerToast("Role diset: Bisnis Owner"); 
            }}
            className={`px-2 py-1 sm:px-2.5 rounded-lg text-[11px] sm:text-xs font-bold transition-all flex items-center gap-1 sm:gap-1.5 cursor-pointer ${
              role === 'owner' ? 'bg-white text-[#EC167F] shadow-2xs' : 'text-slate-600 hover:text-slate-900'
            }`}
          >
            <Briefcase className="w-3 h-3 sm:w-3.5 sm:h-3.5" />
            <span className="text-[10px] sm:text-xs">Owner</span>
          </button>
        </div>

        {/* Desktop Global Search Bar */}
        <div className="relative max-w-sm hidden md:block">
          <input
            type="text"
            placeholder={role === 'superadmin' ? "Cari tenant, pengguna, paket..." : "Cari reservasi, pelanggan..."}
            value={searchQuery}
            onChange={(e) => setSearchQuery(e.target.value)}
            className="pl-8 pr-10 py-1.5 bg-slate-100/80 border border-slate-200/60 rounded-xl text-xs w-56 focus:w-64 transition-all text-slate-700 focus:outline-none focus:ring-2 focus:ring-pink-500/20 focus:bg-white"
          />
          <Search className="w-3.5 h-3.5 text-slate-400 absolute left-2.5 top-2.5" />
          <kbd className="absolute right-2.5 top-2 px-1.5 py-0.5 text-[9px] font-mono text-slate-400 bg-white rounded border border-slate-200 shadow-2xs">⌘K</kbd>
        </div>
      </div>

      {/* Topbar Right Controls */}
      <div className="flex items-center gap-1.5 sm:gap-2 shrink-0">
        {/* Primary Action Button */}
        <button 
          onClick={onOpenAddModal}
          className="bg-[#EC167F] hover:bg-[#D41270] text-white text-xs font-bold px-2.5 py-1.5 sm:px-3 rounded-xl shadow-xs transition-all flex items-center gap-1 active:scale-95 cursor-pointer"
        >
          <Plus className="w-3.5 h-3.5" />
          <span className="hidden xs:inline sm:inline">
            {role === 'superadmin' ? 'Buat Tenant' : 'Buat Reservasi'}
          </span>
        </button>

        {/* Bell Notifications */}
        <button className="w-7 h-7 sm:w-8 sm:h-8 rounded-xl bg-slate-50 hover:bg-slate-100 border border-slate-200/70 flex items-center justify-center relative text-slate-600 transition-colors cursor-pointer">
          <Bell className="w-3.5 h-3.5 sm:w-4 sm:h-4" />
          <span className="absolute -top-1 -right-1 bg-[#EC167F] text-white text-[8px] sm:text-[9px] font-extrabold w-3.5 h-3.5 sm:w-4 sm:h-4 rounded-full flex items-center justify-center ring-2 ring-white">
            {role === 'superadmin' ? '12' : '8'}
          </span>
        </button>

        {/* Messages Chat (Desktop only) */}
        <button className="w-8 h-8 rounded-xl bg-slate-50 hover:bg-slate-100 border border-slate-200/70 hidden sm:flex items-center justify-center relative text-slate-600 transition-colors cursor-pointer">
          <MessageSquare className="w-4 h-4" />
          <span className="absolute -top-1 -right-1 bg-[#EC167F] text-white text-[9px] font-extrabold w-4 h-4 rounded-full flex items-center justify-center ring-2 ring-white">
            3
          </span>
        </button>

        {/* Dark Mode Toggle */}
        <button 
          onClick={() => setIsDarkMode(!isDarkMode)}
          className="w-7 h-7 sm:w-8 sm:h-8 rounded-xl bg-slate-50 hover:bg-slate-100 border border-slate-200/70 flex items-center justify-center text-slate-600 transition-colors cursor-pointer"
        >
          {isDarkMode ? <Sun className="w-3.5 h-3.5 sm:w-4 sm:h-4 text-amber-500" /> : <Moon className="w-3.5 h-3.5 sm:w-4 sm:h-4" />}
        </button>

        {/* User Profile & Logout */}
        <div className="relative flex items-center gap-1.5 sm:gap-2 pl-1.5 sm:pl-2 border-l border-slate-200">
          <button 
            onClick={() => setShowUserDropdown(!showUserDropdown)}
            className="flex items-center gap-1.5 sm:gap-2 cursor-pointer focus:outline-none"
          >
            <div className="w-7 h-7 sm:w-8 sm:h-8 rounded-full bg-slate-800 text-white flex items-center justify-center font-bold text-xs shadow-xs overflow-hidden ring-2 ring-transparent hover:ring-pink-300 transition-all">
              <img 
                src={role === 'superadmin' 
                  ? "https://images.unsplash.com/photo-1534528741775-53994a69daeb?auto=format&fit=crop&q=80&w=120"
                  : "https://images.unsplash.com/photo-1544005313-94ddf0286df2?auto=format&fit=crop&q=80&w=120"
                } 
                alt="Avatar" 
                referrerPolicy="no-referrer"
                onError={(e) => {
                  e.currentTarget.src = `https://ui-avatars.com/api/?name=${role === 'superadmin' ? 'Reza+Setiawan' : 'Reza+Amelia'}&background=fce7f3&color=ec167f&bold=true`;
                }}
                className="w-full h-full object-cover" 
              />
            </div>
            <div className="hidden md:flex flex-col text-left">
              <span className="text-xs font-bold text-slate-900 leading-tight">
                {role === 'superadmin' ? 'Reza Setiawan' : 'Reza Amelia'}
              </span>
              <span className="text-[10px] text-slate-500 leading-tight">
                {role === 'superadmin' ? 'Super Admin' : 'Beauty Studio'}
              </span>
            </div>
            <ChevronDown className="w-3.5 h-3.5 text-slate-400 hidden md:block" />
          </button>

          {/* User Profile Dropdown Menu */}
          {showUserDropdown && (
            <div className="absolute right-0 top-10 w-48 bg-white border border-slate-200 shadow-xl rounded-2xl p-1.5 z-50 text-xs space-y-1 animate-in fade-in zoom-in-95 duration-150">
              <div className="px-3 py-2 border-b border-slate-100">
                <p className="font-extrabold text-slate-900 truncate">
                  {role === 'superadmin' ? 'Reza Setiawan' : 'Reza Amelia'}
                </p>
                <p className="text-[10px] text-slate-500 font-medium truncate">
                  {role === 'superadmin' ? 'admin@muakita.com' : 'owner@rezaameliamua.com'}
                </p>
              </div>

              <button
                onClick={() => {
                  setShowUserDropdown(false);
                  triggerToast("Buka Pengaturan Akun");
                }}
                className="w-full text-left px-3 py-2 text-slate-700 hover:bg-slate-50 rounded-xl font-bold flex items-center gap-2 cursor-pointer transition-colors"
              >
                <UserCheck className="w-3.5 h-3.5 text-slate-500" />
                <span>Pengaturan Akun</span>
              </button>

              <div className="border-t border-slate-100 pt-1">
                <button
                  onClick={() => {
                    setShowUserDropdown(false);
                    if (onLogout) onLogout();
                  }}
                  className="w-full text-left px-3 py-2 text-rose-600 hover:bg-rose-50 rounded-xl font-bold flex items-center gap-2 cursor-pointer transition-colors"
                >
                  <LogOut className="w-3.5 h-3.5" />
                  <span>Keluar (Logout)</span>
                </button>
              </div>
            </div>
          )}

          {/* Direct Logout Button */}
          {onLogout && (
            <button
              onClick={onLogout}
              className="p-1.5 rounded-xl bg-slate-50 hover:bg-rose-50 text-slate-500 hover:text-rose-600 border border-slate-200/80 transition-colors cursor-pointer hidden sm:flex items-center gap-1"
              title="Keluar dari Akun"
            >
              <LogOut className="w-3.5 h-3.5" />
              <span className="text-[11px] font-bold hidden lg:inline">Keluar</span>
            </button>
          )}
        </div>
      </div>
    </header>
  );
};


Zerion Mini Shell 1.0