import React, { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import i18next from 'i18next'; import { useSelector } from 'react-redux'; import { MOBILE_CONFIG_LINKS } from '../../../helpers/constants'; import Tabs from '../Tabs'; import { MobileConfigForm } from './MobileConfigForm'; import { RootState } from '../../../initialState'; interface renderLiProps { label?: string; components?: JSX.Element[]; } const renderLi = ({ label, components }: renderLiProps) => (
  • { if (React.isValidElement(props)) { return props; } const { // eslint-disable-next-line react/prop-types href, target = '_blank', rel = 'noopener noreferrer', key = '0', } = props; return ( link ); })}> {label}
  • ); const getDnsPrivacyList = () => [ { title: 'Android', list: [ { label: 'setup_dns_privacy_android_1', }, { label: 'setup_dns_privacy_android_2', components: [ { key: 0, href: 'https://link.adtidy.org/forward.html?action=android&from=ui&app=home', }, text, ], }, { label: 'setup_dns_privacy_android_3', components: [ { key: 0, href: 'https://getintra.org/', }, text, ], }, ], }, { title: 'iOS', list: [ { label: 'setup_dns_privacy_ios_2', components: [ { key: 0, href: 'https://link.adtidy.org/forward.html?action=ios&from=ui&app=home', }, text, ], }, { label: 'setup_dns_privacy_ios_1', components: [ { key: 0, href: 'https://itunes.apple.com/app/id1452162351', }, text, { key: 2, href: 'https://dnscrypt.info/stamps', }, ], }, ], }, { title: 'setup_dns_privacy_other_title', list: [ { label: 'setup_dns_privacy_other_1', }, { label: 'setup_dns_privacy_other_2', components: [ { key: 0, href: 'https://github.com/AdguardTeam/dnsproxy', }, ], }, { href: 'https://github.com/jedisct1/dnscrypt-proxy', label: 'setup_dns_privacy_other_3', components: [ { key: 0, href: 'https://github.com/jedisct1/dnscrypt-proxy', }, text, ], }, { label: 'setup_dns_privacy_other_4', components: [ { key: 0, href: 'https://support.mozilla.org/kb/firefox-dns-over-https', }, text, ], }, { label: 'setup_dns_privacy_other_5', components: [ { key: 0, href: 'https://dnscrypt.info/implementations', }, { key: 1, href: 'https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Clients', }, ], }, ], }, ]; interface renderDnsPrivacyListProps { title: string; list: unknown[]; renderList?: (...args: unknown[]) => string; } const renderDnsPrivacyList = ({ title, list }: renderDnsPrivacyListProps) => (
    {title}
    ); const getTabs = ({ tlsAddress, httpsAddress, showDnsPrivacyNotice, serverName, portHttps, t }: any) => ({ Router: { // eslint-disable-next-line react/display-name getTitle: () => (

    install_devices_router_desc

    ), title: 'Router', list: [ 'install_devices_router_list_1', 'install_devices_router_list_2', 'install_devices_router_list_3', // eslint-disable-next-line react/jsx-key link , ]}> install_devices_router_list_4 , ], }, Windows: { title: 'Windows', list: [ 'install_devices_windows_list_1', 'install_devices_windows_list_2', 'install_devices_windows_list_3', 'install_devices_windows_list_4', 'install_devices_windows_list_5', 'install_devices_windows_list_6', ], }, macOS: { title: 'macOS', list: [ 'install_devices_macos_list_1', 'install_devices_macos_list_2', 'install_devices_macos_list_3', 'install_devices_macos_list_4', ], }, Android: { title: 'Android', list: [ 'install_devices_android_list_1', 'install_devices_android_list_2', 'install_devices_android_list_3', 'install_devices_android_list_4', 'install_devices_android_list_5', ], }, iOS: { title: 'iOS', list: [ 'install_devices_ios_list_1', 'install_devices_ios_list_2', 'install_devices_ios_list_3', 'install_devices_ios_list_4', ], }, dns_privacy: { title: 'dns_privacy', getTitle: function Title() { return (
    {tlsAddress?.length > 0 && (
    text, text]}> setup_dns_privacy_1
    )} {httpsAddress?.length > 0 && (
    text, text]}> setup_dns_privacy_2
    )} {showDnsPrivacyNotice ? (
    link , text, ]}> setup_dns_notice
    ) : ( <>
    text

    ]}>setup_dns_privacy_3
    {getDnsPrivacyList().map(renderDnsPrivacyList)}
    setup_dns_privacy_ioc_mac
    }}>setup_dns_privacy_4
    )}
    ); }, }, }); interface renderContentProps { title: string; list: unknown[]; getTitle?: (...args: unknown[]) => unknown; } const renderContent = ({ title, list, getTitle }: renderContentProps) => (
    {i18next.t(title)}
    {getTitle?.()} {list && (
      {list.map((item: any) => (
    1. {item}
    2. ))}
    )}
    ); interface GuideProps { dnsAddresses?: unknown[]; } export const Guide = ({ dnsAddresses }: GuideProps) => { const { t } = useTranslation(); const serverName = useSelector((state: RootState) => state.encryption?.server_name); const portHttps = useSelector((state: RootState) => state.encryption?.port_https); const tlsAddress = dnsAddresses?.filter((item: any) => item.includes('tls://')) ?? ''; const httpsAddress = dnsAddresses?.filter((item: any) => item.includes('https://')) ?? ''; const showDnsPrivacyNotice = httpsAddress.length < 1 && tlsAddress.length < 1; const [activeTabLabel, setActiveTabLabel] = useState('Router'); const tabs = getTabs({ tlsAddress, httpsAddress, showDnsPrivacyNotice, serverName, portHttps, t, }); const activeTab = renderContent(tabs[activeTabLabel]); return (
    {activeTab}
    ); }; Guide.defaultProps = { dnsAddresses: [], };