<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Api\PosInvoiceController;
use App\Http\Controllers\ReceiptController;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;

// Helper function to get frontend index.html path (defined before routes)
$getFrontendIndex = function() {
    $possiblePaths = [
        public_path('pos/index.html'), // Check public/pos first (if frontend is built there)
        public_path('frontend/index.html'),
        base_path('frontend/build/index.html'),
        base_path('frontend/index.html'),
    ];
    
    foreach ($possiblePaths as $indexPath) {
        if (File::exists($indexPath)) {
            return $indexPath;
        }
    }
    return null;
};

// FoodImages Route - Serve FoodImages directory files without /public in URL
Route::get('/FoodImages/{file}', function ($file) {
    $imagePath = public_path('FoodImages/' . $file);
    
    if (File::exists($imagePath)) {
        $mimeType = null;
        $extension = strtolower(pathinfo($imagePath, PATHINFO_EXTENSION));
        
        // Set correct MIME type
        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                $mimeType = 'image/jpeg';
                break;
            case 'png':
                $mimeType = 'image/png';
                break;
            case 'gif':
                $mimeType = 'image/gif';
                break;
            case 'svg':
                $mimeType = 'image/svg+xml';
                break;
            case 'webp':
                $mimeType = 'image/webp';
                break;
            default:
                $mimeType = 'image/jpeg';
        }
        
        $response = response()->file($imagePath, [
            'Content-Type' => $mimeType,
        ]);
        
        // Add CORS headers for images
        $response->headers->set('Access-Control-Allow-Origin', '*');
        $response->headers->set('Access-Control-Allow-Methods', 'GET, OPTIONS');
        $response->headers->set('Cache-Control', 'public, max-age=31536000');
        
        return $response;
    }
    
    abort(404, 'Image not found: ' . $file);
})->where('file', '.*');

// Images Route - Serve images with CORS headers
Route::match(['GET', 'OPTIONS'], '/images/{file}', function ($file) {
    // Handle OPTIONS preflight request
    if (request()->getMethod() === 'OPTIONS') {
        return response('', 200)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With')
            ->header('Access-Control-Max-Age', '86400');
    }
    
    $possiblePaths = [
        public_path('images/' . $file),
        public_path($file),
    ];
    
    foreach ($possiblePaths as $imagePath) {
        if (File::exists($imagePath)) {
            $mimeType = null;
            $extension = strtolower(pathinfo($imagePath, PATHINFO_EXTENSION));
            
            // Set correct MIME type
            switch ($extension) {
                case 'jpg':
                case 'jpeg':
                    $mimeType = 'image/jpeg';
                    break;
                case 'png':
                    $mimeType = 'image/png';
                    break;
                case 'gif':
                    $mimeType = 'image/gif';
                    break;
                case 'svg':
                    $mimeType = 'image/svg+xml';
                    break;
                case 'webp':
                    $mimeType = 'image/webp';
                    break;
                default:
                    $mimeType = 'image/jpeg';
            }
            
            $response = response()->file($imagePath, [
                'Content-Type' => $mimeType,
            ]);
            
            // Add CORS headers for images
            $response->headers->set('Access-Control-Allow-Origin', '*');
            $response->headers->set('Access-Control-Allow-Methods', 'GET, OPTIONS');
            $response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
            $response->headers->set('Access-Control-Max-Age', '86400');
            $response->headers->set('Cache-Control', 'public, max-age=31536000');
            
            return $response;
        }
    }
    
    abort(404, 'Image not found: ' . $file);
})->where('file', '.*');

