import { createElement, Fragment } from "react";
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__ */ createElement(FieldFallbackView, {
      fallback,
      fallbackStyle
    });
  }
  const date = new Date(dateField.value);
  if (locale === void 0) {
    if (format === void 0) {
      return /* @__PURE__ */ createElement(Fragment, null, date.toLocaleString());
    }
    if (typeof format === "function") {
      return /* @__PURE__ */ createElement(Fragment, null, format(date));
    }
  }
  const intl = new Intl.DateTimeFormat(locale ?? "default", { ...format, timeZone: "UTC" });
  return /* @__PURE__ */ createElement(Fragment, null, intl.format(date));
}, (props) => /* @__PURE__ */ createElement(Fragment, null, /* @__PURE__ */ createElement(SugaredField, {
  field: props.field
}), /* @__PURE__ */ createElement(FieldFallbackView, {
  fallback: props.fallback,
  fallbackStyle: props.fallbackStyle
})), "DateFieldView");
export { DateFieldView };
//# sourceMappingURL=DateFieldView.js.map
