define(["require","exports","tslib","react","./Calendar","./DatePickerInput","./TimePickerInput","../common","../assets/datetime","../FormElementOuter","../utils"],function(e,t,D,_,M,C,P,E,F,O,I){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),_=D.__importStar(_),C=D.__importDefault(C),P=D.__importDefault(P),O=D.__importDefault(O),t.default=function(e){var t=_.useState(!1),a=t[0],n=t[1],l=_.useState(!1),o=l[0],i=l[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,I.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",T=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"===T?t=void 0:T=b;l={calendar:g,disabled:!r.enabled,doneText:s.renderText("@common-done"),placeholder:s.renderText(u.prompt),title:p};function h(e,t){return void 0===(e=null!=e&&!isFinite(e.valueOf())?void 0:e)?void 0!==y:void 0===y||(T!==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=!o;i(e),e&&n(!1)},p=[];function k(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(C.default,D.__assign({},l,{isOpen:a,onChange:function(e){var t,a,n=b;"datetime"===b&&void 0!==e&&("date"===T&&(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))),h(e,n)&&(k(e,n),r.forceUpdate(),s.post("changed",{name:d,value:u.value}))},onPopupToggle:e,ref:f,value:y}))),_.default.createElement("button",{className:"calendarButton",disabled:l.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(P.default,D.__assign({},l,{isOpen:o,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")),h(e,n)&&(k(e,n),r.forceUpdate(),s.post("changed",{name:d,value:u.value}))},onPopupToggle:c,ref:f,value:t}))),_.default.createElement("button",{className:"clockButton",disabled:l.disabled,onClick:c},F.renderClock()))),k(y,T),_.default.createElement(O.default,{className:m.join(" "),component:r,element:u},p)}});