@model PantheonApi.SyncApi.ViewModels.SyncTableFiltersViewModel
@using PantheonApi.SyncApi.Enumerations

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@Html.Hidden("DeleteColumnValueUrl", Url.Action("DeleteSyncFilterColumnValue", "PartialSync"))
@Html.Hidden("DeleteReferencedTableUrl", Url.Action("DeleteSyncFilterReferencedTable", "PartialSync"))
@Html.Hidden("RedirectUrl", Url.Action("Edit", "PartialSync"))
@Html.Hidden("EditColumnValueUrl", Url.Action("EditColumnValue", "PartialSync"))
@Html.Hidden("EditReferencedTableUrl", Url.Action("EditReferencedTable", "PartialSync"))

<h2>Set up table @TempData["Table-Name"] for partial sync</h2>
<br />
<br />

<ul class="nav nav-tabs">
    <li class="active"><a data-toggle="tab" href="#column-value">Sync filter column values</a></li>
    <li><a data-toggle="tab" href="#referenced-table">Sync filter referenced table</a></li>
</ul>
<br />

<div class="tab-content">
    @*Sync filter column value tab*@
    <div id="column-value" class="tab-pane fade in active">
        <button class="btn btn-success" onclick="openColumnValueModal(0, '@Model.TableName', false)">Add column value</button>
        @*Table*@
        @if (TempData["Table-Message"] != null)
        {
            <div class="alert alert-info no-border">
                <button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
                <span class="text-semibold">@TempData["Table-Message"]</span>
            </div>
        }

        <table class="table table-hover table-bordered table-striped">
            <thead class="bg-primary">
                <tr>
                    <th>Source table name</th>
                    <th>Source column name</th>
                    <th>Value</th>
                    <th>Type</th>
                    <th>Document type</th>
                    <th>Device id</th>
                    <th>Criteria</th>
                    <th>Active</th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.SyncFilterColumnValueData)
                {
                    <tr>
                        <td>@item.SourceTableName</td>
                        <td>@item.SourceColumnName</td>
                        <td>@item.Value</td>
                        <td>@item.Type</td>
                        <td>@item.DocType</td>
                        <td>@item.DeviceId</td>
                        <td>@item.Criteria</td>
                        <td>@item.Active</td>
                        <td><a onclick="openColumnValueModal('@item.Id', '@item.SourceTableName', true)">Edit</a></td>
                        <td><a onclick="deleteColumnValue('@item.Id', '@item.SourceTableName')">Delete</a></td>
                    </tr>
                }
            </tbody>
        </table>

    </div>

    @*Sync filter reference table tab*@
<div id="referenced-table" class="tab-pane fade">
    <button class="btn btn-success" onclick="openReferencedTableModal(0, '@Model.TableName', false)">Add referenced table</button>
    @*Table*@
    @if (TempData["Table-Message"] != null)
    {
        <div class="alert alert-info no-border">
            <button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
            <span class="text-semibold">@TempData["Table-Message"]</span>
        </div>
    }

    <table class="table table-hover table-bordered table-striped">
        <thead class="bg-primary">
            <tr>
                <th>Source table name</th>
                <th>Source column name</th>
                <th>Referenced table name</th>
                <th>Referenced column name</th>
                <th>Referenced column document type column name</th>
                <th>Condition</th>
                <th>Active</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.SyncFilterReferencedTableData)
            {
                <tr>
                    <td>@item.SourceTableName</td>
                    <td>@item.SourceColumnName</td>
                    <td>@item.ReferencedTableName</td>
                    <td>@item.ReferencedColumnName</td>
                    <td>@item.ReferencedDocTypeColumnName</td>
                    <td>@item.Condition</td>
                    <td>@item.Active</td>
                    <td><a onclick="openReferencedTableModal('@item.Id', '@item.SourceTableName', true)">Edit</a></td>
                    <td><a onclick="deleteReferencedTable('@item.Id', '@item.SourceTableName')">Delete</a></td>
                </tr>
            }
        </tbody>
    </table>
</div>
</div>

@Html.Partial("_AddColumnValueModal", Model.ColumnValueModel)
@Html.Partial("_AddReferencedTableModal", Model.ReferenceTableModel)