<?php
require_once __DIR__ . '/../app/core/Controller.php';
require_once __DIR__ . '/../app/core/Model.php';
require_once __DIR__ . '/../app/core/Router.php';
require_once __DIR__ . '/../app/core/Database.php';
require_once __DIR__ . '/../app/core/Auth.php';
require_once __DIR__ . '/../app/core/CSRF.php';
require_once __DIR__ . '/../app/core/PortalAuth.php';

session_name('balorp_admin');
session_start();

$router = new \Router();

$scriptName = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$basePath = rtrim($scriptName, '/');
if ($basePath !== '' && $basePath !== '/') {
    if (str_starts_with($requestUri, $basePath)) {
        $requestUri = substr($requestUri, strlen($basePath));
    }
    if ($requestUri === '') {
        $requestUri = '/';
    }
}

if (str_starts_with($requestUri, '/index.php')) {
    $requestUri = substr($requestUri, strlen('/index.php'));
    if ($requestUri === '') {
        $requestUri = '/';
    }
}

$router->get('/', 'HomeController@index');
$router->get('/about', 'HomeController@about');
$router->get('/services', 'HomeController@services');
$router->get('/services/{id}', 'HomeController@serviceDetail');
$router->get('/portfolio', 'HomeController@portfolio');
$router->get('/gallery', 'HomeController@gallery');
$router->get('/projects/living-room', 'HomeController@projectLivingRoom');
$router->get('/projects/kitchen-renovation', 'HomeController@projectKitchen');
$router->get('/projects/office-space', 'HomeController@projectOffice');
$router->get('/projects/luxury-detail', 'HomeController@projectLuxuryDetail');
$router->get('/projects/modern-finish', 'HomeController@projectModernFinish');
$router->get('/projects/refined-styling', 'HomeController@projectRefinedStyling');
$router->get('/blog', 'HomeController@blog');
$router->get('/estimate', 'HomeController@estimate');
$router->get('/contact', 'HomeController@contact');
$router->get('/wizard', 'WizardController@index');
$router->post('/wizard/submit', 'WizardController@submit');
$router->get('/login', 'AuthController@login');
$router->post('/login', 'AuthController@authenticate');
$router->get('/logout', 'AuthController@logout');

$router->get('/portal/login', 'PortalController@login');
$router->post('/portal/login', 'PortalController@authenticate');
$router->get('/portal/dashboard', 'PortalController@dashboard');
$router->get('/portal/invoice', 'PortalController@invoice');
$router->get('/portal/gallery', 'PortalController@gallery');
$router->get('/portal/document/download', 'PortalController@downloadDocument');
$router->get('/portal/logout', 'PortalController@logout');

$router->get('/admin', 'AdminController@index');
$router->get('/admin/leads', 'AdminController@leads');
$router->get('/admin/leads/view', 'AdminController@viewLead');
$router->get('/admin/leads/download', 'AdminController@downloadLeadAttachment');
$router->get('/admin/leads/download-pdf', 'AdminController@downloadLeadPdf');
$router->get('/admin/projects', 'AdminController@projects');
$router->get('/admin/quotations', 'AdminController@quotations');
$router->get('/admin/invoices', 'AdminController@invoices');
$router->get('/admin/invoices/create', 'AdminController@newInvoice');
$router->post('/admin/invoices/create', 'AdminController@createInvoice');
$router->get('/admin/invoices/edit', 'AdminController@editInvoice');
$router->post('/admin/invoices/update', 'AdminController@updateInvoice');
$router->post('/admin/invoices/delete', 'AdminController@deleteInvoice');
$router->get('/admin/invoices/download', 'AdminController@downloadInvoicePdf');
$router->post('/admin/invoices/status', 'AdminController@updateInvoiceStatus');
$router->get('/admin/customers', 'AdminController@customers');
$router->get('/admin/customers/create', 'AdminController@newCustomer');
$router->post('/admin/customers/create', 'AdminController@createCustomer');
$router->get('/admin/customers/edit', 'AdminController@editCustomer');
$router->post('/admin/customers/update', 'AdminController@updateCustomer');
$router->get('/admin/customers/portal', 'AdminController@portalUsers');
$router->post('/admin/customers/portal', 'AdminController@createPortalUser');
$router->get('/admin/documents', 'AdminController@documents');
$router->post('/admin/documents/upload', 'AdminController@uploadDocument');
$router->get('/admin/project-photos', 'AdminController@projectPhotos');
$router->post('/admin/project-photos/upload', 'AdminController@uploadProjectPhoto');
$router->get('/admin/settings', 'AdminController@settings');
$router->post('/admin/settings', 'AdminController@updateSettings');
$router->get('/admin/cms-slides', 'AdminController@cmsSlides');
$router->get('/admin/cms-slides/create', 'AdminController@newCmsSlide');
$router->post('/admin/cms-slides/create', 'AdminController@createCmsSlide');
$router->get('/admin/cms-slides/edit', 'AdminController@editCmsSlide');
$router->post('/admin/cms-slides/update', 'AdminController@updateCmsSlide');
$router->post('/admin/cms-slides/delete', 'AdminController@deleteCmsSlide');
$router->get('/admin/cms-services', 'AdminController@cmsServices');
$router->get('/admin/cms-services/create', 'AdminController@newCmsService');
$router->post('/admin/cms-services/create', 'AdminController@createCmsService');
$router->get('/admin/cms-services/edit', 'AdminController@editCmsService');
$router->post('/admin/cms-services/update', 'AdminController@updateCmsService');
$router->post('/admin/cms-services/delete', 'AdminController@deleteCmsService');
$router->get('/admin/users', 'AdminController@users');
$router->get('/admin/users/create', 'AdminController@newUser');
$router->post('/admin/users/create', 'AdminController@createUser');
$router->get('/admin/users/edit', 'AdminController@editUser');
$router->post('/admin/users/update', 'AdminController@updateUser');
$router->get('/admin/blog', 'AdminController@blog');
$router->get('/admin/blog/create', 'AdminController@newBlog');
$router->post('/admin/blog/create', 'AdminController@createBlog');
$router->get('/admin/blog/edit', 'AdminController@editBlog');
$router->post('/admin/blog/update', 'AdminController@updateBlog');
$router->post('/admin/blog/delete', 'AdminController@deleteBlog');
$router->get('/admin/gallery', 'AdminController@gallery');
$router->get('/admin/gallery/create', 'AdminController@newGallery');
$router->post('/admin/gallery/create', 'AdminController@createGallery');
$router->get('/admin/gallery/edit', 'AdminController@editGallery');
$router->post('/admin/gallery/update', 'AdminController@updateGallery');
$router->post('/admin/gallery/delete', 'AdminController@deleteGallery');
$router->get('/admin/projects/create', 'AdminController@newProject');
$router->post('/admin/projects/create', 'AdminController@createProject');
$router->get('/admin/projects/edit', 'AdminController@editProject');
$router->post('/admin/projects/update', 'AdminController@updateProject');
$router->post('/admin/projects/delete', 'AdminController@deleteProject');
$router->get('/admin/testimonials', 'AdminController@testimonials');
$router->get('/admin/testimonials/create', 'AdminController@newTestimonial');
$router->post('/admin/testimonials/create', 'AdminController@createTestimonial');
$router->get('/admin/testimonials/edit', 'AdminController@editTestimonial');
$router->post('/admin/testimonials/update', 'AdminController@updateTestimonial');
$router->post('/admin/testimonials/delete', 'AdminController@deleteTestimonial');

$router->dispatch($requestUri, $_SERVER['REQUEST_METHOD']);
