import React, { useCallback } from 'react';
import classnames from 'classnames';
import { uploadFileForSearch } from '@reltio/mdm-sdk';
import { UploadFileButton } from '../UploadFileButton';
import { useStyles } from './styles';
export var FileTypeEditor = function (_a) {
    var value = _a.value, onChange = _a.onChange, onError = _a.onError, className = _a.className;
    var _b = value || {}, downloadLink = _b.downloadLink, filename = _b.filename, expirationDate = _b.expirationDate;
    var isValidLink = expirationDate >= Date.now();
    var supportedFileTypes = ['.txt', '.csv'];
    var onUploadHandler = useCallback(function (file) {
        return uploadFileForSearch(file).then(function (_a) {
            var path = _a.path, downloadLink = _a.downloadLink, expirationDate = _a.expirationDate;
            onChange({
                filename: file.name,
                downloadLink: downloadLink,
                link: path,
                expirationDate: new Date(expirationDate).getTime()
            });
        });
    }, [onChange]);
    var onCancelHandler = useCallback(function () { return onChange(null); }, [onChange]);
    var styles = useStyles();
    return (React.createElement("div", { className: classnames(styles.editor, className) },
        React.createElement(UploadFileButton, { isValidLink: isValidLink, link: downloadLink, filename: filename, supportedFileTypes: supportedFileTypes, onUpload: onUploadHandler, onError: onError, onCancel: onCancelHandler })));
};
