#[warn(unused_imports)]
mod credentails;
mod domains;

use alfis::{
    blockchain::{
        transaction::DomainData,
        types::MineResult
    },
    commons::*,
    crypto::CryptoBox,
    dns::protocol::DnsRecord,
    event::Event,
    eventbus::{post, register},
    miner::Miner,
    keystore, Block, Bytes, Context, Keystore, Transaction
};

use std::{
    sync::{Arc, Mutex, MutexGuard},
    thread,
    time::{Duration, Instant},
    rc::Rc, cell::RefCell
};

use gtk::prelude::*;
use gtk::{
    glib,
    ApplicationWindow,
    Button,
    Label,
    HeaderBar,
    Box,
    Orientation,
    Notebook,
    Entry,
    FileDialog
};


#[derive(Clone, Debug)]
pub struct KeyData {
    pub path: String,
    pub public: String,
    pub hash: String,
}


#[warn(unused_variables)]
pub fn run_ui(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>) -> glib::ExitCode {
    let application = adw::Application::builder()
        .application_id("ru.Revertron.Alfis")
        .build();

    let context = context.clone();
    let miner = miner.clone();
    application.connect_activate(move |app| {
        let window = ApplicationWindow::builder()
            .application(app)
            .title(format!("ALFIS {}", env!("CARGO_PKG_VERSION")))
            .default_width(1023)
            .default_height(720)
            .resizable(false)
            .build();
        let ab = HeaderBar::new();
        window.set_titlebar(Some(&ab));

        let nb = Notebook::new();
        window.set_child(Some(&nb));

        let credentails = Box::new(Orientation::Vertical, 4);
        credentails::menu(&window, &credentails, &context);

        let domains = Box::new(Orientation::Vertical, 4);
        domains::menu(app, &window, &domains, &context, &miner);

        nb.append_page(&credentails, Some(&Label::new(Some("Credentials"))));
        nb.append_page(&domains, Some(&Label::new(Some("Domains"))));

        window.present();
    });

    application.run()
}
