<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DistributionController;
use App\Http\Controllers\TitipController;
use App\Http\Controllers\JatahController;

// Auth Routes (Guest Only)
Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login']);
});

// Protected Panel Routes (Requires Authentication)
Route::middleware('auth')->group(function () {
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/dashboard', [DashboardController::class, 'index']);

    // Distribution Management
    Route::get('/distribution', [DistributionController::class, 'index'])->name('distribution.index');
    Route::get('/distribution/search-ajax', [DistributionController::class, 'searchAjax'])->name('distribution.search-ajax');
    Route::post('/distribution/{id}/distribute', [DistributionController::class, 'distribute'])->name('distribution.distribute');
    Route::post('/distribution/{id}/entrust', [DistributionController::class, 'entrust'])->name('distribution.entrust');
    Route::post('/distribution/{id}/reset', [DistributionController::class, 'reset'])->name('distribution.reset');
    Route::post('/distribution/{id}/cancel-queue', [DistributionController::class, 'cancelQueue'])->name('distribution.cancel-queue');
    Route::get('/antrian-ambil-daging', [DistributionController::class, 'antrianDistribusi'])->name('distribution.antrian');
    Route::get('/paket-distribusi', [DistributionController::class, 'paketDistribusi'])->name('distribution.paket');
    Route::post('/paket-distribusi/{id}/distribute-all', [DistributionController::class, 'distributeAll'])->name('distribution.distribute-all');

    // Entrusted Packages (Titipan)
    Route::get('/titip', [TitipController::class, 'index'])->name('titip.index');
    Route::post('/titip/{id}/update-status', [TitipController::class, 'updateStatus'])->name('titip.update-status');

    // Group Quotas (Jatah RT/Kelompok)
    Route::get('/jatah', [JatahController::class, 'index'])->name('jatah.index');
    Route::post('/jatah/{id}/update-status', [JatahController::class, 'updateStatus'])->name('jatah.update-status');
});
