%PDF- %PDF-
| Direktori : /home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/ |
| Current File : //home2/rezakur1/muakita.rezakurnia.com/Mua-Kita-Web/src/components/views/InventarisView.tsx |
import React, { useState, useMemo } from 'react';
import {
Store,
Package,
AlertTriangle,
ShieldAlert,
Wallet,
Search,
Filter,
Plus,
Edit3,
MoreVertical,
ChevronLeft,
ChevronRight,
ChevronDown,
X,
Check,
Trash2,
Grid,
List,
Layers,
RefreshCw,
FolderPlus,
ArrowUpDown,
Tag,
MapPin,
Box,
TrendingDown
} from 'lucide-react';
export interface InventoryItem {
id: string;
code: string;
name: string;
category: string;
location: string;
stock: number;
unit: string;
buyPrice: number;
status: 'Tersedia' | 'Stok Menipis' | 'Habis';
image: string;
}
export interface InventoryCategory {
id: string;
name: string;
color: string;
badgeBg: string;
badgeText: string;
itemCount: number;
totalValue: number;
description: string;
}
interface InventarisViewProps {
activeTab?: string;
triggerToast: (msg: string) => void;
}
// Initial Mock Inventory Data matching user image exactly
export const initialInventoryItems: InventoryItem[] = [
{
id: 'inv1',
code: 'INV-001',
name: 'Make Over Powerstay Foundation',
category: 'Makeup',
location: 'Ruang Makeup 1',
stock: 45,
unit: 'pcs',
buyPrice: 85000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1631729371254-42c2892f0e6e?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv2',
code: 'INV-002',
name: 'Makeup Brush Set 12 Pcs',
category: 'Alat Makeup',
location: 'Ruang Alat',
stock: 23,
unit: 'set',
buyPrice: 250000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1522337360788-8b13dee7a37e?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv3',
code: 'INV-003',
name: 'Wardah Exclusive Lipstick',
category: 'Makeup',
location: 'Ruang Makeup 1',
stock: 8,
unit: 'pcs',
buyPrice: 79000,
status: 'Stok Menipis',
image: 'https://images.unsplash.com/photo-1586495777744-4413f21062fa?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv4',
code: 'INV-004',
name: "L'Oréal Elnett Hairspray",
category: 'Hair Care',
location: 'Ruang Hair',
stock: 0,
unit: 'pcs',
buyPrice: 120000,
status: 'Habis',
image: 'https://images.unsplash.com/photo-1608248597262-1262d14b1626?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv5',
code: 'INV-005',
name: 'FOCALLURE Eyeshadow Palette',
category: 'Makeup',
location: 'Ruang Makeup 2',
stock: 15,
unit: 'pcs',
buyPrice: 95000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1512496015851-a90fb38ba796?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv6',
code: 'INV-006',
name: 'Jepit Bulu Mata Premium',
category: 'Alat Makeup',
location: 'Ruang Alat',
stock: 4,
unit: 'pcs',
buyPrice: 35000,
status: 'Stok Menipis',
image: 'https://images.unsplash.com/photo-1596462502278-27bfdc403348?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv7',
code: 'INV-007',
name: 'Skintific 5X Ceramide Moisturizer',
category: 'Skincare',
location: 'Ruang Skincare',
stock: 30,
unit: 'pcs',
buyPrice: 110000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1556228720-195a672e8a03?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv8',
code: 'INV-008',
name: 'Maybelline Superstay Matte Ink',
category: 'Makeup',
location: 'Ruang Makeup 1',
stock: 18,
unit: 'pcs',
buyPrice: 105000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1625093742435-6fa192b6fb1a?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv9',
code: 'INV-009',
name: 'Crown Pengantin Crystal Royal',
category: 'Aksesoris',
location: 'Ruang Aksesoris',
stock: 6,
unit: 'pcs',
buyPrice: 350000,
status: 'Tersedia',
image: 'https://images.unsplash.com/photo-1535632066927-ab7c9ab60908?auto=format&fit=crop&q=80&w=150'
},
{
id: 'inv10',
code: 'INV-010',
name: 'Bulu Mata Palsu Premium (10 Pasang)',
category: 'Alat Makeup',
location: 'Ruang Alat',
stock: 2,
unit: 'box',
buyPrice: 65000,
status: 'Stok Menipis',
image: 'https://images.unsplash.com/photo-1583241800698-e8ab01c85b27?auto=format&fit=crop&q=80&w=150'
}
];
export const initialCategories: InventoryCategory[] = [
{
id: 'cat1',
name: 'Makeup',
color: '#EC167F',
badgeBg: 'bg-purple-100/80',
badgeText: 'text-purple-700',
itemCount: 48,
totalValue: 12450000,
description: 'Kosmetik dekoratif wajah: Foundation, Concealer, Powder, Lipstick, Eyeshadow.'
},
{
id: 'cat2',
name: 'Alat Makeup',
color: '#3B82F6',
badgeBg: 'bg-blue-100/80',
badgeText: 'text-blue-700',
itemCount: 32,
totalValue: 6200000,
description: 'Aplikator & kuas rias: Brush set, Beauty blender, Eyelash curler, Cermin.'
},
{
id: 'cat3',
name: 'Hair Care',
color: '#EC167F',
badgeBg: 'bg-pink-100/80',
badgeText: 'text-pink-700',
itemCount: 18,
totalValue: 2850000,
description: 'Produk penataan & perawatan rambut: Hairspray, Vitamin, Catokan, Hairdryer.'
},
{
id: 'cat4',
name: 'Skincare',
color: '#10B981',
badgeBg: 'bg-emerald-100/80',
badgeText: 'text-emerald-700',
itemCount: 15,
totalValue: 3100000,
description: 'Persiapan kulit sebelum makeup: Toner, Serum, Moisturizer, Face Primer, Sunscreen.'
},
{
id: 'cat5',
name: 'Aksesoris',
color: '#F59E0B',
badgeBg: 'bg-amber-100/80',
badgeText: 'text-amber-700',
itemCount: 10,
totalValue: 4500000,
description: 'Hiasan & perhiasan pengantin: Mahkota crystal, Anting, Veils, Hijab crown.'
},
{
id: 'cat6',
name: 'Kebaya & Busana',
color: '#8B5CF6',
badgeBg: 'bg-indigo-100/80',
badgeText: 'text-indigo-700',
itemCount: 5,
totalValue: 15000000,
description: 'Koleksi gaun pengantin, kebaya akad, dan beskap keluarga.'
}
];
export const InventarisView: React.FC<InventarisViewProps> = ({ activeTab: routeActiveTab, triggerToast }) => {
// Navigation View State ('items' vs 'categories')
const [currentView, setCurrentView] = useState<'items' | 'categories'>(
routeActiveTab === 'inventaris_kategori' ? 'categories' : 'items'
);
// Sync route if changed
React.useEffect(() => {
if (routeActiveTab === 'inventaris_kategori') {
setCurrentView('categories');
} else if (routeActiveTab === 'inventaris') {
setCurrentView('items');
}
}, [routeActiveTab]);
const [items, setItems] = useState<InventoryItem[]>(initialInventoryItems);
const [categories, setCategories] = useState<InventoryCategory[]>(initialCategories);
// Filters
const [selectedCategory, setSelectedCategory] = useState<string>('Semua Kategori');
const [selectedLocation, setSelectedLocation] = useState<string>('Semua Lokasi');
const [selectedStatus, setSelectedStatus] = useState<string>('Semua Status');
const [searchQuery, setSearchQuery] = useState<string>('');
// Checkbox Selection State
const [selectedItemIds, setSelectedItemIds] = useState<string[]>([]);
// Pagination State
const [currentPage, setCurrentPage] = useState<number>(1);
const [itemsPerPage, setItemsPerPage] = useState<number>(10);
// Active Action Menu
const [activeActionId, setActiveActionId] = useState<string | null>(null);
// Modal States
const [showAddItemModal, setShowAddItemModal] = useState<boolean>(false);
const [editingItem, setEditingItem] = useState<InventoryItem | null>(null);
const [showAddCatModal, setShowAddCatModal] = useState<boolean>(false);
const [editingCat, setEditingCat] = useState<InventoryCategory | null>(null);
// Item Form State
const [itemForm, setItemForm] = useState({
code: '',
name: '',
category: 'Makeup',
location: 'Ruang Makeup 1',
stock: 10,
unit: 'pcs',
buyPrice: 50000,
image: 'https://images.unsplash.com/photo-1631729371254-42c2892f0e6e?auto=format&fit=crop&q=80&w=150'
});
// Category Form State
const [catForm, setCatForm] = useState({
name: '',
description: '',
badgeBg: 'bg-purple-100/80',
badgeText: 'text-purple-700'
});
// Helper calculation for Top Statistics Cards
const totalItemCount = items.length;
const totalStockCount = items.reduce((acc, curr) => acc + curr.stock, 0);
const lowStockCount = items.filter(i => i.stock > 0 && i.stock <= 10).length;
const outOfStockCount = items.filter(i => i.stock === 0).length;
const totalStockValue = items.reduce((acc, curr) => acc + (curr.stock * curr.buyPrice), 0);
// Helper formatting currency
const formatIDR = (val: number) => {
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(val);
};
// Filtered Inventory Items
const filteredItems = useMemo(() => {
return items.filter(item => {
// 1. Category
if (selectedCategory !== 'Semua Kategori' && item.category !== selectedCategory) return false;
// 2. Location
if (selectedLocation !== 'Semua Lokasi' && item.location !== selectedLocation) return false;
// 3. Status
if (selectedStatus !== 'Semua Status' && item.status !== selectedStatus) return false;
// 4. Search Query
if (searchQuery.trim()) {
const q = searchQuery.toLowerCase();
const matchName = item.name.toLowerCase().includes(q);
const matchCode = item.code.toLowerCase().includes(q);
const matchCat = item.category.toLowerCase().includes(q);
const matchLoc = item.location.toLowerCase().includes(q);
if (!matchName && !matchCode && !matchCat && !matchLoc) return false;
}
return true;
});
}, [items, selectedCategory, selectedLocation, selectedStatus, searchQuery]);
// Paginated Items
const totalPages = Math.ceil(filteredItems.length / itemsPerPage) || 1;
const paginatedItems = useMemo(() => {
const start = (currentPage - 1) * itemsPerPage;
return filteredItems.slice(start, start + itemsPerPage);
}, [filteredItems, currentPage, itemsPerPage]);
const startItemNum = filteredItems.length === 0 ? 0 : (currentPage - 1) * itemsPerPage + 1;
const endItemNum = Math.min(currentPage * itemsPerPage, filteredItems.length);
// Checkbox Select All Handler
const isAllSelected = paginatedItems.length > 0 && paginatedItems.every(i => selectedItemIds.includes(i.id));
const toggleSelectAll = () => {
if (isAllSelected) {
setSelectedItemIds(prev => prev.filter(id => !paginatedItems.some(i => i.id === id)));
} else {
const newIds = [...selectedItemIds];
paginatedItems.forEach(i => {
if (!newIds.includes(i.id)) newIds.push(i.id);
});
setSelectedItemIds(newIds);
}
};
const toggleSelectItem = (id: string) => {
setSelectedItemIds(prev =>
prev.includes(id) ? prev.filter(i => i !== id) : [...prev, id]
);
};
// Add Item Submit
const handleAddItemSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!itemForm.name.trim()) {
triggerToast('Mohon masukkan nama item!');
return;
}
const calculatedStatus: 'Tersedia' | 'Stok Menipis' | 'Habis' =
itemForm.stock === 0 ? 'Habis' : itemForm.stock <= 10 ? 'Stok Menipis' : 'Tersedia';
const newItem: InventoryItem = {
id: `inv_${Date.now()}`,
code: itemForm.code || `INV-0${items.length + 1}`,
name: itemForm.name,
category: itemForm.category,
location: itemForm.location,
stock: Number(itemForm.stock),
unit: itemForm.unit || 'pcs',
buyPrice: Number(itemForm.buyPrice),
status: calculatedStatus,
image: itemForm.image || 'https://images.unsplash.com/photo-1631729371254-42c2892f0e6e?auto=format&fit=crop&q=80&w=150'
};
setItems([newItem, ...items]);
setShowAddItemModal(false);
setItemForm({
code: '',
name: '',
category: 'Makeup',
location: 'Ruang Makeup 1',
stock: 10,
unit: 'pcs',
buyPrice: 50000,
image: 'https://images.unsplash.com/photo-1631729371254-42c2892f0e6e?auto=format&fit=crop&q=80&w=150'
});
triggerToast(`Item "${newItem.name}" berhasil ditambahkan!`);
};
// Edit Item Submit
const handleSaveEditItem = (e: React.FormEvent) => {
e.preventDefault();
if (!editingItem) return;
const calculatedStatus: 'Tersedia' | 'Stok Menipis' | 'Habis' =
editingItem.stock === 0 ? 'Habis' : editingItem.stock <= 10 ? 'Stok Menipis' : 'Tersedia';
const updated = { ...editingItem, status: calculatedStatus };
setItems(prev => prev.map(i => i.id === updated.id ? updated : i));
setEditingItem(null);
triggerToast(`Data item "${updated.name}" berhasil diperbarui.`);
};
// Delete Item
const handleDeleteItem = (id: string, name: string) => {
if (confirm(`Apakah Anda yakin ingin menghapus "${name}" dari inventaris?`)) {
setItems(prev => prev.filter(i => i.id !== id));
setActiveActionId(null);
triggerToast(`"${name}" telah dihapus.`);
}
};
// Add Category Submit
const handleAddCatSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!catForm.name.trim()) {
triggerToast('Mohon masukkan nama kategori!');
return;
}
const newCat: InventoryCategory = {
id: `cat_${Date.now()}`,
name: catForm.name,
color: '#EC167F',
badgeBg: catForm.badgeBg,
badgeText: catForm.badgeText,
itemCount: 0,
totalValue: 0,
description: catForm.description || 'Kategori produk inventaris MuaKita studio.'
};
setCategories([...categories, newCat]);
setShowAddCatModal(false);
setCatForm({ name: '', description: '', badgeBg: 'bg-purple-100/80', badgeText: 'text-purple-700' });
triggerToast(`Kategori "${newCat.name}" berhasil dibuat!`);
};
return (
<div className="space-y-5 animate-fade-in pb-12">
{/* TOP HEADER BAR WITH TITLE, SUB-TABS, & ACTION BUTTONS */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-3">
<div>
<h1 className="text-xl sm:text-2xl font-black text-slate-900 tracking-tight">Manajemen Inventaris & Stok</h1>
<p className="text-xs text-slate-500 font-medium">Kelola kosmetik, peralatan makeup, stok produk, dan kategori inventaris studio.</p>
</div>
{/* SUB MENU VIEW TOGGLER & ACTION BUTTON */}
<div className="flex items-center gap-2 self-start md:self-auto flex-wrap">
{/* Sub-menu View Selector (Items vs Categories) */}
<div className="p-1 bg-slate-100 rounded-xl flex items-center gap-1 border border-slate-200/80">
<button
onClick={() => setCurrentView('items')}
className={`px-3 py-1.5 rounded-lg text-xs font-bold transition-all flex items-center gap-1.5 cursor-pointer ${
currentView === 'items'
? 'bg-white text-[#EC167F] shadow-2xs'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<Package className="w-3.5 h-3.5" />
<span>Daftar Item</span>
</button>
<button
onClick={() => setCurrentView('categories')}
className={`px-3 py-1.5 rounded-lg text-xs font-bold transition-all flex items-center gap-1.5 cursor-pointer ${
currentView === 'categories'
? 'bg-white text-[#EC167F] shadow-2xs'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<Layers className="w-3.5 h-3.5" />
<span>Kategori ({categories.length})</span>
</button>
</div>
{/* Top Action Button */}
{currentView === 'items' ? (
<button
onClick={() => setShowAddItemModal(true)}
className="bg-[#EC167F] hover:bg-[#d0106e] text-white text-xs sm:text-sm font-bold px-4 py-2 rounded-xl flex items-center justify-center gap-2 shadow-sm shadow-pink-200 transition-all cursor-pointer"
>
<Plus className="w-4 h-4" />
<span>Tambah Item</span>
</button>
) : (
<button
onClick={() => setShowAddCatModal(true)}
className="bg-[#EC167F] hover:bg-[#d0106e] text-white text-xs sm:text-sm font-bold px-4 py-2 rounded-xl flex items-center justify-center gap-2 shadow-sm shadow-pink-200 transition-all cursor-pointer"
>
<FolderPlus className="w-4 h-4" />
<span>Tambah Kategori</span>
</button>
)}
</div>
</div>
{/* 5 TOP STAT CARDS MATCHING DESIGN IMAGE EXACTLY */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-3 sm:gap-3.5">
{/* Card 1: Total Item */}
<div className="bg-white border border-slate-200/80 rounded-2xl p-4 shadow-2xs flex flex-col justify-between">
<div className="flex items-center justify-between">
<div className="w-9 h-9 rounded-xl bg-pink-100 flex items-center justify-center text-[#EC167F]">
<Store className="w-4.5 h-4.5" />
</div>
</div>
<div className="mt-2.5">
<span className="text-[11px] font-bold text-slate-500 block">Total Item</span>
<div className="text-2xl font-black text-slate-900 tracking-tight mt-0.5">{totalItemCount}</div>
<span className="text-[10px] text-slate-400 font-medium block mt-0.5">Semua item inventaris</span>
</div>
</div>
{/* Card 2: Total Stok */}
<div className="bg-white border border-slate-200/80 rounded-2xl p-4 shadow-2xs flex flex-col justify-between">
<div className="flex items-center justify-between">
<div className="w-9 h-9 rounded-xl bg-purple-100 flex items-center justify-center text-purple-600">
<Package className="w-4.5 h-4.5" />
</div>
</div>
<div className="mt-2.5">
<span className="text-[11px] font-bold text-slate-500 block">Total Stok</span>
<div className="text-2xl font-black text-slate-900 tracking-tight mt-0.5">{totalStockCount.toLocaleString('id-ID')}</div>
<span className="text-[10px] text-slate-400 font-medium block mt-0.5">Semua item</span>
</div>
</div>
{/* Card 3: Stok Menipis */}
<div className="bg-white border border-slate-200/80 rounded-2xl p-4 shadow-2xs flex flex-col justify-between">
<div className="flex items-center justify-between">
<div className="w-9 h-9 rounded-xl bg-amber-100 flex items-center justify-center text-amber-600">
<AlertTriangle className="w-4.5 h-4.5" />
</div>
</div>
<div className="mt-2.5">
<span className="text-[11px] font-bold text-slate-500 block">Stok Menipis</span>
<div className="text-2xl font-black text-slate-900 tracking-tight mt-0.5">{lowStockCount}</div>
<span className="text-[10px] text-slate-400 font-medium block mt-0.5">Perlu restock</span>
</div>
</div>
{/* Card 4: Habis */}
<div className="bg-white border border-slate-200/80 rounded-2xl p-4 shadow-2xs flex flex-col justify-between">
<div className="flex items-center justify-between">
<div className="w-9 h-9 rounded-xl bg-pink-50 flex items-center justify-center text-[#EC167F]">
<ShieldAlert className="w-4.5 h-4.5" />
</div>
</div>
<div className="mt-2.5">
<span className="text-[11px] font-bold text-slate-500 block">Habis</span>
<div className="text-2xl font-black text-slate-900 tracking-tight mt-0.5">{outOfStockCount}</div>
<span className="text-[10px] text-slate-400 font-medium block mt-0.5">Perlu segera diisi</span>
</div>
</div>
{/* Card 5: Total Nilai Stok */}
<div className="bg-white border border-slate-200/80 rounded-2xl p-4 shadow-2xs flex flex-col justify-between">
<div className="flex items-center justify-between">
<div className="w-9 h-9 rounded-xl bg-emerald-100 flex items-center justify-center text-emerald-600">
<Wallet className="w-4.5 h-4.5" />
</div>
</div>
<div className="mt-2.5">
<span className="text-[11px] font-bold text-slate-500 block">Total Nilai Stok</span>
<div className="text-xl sm:text-2xl font-black text-slate-900 tracking-tight mt-0.5">{formatIDR(totalStockValue)}</div>
<span className="text-[10px] text-slate-400 font-medium block mt-0.5">Berdasarkan harga beli</span>
</div>
</div>
</div>
{/* VIEW CONTENT 1: DAFTAR ITEM INVENTARIS */}
{currentView === 'items' && (
<div className="bg-white border border-slate-200/80 rounded-2xl shadow-2xs overflow-hidden">
{/* FILTER BAR WITH EXACT 5 DROPDOWNS & INPUTS FROM IMAGE */}
<div className="p-4 border-b border-slate-100">
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-12 gap-3 items-center">
{/* 1. Kategori Dropdown */}
<div className="lg:col-span-3">
<label className="block text-[11px] font-bold text-slate-600 mb-1">Kategori</label>
<div className="relative">
<select
value={selectedCategory}
onChange={(e) => { setSelectedCategory(e.target.value); setCurrentPage(1); }}
className="w-full bg-white border border-slate-200/90 rounded-xl px-3 py-2 pr-8 text-xs font-semibold text-slate-800 appearance-none focus:outline-none focus:border-[#EC167F] cursor-pointer shadow-2xs"
>
<option value="Semua Kategori">Semua Kategori</option>
{categories.map(cat => (
<option key={cat.id} value={cat.name}>{cat.name}</option>
))}
</select>
<ChevronDown className="w-4 h-4 text-slate-400 absolute right-2.5 top-2.5 pointer-events-none" />
</div>
</div>
{/* 2. Lokasi / Tempat Dropdown */}
<div className="lg:col-span-3">
<label className="block text-[11px] font-bold text-slate-600 mb-1">Lokasi / Tempat</label>
<div className="relative">
<select
value={selectedLocation}
onChange={(e) => { setSelectedLocation(e.target.value); setCurrentPage(1); }}
className="w-full bg-white border border-slate-200/90 rounded-xl px-3 py-2 pr-8 text-xs font-semibold text-slate-800 appearance-none focus:outline-none focus:border-[#EC167F] cursor-pointer shadow-2xs"
>
<option value="Semua Lokasi">Semua Lokasi</option>
<option value="Ruang Makeup 1">Ruang Makeup 1</option>
<option value="Ruang Makeup 2">Ruang Makeup 2</option>
<option value="Ruang Alat">Ruang Alat</option>
<option value="Ruang Hair">Ruang Hair</option>
<option value="Ruang Skincare">Ruang Skincare</option>
<option value="Ruang Aksesoris">Ruang Aksesoris</option>
</select>
<ChevronDown className="w-4 h-4 text-slate-400 absolute right-2.5 top-2.5 pointer-events-none" />
</div>
</div>
{/* 3. Status Dropdown */}
<div className="lg:col-span-2">
<label className="block text-[11px] font-bold text-slate-600 mb-1">Status</label>
<div className="relative">
<select
value={selectedStatus}
onChange={(e) => { setSelectedStatus(e.target.value); setCurrentPage(1); }}
className="w-full bg-white border border-slate-200/90 rounded-xl px-3 py-2 pr-8 text-xs font-semibold text-slate-800 appearance-none focus:outline-none focus:border-[#EC167F] cursor-pointer shadow-2xs"
>
<option value="Semua Status">Semua Status</option>
<option value="Tersedia">Tersedia</option>
<option value="Stok Menipis">Stok Menipis</option>
<option value="Habis">Habis</option>
</select>
<ChevronDown className="w-4 h-4 text-slate-400 absolute right-2.5 top-2.5 pointer-events-none" />
</div>
</div>
{/* 4. Search Box Input */}
<div className="lg:col-span-3">
<label className="block text-[11px] font-bold text-slate-600 mb-1">Pencarian</label>
<div className="relative">
<input
type="text"
value={searchQuery}
onChange={(e) => { setSearchQuery(e.target.value); setCurrentPage(1); }}
placeholder="Cari nama item, kode, atau merek..."
className="w-full pl-3.5 pr-9 py-2 bg-white border border-slate-200/90 rounded-xl text-xs text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#EC167F] focus:ring-1 focus:ring-[#EC167F] shadow-2xs"
/>
<Search className="w-4 h-4 text-slate-400 absolute right-3 top-2.5 pointer-events-none" />
</div>
</div>
{/* 5. Filter Button */}
<div className="lg:col-span-1 pt-0 sm:pt-4">
<button
onClick={() => {
setSelectedCategory('Semua Kategori');
setSelectedLocation('Semua Lokasi');
setSelectedStatus('Semua Status');
setSearchQuery('');
}}
className="w-full px-3 py-2 bg-white border border-slate-200/90 rounded-xl text-xs font-bold text-slate-700 hover:bg-slate-50 flex items-center justify-center gap-1.5 shadow-2xs cursor-pointer transition-colors"
title="Reset Filter"
>
<Filter className="w-3.5 h-3.5 text-slate-500" />
<span>Filter</span>
</button>
</div>
</div>
</div>
{/* TABLE DATA LIST MATCHING SCREENSHOT EXACTLY */}
<div className="overflow-x-auto">
<table className="w-full text-left border-collapse min-w-[880px]">
<thead>
<tr className="bg-slate-50/70 border-b border-slate-100 text-[11px] font-bold text-slate-500 uppercase tracking-wider">
<th className="px-4 py-3.5 w-10 text-center">
<input
type="checkbox"
checked={isAllSelected}
onChange={toggleSelectAll}
className="w-4 h-4 rounded border-slate-300 text-[#EC167F] focus:ring-[#EC167F] cursor-pointer"
/>
</th>
<th className="px-4 py-3.5">Item</th>
<th className="px-4 py-3.5">Kategori</th>
<th className="px-4 py-3.5">Lokasi</th>
<th className="px-4 py-3.5">Stok</th>
<th className="px-4 py-3.5">Harga Beli</th>
<th className="px-4 py-3.5">Nilai Stok</th>
<th className="px-4 py-3.5">Status</th>
<th className="px-4 py-3.5 text-right">Aksi</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-100">
{paginatedItems.length === 0 ? (
<tr>
<td colSpan={9} className="px-5 py-12 text-center text-slate-400 text-xs">
<Package className="w-8 h-8 text-slate-300 mx-auto mb-2" />
Tidak ada item inventaris yang ditemukan.
</td>
</tr>
) : (
paginatedItems.map((item) => {
const isSelected = selectedItemIds.includes(item.id);
const stockValue = item.stock * item.buyPrice;
return (
<tr
key={item.id}
className={`hover:bg-slate-50/60 transition-colors ${isSelected ? 'bg-pink-50/30' : ''}`}
>
{/* Checkbox */}
<td className="px-4 py-3.5 text-center">
<input
type="checkbox"
checked={isSelected}
onChange={() => toggleSelectItem(item.id)}
className="w-4 h-4 rounded border-slate-300 text-[#EC167F] focus:ring-[#EC167F] cursor-pointer"
/>
</td>
{/* Item Name & Thumbnail */}
<td className="px-4 py-3.5">
<div className="flex items-center gap-3">
<img
src={item.image}
alt={item.name}
referrerPolicy="no-referrer"
className="w-10 h-10 rounded-xl object-cover border border-slate-200/80 shadow-2xs shrink-0"
/>
<div className="min-w-0">
<span className="font-bold text-xs sm:text-sm text-slate-900 block truncate">{item.name}</span>
<span className="text-[10px] text-slate-400 font-mono font-medium block">{item.code}</span>
</div>
</div>
</td>
{/* Kategori Badge */}
<td className="px-4 py-3.5">
{item.category === 'Makeup' && (
<span className="px-2.5 py-1 bg-purple-100/70 text-purple-700 text-xs font-bold rounded-lg inline-block">
Makeup
</span>
)}
{item.category === 'Alat Makeup' && (
<span className="px-2.5 py-1 bg-blue-100/70 text-blue-700 text-xs font-bold rounded-lg inline-block">
Alat Makeup
</span>
)}
{item.category === 'Hair Care' && (
<span className="px-2.5 py-1 bg-pink-100/70 text-pink-700 text-xs font-bold rounded-lg inline-block">
Hair Care
</span>
)}
{item.category === 'Skincare' && (
<span className="px-2.5 py-1 bg-purple-100/70 text-purple-700 text-xs font-bold rounded-lg inline-block">
Skincare
</span>
)}
{item.category === 'Aksesoris' && (
<span className="px-2.5 py-1 bg-amber-100/70 text-amber-700 text-xs font-bold rounded-lg inline-block">
Aksesoris
</span>
)}
{!['Makeup', 'Alat Makeup', 'Hair Care', 'Skincare', 'Aksesoris'].includes(item.category) && (
<span className="px-2.5 py-1 bg-slate-100 text-slate-700 text-xs font-bold rounded-lg inline-block">
{item.category}
</span>
)}
</td>
{/* Lokasi */}
<td className="px-4 py-3.5 text-xs font-semibold text-slate-800">
{item.location}
</td>
{/* Stok */}
<td className="px-4 py-3.5 text-xs font-bold">
{item.stock === 0 ? (
<span className="text-rose-600 font-black">0 {item.unit}</span>
) : item.stock <= 10 ? (
<span className="text-rose-500 font-bold">{item.stock} {item.unit}</span>
) : (
<span className="text-slate-800">{item.stock} {item.unit}</span>
)}
</td>
{/* Harga Beli */}
<td className="px-4 py-3.5 text-xs font-medium text-slate-700 font-mono">
{formatIDR(item.buyPrice)}
</td>
{/* Nilai Stok */}
<td className="px-4 py-3.5 text-xs font-bold text-slate-900 font-mono">
{formatIDR(stockValue)}
</td>
{/* Status Badge */}
<td className="px-4 py-3.5">
{item.status === 'Tersedia' && (
<span className="px-2.5 py-1 bg-emerald-50 text-emerald-600 border border-emerald-100 text-[11px] font-bold rounded-lg inline-block">
Tersedia
</span>
)}
{item.status === 'Stok Menipis' && (
<span className="px-2.5 py-1 bg-amber-50 text-amber-600 border border-amber-100 text-[11px] font-bold rounded-lg inline-block">
Stok Menipis
</span>
)}
{item.status === 'Habis' && (
<span className="px-2.5 py-1 bg-rose-50 text-rose-600 border border-rose-100 text-[11px] font-bold rounded-lg inline-block">
Habis
</span>
)}
</td>
{/* Actions */}
<td className="px-4 py-3.5 text-right relative">
<div className="flex items-center justify-end gap-1">
<button
onClick={() => setEditingItem(item)}
className="p-1.5 border border-slate-200 rounded-lg text-slate-500 hover:bg-slate-100 hover:text-slate-900 transition-colors cursor-pointer"
title="Edit Item"
>
<Edit3 className="w-3.5 h-3.5" />
</button>
<button
onClick={() => setActiveActionId(activeActionId === item.id ? null : item.id)}
className="p-1.5 border border-slate-200 rounded-lg text-slate-500 hover:bg-slate-100 hover:text-slate-900 transition-colors cursor-pointer"
title="Menu Opsi"
>
<MoreVertical className="w-3.5 h-3.5" />
</button>
</div>
{/* Action Dropdown Menu */}
{activeActionId === item.id && (
<div className="absolute right-4 mt-1 w-40 bg-white border border-slate-200 rounded-xl shadow-lg z-30 py-1 text-left animate-in fade-in zoom-in-95">
<button
onClick={() => {
const addAmt = prompt('Tambah berapa jumlah stok?', '10');
if (addAmt && !isNaN(Number(addAmt))) {
const newStock = item.stock + Number(addAmt);
const newStatus = newStock === 0 ? 'Habis' : newStock <= 10 ? 'Stok Menipis' : 'Tersedia';
setItems(prev => prev.map(i => i.id === item.id ? { ...i, stock: newStock, status: newStatus } : i));
triggerToast(`Stok ${item.name} berhasil ditambah +${addAmt}`);
}
setActiveActionId(null);
}}
className="w-full px-3.5 py-2 text-xs font-semibold text-slate-700 hover:bg-slate-50 flex items-center gap-2"
>
<RefreshCw className="w-3.5 h-3.5 text-emerald-600" />
<span>Restock Stok</span>
</button>
<button
onClick={() => handleDeleteItem(item.id, item.name)}
className="w-full px-3.5 py-2 text-xs font-semibold text-rose-600 hover:bg-rose-50 flex items-center gap-2 border-t border-slate-100 mt-1"
>
<Trash2 className="w-3.5 h-3.5 text-rose-600" />
<span>Hapus Item</span>
</button>
</div>
)}
</td>
</tr>
);
})
)}
</tbody>
</table>
</div>
{/* FOOTER & PAGINATION BAR MATCHING SCREENSHOT */}
<div className="p-4 border-t border-slate-100 flex flex-col sm:flex-row items-center justify-between gap-3 text-xs text-slate-500">
{/* Left Info */}
<div>
Menampilkan <span className="font-bold text-slate-800">{startItemNum} - {endItemNum}</span> dari <span className="font-bold text-slate-800">{filteredItems.length}</span> item
</div>
{/* Right Pagination Buttons */}
<div className="flex items-center gap-2 sm:gap-3">
<div className="flex items-center gap-1">
<button
disabled={currentPage === 1}
onClick={() => setCurrentPage(p => Math.max(p - 1, 1))}
className="p-1.5 border border-slate-200 rounded-lg text-slate-600 hover:bg-slate-50 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors"
>
<ChevronLeft className="w-4 h-4" />
</button>
{Array.from({ length: totalPages }).map((_, idx) => {
const pageNum = idx + 1;
return (
<button
key={pageNum}
onClick={() => setCurrentPage(pageNum)}
className={`w-8 h-8 rounded-lg font-bold text-xs flex items-center justify-center transition-all cursor-pointer ${
currentPage === pageNum
? 'bg-[#EC167F] text-white shadow-2xs'
: 'border border-slate-200 text-slate-700 hover:bg-slate-50'
}`}
>
{pageNum}
</button>
);
})}
<button
disabled={currentPage >= totalPages}
onClick={() => setCurrentPage(p => Math.min(p + 1, totalPages))}
className="p-1.5 border border-slate-200 rounded-lg text-slate-600 hover:bg-slate-50 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors"
>
<ChevronRight className="w-4 h-4" />
</button>
</div>
{/* Per Page Select */}
<div className="relative">
<select
value={itemsPerPage}
onChange={(e) => {
setItemsPerPage(Number(e.target.value));
setCurrentPage(1);
}}
className="appearance-none bg-white border border-slate-200 rounded-xl px-3 py-1.5 pr-7 text-xs font-semibold text-slate-700 focus:outline-none focus:border-[#EC167F] cursor-pointer"
>
<option value={5}>5 / halaman</option>
<option value={10}>10 / halaman</option>
<option value={20}>20 / halaman</option>
</select>
<ChevronDown className="w-3.5 h-3.5 text-slate-400 absolute right-2.5 top-2.5 pointer-events-none" />
</div>
</div>
</div>
</div>
)}
{/* VIEW CONTENT 2: SUB MENU KATEGORI INVENTARIS */}
{currentView === 'categories' && (
<div className="space-y-4">
<div className="p-4 bg-white border border-slate-200/80 rounded-2xl shadow-2xs flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h2 className="text-base font-extrabold text-slate-900">Daftar Kategori Inventaris Studio</h2>
<p className="text-xs text-slate-500">Kelompokkan produk dan peralatan berdasarkan tipe untuk mempermudah audit stok.</p>
</div>
<button
onClick={() => setShowAddCatModal(true)}
className="bg-[#EC167F] hover:bg-[#d0106e] text-white text-xs font-bold px-4 py-2 rounded-xl flex items-center justify-center gap-2 shadow-2xs cursor-pointer self-start sm:self-auto"
>
<FolderPlus className="w-4 h-4" />
<span>+ Tambah Kategori Baru</span>
</button>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{categories.map((cat) => {
// Calculate actual item count for category
const catItems = items.filter(i => i.category === cat.name);
const itemCount = catItems.length || cat.itemCount;
const catTotalVal = catItems.reduce((a, b) => a + (b.stock * b.buyPrice), 0) || cat.totalValue;
return (
<div
key={cat.id}
className="bg-white border border-slate-200/90 rounded-2xl p-4.5 shadow-2xs hover:border-pink-300 transition-all flex flex-col justify-between group"
>
<div>
<div className="flex items-center justify-between mb-3">
<span className={`px-3 py-1 rounded-lg text-xs font-extrabold ${cat.badgeBg} ${cat.badgeText}`}>
{cat.name}
</span>
<div className="flex items-center gap-1 opacity-80 group-hover:opacity-100">
<button
onClick={() => setEditingCat(cat)}
className="p-1 text-slate-400 hover:text-slate-800 rounded hover:bg-slate-100"
title="Edit Kategori"
>
<Edit3 className="w-3.5 h-3.5" />
</button>
<button
onClick={() => {
if (confirm(`Hapus kategori "${cat.name}"?`)) {
setCategories(categories.filter(c => c.id !== cat.id));
triggerToast(`Kategori "${cat.name}" dihapus`);
}
}}
className="p-1 text-slate-400 hover:text-rose-600 rounded hover:bg-rose-50"
title="Hapus Kategori"
>
<Trash2 className="w-3.5 h-3.5" />
</button>
</div>
</div>
<p className="text-xs text-slate-600 font-medium mb-4 line-clamp-2 leading-relaxed">
{cat.description}
</p>
</div>
<div className="pt-3 border-t border-slate-100 flex items-center justify-between text-xs">
<div>
<span className="text-[10px] text-slate-400 block font-medium">Jumlah Produk</span>
<span className="font-extrabold text-slate-900">{itemCount} item</span>
</div>
<div className="text-right">
<span className="text-[10px] text-slate-400 block font-medium">Nilai Total Stok</span>
<span className="font-black text-[#EC167F] font-mono">{formatIDR(catTotalVal)}</span>
</div>
</div>
</div>
);
})}
</div>
</div>
)}
{/* MODAL: TAMBAH ITEM BARU */}
{showAddItemModal && (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4 animate-fade-in">
<div className="bg-white rounded-2xl max-w-lg w-full shadow-2xl overflow-hidden border border-slate-200/80 animate-in fade-in zoom-in-95">
<div className="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50">
<div className="flex items-center gap-2">
<div className="w-8 h-8 rounded-xl bg-pink-100 text-[#EC167F] flex items-center justify-center font-bold">
<Package className="w-4 h-4" />
</div>
<div>
<h3 className="font-extrabold text-slate-900 text-sm sm:text-base">Tambah Item Inventaris Baru</h3>
<p className="text-[11px] text-slate-500 font-medium">Masukkan informasi detail produk, stok awal, dan lokasi penyimpanan.</p>
</div>
</div>
<button
onClick={() => setShowAddItemModal(false)}
className="p-1 text-slate-400 hover:text-slate-700 rounded-lg hover:bg-slate-200/60 transition-colors"
>
<X className="w-5 h-5" />
</button>
</div>
<form onSubmit={handleAddItemSubmit} className="p-6 space-y-3.5 text-xs">
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div className="sm:col-span-2">
<label className="block text-slate-700 font-bold mb-1">Nama Item <span className="text-rose-500">*</span></label>
<input
type="text"
required
value={itemForm.name}
onChange={(e) => setItemForm({ ...itemForm, name: e.target.value })}
placeholder="Contoh: Make Over Powder Foundation"
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Kode SKU</label>
<input
type="text"
value={itemForm.code}
onChange={(e) => setItemForm({ ...itemForm, code: e.target.value })}
placeholder="INV-011"
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl font-mono text-slate-800 focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block text-slate-700 font-bold mb-1">Kategori <span className="text-rose-500">*</span></label>
<select
value={itemForm.category}
onChange={(e) => setItemForm({ ...itemForm, category: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
>
{categories.map(c => (
<option key={c.id} value={c.name}>{c.name}</option>
))}
</select>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Lokasi Penyimpanan <span className="text-rose-500">*</span></label>
<select
value={itemForm.location}
onChange={(e) => setItemForm({ ...itemForm, location: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
>
<option value="Ruang Makeup 1">Ruang Makeup 1</option>
<option value="Ruang Makeup 2">Ruang Makeup 2</option>
<option value="Ruang Alat">Ruang Alat</option>
<option value="Ruang Hair">Ruang Hair</option>
<option value="Ruang Skincare">Ruang Skincare</option>
<option value="Ruang Aksesoris">Ruang Aksesoris</option>
</select>
</div>
</div>
<div className="grid grid-cols-3 gap-3">
<div>
<label className="block text-slate-700 font-bold mb-1">Jumlah Stok <span className="text-rose-500">*</span></label>
<input
type="number"
required
min={0}
value={itemForm.stock}
onChange={(e) => setItemForm({ ...itemForm, stock: Number(e.target.value) })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Satuan</label>
<select
value={itemForm.unit}
onChange={(e) => setItemForm({ ...itemForm, unit: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 focus:bg-white focus:outline-none focus:border-[#EC167F]"
>
<option value="pcs">pcs</option>
<option value="set">set</option>
<option value="box">box</option>
<option value="botol">botol</option>
<option value="paket">paket</option>
</select>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Harga Beli (Rp) <span className="text-rose-500">*</span></label>
<input
type="number"
required
min={0}
value={itemForm.buyPrice}
onChange={(e) => setItemForm({ ...itemForm, buyPrice: Number(e.target.value) })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold font-mono focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">URL Foto Produk</label>
<input
type="text"
value={itemForm.image}
onChange={(e) => setItemForm({ ...itemForm, image: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 text-[11px] focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div className="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button
type="button"
onClick={() => setShowAddItemModal(false)}
className="px-4 py-2 border border-slate-200 rounded-xl font-bold text-slate-600 hover:bg-slate-100"
>
Batal
</button>
<button
type="submit"
className="px-5 py-2 bg-[#EC167F] hover:bg-[#d0106e] text-white font-bold rounded-xl shadow-xs"
>
Simpan Item
</button>
</div>
</form>
</div>
</div>
)}
{/* MODAL: EDIT ITEM */}
{editingItem && (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4 animate-fade-in">
<div className="bg-white rounded-2xl max-w-md w-full shadow-2xl overflow-hidden border border-slate-200/80 animate-in fade-in zoom-in-95">
<div className="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50">
<h3 className="font-extrabold text-slate-900 text-sm">Edit Item Inventaris</h3>
<button
onClick={() => setEditingItem(null)}
className="p-1 text-slate-400 hover:text-slate-700 rounded-lg hover:bg-slate-200/60 transition-colors"
>
<X className="w-5 h-5" />
</button>
</div>
<form onSubmit={handleSaveEditItem} className="p-6 space-y-3 text-xs">
<div>
<label className="block text-slate-700 font-bold mb-1">Nama Item</label>
<input
type="text"
value={editingItem.name}
onChange={(e) => setEditingItem({ ...editingItem, name: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-slate-700 font-bold mb-1">Kategori</label>
<select
value={editingItem.category}
onChange={(e) => setEditingItem({ ...editingItem, category: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
>
{categories.map(c => (
<option key={c.id} value={c.name}>{c.name}</option>
))}
</select>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Lokasi</label>
<input
type="text"
value={editingItem.location}
onChange={(e) => setEditingItem({ ...editingItem, location: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
</div>
<div className="grid grid-cols-2 gap-3">
<div>
<label className="block text-slate-700 font-bold mb-1">Jumlah Stok ({editingItem.unit})</label>
<input
type="number"
min={0}
value={editingItem.stock}
onChange={(e) => setEditingItem({ ...editingItem, stock: Number(e.target.value) })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Harga Beli (Rp)</label>
<input
type="number"
min={0}
value={editingItem.buyPrice}
onChange={(e) => setEditingItem({ ...editingItem, buyPrice: Number(e.target.value) })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold font-mono focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
</div>
<div className="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button
type="button"
onClick={() => setEditingItem(null)}
className="px-4 py-2 border border-slate-200 rounded-xl font-bold text-slate-600 hover:bg-slate-100"
>
Batal
</button>
<button
type="submit"
className="px-5 py-2 bg-[#EC167F] hover:bg-[#d0106e] text-white font-bold rounded-xl shadow-xs"
>
Simpan Perubahan
</button>
</div>
</form>
</div>
</div>
)}
{/* MODAL: TAMBAH KATEGORI BARU */}
{showAddCatModal && (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4 animate-fade-in">
<div className="bg-white rounded-2xl max-w-md w-full shadow-2xl overflow-hidden border border-slate-200/80 animate-in fade-in zoom-in-95">
<div className="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50">
<div className="flex items-center gap-2">
<div className="w-8 h-8 rounded-xl bg-pink-100 text-[#EC167F] flex items-center justify-center font-bold">
<FolderPlus className="w-4 h-4" />
</div>
<div>
<h3 className="font-extrabold text-slate-900 text-sm">Tambah Kategori Inventaris</h3>
</div>
</div>
<button
onClick={() => setShowAddCatModal(false)}
className="p-1 text-slate-400 hover:text-slate-700 rounded-lg"
>
<X className="w-5 h-5" />
</button>
</div>
<form onSubmit={handleAddCatSubmit} className="p-6 space-y-3 text-xs">
<div>
<label className="block text-slate-700 font-bold mb-1">Nama Kategori <span className="text-rose-500">*</span></label>
<input
type="text"
required
value={catForm.name}
onChange={(e) => setCatForm({ ...catForm, name: e.target.value })}
placeholder="Contoh: Peralatan Lighting & Backdrop"
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Deskripsi Kategori</label>
<textarea
rows={3}
value={catForm.description}
onChange={(e) => setCatForm({ ...catForm, description: e.target.value })}
placeholder="Keterangan jenis item yang ada dalam kategori ini..."
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div className="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button
type="button"
onClick={() => setShowAddCatModal(false)}
className="px-4 py-2 border border-slate-200 rounded-xl font-bold text-slate-600 hover:bg-slate-100"
>
Batal
</button>
<button
type="submit"
className="px-5 py-2 bg-[#EC167F] hover:bg-[#d0106e] text-white font-bold rounded-xl shadow-xs"
>
Simpan Kategori
</button>
</div>
</form>
</div>
</div>
)}
{/* MODAL: EDIT KATEGORI */}
{editingCat && (
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4 animate-fade-in">
<div className="bg-white rounded-2xl max-w-md w-full shadow-2xl overflow-hidden border border-slate-200/80 animate-in fade-in zoom-in-95">
<div className="px-6 py-4 border-b border-slate-100 flex items-center justify-between bg-slate-50/50">
<h3 className="font-extrabold text-slate-900 text-sm">Edit Kategori</h3>
<button
onClick={() => setEditingCat(null)}
className="p-1 text-slate-400 hover:text-slate-700"
>
<X className="w-5 h-5" />
</button>
</div>
<form onSubmit={(e) => {
e.preventDefault();
setCategories(prev => prev.map(c => c.id === editingCat.id ? editingCat : c));
setEditingCat(null);
triggerToast(`Kategori "${editingCat.name}" berhasil diperbarui.`);
}} className="p-6 space-y-3 text-xs">
<div>
<label className="block text-slate-700 font-bold mb-1">Nama Kategori</label>
<input
type="text"
value={editingCat.name}
onChange={(e) => setEditingCat({ ...editingCat, name: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 font-bold focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div>
<label className="block text-slate-700 font-bold mb-1">Deskripsi</label>
<textarea
rows={3}
value={editingCat.description}
onChange={(e) => setEditingCat({ ...editingCat, description: e.target.value })}
className="w-full p-2.5 bg-slate-50 border border-slate-200 rounded-xl text-slate-800 focus:bg-white focus:outline-none focus:border-[#EC167F]"
/>
</div>
<div className="pt-3 border-t border-slate-100 flex items-center justify-end gap-2.5">
<button
type="button"
onClick={() => setEditingCat(null)}
className="px-4 py-2 border border-slate-200 rounded-xl font-bold text-slate-600 hover:bg-slate-100"
>
Batal
</button>
<button
type="submit"
className="px-5 py-2 bg-[#EC167F] hover:bg-[#d0106e] text-white font-bold rounded-xl shadow-xs"
>
Simpan Perubahan
</button>
</div>
</form>
</div>
</div>
)}
</div>
);
};