"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
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 _formItem = require("./form-item");
var _render = require("./render");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
var formItemPropKeys = Object.keys(_formItem.formItemProps);
var _default = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeFormGroup',
  mixins: [_ui.globalMixins.sizeMixin],
  props: _formItem.formItemProps,
  inject: {
    $xeForm: {
      default: null
    },
    $xeParentFormGroup: {
      from: '$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: {
    renderVN: function renderVN(h) {
      var $xeFormGroup = this;
      var slots = $xeFormGroup.$scopedSlots;
      var formItem = $xeFormGroup.formItem;
      var $xeForm = $xeFormGroup.$xeForm;
      var formProps = $xeForm;
      var $xeGrid = $xeForm.$xeGrid;
      var item = formItem;
      var data = formProps.data,
        readonly = formProps.readonly,
        disabled = formProps.disabled;
      var visible = item.visible,
        field = item.field,
        itemRender = item.itemRender,
        contentStyle = item.contentStyle;
      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 defaultSlot = slots ? slots.default : 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)($xeFormGroup);
      }
      return h('div', {
        ref: 'refElem',
        key: item.id,
        class: (0, _render.getItemClass)($xeForm, item, true),
        style: _xeUtils.default.isFunction(itemStyle) ? itemStyle(params) : itemStyle || {},
        attrs: {
          itemid: item.id
        }
      }, [(0, _render.renderTitle)(h, $xeForm, item, true), h('div', {
        class: (0, _render.getItemContentClass)($xeForm, item, true),
        style: Object.assign({}, _xeUtils.default.isFunction(itemContentStyle) ? itemContentStyle(params) : itemContentStyle, _xeUtils.default.isFunction(contentStyle) ? contentStyle(params) : contentStyle)
      }, defaultSlot ? defaultSlot({}) : [])]);
    }
  },
  provide: function provide() {
    var $xeFormGroup = this;
    var formItem = $xeFormGroup.formItem;
    return {
      $xeFormGroup: $xeFormGroup,
      $xeFormItem: null,
      xeFormItemInfo: {
        itemConfig: formItem
      }
    };
  },
  created: function created() {
    var $xeFormGroup = this;
    var props = $xeFormGroup;
    var $xeForm = $xeFormGroup.$xeForm;
    var formItem = (0, _util.createItem)($xeForm, props);
    formItem.children = [];
    $xeFormGroup.formItem = formItem;
    (0, _util.watchItem)($xeFormGroup, formItemPropKeys, formItem);
  },
  mounted: function mounted() {
    var $xeFormGroup = this;
    var formItem = $xeFormGroup.formItem;
    var $xeForm = $xeFormGroup.$xeForm;
    var $xeParentFormGroup = $xeFormGroup.$xeParentFormGroup;
    var elem = $xeFormGroup.$refs.refElem;
    (0, _util.assembleItem)($xeForm, elem, formItem, $xeParentFormGroup);
  },
  beforeDestroy: function beforeDestroy() {
    var $xeFormGroup = this;
    var formItem = $xeFormGroup.formItem;
    var $xeForm = $xeFormGroup.$xeForm;
    (0, _util.destroyItem)($xeForm, formItem);
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */