{% extends "base.html" %}

{% block title %}
	&raquo; Sites &raquo; {{site.code}} {{site.name}}
{% endblock %}

{% block style %}
	<style>
		label {
			width: 11em;
			float: left;
		}
	</style>
{% endblock %}

{% block nav %}
	&raquo; <a href="/sites">Sites</a> &raquo;
	<a href="/sites/{{site.id}}">{{site.code}} {{site.name}}</a>
 	&raquo; Edit
{% endblock %}

{% block content %}
	{% if request.method == "GET" and request.values.delete %}
		<div class="layer-section">
			<div class="section-header">
				<h2>
					Are you sure you want to delete this site and any associated snags?
				</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm textWidthAuto">
						<form method="post" action="/sites/{{site.id}}/edit">
							<fieldset>
								<input type="submit" name="delete" value="delete"> 
								<a href="/sites/{{site.id}}/edit">Cancel</a>
							</fieldset>
						</form>
					</div>
				</div>
			</div>
		</div>			
	{% else %}
		<div class="layer-section">
			<div class="section-header">
				<h2>Update this site</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm">
						<form action="/sites/{{site.id}}/edit" method="post">
							<fieldset>
								<div class="row">						
									<div class="col-sm-6">
										<label>Name</label>
										{{input_text('site_name', site.name, 40)}}
									</div>
									<div class="col-sm-6">
										<label>Code</label>
										{{input_text('code', site.code)}}
									</div>
								</div>
								<input name="update" type="submit" value="Update">
							</fieldset>
						</form>
					</div>
				</div>
			</div>
		</div>
		<div class="layer-section">
			<div class="section-header">
				<h2>Delete this site</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<form action="/sites/{{site.id}}/edit">
						<fieldset>
							<input type="submit" name="delete" value="Delete">
						</fieldset>
					</form>
				</div>			
			</div>		
		</div>	
		<div class="layer-section">
			<div class="section-header">
				<h2>Eras</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<table class="DataTable widthAuto noMarginBottom">
						<!-- <caption>Eras</caption> -->
						<thead>
							<tr>
								<th>From</th>
								<th>To</th>
								<th>Source</th>
								<th>Supply</th>
								<th>Import MPAN core</th>
								<th>Export MPAN core</th>
							</tr>
						</thead>
						<tbody>
							{% for era in eras %}
								<tr>
									<td>{{era.start_date|hh_format}}</td>
									<td>{{era.finish_date|hh_format}}</td>
									<td>{{era.supply.source.code}}</td>
									<td>{{era.supply.name}}</td>
									<td>
										{% if era.imp_mpan_core %}
											{{era.imp_mpan_core}}
										{% endif %}
									</td>
									<td>
										{% if era.exp_mpan_core %}
											{{era.exp_mpan_core}}
										{% endif %}
									</td>
								</tr>
							{% endfor %}
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="layer-section">
			<div class="section-header">
				<h2>Insert an electricity supply</h2>
			</div>
			<div class="section-content">
				<form method="post">
					<fieldset>
						<div class="section-data">
							<div class="standardForm">
								<div class="row">
									<div class="col-sm-4">
										<label>Source</label>
										<select name="source_id">
											{% for source in sources %}
												{{input_option(
													'source_id', source.id, source.code + ' ' +
												 	source.name)}}
											{% endfor %}
										</select>
									</div>
									<div class="col-sm-4">
										<label>Generator Type</label>
										<select name="generator_type_id">
											{% for generator_type in generator_types %}
												{{input_option(
													'generator_type_id', generator_type.id,
												 	generator_type.code + ' ' +
												 	generator_type.description)}}
											{% endfor %}
										</select>
										<label>* if source is 'gen' or 'gen-net'</label>
									</div>
									<div class="col-sm-4">
										<label>Name</label>
										{{input_text('name', required=True)}}
									</div>
								</div>
							</div>
							<fieldset>
								<div class="standardForm textWidthAuto">
									<legend>Start Date</legend>
									{{input_date('start')}}
								</div>	
								<div class="standardForm">
									<div class="row">
										<div class="col-sm-4">
											<label>Meter Serial Number</label>
											{{input_text('msn')}}
										</div>
										<div class="col-sm-4">
											<label>GSP Group</label>
											<select name="gsp_group_id">
												{% for gsp_group in gsp_groups %}
													{{input_option(
														'gsp_group_id', gsp_group.id,
													 	gsp_group.code + ' ' + gsp_group.description)}}
												{% endfor %}
											</select>
										</div>
										<div class="col-sm-4">
											<label>MOP Contract</label>
											<select name="mop_contract_id">
												{% for contract in mop_contracts %}
													{{input_option(
														'mop_contract_id', contract.id, contract.name)}}
												{% endfor %}
											</select>
										</div>
									</div>
									<div class="row">
										<div class="col-sm-4">
											<label>MOP Account</label>
											{{input_text('mop_account')}}
										</div>
										<div class="col-sm-4">
											<label>DC Contract</label>
											<select name="dc_contract_id">
												{% for contract in dc_contracts %}
													{{input_option(
														'dc_contract_id', contract.id, contract.name)}}
												{% endfor %}
											</select>
										</div>
										<div class="col-sm-4">
											<label>DC Account</label>
											{{input_text('dc_account')}}
										</div>
									</div>
									<div class="row">
										<div class="col-sm-4">
											<label>Profile Class</label>
											<select name="pc_id">
												{% for pc in pcs %}
													{{input_option(
														'pc_id', pc.id, pc.code + ' ' + pc.name)}}
												{% endfor %}
											</select>
										</div>
										<div class="col-sm-4">
											<label>MTC Code</label>
											{{input_text('mtc_code', pattern='[0-9]*',
											maxlength='3')}}
										</div>
										<div class="col-sm-4">
											<label>CoP</label>
											<select name="cop_id">
												{% for cop in cops %}
													{{input_option('cop_id', cop.id, cop.description)}}
												{% endfor %}
											</select>										
										</div>
										<div class="col-sm-4">
											<label>Comm</label>
											<select name="comm_id">
												{% for comm in comms %}
													{{input_option(
														'comm_id', comm.id, comm.code + ' ' + comm.description)}}
												{% endfor %}
											</select>										
										</div>
									</div>
									<div class="row">
										<div class="col-sm-4">
											<label>SSC</label>
											{{input_text('ssc_code')}}
										</div>
										<div class="col-sm-4">
											<label>Energisation Status</label>
											<select name="energisation_status_id">
												{% for energisation_status in energisation_statuses %}
													{{input_option(
														'energisation_status_id', energisation_status.id,
													 	energisation_status.code + ' - ' +
													 	energisation_status.description,
													 	initial=default_energisation_status.id)}}
												{% endfor %}
											</select>
										</div>
									</div>
									<div class="row">
										<div class="col-sm-4">
											<label class="aligned">Properties</label>
											{{input_textarea('properties', '{}', 20, 80)}}
										</div>
									</div>
								</div>
							<fieldset>
									<div class="standardForm">
										<legend>Import</legend>
										<div class="row">
											<div class="col-sm-4">
												<label>Mpan Core</label>
												{{input_text('imp_mpan_core', '', 35,
												pattern='[0-9 ]*')}}
											</div>
											<div class="col-sm-4">
												<label>LLFC</label>
												{{input_text('imp_llfc_code', pattern='[a-zA-Z0-9]{3}',
												maxlength='3')}}
											</div>
											<div class="col-sm-4">
												<label>Supply Capacity</label>
												{{input_number('imp_sc', '0', required=True)}}
											</div>
										</div>
										<div class="row">
											<div class="col-sm-4">
												<label>Supplier Contract</label>
												<select name="imp_supplier_contract_id">
													{% for contract in supplier_contracts %}
														{{input_option(
															'imp_supplier_contract_id', contract.id,
														 	contract.name)}}
													{% endfor %}
												</select>
											</div>
											<div class="col-sm-4">
												<label>Supplier Account</label>
												{{input_text('imp_supplier_account')}}
											</div>
											<div class="col-sm-4">
												
											</div>
										</div>
										
									</div>
								</fieldset>	
								<fieldset>
									<div class="standardForm">
										<legend>Export</legend>
										<div class="row">
											<div class="col-sm-4">
												<label>Mpan Core</label>
												{{input_text('exp_mpan_core', '', 35,
												pattern='[0-9 ]*')}}
											</div>
											<div class="col-sm-4">
												<label>LLFC</label>
												{{input_text('exp_llfc_code', maxlength='3',
												pattern='[0-9]*')}}											
											</div>
											<div class="col-sm-4">
												<label>Supply Capacity</label>
												{{input_number('exp_sc', '0', required=True)}}
											</div>
										</div>
										<div class="row">
											<div class="col-sm-4">
												<label>Supplier Contract</label>
												<select name="exp_supplier_contract_id">
													{% for contract in supplier_contracts %}
														{{input_option(
															'exp_supplier_contract_id', contract.id,
														 	contract.name)}}
													{% endfor %}
												</select>
												
											</div>
											<div class="col-sm-4">
												<label>Supplier Account</label>
												{{input_text('exp_supplier_account')}}
											</div>
											<div class="col-sm-4">
												
											</div>
										</div>
									</div>
								</fieldset>
							</fieldset>
							<br>
							<input name="insert_electricity" type="submit" value="Insert">
						</div>
					</fieldset>
				</form>
			</div>
		</div>
		<div class="layer-section">
			<div class="section-header">
				<h2>Insert a gas supply</h2>
			</div>
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm">
						<form action="/sites/{{site.id}}/edit" method="post">
							<fieldset>
								<legend>Insert a gas supply</legend>
								<label>Name</label>
								{{input_text('name')}}
								<br>
								<br>
								<fieldset>
									<div class="standardForm textWidthAuto">
										<legend>Start Date</legend>
										{{input_date('start')}}
									</div>	
								</fieldset>
								<br>
								<label>Meter Serial Number</label>
								{{input_text('msn')}}
								<br>
								<label>Correction Factor</label>
								{{input_text('correction_factor', '1.02264')}}
								<br>
								<label>MPRN</label>
								{{input_text('mprn', '')}}
								<br>
								<label>Exit Zone</label>
								<select name="g_exit_zone_id">
									{% for g_exit_zone in g_exit_zones %}
										{{
											input_option(
												'g_exit_zone_id', g_exit_zone.id, g_exit_zone.code)}}
									{% endfor %}
								</select>
								<br>
								<label>Contract</label>
								<select name="g_contract_id">
									{% for g_contract in g_contracts %}
										{{
											input_option(
												'g_contract_id', g_contract.id, g_contract.name)}}
									{% endfor %}
								</select>
								<br>
								<label>Account</label>
								{{input_text('account')}}
								<br>
								<br>
								<label>Units</label>
								<select name="g_unit_id">
									{% for g_unit in g_units %}
										{{
											input_option(
												'g_unit_id', g_unit.id,
											 	g_unit.code + ' ' + g_unit.description)}}
									{% endfor %}
								</select>
								<br>
								<label>Reading Frequency</label>
								<select name="g_reading_frequency_id">
									{% for g_reading_frequency in g_reading_frequencies %}
										{{
											input_option(
												'g_reading_frequency_id', g_reading_frequency.id,
												g_reading_frequency.code + ' ' +
												g_reading_frequency.description)}}
									{% endfor %}
								</select>
								<input name="insert_gas" type="submit" value="Insert">
							</fieldset>
						</form>
					</div>
				</div>
			</div>
		</div>
	{% endif %}
{% endblock %}
