import usePisellConfig from "../../../pisell-config-provider/hooks/usePisellConfig.js";
import React, { useMemo } from "react";
import classNames from "classnames";
import dayjs from "dayjs";
import "./ReadPretty.less";
//#region src/components/dataSourceComponents/fields/DatePicker/ReadPretty.tsx
const DEFAULT_FORMAT = "DD/MM/YYYY HH:mm";
const DATE_FORMATS = {
	"zh-CN": {
		withTime: "YYYY-MM-DD HH:mm",
		withoutTime: "YYYY-MM-DD"
	},
	"en-US": {
		withTime: "MM/DD/YYYY HH:mm",
		withoutTime: "MM/DD/YYYY"
	},
	"en-AU": {
		withTime: "DD/MM/YYYY HH:mm",
		withoutTime: "DD/MM/YYYY"
	},
	en: {
		withTime: "DD/MM/YYYY HH:mm",
		withoutTime: "DD/MM/YYYY"
	}
};
const DatePickerReadPretty = ({ value, renderMode, showTime }) => {
	const { locale = "zh-CN" } = usePisellConfig();
	const dateFormat = useMemo(() => {
		if (locale in DATE_FORMATS) {
			const formats = DATE_FORMATS[locale];
			return showTime ? formats.withTime : formats.withoutTime;
		}
		if (process.env.NODE_ENV !== "production") console.warn(`Unsupported locale: ${locale}, falling back to default format`);
		return DEFAULT_FORMAT;
	}, [locale, showTime]);
	const formattedDate = useMemo(() => {
		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);
};
//#endregion
export { DatePickerReadPretty as default };
