<div class="row">
    <div class="col-xl-12 col-lg-12 col-md-12">
        <div class="card mb-0">
            <div class="card-header border-0 d-flex">
                <div class="d-flex align-items-center">
                    <div class="lh-1"><span class="avatar avatar-sm avatar-rounded bg-info-transparent me-2"><i
                                class="ti ti-ticket fs-16"></i></span></div>
                    <h4 class="card-title">{{'Refunds' | translate}}</h4>
                    @if(setting?.enableRefund == 'on'){
                    <div class="ms-5">
                        <button class="btn btn-secondary" id="refundButton" type="button"
                            (click)="RaiseRefund(raiseRefundIns)">{{'Request Refund' | translate}}</button>
                    </div>
                    }
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <div class="dashboardtabledata table-responsive">
                        <!--Dashboard List-->
                        <div class="table-options">
                            <mat-form-field class="pull-right">
                                <input type="text" matInput (keyup)="applyFilter($event)"
                                    [placeholder]="'search' | translate" #input>
                            </mat-form-field>
                        </div>
                        <div>
                            @if (isloader) {
                            <mat-progress-bar mode="indeterminate"></mat-progress-bar>
                            }
                            <table
                                class="table table-bordered border-bottom text-nowrap ticketdeleterow w-100 dataTable"
                                mat-table [dataSource]="dataSource" matSort>
                                <!-- Sno Column -->
                                <ng-container matColumnDef="id">
                                    <th scope="col" class="wpx-40 text-center" mat-header-cell *matHeaderCellDef
                                        mat-sort-header>
                                        {{'Sl.No' | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row; let i = index" class="wpx-40 text-center"> {{i +
                                        1 +
                                        (paginator.pageIndex * paginator.pageSize)}} </td>
                                </ng-container>

                                <!-- invoiceId Column -->
                                <ng-container matColumnDef="invoiceId">
                                    <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header="invoiceId">
                                        {{ "Invoice Id" | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row" class="overflow-hidden ticket-details">
                                        {{row.invoiceId}}
                                    </td>
                                </ng-container>

                                <!-- price Column -->
                                <ng-container matColumnDef="price">
                                    <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header="price">
                                        {{ "Price" | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row" class="overflow-hidden ticket-details">
                                        {{row.ticket_type == 'customInvoice' ? getCurrencyPerTicket(row.amount) :
                                        row.customerAmount}}
                                    </td>
                                </ng-container>

                                <!-- paymentFor Column -->
                                <ng-container matColumnDef="paymentFor">
                                    <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header="paymentFor">
                                        {{ "Payment method" | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row" class="overflow-hidden ticket-details">
                                        {{row.payment_method ? row.payment_method : ('Offline Payment' | translate)}}
                                    </td>
                                </ng-container>
                                <!-- Payment Method Column -->
                                <ng-container matColumnDef="paymentMethod">
                                    <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header="paymentMethod">
                                        {{ "Payment Method" | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row" class="overflow-hidden ticket-details">
                                        {{row.ticket_type == 'customInvoice' ? ('Custom Invoice' | translate) : ''}}
                                    </td>
                                </ng-container>


                                <!-- status Column -->
                                <ng-container matColumnDef="status">
                                    <th scope="col" mat-header-cell *matHeaderCellDef mat-sort-header>
                                        {{ "Status" | translate }}
                                    </th>
                                    <td mat-cell *matCellDef="let row">
                                        <span class="badge" [ngClass]="getStatusElement(row.status)">
                                            {{ getStatusText(row.status) }}
                                        </span>
                                        @if(isPaymentRequired(row.status)){
                                        <span class="text-danger">
                                            {{ 'Payment Required*' | translate}}
                                        </span>
                                        }

                                    </td>
                                </ng-container>

                                <!-- Actions Column -->
                                <ng-container matColumnDef="actions">
                                    <th scope="col" mat-header-cell *matHeaderCellDef>
                                        {{ "Actions" | translate}}
                                    </th>
                                    <td mat-cell *matCellDef="let row">
                                        <div>
                                            <a aria-label="View" routerLink="/customer/refund-view/{{row.encrypted_id}}"
                                                href="javascript:;" class="btn btn-sm action-btns"><i
                                                    class="feather feather-eye text-primary" placement="top"
                                                    [ngbTooltip]="'View' | translate"></i></a>
                                        </div>
                                    </td>
                                </ng-container>

                                <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
                                <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>

                                <!-- Row shown when there is no matching data. -->
                                <tr class="mat-row" *matNoDataRow>
                                    @if (!input.value.length) {
                                    <td class="mat-cell text-center" colspan="12">
                                        {{'No data Found'| translate}}
                                    </td>
                                    } @else {
                                    <td class="mat-cell text-center" colspan="12"> {{'No data matching the filter'|
                                        translate}} "
                                        {{input.value}} " </td>
                                    }
                                </tr>
                            </table>

                            <mat-paginator #paginator showFirstLastButtons [pageSizeOptions]="[10, 25, 50, 100]"
                                (page)="onPaginateTable()" aria-label="Select page of users"
                                [length]="paginator?.length" [pageIndex]="paginator?.pageIndex"
                                [pageSize]="paginator?.pageSize">
                            </mat-paginator>
                        </div>
                        <!--Dashboard List-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<ng-template #raiseRefundIns let-modal>
    <div class="modal-header">
        <h4 class="card-title">{{'Request Refund' | translate}}</h4>
        <button type="button" aria-label="close" class="btn-close" (click)="modal.dismiss('Cross click')">
        </button>
    </div>
    <div class="modal-body">
        <div class="single-page customerpage">
            <div class="wrapper wrapper2 box-shadow-0 border-0">
                <div class="card-body border-top-0 pt-4">
                    <form #groupcreate="ngForm" (ngSubmit)="raiseRefundFn(groupcreate, 'createAddonMod')">
                        <div class="row">


                            <div class="form-group">
                                <label class="form-label"> {{'Choose Item For Refund'|translate}}
                                    <span class="text-red"> *</span></label>
                                <ng-select class="form-control" [items]="RefundableItem"
                                [placeholder]="'Select Category' | translate" [virtualScroll]="true" bindLabel="invoiceId"
                                [loading]="!RefundableItem" [multiple]="false" [searchable]="true" dropdownPosition="auto"
                                bindValue="id" name="refundItem" [ngModel]="null">
                                <ng-template ng-option-tmp let-item="item" let-search="searchTerm">
                                  <div><span>{{'Custom Invoice #' + item?.invoiceId}}</span></div>
                                </ng-template>
                              </ng-select>


                            </div>

                            <div class="form-group">
                                <label class="form-label mb-0 mt-2">
                                    {{'Reason for the refund'|translate}}
                                    <span class="text-red"> *</span></label>

                                <textarea name="reason" id="reason" rows="5" class="form-control"
                                    ngModel></textarea>
                            </div>

                        </div>
                        <div class="modal-footer">
                            <a href="javascript:;" class="btn btn-outline-danger"
                                (click)="modal.dismiss('Close click')">{{'Close' | translate}}</a>
                            <button type="submit" [disabled]="groupcreate.invalid || sendingResponse['createAddonMod']"
                                class="btn btn-secondary">{{'Save changes' | translate}}
                                @if(sendingResponse['createAddonMod']){
                                <i class="fa fa-spinner fa-spin mx-1"></i>
                                }
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</ng-template>