<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<h2 mat-dialog-title>
    Change Version <span class="font-light">({{ versionControlInformation.version }})</span>
</h2>
<div class="change-version">
    <mat-dialog-content>
        <div class="dialog-content flex flex-col gap-y-4 w-full">
            <div class="flex flex-row w-full">
                <div class="w-1/2 pr-2 flex flex-col gap-y-4">
                    <div>
                        <div>Registry</div>
                        <div
                            class="tertiary-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                            [title]="versionControlInformation.registryName">
                            {{ versionControlInformation.registryName }}
                        </div>
                    </div>
                    <div>
                        <div>Bucket</div>
                        <div
                            class="tertiary-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                            [title]="versionControlInformation.bucketName">
                            {{ versionControlInformation.bucketName }}
                        </div>
                    </div>
                </div>
                <div class="w-1/2 pl-2 flex flex-col gap-y-4">
                    <div>
                        @if (versionControlInformation.branch) {
                            <div>Branch</div>
                            <div
                                class="tertiary-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                                [title]="versionControlInformation.branch">
                                {{ versionControlInformation.branch }}
                            </div>
                        }
                    </div>
                    <div>
                        <div>Flow Name</div>
                        <div
                            class="tertiary-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                            [title]="versionControlInformation.flowName">
                            {{ versionControlInformation.flowName }}
                        </div>
                    </div>
                </div>
            </div>
            <div>
                <div>Flow Description</div>
                <div class="tertiary-color font-medium break-words">
                    {{ versionControlInformation.flowDescription || 'No description provided' }}
                </div>
            </div>

            <div class="listing-table flex-1 relative">
                <div class="absolute inset-0 overflow-y-auto overflow-x-hidden">
                    <table
                        mat-table
                        [dataSource]="dataSource"
                        matSort
                        matSortDisableClear
                        (matSortChange)="sortData($event)"
                        [matSortActive]="sort.active"
                        [matSortDirection]="sort.direction">
                        <!-- Current Version Column -->
                        <ng-container matColumnDef="current">
                            <th mat-header-cell *matHeaderCellDef></th>
                            <td mat-cell *matCellDef="let item">
                                @if (isCurrentVersion(item)) {
                                    <div class="flex justify-center items-center">
                                        <i
                                            class="fa fa-check"
                                            nifiTooltip
                                            [tooltipComponentType]="TextTip"
                                            tooltipInputData="Currently installed version"
                                            data-qa="current-version-icon"></i>
                                    </div>
                                }
                            </td>
                        </ng-container>

                        <!-- Version Column -->
                        <ng-container matColumnDef="version">
                            <th mat-header-cell *matHeaderCellDef mat-sort-header>Version</th>
                            <td mat-cell *matCellDef="let item">
                                <div class="overflow-ellipsis overflow-hidden whitespace-nowrap" [title]="item.version">
                                    {{ item.version }}
                                </div>
                            </td>
                        </ng-container>

                        <!-- Create Column -->
                        <ng-container matColumnDef="created">
                            <th mat-header-cell *matHeaderCellDef mat-sort-header>Created</th>
                            <td mat-cell *matCellDef="let item">{{ formatTimestamp(item) }}</td>
                        </ng-container>

                        <!-- Comments Column -->
                        <ng-container matColumnDef="comments">
                            <th mat-header-cell *matHeaderCellDef mat-sort-header>Comments</th>
                            <td mat-cell *matCellDef="let item">
                                <div
                                    class="overflow-ellipsis overflow-hidden whitespace-nowrap"
                                    [title]="item.comments">
                                    {{ item.comments }}
                                </div>
                            </td>
                        </ng-container>

                        <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                        <tr
                            mat-row
                            *matRowDef="let row; let even = even; columns: displayedColumns"
                            (click)="select(row)"
                            (dblclick)="changeFlowVersion()"
                            [class.selected]="isSelected(row)"
                            [class.even]="even"
                            data-qa="version-row"></tr>
                    </table>
                </div>
            </div>
        </div>
    </mat-dialog-content>
    <mat-dialog-actions align="end">
        <button mat-button mat-dialog-close>Cancel</button>
        <button
            [disabled]="!isSelectionValid()"
            type="button"
            (click)="changeFlowVersion()"
            mat-flat-button
            data-qa="change-button">
            Change
        </button>
    </mat-dialog-actions>
</div>
