import { toRef, computed, ref, createVNode, mergeProps } from "vue";
import "./styles/progress.scss";
import { makeTagProps } from "../../composables/tag/index.mjs";
import { makeThemeProps, provideTheme } from "../../composables/theme/index.mjs";
import { makeSizeProps, useSize } from "../../composables/size/index.mjs";
import { useProxiedModel } from "../../composables/proxied-model/index.mjs";
import { useTextColor } from "../../composables/color/index.mjs";
import { useVariant } from "../../composables/variant/index.mjs";
import { useIntersectionObserver } from "../../composables/intersection-observer/index.mjs";
import { makeProgressCircularProps, ProgressCircular, filterProgressCircularProps } from "./progress-circular.mjs";
import { makeProgressLinearProps, ProgressLinear, filterProgressLinearProps } from "./progress-linear.mjs";
import { defineComponent } from "../../utils/define-component.mjs";
import { useRender } from "../../utils/dist/index.mjs";
const progressVariants = [
  "linear",
  "circular"
];
const Progress = defineComponent({
  name: "VeProgress",
  props: {
    color: {
      type: [String, Boolean],
      default: "primary"
    },
    start: Boolean,
    end: Boolean,
    ...makeProgressCircularProps(),
    ...makeProgressLinearProps(),
    ...makeThemeProps(),
    ...makeSizeProps(),
    ...makeTagProps(),
    variant: {
      type: String,
      default: "linear",
      validator: (v) => progressVariants.includes(v)
    }
  },
  emits: {
    "update:modelValue": (_modelValue) => true
  },
  setup(props, {
    slots
  }) {
    const {
      themeClasses
    } = provideTheme(props);
    const {
      variantClasses
    } = useVariant(props);
    const {
      sizeClasses,
      sizeStyles
    } = useSize(props);
    const {
      textColorClasses,
      textColorStyles
    } = useTextColor(toRef(props, "color"));
    const {
      intersectionRef,
      isIntersecting
    } = useIntersectionObserver();
    const model = useProxiedModel(props, "modelValue", props.modelValue, (val) => Math.max(0, Math.min(100, parseFloat(val != null ? val : 0))));
    const strokeWidth = computed(() => Number(props.strokeWidth));
    const size = computed(() => {
      return sizeStyles.value.width ? Number(props.size) : intersectionRef.value ? intersectionRef.value.getBoundingClientRect().width : Math.max(strokeWidth.value, 32);
    });
    const transitionDuration = ref();
    useRender(() => {
      return createVNode(props.tag, {
        "role": "progressbar",
        "aria-valuenow": props.indeterminate ? void 0 : model.value,
        "aria-valuemin": "0",
        "aria-valuemax": "100",
        "ref": intersectionRef,
        "class": ["ve-progress", variantClasses.value, themeClasses.value, sizeClasses.value, textColorClasses.value, {
          "ve-progress--indeterminate": !!props.indeterminate,
          "ve-progress--visible": isIntersecting.value,
          "ve-progress--start": props.start,
          "ve-progress--end": props.end
        }],
        "style": [sizeStyles.value, textColorStyles.value, {
          transitionDuration: transitionDuration.value
        }]
      }, {
        default: () => [props.variant === "circular" && createVNode(ProgressCircular, mergeProps(filterProgressCircularProps(props)[0], {
          "modelValue": model.value,
          "size": size.value
        }), null), props.variant === "linear" && createVNode(ProgressLinear, mergeProps(filterProgressLinearProps(props)[0], {
          "modelValue": model.value
        }), null), slots.default && createVNode("div", {
          "class": "ve-progress__wrapper"
        }, [slots.default({
          value: model.value
        })])]
      });
    });
    let timer;
    return {
      start: () => {
        if (timer)
          clearTimeout(timer);
        transitionDuration.value = "0s";
        model.value = 0;
        setTimeout(() => {
          transitionDuration.value = "4s";
          model.value = 80;
        }, 0);
        timer = setTimeout(() => {
          if (transitionDuration.value === "4s")
            transitionDuration.value = void 0;
          timer = void 0;
        }, 4e3);
      },
      finish: () => {
        return new Promise((resolve) => {
          transitionDuration.value = "0.2s";
          model.value = 100;
          setTimeout(() => {
            transitionDuration.value = void 0;
            if (model.value >= 100)
              resolve(model.value);
          }, 200);
        });
      }
    };
  }
});
export {
  Progress,
  progressVariants
};
//# sourceMappingURL=progress.mjs.map
