<?php

use App\Http\Controllers\Authentication\LoginController;
use App\Http\Controllers\GetDataController;
use App\Http\Controllers\User\BukuAjarController;
use App\Http\Controllers\User\FasilitasController;
use App\Http\Controllers\User\KekayaanIntelController;
use App\Http\Controllers\User\KontrakKerjaController;
use App\Http\Controllers\User\PenelitianSumberDanaController;
use App\Http\Controllers\User\PenelitiAsingController;
use App\Http\Controllers\User\PenyelenggaraanSeminarController;
use App\Http\Controllers\User\PublikasiArtikelController;
use App\Http\Controllers\User\PublikasiJurnalController;
use App\Http\Controllers\User\StafPendukungController;
use App\Http\Controllers\User\UnitBisnisController;

use App\Http\Controllers\Admin\BidangPenelitianController as AdminBidangPenelitianController;
use App\Http\Controllers\Admin\TujuanSosialController as AdminTujuanSosialController;
use App\Http\Controllers\Admin\BidangKepakaranController as AdminBidangKepakaranController;
use App\Http\Controllers\Admin\UserController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| 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::group(['namespace' => 'Authentication'], function () {
    Route::get('sso/{email}/{sessionid}', [LoginController::class, 'sso']);
});

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

    Route::name('admin.')->prefix('admin')->middleware(['role:admin'])->group(function () {
        Route::resource('/bidangpenelitian', AdminBidangPenelitianController::class);
        Route::get('/bidangkategori', [AdminBidangPenelitianController::class, 'bidangkategori'])->name('bidangkategori');
        Route::get('/bidangkategoriedit/{id}', [AdminBidangPenelitianController::class, 'kategoriedit'])->name('bidangkategori.edit');
        Route::post('/bidangkategori-simpan', [AdminBidangPenelitianController::class, 'kategoristore'])->name('bidangkategori.simpan');

        Route::resource('/tujuansosial', AdminTujuanSosialController::class);
        Route::get('/tujuankategori', [AdminTujuanSosialController::class, 'tujuankategori'])->name('tujuankategori');
        Route::get('/tujuankategoriedit/{id}', [AdminTujuanSosialController::class, 'kategoriedit'])->name('tujuankategori.edit');
        Route::post('/tujuankategori-simpan', [AdminTujuanSosialController::class, 'kategoristore'])->name('tujuankategori.simpan');

        Route::resource('/bidangkepakaran', AdminBidangKepakaranController::class);
        Route::get('/kepakarankategori', [AdminBidangKepakaranController::class, 'kepakarankategori'])->name('kepakarankategori');
        Route::get('/kepakarankategoriedit/{id}', [AdminBidangKepakaranController::class, 'kategoriedit'])->name('kepakarankategori.edit');
        Route::post('/kepakarankategori-simpan', [AdminBidangKepakaranController::class, 'kategoristore'])->name('kepakarankategori.simpan');

        Route::get('/tujuankategori', [AdminTujuanSosialController::class, 'tujuankategori'])->name('tujuankategori');
        Route::resource('/users', UserController::class);
        Route::post('/user/remove-role', [UserController::class, 'removeRole'])->name('remove-role');
        Route::post('/user/add-role', [UserController::class, 'addRole'])->name('add-role');
    });

    Route::group(['middleware' => ['role:admin|user']], function () {

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

        Route::get('/get-biodata', [GetDataController::class, 'getBiodata'])->name('get-biodata');
        // Route::get('/get-row-anggota', [PenelitianSumberDanaController::class, 'getRowAnggota'])->name('get-row-anggota');
        Route::get('/get-children', [GetDataController::class, 'getChildren'])->name('get-children');

        Route::resource('/bukuajar', BukuAjarController::class);
        Route::resource('/fasilitas', FasilitasController::class);
        Route::resource('/kekayaanintelek', KekayaanIntelController::class);
        Route::resource('/kontrakkerja', KontrakKerjaController::class);

        Route::resource('/penelitiansumber', PenelitianSumberDanaController::class);
        Route::get('/penelitiansumber/next-form/{id}', [PenelitianSumberDanaController::class, 'nextForm'])->name('penelitiansumber.next-form');
        Route::get('/penelitiansumber/edit-anggota/{id}', [PenelitianSumberDanaController::class, 'editAnggota'])->name('penelitiansumber.edit-anggota');
        Route::post('/penelitiansumber/simpan-anggota/{id}', [PenelitianSumberDanaController::class, 'simpanAnggota'])->name('penelitiansumber.simpan-anggota');
        Route::post('/penelitiansumber/delete-anggota', [PenelitianSumberDanaController::class, 'deleteAnggota'])->name('penelitiansumber.delete-anggota');
        Route::post('/penelitiansumber/cek-simpan-anggota', [PenelitianSumberDanaController::class, 'cekSimpanAnggota'])->name('penelitiansumber.cek-simpan-anggota');

        Route::resource('/penelitiasing', PenelitiAsingController::class);
        Route::resource('/publikasiartikel', PublikasiArtikelController::class);

        Route::resource('/publikasijurnal', PublikasiJurnalController::class);
        Route::get('/publikasijurnal/next-form/{id}', [PublikasiJurnalController::class, 'nextForm'])->name('publikasijurnal.next-form');
        Route::get('/publikasijurnal/edit-anggota/{id}', [PublikasiJurnalController::class, 'editAnggota'])->name('publikasijurnal.edit-anggota');
        Route::post('/publikasijurnal/simpan-anggota/{id}', [PublikasiJurnalController::class, 'simpanAnggota'])->name('publikasijurnal.simpan-anggota');
        Route::post('/publikasijurnal/delete-anggota', [PublikasiJurnalController::class, 'deleteAnggota'])->name('publikasijurnal.delete-anggota');

        Route::resource('/penyelenggaraseminar', PenyelenggaraanSeminarController::class);
        Route::resource('/stafpendukung', StafPendukungController::class);
        Route::resource('/unitbisnis', UnitBisnisController::class);

    });

});
