import { r as __toESM } from "./chunk-1SJ2vVWa.js";
import { m as require_main } from "./transformers-DzHGqYO2.js";
import { n as getUniqueName, r as setUniqueName, t as URLPath } from "./URLPath-BYceu_vY.js";
import { t as camelCase } from "./casing-BSeq_teY.js";

//#region src/utils/Cache.ts
var Cache = class {
	#buffer = /* @__PURE__ */ new Map();
	async get(key) {
		return this.#buffer.get(key) ?? null;
	}
	async set(key, value) {
		this.#buffer.set(key, value);
	}
	async delete(key) {
		this.#buffer.delete(key);
	}
	async clear() {
		this.#buffer.clear();
	}
	async keys() {
		return [...this.#buffer.keys()];
	}
	async values() {
		return [...this.#buffer.values()];
	}
	async flush() {}
};

//#endregion
//#region src/utils/FunctionParams.ts
var import_main = /* @__PURE__ */ __toESM(require_main(), 1);
/**
* @deprecated
*/
var FunctionParams = class FunctionParams {
	#items = [];
	constructor() {
		return this;
	}
	get items() {
		return this.#items.flat();
	}
	add(item) {
		if (!item) return this;
		if (Array.isArray(item)) {
			item.filter(Boolean).forEach((it) => {
				this.#items.push(it);
			});
			return this;
		}
		this.#items.push(item);
		return this;
	}
	static #orderItems(items) {
		return (0, import_main.orderBy)(items.filter(Boolean), [(v) => {
			if (Array.isArray(v)) return;
			return !v.default;
		}, (v) => {
			if (Array.isArray(v)) return;
			return v.required ?? true;
		}], ["desc", "desc"]);
	}
	static #addParams(acc, item) {
		const { enabled = true, name, type, required = true,...rest } = item;
		if (!enabled) return acc;
		if (!name) {
			acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
			return acc;
		}
		const parameterName = name.startsWith("{") ? name : camelCase(name);
		if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
		else acc.push(`${parameterName}?: ${type}`);
		else acc.push(`${parameterName}`);
		return acc;
	}
	static toObject(items) {
		let type = [];
		let name = [];
		const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
		const required = items.every((item) => item.required) ?? true;
		items.forEach((item) => {
			name = FunctionParams.#addParams(name, {
				...item,
				type: void 0
			});
			if (items.some((item$1) => item$1.type)) type = FunctionParams.#addParams(type, item);
		});
		return {
			name: `{ ${name.join(", ")} }`,
			type: type.length ? `{ ${type.join("; ")} }` : void 0,
			enabled,
			required
		};
	}
	static toString(items) {
		return FunctionParams.#orderItems(items).reduce((acc, item) => {
			if (Array.isArray(item)) {
				if (item.length <= 0) return acc;
				const subItems = FunctionParams.#orderItems(item);
				const objectItem = FunctionParams.toObject(subItems);
				return FunctionParams.#addParams(acc, objectItem);
			}
			return FunctionParams.#addParams(acc, item);
		}, []).join(", ");
	}
	toObject() {
		const items = FunctionParams.#orderItems(this.#items).flat();
		return FunctionParams.toObject(items);
	}
	toString() {
		const items = FunctionParams.#orderItems(this.#items);
		return FunctionParams.toString(items);
	}
};

//#endregion
//#region src/utils/promise.ts
function isPromise(result) {
	return !!result && typeof result?.then === "function";
}
function isPromiseFulfilledResult(result) {
	return result.status === "fulfilled";
}
function isPromiseRejectedResult(result) {
	return result.status === "rejected";
}

//#endregion
//#region src/utils/renderTemplate.ts
function renderTemplate(template, data = void 0) {
	if (!data || !Object.keys(data).length) return template.replace(/{{(.*?)}}/g, "");
	return template.match(/{{(.*?)}}/g)?.reduce((prev, curr) => {
		const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
		if (index === void 0) return prev;
		const value = data[index];
		if (value === void 0) return prev;
		return prev.replace(curr, () => {
			if (typeof value === "boolean") return `${value.toString()}` || "false";
			return value || "";
		}).trim();
	}, template) || "";
}

//#endregion
//#region src/utils/timeout.ts
async function timeout(ms) {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve(true);
		}, ms);
	});
}

//#endregion
export { Cache, FunctionParams, URLPath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
//# sourceMappingURL=utils.js.map