/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _asyncToGenerator, r as regenerator } from '../_chunks/dep-38ee6a8f.mjs';
import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, inject, computed, createVNode, ref, nextTick, toRefs, reactive, onMounted, onBeforeUnmount, watch, provide } from 'vue';
import { CheckCircleFilledIcon, CloseCircleFilledIcon, ErrorCircleFilledIcon } from '@ldesign/icons-vue-next';
import { i as isArray_1 } from '../_chunks/dep-b57180d0.mjs';
import { i as isNumber_1 } from '../_chunks/dep-3f21269a.mjs';
import { i as isString_1 } from '../_chunks/dep-876fb3ec.mjs';
import { i as isBoolean_1 } from '../_chunks/dep-35e3b1aa.mjs';
import { c as cloneDeep_1 } from '../_chunks/dep-095107f7.mjs';
import { g as get_1 } from '../_chunks/dep-c81c0ee4.mjs';
import { s as set_1 } from '../_chunks/dep-6c4f38de.mjs';
import { i as isNil_1 } from '../_chunks/dep-01e3f446.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import { _ as _copyObject, k as keysIn_1 } from '../_chunks/dep-9cf86cf1.mjs';
import { _ as _createAssigner } from '../_chunks/dep-40d69a9c.mjs';
import { _ as _apply } from '../_chunks/dep-0fc02184.mjs';
import { _ as _baseRest } from '../_chunks/dep-dcc83161.mjs';
import { _ as _baseGetTag } from '../_chunks/dep-469b4ae0.mjs';
import { i as isObjectLike_1 } from '../_chunks/dep-3da99438.mjs';
import { i as isPlainObject_1 } from '../_chunks/dep-f1994936.mjs';
import { _ as _arrayMap, t as toString_1 } from '../_chunks/dep-42cc3015.mjs';
import { e as eq_1 } from '../_chunks/dep-855db8bc.mjs';
import { _ as _isIterateeCall } from '../_chunks/dep-345e1be3.mjs';
import { k as keys_1 } from '../_chunks/dep-c989dff3.mjs';
import { _ as _basePropertyOf } from '../_chunks/dep-1372b2d3.mjs';
import '../hooks/index.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import { validate } from './form-model.mjs';
import props from './form-item-props.mjs';
import { useCLASSNAMES, FormInjectionKey, ValidateStatus, FormItemInjectionKey } from './const.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-0d3dd4b5.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-550c24c1.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDefaultValue.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../utils/helper.mjs';
import '../_chunks/dep-60fae668.mjs';
import '../_chunks/dep-84acf3c2.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../utils/render-tnode.mjs';
import '../config-provider/type.mjs';

var copyObject = _copyObject,
  createAssigner = _createAssigner,
  keysIn = keysIn_1;

/**
 * This method is like `_.assignIn` except that it accepts `customizer`
 * which is invoked to produce the assigned values. If `customizer` returns
 * `undefined`, assignment is handled by the method instead. The `customizer`
 * is invoked with five arguments: (objValue, srcValue, key, object, source).
 *
 * **Note:** This method mutates `object`.
 *
 * @static
 * @memberOf _
 * @since 4.0.0
 * @alias extendWith
 * @category Object
 * @param {Object} object The destination object.
 * @param {...Object} sources The source objects.
 * @param {Function} [customizer] The function to customize assigned values.
 * @returns {Object} Returns `object`.
 * @see _.assignWith
 * @example
 *
 * function customizer(objValue, srcValue) {
 *   return _.isUndefined(objValue) ? srcValue : objValue;
 * }
 *
 * var defaults = _.partialRight(_.assignInWith, customizer);
 *
 * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
 * // => { 'a': 1, 'b': 2 }
 */
var assignInWith$1 = createAssigner(function (object, source, srcIndex, customizer) {
  copyObject(source, keysIn(source), object, customizer);
});
var assignInWith_1 = assignInWith$1;

var baseGetTag = _baseGetTag,
  isObjectLike = isObjectLike_1,
  isPlainObject = isPlainObject_1;

/** `Object#toString` result references. */
var domExcTag = '[object DOMException]',
  errorTag = '[object Error]';

/**
 * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
 * `SyntaxError`, `TypeError`, or `URIError` object.
 *
 * @static
 * @memberOf _
 * @since 3.0.0
 * @category Lang
 * @param {*} value The value to check.
 * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
 * @example
 *
 * _.isError(new Error);
 * // => true
 *
 * _.isError(Error);
 * // => false
 */
