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