/**
 * Easyinput 输入框
 * @description 此组件可以实现表单的输入与校验，包括 "text" 和 "textarea" 类型。
 * @tutorial https://ext.dcloud.net.cn/plugin?id=3455
 * @property {String}	value	输入内容
 * @property {String }	type	输入框的类型（默认text） password/text/textarea/..
 * 	@value text			文本输入键盘
 * 	@value textarea	多行文本输入键盘
 * 	@value password	密码输入键盘
 * 	@value number		数字输入键盘，注意iOS上app-vue弹出的数字键盘并非9宫格方式
 * 	@value idcard		身份证输入键盘，信、支付宝、百度、QQ小程序
 * 	@value digit		带小数点的数字键盘	，App的nvue页面、微信、支付宝、百度、头条、QQ小程序支持
 * @property {Boolean}	clearable	是否显示右侧清空内容的图标控件，点击可清空输入框内容（默认true）
 * @property {Boolean}	autoHeight	是否自动增高输入区域，type为textarea时有效（默认true）
 * @property {String }	placeholder	输入框的提示文字
 * @property {String }	placeholderStyle	placeholder的样式(内联样式，字符串)，如"color: #ddd"
 * @property {Boolean}	focus	是否自动获得焦点（默认false）
 * @property {Boolean}	disabled	是否禁用（默认false）
 * @property {Number }	maxlength	最大输入长度，设置为 -1 的时候不限制最大长度（默认140）
 * @property {String }	confirmType	设置键盘右下角按钮的文字，仅在type="text"时生效（默认done）
 * @property {Number }	clearSize	清除图标的大小，单位px（默认15）
 * @property {String}	prefixIcon	输入框头部图标
 * @property {String}	suffixIcon	输入框尾部图标
 * @property {String}	primaryColor	设置主题色（默认#2979ff）
 * @property {Boolean}	trim	是否自动去除两端的空格
 * @property {Boolean}	cursorSpacing	指定光标与键盘的距离，单位 px
 * @property {Boolean}  ajust-position 当键盘弹起时，是否上推内容，默认值：true
 * @value both	去除两端空格
 * @value left	去除左侧空格
 * @value right	去除右侧空格
 * @value start	去除左侧空格
 * @value end		去除右侧空格
 * @value all		去除全部空格
 * @value none	不去除空格
 * @property {Boolean}	inputBorder	是否显示input输入框的边框（默认true）
 * @property {Boolean}	passwordIcon	type=password时是否显示小眼睛图标
 * @property {Object}	styles	自定义颜色
 * @event {Function}	input	输入框内容发生变化时触发
 * @event {Function}	focus	输入框获得焦点时触发
 * @event {Function}	blur	输入框失去焦点时触发
 * @event {Function}	confirm	点击完成按钮时触发
 * @event {Function}	iconClick	点击图标时触发
 * @example <uni-easyinput v-model="mobile"></uni-easyinput>
 */
