<?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">عرض المستند</h3>
  </div>
</div>

<div class="content-body">
  <div class="card">
    <div class="card-header bg-blue-grey bg-lighten-4">
      <h4 class="card-title">تفاصيل المستند رقم <?php echo e($document->document_number); ?></h4>
    </div>
    <div class="card-body">
      <p><strong>العنوان:</strong> <?php echo e($document->subject); ?></p>
      <p><strong>تاريخ المستند:</strong> <?php echo e($document->document_date->format('Y-m-d')); ?></p>
      <p><strong>من:</strong> <?php echo e($document->sender->name ?? 'غير محدد'); ?></p>
      <p><strong>إلى:</strong> 
        <?php if($document->receiverUser): ?>
          <?php echo e($document->receiverUser->name); ?>

        <?php elseif($document->receiverGroup): ?>
          <?php echo e($document->receiverGroup->name); ?>

        <?php else: ?>
          -
        <?php endif; ?>
      </p>
      <p><strong>النص:</strong></p>
      <div class="border p-2 bg-light"><?php echo $document->content; ?></div>

    <?php if($document->attachments && is_array($document->attachments)): ?>
    <hr>
    <strong>المرفقات:</strong>
    <ul>
        <?php $__currentLoopData = $document->attachments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <li>
                <a href="<?php echo e(asset('storage/'.$file['path'])); ?>" target="_blank">
                    <?php echo e($file['name']); ?>

                </a>
            </li>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </ul>
<?php endif; ?>


      <hr>
      <p class="text-muted">
        <em>تم إنشاء المستند من قبل <?php echo e($document->sender->name ?? 'غير محدد'); ?> 
        بتاريخ <?php echo e($document->created_at->format('Y-m-d H:i')); ?></em>
      </p>
    </div>
  </div>

  
 <div class="card mt-2">
  <div class="card-header bg-light">
    <h4 class="card-title">الردود</h4>
  </div>
  <div class="card-body">
    <?php $__empty_1 = true; $__currentLoopData = $document->replies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $reply): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
      <div class="border rounded p-2 mb-2">
        <p><strong><?php echo e($reply->user->name); ?></strong> 
           <span class="text-muted">(<?php echo e($reply->replied_at->format('Y-m-d H:i')); ?>)</span></p>
        <p><?php echo e($reply->reply_text); ?></p>

        <?php if($reply->attachments && is_array($reply->attachments)): ?>
          <ul>
            <?php $__currentLoopData = $reply->attachments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <li><a href="<?php echo e(asset($file['path'])); ?>" target="_blank"><?php echo e($file['name']); ?></a></li>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </ul>
        <?php endif; ?>

        <p class="text-muted"><em><?php echo e($reply->signature); ?></em></p>
      </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
      <p class="text-center text-muted">لا توجد ردود حتى الآن.</p>
    <?php endif; ?>
  </div>
</div>


  
  <div class="card mt-2">
    <div class="card-header bg-blue-grey bg-lighten-4">
      <h4 class="card-title">إضافة رد جديد</h4>
    </div>
    <div class="card-body">
      <form action="<?php echo e(route('documents.reply', $document->id)); ?>" method="POST" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <div class="form-group">
          <label>الرد</label>
          <textarea name="reply_text" class="form-control" rows="4" required></textarea>
        </div>
        <div class="form-group">
          <label>المرفقات</label>
          <input type="file" name="attachments[]" multiple class="form-control">
        </div>
        <button type="submit" class="btn btn-primary">إرسال الرد</button>
      </form>
    </div>
  </div>
</div>
<?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/show.blade.php ENDPATH**/ ?>