package fr.insa.clavardator.client.ui.dialogs;

import com.jfoenix.effects.JFXDepthManager;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import org.kordamp.ikonli.javafx.FontIcon;

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

/**
 * Controller for the notification snackbar
 */
public class SnackbarController implements Initializable {

	@FXML
	public Label label;
	@FXML
	public FontIcon icon;
	@FXML
	public HBox container;

	/**
	 * Sets the snackbar text
	 *
	 * @param text The text to display
	 */
	public void setText(String text) {
		label.setText(text);
	}

	/**
	 * Sets the snackbar display mode
	 *
	 * @param mode The mode to set
	 */
	public void setMode(Mode mode) {
		ObservableList<String> styleClasses = container.getStyleClass();
		styleClasses.clear();
		styleClasses.add("snackbar-container");
		switch (mode) {
			case INFO:
				styleClasses.add("snackbar-container-info");
				icon.setIconLiteral("fas-info-circle");
				break;
			case WARNING:
				styleClasses.add("snackbar-container-warning");
				icon.setIconLiteral("fas-exclamation-triangle");
				break;
			case ERROR:
				styleClasses.add("snackbar-container-danger");
				icon.setIconLiteral("fas-times-circle");
				break;
			case SUCCESS:
				styleClasses.add("snackbar-container-success");
				icon.setIconLiteral("fas-check-circle");
				break;
		}
	}

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		setMode(Mode.INFO);
		// Set a small shadow bellow the snackbar
		JFXDepthManager.setDepth(container, 1);
	}

	public enum Mode {
		INFO,
		WARNING,
		ERROR,
		SUCCESS
	}
}
