"use client" import { useMemo, useState } from "react" import { IconApps, IconArrowUp, IconAt, IconBook, IconCircleDashedPlus, IconPaperclip, IconPlus, IconWorld, IconX, } from "@tabler/icons-react" import { useLanguageContext } from "@/components/language-selector" import { Avatar, AvatarFallback, AvatarImage, } from "@/styles/base-nova/ui-rtl/avatar" import { Badge } from "@/styles/base-nova/ui-rtl/badge" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/styles/base-nova/ui-rtl/command" import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/styles/base-nova/ui-rtl/dropdown-menu" import { Field, FieldLabel } from "@/styles/base-nova/ui-rtl/field" import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea, } from "@/styles/base-nova/ui-rtl/input-group" import { Popover, PopoverContent } from "@/styles/base-nova/ui-rtl/popover" import { Switch } from "@/styles/base-nova/ui-rtl/switch" import { Tooltip, TooltipContent, TooltipTrigger, } from "@/styles/base-nova/ui-rtl/tooltip" const translations = { ar: { dir: "rtl" as const, prompt: "الأمر", placeholder: "اسأل، ابحث، أو أنشئ أي شيء...", addContext: "أضف سياق", mentionTooltip: "اذكر شخصًا أو صفحة أو تاريخًا", searchPages: "البحث في الصفحات...", noPagesFound: "لم يتم العثور على صفحات", pages: "الصفحات", users: "المستخدمون", attachFile: "إرفاق ملف", selectModel: "اختر نموذج الذكاء الاصطناعي", selectAgentMode: "اختر وضع الوكيل", webSearch: "البحث على الويب", appsIntegrations: "التطبيقات والتكاملات", allSourcesAccess: "جميع المصادر التي يمكنني الوصول إليها", findKnowledge: "ابحث أو استخدم المعرفة في...", noKnowledgeFound: "لم يتم العثور على معرفة", helpCenter: "مركز المساعدة", connectApps: "ربط التطبيقات", searchSourcesNote: "سنبحث فقط في المصادر المحددة هنا.", send: "إرسال", allSources: "جميع المصادر", auto: "تلقائي", agentMode: "وضع الوكيل", planMode: "وضع التخطيط", beta: "تجريبي", workspace: "مساحة العمل", meetingNotes: "ملاحظات الاجتماع", projectDashboard: "لوحة المشروع", ideasBrainstorming: "أفكار وعصف ذهني", calendarEvents: "التقويم والأحداث", documentation: "التوثيق", goalsObjectives: "الأهداف والغايات", budgetPlanning: "تخطيط الميزانية", teamDirectory: "دليل الفريق", technicalSpecs: "المواصفات التقنية", analyticsReport: "تقرير التحليلات", }, he: { dir: "rtl" as const, prompt: "פקודה", placeholder: "שאל, חפש, או צור משהו...", addContext: "הוסף הקשר", mentionTooltip: "הזכר אדם, עמוד או תאריך", searchPages: "חפש עמודים...", noPagesFound: "לא נמצאו עמודים", pages: "עמודים", users: "משתמשים", attachFile: "צרף קובץ", selectModel: "בחר מודל AI", selectAgentMode: "בחר מצב סוכן", webSearch: "חיפוש באינטרנט", appsIntegrations: "אפליקציות ואינטגרציות", allSourcesAccess: "כל המקורות שיש לי גישה אליהם", findKnowledge: "מצא או השתמש בידע ב...", noKnowledgeFound: "לא נמצא ידע", helpCenter: "מרכז עזרה", connectApps: "חבר אפליקציות", searchSourcesNote: "נחפש רק במקורות שנבחרו כאן.", send: "שלח", allSources: "כל המקורות", auto: "אוטומטי", agentMode: "מצב סוכן", planMode: "מצב תכנון", beta: "בטא", workspace: "סביבת עבודה", meetingNotes: "הערות פגישה", projectDashboard: "לוח מחוונים לפרויקט", ideasBrainstorming: "רעיונות וסיעור מוחות", calendarEvents: "יומן ואירועים", documentation: "תיעוד", goalsObjectives: "מטרות ויעדים", budgetPlanning: "תכנון תקציב", teamDirectory: "ספריית צוות", technicalSpecs: "מפרט טכני", analyticsReport: "דוח אנליטיקה", }, } function MentionableIcon({ item, }: { item: { type: string; title: string; image: string } }) { return item.type === "page" ? ( {item.image} ) : ( {item.title[0]} ) } export function NotionPromptForm() { const context = useLanguageContext() const lang = context?.language === "he" ? "he" : "ar" const t = translations[lang] const SAMPLE_DATA = useMemo( () => ({ mentionable: [ { type: "page", title: t.meetingNotes, image: "📝" }, { type: "page", title: t.projectDashboard, image: "📊" }, { type: "page", title: t.ideasBrainstorming, image: "💡" }, { type: "page", title: t.calendarEvents, image: "📅" }, { type: "page", title: t.documentation, image: "📚" }, { type: "page", title: t.goalsObjectives, image: "🎯" }, { type: "page", title: t.budgetPlanning, image: "💰" }, { type: "page", title: t.teamDirectory, image: "👥" }, { type: "page", title: t.technicalSpecs, image: "🔧" }, { type: "page", title: t.analyticsReport, image: "📈" }, { type: "user", title: "shadcn", image: "https://github.com/shadcn.png", workspace: t.workspace, }, { type: "user", title: "maxleiter", image: "https://github.com/maxleiter.png", workspace: t.workspace, }, { type: "user", title: "evilrabbit", image: "https://github.com/evilrabbit.png", workspace: t.workspace, }, ], models: [ { name: t.auto }, { name: t.agentMode, badge: t.beta }, { name: t.planMode }, ], }), [t] ) const [mentions, setMentions] = useState([]) const [mentionPopoverOpen, setMentionPopoverOpen] = useState(false) const [modelPopoverOpen, setModelPopoverOpen] = useState(false) const [selectedModel, setSelectedModel] = useState< (typeof SAMPLE_DATA.models)[0] >(SAMPLE_DATA.models[0]) const [scopeMenuOpen, setScopeMenuOpen] = useState(false) const grouped = useMemo(() => { return SAMPLE_DATA.mentionable.reduce( (acc, item) => { const isAvailable = !mentions.includes(item.title) if (isAvailable) { if (!acc[item.type]) { acc[item.type] = [] } acc[item.type].push(item) } return acc }, {} as Record ) }, [mentions, SAMPLE_DATA]) const hasMentions = mentions.length > 0 return (
{t.prompt} } onFocusCapture={(e) => e.stopPropagation()} > {!hasMentions && t.addContext} {t.mentionTooltip} {t.noPagesFound} {Object.entries(grouped).map(([type, items]) => ( {items.map((item) => ( { setMentions((prev) => [...prev, currentValue]) setMentionPopoverOpen(false) }} > {item.title} ))} ))}
{mentions.map((mention) => { const item = SAMPLE_DATA.mentionable.find( (item) => item.title === mention ) if (!item) { return null } return ( { setMentions((prev) => prev.filter((m) => m !== mention)) }} > {item.title} ) })}
} > {t.attachFile} } > {selectedModel.name} {t.selectModel} {t.selectAgentMode} {SAMPLE_DATA.models.map((model) => ( { if (checked) { setSelectedModel(model) } }} className="pr-2 *:[span:first-child]:right-auto *:[span:first-child]:left-2" > {model.name} {model.badge && ( {model.badge} )} ))} } > {t.allSources} {t.webSearch}{" "} } onSelect={(e) => e.preventDefault()} > {t.appsIntegrations} } onSelect={(e) => e.preventDefault()} > {t.allSourcesAccess} CN shadcn {t.noKnowledgeFound} {SAMPLE_DATA.mentionable .filter((item) => item.type === "user") .map((user) => ( { console.log("Selected user:", user.title) }} > {user.title[0]} {user.title}{" "} -{" "} { (user as { workspace?: string }) .workspace } ))} {t.helpCenter} {t.connectApps} {t.searchSourcesNote}
) }