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 "verben-ng-ui";
export class DecisionPopupComponent {
    state;
    visible = false;
    decisionNodeId = '';
    popupX = 0;
    popupY = 0;
    closed = new EventEmitter();
    showDuration = true;
    constructor(state) {
        this.state = state;
    }
    getConnectionConditions() {
        if (!this.decisionNodeId)
            return [];
        // Get all connections from this decision node
        return this.state.connections
            .filter((conn) => conn.sourceNodeId === this.decisionNodeId)
            .map((conn) => ({
            connectionId: conn.id,
            sourceNodeId: conn.sourceNodeId,
            targetNodeId: conn.targetNodeId,
            condition: conn.condition || 'order.amount > 500,000', // Default or actual condition
        }));
    }
    getTargetNodeName(nodeId) {
        const nodeInfo = this.state.findNodeById(nodeId);
        if (nodeInfo && nodeInfo.node) {
            return nodeInfo.node.stageData?.Name || 'Stage';
        }
        return 'Unknown Stage';
    }
    getDuration() {
        // Get duration from the decision node or default to 120 days
        const nodeInfo = this.state.findNodeById(this.decisionNodeId);
        if (nodeInfo && nodeInfo.node && nodeInfo.node.stageData) {
            return nodeInfo.node.stageData.Duration || 120;
        }
        return 120;
    }
    onClose() {
        this.closed.emit();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DecisionPopupComponent, deps: [{ token: i1.WorkflowDesignerState }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.13", type: DecisionPopupComponent, selector: "lib-decision-popup", inputs: { visible: "visible", decisionNodeId: "decisionNodeId", popupX: "popupX", popupY: "popupY" }, outputs: { closed: "closed" }, ngImport: i0, template: "<div\n  *ngIf=\"visible\"\n  [style.position]=\"'absolute'\"\n  [style.left.px]=\"popupX\"\n  [style.top.px]=\"popupY\"\n  class=\"decision-conditions-popup\"\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=\"space-y-3\">\n        @for (condition of getConnectionConditions(); track\n        condition.connectionId) {\n        <div class=\"p-3 border rounded\">\n          <div class=\"mb-2\">\n            <span class=\"font-medium\">Action {{ $index + 1 }}:</span>\n          </div>\n          <div class=\"flex items-center\">\n            <input\n              type=\"text\"\n              [value]=\"condition.condition\"\n              readonly\n              class=\"w-full px-3 py-2 bg-gray-50 border rounded\"\n              placeholder=\"No condition\"\n            />\n            <span class=\"ml-2\">&gt;</span>\n          </div>\n          <div class=\"mt-1 text-xs text-gray-500\">\n            {{ getTargetNodeName(condition.targetNodeId) }}\n          </div>\n        </div>\n        }\n      </div>\n\n      @if (getConnectionConditions().length === 0) {\n      <div class=\"text-center py-3 text-gray-500\">\n        No conditions defined for this decision node\n      </div>\n      } @if (showDuration) {\n      <div class=\"mt-4 pt-3 border-t border-gray-200\">\n        <div class=\"flex items-center\">\n          <span class=\"font-medium\">Duration:</span>\n          <span class=\"ml-2\">{{ getDuration() }} days</span>\n        </div>\n      </div>\n      }\n    </div>\n  </verben-pop-Up>\n</div>\n", styles: [".decision-conditions-popup{z-index:1000}.border-purple-300{border-color:#d8b4fe}.bg-gray-50{background-color:#f9fafb}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.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: DecisionPopupComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-decision-popup', template: "<div\n  *ngIf=\"visible\"\n  [style.position]=\"'absolute'\"\n  [style.left.px]=\"popupX\"\n  [style.top.px]=\"popupY\"\n  class=\"decision-conditions-popup\"\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=\"space-y-3\">\n        @for (condition of getConnectionConditions(); track\n        condition.connectionId) {\n        <div class=\"p-3 border rounded\">\n          <div class=\"mb-2\">\n            <span class=\"font-medium\">Action {{ $index + 1 }}:</span>\n          </div>\n          <div class=\"flex items-center\">\n            <input\n              type=\"text\"\n              [value]=\"condition.condition\"\n              readonly\n              class=\"w-full px-3 py-2 bg-gray-50 border rounded\"\n              placeholder=\"No condition\"\n            />\n            <span class=\"ml-2\">&gt;</span>\n          </div>\n          <div class=\"mt-1 text-xs text-gray-500\">\n            {{ getTargetNodeName(condition.targetNodeId) }}\n          </div>\n        </div>\n        }\n      </div>\n\n      @if (getConnectionConditions().length === 0) {\n      <div class=\"text-center py-3 text-gray-500\">\n        No conditions defined for this decision node\n      </div>\n      } @if (showDuration) {\n      <div class=\"mt-4 pt-3 border-t border-gray-200\">\n        <div class=\"flex items-center\">\n          <span class=\"font-medium\">Duration:</span>\n          <span class=\"ml-2\">{{ getDuration() }} days</span>\n        </div>\n      </div>\n      }\n    </div>\n  </verben-pop-Up>\n</div>\n", styles: [".decision-conditions-popup{z-index:1000}.border-purple-300{border-color:#d8b4fe}.bg-gray-50{background-color:#f9fafb}\n"] }]
        }], ctorParameters: () => [{ type: i1.WorkflowDesignerState }], propDecorators: { visible: [{
                type: Input
            }], decisionNodeId: [{
                type: Input
            }], popupX: [{
                type: Input
            }], popupY: [{
                type: Input
            }], closed: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 