'use strict';

var BaseComponent = require('primevue/basecomponent');
var InputTextStyle = require('primevue/inputtext/style');
var vue = require('vue');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
var InputTextStyle__default = /*#__PURE__*/_interopDefaultLegacy(InputTextStyle);

var script$1 = {
  name: 'BaseInputText',
  "extends": BaseComponent__default["default"],
  props: {
    modelValue: null,
    size: {
      type: String,
      "default": null
    },
    invalid: {
      type: Boolean,
      "default": false
    },
    variant: {
      type: String,
      "default": null
    },
    align: {
      type: String,
      "default": null
    },
    "case": {
      type: String,
      "default": ""
    },
    autoSelection: {
      type: Boolean,
      "default": true
    },
    tableCellEditor: {
      type: Boolean,
      "default": false
    }
  },
  style: InputTextStyle__default["default"],
  provide: function provide() {
    return {
      $parentInstance: this
    };
  }
};

script$1.__file = "components/lib/inputtext/BaseInputText.vue";

var script = {
  name: 'InputText',
  "extends": script$1,
  inheritAttrs: false,
  emits: ['update:modelValue', 'update-editing-cell-class'],
  data: function data() {
    return {
      d_displayValue: this.modelValue
    };
  },
  watch: {
    modelValue: function modelValue(newValue) {
      if (newValue !== this.d_displayValue) {
        this.d_displayValue = this.formatValue(newValue);
      }
    }
  },
  created: function created() {
    if (this.tableCellEditor) {
      this.$emit("update-editing-cell-class");
    }
  },
  methods: {
    getPTOptions: function getPTOptions(key) {
      var _ptm = key === 'root' ? this.ptmi : this.ptm;
      return _ptm(key, {
        context: {
          filled: this.filled,
          disabled: this.$attrs.disabled || this.$attrs.disabled === ''
        }
      });
    },
    onInput: function onInput(event) {
      //this.$emit('update:modelValue', event.target.value);
      this.d_displayValue = this.formatValue(event.target.value || '');
    },
    onChange: function onChange(event) {
      var value = this.formatValue(event.target.value || '');
      if (value !== this.d_displayValue) {
        this.d_displayValue = value;
      }
      this.$emit('update:modelValue', value);
    },
    onFocus: function onFocus() {
      this.autoSelection && this.$el.select();
    },
    formatValue: function formatValue(value) {
      if (value === null || value === undefined || value === '') return '';
      var case2 = this["case"].trim().toUpperCase();
      if (case2 === 'UPPER') {
        value = value.toString().toUpperCase();
      } else if (case2 === 'LOWER') {
        value = value.toString().toLowerCase();
      }
      return value;
    }
  },
  computed: {
    filled: function filled() {
      return this.modelValue != null && this.modelValue.toString().length > 0;
    }
  }
};

var _hoisted_1 = ["value", "aria-invalid"];
function render(_ctx, _cache, $props, $setup, $data, $options) {
  return vue.openBlock(), vue.createElementBlock("input", vue.mergeProps({
    "class": _ctx.cx('root'),
    value: $data.d_displayValue,
    "aria-invalid": _ctx.invalid || undefined,
    onInput: _cache[0] || (_cache[0] = function () {
      return $options.onInput && $options.onInput.apply($options, arguments);
    }),
    onChange: _cache[1] || (_cache[1] = function () {
      return $options.onChange && $options.onChange.apply($options, arguments);
    }),
    onFocus: _cache[2] || (_cache[2] = function () {
      return $options.onFocus && $options.onFocus.apply($options, arguments);
    })
  }, $options.getPTOptions('root')), null, 16 /* FULL_PROPS */, _hoisted_1);
}

script.render = render;
script.__file = "components/lib/inputtext/InputText.vue";

module.exports = script;
