

import { observer } from "mobx-react";
// buzzwareTech imports
import { useTranslation } from "@buzzwaretech/i18n";
import { CalendarLayoutIcon } from "@buzzwaretech/propel/icons";
import { cn, getDate, renderFormattedDate } from "@buzzwaretech/utils";

export type TReadonlyDateProps = {
  className?: string;
  hideIcon?: boolean;
  value: Date | string | null;
  placeholder?: string;
  formatToken?: string;
};

export const ReadonlyDate = observer(function ReadonlyDate(
  props: TReadonlyDateProps,
) {
  const {
    className,
    hideIcon = false,
    value,
    placeholder,
    formatToken,
  } = props;

  const { t } = useTranslation();
  const formattedDate = value
    ? renderFormattedDate(getDate(value), formatToken)
    : null;

  return (
    <div className={cn("flex items-center gap-1 text-13", className)}>
      {!hideIcon && <CalendarLayoutIcon className="size-4 flex-shrink-0" />}
      <span className="flex-grow truncate">
        {formattedDate ?? placeholder ?? t("common.none")}
      </span>
    </div>
  );
});
