var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var ClassUtility = /** @class */ (function () {
    function ClassUtility() {
    }
    // public getEntryClasses(item: MixedContentEntry): string[] {
    //   let classes = (item.fields.classes?.map((c) => c.fields.title).filter((c) => !!c) ||
    //     []) as string[];
    //   return classes;
    // }
    // public getEntryClassesStrFromModuleCss(
    //   item: MixedContentEntry,
    //   css: {
    //     readonly [key: string]: string;
    //   },
    //   ...classes: ClassNamesBaseType[]
    // ): string {
    //   return this.getClassesStrFromModuleCss(
    //     css,
    //     ...(this.getEntryClasses(item) as string[]),
    //     ...classes,
    //   );
    // }
    /**
       * This utility process all arguments to be a className as string or string[].
       * * Same goal as classNames npm package just different method including types
       * @param {boolean} asString Default value: true. If we want to return a string of array, set it false
       * @param {ClassNamesBaseType[]} classes Accepted types:
       * * String: 'class1 class2'
      //  * * Array: ['class1','class2 class5',{ class3: false, class4: true }]
       * * Object: { class1: false, class2: true }
       * * Undefined, Null, False, Function: these will be filtered
       * @returns {string | string[]} string OR array of string
       * @example
       * // returns 'class1 class2 class5 class4'
       * composeClasses(true, 'class1','class2 class5',{ class3: false, class4: true }) as string
       * // return ['class1','class2','class5','class4']
       * composeClasses(false, 'class1','class2 class5',{ class3: false, class4: true }) as string[]
       */
    ClassUtility.prototype.composeClasses = function (asString) {
        var _this = this;
        if (asString === void 0) { asString = true; }
        var classes = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            classes[_i - 1] = arguments[_i];
        }
        var list = classes.reduce(function (arr, c) {
            switch (typeof c) {
                case 'undefined':
                case 'boolean':
                case 'function':
                    return arr;
                case 'object': {
                    if (!c)
                        return arr;
                    return Array.isArray(c)
                        ? __spreadArray(__spreadArray([], __read(arr), false), __read(_this.composeClasses.apply(_this, __spreadArray([false], __read(c), false))), false) : __spreadArray(__spreadArray([], __read(arr), false), __read(Object.entries(c).reduce(function (obj, _a) {
                        var _b = __read(_a, 2), key = _b[0], value = _b[1];
                        if (!value)
                            return obj;
                        return __spreadArray(__spreadArray([], __read(obj), false), __read((typeof key === 'string' ? key.trim().split(' ') : [key])), false);
                    }, [])), false);
                }
                case 'string': {
                    if (!c)
                        return arr;
                    return __spreadArray(__spreadArray([], __read(arr), false), __read(c.trim().split(' ')), false);
                }
                default:
                    return __spreadArray(__spreadArray([], __read(arr), false), [c], false);
            }
        }, []);
        return asString ? list.join(' ') : list;
    };
    ClassUtility.prototype.getClassesStrFromModuleCss = function (css) {
        var classes = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            classes[_i - 1] = arguments[_i];
        }
        return this.composeClasses.apply(this, __spreadArray([false], __read(classes), false)).map(function (c) { return css[c] || c; }).join(' ');
    };
    return ClassUtility;
}());
var inst = new ClassUtility();
export default inst;
export var _cx = function (css) {
    if (css === void 0) { css = {}; }
    return function () {
        var classes = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            classes[_i] = arguments[_i];
        }
        return inst.getClassesStrFromModuleCss.apply(inst, __spreadArray([css], __read(classes), false));
    };
};
