<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\KunjunganController;
use App\Http\Controllers\TamuController;
use App\Http\Controllers\LaporanController;
use App\Http\Controllers\PesanController;

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

Route::get('/kunjungan', [KunjunganController::class, 'create'])
    ->name('kunjungan.create');

Route::post('/kunjungan', [KunjunganController::class, 'store'])
    ->name('kunjungan.store');

// Halaman Pesan & Kesan
Route::get('/pesan-kesan/{id}', [KunjunganController::class, 'pesanKesan'])
    ->name('pesan.kesan');

// Simpan Pesan & Kesan
Route::post('/pesan-kesan/{id}', [KunjunganController::class, 'simpanPesanKesan'])
    ->name('pesan.kesan.store');

Route::get('/terima-kasih', function () {
    return view('terimakasih');
})->name('terimakasih');

Route::get('/tentang', function () {
    return redirect('/#tentang');
});

Route::get('/kontak', function () {
    return redirect('/#kontak');
});

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

Route::post('/login', function () {

    $id = request('id');
    $password = request('password');


    // ID dan Password yang dibuat
    if ($id == 'admin' && $password == 'smkn7') {

        session([
            'login' => true,
            'user' => $id
        ]);

        return redirect('/dashboard');

    } else {

        return back()->with('error', 'ID atau Password salah');

    }

})->name('login.process');

use App\Http\Controllers\DashboardController;

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

Route::get('/data-pengunjung', [TamuController::class, 'index'])
    ->name('data.pengunjung');

Route::post('/logout', function () {
    session()->forget('login');
    session()->forget('user');
    session()->flush();

    return redirect('/');
})->name('logout');

Route::get('/laporan', [LaporanController::class, 'index'])
    ->name('laporan');

Route::get('/laporan/export/excel', [LaporanController::class, 'exportExcel'])
    ->name('laporan.export.excel');

Route::get('/pesan-kesan', [PesanController::class, 'index'])
    ->name('pesan');

