package com.imyeyu.fx.ui.examples.view.pages;

import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.fx.ui.components.Hyperlink;
import com.imyeyu.fx.ui.components.TitleLabel;
import com.imyeyu.fx.ui.examples.component.AbstractPane;
import com.imyeyu.fx.utils.bg.BackgroundFillBuilder;
import com.imyeyu.fx.utils.grid.Column;
import com.imyeyu.inject.annotation.Component;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Background;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;

/**
 * 主题样式
 *
 * @author 夜雨
 * @since 2022-08-26 15:44
 */
@Component
public class Style extends AbstractPane {

	public Style() {
		TitleLabel titleTimiFX = new TitleLabel("TimiFX");
		Label labelTimiFXDocument = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("document"));
		Hyperlink timiFXDocument = new Hyperlink("https://doc.imyeyu.net/timi-fx/net/imyeyu/timifx/TimiFX.html");
		Label labelTimiFXSource = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("source"));
		Hyperlink timiFXSource = new Hyperlink("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/java/net/imyeyu/timifx/TimiFX.java");
		Label labelTimiFXDescription = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("description"));
		Label timiFXDescription = new Label(TimiFXUI.MULTILINGUAL.text("fx.example.style.timifx"));

		// 标题颜色
		TitleLabel titleColor = new TitleLabel(TimiFXUI.MULTILINGUAL.text("color"));

		// 聚焦颜色
		Label labelFocusColor = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("focus"));
		Label colorFocus = colorLabel(TimiFXUI.MULTILINGUAL.text("default"), Colorful.FOCUSED_DEFAULT);
		colorFocus.setTextFill(Colorful.WHITE);
		Label colorFocusLight = colorLabel(TimiFXUI.MULTILINGUAL.text("light"), Colorful.FOCUSED_LIGHT);
		Label colorFocusDark = colorLabel(TimiFXUI.MULTILINGUAL.text("dark"), Colorful.FOCUSED_DARK);
		colorFocusDark.setTextFill(Colorful.WHITE);

		// 图标颜色
		Label labelIconColor = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("icon"));
		Label colorIcon = colorLabel(TimiFXUI.MULTILINGUAL.text("default"), Colorful.ICON);
		colorIcon.setTextFill(Colorful.WHITE);
		Label colorIconHover = colorLabel(TimiFXUI.MULTILINGUAL.text("hover"), Colorful.ICON_HOVER);

		// 边框颜色
		Label labelBorderColor = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("border"));
		Label colorBorder = colorLabel(TimiFXUI.MULTILINGUAL.text("default"), Colorful.BORDER);
		Label colorBorderDisable = colorLabel(TimiFXUI.MULTILINGUAL.text("disable"), Paint.valueOf("#E1E1E1"));

		// 背景颜色
		Label labelBackgroundColor = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("background"));
		Label backgroundColor = colorLabel(TimiFXUI.MULTILINGUAL.text("default"), BG.DEFAULT);
		backgroundColor.setBorder(Stroke.DEFAULT);
		Label backgroundColorTitle = colorLabel(TimiFXUI.MULTILINGUAL.text("title"), BG.TITLE);
		backgroundColorTitle.setPrefWidth(100);
		Label backgroundColorTitleFill = colorLabel(TimiFXUI.MULTILINGUAL.text("fx.example.style.color.bg.title_fill"), BG.TITLE_FILL);
		backgroundColorTitleFill.setPrefWidth(100);

		// 投影
		TitleLabel titleShadow = new TitleLabel(TimiFXUI.MULTILINGUAL.text("shadow"));
		Label shadowPopup = shadowLabel(TimiFXUI.MULTILINGUAL.text("fx.example.style.shadow.popup"), Shadow.POPUP);
		Label shadowImage = shadowLabel(TimiFXUI.MULTILINGUAL.text("image"), Shadow.IMAGE);
		Label shadowDown = shadowLabel(TimiFXUI.MULTILINGUAL.text("fx.example.style.shadow.down"), Shadow.DOWN);

		// 样式文件
		TitleLabel styleFile = new TitleLabel(TimiFXUI.MULTILINGUAL.text("fx.example.style.file"));
		Label labelFile = TimiFXUI.label(TimiFXUI.MULTILINGUAL.text("source"));
		Hyperlink file = new Hyperlink("https://git.imyeyu.net/Timi/timi-fx/src/master/src/main/resources/timifx/style/style.css");

		setCenter(new VBox() {{
			setSpacing(16);
			setPadding(new Insets(20));

			final Insets CONTENT_PADDING = new Insets(10, 20, 4, 20);
			getChildren().addAll(new BorderPane() {{
				setTop(titleTimiFX);
				setCenter(new GridPane() {{
					getColumnConstraints().addAll(Column.key(), Column.valueFill());
					setVgap(8);
					setHgap(10);
					setPadding(CONTENT_PADDING);

					int row = 0;
					addRow(row++, labelTimiFXDocument, timiFXDocument);
					addRow(row++, labelTimiFXSource, timiFXSource);
					addRow(row, labelTimiFXDescription, timiFXDescription);
				}});
			}}, new BorderPane() {{
				setTop(titleColor);
				setCenter(new GridPane() {{
					getColumnConstraints().addAll(Column.key(), Column.valueFill());
					setVgap(8);
					setHgap(10);
					setPadding(CONTENT_PADDING);

					int row = 0;
					addRow(row++, labelFocusColor, new HBox() {{
						setSpacing(8);
						getChildren().addAll(colorFocus, colorFocusLight, colorFocusDark);
					}});
					addRow(row++, labelIconColor, new HBox() {{
						setSpacing(8);
						getChildren().addAll(colorIcon, colorIconHover);
					}});
					addRow(row++, labelBorderColor, new HBox() {{
						setSpacing(8);
						getChildren().addAll(colorBorder, colorBorderDisable);
					}});
					addRow(row, labelBackgroundColor, new HBox() {{
						setSpacing(8);
						getChildren().addAll(backgroundColor, backgroundColorTitle, backgroundColorTitleFill);
					}});
				}});
			}}, new BorderPane() {{
				setTop(titleShadow);
				setCenter(new HBox() {{
					BorderPane.setMargin(this, CONTENT_PADDING);
					setPadding(new Insets(20));
					setSpacing(24);
					setBorder(Stroke.DEFAULT);
					setBackground(BG.WHITE);
					getChildren().addAll(shadowPopup, shadowImage, shadowDown);
				}});
			}}, new BorderPane() {{
				setTop(styleFile);
				setCenter(new GridPane() {{
					getColumnConstraints().addAll(Column.key(), Column.valueFill());
					setVgap(8);
					setHgap(10);
					setPadding(CONTENT_PADDING);
					addRow(0, labelFile, file);
				}});
			}});
		}});
	}

	/**
	 * 构造背景颜色标签
	 *
	 * @param text  文本
	 * @param color 颜色
	 * @return 标签
	 */
	private Label colorLabel(String text, Paint color) {
		return colorLabel(text, BackgroundFillBuilder.solid(color).build());
	}

	/**
	 * 构造背景颜色标签
	 *
	 * @param text  文本
	 * @param color 背景颜色
	 * @return 标签
	 */
	private Label colorLabel(String text, Background color) {
		Label label = new Label(text);
		label.setBorder(Stroke.TP);
		label.setPadding(new Insets(4, 16, 4, 16));
		label.setBackground(color);
		return label;
	}

	/**
	 * 构造投影标签
	 *
	 * @param text   文本
	 * @param shadow 投影
	 * @return 标签
	 */
	private Label shadowLabel(String text, DropShadow shadow) {
		Label label = new Label(text);
		label.setEffect(shadow);
		label.setBorder(Stroke.DEFAULT);
		label.setPadding(new Insets(4, 16, 4, 16));
		label.setBackground(BG.DEFAULT);
		return label;
	}
}
