<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminAuthController;
use App\Http\Controllers\AdminEmployabilityController;
use App\Http\Controllers\AdminFeedbackController;
use App\Http\Controllers\AdminStudentController;
use App\Http\Controllers\AdminStaffController;
use App\Http\Controllers\AdminTeacherController;
use App\Http\Controllers\AdministrationDashboardController;
use App\Http\Controllers\dashboardController;
use App\Http\Controllers\FeedbackReportController;
use App\Http\Controllers\StaffController;
use App\Http\Controllers\OfficerLetterController;
use App\Http\Controllers\OfficerAuthController;
// Route::get('/', function () {
//     return view('dashboard'); // jadikan dashboard view utama
// });

Route::get('/welcome', function () {
    return view('welcome');
});

// Dashboard utama
Route::get('/', [dashboardController::class, 'index'])
    ->name('dashboard');

// Dashboard pengguna: Maklumat Pelajar
Route::get('/maklumat-pelajar', [dashboardController::class, 'studentsInfo'])
    ->name('students.info');

// Dashboard pengguna: Maklumat Pensyarah
Route::get('/maklumat-pensyarah', [dashboardController::class, 'teachersInfo'])
    ->name('teachers.info');

// Dashboard pengguna: Kebolehpasaran graduan
Route::get('/kebolehpasaran', [dashboardController::class, 'employabilityInfo'])
    ->name('employability.info');

// Dashboard pengguna: Staf
Route::get('/staf', [StaffController::class, 'index'])
    ->name('staff.info');

// Dashboard pengguna: Pentadbiran
Route::get('/pentadbiran', [AdministrationDashboardController::class, 'index'])
    ->name('pentadbiran');

// Chatbot: laporan data perlu dibaiki (pengguna)
Route::post('/feedback', [FeedbackReportController::class, 'store'])->name('feedback.store');

// Officer: login + rekod surat masuk/keluar
Route::prefix('officer')->group(function () {
    // Login officer
    Route::get('login', [OfficerAuthController::class, 'showLogin'])->name('officer.login');
    Route::post('login', [OfficerAuthController::class, 'login']);
    Route::post('logout', [OfficerAuthController::class, 'logout'])->name('officer.logout');

    // Zon officer (kemaskini rekod surat)
    Route::middleware('officer')->group(function () {
        Route::get('surat', [OfficerLetterController::class, 'index'])->name('officer.letters.index');
        Route::get('surat/create', [OfficerLetterController::class, 'create'])->name('officer.letters.create');
        Route::post('surat', [OfficerLetterController::class, 'store'])->name('officer.letters.store');
    });
});

// Admin login
Route::get('/admin/login', [AdminAuthController::class, 'showLogin'])->name('admin.login');
Route::post('/admin/login', [AdminAuthController::class, 'login']);
Route::post('/admin/logout', [AdminAuthController::class, 'logout'])->name('admin.logout');

// Zon admin (modul kemaskini data)
Route::middleware('admin')->prefix('admin')->group(function () {
    Route::get('/', function () {
        return redirect()->route('admin.students.index');
    })->name('admin.dashboard');

    // Pelajar (mengikut kelas/program)
    Route::resource('students', AdminStudentController::class)
        ->except(['show'])
        ->names('admin.students');

    // Guru
    Route::resource('teachers', AdminTeacherController::class)
        ->except(['show'])
        ->names('admin.teachers');

    // Staf (nama, jantina, jawatan)
    Route::resource('staff', AdminStaffController::class)
        ->except(['show'])
        ->names('admin.staff');

    // Kebolehpasaran graduan (upload CSV + senarai)
    Route::get('employability', [AdminEmployabilityController::class, 'index'])->name('admin.employability.index');
    Route::get('employability/sample', function () {
        $path = storage_path('app/sample_kebolehpasaran.csv');
        if (!file_exists($path)) {
            abort(404);
        }
        return response()->download($path, 'sample_kebolehpasaran.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
    })->name('admin.employability.sample');
    Route::get('employability/upload', [AdminEmployabilityController::class, 'create'])->name('admin.employability.create');
    Route::post('employability/upload', [AdminEmployabilityController::class, 'store'])->name('admin.employability.store');
    Route::delete('employability/{id}', [AdminEmployabilityController::class, 'destroy'])->name('admin.employability.destroy');

    // Laporan data (chatbot)
    Route::get('feedback', [AdminFeedbackController::class, 'index'])->name('admin.feedback.index');
    Route::post('feedback/{id}/read', [AdminFeedbackController::class, 'markRead'])->name('admin.feedback.markRead');
    Route::post('feedback/{id}/resolved', [AdminFeedbackController::class, 'markResolved'])->name('admin.feedback.markResolved');
});