@model ResoursesManager.Models.ReservationCreateViewModel

@{
    ViewBag.Title = "Létrehozás";
}

<h2>Foglalás</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Foglalás</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div class="form-group">
            @Html.LabelFor(model => model.Reservation.Resource.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10 ">
                @if (Model.Resources != null)
                {
                    @Html.DropDownList("ResourceId",
                        Model.Resources.Select(n => new SelectListItem() { Text = n.Name + ", " + n.AssetTag, Value = n.Id.ToString() }),
                        new { @class = "form-control" })
                }
                else
                {
                    @Html.EditorFor(m => m.Reservation.Resource.Name, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
                    @Html.Hidden("ResourceId", Model.Reservation.ResourceId)
                }
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Reservation.Resource.TimeLimit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10 ">
                @Html.EditorFor(model => model.Reservation.Resource.TimeLimit, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })                
            </div>
        </div>

        <div class="form-group">
            *@Html.LabelFor(model => model.Reservation.Begining, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10 ">
                <input type="datetime" name="Begining" value="@Model.Reservation.Begining.ToString("yyyy.MM.dd HH:mm")" class="form-control date-time-picker" id="begining"/>
                @Html.ValidationMessageFor(model => model.Reservation.Begining, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            *@Html.LabelFor(model => model.Reservation.End, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10 ">
                <input type="datetime" name="End" value="@Model.Reservation.End.ToString("yyyy.MM.dd HH:mm")" class="form-control date-time-picker" id="end"/>
                @Html.ValidationMessageFor(model => model.Reservation.End, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Foglal" class="btn btn-primary" />
            </div>
        </div>
    </div>
}


<div>
    <a href="javascript:void(0);" onclick="history.go(-1);" class="btn btn-default">Vissza</a>
</div>
@section Scripts{
    <script type="text/javascript">
        $(function () {
            $('#begining').focusout(function () {
                var begining = $('#begining').val();
                var date = new Date(begining);
                var newDate = new Date(date);
                newDate.setHours(date.getHours() + 1);
                $('#end').val(dateFormat(newDate, "yyyy.mm.dd. HH:MM"));
            });
            $('.date-time-picker').datetimepicker({
                sideBySide: true,
                useCurrent: false,
                locale: 'hu-HU'
            });
        });
    </script>
}