package com.softgraf.vendas.view;

import com.softgraf.vendas.model.bkup.Backup;
import com.softgraf.vendas.model.bkup.Mysqldump;

import javafx.application.Platform;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class BackupView {

	private Stage stage;
	private TextArea texto;
	private Button btnIniciar;
	private static String pathMysqlDump = null;

	public BackupView() {
		texto = new TextArea();
		texto.setPrefSize(480, 240);
		texto.setLayoutX(10);
		texto.setLayoutY(10);
		texto.setEditable(false);
		texto.setStyle("-fx-background-color: transparent");

		btnIniciar = new Button("Iniciar Backup");
		btnIniciar.setLayoutX(200);
		btnIniciar.setLayoutY(260);
		btnIniciar.setOnAction(e -> {
			if (pathMysqlDump == null) {
				pathMysqlDump = Mysqldump.procurarMysqldump();
			}
			if (pathMysqlDump != null) {
				stage.setIconified(true);
				btnIniciar.setVisible(false);
				Platform.runLater(new Backup(stage, texto, pathMysqlDump));
			}
		});

		Parent painel = new AnchorPane(texto, btnIniciar);

		Scene cena = new Scene(painel, 500, 300);
		stage = new Stage();
		stage.setTitle("Backup do banco de dados por FTP");
		stage.setScene(cena);
		stage.setResizable(false);
	}

	public void mostrar() {
		texto.setText("Pressione Iniciar para começar o backup...");
		btnIniciar.setVisible(true);
		stage.show();
	}
}
