<?php $__env->startSection('title','Document Library'); ?>
<?php $__env->startSection('crumbs','<b>Document Library</b>'); ?>
<?php $__env->startSection('content'); ?>
<div class="card"><div class="card-h"><h2>📁 Document Library</h2>
<div class="sp no-print">
<span class="muted"><?php echo e($groups->total()); ?> document(s) · <?php echo e($totalFiles); ?> file(s) · <?php echo e(number_format($totalBytes/1048576,1)); ?> MB</span>
<?php if(perm('docs.create')): ?><a class="btn btn-sm" href="<?php echo e(route('docs-library.create')); ?>">＋ File document</a><?php endif; ?>
</div></div>
<div class="card-b">
<form method="GET" action="<?php echo e(route('docs-library.index')); ?>" class="frow no-print" style="margin-bottom:10px">
<input name="q" value="<?php echo e($req->q); ?>" placeholder="Search filename…" style="max-width:260px">
<select name="owner" style="max-width:200px">
<option value="">All owners</option>
<option value="unfiled" <?php echo e($req->owner==='unfiled'?'selected':''); ?>>Unfiled</option>
<?php $__currentLoopData = $owners; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $class => $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($class); ?>" <?php echo e($req->owner===$class?'selected':''); ?>><?php echo e($o[0]); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
<select name="kind" style="max-width:140px">
<option value="">All types</option>
<?php $__currentLoopData = ['pdf'=>'PDF','image'=>'Image','sheet'=>'Sheet','doc'=>'Doc','other'=>'Other']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k=>$l): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($k); ?>" <?php echo e($req->kind===$k?'selected':''); ?>><?php echo e($l); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</select>
<button class="btn btn-sm">Filter</button>
<?php if($req->q || $req->owner || $req->kind): ?><a class="btn btn-sm btn-ghost" href="<?php echo e(route('docs-library.index')); ?>">Reset</a><?php endif; ?>
</form>
<div class="twrap"><table class="tbl">
<thead><tr><th>Document</th><th>Linked to</th><th>Type</th><th>Size</th><th>Uploaded</th><th>By</th><th class="no-print">Actions</th></tr></thead>
<tbody>
<?php $__empty_1 = true; $__currentLoopData = $groups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $g): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
<?php $a = $g['latest']; [$ownerLabel, $ownerUrl] = \App\Http\Controllers\DocumentLibraryController::ownerInfo($a); ?>
<tr>
<td><b><?php echo e($a->file_name); ?></b>
<?php if($g['count']>1): ?><span class="bdg b-info" title="<?php echo e($g['count']); ?> versions">v<?php echo e($g['count']); ?></span><?php endif; ?>
<?php if($g['count']>1): ?>
<details><summary class="muted" style="cursor:pointer;font-size:12px">Version history</summary>
<table class="tbl" style="margin-top:4px"><tbody>
<?php $__currentLoopData = $g['versions']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vi => $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<tr><td style="white-space:nowrap">v<?php echo e($g['count']-$vi); ?></td><td><?php echo e($v->created_at->format('d M Y H:i')); ?></td>
<td><?php echo e($v->uploader->name ?? '—'); ?></td><td><?php echo e(number_format(($v->size??0)/1024,1)); ?> KB</td>
<td class="no-print"><a class="btn btn-sm btn-ghost" href="<?php echo e(route('docs-library.download',$v->id)); ?>">⬇</a>
<?php if(perm('docs.delete')): ?><form method="POST" action="<?php echo e(route('docs-library.destroy',$v->id)); ?>" data-confirm="Delete v<?php echo e($g['count']-$vi); ?> of <?php echo e($v->file_name); ?>?" style="display:inline"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-sm btn-danger">Del</button></form><?php endif; ?></td></tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</tbody></table></details>
<?php endif; ?>
</td>
<td><?php if($ownerUrl): ?><a href="<?php echo e($ownerUrl); ?>"><?php echo e($ownerLabel); ?></a><?php else: ?><span class="muted"><?php echo e($ownerLabel); ?></span><?php endif; ?></td>
<td><?php echo e(\App\Http\Controllers\DocumentLibraryController::kindOf($a->mime)); ?></td>
<td><?php echo e(number_format(($a->size??0)/1024,1)); ?> KB</td>
<td style="white-space:nowrap"><?php echo e($a->created_at->format('d M Y H:i')); ?></td>
<td><?php echo e($a->uploader->name ?? '—'); ?></td>
<td class="no-print" style="white-space:nowrap">
<a class="btn btn-sm btn-ghost" href="<?php echo e(route('docs-library.download',$a->id)); ?>">⬇ Download</a>
<?php if(perm('docs.delete')): ?><form method="POST" action="<?php echo e(route('docs-library.destroy',$a->id)); ?>" data-confirm="Delete <?php echo e($a->file_name); ?> (latest version)?" style="display:inline"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?><button class="btn btn-sm btn-danger">Del</button></form><?php endif; ?>
</td>
</tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
<tr><td colspan="7" class="muted">No documents filed yet. <?php if(perm('docs.create')): ?><a href="<?php echo e(route('docs-library.create')); ?>">File the first one →</a><?php endif; ?></td></tr>
<?php endif; ?>
</tbody></table></div>
<?php if($groups->hasPages()): ?><div style="margin-top:10px"><?php echo e($groups->links()); ?></div><?php endif; ?>
</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/docs-library/index.blade.php ENDPATH**/ ?>