<!--
  ~ 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.
  -->

<section tabindex="0">
    <div class="extension-creation-dialog p-4 flex flex-col justify-between gap-y-3">
        <div class="flex justify-between items-center">
            <h3 class="text-lg">Add {{ componentType }}</h3>
            <div>
                <input
                    class="border px-1.5 py-1 w-64"
                    type="text"
                    (keyup)="filterTypes($event)"
                    placeholder="Filter types..." />
            </div>
        </div>
        <div class="type-table">
            <div class="h-96 overflow-y-auto overflow-x-hidden border">
                <table
                    mat-table
                    [dataSource]="dataSource"
                    matSort
                    matSortDisableClear
                    (matSortChange)="sortData($event)"
                    [matSortActive]="initialSortColumn"
                    [matSortDirection]="initialSortDirection">
                    <!-- Type Column -->
                    <ng-container matColumnDef="type">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header>Type</th>
                        <td mat-cell *matCellDef="let item">
                            <div
                                class="fa"
                                [class.fa-shield]="item.restricted"
                                nifiTooltip
                                [tooltipComponentType]="RestrictionsTip"
                                [tooltipInputData]="getRestrictionTipData(item)"></div>
                            {{ formatType(item) }}
                        </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">
                            {{ formatVersion(item) }}
                            <div
                                class="fa fa-list"
                                *ngIf="implementsControllerService(item)"
                                nifiTooltip
                                [tooltipComponentType]="ControllerServiceApiTip"
                                [tooltipInputData]="getControllerServiceApiTipData(item)"></div>
                        </td>
                    </ng-container>

                    <!-- Tags Column -->
                    <ng-container matColumnDef="tags">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header>Tags</th>
                        <td mat-cell *matCellDef="let item">{{ formatTags(item) }}</td>
                    </ng-container>

                    <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                    <tr
                        mat-row
                        *matRowDef="let row; let even = even; columns: displayedColumns"
                        (click)="selectType(row)"
                        (dblclick)="createExtension(row)"
                        [class.selected]="isSelected(row)"
                        [class.even]="even"></tr>
                </table>
            </div>
        </div>
        <div class="flex flex-col">
            <ng-container *ngIf="selectedType; else noSelection">
                <div class="flex items-center">
                    <div class="selected-type-name">{{ formatType(selectedType) }}</div>
                    <div class="selected-type-bundle">{{ formatBundle(selectedType) }}</div>
                </div>
                <div class="selected-type-description" [title]="formatDescription(selectedType)">
                    {{ formatDescription(selectedType) }}
                </div>
            </ng-container>
            <ng-template #noSelection>
                <div class="no-selected-type unset">No type selected</div>
            </ng-template>
        </div>
        <div class="flex justify-end gap-x-2">
            <button color="accent" mat-raised-button mat-dialog-close>Cancel</button>
            <button
                [disabled]="selectedType == null || saving"
                color="primary"
                (click)="createExtension(selectedType)"
                mat-raised-button>
                <span *nifiSpinner="saving">Add</span>
            </button>
        </div>
    </div>
</section>
