use tauri::App;
use tauri::{WebviewUrl, WebviewWindowBuilder};

pub fn setup_window(app: &mut App) -> Result<(), Box<dyn std::error::Error>> {
    let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default());
    //.inner_size(480.0, 360.0)
    //.title("Haystack")
    //.resizable(false);

    #[cfg(target_os = "macos")]
    {
        use cocoa::appkit::{NSColor, NSWindow};
        use cocoa::base::{id, nil};
        use tauri::TitleBarStyle;

        let window = win_builder
            .hidden_title(true)
            .title_bar_style(TitleBarStyle::Transparent)
            .build()
            .unwrap();

        let ns_window = window.ns_window().unwrap() as id;
        unsafe {
            let bg_color = NSColor::colorWithRed_green_blue_alpha_(
                nil,
                245.0 / 255.0,
                245.0 / 255.0,
                245.0 / 255.0,
                1.0,
            );
            ns_window.setBackgroundColor_(bg_color);
        }
    }

    #[cfg(not(target_os = "macos"))]
    {
        let _ = win_builder.build().unwrap();
    }

    Ok(())
}
