/** 推广海报页：按俱乐部分缓存二维码与背景 */
import { getClubId } from './club-context.js';
import { resolvePosterBg, refreshPosterConfig } from './miniapp-icons.js';

export function posterQrCacheKey(role) {
  const clubId = getClubId();
  return role === 'zuzhang'
    ? `zuzhang_haibao_url_${clubId}`
    : `guanshi_haibao_url_${clubId}`;
}

export function posterInviteCacheKey() {
  return `zuzhang_yaoqingma_${getClubId()}`;
}

export function getFullImageUrl(url, app) {
  app = app || getApp();
  if (!url) return '';
  const oss = app.globalData.ossImageUrl || '';
  return url.startsWith('http') ? url : oss + url;
}

export async function loadPosterPageConfig(role, app) {
  app = app || getApp();
  await refreshPosterConfig(app);
  return {
    bgUrl: resolvePosterBg(app, role),
    qrCacheKey: posterQrCacheKey(role),
  };
}