// Logos Route - Serve logos with CORS headers
Route::match(['GET', 'OPTIONS'], '/logos/{file}', function ($file) {
    // Handle OPTIONS preflight request
    if (request()->getMethod() === 'OPTIONS') {
        return response('', 200)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With')
            ->header('Access-Control-Max-Age', '86400');
    }
    
    $possiblePaths = [
        public_path('logos/' . $file),
        public_path($file),
    ];
    
    foreach ($possiblePaths as $imagePath) {
        if (File::exists($imagePath)) {
            $mimeType = null;
            $extension = strtolower(pathinfo($imagePath, PATHINFO_EXTENSION));
            
            // Set correct MIME type
            switch ($extension) {
                case 'jpg':
                case 'jpeg':
                    $mimeType = 'image/jpeg';
                    break;
                case 'png':
                    $mimeType = 'image/png';
                    break;
                case 'gif':
                    $mimeType = 'image/gif';
                    break;
                case 'svg':
                    $mimeType = 'image/svg+xml';
                    break;
                case 'webp':
                    $mimeType = 'image/webp';
                    break;
                default:
                    $mimeType = 'image/jpeg';
            }
            
            $response = response()->file($imagePath, [
                'Content-Type' => $mimeType,
            ]);
            
            // Add CORS headers for logos
            $response->headers->set('Access-Control-Allow-Origin', '*');
            $response->headers->set('Access-Control-Allow-Methods', 'GET, OPTIONS');
            $response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
            $response->headers->set('Access-Control-Max-Age', '86400');
            $response->headers->set('Cache-Control', 'public, max-age=31536000');
            
            return $response;
        }
    }
    
    abort(404, 'Logo not found: ' . $file);
})->where('file', '.*');

// Frontend Assets Route - Serve React build assets (JS, CSS, etc.)
// This route MUST be before other routes to catch asset requests
Route::get('/assets/{file}', function ($file) {
    $possiblePaths = [
        base_path('frontend/build/assets/' . $file),
        public_path('frontend/assets/' . $file),
        public_path('assets/' . $file),
    ];
    
    foreach ($possiblePaths as $assetPath) {
        if (File::exists($assetPath)) {
            $mimeType = null;
            $extension = strtolower(pathinfo($assetPath, PATHINFO_EXTENSION));
            
            // Set correct MIME type
            switch ($extension) {
                case 'js':
                    $mimeType = 'application/javascript; charset=utf-8';
                    break;
                case 'css':
                    $mimeType = 'text/css; charset=utf-8';
                    break;
                case 'png':
                    $mimeType = 'image/png';
                    break;
                case 'jpg':
                case 'jpeg':
                    $mimeType = 'image/jpeg';
                    break;
                case 'svg':
                    $mimeType = 'image/svg+xml';
                    break;
                case 'woff':
                    $mimeType = 'font/woff';
                    break;
                case 'woff2':
                    $mimeType = 'font/woff2';
                    break;
                default:
                    $mimeType = 'application/octet-stream';
            }
            
            $response = response()->file($assetPath, [
                'Content-Type' => $mimeType,
            ]);
            
            // Add cache headers for better performance
            $response->headers->set('Cache-Control', 'public, max-age=31536000');
            
            return $response;
        }
    }
    
    abort(404, 'Asset not found: ' . $file);
})->where('file', '.*');

// Vite SVG icon route - Must be before POS routes
Route::get('/vite.svg', function () {
    $possiblePaths = [
        base_path('frontend/build/vite.svg'),
        base_path('frontend/public/vite.svg'),
        public_path('vite.svg'),
    ];
    
    foreach ($possiblePaths as $svgPath) {
        if (File::exists($svgPath)) {
            $response = response()->file($svgPath, [
                'Content-Type' => 'image/svg+xml',
            ]);
            // Add CORS headers
            $response->headers->set('Access-Control-Allow-Origin', '*');
            return $response;
        }
    }
    
    // Return empty SVG if not found to prevent errors
    return response('<svg xmlns="http://www.w3.org/2000/svg"></svg>', 200)
        ->header('Content-Type', 'image/svg+xml')
        ->header('Access-Control-Allow-Origin', '*');
});

// POS Receipt Routes
// Backend Receipt Route (Laravel Blade View) - Thermal receipt design
Route::get('/pos/receipt/{order}', [ReceiptController::class, 'show'])->name('pos.receipt.print');

