// #region Imports
import { DomServiceLocator, isElement } from './Dom';
// #endregion
/**
 * @public
 */
export function getSlot(root, name) {
    return root
        ? DomServiceLocator.current.findDescendant(root, name ? `slot[name="${name}"]` : 'slot:not([name])')
        : null;
}
/**
 * @public
 */
export function getSlotElements(root, name, type, options) {
    const slot = getSlot(root, name);
    const elements = slot ? slot.assignedElements(options) : [];
    if (type) {
        if (isElement(type)) {
            return elements.filter((x) => x.tagName.toUpperCase() === type.is.toUpperCase());
        }
        return elements.filter((x) => x.tagName.toUpperCase() === type.tagName.toUpperCase());
    }
    return elements;
}
/**
 * @public
 */
export function getSlotElementsOfType(root, type, name, options) {
    const assignedElements = getSlot(root, name)?.assignedElements(options);
    const element = (assignedElements ?? []).filter((x) => x.tagName.toUpperCase() === type.is.toUpperCase());
    return element;
}
/**
 * @public
 */
export function getSlotElementOfType(root, type, name, options) {
    const assignedElements = getSlot(root, name)?.assignedElements(options);
    const elements = (assignedElements ?? []).filter((x) => x.tagName.toUpperCase() === type.is.toUpperCase());
    if (elements.length > 1) {
        throw new Error('Only one element is allowed in the slot.');
    }
    return elements[0];
}
//# sourceMappingURL=Slot.js.map