"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const valueParser = require("postcss-value-parser");
const transpileStyled_js_1 = require("./transpileStyled.js");
const jsProcessed = Symbol("jsProcessed-1");
const postCssImportJs = (opts = {}) => {
    return {
        postcssPlugin: "postcss-styled-js",
        Once(root, { AtRule, result }) {
            const promisesList = [];
            root.walkAtRules("import-styled-js", (rule) => {
                if (rule[jsProcessed]) {
                    return;
                }
                rule[jsProcessed] = true;
                promisesList.push((() => tslib_1.__awaiter(this, void 0, void 0, function* () {
                    const params = valueParser(rule.params).nodes;
                    for (const param of params) {
                        if (param.type !== "string") {
                            result.warn(`File path was expected`, {
                                node: rule
                            });
                            continue;
                        }
                        yield (0, transpileStyled_js_1.default)({
                            sourceFile: rule.source.input.file,
                            targets: param.value,
                            AtRule,
                            result,
                            rule
                        });
                    }
                    rule.remove();
                }))());
            });
            return Promise.all(promisesList);
        }
    };
};
postCssImportJs.postcss = true;
exports.default = postCssImportJs;
//# sourceMappingURL=postcss-js.js.map