/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-b859c78 | Cube Dev Team */
import * as fs from "fs";
import * as path from "path";

//#region src/tasty/zero/css-writer.ts
var CSSWriter = class {
	cssBlocks = /* @__PURE__ */ new Map();
	outputPath;
	devMode;
	constructor(outputPath, options = {}) {
		this.outputPath = outputPath;
		this.devMode = options.devMode ?? false;
	}
	/**
	* Add CSS block with deduplication key
	* @param key - Unique key for deduplication
	* @param css - CSS content
	* @param source - Optional source file path (used in devMode)
	*/
	add(key, css, source) {
		this.cssBlocks.set(key, {
			css,
			source
		});
	}
	/**
	* Check if a key already exists
	*/
	has(key) {
		return this.cssBlocks.has(key);
	}
	/**
	* Get the number of CSS blocks
	*/
	get size() {
		return this.cssBlocks.size;
	}
	/**
	* Write all collected CSS to the output file
	*/
	write() {
		const outputDir = path.dirname(this.outputPath);
		if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
		const cssBlocks = [];
		for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
		else cssBlocks.push(block.css);
		const css = cssBlocks.join("\n\n");
		fs.writeFileSync(this.outputPath, `/* Generated by @cube-dev/ui-kit/tasty/zero - DO NOT EDIT */\n\n` + css);
	}
	/**
	* Get all CSS as string (for testing or in-memory use)
	*/
	getCSS() {
		const cssBlocks = [];
		for (const block of this.cssBlocks.values()) if (this.devMode && block.source) cssBlocks.push(`/* from: ${block.source} */\n${block.css}`);
		else cssBlocks.push(block.css);
		return cssBlocks.join("\n\n");
	}
	/**
	* Clear all collected CSS
	*/
	clear() {
		this.cssBlocks.clear();
	}
	/**
	* Get the output path
	*/
	getOutputPath() {
		return this.outputPath;
	}
};

//#endregion
export { CSSWriter };
//# sourceMappingURL=css-writer.js.map