import { defineComponent, toRefs, computed, createVNode, mergeProps } from 'vue';
import { CloseOutlined } from '@ant-design/icons-vue';
import localeValues from '../locale/lang/en_US.mjs';
import LocaleReceiver from '../locale-provider/LocaleReceiver.mjs';
import '../button/index.mjs';
import classNames from '../_util/classNames.mjs';
import { tourStepProps } from './interface.mjs';
import Button from '../button/button.mjs';

const panelRender = /* @__PURE__ */ defineComponent({
  name: "ATourPanel",
  inheritAttrs: false,
  props: tourStepProps(),
  setup(props, {
    attrs,
    slots
  }) {
    const {
      current,
      total
    } = toRefs(props);
    const isLastStep = computed(() => current.value === total.value - 1);
    const prevBtnClick = (e) => {
      var _a;
      const prevButtonProps = props.prevButtonProps;
      (_a = props.onPrev) == null ? void 0 : _a.call(props, e);
      if (typeof (prevButtonProps == null ? void 0 : prevButtonProps.onClick) === "function")
        prevButtonProps == null ? void 0 : prevButtonProps.onClick();
    };
    const nextBtnClick = (e) => {
      var _a, _b;
      const nextButtonProps = props.nextButtonProps;
      if (isLastStep.value)
        (_a = props.onFinish) == null ? void 0 : _a.call(props, e);
      else
        (_b = props.onNext) == null ? void 0 : _b.call(props, e);
      if (typeof (nextButtonProps == null ? void 0 : nextButtonProps.onClick) === "function")
        nextButtonProps == null ? void 0 : nextButtonProps.onClick();
    };
    return () => {
      const {
        prefixCls,
        title,
        onClose,
        cover,
        description,
        type: stepType,
        arrow
      } = props;
      const prevButtonProps = props.prevButtonProps;
      const nextButtonProps = props.nextButtonProps;
      let headerNode;
      if (title) {
        headerNode = createVNode("div", {
          "class": `${prefixCls}-header`
        }, [createVNode("div", {
          "class": `${prefixCls}-title`
        }, [title])]);
      }
      let descriptionNode;
      if (description)
        descriptionNode = createVNode("div", {
          "class": `${prefixCls}-description`
        }, [description]);
      let coverNode;
      if (cover)
        coverNode = createVNode("div", {
          "class": `${prefixCls}-cover`
        }, [cover]);
      let mergeIndicatorNode;
      if (slots.indicatorsRender) {
        mergeIndicatorNode = slots.indicatorsRender({
          current: current.value,
          total
        });
      } else {
        mergeIndicatorNode = [...Array.from({
          length: total.value
        }).keys()].map((stepItem, index) => createVNode("span", {
          "key": stepItem,
          "class": classNames(index === current.value && `${prefixCls}-indicator-active`, `${prefixCls}-indicator`)
        }, null));
      }
      const mainBtnType = stepType === "primary" ? "default" : "primary";
      const secondaryBtnProps = {
        type: "default",
        ghost: stepType === "primary"
      };
      return createVNode(LocaleReceiver, {
        "componentName": "Tour",
        "defaultLocale": localeValues.Tour
      }, {
        default: (contextLocale) => createVNode("div", mergeProps(attrs, {
          "class": classNames(stepType === "primary" ? `${prefixCls}-primary` : "", attrs.class, `${prefixCls}-content`)
        }), [arrow && createVNode("div", {
          "class": `${prefixCls}-arrow`,
          "key": "arrow"
        }, null), createVNode("div", {
          "class": `${prefixCls}-inner`
        }, [createVNode(CloseOutlined, {
          "class": `${prefixCls}-close`,
          "onClick": onClose
        }, null), coverNode, headerNode, descriptionNode, createVNode("div", {
          "class": `${prefixCls}-footer`
        }, [total.value > 1 && createVNode("div", {
          "class": `${prefixCls}-indicators`
        }, [mergeIndicatorNode]), createVNode("div", {
          "class": `${prefixCls}-buttons`
        }, [current.value !== 0 ? createVNode(Button, mergeProps(secondaryBtnProps, prevButtonProps, {
          "onClick": prevBtnClick,
          "size": "small",
          "class": classNames(`${prefixCls}-prev-btn`, prevButtonProps == null ? void 0 : prevButtonProps.className)
        }), {
          default: () => {
            var _a;
            return [(_a = prevButtonProps == null ? void 0 : prevButtonProps.children) != null ? _a : contextLocale.Previous];
          }
        }) : null, createVNode(Button, mergeProps({
          "type": mainBtnType
        }, nextButtonProps, {
          "onClick": nextBtnClick,
          "size": "small",
          "class": classNames(`${prefixCls}-next-btn`, nextButtonProps == null ? void 0 : nextButtonProps.className)
        }), {
          default: () => {
            var _a;
            return [(_a = nextButtonProps == null ? void 0 : nextButtonProps.children) != null ? _a : isLastStep.value ? contextLocale.Finish : contextLocale.Next];
          }
        })])])])])
      });
    };
  }
});

export { panelRender as default };
//# sourceMappingURL=panelRender.mjs.map
