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

<?= $this->section('content') ?>
<?php
$vendorname = '';
$initial = '';
$principal = '';
$email_1 = '';
$email_2 = '';
$phone = '';
$website = '';
$principals = ['Y'=>'yes', 'N'=>'no'];
if(isset($vendors)) { $data = $vendors[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
	if(isset($data['vendorid'])) { $vendorid = $data['vendorid']; }
	$vendorname = $data['vendorname'];
	$initial = $data['initial'];
	$principal = $data['principal'];
	$email_1 = $data['email_1'];
	$email_2 = $data['email_2'];
	$phone = $data['phone'];
	$website = $data['website'];
}
?>
<div class="form-body">
	<h3 class="card-title">Vendor 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='vendorid' value='<?=$vendorid;?>'/>
		<div class="form-group row">
			<label class="col-2 col-form-label">Vendor Name</label>
			<div class="col-10"><input class="form-control" type="text" name='vendorname' value="<?=$vendorname;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Initial</label>
			<div class="col-10"><input class="form-control" type="text" name='initial' value="<?=$initial;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Principal</label>
			<div class="col-10">
				<select name='principal' class='form-control'>
					<?php 
					foreach($principals as $qprincipal => $text) {
						if ($qprincipal == $principal) { echo "<option value='$qprincipal' selected>$text</option>"; }
						else { echo "<option value='$qprincipal'>$text</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Email 1</label>
			<div class="col-10"><input class="form-control" type="text" name='email_1' value="<?=$email_1;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Email 2</label>
			<div class="col-10"><input class="form-control" type="text" name='email_2' value="<?=$email_2;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Phone</label>
			<div class="col-10"><input class="form-control" type="text" name='phone' value="<?=$phone;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Website</label>
			<div class="col-10"><input class="form-control" type="text" name='website' value="<?=$website;?>"></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() ?>