"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _faArrowRight = require("@fortawesome/free-solid-svg-icons/faArrowRight");
var _fontAwesomeIcon = require("../font-awesome-icon");
var _dropdownMenuTrigger = _interopRequireDefault(require("../dropdown-menu/dropdown-menu-trigger"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const DateRangePickerButton = /*#__PURE__*/(0, _react.forwardRef)(({
  onClick,
  isOpen,
  isDisabled,
  start,
  end,
  dateFormat,
  timeFormat,
  showTimeZoneSuffix,
  labelFormat,
  utcSuffix
}, ref) => {
  const triggerOptions = {
    triggerClassName: 'datetime-range-dropdown-button',
    triggerTestId: 'datetime-range-dropdown-button',
    triggerDynamicContent: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonContent, {
      start: start,
      end: end,
      dateFormat: dateFormat,
      timeFormat: timeFormat,
      labelFormat: labelFormat,
      showTimeZoneSuffix: showTimeZoneSuffix,
      utcSuffix: utcSuffix
    })
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dropdownMenuTrigger.default, {
    ref: ref,
    onClick: onClick,
    isOpen: isOpen,
    isDisabled: isDisabled,
    triggerOptions: triggerOptions
  });
});
DateRangePickerButton.displayName = 'DateRangePickerButton';
function DateRangePickerButtonContent({
  start,
  end,
  dateFormat,
  timeFormat,
  showTimeZoneSuffix,
  labelFormat,
  utcSuffix
}) {
  const startLabelTestId = 'datetime-range-button-start-label';
  const endLabelTestId = 'datetime-range-button-end-label';
  if (!timeFormat) {
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonDateLabel, {
        datetime: start,
        dateFormat: dateFormat,
        testId: startLabelTestId,
        labelFormat: labelFormat
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(StartToEndArrowSeparator, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonDateLabel, {
        datetime: end,
        dateFormat: dateFormat,
        testId: endLabelTestId,
        labelFormat: labelFormat
      })]
    });
  }
  if (!dateFormat) {
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonTimeLabel, {
        datetime: start,
        timeFormat: timeFormat,
        testId: startLabelTestId,
        showTimeZoneSuffix: showTimeZoneSuffix,
        utcSuffix: utcSuffix
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(StartToEndArrowSeparator, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonTimeLabel, {
        datetime: end,
        timeFormat: timeFormat,
        testId: endLabelTestId,
        showTimeZoneSuffix: showTimeZoneSuffix,
        utcSuffix: utcSuffix
      })]
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonDateAndTimeLabel, {
      datetime: start,
      dateFormat: dateFormat,
      timeFormat: timeFormat,
      showTimeZoneSuffix: showTimeZoneSuffix,
      testId: startLabelTestId,
      utcSuffix: utcSuffix
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(StartToEndArrowSeparator, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonDateAndTimeLabel, {
      datetime: end,
      dateFormat: dateFormat,
      timeFormat: timeFormat,
      showTimeZoneSuffix: showTimeZoneSuffix,
      testId: endLabelTestId,
      utcSuffix: utcSuffix
    })]
  });
}
function StartToEndArrowSeparator() {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
    icon: _faArrowRight.faArrowRight,
    className: "date-range-picker-arrow-icon"
  });
}
function DateRangePickerButtonDateAndTimeLabel({
  datetime,
  dateFormat,
  timeFormat,
  showTimeZoneSuffix,
  testId,
  utcSuffix
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
    "test-id": testId,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonDateLabel, {
      datetime: datetime,
      dateFormat: dateFormat
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(DateRangePickerButtonTimeLabel, {
      datetime: datetime,
      timeFormat: timeFormat,
      showTimeZoneSuffix: showTimeZoneSuffix,
      utcSuffix: utcSuffix
    })]
  });
}
function DateRangePickerButtonDateLabel({
  datetime,
  dateFormat,
  testId,
  labelFormat
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
    className: "date-part",
    "test-id": testId,
    children: `${datetime.format(labelFormat || dateFormat)}`
  });
}
function DateRangePickerButtonTimeLabel({
  datetime,
  timeFormat,
  showTimeZoneSuffix = true,
  testId,
  utcSuffix
}) {
  const buttonText = showTimeZoneSuffix ? `${datetime.format(timeFormat)} ${utcSuffix}` : datetime.format(timeFormat);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
    className: "time-part",
    "test-id": testId,
    children: buttonText
  });
}
var _default = exports.default = DateRangePickerButton;