"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
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 });
/* @flow */
const react_1 = __importStar(require("react"));
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
class NewsLetterSubScription extends react_1.Component {
    constructor() {
        super(...arguments);
        this.state = {
            isSignUp: false,
            isSusScribed: false,
            emailAddress: '',
            msg: 'You have been added to our mailing list',
        };
        this.subScribe = () => __awaiter(this, void 0, void 0, function* () {
            const { emailAddress } = this.state;
            const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            if (regex.test(emailAddress)) {
                const variables = {
                    emailAddress: emailAddress,
                };
                if (mixpanel) {
                    mixpanel.track('Subscribe', Object.assign({}, variables));
                }
            }
        });
        this.onChangeEmail = event => {
            this.setState({ emailAddress: event.target.value });
        };
    }
    render() {
        const { isSignUp, isSusScribed, msg } = this.state;
        return (react_1.default.createElement(ErrorBoundary_1.default, null,
            react_1.default.createElement("section", { className: "signup_bg" },
                react_1.default.createElement("div", { className: "container" },
                    react_1.default.createElement("div", { className: "signup clearfix" },
                        react_1.default.createElement("div", { className: "heading" },
                            react_1.default.createElement("h3", null, "STAY CONNECTED")),
                        react_1.default.createElement("div", { className: "left_signup clearfix" },
                            react_1.default.createElement("div", { className: "left_thumnail" },
                                react_1.default.createElement("img", { src: require('images/mail-icon@3x.png') })),
                            !isSignUp ? (react_1.default.createElement("div", { className: "desc" },
                                react_1.default.createElement("p", null, "Sign up to the Kudoo newsletter and stay up to date with the latest news and product releases."))) : (react_1.default.createElement("div", { className: "desc" },
                                !isSusScribed && (react_1.default.createElement("input", { type: "text", onChange: this.onChangeEmail, className: "form-control newslettersubscripe", placeholder: "Email ...." })),
                                isSusScribed && react_1.default.createElement("p", null, msg)))),
                        react_1.default.createElement("div", { className: "right_signup" }, !isSignUp ? (react_1.default.createElement("a", { className: "btn signup_btn", onClick: () => this.setState({ isSignUp: true }) }, "Sign me up")) : (!isSusScribed && (react_1.default.createElement("a", { className: "btn signup_btn", onClick: this.subScribe }, "Send")))))))));
    }
}
exports.default = NewsLetterSubScription;
//# sourceMappingURL=index.js.map