import { createVNode as _createVNode, Fragment as _Fragment } from "vue";
import _extends from "@babel/runtime/helpers/esm/extends";
import Cell from './Cell';
import { inject, ref } from 'vue';
import { descriptionsContext } from './index';
const Row = props => {
  const renderCells = (items, {
    colon,
    prefixCls,
    bordered
  }, {
    component,
    type,
    showLabel,
    showContent,
    labelStyle: rootLabelStyle,
    contentStyle: rootContentStyle
  }) => {
    return items.map((item, index) => {
      const {
        prefixCls: itemPrefixCls = prefixCls,
        span = 1,
        labelStyle = item['label-style'],
        contentStyle = item['content-style'],
        label,
        children,
        class: className,
        style
      } = item;
      const {
        key
      } = item;
      if (typeof component === 'string') {
        return _createVNode(Cell, {
          "key": `${type}-${String(key) || index}`,
          "class": className,
          "style": style,
          "labelStyle": _extends(_extends({}, rootLabelStyle), labelStyle),
          "contentStyle": _extends(_extends({}, rootContentStyle), contentStyle),
          "span": span,
          "colon": colon,
          "component": component,
          "itemPrefixCls": itemPrefixCls,
          "bordered": bordered,
          "label": showLabel ? label : null,
          "content": showContent ? children : null
        }, null);
      }
      return [_createVNode(Cell, {
        "key": `label-${String(key) || index}`,
        "class": className,
        "style": _extends(_extends(_extends({}, rootLabelStyle), style), labelStyle),
        "span": 1,
        "colon": colon,
        "component": component[0],
        "itemPrefixCls": itemPrefixCls,
        "bordered": bordered,
        "label": label
      }, null), _createVNode(Cell, {
        "key": `content-${String(key) || index}`,
        "class": className,
        "style": _extends(_extends(_extends({}, rootContentStyle), style), contentStyle),
        "span": span * 2 - 1,
        "component": component[1],
        "itemPrefixCls": itemPrefixCls,
        "bordered": bordered,
        "content": children
      }, null)];
    });
  };
  const {
    prefixCls,
    vertical,
    row,
    index,
    bordered
  } = props;
  const {
    labelStyle,
    contentStyle
  } = inject(descriptionsContext, {
    labelStyle: ref({}),
    contentStyle: ref({})
  });
  if (vertical) {
    return _createVNode(_Fragment, null, [_createVNode("tr", {
      "key": `label-${index}`,
      "class": `${prefixCls}-row`
    }, [renderCells(row, props, {
      component: 'th',
      type: 'label',
      showLabel: true,
      labelStyle: labelStyle.value,
      contentStyle: contentStyle.value
    })]), _createVNode("tr", {
      "key": `content-${index}`,
      "class": `${prefixCls}-row`
    }, [renderCells(row, props, {
      component: 'td',
      type: 'content',
      showContent: true,
      labelStyle: labelStyle.value,
      contentStyle: contentStyle.value
    })])]);
  }
  return _createVNode("tr", {
    "key": index,
    "class": `${prefixCls}-row`
  }, [renderCells(row, props, {
    component: bordered ? ['th', 'td'] : 'td',
    type: 'item',
    showLabel: true,
    showContent: true,
    labelStyle: labelStyle.value,
    contentStyle: contentStyle.value
  })]);
};
export default Row;