import { Base64 } from 'js-base64'

export function getOnlinePreviewUrl(url: string) {
  return import.meta.env.MODE === 'school'
    ? `${import.meta.env.VITE_FILE_PREVIEW_URL}/onlinePreview?url=${encodeURIComponent(Base64.encode(url))}`
    : `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(url)}`
}

/**
 * 分割字符串，取得尾部
 * @param {string} str 字符串
 * @param {string} split 分割符
 * @returns {string}
 */
export function splitStrLast(str: any, split: any) {
  const fileNameArr = str.split(split)
  const last = fileNameArr[fileNameArr.length - 1]
  return last
}
