<?php $__env->startSection('content'); ?>
<div class="p-6">
  <h1 class="text-2xl font-bold mb-6 text-slate-700">Scrap Management</h1>

  <?php if(session('success')): ?>
    <div class="mb-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 rounded">
      <?php echo e(session('success')); ?>

    </div>
  <?php endif; ?>

  
  <form method="POST" action="<?php echo e(route('asset.scraps.store')); ?>" enctype="multipart/form-data"
        class="bg-white shadow p-4 rounded-xl grid md:grid-cols-6 gap-3 mb-6">
    <?php echo csrf_field(); ?>

    <div class="md:col-span-2">
      <label class="block text-xs font-semibold text-slate-500 mb-1">Asset</label>
      <select id="assetSelect" name="asset_id" required class="border rounded-lg px-3 py-2 w-full">
        <option value="">Select Asset</option>
        <?php $__currentLoopData = $assetsAvailable; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <option value="<?php echo e($a->id); ?>"><?php echo e($a->asset_tag); ?> (<?php echo e($a->device_type); ?>)</option>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </select>
      <p class="text-[11px] text-slate-400 mt-1">Type to search assets…</p>
    </div>

    <div>
      <label class="block text-xs font-semibold text-slate-500 mb-1">Reason</label>
      <input type="text" name="reason" placeholder="e.g. Motherboard failure / Obsolete"
             class="border rounded-lg px-3 py-2 w-full focus:ring-2 focus:ring-sky-500">
    </div>

    <div>
      <label class="block text-xs font-semibold text-slate-500 mb-1">Vendor (optional)</label>
      <input type="text" name="vendor" placeholder="Disposal vendor"
             class="border rounded-lg px-3 py-2 w-full focus:ring-2 focus:ring-sky-500">
    </div>

    <div>
      <label class="block text-xs font-semibold text-slate-500 mb-1">Scrap Date</label>
      <input type="date" name="scrap_date" class="border rounded-lg px-3 py-2 w-full focus:ring-2 focus:ring-sky-500">
    </div>

    <div class="md:col-span-2">
      <label class="block text-xs font-semibold text-slate-500 mb-1">Certificate (PDF/JPG/PNG)</label>
      <input type="file" name="certificate" accept=".pdf,.jpg,.jpeg,.png"
             class="border rounded-lg px-3 py-2 w-full focus:ring-2 focus:ring-sky-500">
    </div>

    <div class="md:col-span-1 flex items-end">
      <button class="bg-gradient-to-r from-rose-500 to-red-600 text-white px-5 py-2.5 rounded-lg hover:opacity-90 font-medium w-full">
        Scrap Asset
      </button>
    </div>
  </form>

  
  <div class="bg-white rounded-xl shadow overflow-hidden">
    <table class="min-w-full text-sm text-slate-700">
      <thead class="bg-gradient-to-r from-rose-600 to-red-600 text-white">
        <tr>
          <th class="px-4 py-3 text-left">#</th>
          <th class="px-4 py-3 text-left">Asset</th>
          <th class="px-4 py-3 text-left">Reason</th>
          <th class="px-4 py-3 text-left">Vendor</th>
          <th class="px-4 py-3 text-left">Scrap Date</th>
          <th class="px-4 py-3 text-left">Status</th>
          <th class="px-4 py-3 text-left">Certificate</th>
          <th class="px-4 py-3 text-right">Actions</th>
        </tr>
      </thead>
      <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $scraps; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <tr class="border-b hover:bg-slate-50">
          <td class="px-4 py-3"><?php echo e($scraps->firstItem() + $i); ?></td>
          <td class="px-4 py-3 font-medium"><?php echo e($s->asset->asset_tag ?? '-'); ?> (<?php echo e($s->asset->device_type ?? '-'); ?>)</td>
          <td class="px-4 py-3"><?php echo e($s->reason ?? '—'); ?></td>
          <td class="px-4 py-3"><?php echo e($s->vendor ?? '—'); ?></td>
          <td class="px-4 py-3"><?php echo e($s->scrap_date ?? '—'); ?></td>
          <td class="px-4 py-3">
            <?php if($s->status == 'Scrapped'): ?>
              <span class="px-2 py-1 text-xs rounded bg-rose-100 text-rose-700 font-semibold">Scrapped</span>
            <?php else: ?>
              <span class="px-2 py-1 text-xs rounded bg-emerald-100 text-emerald-700 font-semibold">Restored</span>
            <?php endif; ?>
          </td>
          <td class="px-4 py-3">
            <?php if($s->certificate_path): ?>
              <div class="flex items-center gap-3">
                <a href="<?php echo e(route('asset.scraps.certificate.view', $s->id)); ?>" target="_blank"
                   class="inline-flex items-center gap-1 text-sky-700 hover:underline">
                  <i class="fa-solid fa-file"></i> View
                </a>
                <a href="<?php echo e(route('asset.scraps.certificate.download', $s->id)); ?>"
                   class="inline-flex items-center gap-1 text-slate-700 hover:underline">
                  <i class="fa-solid fa-download"></i> Download
                </a>
              </div>
            <?php else: ?>
              <span class="text-slate-400">—</span>
            <?php endif; ?>
          </td>
          <td class="px-4 py-3 text-right space-x-3">
            <?php if($s->status == 'Scrapped'): ?>
              <form method="POST" action="<?php echo e(route('asset.scraps.restore', $s->id)); ?>" class="inline">
                <?php echo csrf_field(); ?>
                <button class="text-emerald-600 hover:underline">Restore</button>
              </form>
            <?php endif; ?>
            <form method="POST" action="<?php echo e(route('asset.scraps.destroy', $s->id)); ?>" class="inline">
              <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
              <button onclick="return confirm('Delete scrap record?')" class="text-red-600 hover:underline">Delete</button>
            </form>
          </td>
        </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
          <tr><td colspan="8" class="text-center py-4 text-slate-500">No scrapped assets yet.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>

    <div class="p-4 border-t bg-slate-50">
      <?php echo e($scraps->links('pagination::tailwind')); ?>

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

<?php $__env->startPush('scripts'); ?>
  
  <link href="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/css/tom-select.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/tom-select@2.3.1/dist/js/tom-select.complete.min.js"></script>
  <script>
    document.addEventListener('DOMContentLoaded', function () {
      if (window.TomSelect) {
        new TomSelect('#assetSelect', {
          create: false,
          maxOptions: 5000,
          placeholder: 'Search asset…',
          sortField: {field: 'text', direction: 'asc'}
        });
      }
    });
  </script>
<?php $__env->stopPush(); ?>

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

<?php echo $__env->make('asset.partials.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /media/linux/Archive/pac technologies/7oct25_backup/resources/views/asset/scraps/index.blade.php ENDPATH**/ ?>