1 "use client"
2
3 import { Telescope, XMarkMini } from "@medusajs/icons"
4 import clsx from "clsx"
5 import { BloomIcon, Button, HeadlineTags, useAiAssistant } from "docs-ui"
6 import { useState } from "react"
7 import HomepageEdges from "../Edges"
8 import HomepageArrowUpMini from "./ArrowUpMini"
9
10 const HomepageBloom = () => {
11 const {
12 setChatOpened,
13 submitQuery,
14 deepThinkingEnabled,
15 toggleDeepThinking,
16 } = useAiAssistant()
17 const [question, setQuestion] = useState("")
18 const [showCustomCarat, setShowCustomCaret] = useState(false)
19
20 const handleSubmit = (overrideQuestion?: string) => {
21 submitQuery(overrideQuestion || question)
22 setChatOpened(true)
23 setQuestion("")
24 }
25
26 const suggestions: {
27 tag: string
28 questions: string[]
29 }[] = [
30 {
31 tag: "FAQ",
32 questions: [
33 "What is Medusa?",
34 "How can I build with Medusa and AI agents?",
35 "How can I extend the product data model?",
36 "How to create an admin user?",
37 "How do I deploy Medusa to production?",
38 ],
39 },
40 {
41 tag: "Recipes",
42 questions: [
43 "How do I build a marketplace?",
44 "How do I build digital products?",
45 "How do I build subscription-based purchases?",
46 "What other recipes are available?",
47 ],
48 },
49 ]
50
51 return (
52 <div className="w-full flex gap-0 items-center border-b border-medusa-border-base flex-col lg:flex-row lg:h-[480px]">
53 {/* Chat area */}
54 <div
55 className={clsx(
56 "w-full h-full lg:w-1/2 bg-medusa-bg-component relative",
57 "flex flex-col justify-between gap-2",
58 "p-2 border-r border-medusa-border-base",
59 "border-b lg:border-b-0"
60 )}
61 >
62 <div className="flex flex-col gap-2 flex-1">
63 <BloomIcon className="w-2 h-2 text-medusa-fg-subtle" />
64 <span className="text-h1 text-pretty">
65 Hello! I’m Bloom, your go-to ecommerce assistant. How can I help
66 you?
67 </span>
68 <div className="w-full flex-1 py-0.75 border-t border-medusa-border-base relative">
69 <textarea
70 className={clsx(
71 "appearance-none text-base placeholder:text-medusa-fg-muted",
72 "bg-transparent resize-none w-full focus:outline-none",
73 "h-1.5 lg:h-auto",
74 !question && "caret-transparent"
75 )}
76 placeholder={
77 !showCustomCarat ? "Ask anything about Medusa..." : ""
78 }
79 value={question}
80 onChange={(e) => setQuestion(e.target.value)}
81 onFocus={() => setShowCustomCaret(true)}
82 onBlur={() => setShowCustomCaret(false)}
83 onKeyDown={(e) => {
84 if (e.key === "Enter" && !e.shiftKey) {
85 e.preventDefault()
86 handleSubmit()
87 }
88 }}
89 ></textarea>
90 {!question && showCustomCarat && (
91 <span className="block h-[21px] w-[7.5px] bg-medusa-fg-base absolute top-0.75 left-0 animate-[pulsingCursor_0.8s_ease-in-out_infinite] rounded-xxs" />
92 )}
93 </div>
94 </div>
95 <div className="flex justify-between">
96 <Button
97 variant="transparent-clear"
98 onClick={(e) => {
99 toggleDeepThinking()
100 e.currentTarget.blur()
101 }}
102 className={clsx(
103 "group",
104 deepThinkingEnabled && [
105 "!bg-medusa-button-neutral rounded-full flex !pl-[10px] !pr-[9px] !py-0 gap-[6px]",
106 "!shadow-button-neutral",
107 ],
108 !deepThinkingEnabled && [
109 "focus:!bg-transparent active:!bg-transparent",
110 "focus:!shadow-none active:!shadow-none",
111 ]
112 )}
113 >
114 <Telescope
115 className={clsx(
116 deepThinkingEnabled &&
117 "text-medusa-fg-interactive group-hover:hidden",
118 !deepThinkingEnabled && "text-medusa-fg-muted"
119 )}
120 />
121 <XMarkMini
122 className={clsx(
123 "hidden text-medusa-fg-base",
124 deepThinkingEnabled && "group-hover:block"
125 )}
126 />
127 {deepThinkingEnabled && (
128 <span className="text-compact-small-plus text-medusa-fg-base">
129 Deep research
130 </span>
131 )}
132 </Button>
133 <Button
134 variant="primary"
135 className={clsx(
136 "rounded-full !p-[6.5px] border",
137 question && "shadow-button-inverted border-transparent",
138 !question && "border-medusa-border-base"
139 )}
140 disabled={!question}
141 onClick={() => handleSubmit()}
142 >
143 <HomepageArrowUpMini width="13px" height="13px" />
144 </Button>
145 </div>
146 <HomepageEdges />
147 </div>
148 {/* Chat suggestions area */}
149 <div
150 className={clsx(
151 "w-full h-full lg:w-1/2 flex justify-start items-center",
152 "px-2 py-2 lg:py-0"
153 )}
154 >
155 <div className="flex gap-2 flex-col">
156 {suggestions.map((section, index) => (
157 <div className="flex gap-0.75 flex-col" key={index}>
158 <HeadlineTags tags={[section.tag]} className="!justify-start" />
159 <div className="flex gap-0.5 flex-col">
160 {section.questions.map((question, qIndex) => (
161 <div className="w-fit" key={qIndex}>
162 <button
163 className={clsx(
164 "flex px-[6px] py-x appearance-none text-left",
165 "rounded-xs bg-medusa-alphas-alpha-6 font-monospace",
166 "text-code-paragraph-xsmall text-medusa-fg-subtle hover:text-medusa-fg-base"
167 )}
168 onClick={() => handleSubmit(question)}
169 >
170 {question}
171 </button>
172 </div>
173 ))}
174 </div>
175 </div>
176 ))}
177 </div>
178 </div>
179 </div>
180 )
181 }
182
183 export default HomepageBloom