import { useCallback, useEffect, useState } from "react";
import { Image, Pressable, Switch, Text, View } from "react-native";
import { useRpc, useSettings, useTranslation, type PluginSurfaceProps } from "@getpaseo/plugin/client";
import { Icon, SettingsAction, SettingsCard, SettingsInput, SettingsRow, SettingsSection } from "@getpaseo/plugin/client/ui";
import { appsRpc, mergeEntries, openWithSettings, type App, type Entry } from "../shared/open-with";
import { messages } from "./messages";
type Props = PluginSurfaceProps & { onSaved(): void };
export function SettingsScreen(props: Props) {
const state = useSettings(openWithSettings);
const { t } = useTranslation(messages);
const c = props.theme.colors;
if (state.status !== "ready") {
return (
{state.status === "loading" ? t("loading") : state.error}
{state.status !== "loading" && (
void state.reload()} />
{state.status === "invalid" && (
void state.reset()} />
)}
)}
);
}
return (
state.save({ entries }, state.revision)}
/>
);
}
function Editor({
theme,
stored,
saving,
saveError,
save,
onSaved,
}: Props & {
stored: Entry[];
saving: boolean;
saveError: string | null;
save(entries: Entry[]): Promise;
}) {
const { t } = useTranslation(messages);
const c = theme.colors;
const listApps = useRpc(appsRpc);
const [draft, setDraft] = useState(() => mergeEntries(stored));
const [apps, setApps] = useState