"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formItemProps = exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _ui = require("../../ui");
var _utils = require("../../ui/src/utils");
var _util = require("./util");
var _render = require("./render");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
var formItemProps = exports.formItemProps = {
  title: String,
  field: String,
  span: {
    type: [String, Number],
    default: null
  },
  align: {
    type: String,
    default: null
  },
  verticalAlign: {
    type: String,
    default: null
  },
  titleBackground: {
    type: Boolean,
    default: null
  },
  titleBold: {
    type: Boolean,
    default: null
  },
  titleAlign: {
    type: String,
    default: null
  },
  titleWidth: {
    type: [String, Number],
    default: null
  },
  titleColon: {
    type: Boolean,
    default: null
  },
  titleAsterisk: {
    type: Boolean,
    default: null
  },
  showTitle: {
    type: Boolean,
    default: true
  },
  vertical: {
    type: Boolean,
    default: null
  },
  padding: {
    type: Boolean,
    default: null
  },
  formatter: [String, Function],
  className: [String, Function],
  contentClassName: [String, Function],
  contentStyle: [Object, Function],
  titleClassName: [String, Function],
  titleStyle: [Object, Function],
  titleOverflow: {
    type: [Boolean, String],
    default: null
  },
  titlePrefix: Object,
  titleSuffix: Object,
  resetValue: {
    default: null
  },
  visibleMethod: Function,
  visible: {
    type: Boolean,
    default: null
  },
  showContent: {
    type: Boolean,
    default: null
  },
  folding: Boolean,
  collapseNode: Boolean,
  itemRender: Object,
  rules: Array,
  params: Object
};
var formItemPropKeys = Object.keys(formItemProps);
var _default = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeFormItem',
  mixins: [_ui.globalMixins.sizeMixin],
  props: formItemProps,
  inject: {
    $xeForm: {
      default: null
    },
    $xeFormGroup: {
      default: null
    }
  },
  data: function data() {
    var xID = _xeUtils.default.uniqueId();
    var formItem = {};
    var reactData = {};
    return {
      xID: xID,
      formItem: formItem,
      reactData: reactData
    };
  },
  computed: Object.assign({}, {}),
  methods: {
    renderItem: function renderItem(h, $xeForm, item) {
      var $xeFormItem = this;
      var formProps = $xeForm;
      var $xeGrid = $xeForm.$xeGrid;
      var data = formProps.data,
        readonly = formProps.readonly,
        disabled = formProps.disabled;
      var visible = item.visible,
        field = item.field,
        itemRender = item.itemRender,
        contentStyle = item.contentStyle,
        showContent = item.showContent;
      var compConf = (0, _utils.isEnableConf)(itemRender) ? _ui.renderer.get(itemRender.name) : null;
      var itemStyle = compConf ? compConf.formItemStyle || compConf.itemStyle : null;
      var itemContentStyle = compConf ? compConf.formItemContentStyle || compConf.itemContentStyle : null;
      var params = {
        data: data,
        disabled: disabled,
        readonly: readonly,
        field: field,
        property: field,
        item: item,
        $form: $xeForm,
        $grid: $xeGrid
      };
      if (visible === false) {
        return (0, _ui.renderEmptyElement)($xeFormItem);
      }
      return h('div', {
        ref: 'refElem',
        key: item.id,
        class: (0, _render.getItemClass)($xeForm, item),
        style: _xeUtils.default.isFunction(itemStyle) ? itemStyle(params) : itemStyle || {},
        attrs: {
          itemid: item.id
        }
      }, [(0, _render.renderTitle)(h, $xeForm, item), showContent === false ? (0, _ui.renderEmptyElement)($xeFormItem) : h('div', {
        class: (0, _render.getItemContentClass)($xeForm, item),
        style: Object.assign({}, _xeUtils.default.isFunction(itemContentStyle) ? itemContentStyle(params) : itemContentStyle, _xeUtils.default.isFunction(contentStyle) ? contentStyle(params) : contentStyle)
      }, [(0, _render.renderItemContent)(h, $xeForm, item), (0, _render.renderItemErrorIcon)(h, $xeForm, item)])]);
    },
    renderVN: function renderVN(h) {
      var $xeFormItem = this;
      var $xeForm = $xeFormItem.$xeForm;
      var formItem = $xeFormItem.formItem;
      var customLayout = $xeForm ? $xeForm.customLayout : false;
      var item = formItem;
      return customLayout ? $xeFormItem.renderItem(h, $xeForm, item) : h('div', {
        ref: 'refElem'
      });
    }
  },
  provide: function provide() {
    var $xeFormItem = this;
    var formItem = $xeFormItem.formItem;
    return {
      $xeFormGroup: null,
      $xeFormItem: $xeFormItem,
      xeFormItemInfo: {
        itemConfig: formItem
      }
    };
  },
  created: function created() {
    var $xeFormItem = this;
    var props = $xeFormItem;
    var $xeForm = $xeFormItem.$xeForm;
    var formItem = (0, _util.createItem)($xeForm, props);
    $xeFormItem.formItem = formItem;
    (0, _util.watchItem)($xeFormItem, formItemPropKeys, formItem);
  },
  mounted: function mounted() {
    var $xeFormItem = this;
    var slots = $xeFormItem.$scopedSlots;
    var formItem = $xeFormItem.formItem;
    var $xeForm = $xeFormItem.$xeForm;
    var $xeFormGroup = $xeFormItem.$xeFormGroup;
    formItem.slots = slots;
    var elem = $xeFormItem.$refs.refElem;
    (0, _util.assembleItem)($xeForm, elem, formItem, $xeFormGroup);
  },
  beforeDestroy: function beforeDestroy() {
    var $xeFormItem = this;
    var formItem = $xeFormItem.formItem;
    var $xeForm = $xeFormItem.$xeForm;
    (0, _util.destroyItem)($xeForm, formItem);
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */