<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Money Exchange Management</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .app-sidebar {
            width: 260px;
            overflow-y: auto;
        }

        .app-content {
            min-height: 100vh;
        }

        @media (min-width: 992px) {
            .app-content.with-sidebar {
                margin-left: 260px;
            }
        }
    </style>
</head>
<body class="bg-light">
<?php if(session('admin_logged_in')): ?>
    <?php
        $menuItems = [
            ['label' => 'Dashboard', 'route' => 'dashboard', 'active' => request()->routeIs('dashboard')],
            ['label' => 'Currencies', 'route' => 'currencies.index', 'active' => request()->routeIs('currencies.*')],
            ['label' => 'Accounts', 'route' => 'accounts.index', 'active' => request()->routeIs('accounts.index')],
            ['label' => 'Account Summary', 'route' => 'accounts.summary', 'active' => request()->routeIs('accounts.summary')],
            ['label' => 'Stock Dashboard', 'route' => 'stock.dashboard', 'active' => request()->routeIs('stock.*')],
            ['label' => 'Buy Currency', 'route' => 'transactions.buy.create', 'active' => request()->routeIs('transactions.buy.*')],
            ['label' => 'Sell Currency', 'route' => 'transactions.sell.create', 'active' => request()->routeIs('transactions.sell.*')],
            ['label' => 'Profit Summary', 'route' => 'profits.index', 'active' => request()->routeIs('profits.*')],
            ['label' => 'Currency Report', 'route' => 'reports.currencies', 'active' => request()->routeIs('reports.currencies')],
            ['label' => 'Profit Report', 'route' => 'reports.profits', 'active' => request()->routeIs('reports.profits')],
            ['label' => 'Account Report', 'route' => 'reports.accounts', 'active' => request()->routeIs('reports.accounts')],
            ['label' => 'Transaction History', 'route' => 'reports.transactions', 'active' => request()->routeIs('reports.transactions')],
            ['label' => 'Opening Balances', 'route' => 'setup.opening-balances', 'active' => request()->routeIs('setup.opening-balances')],
            ['label' => 'Initial Stock', 'route' => 'setup.initial-stocks', 'active' => request()->routeIs('setup.initial-stocks')],
        ];
    ?>

    <nav class="navbar bg-white border-bottom d-lg-none">
        <div class="container-fluid">
            <button class="btn btn-outline-secondary" type="button" data-bs-toggle="offcanvas" data-bs-target="#mobileSidebar">
                Menu
            </button>
            <a class="navbar-brand fw-semibold" href="<?php echo e(route('dashboard')); ?>">Money Exchange</a>
        </div>
    </nav>

    <aside class="app-sidebar d-none d-lg-flex flex-column position-fixed top-0 bottom-0 start-0 bg-white border-end p-3">
        <a class="h5 text-decoration-none text-dark mb-4" href="<?php echo e(route('dashboard')); ?>">Money Exchange</a>
        <div class="nav nav-pills flex-column gap-1">
            <?php $__currentLoopData = $menuItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <a class="nav-link <?php echo e($item['active'] ? 'active' : 'text-dark'); ?>" href="<?php echo e(route($item['route'])); ?>">
                    <?php echo e($item['label']); ?>

                </a>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
        <form class="mt-auto" method="POST" action="<?php echo e(route('logout')); ?>">
            <?php echo csrf_field(); ?>
            <button class="btn btn-outline-secondary w-100" type="submit">Logout</button>
        </form>
    </aside>

    <div class="offcanvas offcanvas-start" tabindex="-1" id="mobileSidebar">
        <div class="offcanvas-header">
            <h5 class="offcanvas-title">Money Exchange</h5>
            <button class="btn-close" type="button" data-bs-dismiss="offcanvas"></button>
        </div>
        <div class="offcanvas-body d-flex flex-column">
            <div class="nav nav-pills flex-column gap-1">
                <?php $__currentLoopData = $menuItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <a class="nav-link <?php echo e($item['active'] ? 'active' : 'text-dark'); ?>" href="<?php echo e(route($item['route'])); ?>">
                        <?php echo e($item['label']); ?>

                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
            <form class="mt-auto" method="POST" action="<?php echo e(route('logout')); ?>">
                <?php echo csrf_field(); ?>
                <button class="btn btn-outline-secondary w-100" type="submit">Logout</button>
            </form>
        </div>
    </div>
<?php endif; ?>

<div class="app-content <?php echo e(session('admin_logged_in') ? 'with-sidebar' : ''); ?>">
    <main class="container-fluid py-4 px-3 px-lg-4">
        <?php if(session('success')): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <?php echo e(session('success')); ?>

                <button class="btn-close" type="button" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>

        <?php if($errors->any()): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <strong>Please check the form.</strong>
                <ul class="mb-0">
                    <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li><?php echo e($error); ?></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
                <button class="btn-close" type="button" data-bs-dismiss="alert"></button>
            </div>
        <?php endif; ?>

        <?php echo $__env->yieldContent('content'); ?>
    </main>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
    document.querySelectorAll('.atm-decimal').forEach((input) => {
        const format = () => {
            const digits = input.value.replace(/\D/g, '');
            if (!digits) {
                input.value = '';
                return;
            }
            input.value = (parseInt(digits, 10) / 100).toFixed(2);
        };

        input.addEventListener('input', format);
    });

    document.querySelectorAll('.ajax-filter').forEach((form) => {
        const targetSelector = form.dataset.ajaxTarget;
        const target = document.querySelector(targetSelector);
        const exportLink = form.querySelector('.export-link');

        const updateExportLink = () => {
            if (!exportLink) {
                return;
            }

            const params = new URLSearchParams(new FormData(form));
            params.set('export', 'xls');
            exportLink.href = `${form.action}?${params.toString()}`;
        };

        form.addEventListener('submit', async (event) => {
            event.preventDefault();

            const params = new URLSearchParams(new FormData(form));
            const url = `${form.action}?${params.toString()}`;
            const response = await fetch(url, {
                headers: {
                    'X-Requested-With': 'XMLHttpRequest',
                },
            });
            const html = await response.text();
            const parsed = new DOMParser().parseFromString(html, 'text/html');
            const replacement = parsed.querySelector(targetSelector);

            if (target && replacement) {
                target.innerHTML = replacement.innerHTML;
                window.history.replaceState({}, '', url);
                updateExportLink();
            }
        });

        form.addEventListener('change', updateExportLink);
        form.addEventListener('input', updateExportLink);
        updateExportLink();
    });
</script>
</body>
</html>
<?php /**PATH F:\christopher\currencychanger\resources\views/layouts/app.blade.php ENDPATH**/ ?>