<?php

use App\Http\Controllers\AccountController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\ArticleController;
use App\Http\Controllers\BoardingController;
use App\Http\Controllers\BoardingPassController;
use App\Http\Controllers\BookingController;
use App\Http\Controllers\CarController;
use App\Http\Controllers\CheckInController;
use App\Http\Controllers\CheckOutController;
use App\Http\Controllers\CruiseController;
use App\Http\Controllers\CurrencyController;
use App\Http\Controllers\EmployerController;
use App\Http\Controllers\ExpenseReportController;
use App\Http\Controllers\LangController;
use App\Http\Controllers\LocaleController;
use App\Http\Controllers\LocalizationController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\OfficeController;
use App\Http\Controllers\PassengerReportController;
use App\Http\Controllers\PayementController;
use App\Http\Controllers\PortController;
use App\Http\Controllers\RefundController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\RoomController;
use App\Http\Controllers\RoomTypeController;
use App\Http\Controllers\SegmentServiceController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\ShipController;
use App\Http\Controllers\TicketController;
use App\Http\Controllers\TicketReportController;
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\TransferController;
use App\Http\Controllers\UserController;
use Illuminate\Support\Facades\Route;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use App\Http\Controllers\Api\CardController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/

require __DIR__.'/auth.php';
Route::get('api/locales/messages', [LocaleController::class, 'messages'])->name('locales.messages');
Route::group(['middleware' => ['auth']],function(){

    Route::apiResource('transfers',TransferController::class)->middleware('money');
});

// Route::get('tickets/{any}', function($page){return redirect()->to('/');})->where('any', '.*');

// Route::get('{catchall}',function(){
//     dd('dd');
// })

// ->where('catchall', '.*');

Route::group(['middleware' => ['auth:web']],function(){
    Route::apiResource('localization',LangController::class);
    Route::resource('settings', SettingsController::class)->except(['update']);
    Route::put('/settings_update', [SettingsController::class, 'update'])->name('settings.update');
    Route::get('/logs', '\Rap2hpoutre\LaravelLogViewer\LogViewerController@index')->name('logs');
    Route::apiResource('currencies',CurrencyController::class);
    Route::resource('offices',OfficeController::class);
    Route::get('offices/destroy/{id}', [OfficeController::class, 'destroy'])->name('office.destroy');
    Route::get('accounts',[AccountController::class, 'index'])->name('accounts.index');
    Route::put('accounts/{id}',[AccountController::class, 'update']);
    Route::resource('users',UserController::class);
    Route::resource('menu', MenuController::class);
    Route::apiResource('ships',ShipController::class);
    Route::apiResource('services',ServiceController::class)->middleware('money');
    Route::post('menu/order', [MenuController::class, 'order']);
    Route::apiResource('ports',PortController::class);
    Route::post('ports/export', [PortController::class, 'index']);
    Route::apiResource('articles',ArticleController::class);
    Route::apiResource('cars',CarController::class);
    Route::apiResource('room-types',RoomTypeController::class);
    Route::apiResource('rooms',RoomController::class);
    Route::get('boarding-print-{boardingPass}',[BoardingController::class, 'print']);
    Route::get('boarding_pass/print-car/{boardingPass}/{id}',[BoardingController::class, 'printCar']);
    Route::get('boarding-sticker-{bag}',[BoardingController::class, 'sticker']);
});

Route::group(['middleware' => ['auth','can:add_boarding']],function(){
    Route::apiResource('boarding-pass',BoardingController::class)->except(['update']);
    Route::get('boarding-print-{boardingPass}',[BoardingController::class, 'print']);
    Route::get('boarding_pass/print-car/{boardingPass}/{id}',[BoardingController::class, 'printCar']);
    Route::get('boarding-sticker-{bag}',[BoardingController::class, 'sticker']);
});
// Route::get('https://kevalayqueen.com/', function()
// {

// dd('dd');

// });
// Route::group(['domain' => config('app.domain')], function() {

//   dd('dd');

