/** 与消息页「联系客服」一致：跳转客服会话 */
export function openCustomerServiceChat() {
  const app = getApp();
  if (app.globalData.chatEnabled && app.ensureConnection) {
    app.globalData.goEasyConnection.autoReconnect = true;
    app.ensureConnection();
  }
  const param = { teamId: 'support_team' };
  wx.navigateTo({
    url: '/pages/cs-chat/cs-chat?data=' + encodeURIComponent(JSON.stringify(param)),
  });
}

/** 与打手「我的」页在线客服同一图标：beijing/tubiao/grzx_kefu.jpg */
export function resolveKefuIconUrl(app) {
  app = app || getApp();
  const rel = 'beijing/tubiao/grzx_kefu.jpg';
  let base = (app.globalData && app.globalData.ossImageUrl) || '';
  if (!base && typeof app.readConfigFromStorage === 'function') {
    try {
      const cached = app.readConfigFromStorage();
      base = (cached && cached.cos && cached.cos.ossImageUrl) || '';
    } catch (e) {}
  }
  if (!base) return '';
  return base.endsWith('/') ? base + rel : base + rel;
}
