// Copyright (c) 2014, 2015 Kiel University and others.
// Copyright (c) 2026 The elk-go Authors.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0

package p4nodes

import (
	

	basegraph 
	
)

// InteractiveNodePlacer keeps existing vertical coordinates where possible
// and shifts nodes down only enough to eliminate overlaps.
type InteractiveNodePlacer struct{}

func (*InteractiveNodePlacer) (
	 *layered.LGraphArena,
	 layered.LGraphID,
) layered.ProcessorConfiguration {
	var  layered.ProcessorConfiguration
	if basegraph.Get(&.Graph().Properties, layered.GraphProperties)&layered.GraphPropertyExternalPorts != 0 {
		.AddBefore(layered.PhaseEdgeRouting, layered.HierarchicalPortPositionProcessor)
	}
	return 
}

func (*InteractiveNodePlacer) ( *layered.LGraphArena,  layered.LGraphID) error {
	for ,  := range .Graph().Layers {
		 := math.Inf(-1)
		 := layered.NormalNode
		for ,  := range .Layer().Nodes {
			 := .Node()
			 := .Type
			if  != layered.NormalNode {
				,  := basegraph.TryGet(&.Properties, layered.OriginalDummyNodePosition)
				if  {
					.Position.Y = 
				} else {
					 = math.Max(, 0)
					.Position.Y =  + layered.VerticalSpacingByType(, , , )
				}
			}
			 := layered.VerticalSpacingByType(, , , )
			 :=  +  + .Margin.Top
			if .Position.Y <  {
				.Position.Y = 
			}
			 = .Position.Y + .Size.Y + .Margin.Bottom
			 = 
		}
	}
	return nil
}