<div class="open-close-community-dialog-container zoom-anim-dialog mfp-hide dialog" ng-controller="CommunityOpenCloseCtrl">

	<div>

		<h1 class="title"><span>Community Status: {{community.name}}</span></h1>

		<div class="divider"></div>

		<span ng-if="loading"><br></span>

		<div class="bar-loader bar-loader-search" ng-class="{'bar-loader-loading': loading}"></div>

		<ng-form name="formOpenClose" ng-show="!loading">

			<div class="ul-inputs">

				<ul ng-class="{'submitted':formOpenCloseSubmitted}" class="ul-inputs">

					<li class="li-input divider-line">
						<label class="switch-wrap">
							<input type="checkbox" ng-disabled="!community.is_auto_closed" ng-model="community.is_auto_closed"/><div></div>
						</label>
						<div class="label">Is current Auto Closed:</div>
					</li>

					<li class="li-input  divider-line" ng-show="community.is_auto_closed" ng-class="{'error':formOpenClose.autoClosedMessage.$invalid}">
						<div class="label">Auto closed message:</div>
						<div class="input"><input type="text" name="autoClosedMessage" ng-model="community.driver_restaurant_name" ng-required="community.is_auto_closed"
							space-left="community.driver_restaurant_name" space-left-class="space-left-driver-restaurant-name" space-left-width="315"
						></div>
						<div class="box-error">
							<small ng-show="formOpenClose.autoClosedMessage.$error.required">Required.</small>
						</div>
					</li>

					<li class="li-input divider-line">
						<label class="switch-wrap">
							<input type="checkbox" ng-model="community.close_all_restaurants"/><div></div>
						</label>
						<div class="label">Close All Restaurants <br>(you probably never want to do this):</div>
					</li>

					<li class="li-input  divider-line" ng-show="community.close_all_restaurants" ng-class="{'error':formOpenClose.communityCloseAllRestaurantsNote.$invalid}">
						<div class="label">Close All Restaurants Note (follow this same format. e.g. - "Launching Mon 2/2 6PM-12AM"):</div>
						<div class="input"><input type="text" name="communityCloseAllRestaurantsNote" ng-model="community.close_all_restaurants_note" ng-required="community.close_all_restaurants"
						space-left="community.close_all_restaurants_note" space-left-class="space-left-driver-restaurant-name" space-left-width="315"
						></div>
						<div class="box-error">
							<small ng-show="formOpenClose.communityCloseAllRestaurantsNote.$error.required">Required.</small>
						</div>

					</li>

					<li class="li-input divider-line">
						<label class="switch-wrap">
							<input type="checkbox" ng-model="community.close_3rd_party_delivery_restaurants"/><div></div>
						</label>
						<div class="label">Close 3rd Party Delivery Restaurants:</div>
					</li>

					<li class="li-input  divider-line" ng-show="community.close_3rd_party_delivery_restaurants" ng-class="{'error':formOpenClose.communityClose3rdPartyRestaurantsNote.$invalid}">
						<div class="label">Close 3rd Party Delivery Restaurants Note on Driver Restaurant Title (follow this same format. e.g. - "Launching Mon 2/2 6PM-12AM"):</div>
						<div class="input"><input type="text" name="communityClose3rdPartyRestaurantsNote" ng-model="community.close_3rd_party_delivery_restaurants_note" ng-required="community.close_3rd_party_delivery_restaurants"
							space-left="community.close_3rd_party_delivery_restaurants" space-left-class="space-left-driver-restaurant-name" space-left-width="315"
						></div>
						<div class="box-error">
							<small ng-show="formOpenClose.communityClose3rdPartyRestaurantsNote.$error.required">Required.</small>
						</div>
					</li>

					<li class="li-input divider-line" ng-show="community.close_all_restaurants || community.close_3rd_party_delivery_restaurants" >
						<label class="switch-wrap">
							<input type="checkbox" ng-model="community.dont_warn_till_enabled"/><div></div>
						</label>
						<div class="label">Remind me/CS to reopen it at this time (<strong>Pacific, not Local time</strong>):</div>
					</li>

					<li class="li-input  divider-line" ng-class="{'error': formOpenClose.dontWarnTill.$invalid}" ng-if="community.dont_warn_till_enabled">
						<div class="input">
							<input type="datetime-local" ng-disabled="!community.dont_warn_till_enabled" ng-required="community.dont_warn_till_enabled" name="dontWarnTill" ng-model="community.dont_warn_till" placeholder="">
						</div>
						<div class="note">
							(I'll be reminded only if the community is still closed AND has drivers scheduled)<br>
							Reminder: give yourself extra time to get the community reopened by the time you promise customers
						</div>
					</li>


					<li class="li-input divider-line" ng-show="community.close_all_restaurants || community.close_3rd_party_delivery_restaurants" >
						<label class="switch-wrap">
							<input type="checkbox" ng-model="community.reopen_at_enabled"/><div></div>
						</label>
						<div class="label">Reopen the community at this time (<strong>Pacific, not Local time</strong>):</div>
					</li>

					<li class="li-input  divider-line" ng-class="{'error': formOpenClose.dontWarnTill.$invalid}" ng-if="community.reopen_at_enabled">
						<div class="input">
							<input type="datetime-local" ng-disabled="!community.reopen_at_enabled" ng-required="community.reopen_at_enabled" name="dontWarnTill" ng-model="community.reopen_at" placeholder="">
						</div>
						<div class="note">
							The Force-Close will be removed at the time you set.
						</div>
					</li>

					<li class="li-input  divider-line" ng-class="{'error': formOpenClose.reason.$invalid}" ng-show="status_changed && ( community.close_all_restaurants || community.close_3rd_party_delivery_restaurants )">
						<div class="label">Reason for closing:</div>
						<div class="input">
							<select name="reason" ng-model="community.reason" ng-required="status_changed && ( community.close_all_restaurants || community.close_3rd_party_delivery_restaurants )">
								<option value="driver flaked">Driver flaked</option>
								<option value="didn't schedule enough drivers">We didn't schedule enough drivers for demand and I wasn't resourceful enough to find another one</option>
								<option value="other">Other</option>
							</select>
						</div>
						<div class="box-error">
							<small ng-show="formOpenClose.reason.$error.required">Required.</small>
						</div>
					</li>

					<li class="li-input  divider-line" ng-show="community.reason == 'other'" ng-class="{'error':formOpenClose.reasonOther.$invalid}">
						<div class="label">Other Reason:</div>
						<div class="input"><input type="text" name="reasonOther" ng-model="community.reason_other" ng-required="community.reason == 'other'"></div>
						<div class="box-error">
							<small ng-show="formOpenClose.autoClosedMessage.$error.required">Required.</small>
						</div>
					</li>

					<li class="li-input" ng-show="community.reason == 'driver flaked'" ng-class="{'error':formOpenClose.reasonDriverFlaked.$invalid}">
						<div class="label">Driver</div>
						<div class="input">
							<select ng-model="community.reason_driver" ng-required="community.reason == 'driver flaked'" name="reasonDriverFlaked" ng-options="driver.id_admin as driver.name for driver in drivers"></select>
						</div>
						<div class="box-error">
							<small ng-show="formOpenClose.reasonDriverFlaked.$error.required">Required.</small>
						</div>
					</li>

					<li class="li-input" ng-show="community.close_all_restaurants || community.close_3rd_party_delivery_restaurants && drivers.length > 0">
						<strong>Before closing it, please consider contact one of the drivers below:</strong><br>
						<ul class="drivers-list">
							<li ng-repeat="driver in drivers">
								<label>
									<span ng-if="!driver.working">
										<input type="checkbox" ng-click="updateDriversCount();" ng-model="driver.down_to_help_out" style="width:20px;"><strong>{{driver.name}}</strong>: {{driver.phone}}
									</span>
									<span ng-if="driver.working">
										<strong>{{driver.name}}</strong>: {{driver.phone}} <span class="italic">(working)</span>
									</span>
								</label>
								<div ng-if="driver.note">{{driver.note}}</div>
							</li>
						</ul>
					</li>

					<li class="li-input divider-line" ng-show="community.close_all_restaurants || community.close_3rd_party_delivery_restaurants && driversCount">
						<div ng-if="community.last_down_to_help_out_message">
							Last time we asked for help: {{community.last_down_to_help_out_message | timestamp | date:'MM/dd @ h:mm a'}}
							<br>
						</div>
						<button class="button save" ng-click="sendTextMessage();">Text Message {{driversCount}} Driver<span ng-show="driversCount > 1">s</span>	</button>
					</li>

					<li class="li-input divider-line" ng-show="community.has_pre_orders">
						<div class="label label-red">
							<a href="/orders?limit=20&page=1&fullcount=false&search=&restaurant=&community={{community.id_community}}&driver=&date=&view=list&datestart=&dateend=&user=&phone=&type=pre-orders" target="_blank">
								This community has {{community.has_pre_orders}} pending pre-order<span ng-if="community.has_pre_orders > 1">s</span>, please take a look on that before close.
							</a>
						</div>
					</li>

					<li class="li-input divider-line" ng-show="community.close_all_restaurants || community.close_3rd_party_delivery_restaurants">
						<label class="switch-wrap">
							<input type="checkbox" ng-model="reallyWantToClose"/><div></div>
						</label>
						<div class="label">I really want to close!</div>
					</li>

					<li class="li-input" ng-show="(
					( !community.close_all_restaurants || ( community.close_all_restaurants && reallyWantToClose ) ) &&
					( !community.close_3rd_party_delivery_restaurants || ( community.close_3rd_party_delivery_restaurants && reallyWantToClose ) )
					)
					&& !isSavingOpenClose">
						<button class="button button-empty button-border button-green button-full" ng-click="formOpenCloseSave();"><span class="fa fa-save"></span>&nbsp;&nbsp;Save and Double Check It Looks OK</button>
					</li>
					<li class="li-input" ng-show="isSavingOpenClose">
						<i class="fa fa-circle-o-notch fa-spin"></i>
					</li>
				</ul>
			</div>
		</ng-form>
	</div>
</div>