function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { Error } from "@blueprintjs/icons";
import classNames from "classnames";
import React, { useCallback, useMemo } from "react";
import { DatePicker } from "../../shared/calendar/index.js";
import { formatDateForInput } from "../../shared/dateUtils.js";
import { useRegisterPortal } from "../utils/PortalTracker.js";
import styles from "../EditableCell.module.css.js";
function parseDateValue(input) {
  if (input === "") {
    return null;
  }
  const date = new Date(input);
  if (isNaN(date.getTime())) {
    return null;
  }
  return date;
}
function DatePickerCellFieldInner({
  fieldComponentProps,
  inputValue,
  hasValidationError,
  isEdited,
  onChange,
  dataType
}) {
  const portalRef = useRegisterPortal();
  const dateValue = useMemo(() => parseDateValue(inputValue), [inputValue]);
  const showTime = fieldComponentProps?.showTime ?? dataType === "timestamp";
  const handleChange = useCallback(newValue => {
    if (newValue == null) {
      onChange(null);
      return;
    }
    onChange(showTime ? newValue.toISOString() : formatDateForInput(newValue));
  }, [onChange, showTime]);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(styles.osdkEditableCellDatePicker, {
      [styles.error]: hasValidationError,
      [styles.osdkEditedInput]: isEdited
    })
  }, /*#__PURE__*/React.createElement(DatePicker, _extends({}, fieldComponentProps, {
    showTime: showTime,
    value: dateValue,
    onChange: handleChange,
    portalRef: portalRef,
    modal: false
  })), hasValidationError && /*#__PURE__*/React.createElement("span", {
    className: styles.errorIconWrapper
  }, /*#__PURE__*/React.createElement(Error, {
    className: styles.errorIcon
  })));
}
export const DatePickerCellField = /*#__PURE__*/React.memo(DatePickerCellFieldInner);
//# sourceMappingURL=DatePickerCellField.js.map