import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import * as styles from "../styles";
import { ChangeIndicator } from "~/sdks/NeighborhoodMarketTrends/components/ChangeIndicator";
import { useNeighborhoodMarketTrends } from "~/sdks/NeighborhoodMarketTrends/context";
import * as Graphs from "~/sdks/NeighborhoodMarketTrends/components/Graphs";
export const ActiveListings = () => {
    const { t } = useTranslation("neighborhoodMarketTrends");
    const { marketActivity, appearance } = useNeighborhoodMarketTrends();
    const activeListingsCount = 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["30d"]) === null || _b === void 0 ? void 0 : _b.market_activity) === null || _c === void 0 ? void 0 : _c.stats_at_period_end) === null || _d === void 0 ? void 0 : _d.active_listings_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["31-60d"]) === null || _g === void 0 ? void 0 : _g.market_activity) === null || _h === void 0 ? void 0 : _h.stats_at_period_end) === null || _j === void 0 ? void 0 : _j.active_listings_count,
        };
    }, [marketActivity]);
    const monthlyChange = useMemo(() => {
        if (!activeListingsCount || activeListingsCount.previous === 0) {
            return 0;
        }
        return ((activeListingsCount.current - activeListingsCount.previous) /
            activeListingsCount.previous);
    }, [activeListingsCount]);
    if (!activeListingsCount) {
        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.activeListings.title")),
                    React.createElement("h4", { className: styles.amount }, activeListingsCount.current))),
            React.createElement(ChangeIndicator, { yearlyChange: monthlyChange, fieldTitle: t("graphs.activeListings.title") })),
        React.createElement(Graphs.Root, { colors: appearance === null || appearance === void 0 ? void 0 : appearance.colors },
            React.createElement(Graphs.ActiveListings, { yAxisTitle: t("graphs.activeListings.yAxisTitle"), isIncrease: monthlyChange >= 0 }))));
};
//# sourceMappingURL=index.js.map