<div>

<section class="heading b-b">
  <div class="row no-gutter">
    <div class="col-xs-2 col-sm-2 col-md-1">
      <section class="heading-btn">
        <a href="#" ng-click="backPrevLocation($event)"><i class="fa fa-long-arrow-left "></i></a>
      </section>
    </div>
    <div class="col-xs-10 col-sm-10 col-md-8 b-l">
      <section class="heading-title">
        <h1>{{ 'machine_planning' | translate }} : {{machine.name}}</h1>
      </section>
    </div>
  </div>
</section>


<div class="row no-gutter machine-reserve">
  <div class="col-sm-12 col-md-12 col-lg-9">
    <div ui-calendar="calendarConfig" ng-model="eventSources" calendar="calendar" class="wrapper-lg" ng-show="!plansAreShown"></div>
    <ng-include ng-if="!fablabWithoutPlans" src="'<%= asset_path 'plans/_plan.html' %>'"></ng-include>
  </div>


  <div class="col-sm-12 col-md-12 col-lg-3">

    <div>
        <ng-include src="'<%= asset_path 'shared/_member_select.html' %>'" ng-if="currentUser.role === 'admin'"></ng-include>
    </div>

    <div class="widget panel b-a m m-t-lg" ng-show="!ctrl.member && currentUser.role == 'admin' && eventsReserved.length == 0 && (!paidMachineSlots || paidMachineSlots.length == 0) && !slotToModify && !modifiedSlots">
      <div class="panel-heading b-b small">
        <h3 translate>{{ 'summary' }}</h3>
      </div>
      <div class="widget-content no-bg auto wrapper">
        <p class="font-felt fleche-left text-lg"><%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %>
        {{ 'select_one_or_more_slots_in_the_calendar' | translate }}</p>
      </div>
    </div>


    <div class="widget panel b-a m m-t-lg" ng-if="ctrl.member && !slotToModify && !modifiedSlots">
      <div class="panel-heading b-b small">
        <h3 translate>{{ 'summary' }}</h3>
      </div>

      <div class="widget-content no-bg auto wrapper" ng-show="eventsReserved.length == 0 && (!paidMachineSlots || paidMachineSlots.length == 0)">
        <p class="font-felt fleche-left text-lg"><%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %>
          {{ 'select_one_or_more_slots_in_the_calendar' | translate }}</p>
      </div>

      <div class="widget-content no-bg auto wrapper" ng-if="eventsReserved.length > 0">

        <div class="font-sbold m-b-sm " translate>{{ 'you_ve_just_selected_the_slot' }}</div>

        <div class="panel panel-default bg-light" ng-repeat="machineSlot in eventsReserved">
          <div class="panel-body">
            <div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(machineSlot.start | amDateFormat:'LLLL'), END_TIME:(machineSlot.end | amDateFormat:'LT') } }}</div>
            <div class="text-base">{{ 'cost_of_a_machine_hour' | translate }} <span ng-class="{'text-blue': !machineSlot.promo, 'red': machineSlot.promo}">{{machineSlot.price | currency}}</span></div>
            <div ng-show="currentUser.role == 'admin'" class="m-t">
              <label for="offerSlot" class="control-label m-r" translate>{{ 'offer_this_slot' }}</label>
              <input bs-switch
                     ng-model="machineSlot.offered"
                     id="offerSlot"
                     type="checkbox"
                     class="form-control"
                     switch-on-text="{{ 'yes' | translate}}"
                     switch-off-text="{{ 'no' | translate}}"
                     switch-animate="true"
                     switch-readonly="{{machineSlot.isValid}}"/>
            </div>
          </div>
          <div>
            <button class="btn btn-valid btn-warning btn-block text-u-c r-b" ng-click="validMachineSlot(machineSlot)" ng-if="!machineSlot.isValid" translate>{{ 'confirm_this_slot' }}</button>
          </div>

          <div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
        </div>

        <span ng-hide="fablabWithoutPlans">
          <div ng-if="machineSlotsValid() && !ctrl.member.subscribed_plan" ng-show="!plansAreShown">
            <p class="font-sbold text-base l-h-2x" translate>{{ 'to_benefit_from_attractive_prices' }}</p>
            <div><button class="btn btn-warning-full rounded btn-block text-xs" ng-click="showPlans()" translate>{{ 'view_our_subscriptions' }}</button></div>
            <p class="font-bold text-base text-u-c text-center m-b-xs" translate>{{ 'or' }}</p>
          </div>

          <div ng-if="selectedPlan">
            <div class="m-t-md m-b-sm text-base">{{ 'you_ve_just_selected_a_' | translate }} <br> <span class="font-sbold" translate>{{ '_subscription' }}</span> :</div>
            <div class="panel panel-default bg-light m-n">
              <div class="panel-body m-b-md">
                <div class="font-sbold text-u-c">{{selectedPlan | humanReadablePlanName }}</div>
                <div class="text-base">{{ 'cost_of_the_subscription' | translate }} <span class="text-blue">{{selectedPlan.amount | currency}}</span></div>
              </div>
            </div>
          </div>
        </span>

      </div>

      <div class="panel-footer no-padder" ng-if="eventsReserved.length > 0">
          <button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="payMachine()" ng-if="machineSlotsValid() && (!plansAreShown || selectedPlan)">{{ 'confirm_and_pay' | translate }} {{amountTotal | currency}}</button>
      </div>

      <div class="widget-content no-bg auto wrapper" ng-if="paidMachineSlots">
        {{ 'you_have_settled_the_following_machine_hours' | translate }} <strong>{{machine.name}}</strong>:

        <div class="well well-warning m-t-sm" ng-repeat="paidSlot in paidMachineSlots">
          <i class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(paidSlot.start | amDateFormat:'LLLL'), END_TIME:(paidSlot.end | amDateFormat:'LT') } }}</i>
          <div class="font-sbold">{{ 'cost_of_a_machine_hour' | translate }} {{paidSlot.machine.amount() | currency}}</div>
        </div>

        <div ng-if="selectedPlan">
          <div class="m-t-md m-b-sm text-base">{{ 'you_have_settled_a_' | translate }} <br> <span class="font-sbold" translate>{{ '_subscription' }}</span> :</div>
          <div class="well well-warning m-t-sm">
            <i class="font-sbold  text-u-c">{{selectedPlan | humanReadablePlanName }}</i>
            <div class="font-sbold">{{ 'cost_of_the_subscription' | translate }} {{selectedPlan.amount | currency}}</div>
          </div>
        </div>

        <div class="m-t-md font-sbold">{{ 'total_' | translate }} {{amountTotal | currency}}</div>

        <div class="alert alert-success" ng-if="ctrl.member.subscribed_plan">{{ 'thank_you_your_payment_has_been_successfully_registered' | translate }}<br>
          {{ 'your_invoice_will_be_available_soon_from_your_' | translate }} <a ui-sref="app.logged.dashboard.invoices" translate>{{ 'dashboard' }}</a>
        </div>

      </div>
    </div>


    <div class="widget panel b-a m m-t-lg" ng-if="slotToModify || modifiedSlots">
      <div class="panel-heading b-b small">
        <h3 translate>{{ 'summary' }}</h3>
      </div>
      <div class="widget-content no-bg auto wrapper" ng-if="slotToModify">
        <div class="font-sbold m-b-sm " translate>{{ 'i_want_to_change_the_following_reservation' }}</div>

        <div class="panel panel-warning bg-yellow">
          <div class="panel-body">
            <div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(slotToModify.start | amDateFormat:'LLLL'), END_TIME:(slotToModify.end | amDateFormat:'LT') } }}</div>
          </div>
          <div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeSlotToModify($event)" translate>{{ 'cancel_my_modification' }}</a></div>
        </div>

        <div class="widget-content no-bg">
          <p class="font-felt fleche-left text-lg"><%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %>
          {{ 'select_a_new_slot_in_the_calendar' | translate }}</p>
        </div>

        <div class="panel panel-info bg-info text-white" ng-if="slotToPlace">
          <div class="panel-body">
            <div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(slotToPlace.start | amDateFormat:'LLLL'), END_TIME:(slotToPlace.end | amDateFormat:'LT') } }}</div>
          </div>
          <div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeSlotToPlace($event)" translate>{{ 'cancel_my_selection' }}</a></div>
        </div>

        <div ng-if="slotToPlace && slotToModify.tags.length > 0 && slotToPlace.tags.length > 0" ng-class="{'panel panel-danger bg-red': tagMissmatch()}">
          <div class="panel-body">
            <div id="fromTags">
              {{ 'tags_of_the_original_slot' | translate }}<br/>
              <span ng-repeat="tag in slotToModify.tags">
                <span class='label label-success text-white' title="{{tag.name}}">{{tag.name}}</span>
              </span>
            </div><br/>
            <div id="toTags">
              {{ 'tags_of_the_destination_slot' | translate }}<br/>
              <span ng-repeat="tag in slotToPlace.tags">
                <span class='label label-success text-white' title="{{tag.name}}">{{tag.name}}</span>
              </span>
            </div>
          </div>
        </div>
      </div>


      <div class="panel-footer no-padder" ng-if="slotToModify && slotToPlace">
       <button class="btn btn-invalid btn-default btn-block p-l btn-lg text-u-c r-n text-base" ng-click="cancelModifyMachineSlot()" translate>{{ 'cancel' }}</button>
        <div>
          <button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="modifyMachineSlot()" translate>{{ 'confirm_my_modification' }}</button>
        </div>
      </div>

      <div class="widget-content no-bg auto wrapper" ng-if="modifiedSlots">
        <div class="font-sbold m-b-sm " translate>{{ 'your_booking_slot_was_successfully_moved_from_' }}</div>

        <div class="panel panel-default bg-light">
          <div class="panel-body">
            <div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(modifiedSlots.oldReservedSlot.start | amDateFormat:'LLLL'), END_TIME:(modifiedSlots.oldReservedSlot.end | amDateFormat:'LT') } }}</div>
          </div>
        </div>

        <p class="text-center font-bold m-b-sm text-u-c" translate>{{ 'to_date' }}</p>

        <div class="panel panel-success bg-success bg-light">
          <div class="panel-body">
            <div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(modifiedSlots.newReservedSlot.start | amDateFormat:'LLLL'), END_TIME:(modifiedSlots.newReservedSlot.end | amDateFormat:'LT') } }}</div>
          </div>
        </div>
      </div>

    </div>

    <uib-alert type="warning m">
      <p class="text-sm">
        <i class="fa fa-lightbulb-o"></i>
        <span ng-bind-html="machineExplicationsAlert"></span>
      </p>
    </uib-alert>

  </div>
</div>

</div>
