use super::*;

pub(super) fn panel(
    this: &mut PopoverHost,
    repo_id: RepoId,
    index: usize,
    message: String,
    cx: &mut gpui::Context<PopoverHost>,
) -> gpui::Div {
    let theme = this.theme;
    let reference = format!("stash@{{{index}}}");
    let label = if message.is_empty() {
        reference.clone()
    } else {
        format!("{reference} {message}")
    };

    div()
        .flex()
        .flex_col()
        .min_w(px(420.0))
        .child(
            div()
                .px_2()
                .py_1()
                .text_sm()
                .font_weight(FontWeight::BOLD)
                .child("Drop stash?"),
        )
        .child(div().border_t_1().border_color(theme.colors.border))
        .child(
            div().px_2().py_1().text_sm().child(
                div()
                    .font_family("monospace")
                    .text_color(theme.colors.text_muted)
                    .child(label),
            ),
        )
        .child(
            div()
                .px_2()
                .py_1()
                .text_sm()
                .text_color(theme.colors.text_muted)
                .child("This permanently removes this stash entry."),
        )
        .child(
            div()
                .px_2()
                .pb_1()
                .text_xs()
                .font_family("monospace")
                .text_color(theme.colors.text_muted)
                .child(format!("git stash drop {reference}")),
        )
        .child(div().border_t_1().border_color(theme.colors.border))
        .child(
            div()
                .px_2()
                .py_1()
                .flex()
                .items_center()
                .justify_between()
                .child(
                    components::Button::new("stash_drop_confirm_cancel", "Cancel")
                        .style(components::ButtonStyle::Outlined)
                        .on_click(theme, cx, move |this, _e, _w, cx| {
                            this.store.dispatch(Msg::LoadStashes { repo_id });
                            this.popover = None;
                            this.popover_anchor = None;
                            cx.notify();
                        }),
                )
                .child(
                    components::Button::new("stash_drop_confirm_go", "Drop")
                        .style(components::ButtonStyle::Danger)
                        .on_click(theme, cx, move |this, _e, _w, cx| {
                            this.store.dispatch(Msg::DropStash { repo_id, index });
                            this.store.dispatch(Msg::LoadStashes { repo_id });
                            this.popover = None;
                            this.popover_anchor = None;
                            cx.notify();
                        }),
                ),
        )
}
