"use strict";
const uni_modules_tdesignUniapp_components_common_validator = require("../common/validator.js");
const uni_modules_tdesignUniapp_components_common_src_instantiationDecorator = require("../common/src/instantiationDecorator.js");
const uni_modules_tdesignUniapp_components_common_config = require("../common/config.js");
const uni_modules_tdesignUniapp_components_input_props = require("./props.js");
const uni_modules_tdesignUniapp_components_common_utils = require("../common/utils.js");
const uni_modules_tdesignUniapp_components_input_computed = require("./computed.js");
const uni_modules_tdesignUniapp_components_common_utils_wxs = require("../common/utils.wxs.js");
const uni_modules_tdesignUniapp_components_common_relation_parentMap = require("../common/relation/parent-map.js");
const common_vendor = require("../../../../common/vendor.js");
const TIcon = () => "../icon/icon.js";
const name = `${uni_modules_tdesignUniapp_components_common_config.prefix}-input`;
const _sfc_main = uni_modules_tdesignUniapp_components_common_src_instantiationDecorator.uniComponent({
  name,
  options: {
    styleIsolation: "shared"
  },
  inject: {
    [uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey]: {
      default: null
    }
  },
  externalClasses: [
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-prefix-icon`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-label`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-input`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-clearable`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-suffix`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-suffix-icon`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-tips`
  ],
  components: {
    TIcon
  },
  props: {
    ...uni_modules_tdesignUniapp_components_input_props.props
  },
  emits: [
    "blur",
    "change",
    "clear",
    "click",
    "enter",
    "focus",
    "keyboardheightchange",
    "nicknamereview",
    "validate",
    "update:value"
  ],
  data() {
    return {
      prefix: uni_modules_tdesignUniapp_components_common_config.prefix,
      classPrefix: name,
      classBasePrefix: uni_modules_tdesignUniapp_components_common_config.prefix,
      showClearIcon: true,
      tools: uni_modules_tdesignUniapp_components_common_utils_wxs.tools,
      dataValue: uni_modules_tdesignUniapp_components_common_utils.coalesce(this.value, this.defaultValue)
      // rawValue: '',
      // innerMaxLen: -1,
    };
  },
  computed: {},
  watch: {
    prefixIcon: {
      handler(v) {
        this._prefixIcon = uni_modules_tdesignUniapp_components_common_utils.calcIcon(v);
      },
      immediate: true
    },
    suffixIcon: {
      handler(v) {
        this._suffixIcon = uni_modules_tdesignUniapp_components_common_utils.calcIcon(v);
      },
      immediate: true
    },
    clearable: {
      handler(v) {
        this._clearIcon = uni_modules_tdesignUniapp_components_common_utils.calcIcon(v, "close-circle-filled");
      },
      immediate: true
    },
    clearTrigger: "updateClearIconVisible",
    disabled: "updateClearIconVisible",
    readonly: "updateClearIconVisible",
    value: {
      handler(v) {
        this.dataValue = v;
        uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
          this.dataValue = v;
          if (this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey] && this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey].onValueChange) {
            this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey].onValueChange(v);
          }
        });
      }
    }
  },
  mounted() {
    const { value, defaultValue } = this;
    this.updateValue(uni_modules_tdesignUniapp_components_common_utils.coalesce(value, defaultValue, ""));
    this.updateClearIconVisible();
  },
  methods: {
    getInputClass: uni_modules_tdesignUniapp_components_input_computed.getInputClass,
    updateValue(value) {
      this.dataValue = value;
      const { allowInputOverMax, maxcharacter, maxlength } = this;
      if (!allowInputOverMax && maxcharacter && maxcharacter > 0 && !Number.isNaN(maxcharacter)) {
        const { length, characters } = uni_modules_tdesignUniapp_components_common_utils.getCharacterLength("maxcharacter", value, maxcharacter);
        uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
          this.dataValue = characters;
        });
        this.count = length;
      } else if (!allowInputOverMax && maxlength && maxlength > 0 && !Number.isNaN(maxlength)) {
        const { length, characters } = uni_modules_tdesignUniapp_components_common_utils.getCharacterLength("maxlength", value, maxlength);
        uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
          this.dataValue = characters;
        });
        this.count = length;
      } else {
        uni_modules_tdesignUniapp_components_common_utils.nextTick().then(() => {
          this.dataValue = value;
        });
        this.dataValue = value;
        this.count = uni_modules_tdesignUniapp_components_common_validator.isDef(value) ? String(value).length : 0;
      }
    },
    // updateInnerMaxLen() {
    // this.innerMaxLen = this.getInnerMaxLen();
    // },
    // getInnerMaxLen() {
    //   const {
    //     allowInputOverMax,
    //     maxcharacter,
    //     maxlength,
    //     dataValue,
    //     rawValue,
    //     count,
    //   } = this;
    //   return getInnerMaxLen({
    //     allowInputOverMax,
    //     maxcharacter,
    //     maxlength,
    //     dataValue,
    //     rawValue,
    //     count,
    //   });
    // },
    updateClearIconVisible(value = false) {
      const { clearTrigger, disabled, readonly } = this;
      if (disabled || readonly) {
        this.showClearIcon = false;
        return;
      }
      this.showClearIcon = value || clearTrigger === "always";
    },
    onInput(e) {
      const { value, cursor, keyCode } = e.detail;
      this.updateValue(value);
      this.emitChange({ value: this.dataValue, cursor, keyCode });
    },
    onChange(e) {
      if (this.type !== "nickname")
        return;
      const { value } = e.detail;
      this.updateValue(value);
      this.emitChange({ value: this.dataValue });
    },
    emitChange(data) {
      this.$emit("change", data);
      this.$emit("update:value", data.value);
    },
    onFocus(e) {
      this.updateClearIconVisible(true);
      this.$emit("focus", e.detail);
    },
    onBlur(e) {
      this.updateClearIconVisible();
      if (this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey] && this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey].onBlur) {
        this[uni_modules_tdesignUniapp_components_common_relation_parentMap.RELATION_MAP.FormKey].onBlur(this.dataValue);
      }
      if (typeof this.format === "function") {
        const v = this.format(e.detail.value);
        this.updateValue(v);
        this.$emit("blur", { value: this.dataValue, cursor: this.count });
        return;
      }
      this.$emit("blur", e.detail);
    },
    onConfirm(e) {
      this.$emit("enter", e.detail);
    },
    onSuffixClick() {
      this.$emit("click", { trigger: "suffix" });
    },
    onSuffixIconClick() {
      this.$emit("click", { trigger: "suffix-icon" });
    },
    clearInput(e) {
      this.$emit("clear", e.detail);
      this.dataValue = "";
    },
    onKeyboardHeightChange(e) {
      this.$emit("keyboardheightchange", e.detail);
    },
    onNickNameReview(e) {
      this.$emit("nicknamereview", e.detail);
    },
    onClick() {
      this.$emit("click", { trigger: "input" });
    }
  }
});
if (!Array) {
  const _easycom_t_icon2 = common_vendor.resolveComponent("t-icon");
  _easycom_t_icon2();
}
const _easycom_t_icon = () => "../icon/icon.js";
if (!Math) {
  _easycom_t_icon();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: _ctx._prefixIcon
  }, _ctx._prefixIcon ? {
    b: common_vendor.o(($event) => _ctx._prefixIcon.click || ""),
    c: common_vendor.p({
      ["custom-style"]: _ctx._prefixIcon.style || "",
      ["t-class"]: _ctx.tClassPrefixIcon,
      prefix: _ctx._prefixIcon.prefix,
      name: _ctx._prefixIcon.name,
      size: _ctx._prefixIcon.size,
      color: _ctx._prefixIcon.color,
      ["aria-hidden"]: true,
      ["aria-label"]: _ctx._prefixIcon.ariaLabel,
      ["aria-role"]: _ctx._prefixIcon.ariaRole
    })
  } : {}, {
    d: common_vendor.n(_ctx.classPrefix + "__icon--prefix"),
    e: _ctx.label
  }, _ctx.label ? {
    f: common_vendor.t(_ctx.label)
  } : {}, {
    g: common_vendor.n(_ctx.classPrefix + "__label " + _ctx.tClassLabel),
    h: common_vendor.n(_ctx.classPrefix + "__wrap--prefix"),
    i: common_vendor.n(_ctx.getInputClass(_ctx.classPrefix, _ctx.suffix, _ctx.align, _ctx.disabled) + " " + _ctx.tClassInput),
    j: _ctx.allowInputOverMax ? -1 : _ctx.maxlength,
    k: _ctx.disabled || _ctx.readonly,
    l: _ctx.placeholder,
    m: _ctx.placeholderStyle,
    n: _ctx.tools.cls(_ctx.classPrefix + "__placeholder", [["disabled", _ctx.disabled]]) + " " + _ctx.placeholderClass,
    o: _ctx.dataValue,
    p: _ctx.type === "password",
    q: _ctx.type === "password" ? "text" : _ctx.type,
    r: _ctx.focus,
    s: _ctx.confirmType,
    t: _ctx.confirmHold,
    v: _ctx.cursor,
    w: _ctx.cursorColor,
    x: _ctx.cursorSpacing,
    y: _ctx.adjustPosition,
    z: _ctx.autoFocus,
    A: _ctx.alwaysEmbed,
    B: _ctx.selectionStart,
    C: _ctx.selectionEnd,
    D: _ctx.holdKeyboard,
    E: _ctx.safePasswordCertPath,
    F: _ctx.safePasswordLength,
    G: _ctx.safePasswordTimeStamp,
    H: _ctx.safePasswordNonce,
    I: _ctx.safePasswordSalt,
    J: _ctx.safePasswordCustomHash,
    K: _ctx.label,
    L: _ctx.label,
    M: common_vendor.o((...args) => _ctx.onInput && _ctx.onInput(...args)),
    N: common_vendor.o((...args) => _ctx.onChange && _ctx.onChange(...args)),
    O: common_vendor.o((...args) => _ctx.onFocus && _ctx.onFocus(...args)),
    P: common_vendor.o((...args) => _ctx.onBlur && _ctx.onBlur(...args)),
    Q: common_vendor.o((...args) => _ctx.onConfirm && _ctx.onConfirm(...args)),
    R: common_vendor.o((...args) => _ctx.onKeyboardHeightChange && _ctx.onKeyboardHeightChange(...args)),
    S: common_vendor.o((...args) => _ctx.onNickNameReview && _ctx.onNickNameReview(...args)),
    T: _ctx._clearIcon && _ctx.dataValue && _ctx.dataValue.length && _ctx.showClearIcon
  }, _ctx._clearIcon && _ctx.dataValue && _ctx.dataValue.length && _ctx.showClearIcon ? {
    U: common_vendor.o(($event) => _ctx._clearIcon.click || ""),
    V: common_vendor.p({
      ["custom-style"]: _ctx._clearIcon.style || "",
      ["t-class"]: _ctx.tClassClearable,
      prefix: _ctx._clearIcon.prefix,
      name: _ctx._clearIcon.name,
      size: _ctx._clearIcon.size,
      color: _ctx._clearIcon.color,
      ["aria-hidden"]: false,
      ["aria-label"]: _ctx._clearIcon.ariaLabel || "清除",
      ["aria-role"]: _ctx._clearIcon.ariaRole || "button"
    }),
    W: common_vendor.n(_ctx.classPrefix + "__wrap--clearable-icon"),
    X: common_vendor.o((...args) => _ctx.clearInput && _ctx.clearInput(...args))
  } : {}, {
    Y: _ctx.suffix
  }, _ctx.suffix ? {
    Z: common_vendor.t(_ctx.suffix)
  } : {}, {
    aa: common_vendor.n(_ctx.classPrefix + "__wrap--suffix " + _ctx.tClassSuffix),
    ab: common_vendor.o((...args) => _ctx.onSuffixClick && _ctx.onSuffixClick(...args)),
    ac: _ctx._suffixIcon
  }, _ctx._suffixIcon ? {
    ad: common_vendor.o(($event) => _ctx._suffixIcon.click || ""),
    ae: common_vendor.p({
      ["custom-style"]: _ctx._suffixIcon.style || "",
      ["t-class"]: _ctx.tClassSuffixIcon,
      prefix: _ctx._suffixIcon.prefix,
      name: _ctx._suffixIcon.name,
      size: _ctx._suffixIcon.size,
      color: _ctx._suffixIcon.color,
      ["aria-hidden"]: true,
      ["aria-label"]: _ctx._suffixIcon.ariaLabel,
      ["aria-role"]: _ctx._suffixIcon.ariaRole || "button"
    })
  } : {}, {
    af: common_vendor.n(_ctx.classPrefix + "__wrap--suffix-icon"),
    ag: common_vendor.o((...args) => _ctx.onSuffixIconClick && _ctx.onSuffixIconClick(...args)),
    ah: common_vendor.n(_ctx.classPrefix + "__content " + _ctx.classPrefix + "--" + _ctx.status),
    ai: common_vendor.o((...args) => _ctx.onClick && _ctx.onClick(...args)),
    aj: _ctx.tips && _ctx.tips.length > 0
  }, _ctx.tips && _ctx.tips.length > 0 ? {
    ak: common_vendor.t(_ctx.tips),
    al: common_vendor.n(_ctx.classPrefix + "__tips " + _ctx.classPrefix + "--" + _ctx.align + " " + _ctx.tClassTips)
  } : {}, {
    am: common_vendor.n(_ctx.classPrefix + "__wrap"),
    an: common_vendor.s(_ctx.tools._style([_ctx.customStyle])),
    ao: common_vendor.n(_ctx.tools.cls(_ctx.classPrefix, [["border", !_ctx.borderless], ["readonly", _ctx.readonly], ["disabled", _ctx.disabled]]) + " " + _ctx.classPrefix + "--layout-" + _ctx.layout + " " + _ctx.tClass)
  });
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-bdad3b11"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/input/input.js.map
