<div id="layout-wrapper">
    <div class="inner-pg-sp">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="d-sm-flex align-items-center justify-content-between navbar-header p-0">

                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="col-xl-12 mt-4">
                    <div class="card border">
                        <div class="card-body">
                            <div class="table-section">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="card-body mt-2 p-0">
                                            <div class="card mb-0 mt-2">
                                                <div
                                                    class="card-header font-edit-13-child d-flex justify-content-between align-items-center">
                                                    {{'loggerManager' | translate}}
                                                </div>
                                                <div class="card-body">
                                                    <form [formGroup]="logsSearchForm">
                                                        <div class="row g-3 mb-3">
                                                            <div class="col-md-6">
                                                                <div class="d-flex align-items-center gap-2">
                                                                    <label for="fromDate" class="text-nowrap">
                                                                        {{ 'fromDate' | translate }}<span
                                                                            class="mandatory">*</span>
                                                                    </label>
                                                                    <div
                                                                        class="password-wrapper position-relative w-100">
                                                                        <div
                                                                            class="d-flex flex-row align-items-stretch">
                                                                            <input formControlName="fromDate"
                                                                                type="date" id="fromDate"
                                                                                class="form-control" appNoWhitespaces />

                                                                        </div>
                                                                        <div class="text-danger"
                                                                            *ngIf="logsSearchForm.get('fromDate')?.touched && logsSearchForm.get('fromDate')?.invalid">
                                                                            {{ 'fieldRequired' | translate }}
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6">
                                                                <div class="d-flex align-items-start gap-2">
                                                                    <label for="toDate" class="text-nowrap mt-2">
                                                                        {{ 'toDate' | translate }}<span
                                                                            class="mandatory">*</span>
                                                                    </label>
                                                                    <div
                                                                        class="password-wrapper position-relative w-100">

                                                                        <input formControlName="toDate" id="toDate"
                                                                            type="date" class="form-control"
                                                                            maxlength="500" appNoWhitespaces rows="3" />
                                                                        <div class="text-danger" *ngIf="
                                                                            logsSearchForm.get('toDate')?.touched &&
                                                                            (logsSearchForm.get('toDate')?.invalid || logsSearchForm.errors?.['toDateInvalid'] || logsSearchForm.errors?.['toDateGreaterThanToday'])
                                                                          ">
                                                                            <div
                                                                                *ngIf="logsSearchForm.get('toDate')?.hasError('required')">
                                                                                {{ 'fieldRequired' | translate }}
                                                                            </div>

                                                                            <div
                                                                                *ngIf="logsSearchForm.errors?.['toDateInvalid']">
                                                                                {{ 'toDateInvalidError' | translate }}
                                                                            </div>
                                                                            <div
                                                                                *ngIf="logsSearchForm.errors?.['toDateGreaterThanToday']">
                                                                                {{ 'toDateGreaterThanToday' | translate }}
                                                                            </div>
                                                                        </div>



                                                                    </div>
                                                                </div>
                                                            </div>

                                                        </div>

                                                        <div class="row g-3 mb-3">
                                                            <div class="col-md-6 ms-auto text-end">
                                                                <button [disabled]="logsSearchForm.invalid"
                                                                    (click)="getlogsData()"
                                                                    class="btn btn-primary waves-effect waves-light">{{'findLogs'
                                                                    | translate}}</button>


                                                            </div>
                                                        </div>


                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="col-xl-12 mt-4">
                    <div class="card border">
                        <div class="card-body">
                            <div class="table-section">
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="card-body mt-2 p-0">
                                            <div class="card mb-0 mt-2">
                                                <div
                                                    class="card-header font-edit-13-child d-flex justify-content-between align-items-center">
                                                    {{'loggerManagerDetails' | translate}}
                                                    <div class="d-flex align-items-center gap-2" *ngIf="allItems.length">
                                                        <div class="search-box">
                                                            <input type="text" class="form-control form-control-sm" [(ngModel)]="searchText"
                                                                placeholder="{{ 'search' | translate }}">
                                                            <i class="fas fa-search search-icon"></i>
                                                        </div>

                                                        <i (click)="exportDataInExcel()" id="downloadReport" class="fa fa-download"></i>

                                                        <i class="materialdesignicons" (click)="toggleTableCard()">
                                                            <ng-container *ngIf="logsDataExpanded; else collapsedIcon">
                                                                <i class="dripicons-chevron-up float-end"></i>
                                                            </ng-container>
                                                            <ng-template #collapsedIcon>
                                                                <i class="dripicons-chevron-down float-end"></i>
                                                            </ng-template>
                                                        </i>
                                                    </div>
                                                </div>
                                                <div class="card-body" *ngIf="logsDataExpanded && allItems.length; else noRecordsFound">
                                                    <div class="table-responsive">
                                                        <table class="table mb-0 border">
                                                            <thead class="table-light">
                                                                <tr>
                                                                    <th>{{'loggingID' | translate}}</th>
                                                                    <th>{{'loggingRequestUri' | translate}}</th>
                                                                    <th>{{'loggingResponseCode' | translate}}</th>
                                                                    <th>{{'loggingRemoteIP' | translate}}</th>
                                                                    <th>{{'loggingDateTime' | translate}}</th>
                                                                    <th>{{'loggingMethod' | translate}}</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <tr
                                                                    *ngFor="let logs of (allItems | tableFilter: searchText: ['id','method','remoteIp','requestBody','requestUri','responseCode','userId','dateTime']).slice((currentPage-1)*itemsPerPage, currentPage*itemsPerPage)">
                                                                    <td>{{logs?.id}}</td>
                                                                    <td>{{logs?.requestUri}}</td>
                                                                    <td>{{logs?.responseCode}}</td>
                                                                    <td>{{logs?.remoteIp}}</td>
                                                                    <td>{{logs?.dateTime | date:'dd-MM-yyyy, hh:mm a'}}</td>
                                                                    <td>{{logs?.method}}</td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                        <div
                                                            class="d-flex justify-content-between align-items-center mt-3">
                                                            <div class="form-group mb-0">
                                                                <ng-select class="form-select-sm"
                                                                    [items]="pageSizeOptions" bindLabel="label"
                                                                    bindValue="value" [(ngModel)]="itemsPerPage"
                                                                    [searchable]="false"
                                                                    (change)="itemsPerPageChanged()" [clearable]="false"
                                                                    [dropdownPosition]="'top'">
                                                                </ng-select>
                                                            </div>

                                                            <div class="text-muted" *ngIf="allItems.length > 1">
                                                                {{'page' | translate}} {{currentPage}} {{'of' |
                                                                translate}} {{totalPages()}} ({{allItems.length}}
                                                                {{'totalItems' | translate}})
                                                            </div>
                                                            <div class="text-muted" *ngIf="allItems.length === 0">
                                                                {{'no_record' | translate}}
                                                            </div>
                                                            <div class="text-muted" *ngIf="allItems.length === 1">
                                                                {{'page' | translate}} {{currentPage}} {{'of' |
                                                                translate}} {{totalPages()}} ({{allItems.length}}
                                                                {{'record' | translate}})
                                                            </div>

                                                            <div class="btn-group">
                                                                <button class="btn btn-primary waves-effect waves-light"
                                                                    (click)="previousPage()"
                                                                    [disabled]="currentPage === 1">
                                                                    {{ 'previous' | translate }}
                                                                </button>
                                                                <button class="btn btn-primary waves-effect waves-light"
                                                                    (click)="nextPage()"
                                                                    [disabled]="currentPage >= totalPages()">
                                                                    {{ 'next' | translate }}
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<ng-template #noRecordsFound>
    <div *ngIf="!isLoading && logsList.length === 0" class="text-center text-muted mt-3">
        <p>{{'noLoggingDetailsFound' | translate}}</p>
    </div>
</ng-template>