use adw::prelude::*;
use adw::{AlertDialog, ResponseAppearance};
use gtk4::{Widget, Box as GtkBox, Orientation, Image, Align, ScrolledWindow};
use std::path::Path;
pub fn show_image_dialog(
parent: &impl IsA<Widget>,
title: &str,
body: &str,
button_label: &str,
file_path: &str,
width: i32,
height: i32,
) {
let path = Path::new(file_path);
let extension = path.extension()
.and_then(|s| s.to_str())
.unwrap_or("")
.to_lowercase();
let valid_extensions = ["jpg", "jpeg", "png", "svg", "webp", "gif"];
if !valid_extensions.contains(&extension.as_str()) {
return;
}
let content = GtkBox::builder()
.orientation(Orientation::Vertical)
.spacing(12)
.width_request(width)
.build();
let image = Image::from_file(file_path);
image.set_pixel_size(width.max(height));
image.set_vexpand(true);
image.set_hexpand(true);
image.set_halign(Align::Fill);
image.set_valign(Align::Fill);
let scroll = ScrolledWindow::builder()
.child(&image)
.min_content_height(height)
.max_content_height(height)
.propagate_natural_width(true)
.build();
content.append(&scroll);
let dialog = AlertDialog::builder()
.heading(title)
.body(body)
.build();
dialog.set_extra_child(Some(&content));
dialog.add_response("ok", button_label);
dialog.set_response_appearance("ok", ResponseAppearance::Suggested);
dialog.set_close_response("ok");
dialog.present(Some(parent));
}