<style>
	#dna-patients-filters label {
		font-weight: bold;
	}

	#dna-patients-filters .mw-100px {
		min-width: 100px;
	}

	.filter-container {
		display: flex;
		align-items: flex-start;
		flex-wrap: wrap;
	}

	.filter-container>div {
		width: 165px;
	}

	.filter-container>div:not(:last-child) {
		margin-right: 15px;
	}

	.sm-section {
		width: 125px !important;
	}
</style>
<form id="dna-patients-filters" method="GET" action="{{ route('ca.patients') }}" class="filter-container" v-cloak>
	<div class="sm-section">
		<div class="form-group">
			<label>Name:</label>
			<input name="name" class="form-control input-sm" v-model="filters.name">
		</div>
	</div>
	<!-- AGE	 -->
	<div class="sm-section">
		<div class="form-group">
			<label>Age:</label>
			<select name="age_category" class="form-control input-sm" v-model="filters.age_category">
				<option value="">All</option>
				<option value="EXACTLY">Exactly</option>
				<option value="LESS_THAN">Less Than</option>
				<option value="GREATER_THAN">Greater Than</option>
				<option value="BETWEEN">Between</option>
				<option value="NOT_BETWEEN">Not Between</option>
			</select>
			<div v-show="filters.age_category" class="mt-2">
				<div>
					<input name="age_value_1" v-model="filters.age_value_1" type="number" class="form-control input-sm" :placeholder="(filters.age_category === 'BETWEEN' || filters.age_category === 'NOT_BETWEEN') ? 'From' : 'Age'" />
				</div>
				<div v-show="filters.age_category === 'BETWEEN' || filters.age_category === 'NOT_BETWEEN'" class="mt-2">
					<input name="age_value_2" v-model="filters.age_value_2" type="number" class="form-control input-sm" placeholder="To" />
				</div>
			</div>
		</div>
	</div>
	<!-- SEX -->
	<div class="sm-section">
		<div class="form-group">
			<label>Sex:</label>
			<select name="sex" class="form-control input-sm" v-model="filters.sex">
				<option value="">All</option>
				<option value="M">Male</option>
				<option value="F">Female</option>
			</select>
		</div>
	</div>
	<!-- BMI -->
	<div class="sm-section">
		<div class="form-group">
			<label>BMI:</label>
			<select name="bmi_category" class="form-control input-sm" v-model="filters.bmi_category">
				<option value="">All</option>
				<option value="EXACTLY">Exactly</option>
				<option value="LESS_THAN">Less Than</option>
				<option value="GREATER_THAN">Greater Than</option>
				<option value="BETWEEN">Between</option>
				<option value="NOT_BETWEEN">Not Between</option>
			</select>
			<div v-show="filters.bmi_category" class="mt-2">
				<div>
					<input name="bmi_value_1" v-model="filters.bmi_value_1" type="number" class="form-control input-sm" :placeholder="(filters.bmi_category === 'BETWEEN' || filters.bmi_category === 'NOT_BETWEEN') ? 'From' : 'BMI'" />
				</div>
				<div v-show="filters.bmi_category === 'BETWEEN' || filters.bmi_category === 'NOT_BETWEEN'" class="mt-2">
					<input name="bmi_value_2" v-model="filters.bmi_value_2" type="number" class="form-control input-sm" placeholder="To" />
				</div>
			</div>
		</div>
	</div>

	<!-- LAST VISIT -->
	<!-- <div class="sm-section">
		<div class="form-group">
			<label>Last Visit:</label>
			<select name="last_visit_category" class="form-control input-sm" v-model="filters.last_visit_category">
				<option value="">All</option>
				<option value="EXACTLY">Exactly</option>
				<option value="LESS_THAN">Less Than</option>
				<option value="GREATER_THAN">Greater Than</option>
				<option value="BETWEEN">Between</option>
				<option value="NOT_BETWEEN">Not Between</option>
			</select>
			<div v-show="filters.last_visit_category" class="mt-2">
				<div>
					<input name="last_visit_value_1" v-model="filters.last_visit_value_1" type="date" class="form-control input-sm" :placeholder="(filters.last_visit_category === 'BETWEEN' || filters.last_visit_category === 'NOT_BETWEEN') ? 'From' : 'Last Visit'" />
				</div>
				<div v-show="filters.last_visit_category === 'BETWEEN' || filters.last_visit_category === 'NOT_BETWEEN'" class="mt-2">
					<input name="last_visit_value_2" v-model="filters.last_visit_value_2" type="date" class="form-control input-sm" placeholder="To" />
				</div>
			</div>
		</div>
	</div> -->

	<!-- NEXT APPOINTMENT -->
	<div>
		<div class="form-group">
			<label>Next Appointment:</label>
			<select name="next_appointment_category" class="form-control input-sm" v-model="filters.next_appointment_category">
				<option value="">All</option>
				<option value="EXACTLY">Exactly</option>
				<option value="LESS_THAN">Less Than</option>
				<option value="GREATER_THAN">Greater Than</option>
				<option value="BETWEEN">Between</option>
				<option value="NOT_BETWEEN">Not Between</option>
			</select>
			<div v-show="filters.next_appointment_category" class="mt-2">
				<div>
					<input name="next_appointment_value_1" v-model="filters.next_appointment_value_1" type="date" class="form-control input-sm" :placeholder="(filters.next_appointment_category === 'BETWEEN' || filters.next_appointment_category === 'NOT_BETWEEN') ? 'From' : 'Next Appt.'" />
				</div>
				<div v-show="filters.next_appointment_category === 'BETWEEN' || filters.next_appointment_category === 'NOT_BETWEEN'" class="mt-2">
					<input name="next_appointment_value_2" v-model="filters.next_appointment_value_2" type="date" class="form-control input-sm" placeholder="To" />
				</div>
			</div>
		</div>
	</div>

	<!-- STATUS -->
	<div class="sm-section">
		<div class="form-group">
			<label>Status:</label>
			<select name="status" class="form-control input-sm" v-model="filters.status">
				<option value="">All</option>
				<option value="ACTIVE">Active</option>
				<option value="AWAITING_VISIT">Awaiting Visit</option>
				<option value="INACTIVE">Inactive</option>
			</select>
		</div>
	</div>

	<div class="sm-section">
		<div class="">
			<label>Home State:</label>
			<select name="home_address_state" class="form-control input-sm" v-model="filters.home_address_state">
				<option value="">All</option>
				<option value="NONE">Not Available</option>
				<option value="NOT_MD">Not MD</option>
				<option value="AL">Alabama</option>
				<option value="AK">Alaska</option>
				<option value="AZ">Arizona</option>
				<option value="AR">Arkansas</option>
				<option value="CA">California</option>
				<option value="CO">Colorado</option>
				<option value="CT">Connecticut</option>
				<option value="DE">Delaware</option>
				<option value="FL">Florida</option>
				<option value="GA">Georgia</option>
				<option value="HI">Hawaii</option>
				<option value="ID">Idaho</option>
				<option value="IL">Illinois</option>
				<option value="IN">Indiana</option>
				<option value="IA">Iowa</option>
				<option value="KS">Kansas</option>
				<option value="KY">Kentucky</option>
				<option value="LA">Louisiana</option>
				<option value="ME">Maine</option>
				<option value="MD">Maryland</option>
				<option value="MA">Massachusetts</option>
				<option value="MI">Michigan</option>
				<option value="MN">Minnesota</option>
				<option value="MS">Mississippi</option>
				<option value="MO">Missouri</option>
				<option value="MT">Montana</option>
				<option value="NE">Nebraska</option>
				<option value="NV">Nevada</option>
				<option value="NH">New Hampshire</option>
				<option value="NJ">New Jersey</option>
				<option value="NM">NewMexico</option>
				<option value="NY">New York</option>
				<option value="NC">North Carolina</option>
				<option value="ND">North Dakota</option>
				<option value="OH">Ohio</option>
				<option value="OK">Oklahoma</option>
				<option value="OR">Oregon</option>
				<option value="PA">Pennsylvania</option>
				<option value="RI">RhodeIsland</option>
				<option value="SC">South Carolina</option>
				<option value="SD">South Dakota</option>
				<option value="TN">Tennessee</option>
				<option value="TX">Texas</option>
				<option value="UT">Utah</option>
				<option value="VT">Vermont</option>
				<option value="VA">Virginia</option>
				<option value="WA">Washington</option>
				<option value="WV">West Virginia</option>
				<option value="WI">Wisconsin</option>
				<option value="WY">Wyoming</option>
			</select>
		</div>
	</div>

	<div>
		<div class="form-group">
			<label>&nbsp;</label>
			<div class=" d-flex">
				<button type="button" v-on:click.prevent="doSubmit()" class="btn btn-primary btn-sm mr-2"><i class="fas fa-filter"></i> Filter</button>
				<a href="#" v-on:click.prevent="fastLoad('{{route('ca.patients')}}')" class="btn btn-link btn-sm text-danger">Clear Filters</a>
			</div>
		</div>
	</div>
