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","dropdownClassName","dropdownRef","dropdownForm","currentVisibleDate","onChangeCurrentVisibleDate","renderAdditionalControls","onDropdownOpen","dropdownOpen","ignoreOutsideClicksRefs","disabled","inputRef"];import addMonths from"date-fns/addMonths";import startOfMonth from"date-fns/startOfMonth";import React,{forwardRef,useEffect,useRef}from"react";import{useClickOutside}from"../../../hooks/useClickOutside";import{useForkRef}from"../../../hooks/useForkRef";import{setRef}from"../../../utils/setRef";import{DatePickerDropdown}from"../DatePickerDropdown/DatePickerDropdown";import{DatePickerFieldTypeDate}from"../DatePickerFieldTypeDate/DatePickerFieldTypeDate";import{getDropdownZIndex}from"../helpers";import{datePickerPropDateTimeViewDefault}from"../types";import{useCalendarVisible}from"../useCalendarVisible";import{useCurrentVisibleDate}from"../useCurrentVisibleDate";export var DatePickerTypeDate=forwardRef(function(a,b){var c=a.events,d=a.dateTimeView,e=void 0===d?datePickerPropDateTimeViewDefault:d,f=a.locale,g=a.dropdownClassName,h=a.dropdownRef,i=a.dropdownForm,j=a.currentVisibleDate,k=a.onChangeCurrentVisibleDate,l=a.renderAdditionalControls,m=a.onDropdownOpen,n=a.dropdownOpen,o=a.ignoreOutsideClicksRefs,p=a.disabled,q=a.inputRef,r=_objectWithoutProperties(a,_excluded),s=useRef(null),t=useRef(null),u=useRef(null),v=useCalendarVisible({dropdownOpen:n,onDropdownOpen:m,disabled:p,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:startOfMonth,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=startOfMonth(a.value);return void(b.getTime()!==B.getTime()&&C(b))}if(a.value&&"classic"!==e&&B){var c=startOfMonth(a.value);c.getTime()!==B.getTime()&&c.getTime()!==addMonths(B,1).getTime()&&C(c)}},[a.value]),useClickOutside({isActive:x,ignoreClicksInsideRefs:[s,t].concat(_toConsumableArray(null!==o&&void 0!==o?o:[])),handler:y.off}),React.createElement(React.Fragment,null,React.createElement(DatePickerFieldTypeDate,Object.assign({},r,{disabled:p,ref:s,inputRef:useForkRef([u,q]),onClick:y.on})),React.createElement(DatePickerDropdown,{ref:useForkRef([h,t]),anchorRef:s,isOpen:x,value:a.value||void 0,type:"date",view:e,events:c,locale:f,minDate:a.minDate,className:g,maxDate:a.maxDate,currentVisibleDate:B,form:i,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=DatePickerTypeDate.js.map