<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use Maestro\Core\Models\MaestroModule;
use Maestro\Core\Models\NavigationNode;

/**
 * Dutch navigation labels and pin Superbeheer above Instellingen in the sidebar footer.
 */
return new class extends Migration
{
    public function up(): void
    {
        if (Schema::hasTable('maestro_modules')) {
            MaestroModule::query()->where('slug', 'customers')->update(['label' => 'Klanten']);
            MaestroModule::query()->where('slug', 'hours')->update(['label' => 'Urenregistratie']);
            MaestroModule::query()->where('slug', 'offers')->update(['label' => 'Offertes']);
        }

        if (! Schema::hasTable('navigation_nodes')) {
            return;
        }

        $nodes = [
            'root' => [
                'label' => 'Applicatie',
            ],
            'dashboard' => [
                'label' => 'Dashboard',
            ],
            'customers' => [
                'label' => 'Klanten',
            ],
            'offers' => [
                'label' => 'Offertes',
            ],
            'hours-week' => [
                'label' => 'Uren werkplek',
            ],
            'superadmin' => [
                'label' => 'Superbeheer',
                'pinned_bottom' => true,
                'description' => 'Configuratie van deze omgeving',
            ],
            'superadmin-installation-health' => [
                'label' => 'Installatiecontrole',
                'description' => 'Controlelijst (migraties, seed, schakelaars)',
            ],
            'superadmin-modules' => [
                'description' => 'Modulestatus en activering',
            ],
            'superadmin-navigation' => [
                'label' => 'Navigatie',
            ],
            'superadmin-appearance' => [
                'label' => 'Thema & lay-out',
            ],
            'superadmin-branding' => [
                'label' => 'Huisstijl',
            ],
            'settings' => [
                'label' => 'Instellingen',
                'description' => 'Organisatie, gebruikers, rollen en activiteiten — volgens rechten.',
            ],
            'settings-organization' => [
                'label' => 'Organisatie',
            ],
            'settings-users' => [
                'label' => 'Gebruikers',
            ],
            'settings-roles' => [
                'label' => 'Rollen',
            ],
            'settings-activity-log' => [
                'label' => 'Activiteitenlogboek',
            ],
            'settings-offers-catalog' => [
                'label' => 'Offertecatalogus',
            ],
            'settings-offers-templates' => [
                'label' => 'Offertesjablonen',
            ],
        ];

        foreach ($nodes as $key => $cols) {
            NavigationNode::query()->where('key', $key)->update($cols);
        }
    }

    public function down(): void
    {
        // Labels are not restored — hosts may have customized navigation via Superadmin.
    }
};
