import React, { useContext } from 'react';
import { query } from '../../dom-utils';
import { useExamTranslation } from '../../i18n';
import { url } from '../../url';
import AttachmentLinkAnchor from './internal/AttachmentLinkAnchor';
import { CommonExamContext } from '../context/CommonExamContext';
const mkAttachmentLink = (type) => {
    const AttachmentLink = ({ element }) => {
        const name = element.getAttribute('ref');
        const { root } = useContext(CommonExamContext);
        const { attachmentsURL } = useContext(CommonExamContext);
        const { t } = useExamTranslation();
        const attachment = query(root, el => el.localName === 'attachment' && el.getAttribute('name') === name);
        const displayNumber = attachment.getAttribute('display-number');
        const isShort = element.getAttribute('type') === 'short';
        const href = url(attachmentsURL, { hash: displayNumber });
        return isShort ? (React.createElement(AttachmentLinkAnchor, { href, type }, displayNumber)) : (React.createElement(React.Fragment, null,
            '(',
            React.createElement(AttachmentLinkAnchor, { href, type },
                t('material', { postProcess: 'lowercase' }),
                " ",
                displayNumber),
            ')'));
    };
    return React.memo(AttachmentLink);
};
export default mkAttachmentLink;
//# sourceMappingURL=AttachmentLink.js.map