<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FormSubmitController;
use App\Livewire\Register;
use App\Livewire\Login;
use App\Livewire\ChangePassword;
use App\Livewire\Dashboard;
use App\Livewire\Logout;
use App\Livewire\Users\User;
use App\Http\Controllers\ViewDataController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/foo', function () {
    Artisan::call('storage:link');
});

Route::get('/', function () {
    return redirect()->to('/login');
});

Route::group(['middleware'=>'guest'], function(){
    // Route::get('/register', Register::class)->name('register');
    Route::get('/login', Login::class)->name('login');
});

Route::group(['middleware'=>'auth'], function(){
    Route::get('/dashboard', Dashboard::class)->name('dashboard')->lazy();
    Route::get('/change-password', ChangePassword::class)->name('changePassword');
    Route::get('/logout', Logout::class)->name('logout');
    Route::get('/user', User::class)->name('user')->lazy();
    Route::post('save-form-data', [FormSubmitController::class, 'create']);
    Route::get('view-table-data', [ViewDataController::class, 'show']);

    // Start Form Builder===============================================================
    Route::namespace('App\Livewire\FormBuilder')->group(function () {
        Route::get('form-builder', Index::class)->name('form-builder');
        Route::get('formbuilder/{editId?}', Create::class)->name('formBuilder');
        Route::get('open-form/{id}/{from?}/{editId?}', Read::class)->name('openForm');
        Route::get('form-content', Content::class)->name('formContent');
    });
    // End Form Builder===============================================================

    // Start Data Form===============================================================
    Route::namespace('App\Livewire\DataForm')->group(function () {
        Route::get('data-enter/{id}', DataEntry::class)->name('dataEnter')->lazy();
        Route::get('show-data/{id}', ViewData::class)->name('showData');
    });
    
    // Start chart Builder===============================================================
    Route::namespace('App\Livewire\ChartBuilder')->group(function () {
        Route::get('chart-builder', Index::class)->name('chart-builder');
        Route::get('chart-create/{editId?}', Create::class)->name('create-chart');
    });
    // End chart Builder===============================================================
});