import React, { ReactElement } from 'react';
import { Card } from 'react-bootstrap';
import { ResultDocument } from '../../api/result';
import DocumentTeaser from '../document/DocumentTeaser';


export default function DocumentHierarchyHeader({ documents, searchParams }
        : { documents: ResultDocument[], searchParams: string } ): ReactElement {

    const firstDoc = documents?.[0];
    const project = firstDoc?.project;

    return documents.length
        ? <Card.Header className="hierarchy-parent">
            <DocumentTeaser project={ project } searchParams={ searchParams }
                document={ getParentDocument(firstDoc) }
                hierarchyHeader={ true } />
        </Card.Header>
        : <></>;
}


const getParentDocument = (doc: ResultDocument): ResultDocument | undefined =>
    doc.resource.relations?.isChildOf[0];

import React, { ReactElement } from 'react';
import { Card } from 'react-bootstrap';
import { ResultDocument } from '../../api/result';
import DocumentTeaser from '../document/DocumentTeaser';


export default function DocumentHierarchyHeader({ documents, searchParams }
        : { documents: ResultDocument[], searchParams: string } ): ReactElement {

    const firstDoc = documents?.[0];
    const project = firstDoc?.project;

    return documents.length
        ? <Card.Header className="hierarchy-parent">
            <DocumentTeaser project={ project } searchParams={ searchParams }
                document={ getParentDocument(firstDoc) }
                hierarchyHeader={ true } />
        </Card.Header>
        : <></>;
}


const getParentDocument = (doc: ResultDocument): ResultDocument | undefined =>
    doc.resource.relations?.isChildOf?.[0];

Fix bug in document hierarchy header
Fix bug in document hierarchy header
