import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button } from "antd";
import { useActions } from "../../../../overmind";
import { CrossCircle } from "../../../../Components/Icons/CrossCircle";
import { Modal } from "antd-latest";
import { useState } from "react";
import { ProgressButton } from "../../../../Components/ProgressButton";
import { NewcoinRecept } from "../../../../Components/Recepts";
export const ApproveModal = ({ proposal_type, dao_owner, proposal_id }) => {
    const approvalStates = {
        "disabled": 0,
        "start": 1,
        "reciept": 2,
        "end": 3
    };
    const actions = useActions();
    const [mode, setMode] = useState(approvalStates.disabled);
    const [tx, setTx] = useState("");
    const approve = async () => {
        const res = proposal_type == "whitelist"
            ? await actions.newcoin.daoApproveWhitelistProposal({ dao_owner, proposal_id })
            : await actions.newcoin.daoApproveProposal({
                dao_owner, proposal_id,
            });
        const success = !!res.TxID_approveDaoProposal;
        if (success) {
            setTx(res.TxID_approveDaoProposal);
            setMode(approvalStates.reciept);
        }
    };
    const endApproving = async () => {
        setMode(approvalStates.disabled);
        proposal_type == "whitelist"
            ? await actions.newcoin.daoGetWhitelistProposals({ daoOwner: dao_owner, proposal_id: proposal_id })
            : await actions.newcoin.daoGetProposals({ daoOwner: dao_owner, proposal_id: proposal_id });
    };
    return _jsxs("div", { style: { color: "white" }, children: [_jsx(Button, { className: "u-dao-view-btn", onClick: () => setMode(approvalStates.start), children: "Approve" }), _jsxs(NewcoinRecept, { tx: tx, visible: mode == approvalStates.reciept, onDone: endApproving, children: [" ", _jsx("h1", { className: "view-proposal-vote-h1", children: "Nice! " }), _jsx("p", { className: "view-proposal-vote-p", children: "You've approved this proposal." })] }), _jsxs(Modal, { closeIcon: _jsx(CrossCircle, {}), visible: mode == approvalStates.start, onCancel: () => setMode(approvalStates.disabled), className: "nl-white-box-modal view-proposal-vote-ctn", footer: [], children: [_jsx("p", { children: "This proposal is ready to approve" }), _jsx("p", { children: "You are the owner of this dao. Please approve to activate the proposal." }), _jsx(ProgressButton, { actionName: "newcoin." + (proposal_type == "whitelist" ? "daoApproveWhitelistProposal" : "daoApproveProposal"), progressText: "Approving...", type: "primary", onClick: approve, children: "Approve" })] })] });
};
//# sourceMappingURL=ApproveModal.js.map