import { Component, useField, SugaredField } from "@contember/binding";
import { FieldFallbackView } from "./FieldFallbackView.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/fieldViews/DateFieldView.tsx";
const DateFieldView = Component(({
  field,
  locale,
  format,
  fallback,
  fallbackStyle
}) => {
  const dateField = useField(field);
  if (dateField.value === null) {
    return /* @__PURE__ */ jsxDEV(FieldFallbackView, {
      fallback,
      fallbackStyle
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 18,
      columnNumber: 11
    }, void 0);
  }
  const date = new Date(dateField.value);
  if (locale === void 0) {
    if (format === void 0) {
      return /* @__PURE__ */ jsxDEV(Fragment, {
        children: date.toLocaleString()
      }, void 0, false);
    }
    if (typeof format === "function") {
      return /* @__PURE__ */ jsxDEV(Fragment, {
        children: format(date)
      }, void 0, false);
    }
  }
  const intl = new Intl.DateTimeFormat(locale ?? "default", {
    ...format,
    timeZone: "UTC"
  });
  return /* @__PURE__ */ jsxDEV(Fragment, {
    children: intl.format(date)
  }, void 0, false);
}, (props) => /* @__PURE__ */ jsxDEV(Fragment, {
  children: [/* @__PURE__ */ jsxDEV(SugaredField, {
    field: props.field
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 39,
    columnNumber: 4
  }, void 0), /* @__PURE__ */ jsxDEV(FieldFallbackView, {
    fallback: props.fallback,
    fallbackStyle: props.fallbackStyle
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 40,
    columnNumber: 4
  }, void 0)]
}, void 0, true), "DateFieldView");
export {
  DateFieldView
};
//# sourceMappingURL=DateFieldView.js.map
