function updateClearpayAmount(newTotal) {
  const clearpayPlacement = $('.clearpay > square-placement');
  if (clearpayPlacement.length) {
    clearpayPlacement.attr('data-amount', newTotal.toString());
  }
}

export function updateClearpayPlacements(newTotal) {
  const amount = newTotal.toString().replace(/[^0-9.]/g, '');
  updateClearpayAmount(parseFloat(amount));
}

function isClearpayVisible(price) {
  const priceString = price.toString().replace(/[^0-9.]/g, '')
  const priceNumber = parseFloat(priceString);
  return priceNumber >= 1 && priceNumber <= 1500;
}

export function updateClearpayVisibility(price) {
  const display = isClearpayVisible(price);
  const clearpayPlacement = $('.clearpay');

  if (clearpayPlacement.length) {
    if (display) {
      clearpayPlacement.show();
    } else {
      clearpayPlacement.hide();
    }
  }
}
