// Update imports
import { CommonModule } from '@angular/common';
import { Component, EventEmitter, inject, Output } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { DropDownModule, VerbenDialogueModule } from 'verben-ng-ui';
import { NodePreconditionService, } from '../services/node-precondition.service';
import * as i0 from "@angular/core";
import * as i1 from "verben-ng-ui";
import * as i2 from "@angular/forms";
export class NodeSelectorComponent {
    // Replace existing properties with these
    selectedTags = [];
    selectedFormId = '';
    selectedWorkflowId = '';
    condition = '';
    preconditionService = inject(NodePreconditionService);
    select = new EventEmitter();
    // Methods for dropdown handling
    onTagSelectionChange(event) {
        // Handle tag selection change if needed
        console.log('Tag selection changed:', this.selectedTags);
    }
    onDropdownChange(event) {
        console.log('Dropdown selection changed:', event);
    }
    onFormSubmit() {
        const selectedForm = this.preconditionService
            .forms()
            .find((f) => f.id === this.selectedFormId);
        if (selectedForm) {
            this.select.emit(selectedForm);
        }
    }
    onWorkflowSubmit() {
        const selectedWorkflow = this.preconditionService
            .workflows()
            .find((w) => w.id === this.selectedWorkflowId);
        if (selectedWorkflow) {
            this.select.emit(selectedWorkflow);
        }
    }
    getDialogTitle() {
        const type = this.preconditionService.pendingNode()?.type;
        switch (type) {
            case 'form':
                return 'Select Form';
            case 'subflow':
                return 'Select Workflow';
            case 'swimlane':
                return 'Select Tags';
            case 'decision':
                return 'Set Condition';
            default:
                return 'Select';
        }
    }
    onTagsSubmit() {
        this.select.emit({
            type: 'swimlane',
            id: crypto.randomUUID(),
            name: 'Swimlane',
            tags: this.selectedTags,
        });
    }
    onConditionSubmit() {
        this.select.emit({
            type: 'decision',
            id: crypto.randomUUID(),
            name: 'Decision',
            condition: this.condition,
        });
    }
    onSelect(data) {
        this.select.emit(data);
    }
    onModalClose(event) {
        this.preconditionService.clearPendingNode();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: NodeSelectorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: NodeSelectorComponent, isStandalone: true, selector: "wf-node-selector", outputs: { select: "select" }, ngImport: i0, template: `
    <verben-dialogue
      [isVisible]="!!preconditionService.pendingNode()"
      [showCloseIcon]="true"
      [dismissOutsideClick]="true"
      [closeOnEscape]="true"
      [size]="'small'"
      [mode]="'dialogue'"
      [customClass]="'precondition-dialogue'"
      [headerTemplate]="headerTemplate"
      [bodyTemplate]="bodyTemplate"
      (closeModal)="onModalClose($event)"
    >
    </verben-dialogue>

    <ng-template #headerTemplate>
      <h3 class="text-lg font-semibold">{{ getDialogTitle() }}</h3>
    </ng-template>

    <ng-template #bodyTemplate>
      <div class="p-6">
        @switch (preconditionService.pendingNode()?.type) { @case ('swimlane') {
        <div class="space-y-4">
          <verben-drop-down
            [multiselect]="true"
            display="chip"
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Tags"
            optionLabel="Name"
            styleClass="w-full"
            [options]="preconditionService.tags()"
            [(ngModel)]="selectedTags"
            (onChange)="onTagSelectionChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedTags.length"
            (click)="onTagsSubmit()"
          >
            Apply Tags
          </button>
        </div>
        } @case ('decision') {
        <div class="space-y-4">
          <div>
            <label class="block text-sm font-medium mb-2">Condition</label>
            <textarea
              class="w-full p-2 border rounded-md"
              rows="3"
              [(ngModel)]="condition"
              placeholder="Enter condition..."
            ></textarea>
          </div>
          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!condition"
            (click)="onConditionSubmit()"
          >
            Apply Condition
          </button>
        </div>
        } @case ('form') {
        <div class="space-y-4">
          <verben-drop-down
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Form"
            optionLabel="name"
            optionValue="id"
            styleClass="w-full"
            [options]="preconditionService.forms()"
            [(ngModel)]="selectedFormId"
            (onChange)="onDropdownChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedFormId"
            (click)="onFormSubmit()"
          >
            Select Form
          </button>
        </div>
        } @default {
        <div class="space-y-4">
          <verben-drop-down
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Workflow"
            optionLabel="name"
            optionValue="id"
            styleClass="w-full"
            [options]="preconditionService.workflows()"
            [(ngModel)]="selectedWorkflowId"
            (onChange)="onDropdownChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedWorkflowId"
            (click)="onWorkflowSubmit()"
          >
            Select Workflow
          </button>
        </div>
        } }
      </div>
    </ng-template>
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: VerbenDialogueModule }, { kind: "component", type: i1.VerbenDialogueComponent, selector: "verben-dialogue", inputs: ["dialogueWidth", "headerTemplate", "bodyTemplate", "footerTemplate", "showCloseIcon", "dismissOutsideClick", "closeOnEscape", "isVisible", "size", "backdropColor", "customClass", "disableFooter", "margin", "padding", "borderRadius", "dialogueBgColor", "width", "closeIconClass", "boxShadow", "enableTransition", "modalData", "mode", "position", "drawerWidth"], outputs: ["openModal", "closeModal"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: DropDownModule }, { kind: "component", type: i1.DropDownComponent, selector: "verben-drop-down", inputs: ["options", "width", "showHorizontalLine", "horizontalLineColor", "optionLabel", "optionSubLabel", "optionValue", "placeholder", "invalidMessage", "errorPosition", "loadMoreCaption", "display", "showClear", "lazyLoad", "selectKey", "styleClass", "group", "multiselect", "filter", "avoidDuplication", "filterBy", "debounceTime", "minChar", "disabled", "required", "load", "asyncLabel", "search"], outputs: ["optionsChange", "onChange", "onClick", "onClear"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: NodeSelectorComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'wf-node-selector',
                    standalone: true,
                    imports: [CommonModule, VerbenDialogueModule, FormsModule, DropDownModule],
                    template: `
    <verben-dialogue
      [isVisible]="!!preconditionService.pendingNode()"
      [showCloseIcon]="true"
      [dismissOutsideClick]="true"
      [closeOnEscape]="true"
      [size]="'small'"
      [mode]="'dialogue'"
      [customClass]="'precondition-dialogue'"
      [headerTemplate]="headerTemplate"
      [bodyTemplate]="bodyTemplate"
      (closeModal)="onModalClose($event)"
    >
    </verben-dialogue>

    <ng-template #headerTemplate>
      <h3 class="text-lg font-semibold">{{ getDialogTitle() }}</h3>
    </ng-template>

    <ng-template #bodyTemplate>
      <div class="p-6">
        @switch (preconditionService.pendingNode()?.type) { @case ('swimlane') {
        <div class="space-y-4">
          <verben-drop-down
            [multiselect]="true"
            display="chip"
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Tags"
            optionLabel="Name"
            styleClass="w-full"
            [options]="preconditionService.tags()"
            [(ngModel)]="selectedTags"
            (onChange)="onTagSelectionChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedTags.length"
            (click)="onTagsSubmit()"
          >
            Apply Tags
          </button>
        </div>
        } @case ('decision') {
        <div class="space-y-4">
          <div>
            <label class="block text-sm font-medium mb-2">Condition</label>
            <textarea
              class="w-full p-2 border rounded-md"
              rows="3"
              [(ngModel)]="condition"
              placeholder="Enter condition..."
            ></textarea>
          </div>
          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!condition"
            (click)="onConditionSubmit()"
          >
            Apply Condition
          </button>
        </div>
        } @case ('form') {
        <div class="space-y-4">
          <verben-drop-down
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Form"
            optionLabel="name"
            optionValue="id"
            styleClass="w-full"
            [options]="preconditionService.forms()"
            [(ngModel)]="selectedFormId"
            (onChange)="onDropdownChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedFormId"
            (click)="onFormSubmit()"
          >
            Select Form
          </button>
        </div>
        } @default {
        <div class="space-y-4">
          <verben-drop-down
            [required]="true"
            [filter]="true"
            [showClear]="true"
            placeholder="Select Workflow"
            optionLabel="name"
            optionValue="id"
            styleClass="w-full"
            [options]="preconditionService.workflows()"
            [(ngModel)]="selectedWorkflowId"
            (onChange)="onDropdownChange($event)"
          ></verben-drop-down>

          <button
            class="w-full px-4 py-2 bg-purple-600 text-white rounded-md"
            [disabled]="!selectedWorkflowId"
            (click)="onWorkflowSubmit()"
          >
            Select Workflow
          </button>
        </div>
        } }
      </div>
    </ng-template>
  `,
                }]
        }], propDecorators: { select: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 