"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoadButton = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const FileDroppable_1 = require("../../../components/FileDroppable");
const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
const LoadButton = (props) => {
    const onLoadInitialState = (e) => {
        const nativeEvent = e.nativeEvent;
        let files;
        if (nativeEvent && nativeEvent.dataTransfer) {
            files = nativeEvent.dataTransfer.files;
        }
        else {
            files = e.target.files;
        }
        const file = files[0];
        (0, FileDroppable_1.readJSONFile)(file).then((json) => {
            props.onLoad(json);
        });
    };
    return (React.createElement(SimpleButton_1.default, { ...props, className: "ab-StateManagement__Load-Button" },
        React.createElement("input", { "aria-label": "Load Adaptable State", type: "file", onChange: (json) => onLoadInitialState(json), accept: '.json', style: {
                opacity: 0,
                position: 'absolute',
                cursor: 'pointer',
                fontSize: 0,
                lineHeight: 0,
                top: 0,
                left: 0,
                width: '100%',
                height: '100%',
                zIndex: 1,
            } }),
        ' ',
        props.children));
};
exports.LoadButton = LoadButton;
