use gpui::{AnyElement, Context, div, prelude::*, px};
use crate::app::Rosier;
use crate::assets::Icon;
use crate::i18n::t;
use crate::theme;
use crate::ui::{button, icon, primary_button};
impl Rosier {
pub(crate) fn render_onboarding(&mut self, cx: &mut Context<Self>) -> AnyElement {
div()
.size_full()
.flex()
.items_center()
.justify_center()
.bg(theme::glass_fill())
.child(div().w(px(560.0)).child(self.onboard_folders(cx)))
.into_any_element()
}
fn onboard_folders(&mut self, cx: &mut Context<Self>) -> AnyElement {
let list: AnyElement = if self.pending_sources.is_empty() {
div()
.h(px(88.0))
.rounded(px(theme::RADIUS + 2.0))
.border_1()
.border_dashed()
.border_color(theme::line())
.flex()
.items_center()
.justify_center()
.text_sm()
.text_color(theme::text_faint())
.child(t("onboard.folders.none"))
.into_any_element()
} else {
div()
.flex()
.flex_col()
.rounded(px(theme::RADIUS + 2.0))
.bg(theme::raised())
.children(self.pending_sources.clone().into_iter().enumerate().map(|(k, p)| {
div()
.flex()
.flex_row()
.items_center()
.gap_3()
.px_3()
.h(px(44.0))
.when(k > 0, |d| d.border_t_1().border_color(theme::line()))
.child(icon(Icon::Folder, 18.0, theme::text_dim()))
.child(div().flex_grow().text_sm().truncate().child(p.display().to_string()))
.child(button(("onboard-remove", k)).child(t("onboard.folders.remove")).on_click(cx.listener(
move |this, _, _, cx| {
if k < this.pending_sources.len() {
this.pending_sources.remove(k);
}
cx.notify();
},
)))
}))
.into_any_element()
};
let can_continue = !self.pending_sources.is_empty();
div()
.flex()
.flex_col()
.gap_4()
.child(div().text_2xl().font_weight(gpui::FontWeight::SEMIBOLD).child(t("onboard.folders.title")))
.child(div().text_color(theme::text_dim()).line_height(px(24.0)).child(t("onboard.folders.body")))
.child(list)
.when(crate::desktop::supported(), |d| {
let on = self.register_app;
d.child(
div()
.id("onboard-register")
.flex()
.flex_row()
.items_center()
.gap_2()
.text_sm()
.text_color(theme::text_dim())
.cursor_pointer()
.child(
div()
.size(px(18.0))
.flex()
.items_center()
.justify_center()
.rounded(px(5.0))
.border_1()
.when(on, |b| b.bg(theme::accent()).border_color(theme::accent()))
.when(!on, |b| b.border_color(theme::text_faint()))
.when(on, |b| b.child(icon(Icon::Check, 12.0, gpui::white()))),
)
.child(t("onboard.folders.register"))
.on_click(cx.listener(|this, _, _, cx| {
this.register_app = !this.register_app;
cx.notify();
})),
)
})
.child(
div()
.pt_2()
.flex()
.flex_row()
.items_center()
.justify_between()
.child(
button("onboard-add")
.child(icon(Icon::Plus, 16.0, theme::text_dim()))
.child(t("onboard.folders.add"))
.on_click(cx.listener(|this, _, _, cx| this.add_folders(cx))),
)
.child(
primary_button("onboard-continue", t("onboard.folders.next"))
.when(!can_continue, |b| b.opacity(0.4).cursor_default())
.on_click(cx.listener(move |this, _, _, cx| {
if !this.pending_sources.is_empty() {
this.finish_folder_step(cx);
}
})),
),
)
.into_any_element()
}
}