<?php

use App\Http\Controllers\InvoiceController;
use App\Livewire;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Thinkrax Central
|--------------------------------------------------------------------------
|
| An internal panel with no public surface at all: every route below the
| guest block requires a signed-in staff account. There is deliberately no
| self-registration — accounts are created by a super admin.
|
*/

Route::redirect('/', '/dashboard');

/*
|--------------------------------------------------------------------------
| Guest
|--------------------------------------------------------------------------
*/

Route::middleware('guest')->group(function () {
    Route::livewire('/login', Livewire\Auth\Login::class)->name('login');
    Route::livewire('/forgot-password', Livewire\Auth\ForgotPassword::class)->name('password.request');
    Route::livewire('/reset-password/{token}', Livewire\Auth\ResetPassword::class)->name('password.reset');
});

Route::post('/logout', Livewire\Auth\Logout::class)->name('logout')->middleware('auth');

/*
|--------------------------------------------------------------------------
| Panel
|--------------------------------------------------------------------------
*/

Route::middleware('panel')->group(function () {

    Route::livewire('/dashboard', Livewire\Dashboard::class)->name('dashboard');

    /* ------------------------------------------------------------ customers */

    Route::livewire('/shops', Livewire\Tenants\TenantIndex::class)->name('tenants.index');
    Route::livewire('/shops/{tenant}', Livewire\Tenants\TenantShow::class)->name('tenants.show');

    Route::livewire('/subscriptions', Livewire\Billing\Subscriptions::class)->name('subscriptions.index');
    Route::livewire('/invoices', Livewire\Billing\Invoices::class)->name('invoices.index');
    Route::get('/invoices/{invoice}/pdf', [InvoiceController::class, 'pdf'])->name('invoices.pdf');

    Route::livewire('/payments', Livewire\Billing\PaymentHistory::class)->name('payments.index');

    // The reason the panel exists. Gated to staff who may decide.
    Route::livewire('/payments/queue', Livewire\Billing\PaymentQueue::class)
        ->name('payments.queue')
        ->middleware('can:verify-payments');

    /* ----------------------------------------------------------- catalogue */

    Route::middleware('can:manage-catalog')->group(function () {
        Route::livewire('/products', Livewire\Catalog\Products::class)->name('products.index');
        Route::livewire('/plans', Livewire\Catalog\Plans::class)->name('plans.index');
        Route::livewire('/receiving-accounts', Livewire\Catalog\PaymentAccounts::class)->name('accounts.index');
        Route::livewire('/announcements', Livewire\System\Announcements::class)->name('announcements.index');
        Route::livewire('/settings', Livewire\System\Settings::class)->name('settings.index');
    });

    /* ------------------------------------------------------------- reports */

    Route::livewire('/reports/revenue', Livewire\Reports\Revenue::class)->name('reports.revenue');
    Route::livewire('/reports/growth', Livewire\Reports\Growth::class)->name('reports.growth');

    /* -------------------------------------------------------------- system */

    Route::livewire('/staff', Livewire\System\AdminUsers::class)->name('staff.index');
    Route::livewire('/activity', Livewire\System\ActivityFeed::class)->name('activity.index');
    Route::livewire('/notifications', Livewire\System\Notifications::class)->name('notifications.index');
    Route::livewire('/profile', Livewire\System\Profile::class)->name('profile');
});
