"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 styleConstants_1 = require("../styleConstants");
var styled_components_1 = __importDefault(require("styled-components"));
var react_dropzone_1 = __importDefault(require("react-dropzone"));
var elements_1 = require("@joincivil/elements");
var DropArea = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  width: 336px;\n  box-sizing: border-box;\n  height: 336px;\n  ", " {\n    width: 200px;\n    height: 200px;\n  }\n  background-color: #f9faff;\n  border: 2px dashed ", ";\n  color: ", ";\n  border-radius: 168px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  flex-direction: column;\n  padding: 30px;\n\n  ", " {\n    padding-left: 10px;\n    padding-right: 10px;\n  }\n  p {\n    font-size: 18px;\n    font-family: ", ";\n  }\n"], ["\n  width: 336px;\n  box-sizing: border-box;\n  height: 336px;\n  ", " {\n    width: 200px;\n    height: 200px;\n  }\n  background-color: #f9faff;\n  border: 2px dashed ", ";\n  color: ", ";\n  border-radius: 168px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  flex-direction: column;\n  padding: 30px;\n\n  ", " {\n    padding-left: 10px;\n    padding-right: 10px;\n  }\n  p {\n    font-size: 18px;\n    font-family: ", ";\n  }\n"])), styleConstants_1.mediaQueries.MOBILE, styleConstants_1.colors.primary.CIVIL_BLUE_1, styleConstants_1.colors.primary.CIVIL_GRAY_2, styleConstants_1.mediaQueries.MOBILE, styleConstants_1.fonts.SANS_SERIF);
var ImageSelectionContainer = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: space-between;\n  height: 450px;\n  ", " {\n    height: 300px;\n    width: 240px;\n  }\n"], ["\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: space-between;\n  height: 450px;\n  ", " {\n    height: 300px;\n    width: 240px;\n  }\n"])), styleConstants_1.mediaQueries.MOBILE);
var DragAndDropText = styled_components_1.default.span(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  width: 300px;\n  ", " {\n    width: 150px;\n  }\n  text-align: center;\n"], ["\n  width: 300px;\n  ", " {\n    width: 150px;\n  }\n  text-align: center;\n"])), styleConstants_1.mediaQueries.MOBILE);
var SimpleImageFileToDataUri = /** @class */ (function (_super) {
    __extends(SimpleImageFileToDataUri, _super);
    function SimpleImageFileToDataUri(props) {
        var _this = _super.call(this, props) || this;
        _this.showOpenFileDlg = function () {
            _this.inputOpenFileRef.current.click();
        };
        _this.createDataUrlFromFile = function (acceptedFiles) {
            _this.loadAsDataURLFromFile(acceptedFiles[0]);
        };
        _this.createDataUrlFromFile2 = function (e) {
            _this.loadAsDataURLFromFile(e.target.files[0]);
        };
        _this.loadAsDataURLFromFile = function (file) {
            var reader = new FileReader();
            reader.onload = function (event) {
                _this.props.onChange(event.target.result);
                _this.setState({ modalOpen: false });
            };
            reader.readAsDataURL(file);
        };
        _this.inputOpenFileRef = React.createRef();
        return _this;
    }
    SimpleImageFileToDataUri.prototype.renderDropZone = function () {
        return (React.createElement(React.Fragment, 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(elements_1.PhotoDragIcon, null),
                        React.createElement("br", null),
                        React.createElement(DragAndDropText, null, "Drag and drop an image here"))));
            })));
    };
    SimpleImageFileToDataUri.prototype.render = function () {
        var _this = this;
        return (React.createElement(ImageSelectionContainer, null,
            this.renderDropZone(),
            "or",
            React.createElement("input", { ref: this.inputOpenFileRef, type: "file", style: { display: "none" }, onChange: this.createDataUrlFromFile2 }),
            React.createElement(Button_1.InvertedButton, { size: Button_1.buttonSizes.SMALL, onClick: function () { return _this.showOpenFileDlg(); } },
                " ",
                this.props.buttonText || "Upload Image",
                " ")));
    };
    return SimpleImageFileToDataUri;
}(React.Component));
exports.SimpleImageFileToDataUri = SimpleImageFileToDataUri;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=SimpleImageFileToDataUri.js.map