<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel="stylesheet">

<?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" id="horz-layout-icons">بيانات المستند</h4>
                    </div>

                    <div class="card-content collapse show">
                        <div class="card-body">
                            <form class="form form-horizontal striped-rows form-bordered"
                                  method="POST"
                                  action="<?php echo e(route('documents.store')); ?>"
                                  enctype="multipart/form-data">
                                <?php echo csrf_field(); ?>

                                <div class="form-body">

                                 <div class="form-group row">
                                        <label class="col-md-3 label-control">رقم</label>
                                        <div class="col-md-9">
                                            <div class="position-relative has-icon-left">
                                                   <input type="text"
                                                       class="form-control"
                                                       value="<?php echo e($nextId ?? 'سيتم توليده تلقائيًا'); ?>"
                                                       readonly>
                                                <div class="form-control-position">
                                                    <i class="la la-tag"></i>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                          <div class="form-group row">
    <label class="col-md-3 label-control">تاريخ </label>
    <div class="col-md-9">
        <div class="position-relative has-icon-left">
            <input 
                type="date" 
                name="date" 
                required 
                class="form-control"
                value="<?php echo e(date('Y-m-d')); ?>" 
            readonly>
            <div class="form-control-position">
                <i class="la la-calendar"></i>
            </div>
        </div>
    </div>
</div>
                                       <div class="form-group row">
                                        <label class="col-md-3 label-control">رقم المستند</label>
                                        <div class="col-md-9">
                                            <div class="position-relative has-icon-left">
                                                <input type="text" name="document_number" required class="form-control" placeholder="ادخل رقم المستند  ">
                                                <div class="form-control-position">
                                                    <i class="la la-tag"></i>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    
                            

                                          <div class="form-group row">
    <label class="col-md-3 label-control">تاريخ المستند </label>
    <div class="col-md-9">
        <div class="position-relative has-icon-left">
            <input 
                type="date" 
                name="document_date" 
                required 
                class="form-control"
               
            >
            <div class="form-control-position">
                <i class="la la-calendar"></i>
            </div>
        </div>
    </div>
</div>
   <div class="form-group row">
                                        <label class="col-md-3 label-control">عنوان المستند</label>
                                        <div class="col-md-9">
                                            <div class="position-relative has-icon-left">
                                                <input type="text" name="subject" required class="form-control" placeholder="اكتب عنوان المستند">
                                                <div class="form-control-position">
                                                    <i class="la la-tag"></i>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                 

                                


                                    
                                    <div class="form-group row">
                                        <label class="col-md-3 label-control">الموضوع </label>
                                        <div class="col-md-9">
                                            <textarea name="content" class="form-control summernote" rows="9" placeholder="اكتب تفاصيل المستند هنا..."></textarea>
                                        </div>
                                    </div>

                                    
                                    <div class="form-group row">
                                        <label class="col-md-3 label-control">المرفقات</label>
                                        <div class="col-md-9">
                                            <input type="file" name="attachments[]" class="form-control" multiple>
                                        </div>
                                    </div>
                                
<div class="form-group row">
    <label class="col-md-3 label-control">إلى</label>
    <div class="col-md-9">
        <div class="position-relative has-icon-left">
            <select name="receiver_type" id="receiver_type" class="form-control" required>
                <option value="">اختر نوع المستلم</option>
                <option value="user">مستخدم</option>
                <option value="group">مجموعة</option>
            </select>
            <div class="form-control-position">
                <i class="la la-users"></i>
            </div>
        </div>
    </div>
</div>


<div class="form-group row" id="user_select" style="display:none;">
    <label class="col-md-3 label-control">اختر المستخدم</label>
    <div class="col-md-9">
        <select name="to_user_id" class="form-control">
            <option value="">اختر المستخدم</option>
            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($user->id); ?>"><?php echo e($user->name); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
    </div>
</div>


<div class="form-group row" id="group_type_select" style="display:none;">
    <label class="col-md-3 label-control">نوع الجروب</label>
    <div class="col-md-9">
        <select id="group_type" class="form-control">
            <option value="">اختر نوع الجروب</option>
            <option value="main">رئيسي</option>
            <option value="sub">فرعي</option>
        </select>
    </div>
</div>


<div class="form-group row" id="group_select" style="display:none;">
    <label class="col-md-3 label-control">اختر الجروب</label>
    <div class="col-md-9">
        <select name="to_group_id" id="group_list" class="form-control">
            <option value="">اختر الجروب</option>
            
        </select>
    </div>
</div>

                                </div>

                                <div class="form-actions right">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="la la-check-square-o"></i> حفظ المستند
                                    </button>
                                </div>

                            </form>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>
</div>
<script>
document.getElementById('receiver_type').addEventListener('change', function () {
    let type = this.value;
    document.getElementById('user_select').style.display = (type === 'user') ? 'flex' : 'none';
    document.getElementById('group_type_select').style.display = (type === 'group') ? 'flex' : 'none';
    document.getElementById('group_select').style.display = 'none';
});

document.getElementById('group_type').addEventListener('change', function () {
    let type = this.value;
    if (!type) return;

    fetch(`/admin/groups/${type}`)
        .then(response => response.json())
        .then(data => {
            let groupList = document.getElementById('group_list');
            groupList.innerHTML = '<option value="">اختر الجروب</option>';
            data.forEach(group => {
                groupList.innerHTML += `<option value="${group.id}">${group.name}</option>`;
            });
            document.getElementById('group_select').style.display = 'flex';
        });
});
</script>


<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></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/documents/create.blade.php ENDPATH**/ ?>