import { createVNode as _createVNode } from "vue";
import "./styles/carousel.css";
import { toRef, watch } from "vue";
import { createSymbol, defineComponent } from "../../utils";
import { makePaperProps, usePaper } from "../../composables/paper";
import { makeGroupProps, useGroup } from "../../composables/group";
import { CarouselActivator } from "./carousel-activator";
const CarouselKey = createSymbol("carousel");
const Carousel = defineComponent({
  name: "VeCarousel",
  props: {
    /**
     * @zh 自动播放
     */
    autoplay: Boolean,
    /**
     * @zh 播放的时间间隔
     */
    interval: {
      type: [Number, String],
      default: 6e3,
      validator: (value) => value > 0
    },
    ...makeGroupProps({
      mandatory: "force"
    }),
    ...makePaperProps({
      variant: "text",
      size: void 0,
      density: void 0
    })
  },
  emits: {
    "update:modelValue": (_value) => true
  },
  setup(props, {
    slots
  }) {
    const {
      paperStyles,
      paperClasses
    } = usePaper(props);
    const {
      isSelected,
      select,
      selected,
      next,
      items
    } = useGroup(props, CarouselKey);
    let slideTimeout;
    const restartTimeout = () => {
      slideTimeout && clearTimeout(slideTimeout);
      slideTimeout = void 0;
      window.requestAnimationFrame(() => {
        if (!props.autoplay)
          return;
        slideTimeout = window.setTimeout(next, +props.interval > 0 ? +props.interval : 6e3);
      });
    };
    watch([selected, toRef(props, "autoplay"), toRef(props, "interval")], restartTimeout);
    return () => _createVNode(props.tag, {
      "class": ["ve-carousel", paperClasses.value],
      "style": paperStyles.value
    }, {
      default: () => [slots.default?.(), _createVNode("div", {
        "class": "ve-carousel__controls"
      }, [items.value.map((v) => _createVNode(CarouselActivator, {
        "active": isSelected(v.id),
        "onClick": () => select(v.id, true)
      }, null))])]
    });
  }
});
export {
  Carousel,
  CarouselKey
};
//# sourceMappingURL=carousel.mjs.map
