<!--
  ~ 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>Disable Controller Service</h2>
@if ((controllerService$ | async)!; as controllerService) {
    @if ((disableRequest$ | async)!; as disableRequest) {
        <div class="controller-service-disable-form">
            @if (disableRequest.currentStep === SetEnableStep.Pending) {
                <mat-dialog-content>
                    <div class="py-4 flex gap-x-4">
                        <div class="flex basis-2/3 flex-col gap-y-4 pr-4 overflow-hidden">
                            <div class="flex flex-col">
                                <div>Service</div>
                                <div
                                    class="accent-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                                    [title]="controllerService.component.name">
                                    {{ controllerService.component.name }}
                                </div>
                            </div>
                            <div class="flex flex-col">
                                <div>Scope</div>
                                <div>
                                    <span class="accent-color font-medium">Service and referencing components</span>
                                    <i
                                        class="fa fa-info-circle ml-1"
                                        nifiTooltip
                                        [tooltipComponentType]="TextTip"
                                        tooltipInputData="Referencing components must be disabled/stopped in order to disable this service."></i>
                                </div>
                            </div>
                        </div>
                        <div class="flex basis-1/3 flex-col">
                            <div>
                                Referencing Components
                                <i
                                    class="fa fa-info-circle"
                                    nifiTooltip
                                    [tooltipComponentType]="TextTip"
                                    tooltipInputData="Other components referencing this controller service."></i>
                            </div>
                            <div class="relative h-full border" style="min-height: 320px">
                                <div class="absolute inset-0 overflow-y-auto p-1">
                                    <controller-service-references
                                        [serviceReferences]="controllerService.component.referencingComponents"
                                        [goToReferencingComponent]="
                                            goToReferencingComponent
                                        "></controller-service-references>
                                </div>
                            </div>
                        </div>
                    </div>
                </mat-dialog-content>
                <mat-dialog-actions align="end">
                    <button mat-button mat-dialog-close>Cancel</button>
                    <button type="button" color="primary" (click)="submitForm()" mat-button>Disable</button>
                </mat-dialog-actions>
            } @else {
                <mat-dialog-content>
                    <div class="py-4 flex gap-x-4">
                        <div class="flex basis-2/3 flex-col gap-y-4 pr-4 overflow-hidden">
                            <div class="flex flex-col">
                                <div>Service</div>
                                <div
                                    class="accent-color font-medium overflow-ellipsis overflow-hidden whitespace-nowrap"
                                    [title]="controllerService.component.name">
                                    {{ controllerService.component.name }}
                                </div>
                            </div>
                            <div class="flex flex-col">
                                <div
                                    class="overflow-ellipsis overflow-hidden whitespace-nowrap"
                                    title="Steps To Disable {{ controllerService.component.name }}">
                                    Steps To Disable {{ controllerService.component.name }}
                                </div>
                                <div class="flex flex-col gap-y-1.5">
                                    <div class="flex justify-between items-center">
                                        <div class="accent-color font-medium">
                                            Stopping referencing processors and reporting tasks
                                        </div>
                                        <ng-container
                                            *ngTemplateOutlet="
                                                getTemplateForStep(
                                                    SetEnableStep.StopReferencingComponents,
                                                    disableRequest
                                                )
                                            "></ng-container>
                                    </div>
                                    @if (
                                        disableRequest.error &&
                                        disableRequest.error.step == SetEnableStep.StopReferencingComponents
                                    ) {
                                        <div class="text-sm ml-2">
                                            {{ disableRequest.error.error }}
                                        </div>
                                    }
                                    <div class="flex justify-between items-center">
                                        <div class="accent-color font-medium">
                                            Disabling referencing controller services
                                        </div>
                                        <ng-container
                                            *ngTemplateOutlet="
                                                getTemplateForStep(
                                                    SetEnableStep.DisableReferencingServices,
                                                    disableRequest
                                                )
                                            "></ng-container>
                                    </div>
                                    @if (
                                        disableRequest.error &&
                                        disableRequest.error.step == SetEnableStep.DisableReferencingServices
                                    ) {
                                        <div class="text-sm ml-2">
                                            {{ disableRequest.error.error }}
                                        </div>
                                    }
                                    <div class="flex justify-between items-center">
                                        <div class="accent-color font-medium">Disabling this controller service</div>
                                        <ng-container
                                            *ngTemplateOutlet="
                                                getTemplateForStep(SetEnableStep.DisableService, disableRequest)
                                            "></ng-container>
                                    </div>
                                    @if (
                                        disableRequest.error &&
                                        disableRequest.error.step == SetEnableStep.DisableService
                                    ) {
                                        <div class="text-sm ml-2">
                                            {{ disableRequest.error.error }}
                                        </div>
                                    }
                                </div>
                            </div>
                        </div>
                        <div class="flex basis-1/3 flex-col">
                            <div>
                                Referencing Components
                                <i
                                    class="fa fa-info-circle"
                                    nifiTooltip
                                    [tooltipComponentType]="TextTip"
                                    tooltipInputData="Other components referencing this controller service."></i>
                            </div>
                            <div class="relative h-full border" style="min-height: 320px">
                                <div class="absolute inset-0 overflow-y-auto p-1">
                                    <controller-service-references
                                        [serviceReferences]="controllerService.component.referencingComponents"
                                        [goToReferencingComponent]="
                                            goToReferencingComponent
                                        "></controller-service-references>
                                </div>
                            </div>
                        </div>
                    </div>
                </mat-dialog-content>
                <mat-dialog-actions align="end">
                    @if (disableRequest.currentStep === SetEnableStep.Completed || disableRequest.error) {
                        <button mat-button mat-dialog-close>Close</button>
                    } @else {
                        <button (click)="cancelClicked()" mat-button mat-dialog-close>Cancel</button>
                    }
                </mat-dialog-actions>
            }
        </div>
    }
}
<ng-template #stepInProgress>
    <div class="fa fa-spin fa-circle-o-notch primary-color"></div>
</ng-template>
<ng-template #stepComplete>
    <div class="complete fa fa-check success-color"></div>
</ng-template>
<ng-template #stepError>
    <div class="fa fa-times warn-color"></div>
</ng-template>
<ng-template #stepNotStarted><div class="w-3.5"></div></ng-template>
