import { useMemo } from 'react' import { Card, Tag, Icon, Loading } from '@components' import { compareDesc } from '@containers/Proxies' import { Proxy } from '@containers/Proxies/components/Proxy' import { fromNow } from '@lib/date' import { useVisible } from '@lib/hook' import { type Provider as IProvider, type Proxy as IProxy } from '@lib/request' import { useClient, useI18n, useProxyProviders } from '@stores' import './style.scss' interface ProvidersProps { provider: IProvider } export function Provider (props: ProvidersProps) { const { update } = useProxyProviders() const { translation, lang } = useI18n() const client = useClient() const { provider } = props const { t } = translation('Proxies') const { visible, hide, show } = useVisible() function handleHealthChech () { show() client.healthCheckProvider(provider.name).then(async () => await update()).finally(() => hide()) } function handleUpdate () { show() client.updateProvider(provider.name).then(async () => await update()).finally(() => hide()) } const proxies = useMemo(() => { return (provider.proxies as IProxy[]).slice().sort((a, b) => -1 * compareDesc(a, b)) }, [provider.proxies]) return (
{ provider.name } { provider.vehicleType }
{ provider.updatedAt && { `${t('providerUpdateTime')}: ${fromNow(new Date(provider.updatedAt), lang)}`} }
) }