import { Component, EventEmitter, Input, Output } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "../workflow-designer.state";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "verben-ng-ui";
export class ConditionsPopupComponent {
    state;
    visible = false;
    decisionNodeId = '';
    newConnectionId = '';
    popupX = 0;
    popupY = 0;
    closed = new EventEmitter();
    saved = new EventEmitter();
    connectionConditions = [];
    currentCondition = '';
    constructor(state) {
        this.state = state;
    }
    ngOnInit() {
        this.loadConnectionConditions();
    }
    loadConnectionConditions() {
        if (!this.decisionNodeId)
            return;
        // Get all connections from this decision node
        const connections = this.state.connections.filter((conn) => conn.sourceNodeId === this.decisionNodeId);
        this.connectionConditions = connections.map((conn) => {
            const targetNode = this.state.findNodeById(conn.targetNodeId)?.node;
            return {
                connectionId: conn.id,
                sourceNodeId: conn.sourceNodeId,
                targetNodeId: conn.targetNodeId,
                targetNodeName: targetNode?.stageData?.Name || 'Unknown Stage',
                condition: conn.condition || '',
                isActive: conn.id === this.newConnectionId,
            };
        });
        // Find the current connection being edited
        const activeCondition = this.connectionConditions.find((c) => c.isActive);
        if (activeCondition) {
            this.currentCondition = activeCondition.condition;
        }
    }
    saveCondition() {
        this.saved.emit({
            connectionId: this.newConnectionId,
            condition: this.currentCondition,
        });
    }
    onClose() {
        this.closed.emit();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ConditionsPopupComponent, deps: [{ token: i1.WorkflowDesignerState }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: ConditionsPopupComponent, selector: "lib-conditions-popup", inputs: { visible: "visible", decisionNodeId: "decisionNodeId", newConnectionId: "newConnectionId", popupX: "popupX", popupY: "popupY" }, outputs: { closed: "closed", saved: "saved" }, ngImport: i0, template: "<div\n  *ngIf=\"visible\"\n  [style.position]=\"'fixed'\"\n  [style.left.px]=\"popupX\"\n  [style.top.px]=\"popupY\"\n>\n  <verben-pop-Up [dropdownOpen]=\"true\" [customStyles]=\"{ 'z-index': '100' }\">\n    <div dropdown-trigger style=\"display: none\">\n      <!-- Hidden trigger element -->\n    </div>\n    <div\n      class=\"p-4 bg-white border border-purple-300 rounded shadow-md w-80\"\n      dropdown-content\n    >\n      <div class=\"flex justify-between items-center mb-3\">\n        <h3 class=\"text-lg font-medium\">Decision Conditions</h3>\n        <button class=\"text-gray-500 hover:text-gray-700\" (click)=\"onClose()\">\n          <svg\n            xmlns=\"http://www.w3.org/2000/svg\"\n            width=\"18\"\n            height=\"18\"\n            viewBox=\"0 0 24 24\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            stroke-width=\"2\"\n            stroke-linecap=\"round\"\n            stroke-linejoin=\"round\"\n          >\n            <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"></line>\n            <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"></line>\n          </svg>\n        </button>\n      </div>\n\n      <div class=\"mb-3\">\n        <p class=\"text-sm text-gray-600\">Define a condition for this branch.</p>\n      </div>\n\n      <div class=\"mb-4\">\n        <label class=\"block text-sm font-medium mb-1\">Condition</label>\n        <input\n          type=\"text\"\n          [(ngModel)]=\"currentCondition\"\n          placeholder=\"e.g., order.amount > 500,000\"\n          class=\"w-full px-3 py-2 rounded border border-gray-200 text-sm\"\n        />\n      </div>\n\n      <div\n        class=\"space-y-3 max-h-60 overflow-y-auto\"\n        *ngIf=\"connectionConditions.length > 1\"\n      >\n        <h4 class=\"text-sm font-medium\">Existing Conditions:</h4>\n        @for (conn of connectionConditions; track conn.connectionId) { @if\n        (!conn.isActive) {\n        <div class=\"border rounded p-3\">\n          <div class=\"mb-2\">\n            <span class=\"font-medium\">{{ conn.targetNodeName }}</span>\n          </div>\n          <div>\n            <input\n              type=\"text\"\n              [value]=\"conn.condition\"\n              placeholder=\"No condition\"\n              class=\"w-full px-3 py-2 rounded border border-gray-200 bg-gray-50 text-sm\"\n              readonly\n            />\n          </div>\n        </div>\n        } }\n      </div>\n\n      <div class=\"flex justify-end mt-4 pt-3 border-t border-gray-200\">\n        <button\n          class=\"px-4 py-2 mr-2 bg-white border border-gray-200 rounded text-sm font-medium\"\n          (click)=\"onClose()\"\n        >\n          Cancel\n        </button>\n        <button\n          class=\"px-4 py-2 bg-yellow-300 text-black rounded text-sm font-medium\"\n          (click)=\"saveCondition()\"\n        >\n          Save\n        </button>\n      </div>\n    </div>\n  </verben-pop-Up>\n</div>\n", styles: [".border-purple-400{border-color:#d36cff}.bg-purple-50{background-color:#f9f5ff}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.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: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i4.VerbenPopUpComponent, selector: "verben-pop-Up", inputs: ["dropdownOpen", "dropdownWidth", "color", "customStyles", "popUpClass", "border", "borderRadius", "enableMouseLeave", "cdkPosition"], outputs: ["dropdownOpenChange", "close"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: ConditionsPopupComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-conditions-popup', template: "<div\n  *ngIf=\"visible\"\n  [style.position]=\"'fixed'\"\n  [style.left.px]=\"popupX\"\n  [style.top.px]=\"popupY\"\n>\n  <verben-pop-Up [dropdownOpen]=\"true\" [customStyles]=\"{ 'z-index': '100' }\">\n    <div dropdown-trigger style=\"display: none\">\n      <!-- Hidden trigger element -->\n    </div>\n    <div\n      class=\"p-4 bg-white border border-purple-300 rounded shadow-md w-80\"\n      dropdown-content\n    >\n      <div class=\"flex justify-between items-center mb-3\">\n        <h3 class=\"text-lg font-medium\">Decision Conditions</h3>\n        <button class=\"text-gray-500 hover:text-gray-700\" (click)=\"onClose()\">\n          <svg\n            xmlns=\"http://www.w3.org/2000/svg\"\n            width=\"18\"\n            height=\"18\"\n            viewBox=\"0 0 24 24\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            stroke-width=\"2\"\n            stroke-linecap=\"round\"\n            stroke-linejoin=\"round\"\n          >\n            <line x1=\"18\" y1=\"6\" x2=\"6\" y2=\"18\"></line>\n            <line x1=\"6\" y1=\"6\" x2=\"18\" y2=\"18\"></line>\n          </svg>\n        </button>\n      </div>\n\n      <div class=\"mb-3\">\n        <p class=\"text-sm text-gray-600\">Define a condition for this branch.</p>\n      </div>\n\n      <div class=\"mb-4\">\n        <label class=\"block text-sm font-medium mb-1\">Condition</label>\n        <input\n          type=\"text\"\n          [(ngModel)]=\"currentCondition\"\n          placeholder=\"e.g., order.amount > 500,000\"\n          class=\"w-full px-3 py-2 rounded border border-gray-200 text-sm\"\n        />\n      </div>\n\n      <div\n        class=\"space-y-3 max-h-60 overflow-y-auto\"\n        *ngIf=\"connectionConditions.length > 1\"\n      >\n        <h4 class=\"text-sm font-medium\">Existing Conditions:</h4>\n        @for (conn of connectionConditions; track conn.connectionId) { @if\n        (!conn.isActive) {\n        <div class=\"border rounded p-3\">\n          <div class=\"mb-2\">\n            <span class=\"font-medium\">{{ conn.targetNodeName }}</span>\n          </div>\n          <div>\n            <input\n              type=\"text\"\n              [value]=\"conn.condition\"\n              placeholder=\"No condition\"\n              class=\"w-full px-3 py-2 rounded border border-gray-200 bg-gray-50 text-sm\"\n              readonly\n            />\n          </div>\n        </div>\n        } }\n      </div>\n\n      <div class=\"flex justify-end mt-4 pt-3 border-t border-gray-200\">\n        <button\n          class=\"px-4 py-2 mr-2 bg-white border border-gray-200 rounded text-sm font-medium\"\n          (click)=\"onClose()\"\n        >\n          Cancel\n        </button>\n        <button\n          class=\"px-4 py-2 bg-yellow-300 text-black rounded text-sm font-medium\"\n          (click)=\"saveCondition()\"\n        >\n          Save\n        </button>\n      </div>\n    </div>\n  </verben-pop-Up>\n</div>\n", styles: [".border-purple-400{border-color:#d36cff}.bg-purple-50{background-color:#f9f5ff}\n"] }]
        }], ctorParameters: () => [{ type: i1.WorkflowDesignerState }], propDecorators: { visible: [{
                type: Input
            }], decisionNodeId: [{
                type: Input
            }], newConnectionId: [{
                type: Input
            }], popupX: [{
                type: Input
            }], popupY: [{
                type: Input
            }], closed: [{
                type: Output
            }], saved: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 