function isError$2(value) {
  if (!isObjectLike(value)) {
    return false;
  }
  var tag = baseGetTag(value);
  return tag == errorTag || tag == domExcTag || typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value);
}
var isError_1 = isError$2;

var apply = _apply,
  baseRest = _baseRest,
  isError$1 = isError_1;

/**
 * Attempts to invoke `func`, returning either the result or the caught error
 * object. Any additional arguments are provided to `func` when it's invoked.
 *
 * @static
 * @memberOf _
 * @since 3.0.0
 * @category Util
 * @param {Function} func The function to attempt.
 * @param {...*} [args] The arguments to invoke `func` with.
 * @returns {*} Returns the `func` result or error object.
 * @example
 *
 * // Avoid throwing errors for invalid selectors.
 * var elements = _.attempt(function(selector) {
 *   return document.querySelectorAll(selector);
 * }, '>_>');
 *
 * if (_.isError(elements)) {
 *   elements = [];
 * }
 */
var attempt$1 = baseRest(function (func, args) {
  try {
    return apply(func, undefined, args);
  } catch (e) {
    return isError$1(e) ? e : new Error(e);
  }
});
var attempt_1 = attempt$1;

var arrayMap = _arrayMap;

/**
 * The base implementation of `_.values` and `_.valuesIn` which creates an
 * array of `object` property values corresponding to the property names
 * of `props`.
 *
 * @private
 * @param {Object} object The object to query.
 * @param {Array} props The property names to get values for.
 * @returns {Object} Returns the array of property values.
 */
function baseValues$1(object, props) {
  return arrayMap(props, function (key) {
    return object[key];
  });
}
var _baseValues = baseValues$1;

var eq = eq_1;

/** Used for built-in method references. */
var objectProto$1 = Object.prototype;

/** Used to check objects for own properties. */
var hasOwnProperty$1 = objectProto$1.hasOwnProperty;

/**
 * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
 * of source objects to the destination object for all destination properties
 * that resolve to `undefined`.
 *
 * @private
 * @param {*} objValue The destination value.
 * @param {*} srcValue The source value.
 * @param {string} key The key of the property to assign.
 * @param {Object} object The parent object of `objValue`.
 * @returns {*} Returns the value to assign.
 */
function customDefaultsAssignIn$1(objValue, srcValue, key, object) {
  if (objValue === undefined || eq(objValue, objectProto$1[key]) && !hasOwnProperty$1.call(object, key)) {
    return srcValue;
  }
  return objValue;
}
var _customDefaultsAssignIn = customDefaultsAssignIn$1;

/** Used to escape characters for inclusion in compiled string literals. */
var stringEscapes = {
  '\\': '\\',
  "'": "'",
  '\n': 'n',
  '\r': 'r',
  "\u2028": 'u2028',
  "\u2029": 'u2029'
};

/**
 * Used by `_.template` to escape characters for inclusion in compiled string literals.
 *
 * @private
 * @param {string} chr The matched character to escape.
 * @returns {string} Returns the escaped character.
 */
function escapeStringChar$1(chr) {
  return '\\' + stringEscapes[chr];
}
var _escapeStringChar = escapeStringChar$1;

/** Used to match template delimiters. */
var reInterpolate$2 = /<%=([\s\S]+?)%>/g;
var _reInterpolate = reInterpolate$2;

var basePropertyOf = _basePropertyOf;

/** Used to map characters to HTML entities. */
var htmlEscapes = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;'
};

/**
 * Used by `_.escape` to convert characters to HTML entities.
 *
 * @private
 * @param {string} chr The matched character to escape.
 * @returns {string} Returns the escaped character.
 */
var escapeHtmlChar$1 = basePropertyOf(htmlEscapes);
var _escapeHtmlChar = escapeHtmlChar$1;

var escapeHtmlChar = _escapeHtmlChar,
  toString$1 = toString_1;

