use eframe::egui;
use rust_i18n::t;
use crate::installer::{GlobalState, InstallerStep};
use crate::ui::theme;

pub struct FinishStep;

impl InstallerStep for FinishStep {
    fn name(&self) -> String { t!("finish").to_string() }

    fn show(&mut self, ui: &mut egui::Ui, _state: &mut GlobalState) {
        ui.add_space(32.0);
        ui.vertical_centered(|ui| {
            // Büyük onay simgesi
            ui.label(
                egui::RichText::new("✔")
                    .size(72.0)
                    .color(theme::c_success()),
            );
            ui.add_space(16.0);

            ui.label(
                egui::RichText::new(t!("finish_title"))
                    .size(24.0)
                    .strong()
                    .color(theme::c_text()),
            ); 
            ui.add_space(8.0);
            ui.label(
                egui::RichText::new(t!("finish_description"))
                    .size(14.0)
                    .color(theme::c_text_dim()),
            );

            ui.add_space(32.0);

            // Yeniden Başlat — ana eylem butonu
            if theme::primary_button(ui, &t!("finish_restart")).clicked() {
                let _ = std::process::Command::new("sync").status();
                let _ = std::process::Command::new("reboot")
                    .arg("-f")
                    .spawn();
                ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
            }

            ui.add_space(12.0);

            // Canlı masaüstüne dön — ikincil eylem
            if theme::secondary_button(ui, &t!("finish_live")).clicked() {
                ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
            }
        });
    }

    fn is_complete(&self, _state: &GlobalState) -> bool { true }
}
