@inherits Microsoft.Extensions.CodeGeneration.Templating.RazorTemplateBase
@using Microsoft.Extensions.CodeGeneration.EntityFramework
@@model @Model.ViewDataTypeName

@{
    if (Model.IsPartialView)
    {
    }
    else if (Model.IsLayoutPageSelected)
    {
@:@@{
    @:ViewData["Title"] = @@SR["@Model.ViewName"];
        if (!string.IsNullOrEmpty(Model.LayoutPageFile))
        {
    @:Layout = "@Model.LayoutPageFile";
        }
@:}
@:
@:<h2>@@SR["@Model.ViewName"]</h2>
@:
    }
    else
    {
@:@@{
    @:Layout = null;
@:}
@:
@:<!DOCTYPE html>
@:
@:<html>
@:<head>
    @:<meta name="viewport" content="width=device-width" />
    @:<title>@@SR["@Model.ViewName"]</title>
@:</head>
@:<body>
@:
        //    PushIndent("    ");
    }
@:<form asp-action="@Model.ViewName">
    @:<div class="form-horizontal">
        @:<h4>@Model.ViewDataTypeShortName</h4>
        @:<hr />
        @:<div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"></div>
    foreach (PropertyMetadata property in Model.ModelMetadata.Properties)
    {
        if (property.Scaffold)
        {
            if (property.IsPrimaryKey)
            {
        @:<input type="hidden" asp-for="@property.PropertyName" />
                continue;
            }
            if (property.IsReadOnly)
            {
                continue;
            }

            if (property.IsForeignKey)
            {
        @:<div class="form-group">
            @:<label asp-for="@property.PropertyName" class="control-label col-md-2">@GetAssociationName(property)</label>
            @:<div class="col-md-10">
                @:<select asp-for="@property.PropertyName" class="form-control" ></select>
                @:<span asp-validation-for="@property.PropertyName" class="text-danger" ></span>
            @:</div>
        @:</div>
                continue;
            }

            bool isCheckbox = property.TypeName.Equals("System.Boolean");
            if (isCheckbox)
            {
        @:<div class="form-group">
            @:<div class="col-md-offset-2 col-md-10">
                @:<div class="checkbox">
                    @:<input asp-for="@property.PropertyName" />
                    @:<label asp-for="@property.PropertyName"></label>
                @:</div>
            @:</div>
        @:</div>
            }
            else if (property.IsEnum && !property.IsEnumFlags)
            {
        @:<div class="form-group">
            @:<label asp-for="@property.PropertyName" class="col-md-2 control-label"></label>
            @:<div class="col-md-10">
                @:<select asp-for="@property.PropertyName" class="form-control"></select>
                @:<span asp-validation-for="@property.PropertyName" class="text-danger" ></span>
            @:</div>
        @:</div>
            }
            else
            {
        @:<div class="form-group">
            @:<label asp-for="@property.PropertyName" class="col-md-2 control-label"></label>
            @:<div class="col-md-10">
                @:<input asp-for="@property.PropertyName" class="form-control" />
                @:<span asp-validation-for="@property.PropertyName" class="text-danger"></span>
            @:</div>
        @:</div>
            }
        }
    }
}
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
</form>

<div>
    <a asp-action="Index">@@SR["Back to List"]</a>
</div>

@{
    if (Model.ReferenceScriptLibraries && (Model.IsLayoutPageSelected || Model.IsPartialView))
    {
@:@@section Scripts {
    @:<script src="~/lib/jquery/dist/jquery.min.js"></script>
    @:<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
    @:<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@:}
    }
    // The following code closes the tag used in the case of a view using a layout page and the body and html tags in the case of a regular view page
    if (!Model.IsPartialView && !Model.IsLayoutPageSelected)
    {
        if (Model.ReferenceScriptLibraries)
        {
@:@@section Scripts {
    @:<script src="~/lib/jquery/dist/jquery.min.js"></script>
    @:<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
    @:<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@:}
        //ClearIndent();
        }
@:</body>
@:</html>
    }
}
@functions
{
    string GetAssociationName(PropertyMetadata property)
    {
        //Todo: Implement properly.
        return property.PropertyName;
    }
}
