import { Icon } from "@getpaseo/plugin/client/react-native"; import React, { useContext, useState } from "react"; import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"; import { finiteNumber, list, nodes, optionalText, text, type Props } from "../../shared/logic/values"; import { isButtonLike, RenderNode, RenderNodes } from "../node-renderer"; import { CardDepthContext, propsKey, usePersistedState, useUiRuntime } from "../runtime"; export function Card({ props }: { props: Props }) { const { theme, compact } = useUiRuntime(); const depth = useContext(CardDepthContext); const title = optionalText(props.title); const children = nodes(props.children); return ( {title !== null && title.trim() !== "" ? ( {title} ) : null} ); } export function Row({ props }: { props: Props }) { const { compact } = useUiRuntime(); const children = nodes(props.children); // Equal columns suit content; a row of buttons reads as one group instead. if (children.length > 0 && children.every(isButtonLike)) return ; return ( {children.map((child, idx) => ( ))} ); } export function Stack({ props }: { props: Props }) { const { compact } = useUiRuntime(); const children = nodes(props.children); return ( ); } export function Grid({ props }: { props: Props }) { const { compact } = useUiRuntime(); const children = nodes(props.children); const requestedCols = finiteNumber(props.columns); const cols = compact ? 1 : Math.max(1, Math.min(4, requestedCols ? Math.round(requestedCols) : 2)); const rows: typeof children[] = []; for (let i = 0; i < children.length; i += cols) { rows.push(children.slice(i, i + cols)); } return ( {rows.map((row, rIdx) => ( {row.map((child, cIdx) => ( ))} ))} ); } export function Tabs({ props }: { props: Props }) { const { theme } = useUiRuntime(); const labels = list(props.labels).map((item) => text(item)); const children = nodes(props.children); const [selected, setSelected] = usePersistedState( `tabs:${propsKey(labels)}`, 0, (v) => (typeof v === "number" && v >= 0 && v < labels.length ? v : null), ); const activeIdx = Math.min(Math.max(0, selected), Math.max(0, labels.length - 1)); const activeChild = children[activeIdx]; return ( {labels.map((label, index) => { const active = index === activeIdx; return ( setSelected(index)} style={{ paddingHorizontal: 10, paddingVertical: 5, borderRadius: 6, backgroundColor: active ? theme.colors.surface2 : "transparent", }} > {label} ); })} {activeChild ? : null} ); } export function Details({ props }: { props: Props }) { const { theme } = useUiRuntime(); const title = text(props.title); const children = nodes(props.children); const initialOpen = props.open === true; const [open, setOpen] = useState(initialOpen); return ( setOpen((prev) => !prev)} style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingHorizontal: 12, paddingVertical: 9, gap: 8, }} > {title} {open ? ( ) : null} ); } export function Divider() { const { theme } = useUiRuntime(); return ( ); } export function Carousel({ props }: { props: Props }) { const { compact } = useUiRuntime(); const children = nodes(props.children); return ( {children.map((child, idx) => ( ))} ); }