import { VFileMessage as e } from "../../vfile-message/lib/index.js";
import { minpath as t } from "./minpath.browser.js";
import { minproc as n } from "./minproc.browser.js";
import { isUrl as r } from "./minurl.shared.js";
import { urlToPath as i } from "./minurl.browser.js";
//#region ../../node_modules/vfile/lib/index.js
var a = [
	"history",
	"path",
	"basename",
	"stem",
	"extname",
	"dirname"
], o = class {
	constructor(e) {
		let t;
		t = e ? r(e) ? { path: e } : typeof e == "string" || u(e) ? { value: e } : e : {}, this.cwd = "cwd" in t ? "" : n.cwd(), this.data = {}, this.history = [], this.messages = [], this.value, this.map, this.result, this.stored;
		let i = -1;
		for (; ++i < a.length;) {
			let e = a[i];
			e in t && t[e] !== void 0 && t[e] !== null && (this[e] = e === "history" ? [...t[e]] : t[e]);
		}
		let o;
		for (o in t) a.includes(o) || (this[o] = t[o]);
	}
	get basename() {
		return typeof this.path == "string" ? t.basename(this.path) : void 0;
	}
	set basename(e) {
		c(e, "basename"), s(e, "basename"), this.path = t.join(this.dirname || "", e);
	}
	get dirname() {
		return typeof this.path == "string" ? t.dirname(this.path) : void 0;
	}
	set dirname(e) {
		l(this.basename, "dirname"), this.path = t.join(e || "", this.basename);
	}
	get extname() {
		return typeof this.path == "string" ? t.extname(this.path) : void 0;
	}
	set extname(e) {
		if (s(e, "extname"), l(this.dirname, "extname"), e) {
			if (e.codePointAt(0) !== 46) throw Error("`extname` must start with `.`");
			if (e.includes(".", 1)) throw Error("`extname` cannot contain multiple dots");
		}
		this.path = t.join(this.dirname, this.stem + (e || ""));
	}
	get path() {
		return this.history[this.history.length - 1];
	}
	set path(e) {
		r(e) && (e = i(e)), c(e, "path"), this.path !== e && this.history.push(e);
	}
	get stem() {
		return typeof this.path == "string" ? t.basename(this.path, this.extname) : void 0;
	}
	set stem(e) {
		c(e, "stem"), s(e, "stem"), this.path = t.join(this.dirname || "", e + (this.extname || ""));
	}
	fail(e, t, n) {
		let r = this.message(e, t, n);
		throw r.fatal = !0, r;
	}
	info(e, t, n) {
		let r = this.message(e, t, n);
		return r.fatal = void 0, r;
	}
	message(t, n, r) {
		let i = new e(t, n, r);
		return this.path && (i.name = this.path + ":" + i.name, i.file = this.path), i.fatal = !1, this.messages.push(i), i;
	}
	toString(e) {
		return this.value === void 0 ? "" : typeof this.value == "string" ? this.value : new TextDecoder(e || void 0).decode(this.value);
	}
};
function s(e, n) {
	if (e && e.includes(t.sep)) throw Error("`" + n + "` cannot be a path: did not expect `" + t.sep + "`");
}
function c(e, t) {
	if (!e) throw Error("`" + t + "` cannot be empty");
}
function l(e, t) {
	if (!e) throw Error("Setting `" + t + "` requires `path` to be set too");
}
function u(e) {
	return !!(e && typeof e == "object" && "byteLength" in e && "byteOffset" in e);
}
//#endregion
export { o as VFile };
