<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\PenjajaController as PublicPenjajaController;
use App\Http\Controllers\Admin\PenjajaController as AdminPenjajaController;
use App\Http\Controllers\Admin\IkPenjajaController;
use App\Http\Controllers\Admin\PegawaiPenjajaController;
use App\Http\Controllers\Admin\CetakanPenjajaController;
use App\Http\Controllers\Admin\PtPenjajaController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\PengurusanAdminController;
use App\Http\Controllers\Admin\GambarCarouselController;
use App\Http\Controllers\Admin\PengumumanController;
use App\Http\Controllers\BilPelbagaiController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\DataController;


Route::get('/utama', [AuthenticatedSessionController::class, 'create']);
Route::get('/', function () {
    return view('fahmi');
});

//Route::get('/dashboard', [PublicPenjajaController::class, 'list'])->middleware(['auth', 'verified'])->name('dashboard');
Route::get('/dashboard', [PublicPenjajaController::class, 'list'])->middleware(['auth'])->name('dashboard');


Route::middleware(['auth', 'kakitangan'])->group(function () {
    Route::get('/dashmin/{ctahun?}', [DashboardController::class, 'utama'])->name('admin.dashboard');
    Route::post('/dashmin', [DashboardController::class, 'carianutama'])->name('admin.dashboard');
    Route::get('/lantikan_admin', [PengurusanAdminController::class, 'showList'])->name('admin.lantikan-admin');
    Route::post('/cari_admin', [PengurusanAdminController::class, 'showListCarian'])->name('admin.cariadmin');

    Route::patch('/admin/users/{id}/update-role', [PengurusanAdminController::class, 'updateRole'])
        ->name('admin.users.updateRole')->name('admin.add-admin');
    Route::get('/rem-admin/{nokp}/{keyword?}', [PengurusanAdminController::class, 'removeAdmin'])->name('admin.remove-admin')->where('keyword', '.*');


    
    Route::get('/mohon-penjaja-admin', [AdminPenjajaController::class, 'create'])->name('penjaja-admin-mohon');
    Route::post('/simpan-mohon-penjaja-admin', [AdminPenjajaController::class, 'store'])->name('penjaja-admin-simpan_mohon');

    Route::get('/penjaja-baru', [AdminPenjajaController::class, 'senarai_pt'])->name('pt.baru');
    Route::get('/penjaja-proses', [AdminPenjajaController::class, 'senarai_pt_proses'])->name('pt.proses');
    Route::get('/penjaja-bukafail', [AdminPenjajaController::class, 'senarai_pt_bukafail'])->name('pt.bukafail');
    Route::get('/penjaja-daftarlesen', [AdminPenjajaController::class, 'senarai_pt_daftarlesen'])->name('pt.daftarlesen');
    Route::get('/penjaja-pemeriksaan', [IkPenjajaController::class, 'senarai_ik'])->name('ik.pemeriksaan');
    Route::get('/penjaja-cadangan', [PegawaiPenjajaController::class, 'senarai_cadangan'])->name('pegawai.cadangan');
    Route::get('/penjaja-ulasan-cadangan', [PegawaiPenjajaController::class, 'senarai_ulasan_cadangan'])->name('pegawai.ulasan-cadangan');
    Route::get('/penjaja-mesyuarat', [AdminPenjajaController::class, 'senarai_mesyuarat'])->name('pt.mesyuarat');
    Route::get('/penjaja-minitmesyuarat/{id}', [AdminPenjajaController::class, 'senarai_bawa_mesyuarat'])->name('pt.bawa-mesyuarat');
    Route::get('/penjaja-keputusanmesyuarat', [AdminPenjajaController::class, 'senarai_keputusan_mesyuarat'])->name('pt.keputusanmesyuarat');
    Route::get('/penjaja-keputusanminitmesyuarat/{id}', [AdminPenjajaController::class, 'senarai_keputusan_minit_mesyuarat'])->name('pt.dapat-keputusan-mesyuarat');
    
    Route::get('/penjaja-all', [AdminPenjajaController::class, 'senarai_all'])->name('admin.senarai_all');
    
    Route::get('/penjaja-hutang-lesen', [DashboardController::class, 'senaraiLesenBelumBayar'])->name('pt.lesenhutang');
    Route::get('/penjaja-hutang-lesen-semak', [DashboardController::class, 'semakBayaranLesen'])->name('pt.semaklesenhutang');
    Route::get('/penjaja-dokumen/view/{id}/{filename}', [AdminPenjajaController::class, 'showDokumen'])->name('dokumen.penjaja_view');

    Route::get('/penjaja-baru-papar/{id}', [AdminPenjajaController::class, 'papar'])->name('admin.papar');
    Route::get('/penjaja-papar-map/{id}', [AdminPenjajaController::class, 'papar_map'])->name('admin.papar-map');
    Route::get('/penjaja-papar-dokumen/{id}', [AdminPenjajaController::class, 'papar_dokumen'])->name('admin.papar-dokumen');
    Route::get('/penjaja-papar-proses/{id}', [AdminPenjajaController::class, 'papar_wangproses'])->name('admin.papar-wangproses');
    Route::get('/penjaja-papar-pemeriksaan/{id}', [IkPenjajaController::class, 'papar_pemeriksaan'])->name('admin.papar-pemeriksaan');
    Route::get('/penjaja-papar-lesen/{id}', [AdminPenjajaController::class, 'papar_lesen'])->name('admin.papar-lesen');
    Route::get('/penjaja-papar-pemeriksaan/{id}/{borang_ik_id}', [IkPenjajaController::class, 'papar_pemeriksaan_lepas'])->name('admin.papar-pemeriksaan-lepas');
    Route::get('/penjaja-papar-cadangan-pegawai/{id}/{borang_ik_id}', [PegawaiPenjajaController::class, 'papar_cadangan_pegawai'])->name('admin.papar-cadangan-pegawai');
    Route::get('/penjaja-papar-ulasan-cadangan-pengarah/{id}/{borang_ik_id}', [PegawaiPenjajaController::class, 'papar_ulasan_cadangan_pengarah'])->name('admin.papar-ulasan-cadangan-pengarah');


    Route::post('/simpan_petak', [PtPenjajaController::class, 'simpanPetak'])->name('pt.kemaskini-petak');
    Route::post('/simpan_wangproses', [PtPenjajaController::class, 'simpanWangProses'])->name('pt.simpan-wangproses');
    Route::post('/simpan_nofail', [PtPenjajaController::class, 'simpanNoFail'])->name('pt.simpan-nofail');
    Route::post('/simpan_nolesen', [PtPenjajaController::class, 'simpanNoLesen'])->name('pt.simpan-nolesen');
    Route::post('/hantar_ppk', [PtPenjajaController::class, 'hantarPPK'])->name('pt.hantar-ppk');
    Route::post('/simpan_mesyuarat', [PtPenjajaController::class, 'simpanMesyuarat'])->name('pt.simpan-mesyuarat');
    //==============

    Route::post('/simpan_senarai_bawa_mesyuarat', [PtPenjajaController::class, 'simpanSenaraiBawaMesyuarat'])->name('pt.simpan-senarai-bawa-mesyuarat');
    //=============
    Route::get('/tambah_ke_mesyuarat/{permohonan_id}/{mesyuarat_id}', [PtPenjajaController::class, 'tambahKeMesyuarat'])->name('pt.tambah-ke-mesyuarat');
    Route::get('/buang_dari_mesyuarat/{permohonan_id}/{mesyuarat_id}', [PtPenjajaController::class, 'buangDariMesyuarat'])->name('pt.buang-dari-mesyuarat');
    Route::post('/cetak_lampiran_b', [PtPenjajaController::class, 'exportWord'])->name('pt.cetak-lampiran-b');
    Route::post('/sahkan_senarai', [PtPenjajaController::class, 'sahkanSenarai'])->name('pt.sahkan-senarai');
    Route::post('/simpan_keputusan_mesyuarat', [PtPenjajaController::class, 'simpanKeputusanMesyuarat'])->name('pt.simpan-keputusan-mesyuarat');

    Route::post('/ik-simpan-lokasi', [IkPenjajaController::class, 'simpanLokasi'])->name('ik.simpan-lokasi');
    Route::post('/ik-simpan-ulasan', [IkPenjajaController::class, 'simpanUlasan'])->name('ik.simpan-ulasan');

    Route::post('/pegawai-simpan-cadangan', [PegawaiPenjajaController::class, 'simpan_cadangan'])->name('pegawai.simpan-cadangan');
    Route::post('/pegawai-simpan-ulasan-cadangan', [PegawaiPenjajaController::class, 'simpan_ulasan_cadangan'])->name('pegawai.simpan-ulasan-cadangan');

    Route::get('/penjaja-cetak-pemeriksaan/{id}/{borang_ik_id}', [CetakanPenjajaController::class, 'cetak_pemeriksaan_lepas'])->name('admin.cetak-pemeriksaan-lepas');
    Route::get('/penjaja-cetak-cadangan-pegawai/{id}/{borang_ik_id}', [CetakanPenjajaController::class, 'cetak_cadangan_pegawai'])->name('admin.cetak-cadangan-pegawai');

    //Route::post('/pt/jana-bil-automatik', [BilPelbagaiController::class, 'janaBil'])->name('pt.jana-bil-automatik');
    Route::post('/pt/jana-bil-automatik', [BilPelbagaiController::class, 'doNothing'])->name('pt.jana-bil-automatik');

   /* Route::post('/pt/simpan-bil-manual', [JanaBilController::class, 'simpanManual'])
        ->name('pt.simpan-bil-manual');*/
    
    Route::post('/lesen-penjaja/{permohonan}/no-fail-lesen', [PtPenjajaController::class, 'ajaxUpdateNoFailLesen'])
        ->name('lesen-penjaja.ajax.no-fail-lesen');

});

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::get('/mohon-penjaja', [PublicPenjajaController::class, 'create'])->name('penjaja-mohon');
    Route::post('/simpan-mohon-penjaja', [PublicPenjajaController::class, 'store'])->name('penjaja-simpan_mohon');
    /*Route::get('/mohon-penjaja-upload', [PublicPenjajaController::class, 'create_upload'])->name('penjaja-mohon-upload');
    Route::post('/simpan-mohon-penjaja-upload', [PublicPenjajaController::class, 'store_upload'])->name('penjaja-simpan_mohon_upload');*/

    Route::get('/mohon_hapus/{id}', [PublicPenjajaController::class, 'hapus_permohonan'])->name('delete_mohon');
    Route::get('/mohon_edit/{id}', [PublicPenjajaController::class, 'edit_permohonan'])->name('edit_mohon');

    Route::get('/mohon_papar/{id}', [PublicPenjajaController::class, 'papar_permohonan'])->name('penjaja-mohon-papar');
    Route::post('/mohon_hantar', [PublicPenjajaController::class, 'hantar_permohonan'])->name('penjaja-mohon-hantar');

    /*Route::get('/dokumen/view/{id}/{filename}', [PublicPenjajaController::class, 'showDokumen'])
    ->middleware('auth') // hanya user login boleh access
    ->name('dokumen.view');*/

    Route::get('/profil/stream/{filename}', [ProfileController::class, 'stream'])->name('profil.stream');
    Route::get('/dokumen/stream/{id}/{filename}', [PublicPenjajaController::class, 'stream'])->name('dokumen.stream');
    Route::get('/ik/stream/{id}/{filename}', [IkPenjajaController::class, 'stream'])->name('ik.stream');

    Route::post('/pbtpay/checkout/{modul}/{id}', [PbtpayController::class, 'checkout'])->name('pbtpay.bayar');
    
    Route::post('/pbtpay/callback', function () {
        return view('pbtpay.callback');
    })->name('pbtpay.callback');
    Route::post('/pbtpay/indirect', function () {
        return view('pbtpay.indirect');
    })->name('pbtpay.indirect');

    Route::match(['get', 'post'], '/get-bil', [PtPenjajaController::class, 'searchPelanggan'])->name('get-bilpelbagai');

    Route::get('/get_kawasan', [DataController::class, 'getKawasan']);
    Route::get('/get_taman', [DataController::class, 'getTaman']);
    Route::get('/get_jalan', [DataController::class, 'getJalan']);
    Route::get('/get_penempatan', [DataController::class, 'getPenempatan']);

});

Route::middleware(['auth', 'admin'])->group(function () {
    Route::get('/carousel', [GambarCarouselController::class, 'index'])->name('carousel.index');
    Route::get('/carousel/create', [GambarCarouselController::class, 'create'])->name('carousel.create');
    Route::post('/carousel', [GambarCarouselController::class, 'store'])->name('carousel.store');
    Route::delete('/carousel/{id}', [GambarCarouselController::class, 'destroy'])->name('carousel.destroy');


});

Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
    Route::get('/pengumuman', [PengumumanController::class, 'index'])->name('pengumuman.index');
    Route::get('/pengumuman/create', [PengumumanController::class, 'create'])->name('pengumuman.create');
    Route::post('/pengumuman', [PengumumanController::class, 'store'])->name('pengumuman.store');
    Route::get('/pengumuman/{pengumuman}/edit', [PengumumanController::class, 'edit'])->name('pengumuman.edit');
    Route::put('/pengumuman/{pengumuman}', [PengumumanController::class, 'update'])->name('pengumuman.update');
    Route::delete('/pengumuman/{pengumuman}', [PengumumanController::class, 'destroy'])->name('pengumuman.destroy');
});

require __DIR__.'/auth.php';
