import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Avatar, Button, Col } from "antd";
import { BlockExplorerIcon, ProgressBar } from "../../Components/Icons";
import { ContentImage } from "../../../../Components/Image";
import { ContentPreview } from "../../../../Components/EmbedContent/ContentPreview";
import { Link } from "react-router-dom";
import { ProposalFolder } from "../../Components/Links/ProposalFolder";
import { Row } from "antd-latest";
import { UserStake } from "../../../../Components/UserWidget";
import { ViewProposalRow } from "../../Components/Previews/Standard/ViewProposalPageRow/ViewProposalRow";
import { getLocalTimeData, useGetAuthorizedActions } from "../../Utils/Helpers";
import { useAppState } from "../../../../overmind";
import { useCachedDaoProposal, useCachedPool, useCachedUser } from "../../../../hooks/useCached";
import { useEmbed } from "../../../../hooks/useEmbed";
import { useParams } from "react-router";
import isEmpty from "lodash/isEmpty";
export const ViewProposalPage = () => {
    const { daoOwner, id, proposal } = useParams();
    return _jsx(ViewProposal, { proposal: proposal, daoOwner: daoOwner, proposalId: id });
};
const ViewProposal = (props) => {
    const state = useAppState();
    const daoOwner = props.daoOwner || state.config.settings.newcoin.daoDomain;
    const proposalId = props.proposalId;
    const proposal = useCachedDaoProposal({ daoOwner, proposalId });
    const proposerObj = useCachedUser({ username: proposal.proposer });
    const daoOwnerObj = useCachedUser({ username: daoOwner });
    const timeData = getLocalTimeData(proposal);
    const { isLoading, error, embedContent } = useEmbed(proposal.url || "", "200", "350");
    const proposalSummaryArr = proposal.summary?.split("#");
    const proposalSummary = proposalSummaryArr ? proposalSummaryArr[0] : "";
    let proposalType = proposalSummaryArr && proposalSummaryArr[1];
    proposalType = proposalType == "undefined" ? "feature" : proposalType;
    const pool = useCachedPool({ owner: daoOwner });
    const proposal_type = "standart";
    const currUser = state.api.auth.user?.username || "";
    let { status_tag, action_type, vote } = useGetAuthorizedActions({
        daoOwner,
        proposalId,
        currUser,
        proposal_type,
        proposal,
    });
    if (!(Number(proposal?.id) >= 0))
        return _jsx("div", { children: "Proposal was executed or does not exist." });
    const yesVotes = Number(proposal.vote_yes?.quantity?.split(" ")[0]);
    const noVotes = Number(proposal.vote_no?.quantity?.split(" ")[0]);
    const totalVotes = yesVotes + noVotes;
    return (_jsxs(Col, { className: "u-margin-top-mega view-proposal-row-wrapper", children: [_jsx(ViewProposalRow, { daoOwner: daoOwner, proposal: proposal, wrapperClass: "u-margin-bottom-large u-dao-row-wrapper", proposalId: proposal.id, embedded: true, buttonType: false }), _jsx(Row, { align: "middle", justify: "space-between", children: _jsxs("p", { className: " u-margin-bottom-30 view-proposal-row-dao-details", children: ["Posted by", _jsxs(Link, { to: `/user/${proposal.proposer}`, className: "view-proposal-avi-ctn", children: [_jsx(Avatar, { className: "u-margin-right-medium", src: _jsx(ContentImage, { ...proposerObj }) }), _jsx("p", { className: "view-proposal-row-username", children: proposal.proposer })] }), "in the", _jsxs(Link, { to: `/user/${proposal.proposer}`, className: "view-proposal-avi-ctn", children: [_jsx(Avatar, { className: "u-margin-right-medium", src: _jsx(ContentImage, { ...daoOwnerObj }) }), _jsx("p", { className: "view-proposal-row-username", children: daoOwnerObj.username })] }), "DAO", _jsx("a", { href: "#", target: "rel_no_opener", children: _jsx(BlockExplorerIcon, {}) }), _jsx(Button, { className: `u-dao-proposal-${status_tag}-tag-status-btn`, children: _jsx("span", { children: status_tag }) }), _jsx(UserStake, { buttonText: `Get $${pool.code}`, user: { username: daoOwner }, hideButton: false })] }) }), _jsxs("p", { className: "paragraph-1b u-margin-top-large", children: [totalVotes, " votes "] }), _jsx(ProgressBar, { width: "100%", proposal: proposal }), _jsxs(Row, { align: "middle", justify: "space-between", className: "view-proposal-votes-ctn", children: [_jsxs("p", { className: "u-margin-bottom-15 paragraph-2b", children: [" ", yesVotes, " yes votes "] }), _jsxs("p", { className: "u-margin-bottom-15 paragraph-2b", children: [" ", noVotes, " no votes "] })] }), _jsxs(Col, { className: "view-proposal-summary-p", children: [_jsxs(Row, { justify: "space-between", children: [_jsxs("p", { className: "view-proposal-type-p", children: [" ", proposalType && `proposal type: ${proposalType}`] }), _jsxs("p", { className: "view-proposal-type-p", children: [timeData.time_left_seconds > 0 ? "ending" : "ended", " ", timeData.time_left_from_now, " "] })] }), _jsx(Row, { className: "u-margin-bottom-15", children: _jsxs("p", { children: [" ", proposalSummary, " "] }) }), _jsx(Row, { children: embedContent && !isEmpty(embedContent) && !isLoading && !error && (_jsx("div", { className: "view-proposal-embed-container", children: _jsx(ContentPreview, { content: embedContent }) })) }), _jsx(ProposalFolder, { proposal: proposal })] })] }));
};
export default ViewProposal;
//# sourceMappingURL=ViewProposal.js.map