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

<?= $this->section('content') ?>
<?php
$contactid = 0;
$firstname = '';
$lastname = '';
$initial = '';
$title = '';
$birthdate = '';
$email_1 = '';
$email_2 = '';
$phone = '';
$mobile_1 = '';
$mobile_2 = '';
if(isset($contacts[0])) { $data = $contacts[0]; }
if(isset($new_value)) { $data = $new_value; }
if(isset($data)) {
	if(isset($data['contactid'])) { $contactid = $data['contactid']; }
	$firstname = $data['firstname'];
	$lastname = $data['lastname'];
	$initial = $data['initial'];
	$title = $data['title'];
	$birthdate = $data['birthdate'];

	$birthdate= ($birthdate == NULL) ? NULL : date('Y-m-d', strtotime($data['birthdate'])) ;
	$email_1 = $data['email_1'];
	$email_2 = $data['email_2'];
	$phone = $data['phone'];
	$mobile_1 = $data['mobile_1'];
	$mobile_2 = $data['mobile_2'];
}
?>
<div class="form-body">
	<h3 class="card-title">Contact 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'>
		<div class="form-group row">
			<input type='hidden' name='contactid' value='<?=$contactid;?>'/>
			<label class="col-2 col-form-label">First Name</label>
			<div class="col-10"><input class="form-control" type="text" name='firstname' value="<?=$firstname;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Last Name</label>
			<div class="col-10"><input class="form-control" type="text" name='lastname' value="<?=$lastname;?>"></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">Title</label>
			<div class="col-10"><input class="form-control" type="text" name='title' value="<?=$title;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Birthdate</label>
			<div class="col-10"><input class="form-control" type="date" name='birthdate' value="<?=$birthdate;?>"></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">Mobile 1</label>
			<div class="col-10"><input class="form-control" type="text" name='mobile_1' value="<?=$mobile_1;?>"></div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Mobile 2</label>
			<div class="col-10"><input class="form-control" type="text" name='mobile_2' value="<?=$mobile_2;?>"></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() ?>