import React from "react";
import { useTranslation } from "react-i18next";
import { useAppSelector } from "redux/hooks";
import ProText from "../ProText";

interface ArabicPriceProps {
  price: number | string;
  style?: React.CSSProperties;
  strong?: boolean;
  type?: "secondary" | "success" | "warning" | "danger";
  className?: string;
  hideCurrency?: boolean;
}

const ArabicPrice: React.FC<ArabicPriceProps> = ({
  price,
  style = {},
  strong = false,
  type,
  className,
  hideCurrency = false,
}) => {
  const { t } = useTranslation();
  const { isRTL } = useAppSelector((state) => state.locale);

  // Format the price to ensure it has 2 decimal places
  const formattedPrice = typeof price === "number" ? price.toFixed(2) : price;

  return (
    <ProText
      strong={strong}
      type={type}
      className={className}
      style={{
        display: "inline-flex",
        alignItems: "baseline",
        gap: "0.2em",
        lineHeight: 1,
        ...style,
      }}
    >
      {isRTL && !hideCurrency ? (
        <>
          <span
            style={{
              verticalAlign: "baseline",
              lineHeight: 1,
            }}
          >
            {formattedPrice}
          </span>
          <span
            style={{
              fontSize: "0.9em",
              verticalAlign: "baseline",
              lineHeight: 1,
              position: "relative",
              top: -3,
            }}
          >
            {t("common.omanCurrency")}
          </span>
        </>
      ) : !hideCurrency ? (
        <>
          <span
            style={{
              verticalAlign: "baseline",
              lineHeight: 1,
              display: "inline-block",
            }}
          >
            {formattedPrice}
          </span>
          <span
            style={{
              fontSize: "0.9em",
              verticalAlign: "baseline",
              lineHeight: 1,
              display: "inline-block",
            }}
          >
            {t("common.omanCurrency")}
          </span>
        </>
      ) : (
        <>{formattedPrice}</>
      )}
    </ProText>
  );
};

export default ArabicPrice;
