import { Typography } from '@tidbcloud/uikit'

import { Endpoint } from './types'

const defaultFooters = {
  [Endpoint.Public]: (
    <>
      Connections to this instance with public endpoint require TLS. Learn more about{' '}
      <a
        href="https://docs.pingcap.com/tidbcloud/secure-connections-to-serverless-clusters/"
        target="_blank"
        rel="noopener noreferrer"
      >
        secure connection settings
      </a>
      .
    </>
  ),
  [Endpoint.Private]: 'Connections to this instance with private endpoint use Private Link, and TLS is optional.'
}

interface ConnectionModalFooterProps {
  docLink?: string
  rootClientName: string
  endpoint: Endpoint
}

export function ConnectionModalFooter({ docLink, rootClientName, endpoint }: ConnectionModalFooterProps) {
  if (docLink) {
    return (
      <Typography variant="body-lg">
        The above codes show how to connect to your instance with {rootClientName}. Learn more about{' '}
        <a href={docLink} target="_blank" rel="noopener noreferrer">
          {rootClientName} connection
        </a>
        .
      </Typography>
    )
  }

  return <Typography variant="body-lg">{defaultFooters[endpoint]}</Typography>
}
