<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('dashboard_tabs_settings', function (Blueprint $table) {
            $table->id();
            $table->string('tab_key')->unique();
            $table->string('tab_label');
            $table->integer('order_index')->default(0);
            $table->boolean('is_visible')->default(true);
            $table->timestamps();
        });

        // Insert default dashboard tabs
        $defaultTabs = [
            ['tab_key' => 'my_tasks', 'tab_label' => 'My Tasks', 'order_index' => 1, 'is_visible' => true],
            ['tab_key' => 'repairs', 'tab_label' => 'Repairs', 'order_index' => 2, 'is_visible' => true],
            ['tab_key' => 'remote_support', 'tab_label' => 'Remote Support', 'order_index' => 3, 'is_visible' => true],
            ['tab_key' => 'onsite', 'tab_label' => 'Onsite', 'order_index' => 4, 'is_visible' => true],
            ['tab_key' => 'delegated', 'tab_label' => 'Delegated', 'order_index' => 5, 'is_visible' => true],
            ['tab_key' => 'sale_leads', 'tab_label' => 'Sale Leads', 'order_index' => 6, 'is_visible' => true],
            ['tab_key' => 'rma', 'tab_label' => 'RMA', 'order_index' => 7, 'is_visible' => true],
            ['tab_key' => 'projects', 'tab_label' => 'Projects', 'order_index' => 8, 'is_visible' => true],
            ['tab_key' => 'my_completed', 'tab_label' => 'My Completed', 'order_index' => 9, 'is_visible' => true],
            ['tab_key' => 'holidays_calendar', 'tab_label' => 'Holidays Calendar', 'order_index' => 10, 'is_visible' => true],
            ['tab_key' => 'calendar', 'tab_label' => 'Calendar', 'order_index' => 11, 'is_visible' => true],
        ];

        foreach ($defaultTabs as $tab) {
            DB::table('dashboard_tabs_settings')->insert(array_merge($tab, [
                'created_at' => now(),
                'updated_at' => now(),
            ]));
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('dashboard_tabs_settings');
    }
};
