---
import type { Operation } from '../../libs/operation'
import { includesDefaultResponse, type Responses } from '../../libs/response'
import type { Schema } from '../../libs/schema'
import Heading from '../Heading.astro'

import Response from './Response.astro'

interface Props {
  operation: Operation
  responses: Responses | undefined
  schema: Schema
}

const { operation, responses, schema } = Astro.props
---

{
  responses && (
    <>
      <Heading level={2} id="responses">
        Responses
      </Heading>
      {Object.entries(responses).map(([name, response]) => {
        if (name === 'default') {
          return null
        }

        return <Response {name} {operation} {response} {schema} />
      })}
      {includesDefaultResponse(responses) && (
        <Response name="default" {operation} response={responses['default']} {schema} />
      )}
    </>
  )
}
