/*
Copyright 2023 - 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>

This file is part of FitnessTrax.

FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
*/

use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};

#[derive(Default)]
pub struct AboutWindowPrivate {}

#[glib::object_subclass]
impl ObjectSubclass for AboutWindowPrivate {
    const NAME: &'static str = "AboutWindow";
    type Type = AboutWindow;
    type ParentType = gtk::Window;
}

impl ObjectImpl for AboutWindowPrivate {}
impl WidgetImpl for AboutWindowPrivate {}
impl WindowImpl for AboutWindowPrivate {}

glib::wrapper! {
    pub struct AboutWindow(ObjectSubclass<AboutWindowPrivate>) @extends gtk::Window, gtk::Widget;
}

impl Default for AboutWindow {
    fn default() -> Self {
        let s: Self = Object::builder().build();
        s.set_width_request(600);
        s.set_height_request(700);
        s.add_css_class("about");

        s.set_title(Some("About Fitnesstrax"));
        let copyright = gtk::Label::builder()
            .label("Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>")
            .halign(gtk::Align::Start)
            .build();

        let gtk_rs_thanks = gtk::Label::builder()
            .label("I owe a huge debt of gratitude to the GTK-RS project (https://gtk-rs.org/), which makes it possible for me to write this application to begin with. Further, I owe a particular debt to Julian Hofer and his book, GUI development with Rust and GTK 4 (https://gtk-rs.org/gtk4-rs/stable/latest/book/). Without this book, I would have continued to stumble around writing bad user interfaces with even worse code.")
            .halign(gtk::Align::Start).wrap(true)
            .build();

        let dependencies = gtk::Label::builder()
            .label("This application depends on many libraries, most of which are licensed under the BSD-3 or GPL-3 licenses.")
            .halign(gtk::Align::Start).wrap(true)
            .build();

        let content = gtk::Box::builder()
            .orientation(gtk::Orientation::Vertical)
            .css_classes(["about__content"])
            .build();
        content.append(&copyright);
        content.append(&gtk_rs_thanks);
        content.append(&dependencies);

        let scroller = gtk::ScrolledWindow::builder()
            .child(&content)
            .hexpand(true)
            .vexpand(true)
            .hscrollbar_policy(gtk::PolicyType::Never)
            .build();

        s.set_child(Some(&scroller));

        s
    }
}
