"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.dividerProps = exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _vue = require("vue");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _propsUtil = require("../_util/props-util");
var _type = require("../_util/type");
var _useConfigInject = _interopRequireDefault(require("../config-provider/hooks/useConfigInject"));
var _style = _interopRequireDefault(require("./style"));
require("../config-provider/SizeContext");
var _useSize = _interopRequireDefault(require("../config-provider/hooks/useSize"));
const dividerProps = () => ({
  prefixCls: String,
  type: {
    type: String,
    default: 'horizontal'
  },
  dashed: {
    type: Boolean,
    default: false
  },
  orientation: {
    type: String,
    default: 'center'
  },
  plain: {
    type: Boolean,
    default: false
  },
  orientationMargin: [String, Number],
  variant: {
    type: String
  },
  size: {
    type: String
  }
});
exports.dividerProps = dividerProps;
const sizeClassNameMap = {
  small: 'sm',
  middle: 'md'
};
const Divider = (0, _vue.defineComponent)({
  name: 'ADivider',
  inheritAttrs: false,
  compatConfig: {
    MODE: 3
  },
  props: dividerProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls: prefixClsRef,
      direction
    } = (0, _useConfigInject.default)('divider', props);
    const [wrapSSR, hashId] = (0, _style.default)(prefixClsRef);
    const mergedOrientation = (0, _vue.computed)(() => {
      const orientation = props.orientation;
      if (orientation === 'left') {
        return direction.value === 'rtl' ? 'end' : 'start';
      }
      if (orientation === 'right') {
        return direction.value === 'rtl' ? 'start' : 'end';
      }
      return orientation;
    });
    const sizeFullName = (0, _useSize.default)((0, _vue.toRef)(props, 'size'));
    const sizeCls = (0, _vue.computed)(() => sizeClassNameMap[sizeFullName.value]);
    const hasMarginStart = (0, _vue.computed)(() => mergedOrientation.value === 'start' && props.orientationMargin != null);
    const hasMarginEnd = (0, _vue.computed)(() => mergedOrientation.value === 'end' && props.orientationMargin != null);
    const classString = (0, _vue.computed)(() => {
      const {
        type,
        dashed,
        plain,
        variant
      } = props;
      const prefixCls = prefixClsRef.value;
      return {
        [prefixCls]: true,
        [hashId.value]: !!hashId.value,
        [`${prefixCls}-${type}`]: true,
        [`${prefixCls}-dashed`]: !!dashed,
        [`${prefixCls}-${variant}`]: variant !== 'solid',
        [`${prefixCls}-plain`]: !!plain,
        [`${prefixCls}-rtl`]: direction.value === 'rtl',
        [`${prefixCls}-no-default-orientation-margin-left`]: hasMarginStart.value,
        [`${prefixCls}-no-default-orientation-margin-right`]: hasMarginEnd.value,
        [`${prefixCls}-${sizeCls.value}`]: !!sizeCls.value
      };
    });
    const innerStyle = (0, _vue.computed)(() => {
      const marginValue = typeof props.orientationMargin === 'number' ? `${props.orientationMargin}px` : props.orientationMargin;
      return (0, _extends2.default)((0, _extends2.default)({}, hasMarginStart.value && {
        marginInlineStart: marginValue
      }), hasMarginEnd.value && {
        marginInlineEnd: marginValue
      });
    });
    return () => {
      var _a;
      const children = (0, _propsUtil.flattenChildren)((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots));
      return wrapSSR((0, _vue.createVNode)("div", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attrs), {}, {
        "class": [classString.value, children.length ? `${prefixClsRef.value}-with-text ${prefixClsRef.value}-with-text-${mergedOrientation.value}` : '', attrs.class],
        "role": "separator"
      }), [children.length && props.type !== 'vertical' ? (0, _vue.createVNode)("span", {
        "class": `${prefixClsRef.value}-inner-text`,
        "style": innerStyle.value
      }, [children]) : null]));
    };
  }
});
var _default = exports.default = (0, _type.withInstall)(Divider);