<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import CardUtils from './card/CardUtils'
import { ACTIVITY_TYPE } from '../constants'
import { GREY_1 } from 'govuk-colours'
import styled from 'styled-components'

import ActivityCardWrapper from './card/ActivityCardWrapper'
import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityCardLabels from './card/ActivityCardLabels'
import { formatStartAndEndDate } from '../../../utils/date'

export const AVENTRI_ATTENDEE_REG_STATUSES = {
  Attended: 'Attended',
  Cancelled: 'Cancelled',
  Confirmed: 'Registered',
  Incomplete: 'Incomplete',
}

export const transformAventriAttendee = (attendee) => ({
  attendeeName: `${attendee.object['dit:aventri:firstname']} ${attendee.object['dit:aventri:lastname']}`,
  date: formatStartAndEndDate(attendee.startDate, attendee.endDate),
  eventName: attendee.eventName,
  registrationStatus:
    AVENTRI_ATTENDEE_REG_STATUSES[
      attendee.object['dit:aventri:registrationstatus']
    ],
})

const StyledSpan = styled('span')`
  & > span {
    color: ${GREY_1};
  }
`

export default function AventriAttendee({ activity: attendee }) {
  const { attendeeName, eventName, date, registrationStatus } =
    transformAventriAttendee(attendee)

  return eventName ? (
    <ActivityCardWrapper dataTest="aventri-activity">
      <ActivityCardLabels service="event" kind="aventri service delivery" />
      <ActivityCardSubject>
        {eventName}
        {registrationStatus && (
          <StyledSpan>
            : <span>{registrationStatus}</span>
          </StyledSpan>
        )}
      </ActivityCardSubject>
      <ActivityCardMetadata
        metadata={[{ label: 'Event date', value: date || 'Unknown' }]}
      />
    </ActivityCardWrapper>
  ) : (
    <ActivityCardWrapper dataTest="aventri-attendee">
      <ActivityCardSubject dataTest="aventri-attendee-name">
        {attendeeName}
      </ActivityCardSubject>
    </ActivityCardWrapper>
  )
}

AventriAttendee.propTypes = {
  activity: PropTypes.object.isRequired,
}

AventriAttendee.canRender = (attendee) => {
  return CardUtils.canRenderByTypes(attendee, ACTIVITY_TYPE.AventriAttendee)
}<commit_msg>Add a link to attendee names<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import { Link as RouterLink } from 'react-router-dom'
import Link from '@govuk-react/link'
import CardUtils from './card/CardUtils'
import { ACTIVITY_TYPE } from '../constants'
import { GREY_1 } from 'govuk-colours'
import styled from 'styled-components'

import ActivityCardWrapper from './card/ActivityCardWrapper'
import ActivityCardSubject from './card/ActivityCardSubject'
import ActivityCardMetadata from './card/ActivityCardMetadata'
import ActivityCardLabels from './card/ActivityCardLabels'
import { formatStartAndEndDate } from '../../../utils/date'

export const AVENTRI_ATTENDEE_REG_STATUSES = {
  Attended: 'Attended',
  Cancelled: 'Cancelled',
  Confirmed: 'Registered',
  Incomplete: 'Incomplete',
}

export const transformAventriAttendee = (attendee) => ({
  attendeeName: `${attendee.object['dit:aventri:firstname']} ${attendee.object['dit:aventri:lastname']}`,
  date: formatStartAndEndDate(attendee.startDate, attendee.endDate),
  eventName: attendee.eventName,
  registrationStatus:
    AVENTRI_ATTENDEE_REG_STATUSES[
      attendee.object['dit:aventri:registrationstatus']
    ],
  attendeeContactURL: attendee.attendeeContactURL,
})

const StyledSpan = styled('span')`
  & > span {
    color: ${GREY_1};
  }
`

export default function AventriAttendee({ activity: attendee }) {
  const {
    attendeeName,
    eventName,
    date,
    registrationStatus,
    attendeeContactURL,
  } = transformAventriAttendee(attendee)

  return eventName ? (
    <ActivityCardWrapper dataTest="aventri-activity">
      <ActivityCardLabels service="event" kind="aventri service delivery" />
      <ActivityCardSubject>
        {eventName}
        {registrationStatus && (
          <StyledSpan>
            : <span>{registrationStatus}</span>
          </StyledSpan>
        )}
      </ActivityCardSubject>
      <ActivityCardMetadata
        metadata={[{ label: 'Event date', value: date || 'Unknown' }]}
      />
    </ActivityCardWrapper>
  ) : (
    <ActivityCardWrapper dataTest="aventri-attendee">
      <ActivityCardSubject dataTest="aventri-attendee-name">
        {attendeeContactURL ? (
          <Link as={RouterLink} to={attendeeContactURL}>
            {attendeeName}
          </Link>
        ) : (
          attendeeName
        )}
      </ActivityCardSubject>
    </ActivityCardWrapper>
  )
}

AventriAttendee.propTypes = {
  activity: PropTypes.object.isRequired,
}

AventriAttendee.canRender = (attendee) => {
  return CardUtils.canRenderByTypes(attendee, ACTIVITY_TYPE.AventriAttendee)
}
{'fraction_non_alphanumeric': 0.12087010055407346, 'fraction_numerical': 0.0008208495793145906, 'mean_word_length': 4.082377476538061, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150596', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1521, 'n_words': 280}