/**
 * 格式化时间
 * @param time dayjs 时间对象
 * @param config 时间格式配置
 * @returns 格式化后的时间字符串
 *
 * @example
 * formatTime(dayjs(), { use12Hour: false, showSeconds: false, padHour: false })
 * // => "13:45"
 *
 * formatTime(dayjs(), { use12Hour: true, showSeconds: false, padHour: true })
 * // => "01:45 PM"
 *
 * formatTime(dayjs(), { use12Hour: false, showSeconds: true, padHour: false })
 * // => "13:45:30"
 */
export function formatTime(time, config) {
  var _ref = config || {},
    _ref$use12Hour = _ref.use12Hour,
    use12Hour = _ref$use12Hour === void 0 ? false : _ref$use12Hour,
    _ref$showSeconds = _ref.showSeconds,
    showSeconds = _ref$showSeconds === void 0 ? false : _ref$showSeconds,
    _ref$padHour = _ref.padHour,
    padHour = _ref$padHour === void 0 ? false : _ref$padHour,
    _ref$onlyShowHour = _ref.onlyShowHour,
    onlyShowHour = _ref$onlyShowHour === void 0 ? false : _ref$onlyShowHour;

  // 只显示小时
  if (onlyShowHour) {
    return padHour ? time.format('HH') : time.format('H');
  }

  // 12小时制
  if (use12Hour) {
    var _hourFormat = padHour ? 'hh' : 'h';
    var _timeFormat = showSeconds ? "".concat(_hourFormat, ":mm:ss A") : "".concat(_hourFormat, ":mm A");
    return time.format(_timeFormat);
  }

  // 24小时制（默认）
  var hourFormat = padHour ? 'HH' : 'H';
  var timeFormat = showSeconds ? "".concat(hourFormat, ":mm:ss") : "".concat(hourFormat, ":mm");
  return time.format(timeFormat);
}