<?php

use App\Http\Controllers\BelajarController;
use App\Http\Controllers\ChatController;
use App\Http\Controllers\GuruController;
use App\Http\Controllers\JadwalbkController;
use App\Http\Controllers\JadwaljiwaController;
use App\Http\Controllers\KarierController;
use App\Http\Controllers\KuesionerController;
use App\Http\Controllers\PelanggaranController;
use App\Http\Controllers\PengaduanController;
use App\Http\Controllers\PengunduranController;
use App\Http\Controllers\PribasosController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RekapKuesionerController;
use App\Http\Controllers\RiwayatController;
use App\Http\Controllers\RujukanController;
use App\Http\Controllers\SiswaController;
use App\Http\Controllers\SpController;
use App\Http\Controllers\SpesialisController;
use App\Http\Controllers\PindahSekolahController;
use App\Http\Controllers\PsikiaterController;
use App\Http\Controllers\PsikologController;
use Illuminate\Support\Facades\Route;

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

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

Route::middleware('auth')->group(function () {
    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');
});

Route::middleware('auth')->group(function () {
    Route::get('/guru', [GuruController::class, 'index'])->name('guru.index');
    Route::get('/guru/create', [GuruController::class, 'create'])->name('guru.create');
    Route::post('/guru', [GuruController::class, 'store'])->name('guru.store');
    Route::get('/guru/{id_guru}/edit', [GuruController::class, 'edit'])->name('guru.edit');
    Route::match(['put', 'patch'], '/guru/{id_guru}', [GuruController::class, 'update'])->name('guru.update');
    Route::delete('/guru/{id_guru}', [GuruController::class, 'destroy'])->name('guru.destroy');
    Route::get('/guru/export', [GuruController::class, 'export'])->name('guru.export');
    Route::post('/guru/import', [GuruController::class, 'import'])->name('guru.import');
});

Route::middleware('auth')->group(function () {
    route::get('/siswa', [SiswaController::class, 'index'])->name('siswa.index');
    route::get('/siswa/create', [SiswaController::class, 'create'])->name('siswa.create');
    Route::post('/siswa', [SiswaController::class, 'store'])->name('siswa.store');
    Route::get('/siswa/{id_siswa}/edit', [SiswaController::class, 'edit'])->name('siswa.edit');
    Route::match(['put', 'patch'], '/siswa/{id_siswa}', [SiswaController::class, 'update'])->name('siswa.update');
    Route::delete('/siswa/{id_siswa}', [SiswaController::class, 'destroy'])->name('siswa.destroy');
    Route::get('/siswa/export', [SiswaController::class, 'export'])->name('siswa.export');
    Route::post('/siswa/import', [SiswaController::class, 'import'])->name('siswa.import');
    Route::get('/siswa/{id_siswa}', [SiswaController::class, 'show'])->name('siswa.show');
});

