// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { Icon, mergeStyles } from '@fluentui/react';
import React, { useMemo } from 'react';
import { _AttachmentCard } from './AttachmentCard';
import { _AttachmentCardGroup, _AttachmentCardGroupLayout } from './AttachmentCardGroup';
import { useLocaleAttachmentCardStringsTrampoline } from '../utils/common';
const actionIconStyle = {
    height: '1rem'
};
/**
 * @internal
 */
export const _AttachmentUploadCards = (props) => {
    var _a;
    const attachments = props.attachments;
    const localeStrings = useLocaleAttachmentCardStringsTrampoline();
    const removeAttachmentButtonString = useMemo(() => () => {
        var _a, _b;
        return (_b = (_a = props.strings) === null || _a === void 0 ? void 0 : _a.removeAttachment) !== null && _b !== void 0 ? _b : localeStrings.removeAttachment;
    }, [(_a = props.strings) === null || _a === void 0 ? void 0 : _a.removeAttachment, localeStrings.removeAttachment]);
    if (!attachments || attachments.length === 0) {
        return React.createElement(React.Fragment, null);
    }
    return React.createElement(_AttachmentCardGroup, { attachmentGroupLayout: _AttachmentCardGroupLayout.Flex, disabled: props.disabled }, attachments && attachments.filter(attachment => !attachment.error).map(attachment => React.createElement(_AttachmentCard, { attachment: attachment, key: attachment.id, menuActions: [{
                name: removeAttachmentButtonString(),
                icon: React.createElement("div", { "data-testid": "attachment-upload-card-remove" },
                    React.createElement(Icon, { iconName: "CancelAttachmentUpload", className: mergeStyles(actionIconStyle) })),
                onClick: attachment => {
                    return new Promise((resolve, reject) => {
                        try {
                            props.onCancelAttachmentUpload && props.onCancelAttachmentUpload(attachment.id);
                            resolve();
                        }
                        catch (e) {
                            reject(e.message);
                        }
                    });
                }
            }], strings: props.strings })));
};
//# sourceMappingURL=AttachmentUploadCards.js.map