﻿@using Microsoft.AspNetCore.Http.Extensions
@model Definux.Emeraude.Admin.UI.ViewModels.Logging.ActivityLogsViewModel
@{
    Layout = "_LoggerSubLayout";
    ViewData.SetTitle("Activity Logs");
    var tablePagination = new TablePaginationViewModel(Model.CurrentPage, Model.PagesCount);
    ViewData["LoggerTablePagination"] = tablePagination;
    var modalsViewModels = new List<ModalViewModel>();
}

<default-table column-1="Id"
               column-2="Route"
               column-3="Involved User"
               column-4="Trace Id"
               column-5="Mobile Device"
               column-6="Method"
               column-7="Created On"
               column-8="">
    @foreach (var activityLog in Model.Items)
    {
        var parametersModal = new ModalViewModel
        {
            LunchButtonClasses = "btn btn-icons action-btn btn-primary",
            LunchButtonIcon = "<i class=\"mdi mdi-json m-0\"></i>",
            ModalId = $"parameters-modal-{activityLog.Id}",
            Type = ModalType.Normal,
            ModalHeaderClasses = "pb-0",
            ModalBodyClasses = "py-0",
            Content = $"<div class=\"prettify-json\">{activityLog.Parameters}</div>",
            ContentClass = "p-2 border",
            IsContentHtml = true,
            Title = "Parameters",
            HasCloseButton = true
        };
                    
        var headersModal = new ModalViewModel
        {
            LunchButtonClasses = "btn btn-icons action-btn btn-primary",
            LunchButtonIcon = "<i class=\"mdi mdi-iframe-outline m-0\"></i>",
            ModalId = $"headers-modal-{activityLog.Id}",
            Type = ModalType.Large,
            ModalHeaderClasses = "pb-0",
            ModalBodyClasses = "py-0",
            Content = $"<div class=\"prettify-json\">{activityLog.Headers}</div>",
            ContentClass = "p-2 border",
            IsContentHtml = true,
            Title = "Headers",
            HasCloseButton = true
        };
                    
        var userAgentModal = new ModalViewModel
        {
            LunchButtonClasses = "btn btn-icons action-btn btn-primary",
            LunchButtonIcon = "<i class=\"mdi mdi-web-box m-0\"></i>",
            ModalId = $"user-agent-modal-{activityLog.Id}",
            Type = ModalType.Normal,
            ModalHeaderClasses = "pb-0",
            ModalBodyClasses = "py-0",
            Content = $"<div>{activityLog.UserAgent}</div>",
            ContentClass = "p-2 border overflow-wrap-anywhere",
            IsContentHtml = true,
            Title = "User Agent",
            HasCloseButton = true
        };
                  
        modalsViewModels.Add(parametersModal);
        modalsViewModels.Add(headersModal);
        modalsViewModels.Add(userAgentModal);
        
        <tr>
            <td default-table-cell="true">
                @activityLog.Id
            </td>
            <td default-table-cell="true">
                @activityLog.Route
            </td>
            <td default-table-cell="true">
                @(activityLog.InvolvedUser != null ? $"{activityLog.InvolvedUser.Name} ({activityLog.InvolvedUser.Email})" : string.Empty)
            </td>
            <td default-table-cell="true">
                @activityLog.TraceId
            </td>
            <td default-table-cell="true">
                <flag value="@activityLog.IsFromMobileDevice"/>
            </td>
            <td default-table-cell="true">
                @activityLog.Method
            </td>
            <td default-table-cell="true">
                @activityLog.CreatedOn
            </td>
            <td default-table-cell="true" fit="true">
                <partial name="_ModalLunchButton" model="parametersModal"/>
                <partial name="_ModalLunchButton" model="headersModal"/>
                <partial name="_ModalLunchButton" model="userAgentModal"/>
                @{
                    var deleteLoggerEntityFormModel = new DeleteLoggerEntityFormModel
                    {
                        EntityId = activityLog.Id,
                        LoggerEntityType = "activity",
                        FormClasses = "ml-1 d-inline-block",
                        ButtonClasses = "btn btn-icons action-btn btn-primary",
                        ButtonIconClasses = "mdi mdi-delete",
                    };
                }
                <partial name="_DeleteLoggerEntityForm" model="deleteLoggerEntityFormModel"/>
            </td>
        </tr>
    }
</default-table>

@foreach (var modalViewModel in modalsViewModels)
{
    <partial name="_Modal" model="@modalViewModel"/>
}