'use strict';

/**
 * Generate a unique ID with an optional prefix, similar to React's useId hook.
 */
function useId(prefix = "dds") {
    const randomStr = Math.random().toString(36).slice(2, 10);
    return `__${prefix}_${randomStr}`;
}
function inheritAttributes(el, shadowElement, attributes = []) {
    const attributeObject = {};
    // Check for any aria attributes
    for (let i = 0; i < el.attributes.length; i++) {
        const attr = el.attributes[i];
        if (attr.name.includes("aria-")) {
            attributeObject[attr.name] = attr.value;
        }
    }
    // Check for attributes defined by component
    attributes.forEach((attr) => {
        if (el.hasAttribute(attr) || shadowElement?.hasAttribute(attr)) {
            const value = el.getAttribute(attr) ?? shadowElement?.getAttribute(attr) ?? null;
            if (value !== null) {
                attributeObject[attr] = value;
            }
            el.removeAttribute(attr);
        }
    });
    return attributeObject;
}
function hasSlot(el, name) {
    return [...el.childNodes].some((node) => {
        if (node.nodeType === Node.TEXT_NODE) {
            return node.textContent?.trim() !== "";
        }
        if (node.nodeType === Node.ELEMENT_NODE) {
            return !node.hasAttribute("slot");
        }
        return false;
    });
}

exports.hasSlot = hasSlot;
exports.inheritAttributes = inheritAttributes;
exports.useId = useId;
