import { shopeeSetting } from '@/plugins/setting';
import { getShortLink } from '@/api/shopee/affiliate';
import { productUrl } from './render';
import i18n from '@/plugins/i18n';

export const renderContentChat = async ({ id, name }) => {
  const shopId = await shopeeSetting.shopeeShopId.getSync();
  const text = await shopeeSetting.shopeeAffContent.getSync();
  const url = productUrl(id, shopId);
  const shortLink = (await getShortLink(url)) || i18n.t('SHOPEE_AFFILIATE_INVALID');

  return text.replace(/\[PRODUCT_NAME\]/, name).replace(/\[SHORT_LINK\]/, shortLink);
};