function obj2strClass(obj): string {
    let classess = '';
    for (let key in obj) {
        const val = obj[key];
        if (val) {
            classess += `${key} `;
        }
    }
    return classess;
}
function obj2strStyle(obj): string {
    let style = '';
    for (let key in obj) {
        const val = obj[key];
        style += `${key}:${val};`;
    }
    return style;
}
const __sfc__ = defineComponent({
    name: 'uni-easyinput',
    emits: [
        'click',
        'iconClick',
        'update:modelValue',
        'input',
        'focus',
        'blur',
        'confirm',
        'clear',
        'eyes',
        'change',
        'keyboardheightchange'
    ],
    model: {
        prop: 'modelValue',
        event: 'update:modelValue'
    },
    options: {
        virtualHost: true
    },
    inject: {
        form: {
            from: 'uniForm',
            default: null
        },
        formItem: {
            from: 'uniFormItem',
            default: null
        }
    },
    props: {
        name: String,
        value: [Number, String],
        modelValue: [Number, String],
        type: {
            type: String,
            default: 'text'
        },
        clearable: {
            type: Boolean,
            default: true
        },
        autoHeight: {
            type: Boolean,
            default: false
        },
        placeholder: {
            type: String,
            default: ' '
        },
        placeholderStyle: String,
        focus: {
            type: Boolean,
            default: false
        },
        disabled: {
            type: Boolean,
            default: false
        },
        maxlength: {
            type: [Number, String],
            default: 140
        },
        confirmType: {
            type: String,
            default: 'done'
        },
        clearSize: {
            type: [Number, String],
            default: 24
        },
        inputBorder: {
            type: Boolean,
            default: true
        },
        prefixIcon: {
            type: String,
            default: ''
        },
        suffixIcon: {
            type: String,
            default: ''
        },
        trim: {
            type: [Boolean, String],
            default: false
        },
        cursorSpacing: {
            type: Number,
            default: 0
        },
        passwordIcon: {
            type: Boolean,
            default: true
        },
        adjustPosition: {
            type: Boolean,
            default: true
        },
        primaryColor: {
            type: String,
            default: '#2979ff'
        },
        styles: {
            type: Object,
            default() {
                return {
                    color: '#333',
                    backgroundColor: '#fff',
                    disableColor: '#F7F6F6',
                    borderColor: '#e5e5e5'
                };
            }
        },
        errorMessage: {
            type: [String, Boolean],
            default: ''
        },
    },
    data() {
        return {
            focused: false,
            val: '',
            showMsg: '',
            border: false,
            isFirstBorder: false,
            showClearIcon: false,
            showPassword: false,
            focusShow: false,
            localMsg: '',
            isEnter: false // 用于判断当前是否是使用回车操作
        };
    },
    computed: {
        // 输入框内是否有值
        isVal(): boolean {
            const val = this.val;
            // fixed by mehaotian 处理值为0的情况，字符串0不在处理范围
            if (val || val === 0) {
                return true;
            }
            return false;
        },
        msg() {
            // console.log('computed', this.form, this.formItem);
            // if (this.form) {
            // 	return this.errorMessage || this.formItem.errMsg;
            // }
            // TODO 处理头条 formItem 中 errMsg 不更新的问题
            return this.localMsg || this.errorMessage;
        },
        // 因为uniapp的input组件的maxlength组件必须要数值，这里转为数值，用户可以传入字符串数值
        inputMaxlength(): number {
            return Number(this.maxlength);
        },
        // 处理外层样式的style
        boxStyle(): string {
            return `color:${this.inputBorder && this.msg ? '#e43d33' : this.styles.color};`;
        },
        // input 内容的类和样式处理
        inputContentClass(): string {
            return obj2strClass({
                'is-input-border': this.inputBorder,
                'is-input-error-border': this.inputBorder && this.msg,
                'is-textarea': this.type === 'textarea',
                'is-disabled': this.disabled,
                'is-focused': this.focusShow
            });
        },
        inputContentStyle(): string {
            const focusColor = this.focusShow ?
                this.primaryColor :
                this.styles.borderColor;
            const borderColor = this.inputBorder && this.msg ? '#dd524d' : focusColor;
            return obj2strStyle({
                'border-color': borderColor || '#e5e5e5',
                'background-color': this.disabled ?
                    this.styles.disableColor : this.styles.backgroundColor
            });
        },
        // input右侧样式
        inputStyle(): string {
            const paddingRight = this.type === 'password' || this.clearable || this.prefixIcon ?
                '' :
                '10px';
            return obj2strStyle({
                'padding-right': paddingRight,
                'padding-left': this.prefixIcon ? '' : '10px'
            });
        }
    },
    watch: {
        value(newVal) {
            // fix by mehaotian 解决 值为null的情况下，input报错的bug
            if (newVal == null) {
                this.val = '';
                return;
            }
            this.val = newVal;
        },
        modelValue(newVal) {
            if (newVal == null) {
                this.val = '';
                return;
            }
            this.val = newVal;
        },
        focus(newVal) {
            this.$nextTick(() => {
                this.focused = this.focus;
                this.focusShow = this.focus;
            });
        }
    },
    created() {
        this.init();
        // TODO 处理头条vue3 computed 不监听 inject 更改的问题（formItem.errMsg）
        if (this.form && this.formItem) {
            this.$watch('formItem.errMsg', newVal => {
                this.localMsg = newVal;
            });
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.focused = this.focus;
            this.focusShow = this.focus;
        });
    },
    methods: {
        /**
         * 初始化变量值
         */
        init() {
            if (this.value || this.value === 0) {
                this.val = this.value;
            }
            else if (this.modelValue ||
                this.modelValue === 0 ||
                this.modelValue === '') {
                this.val = this.modelValue;
            }
            else {
                // fix by ht 如果初始值为null，则input报错，待框架修复
                this.val = '';
            }
        },
        /**
         * 点击图标时触发
         * @param {Object} type
         */
        onClickIcon(type) {
            this.$emit('iconClick', type);
        },
        /**
         * 显示隐藏内容，密码框时生效
         */
        onEyes() {
            this.showPassword = !this.showPassword;
            this.$emit('eyes', this.showPassword);
        },
        /**
         * 输入时触发
         * @param {Object} event
         */
        onInput(event) {
            let value = event.detail.value;
            // 判断是否去除空格
            if (this.trim) {
                if (typeof this.trim === 'boolean' && this.trim) {
                    value = this.trimStr(value);
                }
                if (typeof this.trim === 'string') {
                    value = this.trimStr(value, this.trim);
                }
            }
            if (this.errMsg)
                this.errMsg = '';
            this.val = value;
            // TODO 兼容 vue2
            this.$emit('input', value);
            // TODO　兼容　vue3
            this.$emit('update:modelValue', value);
        },
        /**
         * 外部调用方法
         * 获取焦点时触发
         * @param {Object} event
         */
        onFocus() {
            this.$nextTick(() => {
                this.focused = true;
            });
            this.$emit('focus', null);
        },
        _Focus(event) {
            this.focusShow = true;
            this.$emit('focus', event);
        },
        /**
         * 外部调用方法
         * 失去焦点时触发
         * @param {Object} event
         */
        onBlur() {
            this.focused = false;
            this.$emit('blur', null);
        },
        _Blur(event) {
            let value = event.detail.value;
            this.focusShow = false;
            this.$emit('blur', event);
            // 根据类型返回值，在event中获取的值理论上讲都是string
            if (this.isEnter === false) {
                this.$emit('change', this.val);
            }
            // 失去焦点时参与表单校验
            if (this.form && this.formItem) {
                const { validateTrigger } = this.form;
                if (validateTrigger === 'blur') {
                    this.formItem.onFieldChange();
                }
            }
        },
        /**
         * 按下键盘的发送键
         * @param {Object} e
         */
        onConfirm(e) {
            this.$emit('confirm', this.val);
            this.isEnter = true;
            this.$emit('change', this.val);
            this.$nextTick(() => {
                this.isEnter = false;
            });
        },
        /**
         * 清理内容
         * @param {Object} event
         */
        onClear(event) {
            this.val = '';
            // TODO 兼容 vue2
            this.$emit('input', '');
            // TODO 兼容 vue2
            // TODO　兼容　vue3
            this.$emit('update:modelValue', '');
            // 点击叉号触发
            this.$emit('clear');
        },
        /**
         * 键盘高度发生变化的时候触发此事件
         * 兼容性：微信小程序2.7.0+、App 3.1.0+
         * @param {Object} event
         */
        onkeyboardheightchange(event) {
            this.$emit('keyboardheightchange', event);
        },
        /**
         * 去除空格
         */
        trimStr(str, pos = 'both'): any {
            if (pos === 'both') {
                return str.trim();
            }
            else if (pos === 'left') {
                return str.trimLeft();
            }
            else if (pos === 'right') {
                return str.trimRight();
            }
            else if (pos === 'start') {
                return str.trimStart();
            }
            else if (pos === 'end') {
                return str.trimEnd();
            }
            else if (pos === 'all') {
                return str.replace(/\s+/g, '');
            }
            else if (pos === 'none') {
                return str;
            }
            return str;
        }
    }
});
export default __sfc__;
function GenUniModulesUniEasyinputComponentsUniEasyinputUniEasyinputRender(this: InstanceType<typeof __sfc__>): any | null {
    const _ctx = this;
    const _cache = this.$.renderCache;
    const _component_uni_icons = resolveEasyComponent("uni-icons", _easycom_uni_icons);
    return createElementVNode("view", utsMapOf({
        class: normalizeClass(["uni-easyinput", utsMapOf({ 'uni-easyinput-error': _ctx.msg })]),
        style: normalizeStyle(_ctx.boxStyle)
    }), [
        createElementVNode("view", utsMapOf({
            class: normalizeClass(["uni-easyinput__content", _ctx.inputContentClass]),
            style: normalizeStyle(_ctx.inputContentStyle)
        }), [
            isTrue(_ctx.prefixIcon)
                ? createVNode(_component_uni_icons, utsMapOf({
                    key: 0,
                    class: "content-clear-icon",
                    type: _ctx.prefixIcon,
                    color: "#c0c4cc",
                    onClick: () => { _ctx.onClickIcon('prefix'); },
                    size: "22"
                }), null, 8 /* PROPS */, ["type", "onClick"])
                : createCommentVNode("v-if", true),
            renderSlot(_ctx.$slots, "left"),
            _ctx.type === 'textarea'
                ? createElementVNode("textarea", utsMapOf({
                    key: 1,
                    class: normalizeClass(["uni-easyinput__content-textarea", utsMapOf({ 'input-padding': _ctx.inputBorder })]),
                    name: _ctx.name,
                    value: _ctx.val,
                    placeholder: _ctx.placeholder,
                    placeholderStyle: _ctx.placeholderStyle,
                    disabled: _ctx.disabled,
                    "placeholder-class": "uni-easyinput__placeholder-class",
                    maxlength: _ctx.inputMaxlength,
                    focus: _ctx.focused,
                    autoHeight: _ctx.autoHeight,
                    "cursor-spacing": _ctx.cursorSpacing,
                    "adjust-position": _ctx.adjustPosition,
                    onInput: _ctx.onInput,
                    onBlur: _ctx._Blur,
                    onFocus: _ctx._Focus,
                    onConfirm: _ctx.onConfirm,
                    onKeyboardheightchange: _ctx.onkeyboardheightchange
                }), null, 42 /* CLASS, PROPS, NEED_HYDRATION */, ["name", "value", "placeholder", "placeholderStyle", "disabled", "maxlength", "focus", "autoHeight", "cursor-spacing", "adjust-position", "onInput", "onBlur", "onFocus", "onConfirm", "onKeyboardheightchange"])
                : createElementVNode("input", utsMapOf({
                    key: 2,
                    type: _ctx.type === 'password' ? 'text' : _ctx.type,
                    class: "uni-easyinput__content-input",
                    style: normalizeStyle(_ctx.inputStyle),
                    name: _ctx.name,
                    value: _ctx.val,
                    password: !_ctx.showPassword && _ctx.type === 'password',
                    placeholder: _ctx.placeholder,
                    placeholderStyle: _ctx.placeholderStyle,
                    "placeholder-class": "uni-easyinput__placeholder-class",
                    disabled: _ctx.disabled,
                    maxlength: _ctx.inputMaxlength,
                    focus: _ctx.focused,
                    confirmType: _ctx.confirmType,
                    "cursor-spacing": _ctx.cursorSpacing,
                    "adjust-position": _ctx.adjustPosition,
                    onFocus: _ctx._Focus,
                    onBlur: _ctx._Blur,
                    onInput: _ctx.onInput,
                    onConfirm: _ctx.onConfirm,
                    onKeyboardheightchange: _ctx.onkeyboardheightchange
                }), null, 44 /* STYLE, PROPS, NEED_HYDRATION */, ["type", "name", "value", "password", "placeholder", "placeholderStyle", "disabled", "maxlength", "focus", "confirmType", "cursor-spacing", "adjust-position", "onFocus", "onBlur", "onInput", "onConfirm", "onKeyboardheightchange"]),
            isTrue(_ctx.type === 'password' && _ctx.passwordIcon)
                ? createElementVNode(Fragment, utsMapOf({ key: 3 }), [
                    isTrue(_ctx.isVal)
                        ? createVNode(_component_uni_icons, utsMapOf({
                            key: 0,
                            class: normalizeClass(["content-clear-icon", utsMapOf({ 'is-textarea-icon': _ctx.type === 'textarea' })]),
                            type: _ctx.showPassword ? 'eye-slash-filled' : 'eye-filled',
                            size: 22,
                            color: _ctx.focusShow ? _ctx.primaryColor : '#c0c4cc',
                            onClick: _ctx.onEyes
                        }), null, 8 /* PROPS */, ["class", "type", "color", "onClick"])
                        : createCommentVNode("v-if", true)
                ], 64 /* STABLE_FRAGMENT */)
                : createCommentVNode("v-if", true),
            isTrue(_ctx.suffixIcon)
                ? createElementVNode(Fragment, utsMapOf({ key: 4 }), [
                    isTrue(_ctx.suffixIcon)
                        ? createVNode(_component_uni_icons, utsMapOf({
                            key: 0,
                            class: "content-clear-icon",
                            type: _ctx.suffixIcon,
                            color: "#c0c4cc",
                            onClick: () => { _ctx.onClickIcon('suffix'); },
                            size: "22"
                        }), null, 8 /* PROPS */, ["type", "onClick"])
                        : createCommentVNode("v-if", true)
                ], 64 /* STABLE_FRAGMENT */)
                : createElementVNode(Fragment, utsMapOf({ key: 5 }), [
                    isTrue(_ctx.clearable && _ctx.isVal && !_ctx.disabled && _ctx.type !== 'textarea')
                        ? createVNode(_component_uni_icons, utsMapOf({
                            key: 0,
                            class: normalizeClass(["content-clear-icon", utsMapOf({ 'is-textarea-icon': _ctx.type === 'textarea' })]),
                            type: "clear",
                            size: _ctx.clearSize,
                            color: _ctx.msg ? '#dd524d' : _ctx.focusShow ? _ctx.primaryColor : '#c0c4cc',
                            onClick: _ctx.onClear
                        }), null, 8 /* PROPS */, ["class", "size", "color", "onClick"])
                        : createCommentVNode("v-if", true)
                ], 64 /* STABLE_FRAGMENT */),
            renderSlot(_ctx.$slots, "right")
        ], 6 /* CLASS, STYLE */)
    ], 6 /* CLASS, STYLE */);
}
export type UniEasyinputComponentPublicInstance = InstanceType<typeof __sfc__>;
const GenUniModulesUniEasyinputComponentsUniEasyinputUniEasyinputStyles = [utsMapOf([["uni-easyinput", padStyleMapOf(utsMapOf([["width", "100%"], ["flex", 1], ["position", "relative"], ["textAlign", "left"], ["color", "#333333"], ["fontSize", 14]]))], ["uni-easyinput__content", padStyleMapOf(utsMapOf([["flex", 1], ["width", "100%"], ["display", "flex"], ["boxSizing", "border-box"], ["flexDirection", "row"], ["alignItems", "center"], ["borderColor", "#ffffff"], ["transitionProperty", "borderColor"], ["transitionDuration", "0.3s"]]))], ["uni-easyinput__content-input", padStyleMapOf(utsMapOf([["width", "auto"], ["position", "relative"], ["overflow", "hidden"], ["flex", 1], ["lineHeight", 1], ["fontSize", 14], ["height", 35]]))], ["uni-easyinput__placeholder-class", utsMapOf([["", utsMapOf([["color", "#999999"], ["fontSize", 12]])], [".is-input-error-border ", utsMapOf([["color", "#f29e99"]])], [".is-disabled ", utsMapOf([["color", "#d5d5d5"], ["fontSize", 12]])]])], ["is-textarea", padStyleMapOf(utsMapOf([["alignItems", "flex-start"]]))], ["is-textarea-icon", padStyleMapOf(utsMapOf([["marginTop", 5]]))], ["uni-easyinput__content-textarea", padStyleMapOf(utsMapOf([["position", "relative"], ["overflow", "hidden"], ["flex", 1], ["lineHeight", 1.5], ["fontSize", 14], ["marginTop", 6], ["marginRight", 6], ["marginBottom", 6], ["marginLeft", 0], ["height", 80], ["minHeight", 80], ["width", "auto"]]))], ["input-padding", padStyleMapOf(utsMapOf([["paddingLeft", 10]]))], ["content-clear-icon", padStyleMapOf(utsMapOf([["paddingTop", 0], ["paddingRight", 5], ["paddingBottom", 0], ["paddingLeft", 5]]))], ["label-icon", padStyleMapOf(utsMapOf([["marginRight", 5], ["marginTop", -1]]))], ["is-input-border", padStyleMapOf(utsMapOf([["display", "flex"], ["boxSizing", "border-box"], ["flexDirection", "row"], ["alignItems", "center"], ["borderWidth", 1], ["borderStyle", "solid"], ["borderColor", "#dcdfe6"], ["borderRadius", 4]]))], ["uni-error-message", padStyleMapOf(utsMapOf([["position", "absolute"], ["bottom", -17], ["left", 0], ["lineHeight", "12px"], ["color", "#e43d33"], ["fontSize", 12], ["textAlign", "left"]]))], ["uni-error-msg--boeder", padStyleMapOf(utsMapOf([["position", "relative"], ["bottom", 0], ["lineHeight", "22px"]]))], ["is-input-error-border", padStyleMapOf(utsMapOf([["borderColor", "#e43d33"]]))], ["uni-easyinput--border", padStyleMapOf(utsMapOf([["marginBottom", 0], ["paddingTop", 10], ["paddingRight", 15], ["paddingBottom", 10], ["paddingLeft", 15], ["borderTopWidth", 1], ["borderTopStyle", "solid"], ["borderTopColor", "#eeeeee"]]))], ["uni-easyinput-error", padStyleMapOf(utsMapOf([["paddingBottom", 0]]))], ["is-first-border", padStyleMapOf(utsMapOf([["borderWidth", "medium"], ["borderStyle", "none"], ["borderColor", "#000000"]]))], ["is-disabled", padStyleMapOf(utsMapOf([["backgroundColor", "#f7f6f6"], ["color", "#d5d5d5"]]))], ["@TRANSITION", utsMapOf([["uni-easyinput__content", utsMapOf([["property", "borderColor"], ["duration", "0.3s"]])]])]])];
import _easycom_uni_icons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.uvue';
//# sourceMappingURL=uni-easyinput.vue.map