package fr.insa.clavardator.client.ui;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import org.jetbrains.annotations.Nullable;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Controller for the loading screen
 */
public class LoadingScreenController implements Initializable {

	@FXML
	public VBox indicatorOnlyContainer;
	@FXML
	public VBox labeledContainer;
	@FXML
	public Label loadingLabel;
	@FXML
	public StackPane container;

	/**
	 * Instantly shows the loading screen
	 */
	public void show() {
		container.setVisible(true);
		setLabel(null);
	}

	/**
	 * Instantly shows the loading screen
	 *
	 * @param label The text to display bellow the loading indicator
	 */
	public void show(String label) {
		container.setVisible(true);
		setLabel(label);
	}

	/**
	 * Instantly hides the loading screen
	 */
	public void hide() {
		container.setVisible(false);
	}

	/**
	 * Sets the text to display bellow the loading indicator
	 *
	 * @param label The text to use
	 */
	public void setLabel(@Nullable String label) {
		loadingLabel.setText(label);
		final boolean showLabel = label != null && !label.isEmpty();
		labeledContainer.setVisible(showLabel);
		indicatorOnlyContainer.setVisible(!showLabel);
	}

	/**
	 * Gets the main container styles to apply custom styling
	 *
	 * @return The style list
	 */
	public ObservableList<String> getRootStyle() {
		return container.getStyleClass();
	}

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		show();
	}
}
