<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\JadwalBelController;
use App\Http\Controllers\BelController;
use App\Models\User;
use Illuminate\Support\Facades\Hash;

// 🟢 1. Redirect root ke halaman bel otomatis
Route::get('/', function () {
    return redirect()->route('bel.otomatis');
});

// 🟢 2. Halaman bel otomatis tanpa login
Route::get('/bel-otomatis', [JadwalBelController::class, 'otomatis'])->name('bel.otomatis');


// 🟢 4. Hanya admin (login) bisa akses CRUD jadwal
Route::middleware(['auth'])->group(function () {
    Route::resource('jadwal-bel', JadwalBelController::class);

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

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

// 🔧 5. Admin generator (sementara)
Route::get('/create-admin', function () {
    $user = User::create([
        'name' => 'Admin',
        'email' => 'admin@sekolah.id',
        'password' => Hash::make('password123'),
    ]);
    return 'Admin created: admin@sekolah.id / password123';
});

// 🔁 6. Auth routes
require __DIR__ . '/auth.php';
