import React, { useMemo } from "react";
import { DemographicsTextCard } from "@local-logic/core/ui";
import useTranslator from "~/hooks/useTranslator";
import { translations as demographicsTranslations } from "~/localization/translation-packs/demographics";
import { OwnersRentersCardProps } from "./types";

export const OwnersRentersCard: React.FC<OwnersRentersCardProps> = ({
  options: { datasets },
}) => {
  const { translations } = useTranslator([demographicsTranslations]);

  const chartOptions = useMemo(
    () => ({
      options: {
        title: translations.ownersRentersTitle,
        values: datasets.map((item) => ({
          variable: item.label.replace(" ", "_"),
          label: item.label,
          value: `${item.data}%`,
        })),
      },
    }),
    [datasets]
  );

  return <DemographicsTextCard {...chartOptions} />;
};
