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