import { Fragment as _Fragment, createVNode as _createVNode } from "vue";
import _extends from "@babel/runtime/helpers/esm/extends";
import { cloneVNode, computed, defineComponent, ref } from 'vue';
import { filterEmpty } from '../_util/props-util';
import { withInstall } from '../_util/type';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import BorderBeamEffect from './BorderBeamEffect';
import useBorderSize from './hooks/useBorderSize';
import useStyle from './style';
import { getBorderBeamGradient } from './util';
import { composeRef } from '../_util/createRef';
const getInset = width => {
  return typeof width === 'string' ? `calc(-1 * ${width})` : `-${width}px`;
};
export const borderBeamProps = () => ({
  prefixCls: String,
  className: String,
  style: Object,
  color: {
    type: [String, Array],
    default: undefined
  },
  outset: {
    type: [Number, String],
    default: undefined
  }
});
const BorderBeam = defineComponent({
  name: 'ABorderBeam',
  inheritAttrs: false,
  compatConfig: {
    MODE: 3
  },
  props: borderBeamProps(),
  setup(props, {
    slots
  }) {
    const {
      prefixCls: prefixClsRef
    } = useConfigInject('border-beam', props);
    const [wrapSSR, hashId] = useStyle(prefixClsRef);
    const childRef = ref(null);
    const borderInfo = useBorderSize(childRef);
    const beamGradient = computed(() => getBorderBeamGradient(props.color));
    const insetOffset = computed(() => {
      return props.outset !== undefined ? getInset(props.outset) : borderInfo.value.borderWidth.map(getInset).join(' ');
    });
    const effectStyle = computed(() => _extends(_extends(_extends({}, props.style), {
      '--ant-border-beam-inset-offset': insetOffset.value,
      '--ant-border-beam-border-radius': borderInfo.value.borderRadius
    }), beamGradient.value && {
      '--ant-border-beam-beam-gradient': beamGradient.value
    }));
    return () => {
      var _a;
      const children = filterEmpty((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots));
      const childNode = children[0];
      if (!childNode) {
        return null;
      }
      const mergedChild = cloneVNode(childNode, {
        ref: composeRef(childNode.ref, childRef)
      });
      return wrapSSR(_createVNode(_Fragment, null, [mergedChild, _createVNode(BorderBeamEffect, {
        "prefixCls": prefixClsRef.value,
        "hostDom": childRef.value,
        "className": [hashId.value, props.className].filter(Boolean).join(' '),
        "style": effectStyle.value
      }, null)]));
    };
  }
});
export default withInstall(BorderBeam);