@extends('adminlte::layouts.app')

@section('htmlheader_title')
	Deletes
@endsection

@section('contentheader_title')
	Deletes
@endsection
@section('contentheader_description')
	#
@endsection
@section('page_title')
	Deletes
@endsection

<?php $data = [
	'ID'=>['id','idlink'],
	'Signature'=>['signature','signature'],
	'File Signature'=>['file_signature','file_signature'],
	'Date Created'=>['date_created','datecreatedtext'],
	'Filename'=>['filename','filename'],
	'Filesize'=>['filesize','filesize'],
	'Is Duplicate'=>['duplicate','duplicatetext'],
	'Flagged'=>['flag','flagtext'],
	'Delete'=>['remove','removecheckbox'],
];?>

@section('content')

	<div class="row">
		<div class="col-md-11 col-md-offset-1">
			<div class="panel panel-default">
				<div class="panel-heading">
					Permanently Delete Items
				</div>

				<div class="text-center">{{ $catalog->links() }}</div>

				<div class="panel-body">
					@if ($catalog->count())
						<form action="{{ $return }}" method="POST">
							<table class="table table-striped table-condensed table-hover">
								<tr>
									<th>Source</th>
									<th>Remove</th>
								</tr>

								@foreach ($catalog as $o)
									<tr>
										@php
											$d=$o->list_duplicates(TRUE); $src=[];
										@endphp
										<td>
											@if($d->where('duplicate',null)->count() > 1)
												More than 1 source?
											@elseif($d->count())
												@php($src = $d->first())
												{!! $src->view() !!}
												<table class="table table-striped table-sm table-hover small">
													@foreach($data as $k=>$v)
														<tr><th>{{$k}}</th><td>{!! $src->{$v[1]} !!}</td></tr>
													@endforeach
												</table>
											@endif
										</td>
										@foreach($d as $item)
											@if($src AND $item->id == $src->id) @continue @endif
											@php($diff=collect($src)->diffAssoc($item))
											<td>
												{!! $item->view() !!}
												<table class="table table-striped table-condensed table-hover small">
													@foreach($data as $k=>$v)
														<tr class="@if($diff->has($v[0])) danger @endif"><th>{{$k}}</th><td>{!! $item->{$v[1]} !!}</td></tr>
													@endforeach
												</table>
											</td>
										@endforeach
									</tr>
								@endforeach
							</table>
							<input type="hidden" name="pagenext" value="{{ $catalog->hasMorePages() ? $catalog->currentPage()+1 : NULL }}">
							<button class="btn btn-default">Confirm Delete</button>
							{{ csrf_field() }}
						</form>
					@else
						NONE!
					@endif
				</div>
			</div>
		</div>
	</div>
@endsection