"use strict";
const vue = require("vue");
const classes = require("./classes-DA6TfAZg.js");
const useId = require("./useId-Dl8Hi5_U.js");
const index = require("./index-C_bsiScj.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const keys = require("./keys-D70E9HED.js");
const index$1 = require("./index-JJEBhaXq.js");
const BImg_vue_vue_type_script_setup_true_lang = require("./BImg.vue_vue_type_script_setup_true_lang-3FYrkHVf.js");
const dom = require("./dom-BgEUZpKg.js");
const getSlotElements = (slot, filterBy) => (slot?.() ?? []).reduce((arr, slot2) => {
  if (typeof slot2.type === "symbol") {
    arr = arr.concat(slot2.children);
  } else {
    arr.push(slot2);
  }
  return arr;
}, []).filter((child) => child.type?.__name === filterBy);
const _hoisted_1$1 = ["id"];
const _hoisted_2 = ["aria-label", "aria-owns"];
const _hoisted_3 = ["aria-current", "aria-label", "aria-controls", "aria-describedby", "onClick"];
const _hoisted_4 = {
  ref: "_relatedTarget",
  class: "carousel-inner"
};
const _hoisted_5 = { class: "visually-hidden" };
const _hoisted_6 = { class: "visually-hidden" };
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  __name: "BCarousel",
  props: /* @__PURE__ */ vue.mergeModels({
    background: { default: void 0 },
    controls: { type: Boolean, default: false },
    controlsNextText: { default: "Next" },
    controlsPrevText: { default: "Previous" },
    fade: { type: Boolean, default: false },
    id: { default: void 0 },
    imgHeight: { default: void 0 },
    imgWidth: { default: void 0 },
    indicators: { type: Boolean, default: false },
    indicatorsButtonLabel: { default: "Slide" },
    interval: { default: 5e3 },
    labelIndicators: { default: "Select a slide to display" },
    keyboard: { type: Boolean, default: true },
    noAnimation: { type: Boolean, default: false },
    noHoverPause: { type: Boolean, default: false },
    noTouch: { type: Boolean, default: false },
    noWrap: { type: Boolean, default: false },
    ride: { type: [Boolean, String], default: false },
    rideReverse: { type: Boolean, default: false },
    touchThreshold: { default: 50 }
  }, {
    "modelValue": { default: 0 },
    "modelModifiers": {}
  }),
  emits: /* @__PURE__ */ vue.mergeModels(["slide", "slid", "prev-click", "next-click"], ["update:modelValue"]),
  setup(__props, { expose: __expose, emit: __emit }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BCarousel");
    const emit = __emit;
    const slots = vue.useSlots();
    const computedId = useId.useId(() => props.id, "carousel");
    const buttonOwnership = useId.useId(void 0, "carousel-button-ownership");
    const modelValue = vue.useModel(__props, "modelValue");
    const slideValues = vue.useTemplateRef("_slideValues");
    const touchThresholdNumber = index$1.useToNumber(() => props.touchThreshold);
    const slideInterval = vue.ref(null);
    vue.onMounted(() => {
      slideInterval.value = slideValues.value?.find((slid) => slid.$el.style.display !== "none")?._interval ?? null;
    });
    const intervalNumber = index$1.useToNumber(() => slideInterval.value ?? props.interval);
    const isTransitioning = vue.ref(false);
    const rideStarted = vue.ref(false);
    const direction = vue.ref(true);
    const relatedTarget = vue.useTemplateRef("_relatedTarget");
    const element = vue.useTemplateRef("_element");
    const previousModelValue = vue.ref(modelValue.value);
    const isHovering = index.useElementHover(element);
    const enterClasses = vue.computed(
      () => `carousel-item carousel-item-${!direction.value ? "next" : "prev"} carousel-item-${!direction.value ? "start" : "end"}`
    );
    const leaveClasses = vue.computed(
      () => `carousel-item active carousel-item-${direction.value ? "start" : "end"}`
    );
    const { pause, resume } = index$1.useIntervalFn(
      () => {
        if (props.rideReverse) {
          prev();
          return;
        }
        next();
      },
      intervalNumber,
      { immediate: props.ride === "carousel" }
    );
    const isRiding = vue.computed(
      () => props.ride === true && rideStarted.value === true || props.ride === "carousel"
    );
    const slides = vue.computed(() => getSlotElements(slots.default, "BCarouselSlide"));
    const computedClasses = vue.computed(() => ({ "carousel-fade": props.fade }));
    const buildBvCarouselEvent = (event) => new classes.BvCarouselEvent(event, {
      componentId: computedId.value,
      cancelable: false,
      target: element.value,
      direction: direction.value ? "right" : "left",
      from: previousModelValue.value,
      to: modelValue.value,
      relatedTarget: relatedTarget.value?.children[modelValue.value] ?? null
    });
    const goToValue = (value) => {
      if (isTransitioning.value === true) return;
      if (props.ride === true) {
        rideStarted.value = true;
      }
      if (isRiding.value === true) {
        resume();
      }
      direction.value = value < modelValue.value ? false : true;
      if (value >= slides.value.length) {
        if (props.noWrap) return;
        modelValue.value = 0;
        return;
      }
      if (value < 0) {
        if (props.noWrap) return;
        modelValue.value = slides.value.length - 1;
        return;
      }
      previousModelValue.value = modelValue.value;
      modelValue.value = value;
    };
    const prev = () => {
      goToValue(modelValue.value - 1);
    };
    const next = () => {
      goToValue(modelValue.value + 1);
    };
    const onKeydown = (fn) => {
      if (props.keyboard === false) return;
      fn();
    };
    const onMouseEnter = () => {
      if (props.noHoverPause) return;
      pause();
    };
    const onMouseLeave = () => {
      if (!isRiding.value) return;
      resume();
    };
    const { lengthX } = index.useSwipe(element, {
      passive: true,
      onSwipeStart() {
        if (props.noTouch === true) return;
        pause();
      },
      onSwipeEnd() {
        if (props.noTouch === true) return;
        const resumeRiding = () => {
          if (isRiding.value === false) return;
          resume();
        };
        if (lengthX.value >= touchThresholdNumber.value) {
          next();
          resumeRiding();
          return;
        }
        if (lengthX.value <= -touchThresholdNumber.value) {
          prev();
          resumeRiding();
        }
      }
    });
    const onBeforeLeave = () => {
      emit("slide", buildBvCarouselEvent("slide"));
      isTransitioning.value = true;
    };
    const onAfterLeave = () => {
      emit("slid", buildBvCarouselEvent("slid"));
      isTransitioning.value = false;
    };
    const onAfterEnter = (el) => {
      if (modelValue.value !== 0) {
        el.classList.add("carousel-item");
      }
    };
    const onEnter = (el) => {
      slideInterval.value = slideValues.value?.find((slid) => slid.$el === el)?._interval ?? null;
    };
    index.onKeyStroke(
      "ArrowLeft",
      () => {
        onKeydown(prev);
      },
      { target: element }
    );
    index.onKeyStroke(
      "ArrowRight",
      () => {
        onKeydown(next);
      },
      { target: element }
    );
    vue.watch(
      () => props.ride,
      () => {
        rideStarted.value = false;
      }
    );
    vue.watch(isHovering, (newValue) => {
      if (newValue) {
        onMouseEnter();
        return;
      }
      onMouseLeave();
    });
    const onClickPrev = (event) => {
      emit("prev-click", event);
      if (event.defaultPrevented) return;
      prev();
    };
    const onClickNext = (event) => {
      emit("next-click", event);
      if (event.defaultPrevented) return;
      next();
    };
    __expose({
      next,
      pause,
      prev,
      resume
    });
    vue.provide(keys.carouselInjectionKey, {
      background: vue.toRef(() => props.background),
      width: vue.toRef(() => props.imgWidth),
      height: vue.toRef(() => props.imgHeight)
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        id: vue.unref(computedId),
        ref: "_element",
        class: vue.normalizeClass(["carousel slide pointer-event", computedClasses.value])
      }, [
        vue.unref(props).indicators ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 0,
          class: "carousel-indicators",
          "aria-label": vue.unref(props).labelIndicators,
          "aria-owns": vue.unref(buttonOwnership)
        }, [
          (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(slides.value.length, (_, i) => {
            return vue.openBlock(), vue.createElementBlock("button", {
              key: i,
              type: "button",
              "data-bs-target": "",
              class: vue.normalizeClass(i === modelValue.value ? "active" : ""),
              "aria-current": i === modelValue.value ? true : void 0,
              "aria-label": `${vue.unref(props).indicatorsButtonLabel} ${i}`,
              "aria-controls": vue.unref(buttonOwnership),
              "aria-describedby": slideValues.value?.[i]?._id,
              onClick: ($event) => goToValue(i)
            }, null, 10, _hoisted_3);
          }), 128))
        ], 8, _hoisted_2)) : vue.createCommentVNode("", true),
        vue.createElementVNode("div", _hoisted_4, [
          vue.createVNode(vue.TransitionGroup, {
            "enter-from-class": enterClasses.value,
            "enter-active-class": enterClasses.value,
            "enter-to-class": enterClasses.value,
            "leave-from-class": leaveClasses.value,
            "leave-active-class": leaveClasses.value,
            "leave-to-class": leaveClasses.value,
            onBeforeLeave,
            onAfterLeave,
            onAfterEnter,
            onEnter
          }, {
            default: vue.withCtx(() => [
              (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(slides.value, (slide, i) => {
                return vue.withDirectives((vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(slide), {
                  key: i,
                  ref_for: true,
                  ref: "_slideValues",
                  class: vue.normalizeClass({ active: i === modelValue.value && isTransitioning.value === false }),
                  style: vue.normalizeStyle(vue.unref(props).noAnimation && { transition: "none" })
                }, null, 8, ["class", "style"])), [
                  [vue.vShow, i === modelValue.value]
                ]);
              }), 128))
            ]),
            _: 1
          }, 8, ["enter-from-class", "enter-active-class", "enter-to-class", "leave-from-class", "leave-active-class", "leave-to-class"])
        ], 512),
        vue.unref(props).controls ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
          vue.createElementVNode("button", {
            class: "carousel-control-prev",
            type: "button",
            onClick: onClickPrev
          }, [
            _cache[0] || (_cache[0] = vue.createElementVNode("span", {
              class: "carousel-control-prev-icon",
              "aria-hidden": "true"
            }, null, -1)),
            vue.createElementVNode("span", _hoisted_5, vue.toDisplayString(vue.unref(props).controlsPrevText), 1)
          ]),
          vue.createElementVNode("button", {
            class: "carousel-control-next",
            type: "button",
            onClick: onClickNext
          }, [
            _cache[1] || (_cache[1] = vue.createElementVNode("span", {
              class: "carousel-control-next-icon",
              "aria-hidden": "true"
            }, null, -1)),
            vue.createElementVNode("span", _hoisted_6, vue.toDisplayString(vue.unref(props).controlsNextText), 1)
          ])
        ], 64)) : vue.createCommentVNode("", true)
      ], 10, _hoisted_1$1);
    };
  }
});
const _hoisted_1 = ["id"];
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BCarouselSlide",
  props: {
    background: { default: void 0 },
    caption: { default: void 0 },
    captionTag: { default: "h3" },
    contentTag: { default: "div" },
    contentVisibleUp: { default: void 0 },
    id: { default: void 0 },
    imgAlt: { default: void 0 },
    imgBlank: { type: Boolean, default: false },
    imgBlankColor: { default: "transparent" },
    imgHeight: { default: void 0 },
    imgSrc: { default: void 0 },
    imgSrcset: { default: void 0 },
    imgWidth: { default: void 0 },
    interval: { default: void 0 },
    text: { default: void 0 },
    textTag: { default: "p" }
  },
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BCarouselSlide");
    const slots = vue.useSlots();
    const computedId = useId.useId(() => props.id, "carousel-slide");
    const parentData = vue.inject(keys.carouselInjectionKey, null);
    const hasText = vue.computed(() => props.text || !dom.isEmptySlot(slots.text));
    const hasCaption = vue.computed(() => props.caption || !dom.isEmptySlot(slots.caption));
    const hasContent = vue.computed(() => hasText.value || hasCaption.value || !dom.isEmptySlot(slots.default));
    const computedStyle = vue.computed(() => ({
      background: `${props.background || parentData?.background.value || "rgb(171, 171, 171)"} none repeat scroll 0% 0%`
    }));
    const computedContentClasses = vue.computed(() => ({
      "d-none": props.contentVisibleUp !== void 0,
      [`d-${props.contentVisibleUp}-block`]: props.contentVisibleUp !== void 0
    }));
    __expose({
      _interval: vue.toRef(() => props.interval),
      _id: computedId
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        id: vue.unref(computedId),
        class: "carousel-item",
        style: vue.normalizeStyle(computedStyle.value)
      }, [
        vue.renderSlot(_ctx.$slots, "img", {}, () => [
          vue.createVNode(BImg_vue_vue_type_script_setup_true_lang._sfc_main, {
            class: "d-block w-100",
            alt: vue.unref(props).imgAlt,
            srcset: vue.unref(props).imgSrcset,
            src: vue.unref(props).imgSrc,
            width: vue.unref(props).imgWidth || vue.unref(parentData)?.width.value,
            height: vue.unref(props).imgHeight || vue.unref(parentData)?.height.value,
            blank: vue.unref(props).imgBlank,
            "blank-color": vue.unref(props).imgBlankColor
          }, null, 8, ["alt", "srcset", "src", "width", "height", "blank", "blank-color"])
        ]),
        hasContent.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(props).contentTag), {
          key: 0,
          class: vue.normalizeClass(["carousel-caption", computedContentClasses.value])
        }, {
          default: vue.withCtx(() => [
            hasCaption.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(props).captionTag), { key: 0 }, {
              default: vue.withCtx(() => [
                vue.renderSlot(_ctx.$slots, "caption", {}, () => [
                  vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(props).caption), 1)
                ])
              ]),
              _: 3
            })) : vue.createCommentVNode("", true),
            hasText.value ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(props).textTag), { key: 1 }, {
              default: vue.withCtx(() => [
                vue.renderSlot(_ctx.$slots, "text", {}, () => [
                  vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(props).text), 1)
                ])
              ]),
              _: 3
            })) : vue.createCommentVNode("", true),
            vue.renderSlot(_ctx.$slots, "default")
          ]),
          _: 3
        }, 8, ["class"])) : vue.createCommentVNode("", true)
      ], 12, _hoisted_1);
    };
  }
});
exports._sfc_main = _sfc_main$1;
exports._sfc_main$1 = _sfc_main;
//# sourceMappingURL=BCarouselSlide.vue_vue_type_script_setup_true_lang-kKbDyp15.js.map