// Frontend Receipt Route - Open route, render receipt same as admin invoice
// This route is excluded from CSRF and auth middleware
Route::match(['GET', 'OPTIONS'], '/frontpos/receipt/{order}', function ($order) {
    // Handle CORS preflight request
    if (request()->isMethod('OPTIONS')) {
        return response('', 200)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-TOKEN, X-XSRF-TOKEN')
            ->header('Access-Control-Allow-Credentials', 'false')
            ->header('Access-Control-Max-Age', '86400')
            ->header('Access-Control-Expose-Headers', 'Content-Type, Authorization');
    }
    
    // Use the same controller method as admin invoice route
    try {
        $controller = app(ReceiptController::class);
        $view = $controller->show(request(), $order);
        
        // Use Laravel's Router to convert view to response (same way Laravel does it internally)
        $router = app('router');
        $response = $router->prepareResponse(request(), $view);
        
        // Add CORS headers to the response
        $response->headers->set('Access-Control-Allow-Origin', '*');
        $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
        $response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With, X-CSRF-TOKEN, X-XSRF-TOKEN');
        $response->headers->set('Access-Control-Expose-Headers', 'Content-Type, Authorization');
        $response->headers->set('Access-Control-Max-Age', '86400');
        
        return $response;
    } catch (\Exception $e) {
        // If there's an error, return error response with CORS headers
        $errorResponse = response('Error: ' . $e->getMessage(), 500);
        $errorResponse->headers->set('Access-Control-Allow-Origin', '*');
        return $errorResponse;
    }
})->name('pos.receipt.frontend')->withoutMiddleware(['auth']);

// POS Invoice Routes
// Backend Invoice Route (Laravel Blade View) - Same receipt design
Route::get('/pos/invoice/{order}', [PosInvoiceController::class, 'print'])->name('pos.invoice.print');
Route::get('/pos/invoice/{order}/download', [PosInvoiceController::class, 'download'])->name('pos.invoice.download');

// Frontend Invoice Route (React) - Serve frontend HTML for React Router
Route::get('/front/pos/invoice/{order}', function ($order) use ($getFrontendIndex) {
    $indexPath = $getFrontendIndex();
    if ($indexPath) {
        $response = response()->file($indexPath, [
            'Content-Type' => 'text/html',
        ]);
        
        // Add CORS headers
        $response->headers->set('Access-Control-Allow-Origin', '*');
        $response->headers->set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
        $response->headers->set('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Requested-With');
        
        return $response;
    }
    abort(404, 'Frontend not found. Please build the frontend first.');
})->name('pos.invoice.frontend');

// KOT Route (keep for kitchen orders)
Route::get('/pos/kot/{order}', [PosInvoiceController::class, 'kot'])->name('pos.kot.print');

// Admin Invoice Route - Single route for admin to view invoice/receipt
// Commented out - Admin panel is now on frontend (SPA)
// Route::prefix('admin')->middleware(['auth'])->group(function () {
//     Route::get('/pos/invoice/{order}', [ReceiptController::class, 'show'])->name('admin.pos.invoice');
// });

Route::get('/migrate', function () {
    try {
        Artisan::call('migrate', ['--force' => true]);

        return 'Migrations executed successfully!';
    } catch (\Exception $e) {
        return 'Migration failed: '.$e->getMessage();
    }
});

Route::get('/cache-clear', function () {
    Artisan::call('optimize:clear');

    return 'Application cache cleared successfully!';
});

// Authentication Routes (outside admin prefix - login, register, forgetpassword)
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
// Register route (outside admin prefix)
// Route::get('/register', [RegisterController::class, 'showRegistrationForm'])->name('register');
// Route::post('/register', [RegisterController::class, 'register']);
// Forget Password routes (outside admin prefix)
// Route::get('/forget-password', [ForgotPasswordController::class, 'showLinkRequestForm'])->name('password.request');
// Route::post('/forget-password', [ForgotPasswordController::class, 'sendResetLinkEmail'])->name('password.email');