Route::middleware('auth')->group(function () {
    Route::get('/spesialis', [SpesialisController::class, 'index'])->name('spesialis.index');
    Route::get('/spesialis/create', [SpesialisController::class, 'create'])->name('spesialis.create');
    Route::post('/spesialis', [SpesialisController::class, 'store'])->name('spesialis.store');
    Route::get('/spesialis/{id_spesialis_kejiwaan}/edit', [SpesialisController::class, 'edit'])->name('spesialis.edit');
    Route::match(['put', 'patch'], '/spesialis/{id_spesialis_kejiwaan}', [SpesialisController::class, 'update'])->name('spesialis.update');
    Route::delete('/spesialis/{id_spesialis_kejiwaan}', [SpesialisController::class, 'destroy'])->name('spesialis.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/jadwalbk', [JadwalbkController::class, 'index'])->name('jadwalbk.index');
    Route::get('/jadwalbk/create', [JadwalbkController::class, 'create'])->name('jadwalbk.create');
    Route::post('/jadwalbk', [JadwalbkController::class, 'store'])->name('jadwalbk.store');
    Route::get('/jadwalbk/{id_jadwal}/edit', [JadwalbkController::class, 'edit'])->name('jadwalbk.edit');
    Route::match(['put', 'patch'], '/jadwalbk/{id_jadwal}', [JadwalbkController::class, 'update'])->name('jadwalbk.update');
    Route::delete('/jadwalbk/{id_jadwal}', [JadwalbkController::class, 'destroy'])->name('jadwalbk.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/jadwaljiwa', [JadwaljiwaController::class, 'index'])->name('jadwaljiwa.index');
    Route::get('/jadwaljiwa/create', [JadwaljiwaController::class, 'create'])->name('jadwaljiwa.create');
    Route::post('/jadwaljiwa', [JadwaljiwaController::class, 'store'])->name('jadwaljiwa.store');
    Route::get('/jadwaljiwa/{id_jadwaljiwa}/edit', [JadwaljiwaController::class, 'edit'])->name('jadwaljiwa.edit');
    Route::match(['put', 'patch'], '/jadwaljiwa/{id_jadwaljiwa}', [JadwaljiwaController::class, 'update'])->name('jadwaljiwa.update');
    Route::delete('/jadwaljiwa/{id_jadwaljiwa}', [JadwaljiwaController::class, 'destroy'])->name('jadwaljiwa.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/pelanggaran', [PelanggaranController::class, 'index'])->name('pelanggaran.index');
    Route::get('/pelanggaran/create', [PelanggaranController::class, 'create'])->name('pelanggaran.create');
    Route::post('/pelanggaran', [PelanggaranController::class, 'store'])->name('pelanggaran.store');
    Route::get('/pelanggaran/{id_pelanggaran}/edit', [PelanggaranController::class, 'edit'])->name('pelanggaran.edit');
    Route::match(['put', 'patch'], '/pelanggaran/{id_pelanggaran}', [PelanggaranController::class, 'update'])->name('pelanggaran.update');
    Route::delete('/pelanggaran/{id_pelanggaran}', [PelanggaranController::class, 'destroy'])->name('pelanggaran.destroy');
    Route::get('/pelanggaran/{id_pelanggaran}/detail', [PelanggaranController::class, 'show'])->name('pelanggaran.detail');
});

Route::middleware('auth')->group(function () {
    Route::get('/riwayat', [RiwayatController::class, 'index'])->name('riwayat.index');
    Route::get('/riwayat/create', [RiwayatController::class, 'create'])->name('riwayat.create');
    Route::post('/riwayat', [RiwayatController::class, 'store'])->name('riwayat.store');
    Route::get('/riwayat/{id_riwayat_bk}/edit', [RiwayatController::class, 'edit'])->name('riwayat.edit');
    Route::match(['put', 'patch'], '/riwayat/{id_riwayat_bk}', [RiwayatController::class, 'update'])->name('riwayat.update');
    Route::delete('/riwayat/{id_riwayat_bk}', [RiwayatController::class, 'destroy'])->name('riwayat.destroy');
    Route::get('/riwayat/jenis/{jenis}', [RiwayatController::class, 'show'])->name('riwayat.jenis');
    Route::get('/riwayat/print', [RiwayatController::class, 'print'])->name('riwayat.print');
});

Route::middleware('auth')->group(function () {
    Route::get('/pribasos', [PribasosController::class, 'index'])->name('pribasos.index');
    Route::get('/pribasos/create', [PribasosController::class, 'create'])->name('pribasos.create');
    Route::post('/pribasos', [PribasosController::class, 'store'])->name('pribasos.store');
    Route::get('/pribasos/{id_pribasos}/edit', [PribasosController::class, 'edit'])->name('pribasos.edit');
    Route::match(['put', 'patch'], '/pribasos/{id_pribasos}', [PribasosController::class, 'update'])->name('pribasos.update');
    Route::delete('/pribasos/{id_pribasos}', [PribasosController::class, 'destroy'])->name('pribasos.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/belajar', [BelajarController::class, 'index'])->name('belajar.index');
    Route::get('/belajar/create', [BelajarController::class, 'create'])->name('belajar.create');
    Route::post('/belajar', [BelajarController::class, 'store'])->name('belajar.store');
    Route::get('/belajar/{id_belajar}/edit', [BelajarController::class, 'edit'])->name('belajar.edit');
    Route::match(['put', 'patch'], '/belajar/{id_belajar}', [BelajarController::class, 'update'])->name('belajar.update');
    Route::delete('/belajar/{id_belajar}', [BelajarController::class, 'destroy'])->name('belajar.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/karier', [KarierController::class, 'index'])->name('karier.index');
    Route::get('/karier/create', [KarierController::class, 'create'])->name('karier.create');
    Route::post('/karier', [KarierController::class, 'store'])->name('karier.store');
    Route::get('/karier/{id_karier}/edit', [KarierController::class, 'edit'])->name('karier.edit');
    Route::match(['put', 'patch'], '/karier/{id_karier}', [KarierController::class, 'update'])->name('karier.update');
    Route::delete('/karier/{id_karier}', [KarierController::class, 'destroy'])->name('karier.destroy');
    Route::get('/karier/print', [KarierController::class, 'print'])->name('karier.print');
});

