<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FrontendController;
use App\Http\Controllers\AuthController;

// ─── Public Frontend ────────────────────────────────────────────────────────
Route::get('/',             [FrontendController::class, 'home'])->name('home');
Route::get('/about',        [FrontendController::class, 'about'])->name('about');
Route::get('/news',         [FrontendController::class, 'news'])->name('news');
Route::get('/news/{slug}',  [FrontendController::class, 'newsShow'])->name('news.show');
Route::get('/events',       [FrontendController::class, 'events'])->name('events');
Route::get('/referees',     [FrontendController::class, 'referees'])->name('referees');
Route::get('/coaches',      [FrontendController::class, 'coaches'])->name('coaches');
Route::get('/gallery',      [FrontendController::class, 'gallery'])->name('gallery');
Route::get('/achievements', [FrontendController::class, 'achievements'])->name('achievements');
Route::get('/achievements/{achievement}', [FrontendController::class, 'achievementShow'])->name('achievements.show');
Route::get('/downloads',    [FrontendController::class, 'downloads'])->name('downloads');
Route::get('/contact',      [FrontendController::class, 'contact'])->name('contact');
Route::post('/contact',     [FrontendController::class, 'contactSubmit'])->name('contact.submit');
Route::get('/verify/{member_id}', [FrontendController::class, 'verifyMember'])->name('verify');
Route::get('/tree',         [FrontendController::class, 'tree'])->name('tree');
Route::get('/tree/search',  [FrontendController::class, 'searchTree'])->name('tree.search');

// ─── Auth ────────────────────────────────────────────────────────────────────
Route::middleware('guest')->group(function () {
    Route::get('/login',    [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login',   [AuthController::class, 'login']);
    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register',[AuthController::class, 'register']);
});
Route::post('/logout', [AuthController::class, 'logout'])->name('logout')->middleware('auth');

// ─── Member Portal ───────────────────────────────────────────────────────────
Route::middleware(['auth', 'role:member'])->prefix('member')->name('member.')->group(function () {
    Route::get('/dashboard', [\App\Http\Controllers\MemberDashboardController::class, 'index'])->name('dashboard');
});

// ─── Admin Portal ────────────────────────────────────────────────────────────
Route::middleware(['auth', 'role:admin,editor,district_manager,coach'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [\App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard');
    Route::get('/settings', [\App\Http\Controllers\Admin\DashboardController::class, 'settings'])->name('settings');
    Route::post('/settings', [\App\Http\Controllers\Admin\DashboardController::class, 'updateSettings'])->name('settings.update');
    Route::get('/logs', [\App\Http\Controllers\Admin\DashboardController::class, 'activityLogs'])->name('logs');

    // News categories
    Route::get('/news/categories', [\App\Http\Controllers\Admin\NewsController::class, 'categories'])->name('news.categories');
    Route::post('/news/categories', [\App\Http\Controllers\Admin\NewsController::class, 'storeCategory'])->name('news.categories.store');
    Route::delete('/news/categories/{newsCategory}', [\App\Http\Controllers\Admin\NewsController::class, 'destroyCategory'])->name('news.categories.destroy');

    // Resources
    Route::resource('news', \App\Http\Controllers\Admin\NewsController::class);
    Route::resource('events', \App\Http\Controllers\Admin\EventController::class);
    Route::resource('referees', \App\Http\Controllers\Admin\RefereeController::class);
    Route::resource('coaches', \App\Http\Controllers\Admin\CoachController::class);
    Route::resource('achievements', \App\Http\Controllers\Admin\AchievementController::class);
    Route::resource('albums', \App\Http\Controllers\Admin\AlbumController::class);
    Route::post('/albums/{album}/items', [\App\Http\Controllers\Admin\AlbumController::class, 'storeItem'])->name('albums.items.store');
    Route::delete('/albums/{album}/items/{item}', [\App\Http\Controllers\Admin\AlbumController::class, 'destroyItem'])->name('albums.items.destroy');
    
    // Members
    Route::post('/members/{member}/approve', [\App\Http\Controllers\Admin\MemberController::class, 'approve'])->name('members.approve');
    Route::post('/members/{member}/renew', [\App\Http\Controllers\Admin\MemberController::class, 'renew'])->name('members.renew');
    Route::get('/members/export', [\App\Http\Controllers\Admin\MemberController::class, 'exportCsv'])->name('members.export');
    Route::resource('members', \App\Http\Controllers\Admin\MemberController::class);
});

