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

<?= $this->section('content') ?>
<?php
$catalogid = '';
$catalognumber = '';
$productname = '';
$nie = '';
$producttypeid = '';
$vendorid = '';
$manufacturer = '';
$productaliasid = '';
$createdate = '';
if(isset($productcatalog)) { $data = $productcatalog[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
	if(isset($data['catalogid'])) { $catalogid= $data['catalogid']; }
	$catalognumber = $data['catalognumber'];
	$productname = $data['productname'];
	$nie = $data['nie'];
	$producttypeid = $data['producttypeid'];
	$vendorid = $data['vendorid'];
	$manufacturer = $data['manufacturer'];
	$productaliasid = $data['productaliasid'];
}
?>
<div class="form-body">
	<h3 class="card-title">Product Catalog Editor</h3>
	<hr>
	<?php 
	if(isset($validation)) {
	?>
		<div class='alert alert-danger alert-dismissible'>
			<?= $validation->listErrors(); ?>
			<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <span aria-hidden="true"></span> </button>
		</div>
	<?php
	}
	?>
	<form method='post'>
		<input type='hidden' name='catalogid' value='<?=$catalogid;?>'/>
		<div class="form-group row">
			<label class="col-3 col-form-label">Catalog#</label>
			<div class="col-9"><input class="form-control" type="text" name='catalognumber' value="<?=$catalognumber;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Product Name</label>
			<div class="col-9"><input class="form-control" type="text" name='productname' value="<?=$productname;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">NIE (Nomor Ijin Edar)</label>
			<div class="col-9"><input class="form-control" type="text" name='nie' value="<?=$nie;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Product Type</label>
			<div class="col-9">
				<select class="form-control select2" name='producttypeid' >
					<option value=''>-</option>
					<?php
					foreach ($producttype as $data) {
						$qproducttypeid = $data['producttypeid'];
						$qtexts = $data['texts'];
						if ($qproducttypeid == $producttypeid ) { echo "<option value='$qproducttypeid' selected>$qtexts</option>"; }
						else { echo "<option value='$qproducttypeid'>$qtexts</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Vendor</label>
			<div class="col-9">
				<select class="form-control select2" name='vendorid' >
					<option value=''>-</option>
					<?php
					foreach ($vendors as $data) {
						$qvendorid = $data['vendorid'];
						$qvendorname = $data['vendorname'];
						if ($qvendorid == $vendorid) { echo "<option value='$qvendorid' selected>$qvendorname</option>"; }
						else { echo "<option value='$qvendorid'>$qvendorname</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Manufacturer</label>
			<div class="col-9"><input class="form-control" type="text" name='manufacturer' value="<?=$manufacturer;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-3 col-form-label">Product Alias</label>
			<div class="col-9">
				<select class="form-control select2" name='productaliasid' >
					<option value=''>-</option>
					<?php
					foreach ($productalias as $data) {
						$qproductaliasid = $data['productaliasid'];
						$qproductaliastext = $data['productaliastext'];
						if ($qproductaliasid == $productaliasid) { echo "<option value='$qproductaliasid' selected>$qproductaliastext</option>"; }
						else { echo "<option value='$qproductaliasid'>$qproductaliastext</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<button type="button" class="btn btn-dark float-start" onclick="window.close()">Cancel</button>
		<button type="submit" class="btn btn-success text-white float-end"> <i class="fa fa-check"></i> Submit</button>
	</form>
</div>
<?= $this->endSection() ?>