"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 __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
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 styled_components_1 = __importDefault(require("styled-components"));
var styleConstants_1 = require("../styleConstants");
var Button_1 = require("../Button");
var Input_1 = require("./Input");
var StyledTextInputButton = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  border: 1px solid;\n  border-color: ", ";\n  border-radius: 3px;\n  font-size: 21px;\n  padding: 26px 20px;\n  position: relative;\n\n  & > div {\n    margin: 0;\n  }\n\n  & > div > input,\n  & > div > input:focus {\n    border: none;\n    margin: 0;\n    padding: 0;\n  }\n"], ["\n  border: 1px solid;\n  border-color: ", ";\n  border-radius: 3px;\n  font-size: 21px;\n  padding: 26px 20px;\n  position: relative;\n\n  & > div {\n    margin: 0;\n  }\n\n  & > div > input,\n  & > div > input:focus {\n    border: none;\n    margin: 0;\n    padding: 0;\n  }\n"])), function (props) { return (props.isFocused ? styleConstants_1.colors.accent.CIVIL_BLUE : styleConstants_1.colors.accent.CIVIL_GRAY_3); });
var StyledIcon = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  color: ", ";\n  font-family: ", ";\n  font-size: 18px;\n  line-height: 21px;\n  position: absolute;\n  right: 40px;\n  top: calc(50% - 10px);\n"], ["\n  color: ", ";\n  font-family: ", ";\n  font-size: 18px;\n  line-height: 21px;\n  position: absolute;\n  right: 40px;\n  top: calc(50% - 10px);\n"])), styleConstants_1.colors.accent.CIVIL_GRAY_2, styleConstants_1.fonts.SANS_SERIF);
var StyledButtonContainer = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  position: absolute;\n  right: 40px;\n  top: calc(50% - 18px);\n"], ["\n  position: absolute;\n  right: 40px;\n  top: calc(50% - 18px);\n"])));
var InputContainer = /** @class */ (function (_super) {
    __extends(InputContainer, _super);
    function InputContainer(props) {
        var _this = _super.call(this, props) || this;
        _this.inputElement = undefined;
        _this.buttonElement = undefined;
        _this.handleButtonClick = function (ev) {
            if (_this.props.onButtonClick) {
                _this.props.onButtonClick(ev);
            }
            if (_this.inputElement) {
                _this.inputElement.blur();
                _this._setUnfocused();
            }
        };
        _this.setFocusState = function (isFocused) {
            _this.setState(function () { return ({ isFocused: isFocused }); });
        };
        _this.setFocused = function () { return _this.setFocusState(true); };
        _this._setUnfocused = function () { return _this.setFocusState(false); };
        _this.setUnfocused = function (ev) {
            if (ev.relatedTarget === _this.buttonElement) {
                ev.preventDefault();
            }
            else {
                _this._setUnfocused();
            }
        };
        _this.setInputRef = function (el) { return (_this.inputElement = el); };
        _this.setButtonRef = function (el) { return (_this.buttonElement = el); };
        _this.state = {
            isFocused: false,
        };
        return _this;
    }
    InputContainer.prototype.render = function () {
        return (React.createElement(StyledTextInputButton, __assign({}, this.state),
            this.props.children(this.state.isFocused, this.setFocused, this.setUnfocused, this.setInputRef),
            this.props.buttonText && this.state.isFocused && (React.createElement(StyledButtonContainer, null,
                React.createElement(Button_1.InvertedButton, { size: Button_1.buttonSizes.SMALL, onClick: this.handleButtonClick, inputRef: this.setButtonRef }, this.props.buttonText))),
            !this.state.isFocused && this.props.icon && React.createElement(StyledIcon, null, this.props.icon)));
    };
    return InputContainer;
}(React.Component));
exports.TextInputWithButton = function (props) {
    var onButtonClick = props.onButtonClick, icon = props.icon, buttonText = props.buttonText, restProps = __rest(props, ["onButtonClick", "icon", "buttonText"]);
    var inputProps = __assign(__assign({}, restProps), { noLabel: true });
    var containerProps = { onButtonClick: onButtonClick, buttonText: buttonText, icon: icon };
    return (React.createElement(InputContainer, __assign({}, containerProps), function (isFocused, setFocused, setUnfocused, setInputRef) {
        return (React.createElement(React.Fragment, null,
            React.createElement(Input_1.TextInput, __assign({}, inputProps, { onFocus: setFocused, onBlur: setUnfocused, inputRef: setInputRef }))));
    }));
};
exports.CurrencyInputWithButton = function (props) {
    var onButtonClick = props.onButtonClick, icon = props.icon, buttonText = props.buttonText, restProps = __rest(props, ["onButtonClick", "icon", "buttonText"]);
    var inputProps = __assign(__assign({}, restProps), { noLabel: true });
    var containerProps = { onButtonClick: onButtonClick, buttonText: buttonText, icon: icon };
    return (React.createElement(InputContainer, __assign({}, containerProps), function (isFocused, setFocused, setUnfocused, setInputRef) {
        return (React.createElement(React.Fragment, null,
            React.createElement(Input_1.NumericInput, __assign({}, inputProps, { onFocus: setFocused, onBlur: setUnfocused, inputRef: setInputRef }))));
    }));
};
exports.CurrencyInputWithoutButton = function (props) {
    var icon = props.icon, restProps = __rest(props, ["icon"]);
    var inputProps = __assign(__assign({}, restProps), { noLabel: true });
    var containerProps = { icon: icon };
    return (React.createElement(InputContainer, __assign({}, containerProps), function (isFocused, setFocused, setUnfocused, setInputRef) {
        return (React.createElement(React.Fragment, null,
            React.createElement(Input_1.NumericInput, __assign({}, inputProps, { onFocus: setFocused, onBlur: setUnfocused, inputRef: setInputRef }))));
    }));
};
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=InputWithButton.js.map