import React from 'react'

import { vui } from '../core'
import { cs } from '../utils'
import Footer from './footer'
import type { ApplicationFooterProps } from './footer.types'
import { defaultLinkedInUrl } from './footerTrademark'

export const ApplicationFooter = vui<'div', ApplicationFooterProps>((props, ref) => {
  const { applicationLinks, applicationStaticItems = [], className, isDNV = false, linkedIn, ...rest } = props

  const applicationSocialLinks = []
  let localLinkedIn = ''

  if (isDNV) {
    applicationStaticItems.splice(0, applicationStaticItems.length)

    //populate the DNV social links
    applicationSocialLinks.push({
      id: 'linked-in',
      text: 'LinkedIn',
      url: 'https://www.linkedin.com/showcase/dnv-digital/',
    })
    applicationSocialLinks.push({
      id: 'twitter',
      text: 'Twitter',
      url: 'https://twitter.com/DNV_Group',
    })
    applicationSocialLinks.push({
      id: 'facebook',
      text: 'FB',
      url: 'https://www.facebook.com/dnvglsoftware',
    })
    applicationSocialLinks.push({
      id: 'youtube',
      text: 'Youtube',
      url: 'https://www.youtube.com/user/DNVsoftware',
    })

    localLinkedIn = 'https://www.linkedin.com/company/4411'
  } else {
    // the static links are trimmed to max 2 items
    applicationStaticItems.splice(2, applicationStaticItems.length - 1)

    applicationSocialLinks.push({
      id: 'linked-in',
      text: 'LinkedIn',
      url: defaultLinkedInUrl,
    })

    localLinkedIn = linkedIn || defaultLinkedInUrl
  }

  return (
    <Footer
      applicationLinks={applicationLinks}
      applicationSocialLinks={applicationSocialLinks}
      applicationStaticItems={applicationStaticItems}
      className={cs(
        'vui-applicationFooter',
        isDNV ? 'vui-applicationDNVFooter' : 'vui-applicationVeracityFooter',
        className,
      )}
      isApplication
      isDNV={isDNV}
      isSlim
      linkedIn={localLinkedIn}
      ref={ref}
      variant="developer"
      {...rest}
    />
  )
})

ApplicationFooter.displayName = 'ApplicationFooter'

export default ApplicationFooter
