!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","react","date-fns","react-date-range","../assets/arrow","../assets/datetime","../common","../FormElementOuter","../../BrowserUtils","../dateUtilities","../utils","../styles/daterange","../constants"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var x,A=e("tslib"),U=A.__importStar(e("react")),k=e("date-fns"),B=e("react-date-range"),V=e("../assets/arrow"),O=e("../assets/datetime"),T=e("../common"),j=A.__importDefault(e("../FormElementOuter")),q=e("../../BrowserUtils"),P=e("../dateUtilities"),R=e("../utils"),a=e("../styles/daterange"),I=e("../constants");R.addStyleToDocument(a.CSS),(a=x=x||{}).Start="start",a.End="end";var K,z=P.getLocaleDateFormat();t.default=function(e){var t=e.component,a=e.element,n=a.value,r=U.useState(!1),o=r[0],s=r[1],i=U.useState(),l=i[0],d=i[1],u=U.useState(P.getDateAsLocaleFormattedString(null==n?void 0:n.startDate)),c=u[0],f=u[1],m=U.useState(),D=m[0],v=m[1],p=U.useState(P.getDateAsLocaleFormattedString(null==n?void 0:n.endDate)),g=p[0],S=p[1],E=!t.enabled,e=t.props,y=e.host,b=e.name,r=y.renderText(a.tooltip),i=t.enabled?"inner":"inner disabled",u=[a.type,R.makeSafeClassName(b)],m=!q.isIE();U.useEffect(function(){A.__awaiter(void 0,void 0,void 0,function(){var t;return A.__generator(this,function(e){switch(e.label){case 0:return"inv"===(t=y.deriveLocale())||"en"===t||"en-US"===t?[2]:[4,P.getDateFnsLocale(t)];case 1:return K=e.sent(),[2]}})})},[]);function w(e,t){var a,n=""!==(s="string"==typeof e?e:e.target.value)&&void 0!==s,r=n?P.tryParseDateText(s):void 0,o=n?r?k.parse(r,z,0):new Date(NaN):void 0,s=(e=t===x.Start)?o:l,t=e?D:o;n?P.isValidDate(o)?e?(d(s),f(r),(a=!P.isValidDate(t)||k.isAfter(s,t))&&(v(s),S(r)),F(),h(s,a?s:t)):(v(t),S(r),(a=!P.isValidDate(s)||k.isBefore(t,s))&&(d(t),f(r)),F(),h(a?t:s,t)):(F({status:"invalid"}),h(),(e?d:v)(new Date(NaN))):((e?void 0===t||P.isValidDate(t):void 0===s||P.isValidDate(s))&&F(),h(),(e?d:v)(void 0))}function C(e,t){(t===x.Start?f:S)(e.target.value)}function N(e,t){var a;e.stopPropagation(),"Enter"===e.key?(a=t===x.Start?c:g,w(a,t)):"Escape"===e.key&&(e=t===x.Start?P.getDateAsLocaleFormattedString(l):P.getDateAsLocaleFormattedString(D),w(e,t))}function h(e,t){_(e,t)&&L(e,t)}function F(e){a.error=e,t.forceUpdate()}var p=U.useCallback(function(e){T.renderFocus(e,b,y)},[]),_=function(e,t){return!(e||t||!n)||(!(!e||!t||n)||!!(e&&t&&n)&&(!k.isEqual(e,n.startDate)||!k.isEqual(t,n.endDate)))},L=function(e,t){a.value=e&&t?{refValueType:"daterange",startDate:e,endDate:t}:void 0,y.post("changed",{name:b,value:a.value})},e={startDate:(null==n?void 0:n.startDate)||new Date,endDate:(null==n?void 0:n.endDate)||new Date,key:"selection",showDateDisplay:!1};return U.default.createElement(j.default,{className:u.join(" "),component:t,element:a},U.default.createElement("div",{className:"outer",title:r},U.default.createElement("div",{className:i},U.default.createElement("input",{ref:p,disabled:E,type:"text",onChange:function(e){return C(e,x.Start)},onBlur:function(e){return w(e,x.Start)},onKeyDown:function(e){return N(e,x.Start)},placeholder:z.toUpperCase(),value:c}),U.default.createElement("span",{className:"arrow"},V.renderArrowRight()),U.default.createElement("input",{disabled:E,type:"text",onChange:function(e){return C(e,x.End)},onBlur:function(e){return w(e,x.End)},onKeyDown:function(e){return N(e,x.End)},placeholder:z.toUpperCase(),value:g})),U.default.createElement("div",{className:"buttonContainer"},m&&U.default.createElement("button",{className:"calendarButton",disabled:E,onClick:function(){s(!o)}},O.renderCalendar()),o&&U.default.createElement("div",{className:I.CssClasses.DROPDOWN},U.default.createElement(B.DateRange,{dateDisplayFormat:z,editableDateInputs:!1,months:1,direction:"horizontal",ranges:[e],onChange:function(e){var t=e.selection.startDate,e=e.selection.endDate;d(t),f(P.getDateAsLocaleFormattedString(t)),v(e),S(P.getDateAsLocaleFormattedString(e)),F(),h(t,e)},locale:K}),U.default.createElement("button",{className:"done",onClick:function(){s(!1)}},y.renderText("@common-done"))))))}});