"use client"
import { useIntl } from "react-intl"

import { formatPrice } from "@/utils/numberFormatting"

import RegularRow from "./Regular"

import type { Price } from "@/types/components/hotelReservation/price"
import { CurrencyEnum } from "@/types/enums/currency"

interface VatProps {
  totalPrice: Price
  vat: number
}

const noVatCurrencies = [
  CurrencyEnum.CC,
  CurrencyEnum.POINTS,
  CurrencyEnum.Voucher,
  CurrencyEnum.Unknown,
]

export default function VatRow({ totalPrice, vat }: VatProps) {
  const intl = useIntl()

  if (noVatCurrencies.includes(totalPrice.local.currency)) {
    return null
  }

  const vatPercentage = vat / 100
  const vatAmount = totalPrice.local.price * vatPercentage

  const priceExclVat = totalPrice.local.price - vatAmount

  return (
    <>
      <RegularRow
        label={intl.formatMessage({ defaultMessage: "Price excluding VAT" })}
        value={formatPrice(intl, priceExclVat, totalPrice.local.currency)}
      />
      <RegularRow
        label={intl.formatMessage({ defaultMessage: "VAT {vat}%" }, { vat })}
        value={formatPrice(intl, vatAmount, totalPrice.local.currency)}
      />
    </>
  )
}