// Frontend Routes (React App) - MUST BE AFTER POS ROUTES
Route::prefix('front')->group(function () use ($getFrontendIndex) {
    Route::get('/{any?}', function () use ($getFrontendIndex) {
        $indexPath = $getFrontendIndex();
        if ($indexPath) {
            return File::get($indexPath);
        }
        abort(404, 'Frontend not found. Please build the frontend first.');
    })->where('any', '.*');
});

// Frontend POS Routes (React App) - /frontpos prefix
// This catch-all route serves the React app for all /frontpos/* paths
// React Router will handle client-side routing
// Note: Specific routes like /frontpos/receipt/{order} are defined BEFORE this route
// so they will be matched first
Route::prefix('frontpos')->group(function () use ($getFrontendIndex) {
    Route::get('/{any?}', function ($any = null) use ($getFrontendIndex) {
        $indexPath = $getFrontendIndex();
        if ($indexPath) {
            return response()->file($indexPath, [
                'Content-Type' => 'text/html; charset=utf-8',
            ]);
        }
        abort(404, 'Frontend not found. Please build the frontend first.');
    })->where('any', '.*');
});

// Signin route for frontend (without /front prefix)
Route::get('/signin', function () use ($getFrontendIndex) {
    $indexPath = $getFrontendIndex();
    if ($indexPath) {
        return File::get($indexPath);
    }
    abort(404, 'Frontend not found. Please build the frontend first.');
});

// Dashboard route for frontend (without /front prefix)
Route::get('/dashboard', function () use ($getFrontendIndex) {
    $indexPath = $getFrontendIndex();
    if ($indexPath) {
        return File::get($indexPath);
    }
    abort(404, 'Frontend not found. Please build the frontend first.');
});

// Admin Routes (React App) - /admin prefix
// This catch-all route serves the React app for all /admin/* paths
// React Router will handle client-side routing
Route::prefix('admin')->group(function () use ($getFrontendIndex) {
    Route::get('/{any?}', function ($any = null) use ($getFrontendIndex) {
        $indexPath = $getFrontendIndex();
        if ($indexPath) {
            return response()->file($indexPath, [
                'Content-Type' => 'text/html; charset=utf-8',
            ]);
        }
        abort(404, 'Frontend not found. Please build the frontend first.');
    })->where('any', '.*');
});

// Root route - serves frontend, frontend will handle redirect logic
Route::get('/', function () use ($getFrontendIndex) {
    $indexPath = $getFrontendIndex();
    if ($indexPath) {
        return File::get($indexPath);
    }
    abort(404, 'Frontend not found. Please build the frontend first.');
});

