import type { ReleaseManifestPlatformView } from '../../release-manifest'
import { formatReleasePublishedAt } from '../../release-manifest'

export function ReleaseValidationSummary({ platform }: { platform: ReleaseManifestPlatformView }) {
  const summary = platform.validation_summary
  if (!summary) {
    return null
  }

  const generatedAt = formatReleasePublishedAt(summary.generated_at) || summary.generated_at
  const resultLabel = summary.result === 'passed' ? 'Packaged validation passed' : 'Packaged validation needs attention'
  const prePackageEditorBuild = summary.pre_package_editor_build
  const packageBuildModeLabel = summary.skip_build
    ? 'reused the existing packaged-game target receipt'
    : 'ran a full package build'

  return (
    <div className="callout top-gap">
      <p className="status-pill status-pill--info">{resultLabel}</p>
      <p>
        The {platform.platform} lane has current first-party package proof on the {summary.lane.toLowerCase()}.
        Latest evidence was generated {generatedAt} in {summary.configuration} mode and covered {summary.smoke_map_count} dedicated-family higher-dimensional training map{summary.smoke_map_count === 1 ? '' : 's'}.
      </p>
      <ul className="list top-gap">
        {summary.smoke_maps.map((map) => (
          <li key={map.map_url}>
            {map.label}: {map.result}
          </li>
        ))}
        {prePackageEditorBuild ? (
          <li>
            Pre-package editor build in same proof packet:{' '}
            {prePackageEditorBuild.performed
              ? `${prePackageEditorBuild.result} on the ${prePackageEditorBuild.lane.toLowerCase()} lane`
              : `not run on the ${prePackageEditorBuild.lane.toLowerCase()} lane`}
          </li>
        ) : null}
        <li>Package helper build mode: {packageBuildModeLabel}</li>
      </ul>
    </div>
  )
}
