import { LISTENERS } from '../../scripts/html/bodyScript';
import type { UNCheckPaymentComponentProps } from './UNCheckPaymentComponent';

import { PaymentMessage } from '../../messages/webMessages/paymentsMessage';

export const getCheckPaymentParams = (props: UNCheckPaymentComponentProps) => {
  const accountIdParam = props.accountId ? `account-id="${props.accountId}"` : '';
  return `
    ${accountIdParam}
    initial-stage-back-button="${props.initialStageBackButton ?? false}"
    final-stage-done-button="${props.finalStageDoneButton ?? false}"
    style="height: 100%"
  `;
};

export const getCheckPaymentScript = () => {
  return `
    window.addEventListener("${PaymentMessage.PAYMENT_CREATED}", (e) => {
      const response = e.detail
        response.then((data) => {
          postMessageToSDK({ type: "${PaymentMessage.PAYMENT_CREATED}", details:  { data: JSON.stringify(data.data) }})
        }).catch((e) => {
          console.log(e)
        })
    });

    ${LISTENERS.requestRefresh}
    ${LISTENERS.unitPaymentInitialStageBackButtonClicked}
    ${LISTENERS.unitPaymentFinalStageDoneButtonClicked}
  `;
};
