import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
import Vue from 'vue';
import "../../../src/scss/textarea.scss";
export default Vue.extend({
  name: 'w-textarea',
  props: {
    placeholder: String,
    showCounter: {
      type: Boolean,
      default: true
    },
    rows: {
      type: [Number, String],
      default: 3
    },
    maxLength: {
      type: [Number, String],
      default: 100
    },
    disabled: Boolean,
    readonly: Boolean,
    value: {
      type: String,
      default: ''
    }
  },
  data: function data() {
    return {
      lazyValue: this.value
    };
  },
  computed: {
    length: function length() {
      return this.lazyValue ? this.lazyValue.length : 0;
    },
    internalValue: {
      get: function get() {
        return this.lazyValue;
      },
      set: function set(val) {
        this.lazyValue = val;
        this.$emit('input', val);
      }
    }
  },
  watch: {
    value: function value(val) {
      // 有最大字数限制时对超出限制部分进行截取
      if (this.maxLength && val.length > this.maxLength) {
        val = val.slice(0, this.maxLength);
      }

      this.lazyValue = val;
    }
  },
  mounted: function mounted() {
    if (this.maxLength && this.length > this.maxLength) {
      this.lazyValue = this.value.slice(0, this.maxLength);
    } else {
      this.lazyValue = this.value;
    }
  },
  methods: {
    onFocus: function onFocus() {
      this.$emit('focus');
    },
    onBlur: function onBlur() {
      this.$emit('blur');
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    return h("div", {
      "class": "weui-cell"
    }, [h("div", {
      "class": "weui-cell__bd"
    }, [h("textarea", _mergeJSXProps([{
      "on": {
        "input": function input($event) {
          if ($event.target.composing) return;
          _this.internalValue = $event.target.value;
        },
        "change": this.$emit('change', this.internalValue),
        "focus": this.onFocus,
        "blur": this.onBlur
      },
      "class": "weui-textarea",
      "ref": "rextarea",
      "attrs": {
        "placeholder": this.placeholder,
        "rows": this.rows,
        "disabled": this.disabled,
        "readonly": this.readonly
      },
      "domProps": {
        "value": _this.internalValue
      }
    }, {
      directives: [{
        name: "model",
        value: _this.internalValue,
        modifiers: {}
      }]
    }])), this.showCounter && h("div", {
      "class": "weui-textarea-counter"
    }, ["".concat(this.length, "/").concat(this.maxLength)])])]);
  }
});
//# sourceMappingURL=WTextarea.js.map