"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _constants = require("../../constants");
var _theme = require("../../contexts/theme");
var _helpers = require("../../utils/helpers");
var _testable = require("../../utils/testable");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const RecordDateIntField = _ref => {
  let {
    field,
    shown,
    style
  } = _ref;
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const {
    ListItems
  } = (0, _theme.useTheme)();
  const [date, setDate] = (0, _react.useState)();
  (0, _react.useEffect)(() => {
    const dateint = field.value;
    if (!dateint) {
      setDate('');
      return;
    }
    if (dateint.length === _constants.dateIntFormat.length) {
      const year = dateint.substring(0, 4);
      const month = dateint.substring(4, 6);
      const day = dateint.substring(6, 8);
      //NOTE: JavaScript counts months from 0 to 11: January = 0, December = 11.
      const date = new Date(Number(year), Number(month) - 1, Number(day));
      if (!isNaN(date.getDate())) {
        setDate((0, _helpers.formatTime)(date, {
          shortMonth: true
        }));
        return;
      }
    }
    setDate(t('Record.InvalidDate') + dateint);
  }, [field]);
  const styles = _reactNative.StyleSheet.create({
    text: {
      ...ListItems.recordAttributeText
    },
    image: {
      height: 150,
      aspectRatio: 1,
      resizeMode: 'contain',
      borderRadius: 10
    }
  });
  return /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: style || styles.text,
    testID: (0, _testable.testIdWithKey)('AttributeValue')
  }, shown ? date : _constants.hiddenFieldValue);
};
var _default = RecordDateIntField;
exports.default = _default;
//# sourceMappingURL=RecordDateIntField.js.map