<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PublicSearchController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\Admin\RecordController;
use App\Http\Controllers\Admin\CustomFieldController;

// Public
Route::get('/', [PublicSearchController::class, 'index'])->name('home');
Route::post('/consultar', [PublicSearchController::class, 'search'])->name('public.search');

// Auth
Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

// Admin
Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
    // CRUD Fichas
    Route::get('/fichas', [RecordController::class, 'index'])->name('records.index');
    Route::get('/fichas/crear', [RecordController::class, 'create'])->name('records.create');
    Route::post('/fichas', [RecordController::class, 'store'])->name('records.store');
    Route::get('/fichas/{record}/editar', [RecordController::class, 'edit'])->name('records.edit');
    Route::put('/fichas/{record}', [RecordController::class, 'update'])->name('records.update');
    Route::delete('/fichas/{record}', [RecordController::class, 'destroy'])->name('records.destroy');

    // IMPORTACIÓN Y EXPORTACIÓN
    Route::post('/fichas/importar', [RecordController::class, 'import'])->name('records.import');
    Route::get('/fichas/exportar-todo', [RecordController::class, 'exportAll'])->name('records.export_all');
    Route::get('/fichas/{record}/exportar-excel', [RecordController::class, 'exportSingle'])->name('records.export_excel');

    // Gestión de Campos Dinámicos
    Route::get('/campos', [CustomFieldController::class, 'index'])->name('custom_fields.index');
    Route::post('/campos', [CustomFieldController::class, 'store'])->name('custom_fields.store');
    Route::delete('/campos/{field}', [CustomFieldController::class, 'destroy'])->name('custom_fields.destroy');
});
