@model StubAP.ViewModels.ProfileViewModel
@using StubCore.Entities
@{
    ViewData["Title"] = "Edit profile";
    ViewData["Description"] = "Change existing profile";
    int lineNumber = 1;
}
<section class="addProfile">
    <div class="contentBlock">
        <div class="fieldHeader">
            <h1>Edit profile</h1>
        </div>
        @using (Html.BeginForm("edit", "profile", null, FormMethod.Post, new { id = "editProfile", autocomplete = "off", enctype = "multipart/form-data" }))
        {
            <div class="fieldContainer">
                <div class="fieldBox">
                    @Html.LabelFor(model => model.id)
                    @Html.TextBoxFor(model => model.id, new { @class = "fieldInput", @disabled = "disabled" })
                    @Html.HiddenFor(model => model.id)
                </div>
                <div class="fieldBox">
                    @Html.LabelFor(model => model.profileName)
                    @Html.TextBoxFor(model => model.profileName, new { @class = "fieldInput", @placeholder = "Name of new profile" })
                    @Html.ValidationMessageFor(model => model.profileName)
                </div>
            </div>
            <div class="fieldContainer">
                <div class="fieldBox">
                    @Html.LabelFor(model => model.requestType)
                    @Html.DropDownListFor(model => model.requestType, new SelectList(Model.requestTypeOptions, "id", "value"), new { @class = "fieldSelect" })
                    @Html.ValidationMessageFor(model => model.requestType)
                </div>
                <div class="fieldBox">
                    @Html.LabelFor(model => model.transport)
                    @Html.DropDownListFor(model => model.transport, new SelectList(Model.transportOptions, "id", "value"), new { @class = "fieldSelect" })
                    @Html.ValidationMessageFor(model => model.transport)
                </div>
            </div>

            <div class="fieldContainer">
                <div class="fieldBox">
                    @Html.LabelFor(model => model.ResponseDelay)
                    @Html.TextBoxFor(model => model.ResponseDelay, new { @class = "fieldInput", @placeholder = "Select delay in seconds" })
                    @Html.ValidationMessageFor(model => model.ResponseDelay)
                </div>
                <div class="fieldBox"></div>
            </div>

            <div class="fieldFilesbox">
                <div class="fieldContainer fieldset">
                    <div class="fieldBox">
                        @Html.LabelFor(model => model.xmlNode)
                        @Html.TextBoxFor(model => model.xmlNode, new { @id = "nodeName", @class = "fieldInput", @placeholder = "Name of key field, what will be used for parsing" })
                        @Html.ValidationMessageFor(model => model.xmlNode)
                    </div>
                    <div class="fieldBox">
                        <div class="labelBuffer">Add</div>
                        <div class="st_addNew jsAction" data-type="node" data-action="add">Add key field</div>
                    </div>
                </div>
                <div class="dataTableArea">
                    <div class="st_dataList">
                        <div class="listHeaders">
                            <div class="contentHBlock">Key node name</div>
                            <div class="contentHBlock">Node included files</div>
                            <div class="actionHBlock">Action</div>
                        </div>
                        <div class="st_filesListIn">
                            <ul id="st_nodes">
                                @if (Model.XmlNodesList != null && Model.XmlNodesList.Count > 0)
                                {
                                    foreach (string node in Model.XmlNodesList)
                                    {
                                        <li id="@node.Replace(" ", "-").Replace(":", "-").ToLower()">
                                            <div class="contentBlock">@node</div>
                                            <div class="contentBlock">
                                                @{
                                                    if (Model.filesList != null && Model.filesList.Count > 0)
                                                    {
                                                        string content = String.Empty;
                                                        int i = 1;
                                                        foreach (string file in Model.filesList)
                                                        {
                                                            content += file;
                                                            if (i < Model.filesList.Count)
                                                            {
                                                                content += ", ";
                                                            }
                                                            i++;
                                                        }
                                                        @Html.Raw(content);
                                                    }
                                                }
                                            </div>
                                            <div class="actionBlock">
                                                <a data-value="@node" data-action="edit" data-type="node" href="#" class="sActionButton jsAction" style="display:none">Edit</a>
                                                <a data-value="@node" data-ref="@Model.profileReference" data-route="edit" data-action="delete" data-type="node" href="#" class="sActionButton jsAction">Delete</a>
                                            </div>
                                        </li>
                                    }
                                }
                                else
                                {
                                    <li class="noresults">No nodes was found</li>
                                }
                            </ul>

                        </div>
                    </div>
                </div>
                <div class="fieldContainer fieldset">
                    <div class="fieldBox">
                        @Html.LabelFor(model => model.profileFiles)
                        @Html.TextBoxFor(model => model.profileFiles, new { type = "file", @id = "nodeFiles", @class = "custom-file-input jsAction", @data_action = "addFiles", Multiple = "multiple" })
                        @Html.ValidationMessageFor(model => model.profileFiles)
                        
                            @if (Model.filesList != null && Model.filesList.Count > 0)
                            {
                                <div id="st_files">
                                    @foreach (string file in Model.filesList)
                                    {
                                        @Html.Raw(lineNumber + ". " + file + "<br>");
                                        lineNumber++;
                                    }
                                </div>
                            }
                                
                        <div id="st_fileSet" style="display:none"></div>
                    </div>
                </div>
            </div>
            <div class="nameSpaceBox">
                <div class="fieldContainer fieldset">
                    <div class="fieldBox">
                        @Html.LabelFor(model => model.nameSpace)
                        @Html.TextBoxFor(model => model.nameSpace, new { @id = "spaceName", @class = "fieldInput", @placeholder = "Name of namespace" })
                        @Html.ValidationMessageFor(model => model.nameSpace)
                    </div>
                    <div class="fieldBox">
                        @Html.LabelFor(model => model.nameSpaceValue)
                        @Html.TextBoxFor(model => model.nameSpaceValue, new { @id = "spaceValue", @class = "fieldInput", @placeholder = "Value of namespace" })
                        @Html.ValidationMessageFor(model => model.nameSpaceValue)
                    </div>
                </div>
                <div class="st_addNew jsAction" data-type="namespace" data-action="add">Add namespace</div>
                <div class="dataTableArea">
                    <div class="st_dataList">
                        <div class="listHeaders">
                            <div class="contentHBlock">Namespace name</div>
                            <div class="contentHBlock">Namespace value</div>
                            <div class="actionHBlock">Action</div>
                        </div>
                        <div class="st_filesListIn">
                            <ul id="st_namespace">
                                @if (Model.nameSpaceList != null && Model.nameSpaceList.Count > 0)
                                {
                                    foreach (TType nameSpace in Model.nameSpaceList)
                                    {
                                        <li id="@nameSpace.id.Replace(" ", "-").Replace(":", "-").ToLower()">
                                            <div class="contentBlock">@nameSpace.id</div>
                                            <div class="contentBlock">@nameSpace.value</div>
                                            <div class="actionBlock">
                                                <a data-value="@nameSpace.id" data-action="edit" data-type="namespace" href="#" class="sActionButton jsAction" style="display:none">Edit</a>
                                                <a data-value="@nameSpace.id" data-ref="@Model.profileReference" data-route="edit" data-action="delete" data-type="namespace" href="#" class="sActionButton jsAction">Delete</a>
                                            </div>
                                        </li>
                                    }
                                }
                                else
                                {
                                    <li class="noresults ns">No namespaces was found</li>
                                }
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <div class="submitContainer">
                <input type="submit" value="Save changes" class="actionButton" />
            </div>
            @Html.HiddenFor(model => model.tempID, new { @id = "tempID" })
        }
    </div>
</section>
<script type="text/javascript">
    $.fn.platform();
</script>