import { isChinese as checkIsChinese } from "./localeUtils";

/**
 * 格式化星期
 * @param weekday dayjs 日期对象
 * @param config 星期格式配置
 * @returns 格式化后的星期字符串
 *
 * @example
 * // 英文环境
 * formatWeekday(dayjs(), { full: false, singleLetter: false })
 * // => "Sat"
 *
 * formatWeekday(dayjs(), { full: true })
 * // => "Saturday"
 *
 * formatWeekday(dayjs(), { singleLetter: true })
 * // => "S"
 *
 * // 中文环境
 * formatWeekday(dayjs(), { full: false, singleLetter: false })
 * // => "周六"
 *
 * formatWeekday(dayjs(), { full: true })
 * // => "星期六"
 *
 * formatWeekday(dayjs(), { singleLetter: true })
 * // => "六"
 */
export function formatWeekday(weekday, config) {
  var _ref = config || {},
    _ref$full = _ref.full,
    full = _ref$full === void 0 ? false : _ref$full,
    _ref$singleLetter = _ref.singleLetter,
    singleLetter = _ref$singleLetter === void 0 ? false : _ref$singleLetter,
    _ref$trailingComma = _ref.trailingComma,
    trailingComma = _ref$trailingComma === void 0 ? false : _ref$trailingComma;

  // 判断是否为中文环境
  var locale = weekday.locale();
  var isChinese = checkIsChinese(locale);
  var appendComma = function appendComma(s) {
    return trailingComma ? isChinese ? "".concat(s, "\uFF0C") : "".concat(s, ",") : s;
  };

  // 单字母展示
  if (singleLetter) {
    if (isChinese) {
      var weekdayMap = ['日', '一', '二', '三', '四', '五', '六'];
      return appendComma(weekdayMap[weekday.day()]);
    }
    return appendComma(weekday.format('dd').charAt(0));
  }

  // 完整展示
  if (full) {
    return appendComma(weekday.format('dddd'));
  }

  // 默认（缩写）ddd: 周一 / Mon
  return appendComma(weekday.format('ddd'));
}