<?php $__env->startSection('title', __('Reports')); ?>
<?php $__env->startSection('active', 'reports'); ?>
<?php $__env->startSection('page_eyebrow', 'Reports'); ?>
<?php $__env->startSection('page_heading', 'Inspection reports'); ?>

<?php $__env->startSection('content'); ?>
  <?php
    $statusClasses = [
      'ready' => 'bg-emerald-50 text-emerald-600',
      'draft' => 'bg-amber-50 text-amber-600',
      'pending' => 'bg-gray-100 text-gray-600',
    ];
    $activeCollection = $collections->firstWhere('id', (int) $filters['collection_id']);
  ?>

  <div class="rounded-2xl border border-[#c7d3fc] bg-[#eff3fe] p-6 lg:p-8">
    <div class="flex flex-col gap-5">
      <div>
        <p class="text-xs font-medium text-[#4f6ef7]"><?php echo e(__('Dynamic report queue')); ?> · <?php echo e(__('Workspace')); ?>: <?php echo e($activeWorkspace->name); ?></p>
        <h2 class="mt-2 text-2xl font-bold tracking-tight lg:text-3xl"><span data-live="readyReports"><?php echo e($stats['ready']); ?></span> <?php echo e(__('reports ready to export.')); ?></h2>
        <p class="mt-2 max-w-2xl text-sm leading-6 text-gray-500">
          <?php echo e($activeCollection ? __('Filtered to collection: :name', ['name' => $activeCollection->displayName()]) : __('Track generated inspection reports, draft summaries, and pending documents from live report records.')); ?>

        </p>
      </div>

      <div class="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
        <?php $__currentLoopData = $workspaces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $workspace): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <a href="<?php echo e(route('reports.index', ['workspace_id' => $workspace->id])); ?>" data-spa-link class="rounded-xl border p-4 transition-colors <?php echo e((int) $filters['workspace_id'] === $workspace->id ? 'border-[#4f6ef7] bg-white shadow-sm' : 'border-[#c7d3fc]/70 bg-white/60 hover:bg-white'); ?>">
            <div class="flex items-center justify-between gap-3">
              <p class="truncate text-sm font-semibold text-gray-900"><?php echo e($workspace->name); ?></p>
              <span class="rounded-full bg-[#eff3fe] px-2 py-0.5 text-[11px] font-medium text-[#4f6ef7]"><?php echo e($workspace->collections_count); ?></span>
            </div>
            <p class="mt-2 text-xs text-gray-500"><?php echo e(__('Ready reports')); ?></p>
            <p class="mt-1 text-lg font-bold"><?php echo e($workspace->ready_reports_count); ?> / <?php echo e($workspace->reports_count); ?></p>
          </a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </div>

      <form id="reportFilterForm" method="GET" action="<?php echo e(route('reports.index')); ?>" class="grid w-full gap-3 md:grid-cols-2 xl:grid-cols-[1fr_220px_220px_160px_auto]">
        <input name="search" value="<?php echo e($filters['search']); ?>" type="search" placeholder="<?php echo e(__('Search report...')); ?>" class="h-11 rounded-xl border border-[#c7d3fc] bg-white px-4 text-sm outline-none focus:border-[#4f6ef7] focus:ring-2 focus:ring-[#4f6ef7]/20">
        <select id="reportWorkspaceSelect" name="workspace_id" class="h-11 rounded-xl border border-[#c7d3fc] bg-white px-4 text-sm outline-none focus:border-[#4f6ef7] focus:ring-2 focus:ring-[#4f6ef7]/20">
          <?php $__currentLoopData = $workspaces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $workspace): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($workspace->id); ?>" <?php if((int) $filters['workspace_id'] === $workspace->id): echo 'selected'; endif; ?>><?php echo e($workspace->name); ?></option>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <select id="reportCollectionSelect" name="collection_id" class="h-11 rounded-xl border border-[#c7d3fc] bg-white px-4 text-sm outline-none focus:border-[#4f6ef7] focus:ring-2 focus:ring-[#4f6ef7]/20">
          <option value=""><?php echo e(__('All collections')); ?></option>
          <?php $__currentLoopData = $collections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $collection): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($collection->id); ?>" <?php if((int) $filters['collection_id'] === $collection->id): echo 'selected'; endif; ?>><?php echo e($collection->displayName()); ?></option>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <select name="status" class="h-11 rounded-xl border border-[#c7d3fc] bg-white px-4 text-sm outline-none focus:border-[#4f6ef7] focus:ring-2 focus:ring-[#4f6ef7]/20">
          <option value=""><?php echo e(__('All status')); ?></option>
          <?php $__currentLoopData = ['ready', 'draft', 'pending']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($status); ?>" <?php if($filters['status'] === $status): echo 'selected'; endif; ?>><?php echo e(Str::headline($status)); ?></option>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <button type="submit" class="h-11 rounded-xl bg-[#4f6ef7] px-4 text-sm font-medium text-white shadow-sm hover:bg-[#3d5ce0]"><?php echo e(__('Filter')); ?></button>
      </form>
    </div>
  </div>

  <div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
    <div class="panel rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
      <p class="text-sm font-medium text-gray-500"><?php echo e(__('Total Reports')); ?></p>
      <p class="mt-2 text-2xl font-bold tracking-tight"><?php echo e($stats['total']); ?></p>
      <p class="mt-2 text-xs font-medium text-[#4f6ef7]"><?php echo e(__('From inspection reports')); ?></p>
    </div>
    <div class="panel rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
      <p class="text-sm font-medium text-gray-500"><?php echo e(__('Ready')); ?></p>
      <p class="mt-2 text-2xl font-bold tracking-tight" data-live="readyReports"><?php echo e($stats['ready']); ?></p>
      <p class="mt-2 text-xs font-medium text-emerald-500"><?php echo e(__('Available now')); ?></p>
    </div>
    <div class="panel rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
      <p class="text-sm font-medium text-gray-500"><?php echo e(__('Draft')); ?></p>
      <p class="mt-2 text-2xl font-bold tracking-tight" data-live="draftReports"><?php echo e($stats['draft']); ?></p>
      <p class="mt-2 text-xs font-medium text-amber-500"><?php echo e(__('Needs review')); ?></p>
    </div>
    <div class="panel rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
      <p class="text-sm font-medium text-gray-500"><?php echo e(__('Pending')); ?></p>
      <p class="mt-2 text-2xl font-bold tracking-tight" data-live="pendingReports"><?php echo e($stats['pending']); ?></p>
      <p class="mt-2 text-xs font-medium text-gray-400"><?php echo e(__('Waiting on scan')); ?></p>
    </div>
  </div>

  <div class="rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
    <div class="mb-4 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
      <h3 class="text-base font-semibold tracking-tight"><?php echo e(__('Report list')); ?></h3>
      <p class="text-sm text-gray-400"><?php echo e(__(':count matched', ['count' => $reports->total()])); ?></p>
    </div>

    <div class="overflow-x-auto">
      <table class="w-full text-left text-sm">
        <thead class="text-xs uppercase text-gray-400">
          <tr>
            <th class="px-3 py-3"><?php echo e(__('Report')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Collection')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Property')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Status')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Findings')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Published')); ?></th>
            <th class="px-3 py-3"><?php echo e(__('Summary')); ?></th>
          </tr>
        </thead>
        <tbody class="divide-y divide-gray-100">
          <?php $__empty_1 = true; $__currentLoopData = $reports; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $report): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
              <td class="px-3 py-3">
                <a href="<?php echo e(route('reports.show', $report)); ?>" data-spa-link class="font-medium text-[#4f6ef7] hover:text-[#3d5ce0]"><?php echo e($report->report_number); ?></a>
              </td>
              <td class="px-3 py-3">
                <p class="font-medium"><?php echo e($report->inspection->collection?->displayName() ?? __('Unbatched')); ?></p>
                <p class="mt-0.5 text-xs text-gray-400"><?php echo e($report->inspection->collection?->workspace?->name ?? $activeWorkspace->name); ?></p>
              </td>
              <td class="px-3 py-3">
                <p class="font-medium"><?php echo e($report->inspection->property_name); ?></p>
                <p class="mt-0.5 text-xs text-gray-400"><?php echo e($report->inspection->property_address); ?></p>
              </td>
              <td class="px-3 py-3">
                <span class="rounded-lg px-2 py-1 text-xs font-medium <?php echo e($statusClasses[$report->status] ?? 'bg-gray-100 text-gray-600'); ?>">
                  <?php echo e(Str::headline($report->status)); ?>

                </span>
              </td>
              <td class="px-3 py-3"><?php echo e($report->inspection->damageFindings->count()); ?></td>
              <td class="px-3 py-3"><?php echo e($report->published_at?->format('M d, Y') ?? '-'); ?></td>
              <td class="max-w-xs px-3 py-3 text-gray-500"><?php echo e(Str::limit($report->summary ?? 'No summary yet.', 72)); ?></td>
            </tr>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
              <td colspan="7" class="px-3 py-10 text-center text-sm text-gray-400"><?php echo e(__('No reports match the current filters.')); ?></td>
            </tr>
          <?php endif; ?>
        </tbody>
      </table>
    </div>

    <div class="mt-5">
      <?php echo e($reports->links()); ?>

    </div>
  </div>

  <div class="rounded-2xl border border-gray-100 bg-white p-5 shadow-sm">
    <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
      <div>
        <h3 class="text-base font-semibold"><?php echo e(__('Report Actions')); ?></h3>
        <p class="text-sm text-gray-400"><?php echo e(__('Live synced at')); ?> <span data-live-updated-at>--:--:--</span></p>
      </div>
      <button type="button" onclick="showPageToast('Report queue refreshed.')" class="rounded-xl border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50"><?php echo e(__('Refresh Queue')); ?></button>
    </div>
  </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script data-page-script>
  function showPageToast(message) {
    const toast = document.createElement('div');
    toast.className = 'fixed bottom-6 right-6 z-[60] rounded-xl bg-gray-900 px-4 py-3 text-sm text-white shadow-xl';
    toast.textContent = message;
    document.body.appendChild(toast);
    setTimeout(() => toast.remove(), 2500);
  }

  document.getElementById('reportWorkspaceSelect')?.addEventListener('change', () => {
    const collection = document.getElementById('reportCollectionSelect');
    if (collection) collection.value = '';
    document.getElementById('reportFilterForm')?.submit();
  });
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\ariqa\Documents\matkul\smster 4\data sains\prj\homeinspector\resources\views/reports/index.blade.php ENDPATH**/ ?>