!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","react","./Calendar","./DatePickerInput","./TimePickerInput","../common","../assets/datetime","../FormElementOuter","../utils"],e)}(function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var D=e("tslib"),_=D.__importStar(e("react")),M=e("./Calendar"),P=D.__importDefault(e("./DatePickerInput")),C=D.__importDefault(e("./TimePickerInput")),E=e("../common"),F=e("../assets/datetime"),I=D.__importDefault(e("../FormElementOuter")),O=e("../utils");t.default=function(e){var t=_.useState(!1),a=t[0],n=t[1],o=_.useState(!1),l=o[0],i=o[1],r=e.component,u=e.element,c=r.props,s=c.host,d=c.name,f=_.useCallback(function(e){E.renderFocus(e,d,s)},[d,s]),m=[u.type,O.makeSafeClassName(d)],p=s.renderText(u.tooltip),v=function(e,t){if("object"==typeof e&&null!==e)switch(e.refValueType){case"date":case"time":case"datetime":t=e.format}if("object"!=typeof t)return"app"===t?t:"device";if(null===t)return"device";var a=t.locale,n=t.timezone;return"string"==typeof a&&"string"==typeof n?{locale:a,timezone:n}:"device"}(u.value,u.format),g=s.deriveCalendar(v),y=function(e,t){if("object"==typeof e){if(null===e)return;switch(e.refValueType){case"date":case"time":case"datetime":break;default:return}e=e.value}if("number"==typeof e||"string"==typeof e){e=t.coerceIntoValue(e);if(null!=e&&isFinite(e.valueOf()))return e}}(u.value,g),b="datetime",k=function(e){if("object"==typeof e&&null!==e)switch(e.refValueType){case"date":case"time":case"datetime":return e.refValueType}}(u.value);"DatePicker"===u.type&&(b="date"),"TimePicker"===u.type&&(b="time");t=y;"datetime"===b&&"date"===k?t=void 0:k=b;o={calendar:g,disabled:!r.enabled,doneText:s.renderText("@common-done"),placeholder:s.renderText(u.prompt),title:p};function T(e,t){return void 0===(e=null!=e&&!isFinite(e.valueOf())?void 0:e)?void 0!==y:void 0===y||(k!==t||("date"===t&&((e=new Date(e)).setHours(y.getHours()),e.setMinutes(y.getMinutes()),e.setSeconds(y.getSeconds()),e.setMilliseconds(y.getMilliseconds())),"time"===t&&((e=new Date(e)).setFullYear(y.getFullYear()),e.setMonth(y.getMonth()),e.setDate(y.getDate())),y.valueOf()!==e.valueOf()))}e=function(){var e=!a;n(e),e&&i(!1)},c=function(){var e=!l;i(e),e&&n(!1)},p=[];function h(e,t){void 0!==e&&isFinite(e.valueOf())?u.value={refValueType:t,format:v,display:g.format(e,M.Calendar.fullFormat),value:e.valueOf()}:u.value=void 0}return"DatePicker"!==u.type&&"DateTimePicker"!==u.type||p.push(_.default.createElement("div",{className:"outer"},_.default.createElement("div",{className:"inner"},_.default.createElement(P.default,D.__assign({},o,{isOpen:a,onChange:function(e){var t,a,n=b;"datetime"===b&&void 0!==e&&("date"===k&&(n="date"),void 0!==y&&(t=g.coerceIntoLocal(y),(a=g.coerceIntoLocal(e)).setHours(t.getHours()),a.setMinutes(t.getMinutes()),a.setSeconds(t.getSeconds()),a.setMilliseconds(t.getMilliseconds()),e=g.coerceIntoValue(a))),T(e,n)&&(h(e,n),r.forceUpdate(),s.post("changed",{name:d,value:u.value}))},onPopupToggle:e,ref:f,value:y}))),_.default.createElement("button",{className:"calendarButton",disabled:o.disabled,onClick:e},F.renderCalendar()))),"TimePicker"!==u.type&&"DateTimePicker"!==u.type||p.push(_.default.createElement("div",{className:"outer"},_.default.createElement("div",{className:"inner"},_.default.createElement(C.default,D.__assign({},o,{isOpen:l,onChange:function(e){var t,a,n=b;"datetime"===b&&void 0!==y&&(void 0!==e?(t=g.coerceIntoLocal(y),(a=g.coerceIntoLocal(e)).setFullYear(t.getFullYear()),a.setMonth(t.getMonth()),a.setDate(t.getDate()),e=g.coerceIntoValue(a)):(e=y,n="date")),T(e,n)&&(h(e,n),r.forceUpdate(),s.post("changed",{name:d,value:u.value}))},onPopupToggle:c,ref:f,value:t}))),_.default.createElement("button",{className:"clockButton",disabled:o.disabled,onClick:c},F.renderClock()))),h(y,k),_.default.createElement(I.default,{className:m.join(" "),component:r,element:u},p)}});