import { useCallback, useMemo, useState } from "react"; import { Pressable, StyleSheet, Text, View } from "react-native"; import { Modal, TextInput, ScrollView } from "@getpaseo/plugin/client/ui"; import { useTranslation, type PluginSurfaceProps } from "@getpaseo/plugin/client"; import { messages } from "./messages"; function useStyles(theme: PluginSurfaceProps["theme"], compact: boolean) { return useMemo(() => { const primary = { padding: 12, borderRadius: 8, backgroundColor: theme.colors.accent }; return StyleSheet.create({ screen: { flex: 1, backgroundColor: theme.colors.surface0 }, content: { padding: compact ? 20 : 36, gap: 20, width: "100%", maxWidth: 760, alignSelf: "center", }, heading: { gap: 8 }, title: { color: theme.colors.foreground, fontSize: 28, fontWeight: "600" }, text: { color: theme.colors.foreground }, muted: { color: theme.colors.foregroundMuted }, label: { color: theme.colors.foreground, fontWeight: "600" }, card: { gap: 12, padding: 20, borderRadius: 12, borderWidth: 1, borderColor: theme.colors.border, backgroundColor: theme.colors.surface1, }, input: { color: theme.colors.foreground, minHeight: 112, padding: 12, borderRadius: 8, borderColor: theme.colors.border, borderWidth: 1, backgroundColor: theme.colors.surface0, }, actions: { flexDirection: "row", gap: 12, flexWrap: "wrap" }, primary, primaryDisabled: { ...primary, opacity: 0.5 }, primaryText: { color: theme.colors.accentForeground }, secondary: { padding: 12, borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border }, preview: { gap: 16 }, close: { padding: 12 }, closeText: { color: theme.colors.accent }, }); }, [theme, compact]); } function Preview({ draft, theme, close, }: { draft: string; theme: PluginSurfaceProps["theme"]; close(): void; }) { // This hook also runs inside native portal hosts. const { t, locale } = useTranslation(messages); const styles = useStyles(theme, false); return ( {draft || t("draftEmpty")} {t("locale", { locale })} {t("close")} ); } export function Notes({ theme, layout }: PluginSurfaceProps) { const { t, locale } = useTranslation(messages); const [draft, setDraft] = useState(""); const [notes, setNotes] = useState<{ id: number; text: string }[]>([]); const [preview, setPreview] = useState(false); const styles = useStyles(theme, layout.compact); const showPreview = useCallback(() => setPreview(true), []); const closePreview = useCallback(() => setPreview(false), []); const addNote = useCallback(() => { setNotes((previous) => [...previous, { id: previous.length, text: draft }]); setDraft(""); }, [draft]); return ( {t("title")} {t("intro")} {t("draft")} {t("add")} {t("preview")} {t("notes", { count: notes.length })} {notes.length === 0 ? ( {t("empty")} ) : ( notes.map((note) => ( {note.text} )) )} {t("locale", { locale })} {t("fallback")} ); }