<?php

use App\Http\Controllers\Admin\BranchController;
use App\Http\Controllers\Admin\FormController;
use App\Http\Controllers\Admin\FormFileController;
use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\Admin\ProjectController;
use App\Http\Controllers\Admin\ProjectFormController as AdminProjectFormController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Auth\ProjectAuthController;
use App\Http\Controllers\Front\FrontPageController;
use App\Http\Controllers\Front\ProjectController as FrontProjectController;
use App\Http\Controllers\Front\ProjectFormController;
use Illuminate\Support\Facades\Auth;
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::post('/language', [App\Http\Controllers\HomeController::class, 'changeLanguage'])->name('language.change');
Route::get('/project-login', [ProjectAuthController::class, 'showLoginForm'])->name('project.login.form');
Route::post('front/project/getProjectsByBranch', [FrontProjectController::class, 'getProjectsByBranch'])->name('frontProject.getProjectsByBranch');
Route::post('/project-login', [ProjectAuthController::class, 'login'])->name('project.login');

Auth::routes();

Route::prefix('admin')->middleware('auth')->group(function () {
    Route::get('/', [App\Http\Controllers\Admin\HomeController::class, 'dashboard'])->name('dashboard');
    //Users
    Route::controller(UserController::class)->group(function () {
        Route::get('user', 'index')->name('user.index');
        Route::post('user', 'store')->name('user.store');
        Route::get('user/create', 'create')->name('user.create');
        Route::get('user/{user}', 'show')->name('user.show');
        Route::put('user/{user}', 'update')->name('user.update');
        Route::delete('user/{user}', 'destroy')->name('user.destroy');
        Route::get('user/{user}/edit', 'edit')->name('user.edit');
    });
    //Pages
    Route::controller(PageController::class)->group(function () {
        Route::get('page', 'index')->name('page.index');
        Route::post('page', 'store')->name('page.store');
        Route::get('page/create', 'create')->name('page.create');
        Route::get('page/{page}', 'show')->name('page.show');
        Route::put('page/{page}', 'update')->name('page.update');
        Route::delete('page/{page}', 'destroy')->name('page.destroy');
        Route::get('page/{page}/edit', 'edit')->name('page.edit');
        Route::post('page/updateEnabel', 'updateEnabel')->name('page.updateEnabel');
    });

    //Branches
    Route::controller(BranchController::class)->group(function () {
        Route::get('branch', 'index')->name('branch.index');
        Route::post('branch', 'store')->name('branch.store');
        Route::get('branch/create', 'create')->name('branch.create');
        Route::get('branch/{branch}', 'show')->name('branch.show');
        Route::put('branch/{branch}', 'update')->name('branch.update');
        Route::delete('branch/{branch}', 'destroy')->name('branch.destroy');
        Route::get('branch/{branch}/edit', 'edit')->name('branch.edit');
        Route::post('branch/updateEnabel', 'updateEnabel')->name('branch.updateEnabel');
        Route::post('uploadBranchExcelFile', 'uploadBranchExcelFile')->name('branch.uploadBranchExcelFile');

    });

    //Projects
    Route::controller(ProjectController::class)->group(function () {
        Route::get('project', 'index')->name('project.index');
        Route::post('project', 'store')->name('project.store');
        Route::get('project/create', 'create')->name('project.create');
        Route::get('project/{project}', 'show')->name('project.show');
        Route::put('project/{project}', 'update')->name('project.update');
        Route::delete('project/{project}', 'destroy')->name('project.destroy');
        Route::get('project/{project}/edit', 'edit')->name('project.edit');
        Route::post('project/getProjectsByBranch', 'getProjectsByBranch')->name('project.getProjectsByBranch');
        Route::post('uploadProjectExcelFile', 'uploadProjectExcelFile')->name('project.uploadProjectExcelFile');

    });

    //Forms
    Route::controller(FormController::class)->group(function () {
        Route::get('form', 'index')->name('form.index');
        Route::get('addField', 'addField')->name('form.addField');
        Route::post('uploadFieldsFile', 'uploadFieldsFile')->name('form.uploadFieldsFile');
        Route::get('getPeriodicTypeSelect', 'getPeriodicTypeSelect')->name('form.getPeriodicTypeSelect');
        Route::post('form', 'store')->name('form.store');
        Route::get('form/create', 'create')->name('form.create');
        Route::get('form/{form}', 'show')->name('form.show');
        Route::put('form/{form}', 'update')->name('form.update');
        Route::delete('form/{form}', 'destroy')->name('form.destroy');
        Route::get('form/{form}/edit', 'edit')->name('form.edit');
        Route::get('form/store-continu/{form_id}', 'continueStoreForm')->name('form.continueStoreForm');
    });

    //ProjectForm
    Route::controller(AdminProjectFormController::class)->group(function () {
        Route::get('project-form', 'index')->name('projectForm.index');
        Route::post('project-form', 'store')->name('projectForm.store');
        Route::get('project-form/create', 'create')->name('projectForm.create');
        Route::get('project-form/{form}', 'show')->name('projectForm.show');
        Route::put('project-form/{form}', 'update')->name('projectForm.update');
        Route::delete('project-form/{form}', 'destroy')->name('projectForm.destroy');
        Route::get('project-form/{form}/edit', 'edit')->name('projectForm.edit');
        Route::get('project-form-update-expiration', 'updateExpiration')->name('projectForm.updateExpiration');
        Route::get('project-form-publish-forms', 'publishForms')->name('projectForm.publishForms');
    });

    //Forms
    Route::controller(FormFileController::class)->group(function () {
        Route::get('formFile', 'index')->name('formFile.index');
        Route::post('formFile', 'store')->name('formFile.store');
        Route::get('formFile/create', 'create')->name('formFile.create');
        Route::get('formFile/{formFile}', 'show')->name('formFile.show');
        Route::put('formFile/{formFile}', 'update')->name('formFile.update');
        Route::delete('formFile/{formFile}', 'destroy')->name('formFile.destroy');
        Route::post('formFile/delete', 'delete')->name('formFile.delete');
        Route::get('formFile/{formFile}/edit', 'edit')->name('formFile.edit');
    });

    // Settings
    Route::controller(SettingController::class)->group(function () {
        Route::get('setting', 'index')->name('setting.index');
        Route::post('setting', 'store')->name('setting.store');
        Route::put('setting/{setting}', 'update')->name('setting.update');
    });
});
Route::middleware('auth.project')->group(function () {
    Route::get('/', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
    Route::get('/getProjectForms', [ProjectFormController::class, 'getProjectForms'])->name('getProjectForms');
    Route::get('/fill-form/{project_form_id}', [ProjectFormController::class, 'fillForm'])->name('fillForm');
    Route::get('/view-form/{project_form_id}', [ProjectFormController::class, 'viewForm'])->name('viewForm');
    Route::post('/submit-fill-form', [ProjectFormController::class, 'submitFillForm'])->name('submitFillForm');
});

//TODO: make pages
Route::get('/{slug}', [FrontPageController::class, 'getPage'])->name('getPage');
