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","currentVisibleDate","onChangeCurrentVisibleDate","renderAdditionalControls","onDropdownOpen","dropdownOpen","disabled","ignoreOutsideClicksRefs"];import{addYears,startOfDecade}from"date-fns";import React,{forwardRef,useEffect,useRef}from"react";import{useClickOutside}from"../../../hooks/useClickOutside/useClickOutside";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.currentVisibleDate,j=a.onChangeCurrentVisibleDate,k=a.renderAdditionalControls,l=a.onDropdownOpen,m=a.dropdownOpen,n=a.disabled,o=a.ignoreOutsideClicksRefs,p=_objectWithoutProperties(a,_excluded),q=useRef(null),r=useRef(null),s=useRef(null),t=useCalendarVisible({dropdownOpen:m,onDropdownOpen:l,startRef:s}),u=_slicedToArray(t,2),v=u[0],w=u[1],x=useCurrentVisibleDate({currentVisibleDate:i,maxDate:a.maxDate,minDate:a.minDate,value:a.value,startOfUnit:startOfDecade,onChangeCurrentVisibleDate:j,calendarVisible:v}),y=_slicedToArray(x,2),z=y[0],A=y[1];return useEffect(function(){b&&setRef(b,q.current)},[b,q]),useEffect(function(){if(a.value&&"classic"===e&&z){var b=startOfDecade(a.value);return void(b.getTime()!==z.getTime()&&A(b))}if(a.value&&"classic"!==e&&z){var c=startOfDecade(a.value);c.getTime()!==z.getTime()&&c.getTime()!==addYears(z,10).getTime()&&A(c)}},[a.value]),useClickOutside({isActive:v,ignoreClicksInsideRefs:[q,r].concat(_toConsumableArray(null!==o&&void 0!==o?o:[])),handler:w.off}),React.createElement(React.Fragment,null,React.createElement(DatePickerFieldTypeYear,Object.assign({},p,{ref:q,inputRef:s,disabled:n,onClick:w.on})),React.createElement(DatePickerDropdown,{ref:r,anchorRef:q,className:h,isOpen:v,value:a.value||void 0,type:"year",view:e,events:c,locale:f,minDate:a.minDate,maxDate:a.maxDate,currentVisibleDate:z,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)),w.off()},renderAdditionalControls:k,zIndex:getDropdownZIndex(a.style),onChangeCurrentVisibleDate:A}))});
//# sourceMappingURL=DatePickerTypeYear.js.map