var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
import { classNames, isValidElement, omit, useDebounceFn, useState } from "@antdv/pro-utils";
import { Avatar } from "ant-design-vue";
import { useConfigContextInject } from "ant-design-vue/lib/config-provider/context";
import ResizeObserver from "ant-design-vue/lib/vc-resize-observer";
import { computed, defineComponent } from "vue";
import { globalHeaderProps } from "../GlobalHeader/props.mjs";
import { useStyle } from "./rightContentStyle.mjs";
const ActionsContent = defineComponent({
  name: "ActionsContent",
  props: globalHeaderProps(),
  slots: Object,
  inheritAttrs: false,
  setup(props, {
    slots
  }) {
    const [rightSize, setRightSize] = useState("auto");
    const {
      getPrefixCls
    } = useConfigContextInject();
    const prefixCls = computed(() => `${getPrefixCls()}-pro-global-header`);
    const {
      wrapSSR,
      hashId
    } = useStyle(prefixCls);
    const avatarDom = computed(() => {
      var _a;
      if (!props.avatarProps) return null;
      const _b = props.avatarProps, {
        title = (_a = slots.avatarTitle) == null ? void 0 : _a.call(slots),
        render
      } = _b, rest = __objRest(_b, [
        "title",
        "render"
      ]);
      const domList = [(rest == null ? void 0 : rest.src) || (rest == null ? void 0 : rest.srcset) || rest.icon ? _createVNode(Avatar, _mergeProps(rest, {
        "size": 28,
        "key": "avatar"
      }), null) : null, title ? _createVNode("span", {
        "key": "name",
        "style": {
          marginInlineStart: `8px`
        }
      }, [title]) : void 0];
      if (render) {
        return render(props.avatarProps, _createVNode("div", null, [domList]), omit(props, ["avatarProps", "actionsRender", "headerContentRender"]));
      }
      ;
      return _createVNode("div", null, [domList]);
    });
    const setRightSizeDebounceFn = useDebounceFn((width) => __async(this, null, function* () {
      setRightSize(`${width}px`);
    }), 160);
    return () => {
      const _a = props, {
        avatarProps,
        actionsRender,
        headerContentRender
      } = _a, restProps = __objRest(_a, [
        "avatarProps",
        "actionsRender",
        "headerContentRender"
      ]);
      const rightActionsRender = actionsRender || avatarDom.value ? (restParams) => {
        const doms = actionsRender && (actionsRender == null ? void 0 : actionsRender(restParams));
        if (!doms && !avatarDom.value) return null;
        if (!Array.isArray(doms)) {
          return wrapSSR(_createVNode("div", {
            "class": `${prefixCls.value}-header-actions ${hashId.value}`.trim()
          }, [doms, avatarDom.value && _createVNode("span", {
            "class": `${prefixCls.value}-header-actions-avatar ${hashId.value}`.trim()
          }, [avatarDom.value])]));
        }
        return wrapSSR(_createVNode("div", {
          "class": `${prefixCls.value}-header-actions ${hashId.value}`.trim()
        }, [doms.filter(Boolean).map((dom, index) => {
          var _a2;
          let hideHover = false;
          if (isValidElement(dom)) {
            hideHover = !!((_a2 = dom == null ? void 0 : dom.props) == null ? void 0 : _a2["aria-hidden"]);
          }
          return _createVNode("div", {
            "key": index,
            "class": classNames(`${prefixCls.value}-header-actions-item ${hashId.value} `, {
              [`${prefixCls.value}-header-actions-hover`]: !hideHover
            })
          }, [dom]);
        }), avatarDom.value && _createVNode("span", {
          "class": `${prefixCls.value}-header-actions-avatar ${hashId.value} `.trim()
        }, [avatarDom.value])]));
      } : void 0;
      return _createVNode("div", {
        "class": `${prefixCls.value}-right-content ${hashId.value} `.trim(),
        "style": {
          minWidth: rightSize.value,
          height: "100%"
        }
      }, [_createVNode("div", {
        "style": {
          height: "100%"
        }
      }, [_createVNode(ResizeObserver, {
        "onResize": ({
          width
        }) => {
          setRightSizeDebounceFn.run(width);
        }
      }, {
        default: () => [rightActionsRender ? _createVNode("div", {
          "style": {
            display: "flex",
            alignItems: "center",
            height: "100%",
            justifyContent: "flex-end"
          }
        }, [rightActionsRender(__spreadProps(__spreadValues({}, restProps), {
          rightContentSize: rightSize.value
        }))]) : null]
      })])]);
    };
  }
});
export {
  ActionsContent
};
