//#region rolldown:runtime
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
	if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
		key = keys[i];
		if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
			get: ((k) => from[k]).bind(null, key),
			enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
		});
	}
	return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
	value: mod,
	enumerable: true
}) : target, mod));

//#endregion
let node_fs = require("node:fs");
node_fs = __toESM(node_fs);

//#region src/index.ts
const UTF8 = "utf8";
const options = [
	{
		label: "ASCII",
		value: "ascii"
	},
	{
		label: "UTF-8",
		value: UTF8
	},
	{
		label: "UTF-16 LE",
		value: "utf16le"
	},
	{
		label: "Base64",
		value: "base64"
	},
	{
		label: "Base64 URL-safe",
		value: "base64url"
	},
	{
		label: "Latin-1",
		value: "latin1"
	},
	{
		label: "Hexadecimal",
		value: "hex"
	}
];
const plugin = { templateFunctions: [{
	name: "fs.readFile",
	description: "Read the contents of a file as utf-8",
	previewArgs: ["encoding"],
	args: [
		{
			title: "Select File",
			type: "file",
			name: "path",
			label: "File"
		},
		{
			type: "select",
			name: "encoding",
			label: "Encoding",
			defaultValue: UTF8,
			description: "Specifies how the file's bytes are decoded into text when read",
			options
		},
		{
			type: "checkbox",
			name: "trim",
			label: "Trim Whitespace",
			description: "Remove leading and trailing whitespace from the file contents"
		}
	],
	async onRender(_ctx, args) {
		if (!args.values.path || !args.values.encoding) return null;
		try {
			const v = await node_fs.default.promises.readFile(String(args.values.path ?? ""), { encoding: String(args.values.encoding ?? "utf-8") });
			return args.values.trim ? v.trim() : v;
		} catch {
			return null;
		}
	}
}] };

//#endregion
exports.plugin = plugin;