<?php

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\InstrumentController;
use App\Http\Controllers\Admin\SubInstrumentController;
use App\Http\Controllers\Admin\PernyataanInstrumentController;
use App\Http\Controllers\Admin\LembarInstrumentMonitoringController;
use App\Http\Controllers\LoginController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('auth.login');
});

Route::post('login-user', [LoginController::class, 'login'])->name('login-user');

Route::get('logout', function() {
    Auth::logout();
    return redirect('/');
})->name('logout');

Route::middleware(['auth:sanctum'])->group(function () {

    Route::get('/users', function() {
        return User::get();
    })->name('user.index')->middleware('permission');

    Route::get('/dashboard', function () {
        // $account = Auth::user()->hasRole('admin');
        return view('dashboard');
    })->name('dashboard.index');



    Route::resource('/instrument', InstrumentController::class);
    Route::resource('/sub_instrument', SubInstrumentController::class);
    Route::resource('/pernyataan_instrument', PernyataanInstrumentController::class);
    Route::resource('/sub_pernyataan_instrument', SubPernyataanInstrumentController::class);
    Route::get('tambahsub/{id}', [PernyataanInstrumentController::class, 'tambahsub'])->name('tambahsub');
    Route::put('tambahsub_pernyataan_instrument/{id}',[PernyataanInstrumentController::class, 'tambahsub_pernyataan_instrument'])->name('tambahsub_pernyataan_instrument');
    Route::get('editsub/{id}', [PernyataanInstrumentController::class, 'editsub'])->name('editsub');
    Route::get('destroysub/{id}', [PernyataanInstrumentController::class, 'destroysub'])->name('destroysub');
    Route::put('updatesub_pernyataan_instrument/{id}',[PernyataanInstrumentController::class, 'updatesub_pernyataan_instrument'])->name('updatesub_pernyataan_instrument');


    Route::resource('/lembar_instrument_monitoring', LembarInstrumentMonitoringController::class);
    Route::post('/filter',[LembarInstrumentMonitoringController::class, 'filter'])->name('filter');

    Route::post('cetak_pdf', [LembarInstrumentMonitoringController::class, 'cetak_pdf'])->name('cetak_pdf');
});