1use std::sync::Arc;
2
3use client::{Client, UserStore};
4use gpui::{Entity, IntoElement, ParentElement};
5use ui::prelude::*;
6
7use crate::ZedAiOnboarding;
8
9pub struct EditPredictionOnboarding {
10 user_store: Entity<UserStore>,
11 client: Arc<Client>,
12 copilot_is_configured: bool,
13 continue_with_zed_ai: Arc<dyn Fn(&mut Window, &mut App)>,
14 continue_with_copilot: Arc<dyn Fn(&mut Window, &mut App)>,
15}
16
17impl EditPredictionOnboarding {
18 pub fn new(
19 user_store: Entity<UserStore>,
20 client: Arc<Client>,
21 copilot_is_configured: bool,
22 continue_with_zed_ai: Arc<dyn Fn(&mut Window, &mut App)>,
23 continue_with_copilot: Arc<dyn Fn(&mut Window, &mut App)>,
24 _cx: &mut Context<Self>,
25 ) -> Self {
26 Self {
27 user_store,
28 copilot_is_configured,
29 client,
30 continue_with_zed_ai,
31 continue_with_copilot,
32 }
33 }
34}
35
36impl Render for EditPredictionOnboarding {
37 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
38 let github_copilot = v_flex()
39 .gap_1()
40 .child(Label::new(if self.copilot_is_configured {
41 "Alternatively, you can continue to use GitHub Copilot as that's already set up."
42 } else {
43 "Alternatively, you can use GitHub Copilot as your edit prediction provider."
44 }))
45 .child(
46 Button::new(
47 "configure-copilot",
48 if self.copilot_is_configured {
49 "Use Copilot"
50 } else {
51 "Configure Copilot"
52 },
53 )
54 .full_width()
55 .style(ButtonStyle::Outlined)
56 .on_click({
57 let callback = self.continue_with_copilot.clone();
58 move |_, window, cx| callback(window, cx)
59 }),
60 );
61
62 v_flex()
63 .gap_2()
64 .child(ZedAiOnboarding::new(
65 self.client.clone(),
66 &self.user_store,
67 self.continue_with_zed_ai.clone(),
68 cx,
69 ))
70 .child(ui::Divider::horizontal())
71 .child(github_copilot)
72 }
73}