import React, { useMemo } from 'react';
import classNames from 'classnames';
import dayjs from 'dayjs';
import usePisellConfig from "../../../pisell-config-provider/hooks/usePisellConfig";
import "./ReadPretty.less";
var DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm:ss';
var DATE_FORMATS = {
  'zh-CN': {
    withTime: 'YYYY-MM-DD HH:mm:ss',
    withoutTime: 'YYYY-MM-DD'
  },
  'en-US': {
    withTime: 'HH:mm:ss YYYY-MM-DD',
    withoutTime: 'YYYY-MM-DD'
  }
};
var DatePickerReadPretty = function DatePickerReadPretty(_ref) {
  var value = _ref.value,
    renderMode = _ref.renderMode,
    showTime = _ref.showTime;
  var _usePisellConfig = usePisellConfig(),
    _usePisellConfig$loca = _usePisellConfig.locale,
    locale = _usePisellConfig$loca === void 0 ? 'zh-CN' : _usePisellConfig$loca;
  var dateFormat = useMemo(function () {
    if (locale in DATE_FORMATS) {
      var formats = DATE_FORMATS[locale];
      return showTime ? formats.withTime : formats.withoutTime;
    }
    if (process.env.NODE_ENV !== 'production') {
      console.warn("Unsupported locale: ".concat(locale, ", falling back to default format"));
    }
    return DEFAULT_FORMAT;
  }, [locale, showTime]);
  var formattedDate = useMemo(function () {
    if (!value) return '';
    try {
      return dayjs(value).format(dateFormat);
    } catch (error) {
      if (process.env.NODE_ENV !== 'production') {
        console.error('Error formatting date:', error);
      }
      return '';
    }
  }, [value, dateFormat]);
  return /*#__PURE__*/React.createElement("span", {
    className: classNames('pisell-date-picker-read-pretty', {
      'pisell-date-picker-read-pretty-table-view': renderMode === 'tableView'
    })
  }, formattedDate);
};
export default DatePickerReadPretty;