import { auth } from "@renderer/util/firebase";
import { Card, Typography } from "antd";
import { JSX, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import ipcTypes from "../../../../util/ipcTypes.json";
import _ from "lodash";
const Welcome = (): JSX.Element => {
  const { t } = useTranslation();
  const [shopName, setShopName] = useState<string | null>(null);
  useEffect(() => {
    window.electron.ipcRenderer
      .invoke(ipcTypes.toMain.user.getActiveShop)
      .then((shopName: string) => {
        console.log("Active shop name:", shopName);
        setShopName(shopName);
      });
  }, []);

  return (
    <>
      <Typography.Title level={4}>
        {t("auth.labels.welcome", {
          name: _.isEmpty(auth.currentUser?.displayName)
            ? auth.currentUser?.email
            : `${auth.currentUser?.displayName} (${auth.currentUser?.email})`.trim(),
        })}
      </Typography.Title>
      <Typography.Paragraph>{shopName || ""}</Typography.Paragraph>
    </>
  );
};

export default Welcome;
