import { jsx, Fragment, jsxs } from "react/jsx-runtime";
import { Component, useField, SugaredField } from "@contember/binding";
import { FieldFallbackView } from "./FieldFallbackView.js";
const DateFieldView = Component(
  ({ field, locale, format, fallback, fallbackStyle }) => {
    const dateField = useField(field);
    if (dateField.value === null) {
      return /* @__PURE__ */ jsx(FieldFallbackView, { fallback, fallbackStyle });
    }
    const date = new Date(dateField.value);
    if (locale === void 0) {
      if (format === void 0) {
        return /* @__PURE__ */ jsx(Fragment, { children: date.toLocaleString() });
      }
      if (typeof format === "function") {
        return /* @__PURE__ */ jsx(Fragment, { children: format(date) });
      }
    }
    const intl = new Intl.DateTimeFormat(locale ?? "default", { ...format, timeZone: "UTC" });
    return /* @__PURE__ */ jsx(Fragment, { children: intl.format(date) });
  },
  (props) => /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(SugaredField, { field: props.field }),
    /* @__PURE__ */ jsx(FieldFallbackView, { fallback: props.fallback, fallbackStyle: props.fallbackStyle })
  ] }),
  "DateFieldView"
);
export {
  DateFieldView
};
//# sourceMappingURL=DateFieldView.js.map
