import { computed, onBeforeUnmount, ref, watch } from "vue";
//#region components/file-card/components/usePercent.ts
var AUTO_INTERVAL = 200;
var STEP_BUCKETS = [
	[30, .05],
	[70, .03],
	[96, .01]
];
function usePercent(spinning, percent) {
	const mockPercent = ref(0);
	let timer = null;
	watch(() => [spinning, percent], () => {
		if (timer) {
			clearInterval(timer);
			timer = null;
		}
		if (percent === "auto" && spinning) {
			mockPercent.value = 0;
			timer = setInterval(() => {
				const restPercent = 100 - mockPercent.value;
				for (const [limit, stepPtg] of STEP_BUCKETS) if (mockPercent.value <= limit) {
					mockPercent.value += restPercent * stepPtg;
					break;
				}
			}, AUTO_INTERVAL);
		}
	}, { immediate: true });
	onBeforeUnmount(() => {
		if (timer) clearInterval(timer);
	});
	return [computed(() => percent === "auto" ? mockPercent.value : percent), computed(() => percent === "auto" ? `${mockPercent.value.toFixed(0)}%` : `${percent ?? 0}%`)];
}
//#endregion
export { usePercent as default };
