import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button } from "antd";
import { CrossCircle } from "../../../../Components/Icons/CrossCircle";
import { Modal } from "antd-latest";
import { NewcoinRecept } from "../../../../Components/Recepts";
import { ProgressButton } from "../../../../Components/ProgressButton";
import { useActions } from "../../../../overmind";
import { useState } from "react";
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", { children: [_jsx(Button, { className: "power-up-btn", onClick: () => setMode(approvalStates.start), children: "Approve" }), _jsxs(NewcoinRecept, { tx: tx, visible: mode == approvalStates.reciept, onDone: endApproving, children: [" ", _jsx("h1", { children: "Nice! " }), _jsx("p", { children: "You've approved this proposal." })] }), _jsxs(Modal, { closeIcon: _jsx(CrossCircle, {}), visible: mode == approvalStates.start, onCancel: () => setMode(approvalStates.disabled), className: "modal-ctn", footer: [], children: [_jsx("h2", { children: "Approve this proposal!" }), _jsx("p", { children: "You need to approve this proposal for DAO members to be able to vote on it!" }), _jsxs(ProgressButton, { actionName: "newcoin." + (proposal_type == "whitelist" ? "daoApproveWhitelistProposal" : "daoApproveProposal"), progressText: "Approving...", onClick: approve, className: "confirm-btn", children: [" ", "Approve"] }), _jsxs(Button, { onClick: () => setMode(approvalStates.disabled), className: "cancel-btn", children: [" ", "Cancel"] }), _jsx("p", { children: "This is only on Testnet! Need help? Join our telegram group!" })] })] }));
};
//# sourceMappingURL=ApproveModal.js.map