</form>

<?php
$loadedFilters = @$filters;
$allFilterKeys = [
	'name',
	'age_category',
	'age_value_1',
	'age_value_2',
	'bmi_category',
	'bmi_value_1',
	'bmi_value_2',	
	'last_visit_category',
	'last_visit_value_1',
	'last_visit_value_2',
	'next_appointment_category',
	'next_appointment_value_1',
	'next_appointment_value_2',
	'sex',
	'status',
];
for ($i = 0; $i < count($allFilterKeys); $i++) {
	if (!isset($loadedFilters[$allFilterKeys[$i]]) || !$loadedFilters[$allFilterKeys[$i]]) {
		$loadedFilters[$allFilterKeys[$i]] = '';
	}
}
?>
<script>
	(function() {
		function init() {
			new Vue({
				el: '#dna-patients-filters',
				delimiters: ['@{{', '}}'],
				data: {
					filters: <?= json_encode($loadedFilters) ?>
				},
				methods: {
					init: function() {

					},
					doSubmit: function() {
						fastLoad('{{ route("ca.patients") }}?' + $('#dna-patients-filters').serialize());
						return false;
					}
				},
				mounted: function() {
					console.log(this.filters);
					this.init();
				},
			});


		}
		addMCInitializer('dna-patients-filters', init, '#dna-patients-filters');
	})();
</script>