<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\StaffRegController;
use App\Http\Controllers\SaveController;
use App\Http\Controllers\FileController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\TaskController;
use App\Http\Controllers\ReportForm41Controller;
use App\Http\Controllers\FormDaily41Controller;
use App\Http\Controllers\FormDaily42Controller;
use App\Http\Controllers\FormDaily43Controller;
use App\Http\Controllers\FormDaily44Controller;
use App\Http\Controllers\FormDaily45Controller;
use App\Http\Controllers\FormDaily46Controller;
use App\Http\Controllers\FormDaily47Controller;
use App\Http\Controllers\FormDaily48Controller;
use App\Http\Controllers\FormController;
use App\Http\Controllers\FarmController;
use App\Http\Controllers\TimelineController;
use App\Http\Controllers\UserController;


//Login
Route::get('/', [\App\Http\Controllers\LoginController::class, 'ShowLoginForm'])->name('login');
Route::post('/', [\App\Http\Controllers\LoginController::class, 'submitLogin'])->name('login-submit');

Route::middleware(['auth'])->group(function () {
    Route::get('/logout', [\App\Http\Controllers\LogoutController::class, 'logout'])->name('logout.submit');

    //adminDashboard
    Route::get('/admin/dashboard', [AdminController::class, 'AdminDashboard'])->name('admin.dashboard');

    // Show registration form
    // Route::get('/registration', [StaffRegController::class, 'showRegistrationForm'])->name('registration');
    // Route::get('registration/visitor/create', [StaffRegController::class, 'create'])->name('registration.visitor.create');
    // Route::post('registration/visitor/store', [StaffRegController::class, 'store'])->name('registration.visitor.store');
    // // Generate QR code and save data
    // Route::post('/generate-qr-code', [StaffRegController::class, 'generateQrCode'])->name('generateQrCode');

    //VPS change start here
    Route::get('/form/{id}', [FormController::class, 'showForm_1'])->name('form.show.1');
    Route::post('/submit-form/{form}', [FormController::class, 'submitForm'])->name('form.submit');

    Route::get('/forms', [FormController::class, 'index'])->name('form.index');
    Route::post('/form/assign/{id}', [FormController::class, 'assign'])->name('form.assign');
    Route::get('/form/{id}/view', [FormController::class, 'viewFormAnswers'])->name('form.view');
    Route::get('/forms/verify/{id}', [FormController::class, 'verifyForm'])->name('form.verify');
    Route::get('/forms/reject/{id}', [FormController::class, 'rejectForm'])->name('form.reject');
    Route::get('/forms/delete/{id}', [FormController::class, 'deleteForm'])->name('form.delete');

    Route::get('/form/{id}/timeline', [TimelineController::class, 'viewFormTimeline'])->name('form.timeline');

    Route::get('/users', [UserController::class, 'index'])->name('users.index');
    Route::get('/users/{id}/edit', [UserController::class, 'edit'])->name('users.edit');
    Route::put('/users/{id}', [UserController::class, 'update'])->name('users.update');
    Route::delete('/users/{id}', [UserController::class, 'destroy'])->name('users.destroy');

    Route::get('/profile', [UserController::class, 'profile'])->name('users.profile');
    Route::put('/profile/update', [UserController::class, 'updateProfile'])->name('users.update-profile');
    Route::put('/profile/change-password', [UserController::class, 'changePassword'])->name('users.change-password');

    // Route for manager to create new staff with role farmer
    Route::get('/staff/create', [UserController::class, 'createStaff'])->name('staff.create');
    Route::post('/staff/store', [UserController::class, 'storeStaff'])->name('staff.store');

    // Route for superadmin to create new users with different roles
    Route::get('/users/create', [UserController::class, 'createUser'])->name('users.create');
    Route::post('/users/store', [UserController::class, 'storeUser'])->name('users.store');

    Route::post('/users/{id}/reset-password', [UserController::class, 'resetPassword'])->name('users.reset-password');


    //Route for tasks
    Route::get('/tasks/get-sections', [TaskController::class, 'getSections'])->name('tasks.get-sections');
    Route::get('/tasks', [TaskController::class, 'index'])->name('tasks.index');
    Route::get('/tasks/create', [TaskController::class, 'create'])->name('tasks.create');
    Route::post('/tasks', [TaskController::class, 'store'])->name('tasks.store');
    Route::get('/tasks/{task}', [TaskController::class, 'show'])->name('tasks.show');
    Route::get('/tasks/{task}/edit', [TaskController::class, 'edit'])->name('tasks.edit');
    Route::put('/tasks/{task}', [TaskController::class, 'update'])->name('tasks.update');
    Route::delete('tasks/{task}', [TaskController::class, 'destroy'])->name('tasks.destroy');



    // Route::get('/api/farms/{farm}/sections', function ($farmId) {
    //     return App\Models\Farm::find($farmId)->farm_section;
    // });

    //Route for farm and farms_section
    Route::resource('farms', FarmController::class);
    Route::get('farms/{farm}/section/create', [FarmController::class, 'createSection'])->name('farms.createSection');
    Route::post('farms/{farm}/section', [FarmController::class, 'storeSection'])->name('farms.storeSection');

    // Route for Daily Task 4.1
    Route::get('/form41/daily/index', [FormDaily41Controller::class, 'index'])->name('form41.daily.index');
    Route::get('/form41/daily/create', [FormDaily41Controller::class, 'create'])->name('form41.daily.create');
    Route::post('/form41/daily', [FormDaily41Controller::class, 'store'])->name('form41.daily.store');
    Route::get('/form41/daily/{id}', [FormDaily41Controller::class, 'show'])->name('form41.daily.show');
    Route::get('/form41/daily/{id}/edit', [FormDaily41Controller::class, 'edit'])->name('form41.daily.edit');
    Route::put('/form41/daily/{id}', [FormDaily41Controller::class, 'update'])->name('form41.daily.update');
    Route::delete('/form/daily/{id}', [FormDaily41Controller::class, 'destroy'])->name('form41.daily.destroy');

    // Route for Daily Task 4.2
    Route::get('/form42/daily/index', [FormDaily42Controller::class, 'index'])->name('form42.daily.index');
    Route::get('/form42/daily/create', [FormDaily42Controller::class, 'create'])->name('form42.daily.create');
    Route::post('/form42/daily', [FormDaily42Controller::class, 'store'])->name('form42.daily.store');
    Route::get('/form42/daily/{id}', [FormDaily42Controller::class, 'show'])->name('form42.daily.show');
    Route::get('/form42/daily/{id}/edit', [FormDaily42Controller::class, 'edit'])->name('form42.daily.edit');
    Route::put('/form42/daily/{id}', [FormDaily42Controller::class, 'update'])->name('form42.daily.update');
    Route::delete('/form42/daily/{id}', [FormDaily42Controller::class, 'destroy'])->name('form42.daily.destroy');

    // Route for Daily Task 4.3
    Route::get('/form43/daily/index', [FormDaily43Controller::class, 'index'])->name('form43.daily.index');
    Route::get('/form43/daily/create', [FormDaily43Controller::class, 'create'])->name('form43.daily.create');
    Route::post('/form43/daily', [FormDaily43Controller::class, 'store'])->name('form43.daily.store');
    Route::get('/form43/daily/{id}', [FormDaily43Controller::class, 'show'])->name('form43.daily.show');
    Route::get('/form43/daily/{id}/edit', [FormDaily43Controller::class, 'edit'])->name('form43.daily.edit');
    Route::put('/form43/daily/{id}', [FormDaily43Controller::class, 'update'])->name('form43.daily.update');
    Route::delete('/form43/daily/{id}', [FormDaily43Controller::class, 'destroy'])->name('form43.daily.destroy');

    // Route for Daily Task 4.4
    Route::get('/form44/daily/index', [FormDaily44Controller::class, 'index'])->name('form44.daily.index');
    Route::get('/form44/daily/create', [FormDaily44Controller::class, 'create'])->name('form44.daily.create');
    Route::post('/form44/daily', [FormDaily44Controller::class, 'store'])->name('form44.daily.store');
    Route::get('/form44/daily/{id}', [FormDaily44Controller::class, 'show'])->name('form44.daily.show');
    Route::get('/form44/daily/{id}/edit', [FormDaily44Controller::class, 'edit'])->name('form44.daily.edit');
    Route::put('/form44/daily/{id}', [FormDaily44Controller::class, 'update'])->name('form44.daily.update');
    Route::delete('/form44/daily/{id}', [FormDaily44Controller::class, 'destroy'])->name('form44.daily.destroy');

    // Route for Daily Task 4.5
    Route::get('/form45/daily/index', [FormDaily45Controller::class, 'index'])->name('form45.daily.index');
    Route::get('/form45/daily/create', [FormDaily45Controller::class, 'create'])->name('form45.daily.create');
    Route::post('/form45/daily', [FormDaily45Controller::class, 'store'])->name('form45.daily.store');
    Route::get('/form45/daily/{id}', [FormDaily45Controller::class, 'show'])->name('form45.daily.show');
    Route::get('/form45/daily/{id}/edit', [FormDaily45Controller::class, 'edit'])->name('form45.daily.edit');
    Route::put('/form45/daily/{id}', [FormDaily45Controller::class, 'update'])->name('form45.daily.update');
    Route::delete('/form45/daily/{id}', [FormDaily45Controller::class, 'destroy'])->name('form45.daily.destroy');

    // Route for Daily Task 4.6
    Route::get('/form46/daily/index', [FormDaily46Controller::class, 'index'])->name('form46.daily.index');
    Route::get('/form46/daily/create', [FormDaily46Controller::class, 'create'])->name('form46.daily.create');
    Route::post('/form46/daily', [FormDaily46Controller::class, 'store'])->name('form46.daily.store');
    Route::get('/form46/daily/{id}', [FormDaily46Controller::class, 'show'])->name('form46.daily.show');
    Route::get('/form46/daily/{id}/edit', [FormDaily46Controller::class, 'edit'])->name('form46.daily.edit');
    Route::put('/form46/daily/{id}', [FormDaily46Controller::class, 'update'])->name('form46.daily.update');
    Route::delete('/form46/daily/{id}', [FormDaily46Controller::class, 'destroy'])->name('form46.daily.destroy');

    // Route for Daily Task 4.7
    Route::get('/form47/daily/index', [FormDaily47Controller::class, 'index'])->name('form47.daily.index');
    Route::get('/form47/daily/create', [FormDaily47Controller::class, 'create'])->name('form47.daily.create');
    Route::post('/form47/daily', [FormDaily47Controller::class, 'store'])->name('form47.daily.store');
    Route::get('/form47/daily/{id}', [FormDaily47Controller::class, 'show'])->name('form47.daily.show');
    Route::get('/form47/daily/{id}/edit', [FormDaily47Controller::class, 'edit'])->name('form47.daily.edit');
    Route::put('/form47/daily/{id}', [FormDaily47Controller::class, 'update'])->name('form47.daily.update');
    Route::delete('/form47/daily/{id}', [FormDaily47Controller::class, 'destroy'])->name('form47.daily.destroy');

    // Route for Daily Task 4.8
    Route::get('/form48/daily/index', [FormDaily48Controller::class, 'index'])->name('form48.daily.index');
    Route::get('/form48/daily/create', [FormDaily48Controller::class, 'create'])->name('form48.daily.create');
    Route::post('/form48/daily', [FormDaily48Controller::class, 'store'])->name('form48.daily.store');
    Route::get('/form48/daily/{id}', [FormDaily48Controller::class, 'show'])->name('form48.daily.show');
    Route::get('/form48/daily/{id}/edit', [FormDaily48Controller::class, 'edit'])->name('form48.daily.edit');
    Route::put('/form48/daily/{id}', [FormDaily48Controller::class, 'update'])->name('form48.daily.update');
    Route::delete('/form48/daily/{id}', [FormDaily48Controller::class, 'destroy'])->name('form48.daily.destroy');

    //route for datatable daily task didnit working
    Route::get('admin/report-data', [ReportForm41Controller::class, 'getReportform'])->name('admin.report-get-data');
    Route::get('report/pdf', [ReportForm41Controller::class, 'downloadPDF'])->name('report.pdf');
    Route::get('export/excel', [ReportForm41Controller::class, 'exportExcel'])->name('export.excel');

   

    Route::get('/form/{submittedFormId}/download', [FormController::class, 'downloadFormPDF'])->name('form.download');


});


