<?php

use Illuminate\Database\Migrations\Migration;
use App\Models\NavigationMenu;
use App\Models\Setting;

return new class extends Migration
{
    public function up(): void
    {
        // 1. Seed top_bar menu items if none exist
        if (NavigationMenu::where('position', 'top_bar')->count() === 0) {
            NavigationMenu::create([
                'name' => 'Hot Offers',
                'link_url' => '/shop',
                'position' => 'top_bar',
                'sort_order' => 0,
                'is_active' => true,
            ]);

            NavigationMenu::create([
                'name' => 'My Orders',
                'link_url' => '/dashboard',
                'position' => 'top_bar',
                'sort_order' => 1,
                'is_active' => true,
            ]);

            NavigationMenu::create([
                'name' => 'Support',
                'link_url' => '/help',
                'position' => 'top_bar',
                'sort_order' => 2,
                'is_active' => true,
            ]);
        }

        // 2. Seed default hotline text setting
        Setting::updateOrCreate(
            ['key' => 'store_hotline_text'],
            ['value' => 'Hotline: +880 1700-000000 (9:00 AM - 10:00 PM)', 'group' => 'general']
        );
    }

    public function down(): void
    {
        NavigationMenu::where('position', 'top_bar')->delete();
        Setting::where('key', 'store_hotline_text')->delete();
    }
};
