<?php

use Mtc\Modules\SiteMenu\Http\Controllers\Admin\SiteMenuController;

\Route::group([
    'middleware' => ['web', 'auth'], // Laravel session + admin auth (shares $_SESSION['adminId'])
    'prefix'     => 'admin',
], function () {

    // SPA shell
    \Route::get('site-menu', [SiteMenuController::class, 'index'])
        ->name('admin-site-menu');

    // JSON API consumed by the Vue SPA
    \Route::get('site-menu/api/items', [SiteMenuController::class, 'apiItems'])
        ->name('admin-site-menu-api-items');
    \Route::get('site-menu/api/form/{id?}', [SiteMenuController::class, 'apiForm'])
        ->name('admin-site-menu-api-form');
    \Route::get('site-menu/api/trash', [SiteMenuController::class, 'apiTrash'])
        ->name('admin-site-menu-api-trash');
    \Route::get('site-menu/api/search', [SiteMenuController::class, 'apiSearch'])
        ->name('admin-site-menu-api-search');
    \Route::post('site-menu/api/reorder', [SiteMenuController::class, 'reorder'])
        ->name('admin-site-menu-api-reorder');

    // Mutations (JSON on AJAX, redirect fallback otherwise)
    \Route::post('site-menu/save', [SiteMenuController::class, 'store'])
        ->name('admin-site-menu-save');
    \Route::get('site-menu/delete/{id}', [SiteMenuController::class, 'destroy'])
        ->name('admin-site-menu-delete');
    \Route::get('site-menu/publish/{id}/{value}', [SiteMenuController::class, 'changePublished'])
        ->name('admin-site-menu-publish');
    \Route::get('site-menu/duplicate/{id}', [SiteMenuController::class, 'duplicate'])
        ->name('admin-site-menu-duplicate');
    \Route::get('site-menu/restore/{id}', [SiteMenuController::class, 'restore'])
        ->name('admin-site-menu-restore');

    // Former pages, kept as redirects to the SPA for old bookmarks / no-JS save
    \Route::get('site-menu/edit/{id?}', [SiteMenuController::class, 'edit'])
        ->name('admin-site-menu-edit');
    \Route::get('site-menu/trash', [SiteMenuController::class, 'trash'])
        ->name('admin-site-menu-trash');
});
