"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _classNames=_interopRequireDefault(require("../libs/classNames")),_constants=require("../shared/constants");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var r;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(r="Object"===(r=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=new Array(t);r<t;r++)a[r]=e[r];return a}function intersperseSpace(e){return e.reduce(function(e,t){return[].concat(_toConsumableArray(e),[" ",t])},[]).slice(1)}var _default=exports.default=Behavior({properties:{validateStatus:{type:null,value:null},required:{type:null,value:null},help:{type:null,value:null},hasFeedback:{type:Boolean,value:!0}},data:{mergedValidateStatus:"",mergedRequired:!1,feedbackMessage:"",validateClasses:""},methods:{getControls:function(){return this.getRelationsByType("descendant").filter(function(e){return!!e.hasFieldDecorator})},getOnlyControl:function(){var e=this.getControls()[0];return void 0!==e?e:null},getChildProp:function(e){var t=this.getOnlyControl();return t&&t.data&&t.data[e]},getMeta:function(){return this.getChildProp(_constants.FIELD_META_PROP)},getField:function(){return this.getChildProp(_constants.FIELD_DATA_PROP)},getValidateState:function(e,t){return this.getOnlyControl()?(e=e||this.getMeta(),(t=t||this.getField()).validating?"validating":t.errors?"error":null!=(t="value"in t?t.value:e.initialValue)&&""!==t?"success":""):""},getRequiredState:function(e){return null!==e?!!e:!!this.getOnlyControl()&&((this.getMeta()||{}).validate||[]).filter(function(e){return!!e.rules}).some(function(e){return e.rules.some(function(e){return e.required})})},getFeedbackMessage:function(e){if(this.getOnlyControl()){var t=this.getField().errors;if(t)return intersperseSpace(t.map(function(e){return e.message}))}return""},getValidateClasses:function(e,t,r){return e?(0,_classNames.default)({"has-success":"success"===e,"has-warning":"warning"===e,"has-error":"error"===e,"is-validating":"validating"===e}):""},reRender:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.data,t=null!==e.validateStatus?"".concat(e.validateStatus):this.getValidateState(),r=(this.data.mergedValidateStatus!==t&&this.setData({mergedValidateStatus:t}),this.getRequiredState(e.required)),r=(this.data.mergedRequired!==r&&this.setData({mergedRequired:r}),this.getFeedbackMessage(e.help)),r=(this.data.feedbackMessage!==r&&this.setData({feedbackMessage:r}),this.getValidateClasses(t,e.hasFeedback,e.help));this.data.validateClasses!==r&&this.setData({validateClasses:r})}}});