Route::middleware('auth')->group(function () {
    Route::get('/pengaduan', [PengaduanController::class, 'index'])->name('pengaduan.index');
    Route::get('/pengaduan/create', [PengaduanController::class, 'create'])->name('pengaduan.create');
    Route::post('/pengaduan', [PengaduanController::class, 'store'])->name('pengaduan.store');
    Route::delete('/pengaduan/{id_pengaduan_bk}', [PengaduanController::class, 'destroy'])->name('pengaduan.destroy');
    Route::match(['put', 'patch'], '/pengaduan/{id_pengaduan_bk}', [PengaduanController::class, 'update'])->name('pengaduan.update');
    Route::patch('/pengaduan/{id_pengaduan_bk}/verifikasi', [PengaduanController::class, 'verify'])->name('pengaduan.verify');
    Route::patch('/pengaduan/{id_pengaduan_bk}/unverifikasi', [PengaduanController::class, 'unverify'])->name('pengaduan.unverify');
    Route::get('/pengaduan/jenis/{jenis}', [PengaduanController::class, 'show'])->name('pengaduan.jenis');
});

Route::middleware('auth')->group(function () {
    Route::get('tindak-lanjut/sp', [SpController::class, 'index'])->name('tindak-lanjut.sp.index');
    Route::post('tindak-lanjut/sp', [SpController::class, 'store'])->name('tindak-lanjut.sp.store');
    Route::match(['put', 'patch'], 'tindak-lanjut/sp/{id_sp}', [SpController::class, 'update'])->name('tindak-lanjut.sp.update');
    Route::delete('tindak-lanjut/sp/{id_sp}', [SpController::class, 'destroy'])->name('tindak-lanjut.sp.destroy');
    Route::get('tindak-lanjut/sp/print/{id_sp}', [SpController::class, 'print'])->name('tindak-lanjut.sp.print');
});

Route::middleware('auth')->group(function () {
    Route::get('tindak-lanjut/pindah-sekolah', [PindahSekolahController::class, 'index'])->name('tindak-lanjut.pindah-sekolah.index');
    Route::post('tindak-lanjut/pindah-sekolah', [PindahSekolahController::class, 'store'])->name('tindak-lanjut.pindah-sekolah.store');
    Route::match(['put', 'patch'], 'tindak-lanjut/pindah-sekolah/{id_pindah_sekolah}', [PindahSekolahController::class, 'update'])->name('tindak-lanjut.pindah-sekolah.update');
    Route::delete('tindak-lanjut/pindah-sekolah/{id_pindah_sekolah}', [PindahSekolahController::class, 'destroy'])->name('tindak-lanjut.pindah-sekolah.destroy');
    Route::get('tindak-lanjut/pindah-sekolah/print/{id_pindah_sekolah}', [PindahSekolahController::class, 'print'])->name('tindak-lanjut.pindah-sekolah.print');
});

Route::middleware('auth')->group(function () {
    Route::get('tindak-lanjut/pengunduran-diri', [PengunduranController::class, 'index'])->name('tindak-lanjut.pengunduran-diri.index');
    Route::post('tindak-lanjut/pengunduran-diri', [PengunduranController::class, 'store'])->name('tindak-lanjut.pengunduran-diri.store');
    Route::match(['put', 'patch'], 'tindak-lanjut/pengunduran-diri/{id_pengunduran}', [PengunduranController::class, 'update'])->name('tindak-lanjut.pengunduran-diri.update');
    Route::delete('tindak-lanjut/pengunduran-diri/{id_pengunduran}', [PengunduranController::class, 'destroy'])->name('tindak-lanjut.pengunduran-diri.destroy');
    Route::get('tindak-lanjut/pengunduran-diri/print/{id_pengunduran}', [PengunduranController::class, 'print'])->name('tindak-lanjut.pengunduran-diri.print');
});

