import { jsx as _jsx } from "react/jsx-runtime";
import { HTMLUtilities } from "../../../CommonUI/HTMLUtilities";
import { FlowConstants } from "../../CommonUI/FlowConstants";
import { HorizontalSequenceContent } from "../../DesignerUI/Horizontal/FlowStackContent";
import { HorizontalSequenceActions } from "../../DesignerUI/Horizontal/SequenceActions";
import { HorizontalSequenceStrategy } from "../../DesignerUI/Horizontal/SequenceStrategy";
import { HorizontalSequenceTitle } from "../../DesignerUI/Horizontal/SequenceTitle";
import { HorizontalStepStrategy } from "../../DesignerUI/Horizontal/StepStrategy";
import { CandidateSequence } from "../CandidateSequence";
import { FlowStepSequenceStrategy } from "../FlowStepSequence";
import { BaseDisplayBehavior } from "./BaseDisplayBehavior";
export class HorizontalDisplayBehavior extends BaseDisplayBehavior {
    constructor() {
        super(...arguments);
        this.lineLabelPosition = "end";
        this.isEnableContextMenu = false;
        this.candidateWidth = FlowConstants.HORIZONTAL_PATH_CANDIDATE_WIDTH;
        this.candidateHeight = FlowConstants.HORIZONTAL_PATH_CANDIDATE_HEIGHT;
        this.candidateDraggingWidth = FlowConstants.PATH_DRAGGING_CANDIDATE_WIDTH;
        this.candidateDraggingHeight = FlowConstants.PATH_DRAGGING_CANDIDATE_HEIGHT;
        this.candidatePadding = "0 10px";
        this.collapsedWidth = FlowConstants.DEFAULT_COLLAPSED_STACK_WIDTH;
        this.collapsedHeight = FlowConstants.DEFAULT_COLLAPSED_STACK_HEIGHT;
        this.errorCollapsedWidth = FlowConstants.COLLAPSED_ERROR_STACK_WIDTH;
        this.emptyTextFontSize = 11;
        this.sequenceTitleColor = "rgba(39, 41, 50, 0.7)";
        this.stackWidth = FlowConstants.DEFAULT_HORIZONTAL_STACK_WIDTH;
        this.stackHeight = FlowConstants.DEFAULT_HORIZONTAL_STACK_HEIGHT;
        this.linePathType = "grid";
        this.pathCandidateShift = FlowConstants.HORIZONTAL_PATH_CANDIDATE_SHIFT;
        this.sequenceCandidateShift = FlowConstants.SEQUENCE_CANDIDATE_SHIFT;
    }
    getLine(value) {
        let superLine = super.getLine(value);
        let isHiddenStep = Reflect.get(value.fromStep, "hidden");
        let startAnchor = "right";
        startAnchor = ["bottom"];
        if (isHiddenStep) {
            startAnchor = "right";
        }
        return Object.assign(Object.assign({}, superLine), { arrow: Object.assign(Object.assign({}, superLine.arrow), { startAnchor }) });
    }
    getSequenceExtraSize(sequence) {
        return {
            width: sequence.strategy !== FlowStepSequenceStrategy.LINK ? 100 : 0,
            height: FlowConstants.FLOW_CONNECT_AREA_HEIGHT + 20,
        };
    }
    renderSequenceTitle(sequence) {
        return _jsx(HorizontalSequenceTitle, { sequence: sequence, displayBehavior: this }, void 0);
    }
    renderSequenceActions(sequence) {
        return _jsx(HorizontalSequenceActions, { sequence: sequence, displayBehavior: this }, void 0);
    }
    renderSequenceContent(sequence) {
        return _jsx(HorizontalSequenceContent, { editContext: this.editContext, flow: this.flow, sequence: sequence }, void 0);
    }
    renderStepStrategy() {
        return _jsx(HorizontalStepStrategy, { editContext: this.editContext }, void 0);
    }
    renderSequenceStrategy(sequence) {
        return _jsx(HorizontalSequenceStrategy, { sequence: sequence }, void 0);
    }
    getSequenceDroppableDirection(sequence) {
        return "horizontal";
    }
    setCandidateDesiredPositionForSequenceStrategy(inst) {
        let seq = this.flow.findSequenceByStepId(inst.stepId);
        if (!seq)
            return;
        // getting html geometry for sequence as
        let pos = HTMLUtilities.getGeometry(seq._id, FlowConstants.DESIGN_SURFACE_ID);
        if (pos) {
            let insty = pos.top + pos.height / 2 - this.getCandidateCommonStyles().height / 2;
            let instx = pos.left + pos.width + this.sequenceCandidateShift;
            inst.candidateStackY = insty;
            inst.candidateStackX = instx;
        }
        else {
            let insty = seq.y + seq.height / 2 - this.getCandidateCommonStyles().height / 2;
            let instx = seq.x + seq.width + this.sequenceCandidateShift;
            inst.candidateStackY = insty;
            inst.candidateStackX = instx;
        }
    }
    setCandidateDesiredPositionForSeqeuence(sequence) {
        // when sequence is expanded, we need to set the disired position of candidates by instruction.
        if (!this.isCollapsed(sequence)) {
            // set the position by step
            for (let step of sequence.steps) {
                let idx = 0;
                let left = -1;
                for (let inst of this.getPathsForStep(step)) {
                    let pos = HTMLUtilities.getGeometry(inst.getElementId(), FlowConstants.DESIGN_SURFACE_ID);
                    // store first left as we need to set all candidates position with first candidate left
                    if (pos) {
                        if (left < 0) {
                            left = pos.left + pos.width;
                        }
                        let insty = pos.top + idx * this.getCandidateCommonStyles().height + 10;
                        let instx = left + this.pathCandidateShift;
                        inst.candidateStackY = insty;
                        inst.candidateStackX = instx;
                        idx += 1;
                    }
                }
            }
            // set for sequence strategy
            for (let inst of this.getPathsForStep(sequence.hiddenStep))
                this.setCandidateDesiredPositionForSequenceStrategy(inst);
        }
        // when sequenece is collapsed, we need to set the disired position of candidates by sequence and index
        else {
            let pos = HTMLUtilities.getGeometry(sequence._id, FlowConstants.DESIGN_SURFACE_ID);
            let x = sequence.x - sequence.width / 2;
            let y = sequence.y + sequence.height;
            if (pos) {
                x = pos.left + pos.width / 2;
                y = pos.top + pos.height;
            }
            let idx = 0;
            for (let inst of sequence.instructions) {
                // for hidden step
                if (inst.stepId.endsWith("_end")) {
                    this.setCandidateDesiredPositionForSequenceStrategy(inst);
                    continue;
                }
                let c = this.editContext.getCandidateOrRealSequence(inst.connectedSequenceId);
                if (c instanceof CandidateSequence) {
                    let insty = y + idx * this.getCandidateCommonStyles().height + 10;
                    let instx = x + this.pathCandidateShift;
                    inst.candidateStackY = insty;
                    inst.candidateStackX = instx;
                    idx += 1;
                }
            }
        }
    }
}
//# sourceMappingURL=HorizontalDisplayBehavior.js.map