@model GreenTree.Strohrmann.ERP.Web.Models.Business.CraftModel

@{
    ViewData["Title"] = "Neues Gewerk";
}

<script type="text/javascript">

    function addCraftEmployeePartial() {
        $.ajax({
            type: "GET",
            url: '@Url.Action("AddCraftEmployeePartial")',
            data: {
                Index: $("#craftemployeelist").children(".row").length
			},
            success: function (data) { 
                $("#craftemployeelist").append(data);
            },
            error: function (errorData) { console.error(errorData); }
        });
	}

</script>

<h1>Gewerk erstellen</h1>

<h4>Neues Gewerk</h4>
<hr />

<form asp-action="Create">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <div class="card-deck">
        <div class="card card-maxw bg-light">
            <div class="card-header pb-1">
                <h6>Allgemein</h6>
            </div>
            <div class="card-body">
                <div class="form-group">
                    <label asp-for="Name" class="control-label"></label>
                    <input asp-for="Name" class="form-control" />
                    <span asp-validation-for="Name" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="CreationDate" class="control-label"></label>
                    <input asp-for="CreationDate" class="form-control" />
                    <span asp-validation-for="CreationDate" class="text-danger"></span>
                </div>
                <div class="form-group">
                    <label asp-for="Customer" class="control-label"></label>
                    @await Html.PartialAsync("~/Views/Customer/_SearchCustomerPartial.cshtml")
                    <span asp-validation-for="Customer" class="text-danger"></span>
                </div>
            </div>
        </div>
        <div class="card bg-light">
            <div class="card-header pb-1">
                <h6 class="float-left">Arbeitsstunden</h6>
                <a class="float-right" href="#" onclick="addCraftEmployeePartial()">Hinzufügen</a>
            </div>
            <div id="craftemployeelist" class="card-body">
                @if (Model != null && Model.CraftEmployees != null)
				{
                    @for (int i = 0; i < Model.CraftEmployees.Count; i++)
				    {
                        @await Html.PartialAsync("_CraftEmployeePartial", Model.CraftEmployees[i])
				    }
				}
				else
				{
                    @await Html.PartialAsync("_CraftEmployeePartial", new GreenTree.Strohrmann.ERP.Web.Models.Business.CraftEmployeeModel())
				}
            </div>
        </div>
        @*<div class="card card-maxw bg-light">
            <div class="card-header pb-1">
                <h6>Materialien</h6>
            </div>
            <div class="card-body">
            </div>
        </div>*@
    </div>

    <hr />

    <div class="form-group d-flex mt-3">
        <input type="submit" value="Erstellen" class="btn btn-primary" />
        <div class="align-self-center ml-3">
            <a asp-action="Index">Zurück zur Liste</a>
        </div>
    </div>
</form>