<?= $this->extend('layouts/main.php') ?>

<?= $this->section('content') ?>
<div class="page-wrapper">
	<div class="container-fluid">
		
		<div class="row page-titles">
			<div class="col-md-5 align-self-center">
				<h4 class="text-themecolor">Vendors Management Page</h4>
			</div>
			<div class="col-md-7 align-self-center text-end">
				<a class='btn btn-info text-white btn-sm' href='vendors/create/' 
					onclick="window.open(this.href, 'Create Vendors','width=900,height=600,toolbar=1,resizable=0'); return false;">
					<i class="fas fa-plus-circle"></i> Create
				</a>
			</div>
		</div>
		
		<div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-body">
						<div class="table-responsive">
							<table id="myTable" class="table display table-striped border">
								<thead>
									<th>VendorID</th> <th>Vendor Name</th> <th>Initial</th> <th>Create Date</th> <th></th>
								</thead>
								<tbody>
									<?php
									foreach($vendors as $data) {
										$vendorid = $data['vendorid'];
										$vendorname = $data['vendorname'];
										$initial = $data['initial'];
										$principal = $data['principal'];
										$classend = '';
										if( $data['createdate'] != '' ) {
											$createdate = date('d-m-Y', strtotime($data['createdate']));
										} else { $createdate = ''; }
										if( $data['enddate'] != '' ) { 
											$classend = 'class="bg-danger"'; 
											$toggletext = "<a class='btn btn-success btn-sm' href='vendors/toggle/$vendorid' 
												onclick=\"window.open(this.href, 'form','width=400,height=300,toolbar=1,resizable=0'); return false;\">
												<i class='fa-solid fa-check'></i> Enable
											</a>";
										} else {
											$toggletext = "<a class='btn btn-danger btn-sm' href='vendors/toggle/$vendorid' 
												onclick=\"window.open(this.href, 'form','width=400,height=300,toolbar=1,resizable=0'); return false;\">
												<i class='fas fa-trash-alt'></i> Disable
											</a>";
										}
									?>
									<tr <?=$classend;?>> 
										<td><?=$vendorid;?></td> <td><?=$vendorname;?></td> <td><?=$initial;?></td> <td><?=$createdate;?></td> 
										<td>
											<a class='btn btn-warning btn-sm' href='vendors/edit/<?=$vendorid;?>' 
												onclick="window.open(this.href, 'Site Editor','width=900,height=600,toolbar=1,resizable=0'); return false;">
												<i class="fas fa-pencil-alt"></i> Edit
											</a>
											<?=$toggletext;?>
										</td>
									</tr>
									<?php } ?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<?= $this->endSection() ?>

<?= $this->section('script') ?>
<script>
$(function () {
	$('#myTable').DataTable({
		"order" : []
	});
});
</script>
<?= $this->endSection() ?>