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

#[derive(Default)]
pub struct LicenseStep;

const GPL_TEXT: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/LICENSE"));

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

    fn show(&mut self, ui: &mut egui::Ui, state: &mut GlobalState) {
        ui.heading(t!("license_title"));
        ui.label(t!("license_description"));
        ui.add_space(8.0);

        let avail = ui.available_height();
        egui::ScrollArea::vertical()
            .max_height(avail - 60.0)
            .stick_to_bottom(true)
            .auto_shrink([false; 2])
            .show(ui, |ui| {
                egui::Frame::group(ui.style())
                    .inner_margin(egui::Margin::same(12.0))
                    .show(ui, |ui| {
                        ui.label(
                            egui::RichText::new(GPL_TEXT)
                                .size(14.0)
                                .family(egui::FontFamily::Monospace)
                                .color(egui::Color32::from_rgb(180, 180, 200)),
                        );
                    });
            });

        ui.add_space(10.0);
        ui.horizontal(|ui| {
            ui.add(egui::Checkbox::new(&mut state.license_accepted, ""));
            ui.label(
                egui::RichText::new(t!("license_accept"))
                    .size(14.0)
                    .strong(),
            );
        });
    }

    fn is_complete(&self, state: &GlobalState) -> bool {
        state.license_accepted
    }
}
