"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _YearDropdownSt = require("./YearDropdown.st.css.js");
var _setYear = _interopRequireDefault(require("date-fns/setYear"));
var _DatePickerDropdown = _interopRequireDefault(require("../../DatePickerDropdown"));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Calendar/DatePickerHead/YearDropdown/YearDropdown.tsx";
var YearDropdown = _ref => {
  var _years$find;
  var {
    className,
    date,
    onChange: _onChange,
    ariaLabel,
    ariaLabelledBy
  } = _ref;
  var year = date.getFullYear();
  var maxYear = Math.max(year, new Date().getFullYear() + 15);
  var minYear = Math.min(year - 1, 1899);
  var years = Array.from({
    length: maxYear - minYear
  }, (_, i) => ({
    id: i,
    value: maxYear - i
  }));
  var selectedYear = (_years$find = years.find(_ref2 => {
    var {
      value
    } = _ref2;
    return value === year;
  })) !== null && _years$find !== void 0 ? _years$find : years[0];
  return /*#__PURE__*/_react.default.createElement(_DatePickerDropdown.default, {
    dataHook: "datepicker-year-dropdown",
    className: (0, _YearDropdownSt.st)(_YearDropdownSt.classes.root, className),
    caption: selectedYear.value,
    options: years,
    selectedId: selectedYear.id,
    onChange: _ref3 => {
      var {
        value
      } = _ref3;
      return _onChange((0, _setYear.default)(date, value));
    },
    ariaLabel: ariaLabel,
    ariaLabelledBy: ariaLabelledBy,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 27,
      columnNumber: 5
    }
  });
};
var _default = exports.default = YearDropdown;
//# sourceMappingURL=YearDropdown.js.map