Route::middleware('auth')->group(function () {
    Route::get('tindak-lanjut/rujukan-spesialis', [RujukanController::class, 'index'])->name('tindak-lanjut.rujukan-spesialis.index');
    Route::post('tindak-lanjut/rujukan-spesialis', [RujukanController::class, 'store'])->name('tindak-lanjut.rujukan-spesialis.store');
    Route::match(['put', 'patch'], 'tindak-lanjut/rujukan-spesialis/{id_rujukan}', [RujukanController::class, 'update'])->name('tindak-lanjut.rujukan-spesialis.update');
    Route::delete('tindak-lanjut/rujukan-spesialis/{id_rujukan}', [RujukanController::class, 'destroy'])->name('tindak-lanjut.rujukan-spesialis.destroy');
    Route::get('tindak-lanjut/rujukan-spesialis/komponen/print/{id_rujukan}', [RujukanController::class, 'print'])->name('tindak-lanjut.rujukan-spesialis.komponen.print');
    Route::get('tindak-lanjut/rujukan-spesialis/jawaban/{siswa_id}', function ($siswaId) {
        $jawaban = \App\Models\JawabanKuesioner::where('siswa_id', $siswaId)
                    ->pluck('nilai', 'pertanyaan_id'); // hasilnya: [pertanyaan_id => nilai]
        return response()->json($jawaban);
    })->name('tindak-lanjut.rujukan-spesialis.jawaban');
});

Route::middleware('auth')->group(function () {
    Route::get('psikolog', [PsikologController::class, 'index'])->name('psikolog.index');
    Route::post('psikolog', [PsikologController::class, 'store'])->name('psikolog.store');
    Route::match(['put', 'patch'], '/psikolog/{id_psikolog}', [PsikologController::class, 'update'])->name('psikolog.update');
    Route::patch('psikolog/{id_psikolog}/verifikasi', [PsikologController::class, 'verify'])->name('psikolog.verify');
    Route::patch('psikolog/{id_psikolog}/unverifikasi', [PsikologController::class, 'unverify'])->name('psikolog.unverify');
    Route::delete('psikolog/{id_psikolog}', [PsikologController::class, 'destroy'])->name('psikolog.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('psikiater', [PsikiaterController::class, 'index'])->name('psikiater.index');
    Route::post('psikiater', [PsikiaterController::class, 'store'])->name('psikiater.store');
    Route::match(['put', 'patch'], '/psikiater/{id_psikiater}', [PsikiaterController::class, 'update'])->name('psikiater.update');
    Route::patch('psikiater/{id_psikiater}/verifikasi', [PsikiaterController::class, 'verify'])->name('psikiater.verify');
    Route::patch('psikiater/{id_psikiater}/unverifikasi', [PsikiaterController::class, 'unverify'])->name('psikiater.unverify');
    Route::delete('psikiater/{id_psikiater}', [PsikiaterController::class, 'destroy'])->name('psikiater.destroy');
});

Route::middleware('auth')->group(function () {
    Route::get('/kuesioner', [KuesionerController::class, 'index'])->name('kuesioner.index');
    Route::post('/kuesioner', [KuesionerController::class, 'store'])->name('kuesioner.store');
});

Route::middleware('auth')->group(function () {
    Route::get('/rekap-kuesioner', [RekapKuesionerController::class, 'index'])->name('rekap-kuesioner.index');
    Route::get('/rekap-kuesioner/detail/{id_siswa}', [RekapKuesionerController::class, 'detail'])
        ->name('rekap-kuesioner.detail');
});

Route::middleware(['auth', 'role:Siswa|GuruBK|Admin|Spesialis'])->group(function () {
    Route::get('/chat/{receiver}', [ChatController::class, 'index'])->name('chat.index');
    Route::post('/chat/send', [ChatController::class, 'store'])->name('chat.store');
    Route::get('/chat/{receiverId?}', [ChatController::class, 'index'])->name('chat.index');

});




require __DIR__ . '/auth.php';
