@{
    ViewData["Title"] = "View Templates";
    Layout = "~/Views/Shared/_GuruLayout.cshtml";
}

@model EForT.Models.TemplateModel

@using (Html.BeginForm("ViewTemplates", "Template", FormMethod.Post, Model.ListOfTemplates))
{
    <div class="app-content container center-layout py-3">
        <div class="content-header row">
            <div class="content-header-left col-12 mb-2">
                <h1 class="content-header-title mb-0">View Templates</h1>
                <div class="row breadcrumbs-top">
                    <div class="breadcrumb-wrapper col-12">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="@Url.Action("Guru", "Home")">Home</a>
                            </li>
                            <li class="breadcrumb-item">
                                Templates
                            </li>
                            <li class="breadcrumb-item active">
                                View Templates
                            </li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-wrapper">
            <div class="content-body">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header pb-0">
                                <div class="font-medium-2 bottom-border">
                                    <p>Templates List</p>
                                </div>
                                <div class="heading-elements">
                                    <a href="@Url.Action("AddTemplate", "Template")" class="btn btn-sm btn-icon btn-primary">Add Template</a>
                                </div>
                            </div>
                            <div class="card-body pt-2">
                                <div class="table-responsive">
                                    <table id="users-list" class="table table-striped table-bordered">
                                        <thead>
                                            <tr>
                                                <th scope="col" style="width:30%; min-width:200px;">Name</th>
                                                <th scope="col" style="width:10%" class="text-center">Enabled</th>
                                                <th scope="col" style="width:10%" class="text-center">Edit</th>
                                                <th scope="col" style="width:10%" class="text-center">Delete</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @if (Model.ListOfTemplates != null)
                                            {
                                                if (Model.ListOfTemplates.ToList().Count > 0)
                                                {
                                                    @for (int i = 0; i < Model.ListOfTemplates.ToList().Count; i++)
                                                    {
                                                        <tr>
                                                            <td>@Model.ListOfTemplates.ToArray()[i].Filename</td>
                                                            <td class="text-center">
                                                                <label class="switch display-inline-block mb-0">
                                                                    <input type="checkbox" asp-for="@Model.ListOfTemplates.ToArray()[i].Enabled" id="@Model.ListOfTemplates.ToArray()[i].Id" class="checkbox_scripts" onclick="toggleTemplate(@Model.ListOfTemplates.ToArray()[i].Id)">
                                                                    <span class="slider round"></span>
                                                                </label>
                                                            </td>
                                                            <td class="text-center">
                                                                <a href="@Url.Action("EditTemplate", "Template", new { Id = Model.ListOfTemplates.ToArray()[i].Id })" title="Edit Template" class="btn btn-icon btn-pure secondary"><i class="fa fa-pencil"></i></a>
                                                            </td>
                                                            <td class="text-center">
                                                                <a href="@Url.Action("DeleteTemplate", "Template", new { Id = Model.ListOfTemplates.ToArray()[i].Id })" onclick="return confirm('Are you sure you want to delete the template?')" title="Delete Template" class="btn btn-icon btn-pure danger"><i class="fa fa-trash"></i></a>
                                                            </td>
                                                        </tr>
                                                    }
                                                }
                                                else
                                                {
                                                    <tr>
                                                        <td colspan="5" class="danger text-center">No Templates in the system</td>
                                                    </tr>
                                                }
                                            }
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}