/**
 * Shared primitive utilities
 * @countermeasure/web-components/primitives
 */

/** Resolve a container reference to an HTMLElement */
export function resolveContainer(container: HTMLElement | string): HTMLElement {
  if (typeof container === 'string') {
    const el = document.querySelector<HTMLElement>(container)
    if (el === null) {
      throw new Error(`Container not found: ${container}`)
    }
    return el
  }
  return container
}

let nextId = 0

/** Generate a unique ID for accessibility linkage */
export function uniqueId(prefix: string): string {
  nextId += 1
  return `${prefix}-${String(nextId)}`
}
