<?php

use Illuminate\Support\Facades\Route;
use App\Http\Middleware\Session;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\Master\InstansiController;
use App\Http\Controllers\Master\ResourceController;
use App\Http\Controllers\Master\TopikController;
use App\Http\Controllers\Master\TabelDataController;
use App\Http\Controllers\Master\TabelDataKolomController;
use App\Http\Controllers\Management\UserController;
use App\Http\Controllers\Management\RoleController;
use App\Http\Controllers\Management\AksesController;
use App\Http\Controllers\Opendata\DatasetController;
use App\Http\Controllers\Opendata\DatasetTambahanController;
use App\Http\Controllers\AjaxController;

Route::get('getPenduduk/{tahun}',[AjaxController::class,'getPenduduk'])->name('getPenduduk');
Route::get('getTimbulan/{tahun}',[AjaxController::class,'getTimbulan'])->name('getTimbulan');
Route::get('getResourceData',[AjaxController::class,'getResourceData'])->name('getResourceData');
Route::get('getResourceDataDashboard/{id}',[AjaxController::class,'getResourceDataDashboard'])->name('getResourceDataDashboard');

Route::name('dashboard.')->prefix('dashboard')->group(function () {
    Route::get('/',[HomeController::class,'dashboard'])->name('dashboard');
    Route::get('/dataset/{alias}',[HomeController::class,'dataset'])->name('dataset');
    Route::get('/dataset/resource/{id}',[HomeController::class,'resource'])->name('resource');
    Route::get('/dataset/resource/instansi/{instansi_id}/{id}',[HomeController::class,'resource_instansi'])->name('resource_instansi');
    Route::get('/grid',[HomeController::class,'grid'])->name('grid');
    Route::get('/grid/tabel',[HomeController::class,'gridTabel'])->name('gridTabel');
    Route::get('/gridResource',[HomeController::class,'gridResource'])->name('gridResource');
    Route::get('/gridInstansiUtama',[HomeController::class,'gridInstansiUtama'])->name('gridInstansiUtama');
    Route::get('/gridInstansiTambahan',[HomeController::class,'gridInstansiTambahan'])->name('gridInstansiTambahan');
    Route::get('/datasetGrid/{alias}',[HomeController::class,'datasetGrid'])->name('datasetGrid');
    Route::get('/api/chart/{template_id}/{instansi_id}',[HomeController::class,'apiChart'])->name('apiChart');
});


Route::name('opendata.')->prefix('opendata')->group(function () {
    Route::name('dataset.')->prefix('dataset')->group(function () {
        Route::resource('/',DatasetController::class);
        Route::get('grid',[DatasetController::class,'grid'])->name('grid');
        Route::get('gridDetail',[DatasetController::class,'gridDetail'])->name('gridDetail');
        Route::get('update/{id?}',[DatasetController::class,'update'])->name('update');
        Route::get('view/{id?}',[DatasetController::class,'view'])->name('view');
        Route::get('delete/{id?}',[DatasetController::class,'delete'])->name('delete');
        Route::get('aktif/{id?}',[DatasetController::class,'aktif'])->name('aktif');
        Route::post('verifikasi/{id?}',[DatasetController::class,'verifikasi'])->name('verifikasi');
        Route::get('generateTemplate/{id?}',[DatasetController::class,'generateTemplate'])->name('generateTemplate');
        // Route::get('download/{id?}',[DatasetController::class,'download'])->name('download');
    });

    Route::name('dataset-tambahan.')->prefix('dataset-tambahan')->group(function () {
        Route::resource('/',DatasetTambahanController::class);
        Route::get('grid',[DatasetTambahanController::class,'grid'])->name('grid');
        Route::get('gridDetail',[DatasetTambahanController::class,'gridDetail'])->name('gridDetail');
        Route::get('update/{id?}',[DatasetTambahanController::class,'update'])->name('update');
        Route::get('view/{id?}',[DatasetTambahanController::class,'view'])->name('view');
        Route::get('delete/{id?}',[DatasetTambahanController::class,'delete'])->name('delete');
        Route::get('aktif/{id?}',[DatasetTambahanController::class,'aktif'])->name('aktif');
        Route::post('verifikasi/{id?}',[DatasetTambahanController::class,'verifikasi'])->name('verifikasi');
    });
});

Route::name('master.')->prefix('master')->group(function () {

    Route::name('tabel-data.')->prefix('tabel-data')->group(function () {

        Route::resource('/',TabelDataController::class);
        Route::get('grid',[TabelDataController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[TabelDataController::class,'update'])->name('update');

        Route::name('kolom.')->prefix('kolom/{id?}')->group(function () {
            Route::resource('/',TabelDataKolomController::class);
            Route::get('/grid',[TabelDataKolomController::class,'grid'])->name('grid');
            Route::get('/update/{kolomId?}',[TabelDataKolomController::class,'update'])->name('update');
        });

    });

    Route::name('resource.')->prefix('resource')->group(function () {
        Route::resource('/',ResourceController::class);
        Route::get('grid',[ResourceController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[ResourceController::class,'update'])->name('update');
        Route::post('changeShowDashboard',[ResourceController::class,'changeShowDashboard'])->name('changeShowDashboard');
    });

    Route::name('topik.')->prefix('topik')->group(function () {
        Route::resource('/',TopikController::class);
        Route::get('grid',[TopikController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[TopikController::class,'update'])->name('update');
    });

    Route::name('instansi.')->prefix('instansi')->group(function () {
        Route::resource('/',InstansiController::class);
        Route::get('grid',[InstansiController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[InstansiController::class,'update'])->name('update');
        Route::get('delete/{id?}',[InstansiController::class,'delete'])->name('delete');
    });
});

Route::name('management.')->prefix('management')->group(function () {
    Route::name('user.')->prefix('user')->group(function () {
        Route::resource('/',UserController::class);
        Route::get('grid',[UserController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[UserController::class,'update'])->name('update');
        Route::get('delete/{id?}',[UserController::class,'delete'])->name('delete');
        Route::get('forcelogin/{id?}',[UserController::class,'forcelogin'])->name('forcelogin');
    });

    Route::name('role.')->prefix('role')->group(function () {
        Route::resource('/',RoleController::class);
        Route::get('grid',[RoleController::class,'grid'])->name('grid');
        Route::get('update/{id?}',[RoleController::class,'update'])->name('update');
        Route::get('delete/{id?}',[RoleController::class,'delete'])->name('delete');

        Route::name('akses.')->prefix('akses')->group(function () {
            Route::resource('/',AksesController::class);
            Route::get('{id}/edit',[AksesController::class,'edit'])->name('edit');
        });
    }); 
});