"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var Button_1 = require("../Button");
var Modal_1 = require("../Modal");
var styleConstants_1 = require("../styleConstants");
var styled_components_1 = __importDefault(require("styled-components"));
var react_dropzone_1 = __importDefault(require("react-dropzone"));
var DropArea = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  cursor: pointer;\n  outline: none;\n  width: 100%;\n  box-sizing: border-box;\n  height: 200px;\n  border: 3px dashed ", ";\n  color: ", ";\n  border-radius: 5px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  padding: 30px;\n  &:hover {\n    border-color: ", ";\n  }\n  p {\n    font-size: 18px;\n    font-family: ", ";\n  }\n"], ["\n  cursor: pointer;\n  outline: none;\n  width: 100%;\n  box-sizing: border-box;\n  height: 200px;\n  border: 3px dashed ", ";\n  color: ", ";\n  border-radius: 5px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  padding: 30px;\n  &:hover {\n    border-color: ", ";\n  }\n  p {\n    font-size: 18px;\n    font-family: ", ";\n  }\n"])), styleConstants_1.colors.primary.CIVIL_GRAY_2, styleConstants_1.colors.primary.CIVIL_GRAY_2, styleConstants_1.colors.primary.CIVIL_BLUE_1, styleConstants_1.fonts.SANS_SERIF);
var ButtonContainer = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  display: flex;\n  justify-content: flex-end;\n  margin-top: 25px;\n"], ["\n  display: flex;\n  justify-content: flex-end;\n  margin-top: 25px;\n"])));
var ImageFileToDataUri = /** @class */ (function (_super) {
    __extends(ImageFileToDataUri, _super);
    function ImageFileToDataUri(props) {
        var _this = _super.call(this, props) || this;
        _this.createDataUrlFromFile = function (acceptedFiles) {
            var reader = new FileReader();
            reader.onload = function (event) {
                _this.props.onChange(event.target.result);
                _this.setState({ modalOpen: false });
            };
            reader.readAsDataURL(acceptedFiles[0]);
        };
        _this.state = {
            modalOpen: false,
        };
        return _this;
    }
    ImageFileToDataUri.prototype.renderModal = function () {
        var _this = this;
        if (!this.state.modalOpen) {
            return null;
        }
        return (React.createElement(Modal_1.Modal, null,
            React.createElement(react_dropzone_1.default, { onDrop: this.createDataUrlFromFile }, function (_a) {
                var getRootProps = _a.getRootProps, getInputProps = _a.getInputProps;
                return (React.createElement("section", null,
                    React.createElement(DropArea, __assign({}, getRootProps()),
                        React.createElement("input", __assign({}, getInputProps())),
                        React.createElement("p", null, "Drop files here, or click to select files"))));
            }),
            React.createElement(ButtonContainer, null,
                React.createElement(Button_1.BorderlessButton, { size: Button_1.buttonSizes.SMALL, onClick: function () { return _this.setState({ modalOpen: false }); } }, "Close"))));
    };
    ImageFileToDataUri.prototype.render = function () {
        var _this = this;
        return (React.createElement(React.Fragment, null,
            React.createElement(Button_1.InvertedButton, { size: Button_1.buttonSizes.SMALL, onClick: function () { return _this.setState({ modalOpen: true }); } },
                " ",
                this.props.buttonText || "Add Image",
                " "),
            this.renderModal()));
    };
    return ImageFileToDataUri;
}(React.Component));
exports.ImageFileToDataUri = ImageFileToDataUri;
var templateObject_1, templateObject_2;
//# sourceMappingURL=ImageFileToDataUri.js.map