import * as Clipboard from "expo-clipboard";
import { Link, router } from "expo-router";
import { Pressable, View } from "react-native";
import { Text } from "@/components/fixed-text";
import { haptics } from "@/lib/haptics";
import { MOBILE_LOCALE_OPTIONS, useLocale } from "@/lib/locale";
import { colors } from "@/theme/colors";
import { mono, radius, type } from "@/theme/type";
import { Button } from "./button";
import { Icon } from "./icon";
import { EmptyState, LoadingState } from "./state-views";
import { useAccount } from "@/lib/account";
import { useConnectionRecovering } from "@/lib/client";
import { listComputers, retryComputerDiscovery, useComputerDiscovery, useComputers } from "@/lib/computers";
const SETUP = "npm i -g linkshell-cli\nlinkshell host --daemon";
const DESKTOP_INSTALL = "https://liutianjie.github.io/LinkShell/#install";
/** Onboarding only after the account's computer list has finished restoring. */
export function Welcome() {
const { locale, preference, setPreference, t } = useLocale();
const discovery = useComputerDiscovery();
const recovering = useConnectionRecovering();
const account = useAccount((state) => state.session);
const discovered = useComputers((state) => listComputers(state).length > 0);
if (discovered || discovery === "loading" || (discovery === "failed" && recovering)) {
return ;
}
if (discovery === "failed" || discovery === "refused") {
return (
);
}
return (
{MOBILE_LOCALE_OPTIONS.map((option) => {
const active = preference === option.value;
return (
{
haptics.selection();
setPreference(option.value);
}}
style={({ pressed }) => ({
paddingHorizontal: 11,
paddingVertical: 6,
borderRadius: 999,
borderCurve: "continuous",
backgroundColor: active ? colors.accentSoft : colors.fill,
opacity: pressed ? 0.6 : 1,
})}
>
{option.label(locale)}
);
})}
{t("welcome.connectComputerTitle")}
{t("welcome.connectComputerSubtitle")}
{t("welcome.desktopTitle")}
{t("welcome.desktopDesc")}
({ opacity: pressed ? 0.6 : 1 })}>
{t("welcome.desktopInstallGuide")}
{
void Clipboard.setStringAsync(SETUP);
haptics.success();
}}
accessibilityRole="button"
accessibilityLabel={t("common.copy")}
style={({ pressed }) => ({ backgroundColor: colors.card, borderRadius: radius.card, borderCurve: "continuous", padding: 16, gap: 10, opacity: pressed ? 0.6 : 1 })}
>
{t("welcome.cliTitle")}
{SETUP}
{t("welcome.cliTapToCopy")}
);
}