import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import * as styles from "../styles";
import { ChangeIndicator } from "~/sdks/NeighborhoodMarketTrends/components/ChangeIndicator";
import { InfoPopover } from "~/sdks/NeighborhoodMarketTrends/components/InfoPopover";
import { useNeighborhoodMarketTrends } from "~/sdks/NeighborhoodMarketTrends/context";
import * as Graphs from "~/sdks/NeighborhoodMarketTrends/components/Graphs";
export const HomesSold = () => {
    const { t } = useTranslation("neighborhoodMarketTrends");
    const { marketActivity, appearance } = useNeighborhoodMarketTrends();
    const homesSold = useMemo(() => {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j;
        if (!marketActivity) {
            return null;
        }
        return {
            current: (_d = (_c = (_b = (_a = marketActivity.market_activity_by_property_type) === null || _a === void 0 ? void 0 : _a.all_residential_properties.intervals["12m"]) === null || _b === void 0 ? void 0 : _b.market_activity) === null || _c === void 0 ? void 0 : _c.stats_over_period) === null || _d === void 0 ? void 0 : _d.sold_homes_count,
            previous: (_j = (_h = (_g = (_f = (_e = marketActivity.market_activity_by_property_type) === null || _e === void 0 ? void 0 : _e.all_residential_properties) === null || _f === void 0 ? void 0 : _f.intervals["13-24m"]) === null || _g === void 0 ? void 0 : _g.market_activity) === null || _h === void 0 ? void 0 : _h.stats_over_period) === null || _j === void 0 ? void 0 : _j.sold_homes_count,
        };
    }, [marketActivity]);
    const yearlyChange = useMemo(() => {
        if (!homesSold || !homesSold.current || !homesSold.previous) {
            return null;
        }
        return (homesSold.current - homesSold.previous) / homesSold.previous;
    }, [homesSold]);
    if (!homesSold) {
        return null;
    }
    return (React.createElement("div", { className: styles.container },
        React.createElement("div", { className: styles.summary },
            React.createElement("div", null,
                React.createElement("div", { className: styles.header },
                    React.createElement("h3", { className: styles.title },
                        t("graphs.homesSold.title"),
                        React.createElement(InfoPopover, { change: yearlyChange }, t("graphs.homesSold.disclaimer"))),
                    React.createElement("h4", { className: styles.amount }, homesSold.current))),
            React.createElement(ChangeIndicator, { yearlyChange: yearlyChange, fieldTitle: t("graphs.homesSold.title"), disclaimer: t("graphs.homesSold.changeDisclaimer") })),
        React.createElement(Graphs.Root, { colors: appearance === null || appearance === void 0 ? void 0 : appearance.colors },
            React.createElement(Graphs.HomesSold, { isIncrease: !yearlyChange || yearlyChange >= 0 }))));
};
//# sourceMappingURL=index.js.map