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","dropdownForm","currentVisibleDate","onChangeCurrentVisibleDate","renderAdditionalControls","onDropdownOpen","dropdownOpen","ignoreOutsideClicksRefs"];import addMonths from"date-fns/addMonths";import startOfMonth from"date-fns/startOfMonth";import React,{forwardRef,useEffect,useRef}from"react";import{useClickOutside}from"../../../hooks/useClickOutside/useClickOutside";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.dropdownForm,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:startOfMonth,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=startOfMonth(a.value);return void(b.getTime()!==y.getTime()&&z(b))}if(a.value&&"classic"!==e&&y){var c=startOfMonth(a.value);c.getTime()!==y.getTime()&&c.getTime()!==addMonths(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(DatePickerFieldTypeDate,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:"date",view:e,events:c,locale:f,minDate:a.minDate,className:g,maxDate:a.maxDate,currentVisibleDate:y,form:h,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,zIndex:getDropdownZIndex(a.style),onChangeCurrentVisibleDate:z}))});
//# sourceMappingURL=DatePickerTypeDate.js.map