<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo $__env->yieldContent('title', 'Almacen'); ?></title>
    <script>
        (() => {
            const storageKey = 'almacen.theme';
            const storedTheme = localStorage.getItem(storageKey);
            const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
            const theme = storedTheme === 'light' || storedTheme === 'dark'
                ? storedTheme
                : (systemPrefersDark ? 'dark' : 'light');

            document.documentElement.setAttribute('data-theme', theme);
            document.documentElement.style.colorScheme = theme;
        })();
    </script>
    <link rel="stylesheet" href="<?php echo e(asset('css/bootstrap.min.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(asset('css/app-theme.css')); ?>">
    <?php echo $__env->yieldPushContent('styles'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('css/dark-theme.css')); ?>">
</head>
<body class="<?php echo $__env->yieldContent('body_class'); ?>">
<?php if (! (View::hasSection('hide_navbar'))): ?>
    <?php if(auth()->guard()->check()): ?>
        <?php
            $segments = request()->segments();
            $breadcrumbs = [['label' => 'Dashboard', 'url' => route('dashboard')]];
            $path = '';
            $currentUser = auth()->user();
            $isAdminUser = $currentUser?->isAdmin() ?? false;
            $canAccessAdministracion = $currentUser?->canAccessAdministracion() ?? false;
            $canAccessAsignacion = $currentUser?->canAccessAsignacion() ?? false;
            $canAccessAlmacen = $currentUser?->canAccessAlmacen() ?? false;
            $canAccessManualAdministrador = $currentUser?->canAccessManualAdministrador() ?? false;
            $canAccessShipMarket = $currentUser?->canAccessShipMarket() ?? false;
            $canAccessReportes = $currentUser?->canAccessReportes() ?? false;
            $canAccessGraficas = $currentUser?->canAccessGraficas() ?? false;
            $isSolicitante = $currentUser?->isSolicitante() ?? false;
            $currentUserRoleLabel = $currentUser?->roleLabel() ?? 'Sin tipo';
            $appVersion = config('app.version');

            foreach ($segments as $segment) {
                if ($segment === 'dashboard') {
                    continue;
                }

                $path .= '/' . $segment;

                if ($segment === 'crud') {
                    continue;
                }

                $breadcrumbs[] = [
                    'label' => ucwords(str_replace('-', ' ', $segment)),
                    'url' => url($path),
                ];
            }
        ?>

        <div class="app-shell" id="appShell">
            <aside class="app-sidebar desktop">
                <a class="brand d-flex flex-column align-items-center gap-1 text-decoration-none" href="<?php echo e($isSolicitante ? route('ship-market.index') : route('dashboard')); ?>">
                    <span>Almacen Admin</span>
                    <img class="brand-logo mb-1" src="<?php echo e(asset('imgs/avante-logo.png')); ?>" alt="Avante" onerror="this.style.display='none'">
                </a>

                <?php if (! ($isSolicitante)): ?>
                    <a class="side-link <?php echo e(request()->routeIs('dashboard') ? 'active' : ''); ?>" href="<?php echo e(route('dashboard')); ?>"><img class="dashboard-icon" src="<?php echo e(asset('imgs/avante-logo.png')); ?>" alt="Dashboard" onerror="this.style.display='none'">Dashboard</a>
                <?php endif; ?>
                <?php if($canAccessShipMarket): ?>
                    <a class="side-link <?php echo e(request()->routeIs('ship-market.*') ? 'active' : ''); ?>" href="<?php echo e(route('ship-market.index')); ?>">Ship Market</a>
                <?php endif; ?>
                <?php if($canAccessAsignacion): ?>
                    <a class="side-link <?php echo e(request()->is('asignacion*') ? 'active' : ''); ?>" href="<?php echo e(route('asignacion.iniciar')); ?>">Asignacion</a>
                <?php endif; ?>
                <?php if($canAccessAlmacen): ?>
                    <a class="side-link <?php echo e(request()->is('almacen*') ? 'active' : ''); ?>" href="<?php echo e(route('almacen.index')); ?>">Almacen</a>
                <?php endif; ?>
                <?php if($canAccessAdministracion): ?>
                    <a class="side-link <?php echo e(request()->is('administracion*') ? 'active' : ''); ?>" href="<?php echo e(url('/administracion')); ?>">Administracion</a>
                <?php endif; ?>
                <?php if($canAccessManualAdministrador): ?>
                    <a class="side-link <?php echo e(request()->routeIs('manual.administrador*') ? 'active' : ''); ?>" href="<?php echo e(route('manual.administrador')); ?>">Manual de Administrador</a>
                <?php endif; ?>
                <?php if($canAccessReportes): ?>
                    <a class="side-link <?php echo e(request()->is('reportes*') ? 'active' : ''); ?>" href="<?php echo e(route('reportes.index')); ?>">Reportes</a>
                <?php endif; ?>
                <?php if($canAccessGraficas): ?>
                    <a class="side-link <?php echo e(request()->is('graficas*') ? 'active' : ''); ?>" href="<?php echo e(route('graficas.index')); ?>">Graficas</a>
                <?php endif; ?>

                <form action="<?php echo e(route('logout')); ?>" method="POST" class="mt-3">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="btn btn-sm btn-light w-100">Cerrar sesion</button>
                </form>
            </aside>

            <div class="app-main">
                <div class="app-topbar">
                    <div class="topbar-shell container-fluid px-0 px-lg-2">
                        <button class="sidebar-toggle-btn desktop-only" type="button" id="desktopSidebarToggle" aria-label="Ocultar menu lateral">☰</button>
                        <button class="btn btn-sm btn-outline-secondary mobile-menu-trigger" type="button" data-bs-toggle="offcanvas" data-bs-target="#mobileSidebar" aria-controls="mobileSidebar">Menu</button>
                        <nav aria-label="breadcrumb" class="flex-grow-1">
                            <ol class="breadcrumb topbar-breadcrumb">
                                <?php $__currentLoopData = $breadcrumbs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $crumb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <li class="breadcrumb-item <?php echo e($index === count($breadcrumbs) - 1 ? 'active' : ''); ?>" <?php echo e($index === count($breadcrumbs) - 1 ? 'aria-current=page' : ''); ?>>
                                        <?php if($index === count($breadcrumbs) - 1): ?>
                                            <?php echo e($crumb['label']); ?>

                                        <?php else: ?>
                                            <a href="<?php echo e($crumb['url']); ?>"><?php echo e($crumb['label']); ?></a>
                                        <?php endif; ?>
                                    </li>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </ol>
                        </nav>
                        <div class="topbar-actions">
                                    <div class="topbar-user-role topbar-mobile-hidden" title="Version actual de la aplicacion">
                                        <span class="topbar-user-role-value">v<?php echo e($appVersion); ?></span>
                                    </div>
                                    <div class="operation-counter topbar-mobile-hidden" title="Operaciones contadas">
                                        <span class="operation-counter-label" aria-hidden="true">⚙️</span>
                                        <span class="operation-counter-value"><?php echo e(number_format((int) ($totalOperacionesContadas ?? 0), 0, ',', '.')); ?></span>
                                    </div>
                                    <div class="topbar-user-role topbar-mobile-hidden" title="Rol del usuario actual">
                                        <span class="topbar-user-role-value"><?php echo e($currentUserRoleLabel); ?></span>
                                    </div>
                                    <button class="btn btn-sm theme-toggle-btn topbar-mobile-hidden" type="button" id="themeToggleButton" aria-label="Cambiar tema" title="Cambiar tema">
                                        <span class="theme-toggle-icon" aria-hidden="true">◐</span>
                                        <span class="theme-toggle-label">Tema</span>
                                    </button>
                        </div>
                    </div>
                </div>

                <div class="offcanvas offcanvas-start" tabindex="-1" id="mobileSidebar" aria-labelledby="mobileSidebarLabel">
                    <div class="offcanvas-header flex-column align-items-center">
                        <a href="<?php echo e($isSolicitante ? route('ship-market.index') : route('dashboard')); ?>" class="d-flex flex-column align-items-center gap-1 text-decoration-none w-100">
                            <span class="offcanvas-title w-100 text-center" id="mobileSidebarLabel">Almacen Admin</span>
                            <img class="brand-logo mb-1" src="<?php echo e(asset('imgs/avante-logo.png')); ?>" alt="Avante" onerror="this.style.display='none'">
                        </a>
                        <button type="button" class="btn-close align-self-end mt-2" data-bs-dismiss="offcanvas" aria-label="Close"></button>
                    </div>
                    <div class="offcanvas-body">
                        <?php if (! ($isSolicitante)): ?>
                            <a class="side-link text-dark border" href="<?php echo e(route('dashboard')); ?>"><img class="dashboard-icon" src="<?php echo e(asset('imgs/avante-logo.png')); ?>" alt="Dashboard" onerror="this.style.display='none'">Dashboard</a>
                        <?php endif; ?>
                        <?php if($canAccessShipMarket): ?>
                            <a class="side-link text-dark border <?php echo e(request()->routeIs('ship-market.*') ? 'active' : ''); ?>" href="<?php echo e(route('ship-market.index')); ?>">Ship Market</a>
                        <?php endif; ?>
                        <?php if($canAccessAsignacion): ?>
                            <a class="side-link text-dark border" href="<?php echo e(route('asignacion.iniciar')); ?>">Asignacion</a>
                        <?php endif; ?>
                        <?php if($canAccessAlmacen): ?>
                            <a class="side-link text-dark border" href="<?php echo e(route('almacen.index')); ?>">Almacen</a>
                        <?php endif; ?>
                        <?php if($canAccessAdministracion): ?>
                            <a class="side-link text-dark border" href="<?php echo e(url('/administracion')); ?>">Administracion</a>
                        <?php endif; ?>
                        <?php if($canAccessManualAdministrador): ?>
                            <a class="side-link text-dark border <?php echo e(request()->routeIs('manual.administrador*') ? 'active' : ''); ?>" href="<?php echo e(route('manual.administrador')); ?>">Manual de Administrador</a>
                        <?php endif; ?>
                        <?php if($canAccessReportes): ?>
                            <a class="side-link text-dark border" href="<?php echo e(route('reportes.index')); ?>">Reportes</a>
                        <?php endif; ?>
                        <?php if($canAccessGraficas): ?>
                            <a class="side-link text-dark border" href="<?php echo e(route('graficas.index')); ?>">Graficas</a>
                        <?php endif; ?>
                        <div class="mobile-sidebar-meta-group mt-3">
                            <div class="topbar-user-role mobile-sidebar-meta-item" title="Version actual de la aplicacion">
                                <span class="topbar-user-role-value">v<?php echo e($appVersion); ?></span>
                            </div>
                            <div class="operation-counter mobile-sidebar-meta-item" title="Operaciones contadas">
                                <span class="operation-counter-label" aria-hidden="true">⚙️</span>
                                <span class="operation-counter-value"><?php echo e(number_format((int) ($totalOperacionesContadas ?? 0), 0, ',', '.')); ?></span>
                            </div>
                            <button class="btn btn-sm theme-toggle-btn mobile-sidebar-theme-toggle" type="button" data-theme-toggle aria-label="Cambiar tema" title="Cambiar tema">
                                <span class="theme-toggle-icon" aria-hidden="true">◐</span>
                                <span class="theme-toggle-label">Tema</span>
                            </button>
                        </div>
                        <div class="mobile-sidebar-role-group mt-3">
                            <div class="topbar-user-role mobile-user-role" title="Rol del usuario actual">
                                <span class="topbar-user-role-value"><?php echo e($currentUserRoleLabel); ?></span>
                            </div>
                        </div>
                    </div>
                </div>

                <main class="<?php echo e(View::hasSection('full_width') ? 'content-wrap' : 'container content-wrap'); ?>">
                    <?php if(session('status')): ?>
                        <div class="alert alert-success"><?php echo e(session('status')); ?></div>
                    <?php endif; ?>

                    <?php if(session('warning')): ?>
                        <div class="alert alert-warning"><?php echo e(session('warning')); ?></div>
                    <?php endif; ?>

                    <?php if(session('error')): ?>
                        <div class="alert alert-danger"><?php echo e(session('error')); ?></div>
                    <?php endif; ?>

                    <?php if($errors->any()): ?>
                        <div class="alert alert-danger">
                            <?php echo e($errors->first()); ?>

                        </div>
                    <?php endif; ?>

                    <?php echo $__env->yieldContent('content'); ?>
                </main>
            </div>
        </div>
    <?php else: ?>
        <nav class="navbar navbar-expand-lg bg-white border-bottom">
            <div class="container">
                <a class="navbar-brand" href="<?php echo e(route('dashboard')); ?>">Almacen</a>
                <div class="ms-auto d-flex align-items-center gap-2">
                    <span class="badge text-bg-light border topbar-mobile-hidden">v<?php echo e(config('app.version')); ?></span>
                    <button class="btn btn-sm theme-toggle-btn topbar-mobile-hidden" type="button" data-theme-toggle aria-label="Cambiar tema" title="Cambiar tema">
                        <span class="theme-toggle-icon" aria-hidden="true">◐</span>
                        <span class="theme-toggle-label">Tema</span>
                    </button>
                    <a class="btn btn-sm btn-brand" href="<?php echo e(route('login')); ?>">Iniciar sesion</a>
                </div>
            </div>
        </nav>

        <main class="<?php echo e(View::hasSection('full_width') ? 'content-wrap' : 'container content-wrap'); ?>">
            <?php echo $__env->yieldContent('content'); ?>
        </main>
    <?php endif; ?>
