<?php

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

$middlewareGroups = [
    'private' => [
        \App\Http\Middleware\TenanMiddleware::class
    ],

];

Route::get("/register", [\App\Http\Controllers\AccountController::class, 'registerView']);
Route::post("/register", [\App\Http\Controllers\AccountController::class, 'register']);
Route::get("/login", [\App\Http\Controllers\AccountController::class, 'loginView']);
Route::post("/login", [\App\Http\Controllers\AccountController::class, 'login']);

Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function () {
    Route::get("/d", [\App\Http\Controllers\DashboardController::class, 'dashboardView']);

    Route::get("/t/new", [\App\Http\Controllers\TenantController::class, 'newView']);
    Route::post("/t/new", [\App\Http\Controllers\TenantController::class, 'newTenant']);
    Route::get("/t/select/{name}", [\App\Http\Controllers\TenantController::class, 'switchTenant']);

    Route::get("/g", [\App\Http\Controllers\GalleryController::class, 'listView']);
    Route::get("/g/new", [\App\Http\Controllers\GalleryController::class, 'newView']);
    Route::post("/g/new", [\App\Http\Controllers\GalleryController::class, 'newGallery']);
    Route::get("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imagesUploadView']);
    Route::post("/g/{url}/upload", [\App\Http\Controllers\GalleryController::class, 'imageUpload']);
    Route::get("/g/{url}", [\App\Http\Controllers\GalleryController::class, 'showImagesView']);
    Route::get("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGalleryView']);
    Route::post("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGallery']);
    Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']);
    Route::get("/g/{url}/delete", [\App\Http\Controllers\GalleryController::class, 'deleteImage']);
    Route::post("/g/{url}/save", [\App\Http\Controllers\GalleryController::class, 'saveImage']);
});

Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
Route::get("/{tenant}/{gallery}", [\App\Http\Controllers\PublicController::class, 'listGalleryImagesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
Route::get("/{tenant}/{gallery}/{image}/file", [\App\Http\Controllers\PublicController::class, 'returnImageFile']);


Route::get('/', function () {
    return redirect("/login");
});
