"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const source_map_1 = require("source-map");
const stacktrace_parser_1 = require("stacktrace-parser");
const glob_1 = require("glob");
const path = require("node:path");
const FilePath_js_1 = require("./FilePath.js");
class styled {
    static css(t, ...a) {
        const stack = (0, stacktrace_parser_1.parse)(new Error().stack);
        const callee = stack[1];
        const file = callee.file;
        const filePath = new FilePath_js_1.default(file);
        const s = new source_map_1.SourceNode(callee.lineNumber, callee.column || 1, filePath.webPath);
        for (let index = 0; index < t.length; index++) {
            const element = t[index];
            s.add(element);
            if (index < a.length) {
                const arg = a[index];
                if (Array.isArray(arg)) {
                    for (const item of arg) {
                        s.add(item);
                    }
                    continue;
                }
                if (arg instanceof source_map_1.SourceNode) {
                    s.add(arg);
                    continue;
                }
                s.add(arg);
            }
        }
        return s;
    }
    static import(src) {
        const stack = (0, stacktrace_parser_1.parse)(new Error().stack);
        const callee = stack[1];
        const file = callee.file;
        const filePath = new FilePath_js_1.default(file);
        const { dir, name } = filePath;
        if (!Array.isArray(src)) {
            src = [src];
        }
        const srcPath = src.map((s) => path.join(dir, s).replaceAll("\\", "/"));
        const s = new source_map_1.SourceNode(callee.lineNumber, callee.column || 1, name);
        console.log({ filePath, dir, srcPath });
        for (const file of (0, glob_1.globIterateSync)(srcPath, { absolute: true })) {
            const fp = new FilePath_js_1.default(file);
            const src = fp.relativeTo(filePath);
            const text = `@import "${src}";`;
            console.log(text);
            s.add(text);
        }
        return s;
    }
}
exports.default = styled;
//# sourceMappingURL=styled.js.map