<?php

use App\Http\Controllers\ApiWaController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LanguageController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\AppsController;
use App\Http\Controllers\UserInterfaceController;
use App\Http\Controllers\CardsController;
use App\Http\Controllers\ComponentsController;
use App\Http\Controllers\ExtensionController;
use App\Http\Controllers\PageLayoutController;
use App\Http\Controllers\FormsController;
use App\Http\Controllers\TableController;
use App\Http\Controllers\PagesController;
use App\Http\Controllers\MiscellaneousController;
use App\Http\Controllers\AuthenticationController;
use App\Http\Controllers\BantaranSungaiController;
use App\Http\Controllers\BroadcastPeringatanController;
use App\Http\Controllers\ChartsController;
use App\Http\Controllers\DashboardCommandCenter;
use App\Http\Controllers\DeviceController;
use App\Http\Controllers\GroupController;
use App\Http\Controllers\HasilPerhitunganController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\JabatanController;
use App\Http\Controllers\KetinggianAirController;
use App\Http\Controllers\KontakController;
use App\Http\Controllers\LevelController;
use App\Http\Controllers\PangkatController;
use App\Http\Controllers\PegawaiController;
use App\Http\Controllers\PengaturanBantaranSungaiController;
use App\Http\Controllers\PenggunaController;
use App\Http\Controllers\StatusSiagaController;
use Illuminate\Broadcasting\BroadcastController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use PHPUnit\TextUI\XmlConfiguration\Group;

