"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_router_dom_1 = require("react-router-dom");
const icons_1 = require("@ant-design/icons");
const antd_1 = require("antd");
const styled_components_1 = __importDefault(require("styled-components"));
const ACTIONS = __importStar(require("@/actions/system/register"));
const Logo_1 = __importDefault(require("@/components/common/Logo"));
const Container = styled_components_1.default.div `
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
`;
const FormContainer = styled_components_1.default.div `
  width: 300px;
  margin: 0 auto;
  background: rgb(255, 255, 255);
  padding: 18px;
  border: 1px solid rgb(217, 217, 217);
  border-radius: 4px;
`;
const mapStateToProps = (store) => ({
    loading: store.system.register.loading,
});
const mapDispatchToProps = {
    register: ACTIONS.register,
};
const Register = (props) => {
    const { loading, register } = props;
    const [, forceUpdate] = (0, react_1.useState)({});
    const history = (0, react_router_dom_1.useHistory)();
    const [form] = antd_1.Form.useForm();
    (0, react_1.useEffect)(() => {
        forceUpdate({});
    }, []);
    const onFinish = (values) => {
        register(Object.assign(Object.assign({}, values), { onSuccess: () => {
                antd_1.message.success('Register succeed, please login!');
                history.push('/login');
            } }));
    };
    return (react_1.default.createElement(Container, null,
        react_1.default.createElement(antd_1.Spin, { spinning: loading },
            react_1.default.createElement(FormContainer, null,
                react_1.default.createElement(antd_1.Form, { name: "normal_login", className: "login-form", form: form, initialValues: { remember: true }, onFinish: onFinish },
                    react_1.default.createElement(Logo_1.default, null),
                    react_1.default.createElement(antd_1.Form.Item, { name: "account", rules: [
                            { required: true, message: 'Please input your account!' },
                            { pattern: new RegExp('^[0-9a-zA-Z-_/@.]+$'), message: 'Please input valid account!' },
                        ] },
                        react_1.default.createElement(antd_1.Input, { prefix: react_1.default.createElement(icons_1.UserOutlined, { className: "site-form-item-icon" }), placeholder: "Account" })),
                    react_1.default.createElement(antd_1.Form.Item, { name: "email", rules: [
                            { required: true, message: 'Please input your email!' },
                            {
                                pattern: new RegExp('^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$'),
                                message: 'Please input valid email!',
                            },
                        ] },
                        react_1.default.createElement(antd_1.Input, { prefix: react_1.default.createElement(icons_1.MailOutlined, { className: "site-form-item-icon" }), placeholder: "Email" })),
                    react_1.default.createElement(antd_1.Form.Item, { name: "password", rules: [{ required: true, message: 'Please input your password!' }] },
                        react_1.default.createElement(antd_1.Input, { prefix: react_1.default.createElement(icons_1.LockOutlined, { className: "site-form-item-icon" }), type: "password", placeholder: "Password" })),
                    react_1.default.createElement(antd_1.Form.Item, null,
                        react_1.default.createElement(antd_1.Button, { type: "primary", htmlType: "submit", className: "login-form-button", style: { width: '100%' } }, "Register"),
                        react_1.default.createElement(react_router_dom_1.Link, { to: "/login" }, "login now!")))))));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(Register);
