import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Col, Form, Input } from "antd";
import { ContentLayout } from "../../Components/ContentLayout";
import { NextButton } from "./NextButton";
import { useActions, useAppState } from "../../overmind";
import { useCallback, useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import isEmpty from "lodash/isEmpty";
export const LinkHash = () => {
    const queryString = useLocation().search;
    const actions = useActions();
    const state = useAppState();
    const [isErrorSubmit, setIsErrorSubmit] = useState(false);
    const done = () => {
        try {
            actions.flows.user.create.verifyHash({ inviteHash: state.flows.user.create.form.inviteHash || "" });
        }
        catch (e) {
            setIsErrorSubmit(true);
        }
    };
    useEffect(() => {
        const urlParams = new URLSearchParams(queryString);
        if (!isEmpty(urlParams.get("invite"))) {
            actions.flows.user.create.updateForm({ inviteHash: urlParams.get("invite") });
            done();
            actions.routing.historyPush({ location: "/signup/auth" });
        }
    }, [actions.flows.user, actions.routing, done, queryString]);
    const onChangeHandler = useCallback((e) => {
        actions.flows.user.create.updateForm({ inviteHash: e.target.value });
    }, [actions]);
    return (_jsxs(ContentLayout, { children: ["Enter your secret invite key:", _jsxs(Form, { onFinish: done, children: [_jsx(Input, { name: "hash", className: "u-margin-top-large", onChange: onChangeHandler, defaultValue: state.flows.user.create.form.inviteHash, style: { textAlign: "center" } }), _jsx(Col, { className: "u-margin-top-large", children: _jsx(NextButton, { isErrorSubmit: isErrorSubmit, nextProps: { text: "Next", command: () => done() }, visible: !isEmpty(state.flows.user.create.form.inviteHash) }) })] })] }));
};
//# sourceMappingURL=LinkHash.js.map