import { Contracts } from "ts-extractor" ; import { GeneratorHelpers } from "../../generator-helpers" ; import { ApiEnumMember } from "./api-enum-member" ; import { ApiDefinitionBase } from "../api-definition-base" ; import { ApiItemReference } from "../../contracts/api-item-reference" ; import { ReferenceRenderHandler } from "../../contracts/serialized-api-item" ; export class ApiEnum extends ApiDefinitionBase < Contracts . ApiEnumDto > { private enumMembers : ApiEnumMember [ ] | undefined ; public get EnumMembers ( ) : ApiEnumMember [ ] { if ( this . enumMembers == null ) { this . enumMembers = GeneratorHelpers . GetApiItemReferences ( this . ExtractedData , this . ApiItem . Members ) . map < [ ApiItemReference , Contracts . ApiEnumMemberDto ] > ( reference => [ reference , this . ExtractedData . Registry [ reference . Id ] as Contracts . ApiEnumMemberDto ] ) . map ( ( [ reference , enumMember ] ) => new ApiEnumMember ( this . ExtractedData , enumMember , reference ) ) ; } return this . enumMembers ; } public ToText ( render = this . DefaultReferenceRenderer ) { const $const = this . ApiItem . IsConst ? "const " : "" ; const membersStrings = this . EnumMembers . map ( ( memberItem , index , array ) => { let memberString = `${ GeneratorHelpers . Tab ( ) } ${ memberItem . ToText ( ) }` ; if ( index !== this . EnumMembers . length - 1 ) { memberString += "," ; } return memberString ; } ) ; return [ `${ $const }enum ${ this . Name } {` , ... membersStrings , "}" ] ; } public ToHeadingText ( ) { return this . Name ; } }