Untitled
Anonymous
Plain Text
10/31/2025 4:48 AM
8.4 KB
23
Indexable
Never
import React, { useState, useEffect } from 'react';
import { Plus, Minus, Trash2, RotateCcw } from 'lucide-react';
const ClosetManager = () => {
const initialInventory = {
pangLakat: 11,
pangBalay: 20,
pants: 7,
shortsLakat: 6,
shortsBalay: 4,
uniform: 2,
jackets: 5,
polo: 10
};
const [inventory, setInventory] = useState(initialInventory);
const [newItem, setNewItem] = useState('');
const [newQuantity, setNewQuantity] = useState(1);
const [customItems, setCustomItems] = useState([]);
const categories = [
{ key: 'pangLakat', label: 'Pang lakat (Going out)', icon: '👔' },
{ key: 'pangBalay', label: 'Pang balay (House clothes)', icon: '👕' },
{ key: 'polo', label: 'Polo', icon: '👔' },
{ key: 'pants', label: 'Pants', icon: '👖' },
{ key: 'shortsLakat', label: 'Shorts - Panglakat', icon: '🩳' },
{ key: 'shortsBalay', label: 'Shorts - Pangbalay', icon: '🩳' },
{ key: 'jackets', label: 'Jackets', icon: '🧥' },
{ key: 'uniform', label: 'Uniform (STI)', icon: '🎓' }
];
const updateQuantity = (key, delta) => {
setInventory(prev => ({
...prev,
[key]: Math.max(0, prev[key] + delta)
}));
};
const updateCustomQuantity = (index, delta) => {
setCustomItems(prev => {
const updated = [...prev];
updated[index].quantity = Math.max(0, updated[index].quantity + delta);
return updated;
});
};
const addCustomItem = () => {
if (newItem.trim()) {
setCustomItems(prev => [...prev, { name: newItem, quantity: newQuantity }]);
setNewItem('');
setNewQuantity(1);
}
};
const deleteCustomItem = (index) => {
setCustomItems(prev => prev.filter((_, i) => i !== index));
};
const resetInventory = () => {
if (confirm('Reset all items to initial values?')) {
setInventory(initialInventory);
setCustomItems([]);
}
};
const totalTops = inventory.pangLakat + inventory.pangBalay + inventory.polo;
const totalBottoms = inventory.pants + inventory.shortsLakat + inventory.shortsBalay;
const totalOuterwear = inventory.jackets + inventory.uniform;
const totalCustom = customItems.reduce((sum, item) => sum + item.quantity, 0);
const grandTotal = totalTops + totalBottoms + totalOuterwear + totalCustom;
return (
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 p-6">
<div className="max-w-4xl mx-auto">
<div className="bg-white rounded-2xl shadow-xl p-8 mb-6">
<div className="flex justify-between items-center mb-6">
<h1 className="text-4xl font-bold text-gray-800">👗 Closet Manager</h1>
<button
onClick={resetInventory}
className="flex items-center gap-2 px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg transition"
>
<RotateCcw size={18} />
Reset
</button>
</div>
{/* Summary Cards */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
<div className="bg-blue-50 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-blue-600">{totalTops}</div>
<div className="text-sm text-gray-600">Tops/Shirts</div>
</div>
<div className="bg-green-50 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-green-600">{totalBottoms}</div>
<div className="text-sm text-gray-600">Bottoms</div>
</div>
<div className="bg-purple-50 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-purple-600">{totalOuterwear}</div>
<div className="text-sm text-gray-600">Outerwear</div>
</div>
<div className="bg-orange-50 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-orange-600">{grandTotal}</div>
<div className="text-sm text-gray-600">Total Items</div>
</div>
</div>
{/* Inventory Items */}
<div className="space-y-3 mb-8">
{categories.map(({ key, label, icon }) => (
<div key={key} className="flex items-center justify-between bg-gray-50 rounded-xl p-4 hover:bg-gray-100 transition">
<div className="flex items-center gap-3">
<span className="text-2xl">{icon}</span>
<span className="font-medium text-gray-700">{label}</span>
</div>
<div className="flex items-center gap-3">
<button
onClick={() => updateQuantity(key, -1)}
className="p-2 bg-red-100 hover:bg-red-200 rounded-lg transition"
disabled={inventory[key] === 0}
>
<Minus size={18} className="text-red-600" />
</button>
<span className="text-2xl font-bold text-gray-800 w-12 text-center">
{inventory[key]}
</span>
<button
onClick={() => updateQuantity(key, 1)}
className="p-2 bg-green-100 hover:bg-green-200 rounded-lg transition"
>
<Plus size={18} className="text-green-600" />
</button>
</div>
</div>
))}
{/* Custom Items */}
{customItems.map((item, index) => (
<div key={index} className="flex items-center justify-between bg-yellow-50 rounded-xl p-4 hover:bg-yellow-100 transition">
<div className="flex items-center gap-3">
<span className="text-2xl">📦</span>
<span className="font-medium text-gray-700">{item.name}</span>
</div>
<div className="flex items-center gap-3">
<button
onClick={() => updateCustomQuantity(index, -1)}
className="p-2 bg-red-100 hover:bg-red-200 rounded-lg transition"
disabled={item.quantity === 0}
>
<Minus size={18} className="text-red-600" />
</button>
<span className="text-2xl font-bold text-gray-800 w-12 text-center">
{item.quantity}
</span>
<button
onClick={() => updateCustomQuantity(index, 1)}
className="p-2 bg-green-100 hover:bg-green-200 rounded-lg transition"
>
<Plus size={18} className="text-green-600" />
</button>
<button
onClick={() => deleteCustomItem(index)}
className="p-2 bg-gray-200 hover:bg-gray-300 rounded-lg transition ml-2"
>
<Trash2 size={18} className="text-gray-600" />
</button>
</div>
</div>
))}
</div>
{/* Add Custom Item */}
<div className="bg-indigo-50 rounded-xl p-6">
<h3 className="text-lg font-semibold text-gray-800 mb-4">Add New Item</h3>
<div className="flex gap-3">
<input
type="text"
value={newItem}
onChange={(e) => setNewItem(e.target.value)}
placeholder="Item name (e.g., Hoodie, Dress)"
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"
onKeyPress={(e) => e.key === 'Enter' && addCustomItem()}
/>
<input
type="number"
value={newQuantity}
onChange={(e) => setNewQuantity(Math.max(1, parseInt(e.target.value) || 1))}
min="1"
className="w-20 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"
/>
<button
onClick={addCustomItem}
className="px-6 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition font-medium"
>
Add
</button>
</div>
</div>
</div>
</div>
</div>
);
};
export default ClosetManager;Editor is loading...
Leave a Comment