// 超过?000的数字转换为?k+，超过?0000的数字转换为?w+，超过?00000的数字转换为?kw+，以此类推
export function formatNumber(numb: string | number) {
  const num = Number(numb)
  if (num < 1000)
    return num
  if (num < 10000)
    return `${Math.floor(num / 1000)}k+`
  if (num < 100000)
    return `${Math.floor(num / 10000)}w+`
  return `${Math.floor(num / 100000)}kw+`
}
export function getFullPath(unpath: string) {
  const prefix = window.GLOBAL_CONFIG.oss
  const path = unpath?.split('|')[0]
  if (path?.startsWith('http'))
    return path
  else
    return prefix + path
}

export const TypeMap: {
  [key: string]: any
} = {
  mszy_zj: {
    name: '名师资源/春季课程/基础课程',
    idx: 1,
    pid: 'tmk_id',
    id: 'tmz_id',
    title: 'tmz_zjmc',
    img: 'tmz_img_url',
    video: 'tmz_video_url',
    lll: 'tmk_lll',
    dzl: 'tmz_dzl',
    teacher: 'teacher_name',
    school: 'school_name',
  },
  tskc_zj: {
    name: '特色课程',
    idx: 2,
    pid: 'ttk_id',
    id: 'ttz_id',
    title: 'ttz_mc',
    img: 'ttz_img',
    video: 'ttz_video_file',
    lll: 'ttz_lll',
    dzl: 'ttz_dzl',
    teacher: 'teacher_name',
    school: 'school_name',
  },
  zbkc_ks: {
    name: '直播课程',
    idx: 3,
    pid: 'tz_id',
    id: 'tzk_id',
    title: 'tzk_ksmc',
    img: 'tzk_img',
    video: 'pull_m3u8_address',
    lll: 'tzk_lll',
    dzl: 'tzk_dzl',
    teacher: 'tzk_xm',
    school: 'tzk_ssdw',
  },
  zyfd: {
    name: '作业辅导',
    idx: 4,
    pid: ['tjzn_id', 'tjzx_id'],
    id: 'tz_id',
    title: 'tz_mc',
    img: 'tz_img',
    video: 'tz_video_file',
    lll: 'tz_lll',
    dzl: 'tz_dzl',
    teacher: 'tz_zjyhmc',
    school: null,
  },
  jtjy_zj: {
    name: '家庭教育',
    idx: 5,
    pid: 'tjk_id',
    id: 'tjz_id',
    title: 'tjz_mc',
    img: 'tjz_img',
    video: 'tjz_video_file',
    lll: 'tjz_lll',
    dzl: 'tjz_dzl',
    teacher: 'teacher_name',
    school: 'school_name',
  },
  // xkzy_zj: {
  //   name: '学科资源',
  //   idx: 6,
  // },
}

// 正则表达式匹配
// 'LiteLiveClass://push_screen://rtmp://push.txhlwxx.com/swh/24' to 'rtmp://push.txhlwxx.com/swh/24'
export function splitRtmpPath(path: string) {
  const reg = /rtmp:\/\/.*\/.*\/.*$/
  const res = path.match(reg)
  return res?.[0] ?? null
}
