import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { Button } from "antd";
import { CrossCircle } from "../../../../Components/Icons/CrossCircle";
import { Modal } from "antd-latest";
import { useActions } from "../../../../overmind";
import { useState } from "react";
export const BulkActionModal = ({ proposals, showProposalType, daoId, actionType, dao_owner }) => {
    const bulkActionStates = {
        disabled: 0,
        start: 1,
        end: 2,
    };
    const actions = useActions();
    const [mode, setMode] = useState(bulkActionStates.start);
    const dao_Id = daoId;
    const approveAll = async () => {
        if (showProposalType == "members" || !proposals.length) {
            return;
        }
        proposals.map(async (proposal) => {
            const proposalId = proposal.id;
            const proposalAuthor = proposal.proposer;
            showProposalType == "whitelist"
                ? await actions.newcoin.daoApproveWhitelistProposal({ dao_owner: proposalAuthor, proposal_id: proposalId })
                : await actions.newcoin.daoApproveProposal({
                    dao_owner: proposalAuthor,
                    proposal_id: proposalId,
                });
        });
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    };
    const executeAll = async () => {
        setTimeout(() => { }, 1000);
        if (showProposalType == "members" || !proposals.length) {
            return;
        }
        proposals.map(async (proposal) => {
            const proposalId = proposal.id;
            const proposalAuthor = proposal.proposer;
            const daoId = dao_Id || "";
            showProposalType == "whitelist"
                ? await actions.newcoin.daoExecuteWhitelistProposal({
                    dao_id: daoId,
                    proposal_id: proposalId,
                    proposal_author: proposalAuthor,
                })
                : await actions.newcoin.daoExecuteProposal({
                    dao_id: daoId,
                    proposal_id: proposalId,
                    proposal_author: proposalAuthor,
                    dao_owner: proposalAuthor,
                });
        });
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    };
    return (_jsxs(Modal, { visible: mode == bulkActionStates.start, closeIcon: _jsx(CrossCircle, {}), onCancel: () => window.location.reload(), className: "modal-ctn", footer: [], children: [_jsxs("h2", { children: ["Are you sure you want to ", actionType, " ", proposals.length, " proposals?", " "] }), _jsxs(Button, { onClick: actionType == "approve" ? approveAll : executeAll, className: "confirm-btn", children: [actionType, " ", proposals.length, " proposals"] }), _jsxs(Button, { onClick: () => window.location.reload(), className: "cancel-btn", children: [" ", "Cancel bulk action"] }), _jsx("p", { children: "This is only on Testnet! Need help? Join our telegram group!" })] }));
};
//# sourceMappingURL=BulkActionModal.js.map