<?php

declare(strict_types=1);

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Menu;
use App\Models\User;
use Illuminate\Database\Seeder;

class MenusTableHeaderSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $admin = User::role('admin')->first();

        $headerMenu = Menu::updateOrCreate(
            ['title' => 'هدر'],
            [
                'url' => '',
                'order_id' => 0,
                'icon' => '',
                'created_by' => $admin->id,
                'parent_id' => null,
            ]
        );

        $homeMenu = Menu::updateOrCreate(
            ['title' => 'خانه'],
            [
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $headerMenu->id,
            ]
        );

        $productsMenu = Menu::updateOrCreate(
            ['title' => 'محصولات'],
            [
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $headerMenu->id,
            ]
        );

        $blogMenu = Menu::updateOrCreate(
            ['title' => 'بلاگ'],
            [
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
                'parent_id' => $headerMenu->id,
            ]
        );

        $homeChildren = [
            [
                'title' => 'خانه آیتم ۱',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'خانه آیتم ۲',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'خانه آیتم ۳',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        $productsChildren = [
            [
                'title' => 'محصولات آیتم ۱',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'محصولات آیتم ۲',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'محصولات آیتم ۳',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        $blogChildren = [
            [
                'title' => 'بلاگ آیتم ۱',
                'url' => '#',
                'order_id' => 1,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'بلاگ آیتم ۲',
                'url' => '#',
                'order_id' => 2,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
            [
                'title' => 'بلاگ آیتم ۳',
                'url' => '#',
                'order_id' => 3,
                'icon' => 'files/default_icon.png',
                'created_by' => $admin->id,
            ],
        ];

        foreach ($homeChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $homeMenu->id])
            );
        }

        foreach ($productsChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $productsMenu->id])
            );
        }

        foreach ($blogChildren as $child) {
            Menu::updateOrCreate(
                ['title' => $child['title']],
                array_merge($child, ['parent_id' => $blogMenu->id])
            );
        }
    }
}
