import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;

/**
 * @author Sergey A. Malenkov
 */

public class RoundRect extends CustomNode {
  public-init var fit = true;
  public-init var node: Node;

  override function create() {
    def width = bind if (fit)
                then scene.width - Config.SPACE_DOUBLE
                else node.boundsInLocal.width + Config.SPACE_DOUBLE;
    def height = Config.LARGE_FONT.size + Config.SPACE_DOUBLE;
    def offset = bind if (fit)
                 then Config.SPACE
                 else (height - node.boundsInLocal.height) / 2;
    Group {
      translateX: bind scene.width - width
      content: [
        Rectangle {
          x: - Config.SPACE
          width: bind width
          height: height
          arcWidth: Config.ROUND
          arcHeight: Config.ROUND
          stroke: Config.DARK_COLOR
          fill: LinearGradient {
            endY: 0
            stops: [
              Stop { offset: 0   color: Config.DARK_COLOR }
              Stop { offset: 1   color: Config.LIGHT_COLOR }
            ]
          }
        }
        Group {
          translateY: bind offset - node.boundsInLocal.minY;
          content: node
        }
      ]
    }
  }
}