"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _i18n = require("@wordpress/i18n");
var _date = require("@wordpress/date");
var _tooltip = _interopRequireDefault(require("../../tooltip"));
var _styles = require("./styles");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Displays timezone information when user timezone is different from site
 * timezone.
 */const TimeZone = () => {
  const {
    timezone
  } = (0, _date.getSettings)();

  // Convert timezone offset to hours.
  const userTimezoneOffset = -1 * (new Date().getTimezoneOffset() / 60);

  // System timezone and user timezone match, nothing needed.
  // Compare as numbers because it comes over as string.
  if (Number(timezone.offset) === userTimezoneOffset) {
    return null;
  }
  const offsetSymbol = Number(timezone.offset) >= 0 ? '+' : '';
  const zoneAbbr = '' !== timezone.abbr && isNaN(Number(timezone.abbr)) ? timezone.abbr : `UTC${offsetSymbol}${timezone.offsetFormatted}`;

  // Replace underscore with space in strings like `America/Costa_Rica`.
  const prettyTimezoneString = timezone.string.replace('_', ' ');
  const timezoneDetail = 'UTC' === timezone.string ? (0, _i18n.__)('Coordinated Universal Time') : `(${zoneAbbr}) ${prettyTimezoneString}`;

  // When the prettyTimezoneString is empty, there is no additional timezone
  // detail information to show in a Tooltip.
  const hasNoAdditionalTimezoneDetail = prettyTimezoneString.trim().length === 0;
  return hasNoAdditionalTimezoneDetail ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.TimeZone, {
    className: "components-datetime__timezone",
    children: zoneAbbr
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.default, {
    placement: "top",
    text: timezoneDetail,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.TimeZone, {
      className: "components-datetime__timezone",
      children: zoneAbbr
    })
  });
};
var _default = exports.default = TimeZone;
//# sourceMappingURL=timezone.js.map