import React from 'react';
import { DEFAULT_REFERENCE_PAYMENT_TYPE } from 'src/constants';
import {
    getAdvancePaymentDetail,
    getCustomPaymentDetail,
} from 'src/urls/frontend-royalties';
import { getValueOrEmptyChar } from 'src/utils/get-value-or-empty-char';

export interface PaymentDescriptionProps {
    paymentName: string;
    referencePaymentTypeId?: string;
    worksheetPaymentContractAdvanceId?: string;
    worksheetPaymentCustomId?: string;
}

const PaymentDescription: React.FC<PaymentDescriptionProps> = ({
    paymentName,
    referencePaymentTypeId,
    worksheetPaymentContractAdvanceId,
    worksheetPaymentCustomId,
}) => {
    if (
        referencePaymentTypeId ===
            DEFAULT_REFERENCE_PAYMENT_TYPE.referencePaymentTypeId &&
        worksheetPaymentContractAdvanceId
    ) {
        return (
            <a
                href={getAdvancePaymentDetail(
                    worksheetPaymentContractAdvanceId
                )}
            >
                {getValueOrEmptyChar(paymentName)}
            </a>
        );
    }
    if (worksheetPaymentCustomId) {
        return (
            <a href={getCustomPaymentDetail(worksheetPaymentCustomId)}>
                {getValueOrEmptyChar(paymentName)}
            </a>
        );
    }
    return <div>{getValueOrEmptyChar(paymentName)}</div>;
};

export default PaymentDescription;
