<?php

namespace Database\Seeders;

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

class CategorySeeder extends Seeder
{
    public function run(): void
    {
        $categories = [
            [
                'name' => 'Roupas Femininas',
                'slug' => 'roupas-femininas',
                'description' => 'Moda feminina completa',
                'icon' => 'shirt',
                'is_active' => true,
                'order_index' => 1,
                'children' => [
                    ['name' => 'Vestidos', 'slug' => 'vestidos', 'icon' => 'dress'],
                    ['name' => 'Blusas', 'slug' => 'blusas', 'icon' => 'shirt'],
                    ['name' => 'Calças', 'slug' => 'calcas-femininas', 'icon' => 'trousers'],
                    ['name' => 'Saias', 'slug' => 'saias', 'icon' => 'skirt'],
                ],
            ],
            [
                'name' => 'Roupas Masculinas',
                'slug' => 'roupas-masculinas',
                'description' => 'Moda masculina completa',
                'icon' => 'user',
                'is_active' => true,
                'order_index' => 2,
                'children' => [
                    ['name' => 'Camisas', 'slug' => 'camisas', 'icon' => 'shirt'],
                    ['name' => 'Camisetas', 'slug' => 'camisetas', 'icon' => 'tshirt'],
                    ['name' => 'Calças', 'slug' => 'calcas-masculinas', 'icon' => 'trousers'],
                    ['name' => 'Bermudas', 'slug' => 'bermudas', 'icon' => 'shorts'],
                ],
            ],
            [
                'name' => 'Calçados',
                'slug' => 'calcados',
                'description' => 'Sapatos e tênis',
                'icon' => 'shoe',
                'is_active' => true,
                'order_index' => 3,
                'children' => [
                    ['name' => 'Tênis', 'slug' => 'tenis', 'icon' => 'sneaker'],
                    ['name' => 'Sapatos Sociais', 'slug' => 'sapatos-sociais', 'icon' => 'shoe'],
                    ['name' => 'Sandálias', 'slug' => 'sandalias', 'icon' => 'sandal'],
                    ['name' => 'Botas', 'slug' => 'botas', 'icon' => 'boot'],
                ],
            ],
            [
                'name' => 'Acessórios',
                'slug' => 'acessorios',
                'description' => 'Bolsas, cintos e mais',
                'icon' => 'bag',
                'is_active' => true,
                'order_index' => 4,
                'children' => [
                    ['name' => 'Bolsas', 'slug' => 'bolsas', 'icon' => 'bag'],
                    ['name' => 'Cintos', 'slug' => 'cintos', 'icon' => 'belt'],
                    ['name' => 'Carteiras', 'slug' => 'carteiras', 'icon' => 'wallet'],
                    ['name' => 'Relógios', 'slug' => 'relogios', 'icon' => 'watch'],
                ],
            ],
            [
                'name' => 'Roupas Infantis',
                'slug' => 'roupas-infantis',
                'description' => 'Moda infantil',
                'icon' => 'baby',
                'is_active' => true,
                'order_index' => 5,
                'children' => [
                    ['name' => 'Meninos', 'slug' => 'infantil-meninos', 'icon' => 'boy'],
                    ['name' => 'Meninas', 'slug' => 'infantil-meninas', 'icon' => 'girl'],
                    ['name' => 'Bebês', 'slug' => 'bebes', 'icon' => 'baby'],
                ],
            ],
        ];

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

            $parent = Category::create($categoryData);

            foreach ($children as $child) {
                Category::create([
                    'name' => $child['name'],
                    'slug' => $child['slug'],
                    'icon' => $child['icon'] ?? null,
                    'parent_id' => $parent->id,
                    'is_active' => true,
                    'order_index' => 0,
                ]);
            }
        }
    }
}