/*
|--------------------------------------------------------------------------
| 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('/',[berandacontroller::class,'index']);

Route::get("/",[HomeController::class,'index']);
Route::get("/check",[HomeController::class,'check']);
Route::get("/lupa_password",[HomeController::class,'lupa_password']);
Route::put("/simpan_reset_password",[HomeController::class,'simpan_reset_password']);
Route::get("/reset_password/{id}/{token}",[HomeController::class,'reset_password']);
Route::post("/forgot",[HomeController::class,'forgot']);

// Main Page Route
Route::group(["middleware" => "auth_not_login"],function() {
    Route::get('/login',[AuthenticationController::class, 'login_cover'])->name('auth-login-cover');
    Route::post("masuk",[AuthenticationController::class,'masuk']);
});

Route::get("/keluar",[AuthenticationController::class,'keluar']);


/* Route Dashboards */
Route::group(['prefix' => 'dashboard','middleware' => 'auth_admin'], function () {
    Route::get('analytics', [DashboardController::class, 'dashboardAnalytics'])->name('dashboard-analytics');
    Route::get("refresh_dashboard",function() {
        return redirect()->to("dashboard/analytics")->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::get("refresh_dashboard/{id}",[DashboardController::class,'refresh_dashboard']);
});
/* Route Dashboards */

// level
Route::group(['prefix' => 'level','middleware' => 'auth_admin'],function() {
    Route::get("index",[LevelController::class,'index']);
    Route::get("ambil_data",[LevelController::class,'ambil_data']);
    Route::post("add_level",[LevelController::class,'store']);
    Route::put("edit_level",[LevelController::class,'edit_level']);
    Route::delete("hapus_level",[LevelController::class,'hapus_level']);
});

// pengguna
Route::group(['prefix' => 'pengguna','middleware' => 'auth_admin'],function() {
    Route::get("index",[PenggunaController::class,'index']);
    Route::get("ambil",[PenggunaController::class,'ambil']);
    Route::get("edit_show/{id}",[PenggunaController::class,'edit_show']);
    Route::get("created",[PenggunaController::class,'created']);
    Route::get("ambil_data",[PenggunaController::class,'ambil_data']);
    Route::post("add_pengguna",[PenggunaController::class,'store']);
    Route::put("edit_pengguna",[PenggunaController::class,'update']);
    Route::delete("hapus_pengguna",[PenggunaController::class,'destroy']);
    Route::put("ganti_profile",[PenggunaController::class,'ganti_profile']);
    Route::put("ganti_password",[PenggunaController::class,'ganti_password']);
});

// jabatan
Route::group(['prefix' => 'jabatan','middleware' => 'auth_admin'],function() {
    Route::get("index",[JabatanController::class,'index']);
    Route::get("tambah_jabatan",[JabatanController::class,'tambah_jabatan']);
    Route::get("jabat/{id}",[JabatanController::class,'jabat']);
    Route::get("index",[JabatanController::class,'index']);
    Route::get("ambil_data",[JabatanController::class,'ambil_data']);
    Route::post("add_jabatan",[JabatanController::class,'store']);
    Route::put("edit_jabatan",[JabatanController::class,'update']);
    Route::delete("hapus_jabatan",[JabatanController::class,'destroy']);
});

// pangkat
Route::group(['prefix' => 'pangkat','middleware' => 'auth_admin'],function() {
    Route::get("index",[PangkatController::class,'index']);
    Route::get("created_pangkat",[PangkatController::class,'created_pangkat']);
    Route::get("ambil_data",[PangkatController::class,'ambil_data']);
    Route::get("edits_pangkat/{id}",[PangkatController::class,'edits_pangkat']);
    Route::post("add_pangkat",[PangkatController::class,'store']);
    Route::put("edit_pangkat",[PangkatController::class,'update']);
    Route::delete("hapus_pangkat",[PangkatController::class,'destroy']);
});

// pegawai
Route::group(['prefix' => 'pegawai','middleware' => 'auth_admin'],function() {
    Route::get("ambil",[PegawaiController::class,'ambil']);
    Route::get("index",[PegawaiController::class,'index']);
    Route::get("tambah_data",[PegawaiController::class,'tambah_data']);
    Route::get("edit_pegawai/{id}",[PegawaiController::class,'edit_pegawai']);
    Route::get("ambil_data",[PegawaiController::class,'ambil_data']);
    Route::post("add_pegawai",[PegawaiController::class,'store']);
    Route::delete("hapus_pegawai",[PegawaiController::class,'destroy']);
    Route::put("edit_pegawai",[PegawaiController::class,'update']);
});

// group
Route::group(['prefix' => 'group','middleware' => 'auth_admin'],function() {
    Route::get("index",[GroupController::class,'index']);
    Route::get("create",[GroupController::class,'create']);
    Route::get("edits/{id}",[GroupController::class,'edits']);
    Route::get("ambil_data",[GroupController::class,'ambil_data']);
    Route::get("detail_group/{id}",[GroupController::class,'show']);
    Route::get("detail_data_group/{id}",[GroupController::class,'detail_data_group']);
    Route::post("add_group",[GroupController::class,'store']);
    Route::post("add_detail_group",[GroupController::class,'add_detail_group']);
    Route::put("edit_group",[GroupController::class,'update']);
    Route::put("edit_detail_group",[GroupController::class,'edit_detail_group']);
    Route::delete("hapus_group",[GroupController::class,'destroy']);
    Route::delete("hapus_detail_group",[GroupController::class,'hapus_detail_group']);
});

//wa
Route::group(['prefix' => 'wa','middleware' => 'auth_admin'],function() {
    Route::get("index",[ApiWaController::class,'index']);
    Route::put("update_token",[ApiWaController::class,'update']);
});

// kontak
Route::group(['prefix' => 'kontak','middleware' => 'auth_admin'],function() {
    Route::get('index',[KontakController::class,'index']);
});

// ketinggian air
Route::group(["prefix" => "ketinggian_air",'middleware' => 'auth_admin'],function() {
    Route::get("/ambil",[KetinggianAirController::class,'ambil']);
    Route::get("/index",[KetinggianAirController::class,'index']);
});

// hasil perhitungan
Route::group(["prefix" => "hasil_pehitungan",'middleware' => 'auth_admin'],function() {
    Route::get("/index",[HasilPerhitunganController::class,'index']);
    Route::get("/perhitungan_bantaran_sungai",[HasilPerhitunganController::class,'perhitungan_bantaran_sungai']);
    Route::get("/ambil_perhitungan_bantaran",[HasilPerhitunganController::class,'ambil_perhitungan_bantaran']);
    Route::get("/ambil",[HasilPerhitunganController::class,'ambil']);
    Route::get("/get",[HasilPerhitunganController::class,'get']);
    Route::get('/semua_data',[HasilPerhitunganController::class,'semua_data']);
});

// hasil perhitungan
Route::group(["prefix" => "broadcast_peringatan",'middleware' => 'auth_admin'],function() {
    Route::get("/index",[BroadcastPeringatanController::class,'index']);
    Route::get("/tambah_broadcast",[BroadcastPeringatanController::class,'tambah_broadcast']);
    Route::get("/detail/{id_pesan}",[BroadcastPeringatanController::class,'detail']);
    Route::get("/ambil_group_penerima/{id_pesan}",[BroadcastPeringatanController::class,'ambil_group_penerima']);
    Route::get("/penerima_pesan/{id_group}/{id_pesan}",[BroadcastPeringatanController::class,'penerima_pesan']);
    Route::get("/penerima_pesan_pengguna/{id_group}/{id_pesan}",[BroadcastPeringatanController::class,'penerima_pesan_pengguna']);
    Route::get("/ambil",[BroadcastPeringatanController::class,'ambil']);
    
    Route::delete("/deleted_soft",[BroadcastPeringatanController::class,'deleted_soft']);
    Route::get("ambil_siaga/{id}",[BroadcastPeringatanController::class,'ambil_siaga']);
    Route::get("create",function(){
        return redirect()->to("broadcast_peringatan/index")->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::post("/create",[BroadcastPeringatanController::class,'store']);
});

// laporan ketinggian air
Route::group(["prefix" => "laporan_ketinggian_air",'middleware' => 'auth_admin'],function() {
    Route::get("/index",[KetinggianAirController::class,'laporan_ketinggian_air']);
    Route::get("/ambil_laporan_ketinggian",[KetinggianAirController::class,'ambil_laporan_ketinggian']);
    Route::get("/ambil",[KetinggianAirController::class,'ambil']);
    Route::get("/ambil_search/{device}/{awal}/{akhir}",[KetinggianAirController::class,'ambil_search']);
    Route::get("seacrh",function() {
        return redirect()->to('laporan_ketinggian_air/index')->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::post("/seacrh",[KetinggianAirController::class,'seacrh']);
});

// laporan hasil perhitungan air
Route::group(["prefix" => "laporan_hasil_perhitungan",'middleware' => 'auth_admin'],function() {
    Route::get("/index",[HasilPerhitunganController::class,'laporan_hasil_perhitungan']);
    Route::get("/laporan_bantaran_sungai",[HasilPerhitunganController::class,'laporan_bantaran_sungai']);
    Route::get("/ambil_laporan",[HasilPerhitunganController::class,'ambil_laporan']);
    Route::get("/ambil",[HasilPerhitunganController::class,'ambil']);
    Route::get("/ambil_laporans/{device}/{awal}/{akhir}",[HasilPerhitunganController::class,'ambil_laporans']);
    Route::get("/ambil_perhitungan_bantaran_pencarian/{device}/{awal}/{akhir}",[HasilPerhitunganController::class,'ambil_perhitungan_bantaran_pencarian']);
    Route::get('search',function() {
        return redirect()->to("laporan_hasil_perhitungan/index")->with('error','Terjadi Kesalahan Silahkan Coba Lagi');
    });
    Route::get('cari_bantaran',function() {
        return redirect()->to("laporan_hasil_perhitungan/laporan_bantaran_sungai")->with('error','Terjadi Kesalahan Silahkan Coba Lagi');
    });
    Route::post("/search",[HasilPerhitunganController::class,'search']);
    Route::post("/cari_bantaran",[HasilPerhitunganController::class,'cari_bantaran']);
});

// status siaga
Route::group(["prefix" => "status_siaga",'middleware' => 'auth_admin'],function() {
    Route::get("/ambil",[StatusSiagaController::class,'ambil']);
    Route::get("/index",[StatusSiagaController::class,'index']);
    Route::get("/add_siaga",[StatusSiagaController::class,'create']);
    Route::get("/ambil_device/{id}",[StatusSiagaController::class,'show']);
    Route::get("/edit_siaga/{id}",[StatusSiagaController::class,'edit_siaga']);
    Route::get('tambah_siaga',function(){
        return redirect()->to('status_siaga/add_siaga')->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::post("/tambah_siaga",[StatusSiagaController::class,'store']);
    Route::get('update_siaga',function(){
        return redirect()->to('status_siaga/index')->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::put("/update_siaga",[StatusSiagaController::class,'update']);
    Route::delete("/hapus_siaga",[StatusSiagaController::class,'destroy']);
});

//device
Route::group(["prefix" => "device",'middleware' => 'auth_admin'],function() {
    Route::get("index",[DeviceController::class,'index']);
    Route::get("ambil",[DeviceController::class,'ambil']);
    Route::get("tambah_device",[DeviceController::class,'create']);
    Route::get("edit",[DeviceController::class,'edit']);
    Route::get("show_device/{id}",[DeviceController::class,'show_device']);
    Route::get("edit_device",function() {
        return redirect()->to('device/index')->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::put("edit_device",[DeviceController::class,'update']);
    Route::get("add_device",function() {
        return redirect()->to('device/tambah_device')->with('error',"Terjadi Kesalahan Silahkan Coba Lagi");
    });
    Route::post("add_device",[DeviceController::class,'store']);
    Route::delete("hapus_device",[DeviceController::class,'destroy']);
});

// Route::group(['prefix' => 'page-layouts'], function () {
//     Route::get('collapsed-menu', [PageLayoutController::class, 'layout_collapsed_menu'])->name('layout-collapsed-menu');
//     Route::get('full', [PageLayoutController::class, 'layout_full'])->name('layout-full');
//     Route::get('without-menu', [PageLayoutController::class, 'layout_without_menu'])->name('layout-without-menu');
//     Route::get('empty', [PageLayoutController::class, 'layout_empty'])->name('layout-empty');
//     Route::get('blank', [PageLayoutController::class, 'layout_blank'])->name('layout-blank');
// });

// master data bantaran sungai
Route::group(['prefix' => 'bantaran_sungai','middleware' => 'auth_admin'],function() {
    Route::get("index",[BantaranSungaiController::class,'index']);
    Route::get("add",[BantaranSungaiController::class,'create']);
    Route::get("show/{uuid}",[BantaranSungaiController::class,'show']);
    Route::post("created",[BantaranSungaiController::class,'created']);
    Route::put("update",[BantaranSungaiController::class,'update']);
    Route::delete("delete",[BantaranSungaiController::class,'delete']);
    Route::get("ambil_bantaran_sungai",[BantaranSungaiController::class,'ambil_bantaran_sungai']);
});

// pengaturan bantaran
Route::group(['prefix' => 'pengaturan_bantaran_sungai','middleware' => 'auth_admin'],function() {
    Route::get('index',[PengaturanBantaranSungaiController::class,'index']);
    Route::get('ambil',[PengaturanBantaranSungaiController::class,'ambil']);
    Route::get('ambil_data/{id}',[PengaturanBantaranSungaiController::class,'ambil_data']);
    Route::get('add',[PengaturanBantaranSungaiController::class,'add']);
    Route::get('show/{id}',[PengaturanBantaranSungaiController::class,'show']);
    Route::post('created',[PengaturanBantaranSungaiController::class,'created']);
    Route::put('update',[PengaturanBantaranSungaiController::class,'update']);
    Route::put('normalisasi',[PengaturanBantaranSungaiController::class,'normalisasi']);
    Route::delete('delete',[PengaturanBantaranSungaiController::class,'delete']);
    Route::get('update_status/{id}/{id_data}',[PengaturanBantaranSungaiController::class,'update_status']);
});


Route::group(['prefix' => 'dashboard'],function() {
    Route::get("/grafik_batang",[DashboardCommandCenter::class,'index']);
    Route::get("/grafik_garis",[DashboardCommandCenter::class,'grafik_garis']);
    Route::get("/table_bantaran",[DashboardCommandCenter::class,'table_bantaran']);
    Route::get("/hasil_data",[DashboardCommandCenter::class,'hasil_data']);
    Route::get("/ambil_data",[DashboardCommandCenter::class,'ambil_data']);
    Route::get("/cuaca",[DashboardCommandCenter::class,'cuaca']);
});