<?php endif; ?>

<?php if(View::hasSection('hide_navbar')): ?>
    <main class="<?php echo e(View::hasSection('full_width') ? 'content-wrap' : 'container content-wrap'); ?>">
        <?php echo $__env->yieldContent('content'); ?>
    </main>
<?php endif; ?>

<script src="<?php echo e(asset('js/bootstrap.bundle.min.js')); ?>"></script>
<script>
    (() => {
        const appShell = document.getElementById('appShell');
        const toggleButton = document.getElementById('desktopSidebarToggle');

        if (!appShell || !toggleButton) {
            return;
        }

        const storageKey = 'almacen.sidebar.collapsed';
        const applyState = (collapsed) => {
            appShell.classList.toggle('sidebar-collapsed', collapsed);
            toggleButton.setAttribute('aria-label', collapsed ? 'Mostrar menu lateral' : 'Ocultar menu lateral');
            toggleButton.setAttribute('title', collapsed ? 'Mostrar menu lateral' : 'Ocultar menu lateral');
        };

        applyState(localStorage.getItem(storageKey) === 'true');

        toggleButton.addEventListener('click', () => {
            const collapsed = !appShell.classList.contains('sidebar-collapsed');
            applyState(collapsed);
            localStorage.setItem(storageKey, String(collapsed));
        });
    })();

    (() => {
        const storageKey = 'almacen.theme';
        const root = document.documentElement;
        const buttons = Array.from(document.querySelectorAll('[data-theme-toggle], #themeToggleButton'));

        if (buttons.length === 0) {
            return;
        }

        const applyTheme = (theme) => {
            root.setAttribute('data-theme', theme);
            root.style.colorScheme = theme;

            buttons.forEach((button) => {
                const icon = button.querySelector('.theme-toggle-icon');
                const label = button.querySelector('.theme-toggle-label');
                const isDark = theme === 'dark';

                button.setAttribute('aria-label', isDark ? 'Cambiar a modo claro' : 'Cambiar a modo oscuro');
                button.setAttribute('title', isDark ? 'Cambiar a modo claro' : 'Cambiar a modo oscuro');

                if (icon) {
                    icon.textContent = isDark ? '☀' : '☾';
                }

                if (label) {
                    label.textContent = isDark ? 'Claro' : 'Oscuro';
                }
            });
        };

        const currentTheme = root.getAttribute('data-theme') === 'dark' ? 'dark' : 'light';
        applyTheme(currentTheme);

        buttons.forEach((button) => {
            button.addEventListener('click', () => {
                const nextTheme = root.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
                applyTheme(nextTheme);
                localStorage.setItem(storageKey, nextTheme);
            });
        });
    })();
</script>
<?php echo $__env->yieldPushContent('scripts'); ?>
</body>
</html>
<?php /**PATH C:\xampp\htdocs\almacen2\resources\views/layouts/app.blade.php ENDPATH**/ ?>