import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

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

public class Forecast extends CustomNode {
  public-init var day:  String;
  public-init var low:  String;
  public-init var high: String;
  public-init var text: String;
  public-init var code: String;
  public-init var unit: String;
  public-init var wind: Wind on replace {
    visible = wind != null
  }
  override function create() {
    Group {
      content: [
        wind
        RoundRect {
          translateY: Config.OFFSET
          node: Text {
            content: text
            fill: Config.FONT_COLOR
            font: Config.LARGE_FONT
          }
        }
        RoundRect {
          translateY: Config.OFFSET
          fit: false
          node: if (low == "") Text {
            content: "{high}{unit}"
            fill: Config.FONT_COLOR
            font: Config.LARGE_FONT
          } else HBox {
            content: [
              Text {
                content: "high:\nlow:"
                fill: Config.FONT_COLOR
                font: Config.SMALL_FONT
              }
              Text {
                textAlignment: TextAlignment.RIGHT
                content: "{high}{unit}\n{low}{unit}"
                fill: Config.FONT_COLOR
                font: Config.SMALL_FONT
              }
            ]
          }
        }
        ImageView {
          image: Image {
            backgroundLoading: true
            url: "http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/{code}n.png"
          }
        }
      ]
    }
  }
}