<nav class="main-header navbar navbar-expand  navbar-light">
    <!-- Left navbar links -->
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
        </li>
        <li class="nav-item  d-none d-sm-inline-block">
            <a class="nav-link" data-widget="fullscreen" href="#" role="button">
                <i class="fas fa-expand-arrows-alt"></i>
            </a>
        </li>
    </ul>

    <!-- Right navbar links -->
    <ul class="navbar-nav ml-auto w-100 justify-content-end">
        <li class="nav-item w-100">
            <div class="nav-link p-0">
                <div class="input-group input-group-sm justify-content-end">
                    <div class="input-group-prepend">
                        <span class="input-group-text bg-warning">
                            <i class="fas fa-store"></i>
                        </span>
                    </div>
                    <select name="store_id"
                        class="form-control select2 select2-warning"
                        data-dropdown-css-class="select2-warning"
                        required
                        onchange="changeCustomer(this)" style="width:80%">
                        <option value="">&emsp;-- Pilih Store --&emsp;</option>
                        <?php $__currentLoopData = Cache::get('select_stores', []); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($comb->id); ?>" <?php echo e(session('store_selected') == $comb->id ? 'selected' : ''); ?>>
                            <?php echo e($comb->name); ?>

                        </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            </div>
        </li>
    </ul>

</nav>
<style>
    /* default sidebar width */
    .custom-alert-below-navbar {
        margin-left: 255px;
        transition: margin-left 0.3s ease;
        font-weight: 500;
        font-size: 15px;
        border-radius: 0;
        z-index: 1030;
    }

    /* kalau sidebar collapsed */
    .sidebar-collapse .custom-alert-below-navbar {
        margin-left: 80px;
        /* ikut ukuran sidebar collapsed */
    }
</style>
<script>
    function changeCustomer(that) {
        const selected = that.value || null;
        const selectedText = that.options[that.selectedIndex].text;

        // Dispatch event to notify other components about store change
        if (selected) {
            window.dispatchEvent(new CustomEvent('storeChanged', {
                detail: {
                    storeId: selected,
                    storeName: selectedText
                }
            }));
        }

        fetch("<?php echo e(route('change.store')); ?>", {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
                },
                body: JSON.stringify({
                    store_id: selected
                })
            })
            .then(res => res.json())
            .then(data => {
                if (data.status === 'success') {
                    // Small delay to allow event processing before reload
                    setTimeout(() => {
                        let url_active = getCookie("sidebar_active"); //function ada di baseview
                        // console.log('ketemuu : '+url_active);
                        if (url_active) {
                            window.location.href = url_active;
                        } else {
                            location.reload(); // reload biar session bisa digunakan
                        }

                    }, 100);
                } else {
                    alert(data.message || 'Failed to change store.');
                }
            }).catch(error => {
                console.error('Error:', error);
                alert('Error occurred.');
            });
    }
</script><?php /**PATH D:\LSM\resources\views/layouts/partials/navbar.blade.php ENDPATH**/ ?>