<template name="eventEdit">
	<form>
	<div class="edit-page">
		{{#unless hasParentCourse}}
			{{#if _id}}
				<h2>{{mf 'course.event.edit.edit' 'Edit event'}}</h2>
			{{else}}
				<h2>{{mf 'course.event.edit.add' 'Add event'}}</h2>
				{{#mf KEY='course.createEventInfo'}}
					Use this form if you want to publish a singular, one-off, allready organised event.
					Otherwise create or propose a course here:
				{{/mf}}
				<a href="/courses/propose">{{mf 'menue.ProposeCourse' 'Propose a course'}}</a>
			{{/if}}
		{{/unless}}

		<div class="edit-page-header event-edit-header">
			{{#if showRegionTag}}
				{{> regionTag}}
			{{/if}}
			<div class="form-group">
				<label>{{mf 'course.event.edit.title' 'Event title'}}</label>
				<input type="text"
				       class="form-control input-lg"
				       id="eventEditTitle"
				       name="_"
				       placeholder="{{mf 'event.title.placeholder' 'Put a catchy title here'}}"
				       size="30"
				       value="{{this.title}}">
			</div>
			<div class="form-group">
				<div class="form-group-element">
					<label>{{mf 'course.event.edit.date_start' 'Date'}}</label>
					<div class="input-group">
						<span class="input-group-addon">
							<span class="fa fa-calendar fa-fw" aria-hidden="true"></span>
						</span>
						<input type="text"
						       class="form-control js-event-start-date"
						       value="{{localDate startLocal}}"
						       {{disableForPast}}>
					</div>
				</div>
				<div class="form-group-element">
					<label>{{mf 'course.event.edit.time_start' 'Time start'}}</label>
					<div class="input-group">
						<span class="input-group-addon">
							<span class="fa fa-hourglass-start fa-fw" aria-hidden="true"></span>
						</span>
						<input type="text"
						       class="form-control"
						       id="editEventStartTime"
						       size="5"
						       value="{{timeformat startLocal}}"
						       {{disableForPast}}>
					</div>
				</div>
				<div class="form-group-element time-end">
					<label style="display:none">
						{{mf 'course.event.edit.duration' 'Duration (in minutes)'}}
						<button type="button"
						        class="js-toggle-duration btn-icon"
						        data-tooltip="{{mf 'course.event.edit.switch_time_end' 'Switch to end time'}}">
							<span class="fa fa-exchange"></span>
						</button>
					</label>
					<div class="input-group" style="display:none">
						<span class="input-group-addon">
							<span class="fa fa-hourglass-end fa-fw" aria-hidden="true"></span>
						</span>
						<input type="number"
						       class="form-control"
						       id="editEventDuration"
						       value=""
						       size="5"
						       {{disableForPast}}>
					</div>
					<label>
						{{mf 'course.event.edit.time_end' 'Time end'}}
						<button type="button"
						        class="js-toggle-duration btn-icon"
						        data-tooltip="{{mf 'course.event.edit.swich_duration' 'Switch to duration'}}">
							<span class="fa fa-exchange"></span>
						</button>
					</label>
					<div class="input-group">
						<span class="input-group-addon">
							<span class="fa fa-hourglass-end fa-fw" aria-hidden="true"></span>
						</span>
						<input type="text"
						       class="form-control"
						       id="editEventEndTime"
						       size="5"
						       value="{{timeformat endLocal}}
						       {{disableForPast}}">
					</div>
				</div>
			</div>
		</div>
		<div class="edit-page-body event-edit-body">
			<div class="form-group">
				<label>{{mf 'course.event.edit.desc' 'Description'}}</label>
				{{> editableTextarea editableDescription}}
			</div>
			{{> pricePolicy dismissable=true wrap='form-group'}}

			{{#if showRegionSelection}}
				<div class="form-group">
					<label>{{mf 'course.edit.region' 'Region'}}</label>
					<div class="input-group">
						<div class="input-group-addon">
							<span class="fa fa-dot-circle-o fa-fw" aria-hidden="true"></span>
						</div>
						<select class="region_select js-select-region form-control"
							name='region'>
							<option class="select-placeholder"
							        disabled
							        selected
							        value=''>
								{{mf '_selection.pleaseSelect'}}
							</option>
							{{#each regions}}
								<option selected="{{#if currentRegion this}}selected{{/if}}"
								        value='{{_id}}'>
									{{name}}
								</option>
							{{/each}}
						</select>
					</div>
				</div>
			{{/if}}

			{{#if showVenueSelection}}
				{{>eventEditVenue}}
				<div class="form-group">
					<label>
						{{mf 'course.event.edit.room' 'Room'}}
						<small> {{mf '_inputField.optional'}}</small>
					</label>
					<div class="input-group" id="editform_room" name="editform_room">
						<span class="input-group-addon">
							<span class="fa fa-map-signs fa-fw" aria-hidden="true"></span>
						</span>
						<input type="text"
						       class="form-control"
						       id="eventEditRoom"
						       size="40"
						       value="{{room}}">
					</div>
				</div>
			{{/if}}


			<div class="form-group">
				<div class="checkbox">
					<label>
						<input type="checkbox" class="js-check-event-internal" {{isInternal}}>
						{{mf 'event.edit.internal' 'Hide on front page'}}
						<span class="help-block internal-disclaimer">
							{{#mf KEY='event.edit.internal.description'}}
								Show this event only on group and venue pages
							{{/mf}}
						</span>
					</label>
				</div>
				{{#if affectedReplicaCount}}
					<div class="checkbox {{disabledIfDayChanged}}">
						<label>
							<input
								class="js-update-replicas"
								type="checkbox"
								name="updateReplicas"
								{{disabledIfDayChanged}}
							>
							{{#mf KEY='event.edit.updateReplicas' COUNT=affectedReplicaCount}}
								Update {COUNT, plural,
									one {later copy}
									other {# later copies as well}
								}
							{{/mf}}
						</label>
					</div>
					{{#if startDayChanged}}
						<div class="panel panel-danger">
							<div class="panel-heading">
								<i class="fa fa-warning fa-fw" aria-hidden="true"></i>
								{{mf 'event.edit.startDayChanged' 'Updating the copies when the start day has been changed is not (yet) supported.'}}
							</div>
						</div>
					{{else}}
						{{#if changedReplicas.length}}
							<div class="panel panel-warning changed-replicas {{emphasizeClass}}">
								<div class="panel-heading">
									<i class="fa fa-warning fa-fw" aria-hidden="true"></i>
									{{#mf KEY='event.edit.changedReplicas.heading' NUM=changedReplicas.length}}
										Found {NUM, plural,
											one {one copy which varies}
											other {# copies which vary}
										} in time
									{{/mf}}
								</div>
								<div class="panel-body">
									{{#unless updateChangedReplicas}}
										<span class="update-changed-replicas-help">
											{{#mf KEY='event.edit.changedReplicas.body' NUM=changedReplicas.length}}
												By default {NUM, plural,
													one {this copy}
													other {these copies}
												} won't be updated as
												{NUM, plural,
													one {it has}
													other {they have}
												} another time set than the original event:
											{{/mf}}
										</span>
									{{/unless}}
									<ul>
										{{#each replica in changedReplicas}}
											<li>
												<a href="{{pathFor 'showEvent' replica}}" target="_blank">
													{{dateformat replica.startLocal}}
													-
													{{replica.title}}

													({{timeformat replica.startLocal}}
													-
													{{timeformat replica.endLocal}})
												</a>
											</li>
										{{/each}}
									</ul>
									<div class="checkbox">
										<label>
											<input class="js-update-changed-replicas" type="checkbox">
											{{#mf KEY='event.edit.updateChangedReplicas' NUM=changedReplicas.length}}
												Update {NUM, plural,
													one {this event}
													other {these events}
												} (including {NUM, plural,
													one {it's time}
													other {their time}
												}) too
											{{/mf}}
										</label>
										</div>
								</div>
							</div>
						{{/if}}
					{{/if}}
				{{/if}}
				{{#if courseId}}
					<div class="checkbox">
						<label>
							{{#if new}}
								<input type="checkbox" class="js-check-notify" checked>
								{{#mf KEY='event.edit.notifyNewEvent' COURSE=course.name}}
									Notify all members of the course "{COURSE}" about this event.
								{{/mf}}
							{{else}}
								<input type="checkbox" class="js-check-notify">
								{{#mf KEY='event.edit.notifyEditEvent' COURSE=course.name}}
									Notify all members of the course "{COURSE}" about the changes you made.
								{{/mf}}
							{{/if}}
						</label>
					</div>
				{{/if}}
				{{#if notifyChecked}}
					<label>
						{{mf 'course.event.edit.AddMessage' 'Add message'}}
						<small> {{mf '_inputField.optional'}}</small>
					</label>
					<div class="input-group" id="editform_message" name="editform_message">
						<span class="input-group-addon">
							<span class="glyphicon glyphicon-pencil fa-fw" aria-hidden="true"></span>
						</span>
						<textarea rows="3"
						       class="form-control js-event-edit-add-message"
						       maxlength="2000"
						       placeholder="{{mf 'event.edit.additionalMessage' 'If you feel good, describe what the members of the course should know.'}}"></textarea>
					</div>
				{{/if}}
			</div>

			<div class="form-actions">
				{{> buttonSave saving=saving}}
				{{> buttonCancel event="js-event-edit-cancel"}}
			</div>
		</div>
	</div>
	</form>
</template>
