<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FingerDevicesControlller;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EmployeeController;
use App\Http\Controllers\AttendanceController;
use App\Http\Controllers\LeaveController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\AnnouncementController;
use App\Http\Controllers\Api\AuthController;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Admin\ProfileController;
use App\Http\Controllers\IzinController;
use App\Http\Controllers\CheckController;


// Web Routes
Route::get('/', function () {
    return redirect()->route('login');
})->name('welcome');

Auth::routes(['register' => false]);

// Admin Web Routes
Route::group(['middleware' => ['auth:admin']], function () {
    Route::get('/admin', [DashboardController::class, 'index'])->name('admin.dashboard');
    
    // Profile Route
    Route::get('/profile', [App\Http\Controllers\Admin\ProfileController::class, 'index'])->name('profile.view');
    
    // Logout Route
    Route::post('/admin/logout', [AuthController::class, 'logout'])->name('admin.logout');
    
    // Data Karyawan
    Route::resource('employees', '\App\Http\Controllers\EmployeeController');
    
    // Monitoring Presensi
    Route::get('/attendance', [AttendanceController::class, 'index'])->name('admin.attendance');
    
    // Pengajuan Izin
    Route::get('/leave', [LeaveController::class, 'index'])->name('admin.leave');
    Route::get('/leave/{id}/details', [LeaveController::class, 'getDetails'])->name('leave.details');
    Route::post('/leave/{id}/update-status', [LeaveController::class, 'updateStatus'])->name('leave.updateStatus');

    // Rekap Data
    Route::get('/check', [CheckController::class, 'index'])->name('admin.reports');
    Route::get('/reports/data', [CheckController::class, 'getData'])->name('admin.reports.data');
    Route::get('/reports/summary', [CheckController::class, 'getSummary'])->name('admin.reports.summary');
    Route::post('/check-store', [CheckController::class, 'checkStore'])->name('check_store');
    Route::get('/sheet-report', [CheckController::class, 'sheetReport'])->name('sheet-report');

    // Announcement Routes
    Route::get('/announcements', [AnnouncementController::class, 'announcement'])->name('announcements.announcement');
    Route::get('/announcements/create', [AnnouncementController::class, 'create'])->name('announcements.create');
    Route::post('/announcements', [AnnouncementController::class, 'store'])->name('announcements.store');
    Route::get('/announcements/{announcement}/edit', [AnnouncementController::class, 'edit'])->name('announcements.edit');
    Route::put('/announcements/{announcement}', [AnnouncementController::class, 'update'])->name('announcements.update');
    Route::delete('/announcements/{announcement}', [AnnouncementController::class, 'destroy'])->name('announcements.destroy');

    Route::delete('/attendance/{id}', [AttendanceController::class, 'destroy'])->name('attendance.destroy');

    // Izin Routes
    Route::get('/admin/izin', [IzinController::class, 'index'])->name('admin.izin');
    Route::delete('/admin/izin/{id}', [IzinController::class, 'destroy'])->name('izin.destroy');
    Route::put('/admin/izin/{id}/approve', [IzinController::class, 'approve'])->name('izin.approve');
    Route::put('/admin/izin/{id}/reject', [IzinController::class, 'reject'])->name('izin.reject');
});

Route::get('attended/{user_id}', [AttendanceController::class, 'attended'])->name('attended');
Route::get('attended-before/{user_id}', [AttendanceController::class, 'attendedBefore'])->name('attendedBefore');


// Route::get('/attendance/assign', function () {
//     return view('attendance_leave_login');
// })->name('attendance.login');

// Route::post('/attendance/assign', '\App\Http\Controllers\AttendanceController@assign')->name('attendance.assign');


// Route::get('/leave/assign', function () {
//     return view('attendance_leave_login');
// })->name('leave.login');

// Route::post('/leave/assign', '\App\Http\Controllers\LeaveController@assign')->name('leave.assign');


// Route::get('{any}', 'App\http\controllers\VeltrixController@index');

// Route untuk mendapatkan CSRF token mentah
Route::get('/get-csrf-token', function () {
    return response()->json([
        'token' => csrf_token()
    ]);
});

