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