import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Col, DatePicker, Form, Input, Row, Select } from "antd-latest";
import { ContentLayout } from "../../../../Components/ContentLayout";
import { NewcoinRecept } from "../../../../Components/Recepts";
import { ProgressButton } from "../../../../Components/ProgressButton";
import { RowCheckbox } from "../../../../Components/RowCheckbox";
import { useActions } from "../../../../overmind";
import { useEffect, useState } from "react";
import { useForm } from "antd-latest/lib/form/Form";
import { useParams } from "react-router-dom";
import moment from "moment";
const { RangePicker } = DatePicker;
const NewProposal = () => {
    const [form] = useForm();
    const actions = useActions();
    const { daoOwner } = useParams();
    const proposalType = Form.useWatch("proposal_type", form);
    const [showWhitelist, setShowWhitelist] = useState(false);
    const whitelistSelection = Form.useWatch("whitelist_selection", form);
    const [tx, setTx] = useState("");
    const [proposalCreated, setProposalCreated] = useState(false);
    const whiteListProposalCreate = async (val) => {
        // const voteStart = moment(val.vote_dates[0]);
        const voteEnd = moment(val.vote_dates[1]);
        const res = await actions.newcoin.daoCreateWhitelistProposal({
            ...val,
            vote_start: moment().add("2", "minutes").utc().format("YYYY-MM-DDTHH:mm:ss"),
            vote_end: voteEnd.utc().format("YYYY-MM-DDTHH:mm:ss"),
            dao_owner: daoOwner,
            user: whitelistSelection,
        });
        const success = !!res.TxID_createDaoProposal;
        if (success) {
            setTx(res["TxID_createDaoProposal"]);
            setProposalCreated(true);
        }
    };
    const proposalCreate = async (val) => {
        const voteStart = moment(val.vote_dates[0]);
        const voteEnd = moment(val.vote_dates[1]);
        const res = await actions.newcoin.daoCreateProposal({
            ...val,
            summary: val.summary + "#" + proposalType,
            vote_start: voteStart.add(1, "minutes").utc().format("YYYY-MM-DDTHH:mm:ss"),
            vote_end: voteEnd.utc().format("YYYY-MM-DDTHH:mm:ss"),
            dao_owner: daoOwner,
        });
        const success = !!res.TxID_createDaoProposal;
        if (success) {
            setTx(res["TxID_createDaoProposal"]);
            setProposalCreated(true);
        }
    };
    const changeFormView = () => {
        if (proposalType == "whitelist") {
            setShowWhitelist(true);
        }
        else
            setShowWhitelist(false);
    };
    useEffect(() => changeFormView(), [proposalType]);
    return (_jsxs(ContentLayout, { children: [_jsxs(Form, { name: "new-proposal-form", form: form, onFinish: proposalType == "whitelist" ? whiteListProposalCreate : proposalCreate, wrapperCol: { span: 24 }, autoComplete: "off", initialValues: {
                    vote_start: moment().add(2, "minute").seconds(0),
                    vote_end: moment().add(5, "minute").seconds(0),
                }, children: [moment().add(1, "day").seconds(0).toISOString().replace(/\..+$/, ""), _jsx("p", { className: "super-size font-variant-none", style: { marginBottom: "40px" }, children: !showWhitelist ? "new proposal" : "new member" }), showWhitelist && _jsx(Form.Item, { name: "title", children: "New Member Proposal" }), !showWhitelist && (_jsx(Form.Item, { name: "title", rules: [{ required: true }], children: _jsx(Input, { placeholder: "title" }) })), _jsx(Form.Item, { name: "proposal_type", rules: [{ required: true }], children: _jsxs(Select, { bordered: false, className: "new-proposal-type-dropdown", placeholder: "topic", children: [_jsx(Select.Option, { value: "whitelist", children: "new members" }), _jsx(Select.Option, { value: "feature", children: "feature request" }), _jsx(Select.Option, { value: "improvement", children: "org improvement" }), _jsx(Select.Option, { value: "other", children: "other" })] }) }), showWhitelist && (_jsx(Form.Item, { name: "whitelist_selection", rules: [{ required: true }], children: _jsx(Input, { placeholder: "username of new member" }) })), _jsx(Row, { children: _jsx(Form.Item, { name: "vote_dates", rules: [{ required: true }], children: _jsx(RangePicker, { ranges: {
                                    "One Week": [moment(), moment().endOf("week")],
                                    "One Month": [moment(), moment().endOf("month")],
                                }, format: "YYYY-MM-DD-HH:mm", disabled: [true, false] }) }) }), !showWhitelist && (_jsx(Form.Item, { name: "summary", rules: [
                            {
                                required: true,
                            },
                        ], children: _jsx(Input.TextArea, { placeholder: "Explain your proposal to the community!" }) })), !showWhitelist && (_jsx(Form.Item, { name: "url", label: "", rules: [{ required: true }], children: _jsx(Input, { placeholder: "link" }) })), _jsx(Form.Item, { name: "dao-check", valuePropName: "checked", rules: [{ required: true }], wrapperCol: { offset: 0, span: 24 }, children: _jsx(RowCheckbox, { children: _jsx("p", { className: "paragraph-2r", style: {}, children: "I am fostering community health with my proposal" }) }) }), _jsx(Row, { justify: "center", children: _jsx(ProgressButton, { actionName: proposalType == "whitelist" ? "newcoin.daoCreateWhitelistProposal" : "newcoin.daoCreateProposal", type: "primary", progressText: "Sharing...", htmlType: "submit", children: "Share Proposal" }) }), _jsxs(NewcoinRecept, { tx: tx, visible: proposalCreated, onDone: () => actions.routing.historyPush({ location: `/dao/${daoOwner}/proposals` }), children: [_jsx("h1", { className: "view-proposal-vote-h1", children: "Congratulations! " }), _jsxs("p", { className: "view-proposal-vote-p", children: ["You Created a proposal and shared it to the ", daoOwner, " DAO!"] })] })] }), _jsxs(Col, { className: "u-margin-top-large new-proposal-note", children: [_jsx(Row, { justify: "center", children: _jsxs("p", { children: [" ", "Note: A fee of 1000 NCO tokens is charged by the smart contract. Fees will be returned to the user once the proposal receives 2% votes out of total supply."] }) }), _jsx(Row, { className: "u-margin-top-large", justify: "center", children: _jsx("p", { children: "learn more here" }) })] })] }));
};
export default NewProposal;
//# sourceMappingURL=NewProposal.js.map