/** Used to match HTML entities and HTML characters. */
var reUnescapedHtml = /[&<>"']/g,
  reHasUnescapedHtml = RegExp(reUnescapedHtml.source);

/**
 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
 * corresponding HTML entities.
 *
 * **Note:** No other characters are escaped. To escape additional
 * characters use a third-party library like [_he_](https://mths.be/he).
 *
 * Though the ">" character is escaped for symmetry, characters like
 * ">" and "/" don't need escaping in HTML and have no special meaning
 * unless they're part of a tag or unquoted attribute value. See
 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
 * (under "semi-related fun fact") for more details.
 *
 * When working with HTML you should always
 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
 * XSS vectors.
 *
 * @static
 * @since 0.1.0
 * @memberOf _
 * @category String
 * @param {string} [string=''] The string to escape.
 * @returns {string} Returns the escaped string.
 * @example
 *
 * _.escape('fred, barney, & pebbles');
 * // => 'fred, barney, &amp; pebbles'
 */
function escape$1(string) {
  string = toString$1(string);
  return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, escapeHtmlChar) : string;
}
var _escape = escape$1;

/** Used to match template delimiters. */
var reEscape$1 = /<%-([\s\S]+?)%>/g;
var _reEscape = reEscape$1;

/** Used to match template delimiters. */
var reEvaluate$1 = /<%([\s\S]+?)%>/g;
var _reEvaluate = reEvaluate$1;

var escape = _escape,
  reEscape = _reEscape,
  reEvaluate = _reEvaluate,
  reInterpolate$1 = _reInterpolate;

/**
 * By default, the template delimiters used by lodash are like those in
 * embedded Ruby (ERB) as well as ES2015 template strings. Change the
 * following template settings to use alternative delimiters.
 *
 * @static
 * @memberOf _
 * @type {Object}
 */
var templateSettings$1 = {
  /**
   * Used to detect `data` property values to be HTML-escaped.
   *
   * @memberOf _.templateSettings
   * @type {RegExp}
   */
  'escape': reEscape,
  /**
   * Used to detect code to be evaluated.
   *
   * @memberOf _.templateSettings
   * @type {RegExp}
   */
  'evaluate': reEvaluate,
  /**
   * Used to detect `data` property values to inject.
   *
   * @memberOf _.templateSettings
   * @type {RegExp}
   */
  'interpolate': reInterpolate$1,
  /**
   * Used to reference the data object in the template text.
   *
   * @memberOf _.templateSettings
   * @type {string}
   */
  'variable': '',
  /**
   * Used to import variables into the compiled template.
   *
   * @memberOf _.templateSettings
   * @type {Object}
   */
  'imports': {
    /**
     * A reference to the `lodash` function.
     *
     * @memberOf _.templateSettings.imports
     * @type {Function}
     */
    '_': {
      'escape': escape
    }
  }
};
var templateSettings_1 = templateSettings$1;

var assignInWith = assignInWith_1,
  attempt = attempt_1,
  baseValues = _baseValues,
  customDefaultsAssignIn = _customDefaultsAssignIn,
  escapeStringChar = _escapeStringChar,
  isError = isError_1,
  isIterateeCall = _isIterateeCall,
  keys = keys_1,
  reInterpolate = _reInterpolate,
  templateSettings = templateSettings_1,
  toString = toString_1;

/** Error message constants. */
var INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';

/** Used to match empty string literals in compiled template source. */
var reEmptyStringLeading = /\b__p \+= '';/g,
  reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;

/**
 * Used to validate the `validate` option in `_.template` variable.
 *
 * Forbids characters which could potentially change the meaning of the function argument definition:
 * - "()," (modification of function parameters)
 * - "=" (default value)
 * - "[]{}" (destructuring of function parameters)
 * - "/" (beginning of a comment)
 * - whitespace
 */
var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;

/**
 * Used to match
 * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
 */
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;

/** Used to ensure capturing order of template delimiters. */
var reNoMatch = /($^)/;

