<?php $__env->startSection('title', $cfg['title']); ?>
<?php $__env->startSection('crumbs', '<b>'.$cfg['title'].'</b>'); ?>
<?php $__env->startSection('content'); ?>
<div class="card">
  <div class="card-h"><h2><?php echo e($cfg['title']); ?></h2>
    <div class="sp">
      <?php if(perm($cfg['perm'].'.create') && empty($cfg['no_create'])): ?><a class="btn btn-pri btn-sm" href="<?php echo e(crud_url($key,'create')); ?>">+ New <?php echo e($cfg['singular']); ?></a><?php endif; ?>
    </div>
  </div>
  <div class="card-b">
    <form method="GET" class="toolbar no-print">
      <?php if(!empty($cfg['search'])): ?><input type="search" name="q" value="<?php echo e(request('q')); ?>" placeholder="Search…"><?php endif; ?>
      <?php $__currentLoopData = $cfg['fields']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fname => $f): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if(!empty($f['filter'])): ?>
          <?php if(($f['type'] ?? '') === 'select' && !empty($f['options'])): ?>
            <select name="<?php echo e($fname); ?>"><option value="">— <?php echo e($f['label']); ?> —</option>
            <?php $__currentLoopData = $f['options']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ov => $ol): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($ov); ?>" <?php echo e(request($fname)==$ov?'selected':''); ?>><?php echo e($ol); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
          <?php elseif(!empty($options[$fname])): ?>
            <select name="<?php echo e($fname); ?>"><option value="">— <?php echo e($f['label']); ?> —</option>
            <?php $__currentLoopData = $options[$fname]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ov => $ol): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($ov); ?>" <?php echo e(request($fname)==$ov?'selected':''); ?>><?php echo e($ol); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
          <?php endif; ?>
        <?php endif; ?>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      <button class="btn btn-sm">Filter</button>
      <?php if(request('q') || count($activeFilters)): ?><a class="btn btn-sm btn-ghost" href="<?php echo e(crud_url($key,'index')); ?>">Reset</a><?php endif; ?>
    </form>
    <div class="twrap"><table class="tbl">
      <thead><tr>
        <?php $__currentLoopData = $cfg['columns']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $field => $spec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <?php [$label,$fmt] = array_pad(explode('|',$spec,2),2,null); ?>
          <th <?php if(in_array($fmt,['money','qty'])): ?>class="r"<?php endif; ?>><?php echo e($label); ?></th>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <th class="no-print">Actions</th>
      </tr></thead>
      <tbody>
      <?php $__empty_1 = true; $__currentLoopData = $rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><tr>
        <?php $__currentLoopData = $cfg['columns']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $field => $spec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <?php [$label,$fmt] = array_pad(explode('|',$spec,2),2,null); $v = data_get($row,$field); ?>
          <td <?php if(in_array($fmt,['money','qty'])): ?>class="r"<?php endif; ?>>
            <?php if($fmt==='bool'): ?> <?php echo $v ? '<span class="bdg b-ok">Yes</span>' : '<span class="muted">—</span>'; ?>

            <?php elseif($fmt==='money'): ?> <?php echo e(money($v)); ?>

            <?php elseif($fmt==='qty'): ?> <?php echo e(qty($v)); ?>

            <?php elseif($fmt==='date'): ?> <?php echo e(fdate($v)); ?>

            <?php elseif($fmt==='badge'): ?> <span class="bdg b-<?php echo e(statusClass($v)); ?>"><?php echo e($v ?? '—'); ?></span>
            <?php else: ?> <?php echo e(is_string($v) && strlen($v)>70 ? substr($v,0,70).'…' : ($v ?? '—')); ?>

            <?php endif; ?>
          </td>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <td class="no-print"><div class="row-actions">
          <a class="btn btn-sm btn-ghost" href="<?php echo e(crud_url($key,'show',$row->id)); ?>">View</a>
          <?php if(perm($cfg['perm'].'.edit') && empty($cfg['no_edit']) && ($editUrl = crud_route($key,'edit',$row->id))): ?><a class="btn btn-sm btn-ghost" href="<?php echo e($editUrl); ?>">Edit</a><?php endif; ?>
          <?php $__currentLoopData = ($cfg['transitions'] ?? []); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tkey => $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php if(perm($cfg['perm'].'.approve') && isset($row->status) && in_array($row->status,$t['from'])): ?>
            <form method="POST" action="<?php echo e(route('crud.transition',['key'=>$key,'id'=>$row->id,'action'=>$tkey])); ?>" data-confirm="Set status to <?php echo e($t['to']); ?>?" style="display:inline"><?php echo csrf_field(); ?><button class="btn btn-sm <?php echo e(($t['class']??'')==='ok'?'btn-ok':((($t['class']??'')==='danger'?'btn-danger':'btn-info'))); ?>"><?php echo e($t['label']); ?></button></form>
            <?php endif; ?>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          <?php if(perm($cfg['perm'].'.delete') && empty($cfg['no_delete'])): ?>
          <form method="POST" action="<?php echo e(crud_url($key,'destroy',$row->id)); ?>" data-confirm="Delete this record?" style="display:inline"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-sm btn-danger">Del</button></form>
          <?php endif; ?>
        </div></td>
      </tr><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><tr><td colspan="<?php echo e(count($cfg['columns'])+1); ?>" class="muted c">No records found.</td></tr><?php endif; ?>
      </tbody>
    </table></div>
    <?php echo e($rows->links()); ?>

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

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/user/nowills-sqc-erp/resources/views/crud/index.blade.php ENDPATH**/ ?>