"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.styled = exports.v = exports.css = exports.createGlobalStyle = void 0;
/* eslint-disable @typescript-eslint/ban-ts-comment */
const core_1 = require("@xstyled/core");
const styled_components_1 = require("@xstyled/styled-components");
const util_1 = require("@xstyled/util");
const styled_components_2 = __importStar(require("styled-components"));
const system_1 = require("../system");
/** Creates enhanced 'styled' function with optional style generators and prop-forwarding safeguard. */
function createBaseStyled(css, generator) {
    const config = generator ? forwardPropConfig(generator) : {};
    return ((component) => {
        const baseStyled = config ? (0, styled_components_2.default)(component).withConfig(config) : (0, styled_components_2.default)(component);
        return getCreateStyle(baseStyled, css, generator);
    });
}
/** Enhances createGlobalStyle function with custom 'css' helper. */
function createCreateGlobalStyle() {
    const css = createCssFunction();
    return ((...args) => (0, styled_components_2.createGlobalStyle)([
        // @ts-ignore
        css(...args),
    ]));
}
/** Enhances styled-components' 'css' function with automatic theming. */
function createCssFunction() {
    return ((...args) => {
        const scCssArgs = (0, styled_components_2.css)(...args);
        const flattenedArgs = (0, util_1.flattenStrings)(scCssArgs);
        return flattenedArgs.map(core_1.transform);
    });
}
/**
 * Creates full 'styled' function with properties for components.
 * Includes base version and system version using 'Box' postfix.
 */
function createStyled(generator) {
    const css = createCssFunction();
    const styled = createBaseStyled(css);
    const vstyled = createBaseStyled(css, generator);
    Object.keys(styled_components_2.default).forEach(key => {
        // @ts-ignore
        styled[key] = styled(key);
        // @ts-ignore
        styled[`${key}Box`] = vstyled(key);
    });
    return styled;
}
/** Provides configuration to the 'styled' function, which filters out xstyled system props. */
function forwardPropConfig(generator) {
    return {
        shouldForwardProp: (prop, defaultValidatorFn) => {
            if (typeof prop === 'string' && generator.meta.props.includes(prop))
                return false;
            return defaultValidatorFn(prop);
        },
    };
}
/** Extends styled component with a given styles generator (system). */
function getCreateStyle(baseCreateStyle, css, generator) {
    const createStyle = (...args) => baseCreateStyle `${css(...args)}${generator}`;
    createStyle.attrs = (attrs) => getCreateStyle(baseCreateStyle.attrs(attrs), css, generator);
    createStyle.withConfig = (config) => getCreateStyle(baseCreateStyle.withConfig(config), css, generator);
    return createStyle;
}
exports.createGlobalStyle = createCreateGlobalStyle();
exports.css = createCssFunction();
exports.v = (0, styled_components_1.createX)(system_1.system);
exports.styled = createStyled(system_1.system);
exports.default = exports.styled;
//# sourceMappingURL=styled.js.map