<?php $__env->startSection('title', 'Branch Management & Working Hours'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6" x-data="{ createModal: false }">

    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Branches & Operating Hours</h1>
            <p class="text-xs text-slate-500">Configure typing center branches, main branch, and 7-day working schedules.</p>
        </div>

        <button @click="createModal = true" class="px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white font-bold text-xs rounded-xl shadow-sm">
            + Add New Branch
        </button>
    </div>

    <!-- Subscription Branch Limit Indicator (Requirement 12) -->
    <div class="bg-sky-50 dark:bg-sky-950/40 border border-sky-200 dark:border-sky-800 p-4 rounded-2xl flex items-center justify-between text-xs">
        <div class="flex items-center space-x-2 rtl:space-x-reverse font-bold text-sky-800 dark:text-sky-200">
            <svg class="w-5 h-5 text-sky-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
            <span>Plan Branch Limit: Currently using <?php echo e(count($branches)); ?> of <?php echo e($allowedBranches); ?> allowed branches.</span>
        </div>
        <?php if(count($branches) >= $allowedBranches): ?>
            <span class="px-3 py-1 bg-amber-500 text-white font-extrabold rounded-lg">Limit Reached (Upgrade Available)</span>
        <?php endif; ?>
    </div>

    <!-- Branches List Cards (Requirements 11, 13) -->
    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
        <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="bg-white dark:bg-slate-800 rounded-3xl p-6 border border-slate-200 dark:border-slate-700/60 shadow-sm space-y-4 text-xs">
                <div class="flex items-center justify-between border-b border-slate-100 dark:border-slate-700 pb-3">
                    <div class="flex items-center space-x-2 rtl:space-x-reverse">
                        <h3 class="font-extrabold text-slate-900 dark:text-white text-sm"><?php echo e($branch->name); ?></h3>
                        <?php if($branch->is_main): ?>
                            <span class="px-2 py-0.5 rounded bg-emerald-100 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300 font-bold text-[10px]">MAIN BRANCH</span>
                        <?php endif; ?>
                    </div>
                    <span class="font-mono text-slate-400 font-bold">Code: <?php echo e($branch->code); ?></span>
                </div>

                <div class="space-y-1 text-slate-600 dark:text-slate-300">
                    <p>Emirate: <strong><?php echo e($branch->emirate); ?></strong></p>
                    <p>Phone: <?php echo e($branch->phone ?? 'N/A'); ?> • Email: <?php echo e($branch->email ?? 'N/A'); ?></p>
                </div>

                <!-- 7-Day Working Hours Grid (Requirement 19) -->
                <div class="pt-2">
                    <h4 class="font-bold text-slate-700 dark:text-slate-300 mb-2">7-Day Working Schedule</h4>
                    <form action="<?php echo e(route('app.settings.branches.working_hours', $branch->id)); ?>" method="POST" class="space-y-2">
                        <?php echo csrf_field(); ?>
                        <?php $days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; ?>
                        <?php $__currentLoopData = $days; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $day): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php $wh = $branch->workingHours->where('day_of_week', $day)->first(); ?>
                            <div class="flex items-center justify-between p-2 rounded-xl bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-700">
                                <span class="font-bold w-24 text-slate-800 dark:text-slate-200"><?php echo e($day); ?></span>
                                <div class="flex items-center space-x-2 rtl:space-x-reverse">
                                    <input type="time" name="hours[<?php echo e($day); ?>][opening_time]" value="<?php echo e($wh->opening_time ?? '09:00'); ?>" class="px-2 py-1 bg-white dark:bg-slate-800 border rounded text-[11px]">
                                    <span>to</span>
                                    <input type="time" name="hours[<?php echo e($day); ?>][closing_time]" value="<?php echo e($wh->closing_time ?? '21:00'); ?>" class="px-2 py-1 bg-white dark:bg-slate-800 border rounded text-[11px]">
                                    <label class="flex items-center space-x-1 rtl:space-x-reverse text-[10px] cursor-pointer">
                                        <input type="checkbox" name="hours[<?php echo e($day); ?>][is_closed]" value="1" <?php echo e(($wh && $wh->is_closed) ? 'checked' : ''); ?> class="rounded">
                                        <span>Closed</span>
                                    </label>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <button type="submit" class="w-full py-1.5 bg-slate-800 text-white font-bold rounded-xl mt-2">Save Schedule</button>
                    </form>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <!-- Create Branch Modal -->
    <div x-show="createModal" class="fixed inset-0 bg-slate-950/80 backdrop-blur-sm z-50 flex items-center justify-center p-4" x-cloak>
        <div class="bg-white dark:bg-slate-800 rounded-3xl max-w-md w-full p-6 border border-slate-200 dark:border-slate-700 shadow-2xl space-y-4 text-xs">
            <h3 class="text-sm font-bold text-slate-900 dark:text-white uppercase tracking-wider">Add New Branch Workspace</h3>

            <form action="<?php echo e(route('app.settings.branches.store')); ?>" method="POST" class="space-y-3">
                <?php echo csrf_field(); ?>
                <div>
                    <label class="block font-semibold mb-1">Branch Name *</label>
                    <input type="text" name="name" required placeholder="Al Qusais Branch" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl">
                </div>

                <div>
                    <label class="block font-semibold mb-1">Branch Code</label>
                    <input type="text" name="code" placeholder="DXB-QS01" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl">
                </div>

                <div>
                    <label class="block font-semibold mb-1">Emirate *</label>
                    <select name="emirate" class="w-full px-3 py-2 bg-slate-50 dark:bg-slate-900 border border-slate-300 dark:border-slate-700 rounded-xl">
                        <option value="Dubai" selected>Dubai</option>
                        <option value="Abu Dhabi">Abu Dhabi</option>
                        <option value="Sharjah">Sharjah</option>
                        <option value="Ajman">Ajman</option>
                    </select>
                </div>

                <div class="flex justify-end space-x-2 rtl:space-x-reverse pt-2">
                    <button type="button" @click="createModal = false" class="px-4 py-2 bg-slate-200 dark:bg-slate-700 text-slate-700 dark:text-slate-200 font-bold rounded-xl">Cancel</button>
                    <button type="submit" class="px-5 py-2 bg-sky-600 text-white font-bold rounded-xl">Create Branch</button>
                </div>
            </form>
        </div>
    </div>

</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\typingcenter\resources\views\tenant\settings\branches\index.blade.php ENDPATH**/ ?>