import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["events","dateTimeView","locale","dropdownForm","dropdownClassName","dropdownRef","currentVisibleDate","onChangeCurrentVisibleDate","renderAdditionalControls","onDropdownOpen","dropdownOpen","disabled","ignoreOutsideClicksRefs","inputRef"];import{addYears,startOfDecade}from"date-fns";import React,{forwardRef,useEffect,useRef}from"react";import{useClickOutside}from"../../../hooks/useClickOutside/useClickOutside";import{useForkRef}from"../../../hooks/useForkRef";import{setRef}from"../../../utils/setRef";import{DatePickerDropdown}from"../DatePickerDropdown/DatePickerDropdown";import{DatePickerFieldTypeYear}from"../DatePickerFieldTypeYear/DatePickerFieldTypeYear";import{getDropdownZIndex}from"../helpers";import{datePickerPropDateTimeViewDefault}from"../types";import{useCalendarVisible}from"../useCalendarVisible";import{useCurrentVisibleDate}from"../useCurrentVisibleDate";export var DatePickerTypeYear=forwardRef(function(a,b){var c=a.events,d=a.dateTimeView,e=void 0===d?datePickerPropDateTimeViewDefault:d,f=a.locale,g=a.dropdownForm,h=a.dropdownClassName,i=a.dropdownRef,j=a.currentVisibleDate,k=a.onChangeCurrentVisibleDate,l=a.renderAdditionalControls,m=a.onDropdownOpen,n=a.dropdownOpen,o=a.disabled,p=a.ignoreOutsideClicksRefs,q=a.inputRef,r=_objectWithoutProperties(a,_excluded),s=useRef(null),t=useRef(null),u=useRef(null),v=useCalendarVisible({dropdownOpen:n,onDropdownOpen:m,disabled:o,startRef:u}),w=_slicedToArray(v,2),x=w[0],y=w[1],z=useCurrentVisibleDate({currentVisibleDate:j,maxDate:a.maxDate,minDate:a.minDate,value:a.value,startOfUnit:startOfDecade,onChangeCurrentVisibleDate:k,calendarVisible:x}),A=_slicedToArray(z,2),B=A[0],C=A[1];return useEffect(function(){b&&setRef(b,s.current)},[b,s]),useEffect(function(){if(a.value&&"classic"===e&&B){var b=startOfDecade(a.value);return void(b.getTime()!==B.getTime()&&C(b))}if(a.value&&"classic"!==e&&B){var c=startOfDecade(a.value);c.getTime()!==B.getTime()&&c.getTime()!==addYears(B,10).getTime()&&C(c)}},[a.value]),useClickOutside({isActive:x,ignoreClicksInsideRefs:[s,t].concat(_toConsumableArray(null!==p&&void 0!==p?p:[])),handler:y.off}),React.createElement(React.Fragment,null,React.createElement(DatePickerFieldTypeYear,Object.assign({},r,{ref:s,inputRef:useForkRef([u,q]),disabled:o,onClick:y.on})),React.createElement(DatePickerDropdown,{ref:useForkRef([i,t]),anchorRef:s,className:h,isOpen:x,value:a.value||void 0,type:"year",view:e,events:c,locale:f,minDate:a.minDate,maxDate:a.maxDate,currentVisibleDate:B,form:g,onChange:function onChange(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];null===(b=a.onChange)||void 0===b?void 0:b.call.apply(b,[a].concat(d)),y.off()},renderAdditionalControls:l,zIndex:getDropdownZIndex(a.style),onChangeCurrentVisibleDate:C}))});
//# sourceMappingURL=DatePickerTypeYear.js.map