<?php $__env->startSection('content'); ?>
<div class="content-header row">
    <div class="content-header-left col-md-6 col-12 mb-2 breadcrumb-new">
        <h3 class="content-header-title mb-0 d-inline-block">تعديل الجروب</h3>
    </div>
</div>

<div class="content-body">
    <section id="striped-row-form-layouts">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">تعديل بيانات الجروب</h4>
                    </div>
                    <div class="card-content collapse show">
                        <div class="card-body">
                            <form method="POST" action="<?php echo e(route('groups.update', $group->id)); ?>">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('PUT'); ?>

                                <div class="row">
                                    <!-- نوع الجروب -->
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>نوع الجروب</label>
                                            <select name="type" id="groupType" class="form-control" required>
                                                <option value="main" <?php echo e($group->parent_id === null ? 'selected' : ''); ?>>رئيسي</option>
                                                <option value="sub" <?php echo e($group->parent_id !== null ? 'selected' : ''); ?>>فرعي</option>
                                            </select>
                                        </div>
                                    </div>

                                    <!-- جروب أب -->
                                    <div class="col-md-6" id="parentGroupDiv">
                                        <div class="form-group">
                                            <label>جروب أب (اختياري)</label>
                                            <select name="parent_id" class="form-control">
                                                <option value="">-- بدون جروب أب --</option>
                                                <?php $__currentLoopData = $groups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $g): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($g->parent_id === null): ?> <!-- عرض الجروبات الرئيسية فقط -->
                                                        <option value="<?php echo e($g->id); ?>" <?php if($group->parent_id == $g->id): ?> selected <?php endif; ?>><?php echo e($g->name); ?></option>
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                            <?php $__errorArgs = ['parent_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>
                                </div>

                                <div class="row mt-2">
                                    <!-- اسم الجروب -->
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>اسم الجروب</label>
                                            <input type="text" name="name" class="form-control" value="<?php echo e(old('name', $group->name)); ?>" required>
                                            <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>
                                </div>

                                <!-- أزرار الحفظ والإلغاء -->
                                <div class="form-group mt-2">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="ft-save"></i> حفظ التعديلات
                                    </button>
                                    <a href="<?php echo e(route('groups.index')); ?>" class="btn btn-secondary">
                                        <i class="ft-x"></i> إلغاء
                                    </a>
                                </div>

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

<?php $__env->startSection('scripts'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    let groupType = document.getElementById('groupType');
    let parentDiv = document.getElementById('parentGroupDiv');
    let parentSelect = parentDiv.querySelector('select[name="parent_id"]');

    function toggleParent() {
        if(groupType.value === 'sub') {
            parentDiv.style.display = 'block';
            parentSelect.disabled = false;
        } else {
            parentDiv.style.display = 'none';
            parentSelect.disabled = true;
            parentSelect.value = "";
        }
    }

    // تفعيل عند التحميل
    toggleParent();

    // تفعيل عند تغيير النوع
    groupType.addEventListener('change', toggleParent);
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/almaugqb/chating.bariqgreenline.com/resources/views/admin/groups/edit.blade.php ENDPATH**/ ?>