/** Used to match unescaped characters in compiled string literals. */
var reUnescapedString = /['\n\r\u2028\u2029\\]/g;

/** Used for built-in method references. */
var objectProto = Object.prototype;

/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;

/**
 * Creates a compiled template function that can interpolate data properties
 * in "interpolate" delimiters, HTML-escape interpolated data properties in
 * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
 * properties may be accessed as free variables in the template. If a setting
 * object is given, it takes precedence over `_.templateSettings` values.
 *
 * **Note:** In the development build `_.template` utilizes
 * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
 * for easier debugging.
 *
 * For more information on precompiling templates see
 * [lodash's custom builds documentation](https://lodash.com/custom-builds).
 *
 * For more information on Chrome extension sandboxes see
 * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
 *
 * @static
 * @since 0.1.0
 * @memberOf _
 * @category String
 * @param {string} [string=''] The template string.
 * @param {Object} [options={}] The options object.
 * @param {RegExp} [options.escape=_.templateSettings.escape]
 *  The HTML "escape" delimiter.
 * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
 *  The "evaluate" delimiter.
 * @param {Object} [options.imports=_.templateSettings.imports]
 *  An object to import into the template as free variables.
 * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
 *  The "interpolate" delimiter.
 * @param {string} [options.sourceURL='templateSources[n]']
 *  The sourceURL of the compiled template.
 * @param {string} [options.variable='obj']
 *  The data object variable name.
 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
 * @returns {Function} Returns the compiled template function.
 * @example
 *
 * // Use the "interpolate" delimiter to create a compiled template.
 * var compiled = _.template('hello <%= user %>!');
 * compiled({ 'user': 'fred' });
 * // => 'hello fred!'
 *
 * // Use the HTML "escape" delimiter to escape data property values.
 * var compiled = _.template('<b><%- value %></b>');
 * compiled({ 'value': '<script>' });
 * // => '<b>&lt;script&gt;</b>'
 *
 * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
 * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
 * compiled({ 'users': ['fred', 'barney'] });
 * // => '<li>fred</li><li>barney</li>'
 *
 * // Use the internal `print` function in "evaluate" delimiters.
 * var compiled = _.template('<% print("hello " + user); %>!');
 * compiled({ 'user': 'barney' });
 * // => 'hello barney!'
 *
 * // Use the ES template literal delimiter as an "interpolate" delimiter.
 * // Disable support by replacing the "interpolate" delimiter.
 * var compiled = _.template('hello ${ user }!');
 * compiled({ 'user': 'pebbles' });
 * // => 'hello pebbles!'
 *
 * // Use backslashes to treat delimiters as plain text.
 * var compiled = _.template('<%= "\\<%- value %\\>" %>');
 * compiled({ 'value': 'ignored' });
 * // => '<%- value %>'
 *
 * // Use the `imports` option to import `jQuery` as `jq`.
 * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
 * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
 * compiled({ 'users': ['fred', 'barney'] });
 * // => '<li>fred</li><li>barney</li>'
 *
 * // Use the `sourceURL` option to specify a custom sourceURL for the template.
 * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
 * compiled(data);
 * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
 *
 * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
 * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
 * compiled.source;
 * // => function(data) {
 * //   var __t, __p = '';
 * //   __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
 * //   return __p;
 * // }
 *
 * // Use custom template delimiters.
 * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
 * var compiled = _.template('hello {{ user }}!');
 * compiled({ 'user': 'mustache' });
 * // => 'hello mustache!'
 *
 * // Use the `source` property to inline compiled templates for meaningful
 * // line numbers in error messages and stack traces.
 * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
 *   var JST = {\
 *     "main": ' + _.template(mainText).source + '\
 *   };\
 * ');
 */
function template(string, options, guard) {
  // Based on John Resig's `tmpl` implementation
  // (http://ejohn.org/blog/javascript-micro-templating/)
  // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  var settings = templateSettings.imports._.templateSettings || templateSettings;
  if (guard && isIterateeCall(string, options, guard)) {
    options = undefined;
  }
  string = toString(string);
  options = assignInWith({}, options, settings, customDefaultsAssignIn);
  var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
    importsKeys = keys(imports),
    importsValues = baseValues(imports, importsKeys);
  var isEscaping,
    isEvaluating,
    index = 0,
    interpolate = options.interpolate || reNoMatch,
    source = "__p += '";

  // Compile the regexp to match each delimiter.
  var reDelimiters = RegExp((options.escape || reNoMatch).source + '|' + interpolate.source + '|' + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + (options.evaluate || reNoMatch).source + '|$', 'g');

  // Use a sourceURL for easier debugging.
  // The sourceURL gets injected into the source that's eval-ed, so be careful
  // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  // and escape the comment, thus injecting code that gets evaled.
  var sourceURL = hasOwnProperty.call(options, 'sourceURL') ? '//# sourceURL=' + (options.sourceURL + '').replace(/\s/g, ' ') + '\n' : '';
  string.replace(reDelimiters, function (match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
    interpolateValue || (interpolateValue = esTemplateValue);

    // Escape characters that can't be included in string literals.
    source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);

    // Replace delimiters with snippets.
    if (escapeValue) {
      isEscaping = true;
      source += "' +\n__e(" + escapeValue + ") +\n'";
    }
    if (evaluateValue) {
      isEvaluating = true;
      source += "';\n" + evaluateValue + ";\n__p += '";
    }
    if (interpolateValue) {
      source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
    }
    index = offset + match.length;

    // The JS engine embedded in Adobe products needs `match` returned in
    // order to produce the correct `offset` value.
    return match;
  });
  source += "';\n";

  // If `variable` is not specified wrap a with-statement around the generated
  // code to add the data object to the top of the scope chain.
  var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  if (!variable) {
    source = 'with (obj) {\n' + source + '\n}\n';
  }
  // Throw an error if a forbidden character was found in `variable`, to prevent
  // potential command injection attacks.
  else if (reForbiddenIdentifierChars.test(variable)) {
    throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  }

  // Cleanup code by stripping empty strings.
  source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source).replace(reEmptyStringMiddle, '$1').replace(reEmptyStringTrailing, '$1;');

  // Frame code as the function body.
  source = 'function(' + (variable || 'obj') + ') {\n' + (variable ? '' : 'obj || (obj = {});\n') + "var __t, __p = ''" + (isEscaping ? ', __e = _.escape' : '') + (isEvaluating ? ', __j = Array.prototype.join;\n' + "function print() { __p += __j.call(arguments, '') }\n" : ';\n') + source + 'return __p\n}';
  var result = attempt(function () {
    return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  });

  // Provide the compiled function's source by its `toString` method or
  // the `source` property as a convenience for inlining compiled templates.
  result.source = source;
  if (isError(result)) {
    throw result;
  }
  return result;
}
var template_1 = template;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _FormItem = defineComponent({
  name: "TFormItem",
  props: _objectSpread({}, props),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var renderContent = useTNodeJSX();
    var CLASS_NAMES = useCLASSNAMES();
    var _useConfig = useConfig("form"),
      globalConfig = _useConfig.globalConfig;
    var _useGlobalIcon = useGlobalIcon({
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        CloseCircleFilledIcon: CloseCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon
      }),
      CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
      CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon;
    var form = inject(FormInjectionKey, void 0);
    var FORM_ITEM_CLASS_PREFIX = usePrefixClass("form-item__");
    var needRequiredMark = computed(function () {
      var _ref2, _props2$requiredMark;
      var requiredMark = (_ref2 = (_props2$requiredMark = props2.requiredMark) !== null && _props2$requiredMark !== void 0 ? _props2$requiredMark : form === null || form === void 0 ? void 0 : form.requiredMark) !== null && _ref2 !== void 0 ? _ref2 : globalConfig.value.requiredMark;
      var isRequired = innerRules.value.filter(function (rule) {
        return rule.required;
      }).length > 0;
      return requiredMark !== null && requiredMark !== void 0 ? requiredMark : isRequired;
    });
    var hasLabel = computed(function () {
      return slots.label || props2.label;
    });
    var hasColon = computed(function () {
      return !!(form !== null && form !== void 0 && form.colon && hasLabel.value);
    });
    var FROM_LABEL = usePrefixClass("form__label");
    var labelAlign = computed(function () {
      return isNil_1(props2.labelAlign) ? form === null || form === void 0 ? void 0 : form.labelAlign : props2.labelAlign;
    });
    var labelWidth = computed(function () {
      return isNil_1(props2.labelWidth) ? form === null || form === void 0 ? void 0 : form.labelWidth : props2.labelWidth;
    });
    var labelClasses = computed(function () {
      var _ref3;
      return [CLASS_NAMES.value.label, (_ref3 = {}, _defineProperty(_ref3, "".concat(FROM_LABEL.value, "--required"), needRequiredMark.value), _defineProperty(_ref3, "".concat(FROM_LABEL.value, "--colon"), hasColon.value), _defineProperty(_ref3, "".concat(FROM_LABEL.value, "--top"), hasLabel.value && (labelAlign.value === "top" || !labelWidth.value)), _defineProperty(_ref3, "".concat(FROM_LABEL.value, "--left"), labelAlign.value === "left" && labelWidth.value), _defineProperty(_ref3, "".concat(FROM_LABEL.value, "--right"), labelAlign.value === "right" && labelWidth.value), _ref3)];
    });
    var renderLabel = function renderLabel() {
      if (Number(labelWidth.value) === 0) return;
      var labelStyle = {};
      if (labelWidth.value && labelAlign.value !== "top") {
        if (isNumber_1(labelWidth.value)) labelStyle = {
          width: "".concat(labelWidth.value, "px")
        };else labelStyle = {
          width: labelWidth.value
        };
      }
      return createVNode("div", {
        "class": labelClasses.value,
        "style": labelStyle
      }, [createVNode("label", {
        "for": props2["for"]
      }, [renderContent("label")])]);
    };
    var getDefaultIcon = function getDefaultIcon() {
      var resultIcon = function resultIcon(Icon) {
        return createVNode("span", {
          "class": CLASS_NAMES.value.status
        }, [createVNode(Icon, null, null)]);
      };
      var list = errorList.value;
      if (verifyStatus.value === ValidateStatus.SUCCESS) return resultIcon(CheckCircleFilledIcon$1);
      if (list !== null && list !== void 0 && list[0]) {
        var type = list[0].type || "error";
        var icon = {
          error: CloseCircleFilledIcon$1,
          warning: ErrorCircleFilledIcon$1
        }[type] || CheckCircleFilledIcon$1;
        return resultIcon(icon);
      }
      return null;
    };
    var renderSuffixIcon = function renderSuffixIcon() {
      var statusIcon = props2.statusIcon;
      if (statusIcon === false) return;
      var resultIcon = renderContent("statusIcon", {
        defaultNode: getDefaultIcon()
      });
      if (resultIcon) return createVNode("span", {
        "class": CLASS_NAMES.value.status
      }, [resultIcon]);
      if (resultIcon === false) return;
      resultIcon = form === null || form === void 0 ? void 0 : form.renderContent("statusIcon", {
        defaultNode: getDefaultIcon()
      });
      if (resultIcon) return resultIcon;
    };
    var errorClasses = computed(function () {
      if (!showErrorMessage.value) return "";
      if (verifyStatus.value === ValidateStatus.SUCCESS) {
        return props2.successBorder ? [CLASS_NAMES.value.success, CLASS_NAMES.value.successBorder].join(" ") : CLASS_NAMES.value.success;
      }
      if (!errorList.value.length) return;
      var type = errorList.value[0].type || "error";
      return type === "error" ? CLASS_NAMES.value.error : CLASS_NAMES.value.warning;
    });
    var contentClasses = computed(function () {
      return [CLASS_NAMES.value.controls, errorClasses.value];
    });
    var contentStyle = computed(function () {
      var contentStyle2 = {};
      if (labelWidth.value && labelAlign.value !== "top") {
        if (isNumber_1(labelWidth.value)) contentStyle2 = {
          marginLeft: "".concat(labelWidth.value, "px")
        };else contentStyle2 = {
          marginLeft: labelWidth.value
        };
      }
      return contentStyle2;
    });
    var errorList = ref([]);
    var successList = ref([]);
    var verifyStatus = ref(ValidateStatus.TO_BE_VALIDATED);
    var resetValidating = ref(false);
    var needResetField = ref(false);
    var resetHandler = function resetHandler() {
      needResetField.value = false;
      errorList.value = [];
      successList.value = [];
      verifyStatus.value = ValidateStatus.TO_BE_VALIDATED;
    };
    var getEmptyValue = function getEmptyValue() {
      var type = Object.prototype.toString.call(get_1(form === null || form === void 0 ? void 0 : form.data, props2.name));
      var emptyValue;
      if (type === "[object String]") emptyValue = "";
      if (type === "[object Array]") emptyValue = [];
      if (type === "[object Object]") emptyValue = {};
      return emptyValue;
    };
    var resetField = /*#__PURE__*/function () {
      var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
        var resetType,
          _args = arguments;
        return regenerator.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              resetType = _args.length > 0 && _args[0] !== undefined ? _args[0] : form === null || form === void 0 ? void 0 : form.resetType;
              if (props2.name) {
                _context.next = 3;
                break;
              }
              return _context.abrupt("return");
            case 3:
              if (resetType === "empty") set_1(form === null || form === void 0 ? void 0 : form.data, props2.name, getEmptyValue());else if (resetType === "initial") set_1(form === null || form === void 0 ? void 0 : form.data, props2.name, initialValue.value);
              _context.next = 6;
              return nextTick();
            case 6:
              if (resetValidating.value) needResetField.value = true;else resetHandler();
            case 7:
            case "end":
              return _context.stop();
          }
        }, _callee);
      }));
      return function resetField() {
        return _ref4.apply(this, arguments);
      };
    }();
    var errorMessages = computed(function () {
      var _form$errorMessage;
      return (_form$errorMessage = form === null || form === void 0 ? void 0 : form.errorMessage) !== null && _form$errorMessage !== void 0 ? _form$errorMessage : globalConfig.value.errorMessage;
    });
    var innerRules = computed(function () {
      var _props2$rules;
      if ((_props2$rules = props2.rules) !== null && _props2$rules !== void 0 && _props2$rules.length) return props2.rules;
      if (!props2.name) return [];
      var index = "".concat(props2.name).lastIndexOf(".") || -1;
      var pRuleName = "".concat(props2.name).slice(index + 1);
      return get_1(form === null || form === void 0 ? void 0 : form.rules, props2.name) || get_1(form === null || form === void 0 ? void 0 : form.rules, pRuleName) || [];
    });
    var analysisValidateResult = /*#__PURE__*/function () {
      var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(trigger) {
        var _result$rules;
        var result;
        return regenerator.wrap(function _callee2$(_context2) {
          while (1) switch (_context2.prev = _context2.next) {
            case 0:
              result = {
                successList: [],
                errorList: [],
                rules: [],
                resultList: [],
                allowSetValue: false
              };
              result.rules = trigger === "all" ? innerRules.value : innerRules.value.filter(function (item) {
                return (item.trigger || "change") === trigger;
              });
              if (!(innerRules.value.length && !((_result$rules = result.rules) !== null && _result$rules !== void 0 && _result$rules.length))) {
                _context2.next = 4;
                break;
              }
              return _context2.abrupt("return", result);
            case 4:
              result.allowSetValue = true;
              _context2.next = 7;
              return validate(value.value, result.rules);
            case 7:
              result.resultList = _context2.sent;
              result.errorList = result.resultList.filter(function (item) {
                return item.result !== true;
              }).map(function (item) {
                Object.keys(item).forEach(function (key) {
                  if (!item.message && errorMessages.value[key]) {
                    var compiled = template_1(errorMessages.value[key]);
                    var name2 = isString_1(props2.label) ? props2.label : props2.name;
                    item.message = compiled({
                      name: name2,
                      validate: item[key]
                    });
                  }
                });
                return item;
              });
              result.successList = result.resultList.filter(function (item) {
                return item.result === true && item.message && item.type === "success";
              });
              return _context2.abrupt("return", result);
            case 11:
            case "end":
              return _context2.stop();
          }
        }, _callee2);
      }));
      return function analysisValidateResult(_x) {
        return _ref5.apply(this, arguments);
      };
    }();
    var validateHandler = /*#__PURE__*/function () {
      var _ref6 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(trigger, showErrorMessage2) {
        var _yield$analysisValida, innerSuccessList, innerErrorList, rules, resultList, allowSetValue;
        return regenerator.wrap(function _callee3$(_context3) {
          while (1) switch (_context3.prev = _context3.next) {
            case 0:
              resetValidating.value = true;
              freeShowErrorMessage.value = showErrorMessage2;
              _context3.next = 4;
              return analysisValidateResult(trigger);
            case 4:
              _yield$analysisValida = _context3.sent;
              innerSuccessList = _yield$analysisValida.successList;
              innerErrorList = _yield$analysisValida.errorList;
              rules = _yield$analysisValida.rules;
              resultList = _yield$analysisValida.resultList;
              allowSetValue = _yield$analysisValida.allowSetValue;
              if (allowSetValue) {
                successList.value = innerSuccessList;
                errorList.value = innerErrorList;
              }
              if (rules.length) verifyStatus.value = innerErrorList.length ? ValidateStatus.FAIL : ValidateStatus.SUCCESS;
              if (needResetField.value) resetHandler();
              resetValidating.value = false;
              return _context3.abrupt("return", _defineProperty({}, props2.name, innerErrorList.length === 0 ? true : resultList));
            case 15:
            case "end":
              return _context3.stop();
          }
        }, _callee3);
      }));
      return function validateHandler(_x2, _x3) {
        return _ref6.apply(this, arguments);
      };
    }();
    var validateOnly = /*#__PURE__*/function () {
      var _ref8 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(trigger) {
        var _yield$analysisValida2, innerErrorList, resultList;
        return regenerator.wrap(function _callee4$(_context4) {
          while (1) switch (_context4.prev = _context4.next) {
            case 0:
              _context4.next = 2;
              return analysisValidateResult(trigger);
            case 2:
              _yield$analysisValida2 = _context4.sent;
              innerErrorList = _yield$analysisValida2.errorList;
              resultList = _yield$analysisValida2.resultList;
              return _context4.abrupt("return", _defineProperty({}, props2.name, innerErrorList.length === 0 ? true : resultList));
            case 6:
            case "end":
              return _context4.stop();
          }
        }, _callee4);
      }));
      return function validateOnly(_x4) {
        return _ref8.apply(this, arguments);
      };
    }();
    var setValidateMessage = function setValidateMessage(validateMessage) {
      if (!validateMessage && !isArray_1(validateMessage)) return;
      if (validateMessage.length === 0) {
        errorList.value = [];
        verifyStatus.value = ValidateStatus.SUCCESS;
      }
      errorList.value = validateMessage.map(function (item) {
        return _objectSpread(_objectSpread({}, item), {}, {
          result: false
        });
      });
      verifyStatus.value = ValidateStatus.FAIL;
    };
    var value = computed(function () {
      return (form === null || form === void 0 ? void 0 : form.data) && get_1(form === null || form === void 0 ? void 0 : form.data, props2.name);
    });
    var initialValue = ref(void 0);
    var _toRefs = toRefs(props2),
      name = _toRefs.name;
    var context = reactive({
      name: name,
      resetHandler: resetHandler,
      resetField: resetField,
      validate: validateHandler,
      validateOnly: validateOnly,
      setValidateMessage: setValidateMessage
    });
    onMounted(function () {
      initialValue.value = cloneDeep_1(value.value);
      form === null || form === void 0 ? void 0 : form.children.push(context);
    });
    onBeforeUnmount(function () {
      if (form) form.children = form === null || form === void 0 ? void 0 : form.children.filter(function (ctx) {
        return ctx !== context;
      });
    });
    watch(value, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
      return regenerator.wrap(function _callee5$(_context5) {
        while (1) switch (_context5.prev = _context5.next) {
          case 0:
            _context5.next = 2;
            return validateHandler("change");
          case 2:
          case "end":
            return _context5.stop();
        }
      }, _callee5);
    })), {
      deep: true
    });
    watch(function () {
      return [props2.name, JSON.stringify(props2.rules)].join(",");
    }, function () {
      validateHandler("change");
    });
    var freeShowErrorMessage = ref(void 0);
    var showErrorMessage = computed(function () {
      if (isBoolean_1(freeShowErrorMessage.value)) return freeShowErrorMessage.value;
      if (isBoolean_1(props2.showErrorMessage)) return props2.showErrorMessage;
      return form === null || form === void 0 ? void 0 : form.showErrorMessage;
    });
    var classes = computed(function () {
      var _ref11;
      return [CLASS_NAMES.value.formItem, FORM_ITEM_CLASS_PREFIX.value + (props2.name || ""), (_ref11 = {}, _defineProperty(_ref11, CLASS_NAMES.value.formItemWithHelp, helpNode.value), _defineProperty(_ref11, CLASS_NAMES.value.formItemWithExtra, extraNode.value), _ref11)];
    });
    var helpNode = computed(function () {
      var help = renderContent("help");
      if (help) return createVNode("div", {
        "class": CLASS_NAMES.value.help
      }, [help]);
      return null;
    });
    var extraNode = computed(function () {
      var _list$;
      var getExtraNode = function getExtraNode(content) {
        return createVNode("div", {
          "class": CLASS_NAMES.value.extra
        }, [content]);
      };
      var list = errorList.value;
      if (showErrorMessage.value && list !== null && list !== void 0 && (_list$ = list[0]) !== null && _list$ !== void 0 && _list$.message) return getExtraNode(list[0].message);
      if (successList.value.length) return getExtraNode(successList.value[0].message);
      return null;
    });
    var handleBlur = /*#__PURE__*/function () {
      var _ref12 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
        return regenerator.wrap(function _callee6$(_context6) {
          while (1) switch (_context6.prev = _context6.next) {
            case 0:
              _context6.next = 2;
              return validateHandler("blur");
            case 2:
            case "end":
              return _context6.stop();
          }
        }, _callee6);
      }));
      return function handleBlur() {
        return _ref12.apply(this, arguments);
      };
    }();
    provide(FormItemInjectionKey, {
      handleBlur: handleBlur
    });
    return function () {
      return createVNode("div", {
        "class": classes.value
      }, [renderLabel(), createVNode("div", {
        "class": contentClasses.value,
        "style": contentStyle.value
      }, [createVNode("div", {
        "class": CLASS_NAMES.value.controlsContent
      }, [renderContent("default"), renderSuffixIcon()]), [helpNode.value, extraNode.value]])]);
    };
  }
});

export { _FormItem as default };
//# sourceMappingURL=form-item.mjs.map
