/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
const appendClasses = (currentValue, value) => {
    if (value === null || value === void 0 ? void 0 : value.length)
        return `${currentValue} ${Array.from(value).join(' ')}`;
    return currentValue;
};
export default function getCustomClassesForPortal(element) {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j;
    let current = element;
    let finaleClass = '';
    let foundHostParent = false;
    while (current && !foundHostParent) {
        const root = (_a = current.getRootNode) === null || _a === void 0 ? void 0 : _a.call(current);
        if (((_b = current.part) === null || _b === void 0 ? void 0 : _b.contains('shift-form')) ||
            ((_c = current.classList) === null || _c === void 0 ? void 0 : _c.contains('shift-form')) ||
            ((_d = current.part) === null || _d === void 0 ? void 0 : _d.contains('shift-component')) ||
            ((_e = current.classList) === null || _e === void 0 ? void 0 : _e.contains('shift-component'))) {
            finaleClass = appendClasses(finaleClass, (_f = current === null || current === void 0 ? void 0 : current.part) !== null && _f !== void 0 ? _f : null);
            finaleClass = appendClasses(finaleClass, (_g = current === null || current === void 0 ? void 0 : current.classList) !== null && _g !== void 0 ? _g : null);
        }
        if (current.parentElement) {
            current = current.parentElement;
            continue;
        }
        if (root instanceof ShadowRoot) {
            current = root.host;
            if (!!finaleClass)
                foundHostParent = true;
            continue;
        }
        break;
    }
    if (foundHostParent && current) {
        finaleClass = appendClasses(finaleClass, (_h = current === null || current === void 0 ? void 0 : current.part) !== null && _h !== void 0 ? _h : null);
        finaleClass = appendClasses(finaleClass, (_j = current === null || current === void 0 ? void 0 : current.classList) !== null && _j !== void 0 ? _j : null);
    }
    return finaleClass === null || finaleClass === void 0 ? void 0 : finaleClass.replaceAll('  ', ' ');
}
