import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { Row, Button, Col } from "antd";
import ArrowDown from '../../Components/Icons/ArrowDown';
import ListToggle from '../../Components/Icons/ListToggle';
import { Burger } from '../../Components/Icons/Burger';
import { Link, useParams } from "react-router-dom";
import { useAppState } from "../../overmind";
import { useState, useEffect } from "react";
import { useCachedDaoProposals } from "../../hooks/useCached";
import { convertDaoProposalsForUI } from "./Utils/Helpers";
import { ProposalRow, ProposalCard } from "./Components/UI-Elements";
export const ProposalsPage = () => {
    const { daoOwner, id } = useParams();
    return _jsx(Proposals, { daoOwner: daoOwner });
};
const Proposals = (props) => {
    const state = useAppState();
    const daoOwner = props.daoOwner || state.config.settings.newcoin.daoDomain;
    const daoProposals = useCachedDaoProposals({ daoOwner });
    const ownDao = state.api.auth.user?.username === daoOwner;
    const [toggleView, setToggleView] = useState(false);
    const [proposals, setProposals] = useState([]);
    const Toggle = () => setToggleView(!toggleView);
    const ProcessDaoProposalsForUi = async () => {
        if (daoProposals.rows?.length) {
            setProposals(convertDaoProposalsForUI(daoProposals.rows));
            // } else {
            // 	setProposals( createSeedProposalsForUI() );
        }
    };
    useEffect(() => { ProcessDaoProposalsForUi(); }, []);
    if (daoProposals.dao_id) {
        return _jsx(_Fragment, { children: ownDao ?
                _jsxs(_Fragment, { children: ["You have not created your DAO yet. Creating a DAO is easy:\u00A0", _jsx(Link, { to: "/dao/create", children: "click here to start" })] }) :
                _jsxs(_Fragment, { children: ["User ", daoOwner, " had not created their dao yet."] }) });
    }
    return _jsxs(Col, { className: "u-dao-page-wrapper", children: [_jsxs(Row, { className: "u-dao-menu-wrapper", justify: "space-between", children: [_jsxs(Row, { align: "middle", children: [_jsx("h2", { className: "proposal-list-menu-community-history-h2", children: "Community history" }), _jsxs(Row, { className: "proposal-list-menu-sort-ctn", children: [_jsx("p", { className: "proposal-list-menu-sort-p", children: "Sort by" }), _jsx(ArrowDown, {})] }), _jsx(Row, { onClick: Toggle, children: toggleView ? _jsx(Burger, {}) : _jsx(ListToggle, {}) })] }), _jsx(Button, { type: "primary", children: _jsx(Link, { to: "/newlife-dao/new-proposal", children: "New Proposal" }) })] }), _jsx(Col, { className: "u-dao-view-toggle-wrapper", children: !toggleView
                    ? (proposals || []).map(proposal => _jsx(ProposalRow, { daoOwner: daoOwner, proposal: proposal, buttonType: "View", wrapperClass: "proposal-list-row-wrapper app-main-full-width" }))
                    : _jsx(Row, { justify: "space-between", children: (proposals || []).map(proposal => _jsx(ProposalCard, { proposal: proposal })) }) })] });
};
export default Proposals;
//# sourceMappingURL=ProposalList.js.map