// Admin Routes (all protected routes under /admin prefix)
// Commented out - Admin panel is now on frontend (SPA), all routing handled by React Router
// Route::prefix('admin')->middleware(['auth'])->group(function () {
//     Route::get('/dashboard', [DashboardController::class, 'index'])->name('admin.dashboard');
//
//     // Inventory Routes
//     Route::prefix('inventory')->name('admin.inventory.')->group(function () {
//         Route::get('/', [InventoryController::class, 'index'])->name('index');
//         Route::get('/create', [InventoryController::class, 'create'])->name('create');
//         Route::post('/', [InventoryController::class, 'store'])->name('store');
//         Route::get('/{inventory}/edit', [InventoryController::class, 'edit'])->name('edit');
//         Route::put('/{inventory}', [InventoryController::class, 'update'])->name('update');
//         Route::delete('/{inventory}', [InventoryController::class, 'destroy'])->name('destroy');
//         Route::get('/export', [InventoryController::class, 'export'])->name('export');
//         Route::get('/get-items-by-category', [InventoryController::class, 'getItemsByCategory'])->name('get-items-by-category');
//         Route::post('/save-item', [InventoryController::class, 'saveItem'])->name('save-item');
//     });
//
//
//     // Stock Out Routes
//     Route::prefix('stock-out')->name('admin.stock-out.')->group(function () {
//         Route::get('/', [StockOutController::class, 'index'])->name('index');
//         Route::get('/create', [StockOutController::class, 'create'])->name('create');
//         Route::post('/', [StockOutController::class, 'store'])->name('store');
//         Route::get('/get-agents', [StockOutController::class, 'getAgents'])->name('get-agents');
//         Route::get('/get-available-quantity', [StockOutController::class, 'getAvailableQuantity'])->name('get-available-quantity');
//     });
//
//     // Stock Closing Routes
//     Route::prefix('stock-closing')->name('admin.stock-closing.')->middleware('role:admin,manager')->group(function () {
//         Route::get('/', [StockClosingController::class, 'index'])->name('index');
//         Route::get('/create', [StockClosingController::class, 'create'])->name('create');
//         Route::post('/', [StockClosingController::class, 'store'])->name('store');
//         Route::get('/{stockClosing}', [StockClosingController::class, 'show'])->name('show');
//         Route::post('/{stockClosing}/close', [StockClosingController::class, 'close'])->name('close');
//     });
//
//     // Import Routes
//     Route::prefix('import')->name('admin.import.')->group(function () {
//         Route::get('/', [ImportController::class, 'index'])->name('index');
//         Route::post('/inventory', [ImportController::class, 'importInventory'])->name('inventory');
//         Route::post('/stock-out', [ImportController::class, 'importStockOut'])->name('stock-out');
//         Route::get('/download-inventory-template', [ImportController::class, 'downloadInventoryTemplate'])->name('download-inventory-template');
//         Route::get('/download-all-inventory-items', [ImportController::class, 'downloadAllInventoryItems'])->name('download-all-inventory-items');
//         Route::get('/download-stock-out-template', [ImportController::class, 'downloadStockOutTemplate'])->name('download-stock-out-template');
//     });
//
//     // Report Routes
//     Route::prefix('reports')->name('admin.reports.')->group(function () {
//         Route::get('/', [ReportController::class, 'index'])->name('index');
//         Route::get('/inventory', [ReportController::class, 'inventoryReport'])->name('inventory');
//         Route::get('/transfer', [ReportController::class, 'transferReport'])->name('transfer');
//         Route::get('/closing', [ReportController::class, 'closingReport'])->name('closing');
//         Route::get('/stock-verification', [\App\Http\Controllers\StockVerificationController::class, 'index'])->name('stock-verification');
//         Route::get('/stock-verification/export', [\App\Http\Controllers\StockVerificationController::class, 'export'])->name('stock-verification.export');
//     });
//
//     // Settings Routes
//     // Warehouse Logs (Admin only)
//     Route::prefix('warehouse-logs')->name('admin.warehouse-logs.')->middleware('role:admin')->group(function () {
//         Route::get('/', [\App\Http\Controllers\Admin\WarehouseLogsController::class, 'index'])->name('index');
//         Route::get('/{warehouseId}/logs/{logId}', [\App\Http\Controllers\Admin\WarehouseLogsController::class, 'show'])->name('show');
//     });
//
//     Route::prefix('settings')->name('admin.settings.')->group(function () {
//         // Admin Settings (Logo & Project Name)
//         Route::middleware('role:admin')->group(function () {
//             Route::get('/admin', [SettingsController::class, 'index'])->name('logo-setup');
//             Route::put('/admin', [SettingsController::class, 'update'])->name('logo-setup.update');
//         });
//
//         // Warehouse Routes
//         Route::prefix('warehouse')->name('warehouse.')->group(function () {
//             Route::get('/', [WarehouseController::class, 'index'])->name('index');
//             Route::get('/create', [WarehouseController::class, 'create'])->name('create');
//             Route::post('/', [WarehouseController::class, 'store'])->name('store');
//             Route::get('/{warehouse}/edit', [WarehouseController::class, 'edit'])->name('edit');
//             Route::put('/{warehouse}', [WarehouseController::class, 'update'])->name('update');
//             Route::delete('/{warehouse}', [WarehouseController::class, 'destroy'])->name('destroy');
//         });
//
//         // Inventory Categories Routes
//         Route::prefix('inventory-categories')->name('inventory-categories.')->group(function () {
//             Route::get('/', [InventoryCategoryController::class, 'index'])->name('index');
//             Route::get('/create', [InventoryCategoryController::class, 'create'])->name('create');
//             Route::post('/', [InventoryCategoryController::class, 'store'])->name('store');
//             Route::get('/{inventoryCategory}/edit', [InventoryCategoryController::class, 'edit'])->name('edit');
//             Route::put('/{inventoryCategory}', [InventoryCategoryController::class, 'update'])->name('update');
//             Route::delete('/{inventoryCategory}', [InventoryCategoryController::class, 'destroy'])->name('destroy');
//         });
//
//         // Items Routes
//         Route::prefix('items')->name('items.')->group(function () {
//             Route::get('/', [ItemController::class, 'index'])->name('index');
//             Route::get('/create', [ItemController::class, 'create'])->name('create');
//             Route::post('/', [ItemController::class, 'store'])->name('store');
//             Route::get('/{item}', [ItemController::class, 'show'])->name('show');
//             Route::get('/{item}/edit', [ItemController::class, 'edit'])->name('edit');
//             Route::put('/{item}', [ItemController::class, 'update'])->name('update');
//             Route::delete('/{item}', [ItemController::class, 'destroy'])->name('destroy');
//         });
//
//         // Agents Routes
//         Route::prefix('agents')->name('agents.')->group(function () {
//             Route::get('/', [AgentController::class, 'index'])->name('index');
//             Route::get('/create', [AgentController::class, 'create'])->name('create');
//             Route::post('/', [AgentController::class, 'store'])->name('store');
//             Route::get('/{agent}/edit', [AgentController::class, 'edit'])->name('edit');
//             Route::put('/{agent}', [AgentController::class, 'update'])->name('update');
//             Route::delete('/{agent}', [AgentController::class, 'destroy'])->name('destroy');
//             Route::get('/get-agents', [AgentController::class, 'getAgents'])->name('get-agents');
//         });
//
//         // User Routes (Admin Only)
//         Route::prefix('users')->name('users.')->middleware('role:admin')->group(function () {
//             Route::get('/', [UserController::class, 'index'])->name('index');
//             Route::get('/create', [UserController::class, 'create'])->name('create');
//             Route::post('/', [UserController::class, 'store'])->name('store');
//             Route::get('/{user}/edit', [UserController::class, 'edit'])->name('edit');
//             Route::put('/{user}', [UserController::class, 'update'])->name('update');
//             Route::delete('/{user}', [UserController::class, 'destroy'])->name('destroy');
//         });
//
//         // Activity Logs Routes
//         Route::prefix('activity-logs')->name('activity-logs.')->group(function () {
//             Route::get('/', [ActivityLogController::class, 'index'])->name('index');
//             Route::get('/{activityLog}', [ActivityLogController::class, 'show'])->name('show');
//         });
//
//         // POS Settings Routes
//         Route::prefix('pos')->name('pos.')->middleware('role:admin,manager,pos_manager')->group(function () {
//             // Restaurant Menu Categories
//             Route::prefix('restaurant-categories')->name('restaurant-categories.')->group(function () {
//                 Route::get('/', [RestaurantMenuCategoryController::class, 'index'])->name('index');
//                 Route::get('/create', [RestaurantMenuCategoryController::class, 'create'])->name('create');
//                 Route::post('/', [RestaurantMenuCategoryController::class, 'store'])->name('store');
//                 Route::get('/{restaurantMenuCategory}/edit', [RestaurantMenuCategoryController::class, 'edit'])->name('edit');
//                 Route::put('/{restaurantMenuCategory}', [RestaurantMenuCategoryController::class, 'update'])->name('update');
//                 Route::delete('/{restaurantMenuCategory}', [RestaurantMenuCategoryController::class, 'destroy'])->name('destroy');
//             });
//
//             // POS Menu Items
//             Route::prefix('menu-items')->name('menu-items.')->group(function () {
//                 Route::get('/', [PosMenuItemsController::class, 'index'])->name('index');
//                 Route::get('/create', [PosMenuItemsController::class, 'create'])->name('create');
//                 Route::post('/', [PosMenuItemsController::class, 'store'])->name('store');
//                 Route::get('/{menuItem}/edit', [PosMenuItemsController::class, 'edit'])->name('edit');
//                 Route::put('/{menuItem}', [PosMenuItemsController::class, 'update'])->name('update');
//                 Route::delete('/{menuItem}', [PosMenuItemsController::class, 'destroy'])->name('destroy');
//                 
//                 // Recipe routes
//                 Route::get('/{menuItem}/recipes', [\App\Http\Controllers\PosSettings\MenuItemRecipeController::class, 'index'])->name('recipes.index');
//                 Route::get('/recipes/{recipe}', [\App\Http\Controllers\PosSettings\MenuItemRecipeController::class, 'show'])->name('recipes.show');
//                 Route::delete('/recipes/{recipe}', [\App\Http\Controllers\PosSettings\MenuItemRecipeController::class, 'destroy'])->name('recipes.destroy');
//             });
//
//             // POS Tables
//             Route::prefix('tables')->name('tables.')->group(function () {
//                 Route::get('/', [PosTablesController::class, 'index'])->name('index');
//                 Route::get('/create', [PosTablesController::class, 'create'])->name('create');
//                 Route::post('/', [PosTablesController::class, 'store'])->name('store');
//                 Route::get('/{table}/edit', [PosTablesController::class, 'edit'])->name('edit');
//                 Route::put('/{table}', [PosTablesController::class, 'update'])->name('update');
//                 Route::delete('/{table}', [PosTablesController::class, 'destroy'])->name('destroy');
//             });
//
//             // POS Waiters
//             Route::prefix('waiters')->name('waiters.')->group(function () {
//                 Route::get('/', [WaitersController::class, 'index'])->name('index');
//                 Route::get('/create', [WaitersController::class, 'create'])->name('create');
//                 Route::post('/', [WaitersController::class, 'store'])->name('store');
//                 Route::get('/{waiter}/edit', [WaitersController::class, 'edit'])->name('edit');
//                 Route::put('/{waiter}', [WaitersController::class, 'update'])->name('update');
//                 Route::delete('/{waiter}', [WaitersController::class, 'destroy'])->name('destroy');
//             });
//
//             // POS Staff
//             Route::prefix('staff')->name('staff.')->group(function () {
//                 Route::get('/', [PosStaffController::class, 'index'])->name('index');
//                 Route::get('/create', [PosStaffController::class, 'create'])->name('create');
//                 Route::post('/', [PosStaffController::class, 'store'])->name('store');
//                 Route::get('/{user}/edit', [PosStaffController::class, 'edit'])->name('edit');
//                 Route::put('/{user}', [PosStaffController::class, 'update'])->name('update');
//                 Route::delete('/{user}', [PosStaffController::class, 'destroy'])->name('destroy');
//             });
//
//             // POS Orders
//             Route::prefix('orders')->name('orders.')->group(function () {
//                 Route::get('/', [PosOrdersController::class, 'index'])->name('index');
//                 Route::get('/export', [PosOrdersController::class, 'export'])->name('export');
//                 Route::get('/{order}', [PosOrdersController::class, 'show'])->name('show');
//                 Route::post('/{order}/mark-paid', [PosOrdersController::class, 'markAsPaid'])->name('mark-paid');
//                 Route::delete('/{order}', [PosOrdersController::class, 'destroy'])->name('destroy');
//             });
//         });
//     });
//
// });

