import { useI18n } from '@solid-primitives/i18n' import { IconBrandSpeedtest, IconReload } from '@tabler/icons-solidjs' import { For, Show, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button, Collapse, ForTwoColumns, ProxyCardGroups, ProxyNodePreview, SubscriptionInfo, } from '~/components' import { formatTimeFromNow, sortProxiesByOrderingType, useStringBooleanMap, } from '~/helpers' import { proxiesOrderingType, useProxies } from '~/signals' import type { Proxy } from '~/types' enum ActiveTab { proxyProviders = 'proxyProviders', proxies = 'proxies', } export default () => { const [t] = useI18n() const { proxies, setProxyGroupByProxyName, latencyTestByProxyGroupName, latencyMap, proxyProviders, updateProviderByProviderName, updateAllProvider, healthCheckByProviderName, } = useProxies() const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap() const { map: latencyTestingMap, setWithCallback: setLatencyTestingMap } = useStringBooleanMap() const onProxyNodeClick = async (proxy: Proxy, proxyName: string) => { void setProxyGroupByProxyName(proxy, proxyName) } const onLatencyTestClick = async (e: MouseEvent, name: string) => { e.stopPropagation() void setLatencyTestingMap(name, () => latencyTestByProxyGroupName(name)) } const { map: healthCheckingMap, setWithCallback: setHealthCheckingMap } = useStringBooleanMap() const { map: updatingMap, setWithCallback: setUpdatingMap } = useStringBooleanMap() const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false) const onHealthCheckClick = (e: MouseEvent, name: string) => { e.stopPropagation() void setHealthCheckingMap(name, () => healthCheckByProviderName(name)) } const onUpdateProviderClick = (e: MouseEvent, name: string) => { e.stopPropagation() void setUpdatingMap(name, () => updateProviderByProviderName(name)) } const onUpdateAllProviderClick = async (e: MouseEvent) => { e.stopPropagation() setIsAllProviderUpdating(true) try { await updateAllProvider() } catch {} setIsAllProviderUpdating(false) } const [activeTab, setActiveTab] = createSignal(ActiveTab.proxies) const tabs = () => [ { type: ActiveTab.proxies, name: t('proxies'), count: proxies().length, }, { type: ActiveTab.proxyProviders, name: t('proxyProviders'), count: proxyProviders().length, }, ] return (