use std::borrow::Cow;

use iced::widget::text::LineHeight;
pub use iced::widget::tooltip::Position;
use iced::widget::{container, text};

use super::Element;
use crate::{Theme, font, theme};

pub fn tooltip<'a, Message: 'a>(
    content: impl Into<Element<'a, Message>>,
    tooltip: Option<impl Into<Cow<'a, str>>>,
    position: Position,
    theme: &'a Theme,
) -> Element<'a, Message> {
    match tooltip {
        Some(tooltip) => iced::widget::tooltip(
            content,
            container(
                text(tooltip.into())
                    .style(theme::text::secondary)
                    .line_height(LineHeight::Relative(1.0))
                    .font_maybe(
                        theme::font_style::secondary(theme).map(font::get),
                    ),
            )
            .style(theme::container::tooltip)
            .padding(8),
            position,
        )
        .delay(iced::time::Duration::ZERO)
        .into(),
        None => content.into(),
    }
}
