<?php

namespace Database\Seeders;

use App\Models\Category;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $categories = [
            // KATEGORI PEMASUKAN
            [
                'name' => 'Pemasukan',
                'type' => 'income',
                'icon' => 'wallet',
                'color' => '#10B981',
                'is_system' => true,
                'children' => [
                    ['name' => 'Gaji', 'icon' => 'money-bill-wave', 'color' => '#059669'],
                    ['name' => 'Freelance', 'icon' => 'laptop-code', 'color' => '#047857'],
                    ['name' => 'Investasi', 'icon' => 'chart-line', 'color' => '#065F46'],
                    ['name' => 'Hadiah', 'icon' => 'gift', 'color' => '#064E3B'],
                    ['name' => 'Pengembalian Dana', 'icon' => 'rotate-left', 'color' => '#0D9488'],
                    ['name' => 'Bonus', 'icon' => 'star', 'color' => '#14B8A6'],
                    ['name' => 'Dividen', 'icon' => 'coins', 'color' => '#0F766E'],
                    ['name' => 'Sewa', 'icon' => 'building', 'color' => '#115E59'],
                    ['name' => 'Pemasukan Lainnya', 'icon' => 'plus-circle', 'color' => '#134E4A'],
                ],
            ],

            // KATEGORI PENGELUARAN
            [
                'name' => 'Makanan & Minuman',
                'type' => 'expense',
                'icon' => 'utensils',
                'color' => '#F59E0B',
                'is_system' => true,
                'children' => [
                    ['name' => 'Belanja Groceries', 'icon' => 'cart-shopping', 'color' => '#D97706'],
                    ['name' => 'Restoran', 'icon' => 'utensils', 'color' => '#B45309'],
                    ['name' => 'Kopi & Minuman', 'icon' => 'mug-hot', 'color' => '#92400E'],
                    ['name' => 'Pesan Antar Makanan', 'icon' => 'motorcycle', 'color' => '#78350F'],
                    ['name' => 'Jajanan', 'icon' => 'cookie-bite', 'color' => '#A16207'],
                ],
            ],

            [
                'name' => 'Transportasi',
                'type' => 'expense',
                'icon' => 'car',
                'color' => '#3B82F6',
                'is_system' => true,
                'children' => [
                    ['name' => 'Bensin', 'icon' => 'gas-pump', 'color' => '#2563EB'],
                    ['name' => 'Transportasi Umum', 'icon' => 'bus', 'color' => '#1D4ED8'],
                    ['name' => 'Ojek Online', 'icon' => 'motorcycle', 'color' => '#1E40AF'],
                    ['name' => 'Parkir', 'icon' => 'square-parking', 'color' => '#1E3A8A'],
                    ['name' => 'Perawatan Kendaraan', 'icon' => 'screwdriver-wrench', 'color' => '#3730A3'],
                    ['name' => 'Tol', 'icon' => 'road', 'color' => '#4338CA'],
                ],
            ],

            [
                'name' => 'Rumah & Tempat Tinggal',
                'type' => 'expense',
                'icon' => 'house',
                'color' => '#8B5CF6',
                'is_system' => true,
                'children' => [
                    ['name' => 'Sewa Rumah/Kos', 'icon' => 'house-user', 'color' => '#7C3AED'],
                    ['name' => 'Cicilan KPR', 'icon' => 'building-columns', 'color' => '#6D28D9'],
                    ['name' => 'Asuransi Rumah', 'icon' => 'shield-halved', 'color' => '#5B21B6'],
                    ['name' => 'Perbaikan Rumah', 'icon' => 'hammer', 'color' => '#4C1D95'],
                    ['name' => 'Perabotan', 'icon' => 'couch', 'color' => '#581C87'],
                ],
            ],

            [
                'name' => 'Tagihan & Utilitas',
                'type' => 'expense',
                'icon' => 'file-invoice-dollar',
                'color' => '#EC4899',
                'is_system' => true,
                'children' => [
                    ['name' => 'Listrik', 'icon' => 'bolt', 'color' => '#DB2777'],
                    ['name' => 'Air PDAM', 'icon' => 'droplet', 'color' => '#BE185D'],
                    ['name' => 'Internet', 'icon' => 'wifi', 'color' => '#9D174D'],
                    ['name' => 'Pulsa & Paket Data', 'icon' => 'mobile-screen', 'color' => '#831843'],
                    ['name' => 'TV Kabel', 'icon' => 'tv', 'color' => '#701A75'],
                    ['name' => 'Langganan Streaming', 'icon' => 'play', 'color' => '#A21CAF'],
                ],
            ],

            [
                'name' => 'Belanja',
                'type' => 'expense',
                'icon' => 'bag-shopping',
                'color' => '#EF4444',
                'is_system' => true,
                'children' => [
                    ['name' => 'Pakaian', 'icon' => 'shirt', 'color' => '#DC2626'],
                    ['name' => 'Elektronik', 'icon' => 'laptop', 'color' => '#B91C1C'],
                    ['name' => 'Perlengkapan Rumah', 'icon' => 'box-open', 'color' => '#991B1B'],
                    ['name' => 'Kosmetik & Kecantikan', 'icon' => 'spa', 'color' => '#7F1D1D'],
                    ['name' => 'Belanja Online', 'icon' => 'boxes-stacked', 'color' => '#F87171'],
                ],
            ],

            [
                'name' => 'Hiburan',
                'type' => 'expense',
                'icon' => 'film',
                'color' => '#06B6D4',
                'is_system' => true,
                'children' => [
                    ['name' => 'Bioskop', 'icon' => 'clapperboard', 'color' => '#0891B2'],
                    ['name' => 'Game', 'icon' => 'gamepad', 'color' => '#0E7490'],
                    ['name' => 'Konser & Acara', 'icon' => 'ticket', 'color' => '#155E75'],
                    ['name' => 'Hobi', 'icon' => 'palette', 'color' => '#164E63'],
                    ['name' => 'Liburan', 'icon' => 'umbrella-beach', 'color' => '#22D3EE'],
                ],
            ],

            [
                'name' => 'Kesehatan',
                'type' => 'expense',
                'icon' => 'heart-pulse',
                'color' => '#F97316',
                'is_system' => true,
                'children' => [
                    ['name' => 'Dokter & Rumah Sakit', 'icon' => 'stethoscope', 'color' => '#EA580C'],
                    ['name' => 'Obat-obatan', 'icon' => 'pills', 'color' => '#C2410C'],
                    ['name' => 'Gym & Olahraga', 'icon' => 'dumbbell', 'color' => '#9A3412'],
                    ['name' => 'BPJS & Asuransi Kesehatan', 'icon' => 'id-card', 'color' => '#7C2D12'],
                    ['name' => 'Vitamin & Suplemen', 'icon' => 'capsules', 'color' => '#FB923C'],
                ],
            ],

            [
                'name' => 'Perawatan Diri',
                'type' => 'expense',
                'icon' => 'face-smile',
                'color' => '#A855F7',
                'is_system' => true,
                'children' => [
                    ['name' => 'Potong Rambut', 'icon' => 'scissors', 'color' => '#9333EA'],
                    ['name' => 'Salon & Spa', 'icon' => 'spa', 'color' => '#7E22CE'],
                    ['name' => 'Skincare', 'icon' => 'pump-soap', 'color' => '#6B21A8'],
                    ['name' => 'Laundry', 'icon' => 'jug-detergent', 'color' => '#C084FC'],
                ],
            ],

            [
                'name' => 'Pendidikan',
                'type' => 'expense',
                'icon' => 'graduation-cap',
                'color' => '#14B8A6',
                'is_system' => true,
                'children' => [
                    ['name' => 'Kursus & Pelatihan', 'icon' => 'chalkboard-user', 'color' => '#0D9488'],
                    ['name' => 'Buku & Materi', 'icon' => 'book', 'color' => '#0F766E'],
                    ['name' => 'Alat Tulis', 'icon' => 'pen', 'color' => '#115E59'],
                    ['name' => 'SPP Sekolah', 'icon' => 'school', 'color' => '#134E4A'],
                    ['name' => 'Les Privat', 'icon' => 'person-chalkboard', 'color' => '#2DD4BF'],
                ],
            ],

            [
                'name' => 'Wisata & Perjalanan',
                'type' => 'expense',
                'icon' => 'plane',
                'color' => '#6366F1',
                'is_system' => true,
                'children' => [
                    ['name' => 'Tiket Pesawat', 'icon' => 'plane-departure', 'color' => '#4F46E5'],
                    ['name' => 'Hotel & Penginapan', 'icon' => 'hotel', 'color' => '#4338CA'],
                    ['name' => 'Wisata & Aktivitas', 'icon' => 'map-location-dot', 'color' => '#3730A3'],
                    ['name' => 'Asuransi Perjalanan', 'icon' => 'shield-halved', 'color' => '#312E81'],
                    ['name' => 'Oleh-oleh', 'icon' => 'basket-shopping', 'color' => '#818CF8'],
                ],
            ],

            [
                'name' => 'Keuangan',
                'type' => 'expense',
                'icon' => 'building-columns',
                'color' => '#64748B',
                'is_system' => true,
                'children' => [
                    ['name' => 'Biaya Admin Bank', 'icon' => 'credit-card', 'color' => '#475569'],
                    ['name' => 'Bunga Pinjaman', 'icon' => 'percent', 'color' => '#334155'],
                    ['name' => 'Pajak', 'icon' => 'receipt', 'color' => '#1E293B'],
                    ['name' => 'Asuransi', 'icon' => 'umbrella', 'color' => '#0F172A'],
                    ['name' => 'Cicilan Pinjaman', 'icon' => 'hand-holding-dollar', 'color' => '#475569'],
                    ['name' => 'Transfer & Biaya', 'icon' => 'money-bill-transfer', 'color' => '#94A3B8'],
                ],
            ],

            [
                'name' => 'Keluarga',
                'type' => 'expense',
                'icon' => 'people-roof',
                'color' => '#F472B6',
                'is_system' => true,
                'children' => [
                    ['name' => 'Penitipan Anak', 'icon' => 'baby', 'color' => '#EC4899'],
                    ['name' => 'Hewan Peliharaan', 'icon' => 'paw', 'color' => '#DB2777'],
                    ['name' => 'Kegiatan Keluarga', 'icon' => 'cake-candles', 'color' => '#BE185D'],
                    ['name' => 'Uang Saku Anak', 'icon' => 'piggy-bank', 'color' => '#9D174D'],
                    ['name' => 'Perlengkapan Bayi', 'icon' => 'baby-carriage', 'color' => '#F9A8D4'],
                ],
            ],

            [
                'name' => 'Sosial & Amal',
                'type' => 'expense',
                'icon' => 'hand-holding-heart',
                'color' => '#22C55E',
                'is_system' => true,
                'children' => [
                    ['name' => 'Zakat', 'icon' => 'mosque', 'color' => '#16A34A'],
                    ['name' => 'Infaq & Sedekah', 'icon' => 'hand-holding-heart', 'color' => '#15803D'],
                    ['name' => 'Donasi', 'icon' => 'circle-dollar-to-slot', 'color' => '#166534'],
                    ['name' => 'Sumbangan', 'icon' => 'handshake-angle', 'color' => '#14532D'],
                ],
            ],

            [
                'name' => 'Pengeluaran Lainnya',
                'type' => 'expense',
                'icon' => 'ellipsis',
                'color' => '#78716C',
                'is_system' => true,
                'children' => [
                    ['name' => 'Denda', 'icon' => 'triangle-exclamation', 'color' => '#57534E'],
                    ['name' => 'Kehilangan', 'icon' => 'circle-question', 'color' => '#44403C'],
                    ['name' => 'Lain-lain', 'icon' => 'asterisk', 'color' => '#292524'],
                ],
            ],
        ];

        $sortOrder = 0;
        foreach ($categories as $categoryData) {
            $children = $categoryData['children'] ?? [];
            unset($categoryData['children']);

            $categoryData['slug'] = Str::slug($categoryData['name']);
            $categoryData['sort_order'] = $sortOrder++;
            $categoryData['user_id'] = null; // System category

            $parent = Category::firstOrCreate(
                ['slug' => $categoryData['slug'], 'user_id' => null],
                $categoryData
            );

            $childSortOrder = 0;
            foreach ($children as $childData) {
                Category::firstOrCreate(
                    ['slug' => Str::slug($childData['name']), 'user_id' => null, 'parent_id' => $parent->id],
                    [
                        'name' => $childData['name'],
                        'type' => $categoryData['type'],
                        'icon' => $childData['icon'],
                        'color' => $childData['color'],
                        'is_system' => true,
                        'sort_order' => $childSortOrder++,
                    ]
                );
            }
        }
    }
}