// });
Route::group(['middleware' => 'auth'],function(){
    Route::get('/',[AdminController::class,'dashboard'])->name('dashboard');
    Route::get('/statistic_results',[AdminController::class,'dashboard'])->name('statistic_results');
    Route::apiResource('roles',RoleController::class)->middleware('can:manage_roles');
    Route::get('/notif',[AdminController::class,'notif'])->name('notif');
    Route::post('/mark-notif',[AdminController::class,'markNotif'])->name('mark_notif');
    Route::get('/profile', [AdminController::class, 'profile'])->name('user.profile');
    Route::post('/profile_update', [AdminController::class, 'update'])->name('user.profile_update');
    Route::get('locale/{locale}', [LocalizationController::class, 'setLocale'])->name('locale');
    Route::resource('employers',EmployerController::class);
    Route::apiResource('cruises',CruiseController::class);
    Route::resource('booking',BookingController::class)->middleware('money');
    Route::post('booking/refund/{booking}',[BookingController::class, 'refund'])->name('booking.refund');
    Route::post('booking/refund1/{booking}',[BookingController::class, 'refund1'])->name('booking.refund1');
    Route::get('booking/print/{id}',[BookingController::class, 'print'])->name('booking.print');
    Route::get('booking/print_ticket/{id}',[BookingController::class, 'print_ticket'])->name('booking.print.ticket');
    Route::resource('tickets',TicketController::class);
    // Route::get('tickets/{slug}/edit]',[TicketController::class, 'edit'])->name('tickets.edit');
    Route::get('edit-passenger/{ticket}',[TicketController::class, 'editPassenger'])->name('edit_passenger');
    Route::post('passenger_update',[TicketController::class, 'updatePassenger'])->name('ticket.passenger');
    Route::apiResource('segment-services',SegmentServiceController::class);
    Route::get('segment-services-print-{segmentService}',[SegmentServiceController::class, 'print'])->name('segment-services.print');
    Route::post('tickets/refund/{ticket}',[TicketController::class, 'refund'])->name('ticket.refund');
    Route::post('tickets/void/{ticket}',[TicketController::class, 'void'])->name('ticket.void');
    Route::get('boarding-passes',[BoardingPassController::class, 'index'])->name('boarding-passes.index');
    Route::get('transactions',[TransactionController::class, 'index'])->name('transactions.index');
    Route::post('installments',[TransferController::class, 'installmentStore'])->name('installments.store');
    Route::apiResource('refunds',RefundController::class)->except(['store','destroy']);
    Route::apiResource('payements',PayementController::class);
    Route::get('expense-reports', [ExpenseReportController::class , 'index'])->name('expense_reports');
    Route::get('ticket-reports', [TicketReportController::class , 'index'])->name('ticket_reports');
    Route::get('ticket-reports/export', [TicketReportController::class , 'export'])->name('ticket_reports_export');
      Route::get('banner/export', [AdminController::class , 'bannerExport'])->name('banner_export');

    Route::get('transactions/export', [TransactionController::class , 'export'])->name('transactions_export');
    Route::get('installments/export', [TransferController::class , 'installmentExport'])->name('installments_export');
    Route::get('refunds_export', [RefundController::class , 'export'])->name('refunds_export');
    Route::get('manifest', [PassengerReportController::class , 'index'])->name('manifest');
    Route::get('manifest/export', [PassengerReportController::class , 'export'])->name('passengers_reports_export');
    Route::get('car/export', [PassengerReportController::class , 'exportCar'])->name('cars_reports_export');
    

    Route::get('image-passanger', [PassengerReportController::class , 'exportImage'])->name('image');
    Route::get('delete_images', [TicketController::class , 'deleteImage'])->name('delete.image');
    // Route::get('image-export', [PassengerReportController::class , 'ddddd'])->name('image');
    Route::get('check-in/{cruise}', [CheckInController::class , 'index'])->name('check_in.index');
    Route::get('check-out/{cruise}', [CheckOutController::class , 'CheckOut'])->name('check_out');
    Route::get('check-in_list/{cruise}', [CheckInController::class , 'list'])->name('check_in.list');
    Route::post('check-in/{cruise}', [CheckInController::class , 'checkIn'])->name('check_in');
    Route::group(['prefix'=>'api/search'],function(){
        Route::get('permissions', function(){
            return auth()->user()->is_admin?Permission::all():auth()->user()->getAllPermissions();
        });
    });
    Route::post('api/card/add-passenger',[CardController::class,'addPassenger'])->name("card_add_passenger");
});

Route::group(['prefix'=>'search'],function(){
    Route::get('ports',[PortController::class,'search'])->name('ports.search');
    Route::get('origin-ports',[CruiseController::class,'originPort'])->name('ports.origin.search');
    Route::get('destination-ports',[CruiseController::class,'destinationPort'])->name('ports.destination.search');
    Route::get('ships',[ShipController::class,'search'])->name('ships.search');
    Route::get('country',[PortController::class,'countrySearch'])->name('country.search');
    Route::get('room-types',[RoomTypeController::class,'search'])->name('room-types.search');
    Route::get('accounts',[AccountController::class,'search'])->name('accounts.search');
    Route::get('cars',[CarController::class,'search'])->name('cars.search');
    Route::get('articles',[ArticleController::class,'search'])->name('articles.search');
    Route::post('cruises',[CruiseController::class,'search'])->name('cruises.search');
    Route::get('tickets',[TicketController::class,'search'])->name('tickets.search');
    Route::post('passport',[TicketController::class,'searchPassport'])->name('tickets.passport');
    Route::get('cruise_services/{cruise}',[CruiseController::class,'services'])->name('cruises.services')->middleware('money');
    Route::get('car_capacity/{car}/{cruise}',[CruiseController::class,'carCapacity'])->name('car.capacity');
    Route::get('cruise_room_type/{cruise}',[CruiseController::class,'roomTypes'])->name('cruises.room-type')->middleware('money');
    Route::get('specific_rooms/{room_type}',[RoomController::class, 'specificRooms']);
    Route::get('items/{category}',function($category){
        $categories = ['nationalities','calleds','colors'];
       
        if(in_array($category,$categories)){
           
            return explode(',',config('app.'.$category));
        }
        return [];
    });
    
});

Route::get('test',function(){
    dd(config('app.amount_weight'));
});

