import type { Channel, ChannelMap, ChannelSortField, ProviderGroup, SortDirection } from "../types/index.js"; /** * Gets the provider tag for a channel key. For variant keys (e.g., "espn-hulu"), extracts the suffix after the canonical prefix (e.g., "hulu"). For canonical keys, * looks up the URL domain via getDomainConfig() and reads the providerTag field, falling back to "direct" if not found. * @param key - The channel key. * @returns The provider tag string. */ export declare function getProviderTagForChannel(key: string): string; /** * Returns all provider tags for a channel (canonical tag + all variant suffix tags). Used to determine which providers offer this channel. * @param canonicalKey - The canonical channel key. * @returns Array of provider tag strings. */ export declare function getChannelProviderTags(canonicalKey: string): string[]; /** * Scans all provider groups and collects unique provider tags with display names. Display names are derived from the provider field in DOMAIN_CONFIG entries that * have a providerTag. * @returns Array of { displayName, tag } objects sorted alphabetically by display name, with "direct" always first. */ export declare function getAllProviderTags(): { displayName: string; tag: string; }[]; /** * Gets the current enabled provider tags. * @returns Copy of the enabled providers array. Empty means no filter (all shown). */ export declare function getEnabledProviders(): string[]; /** * Sets the enabled provider tags. Empty array means "no filter" (all providers shown). * @param tags - The provider tags to enable. */ export declare function setEnabledProviders(tags: string[]): void; /** * Checks if a provider tag is currently enabled. Returns true if the tag is enabled, if no filter is active (empty set), or if the tag is "direct". * @param tag - The provider tag to check. * @returns True if the provider is available. */ export declare function isProviderTagEnabled(tag: string): boolean; /** * Centralized availability check for the provider filter. Returns true if the channel has at least one variant whose provider tag is enabled. * @param canonicalKey - The canonical channel key. * @returns True if the channel passes the provider filter. */ export declare function isChannelAvailableByProvider(canonicalKey: string): boolean; /** * Builds provider groups by scanning all channels and grouping them by key patterns. A key like "espn-disneyplus" is a variant of "espn" because it starts with * "espn-". Should be called at startup after channels are loaded. * @param channels - The merged channel map (predefined + user channels). */ export declare function buildProviderGroups(channels: ChannelMap): void; /** * Resolves a URL to a friendly provider display name. Checks built-in DOMAIN_CONFIG first for a stable, well-known provider name, then falls back to * getDomainConfig() which includes user domain mappings. This ordering prevents user domain overrides from corrupting display labels for predefined channel * variants — a user mapping a built-in domain to a custom profile should not rename every provider dropdown entry that uses that domain. * @param url - The URL to resolve a provider display name for. * @returns The provider display name, or the concise domain if no provider name is configured. */ export declare function getProviderDisplayName(url: string): string; /** * Resolves the provider display label for a channel. Checks in order: explicit `provider` field on the channel, the channel's explicit profile resolved via * user domain mappings, then URL-based built-in display name. This ensures channels assigned to user-defined profiles show the profile's provider name rather * than the built-in name for the URL domain. * @param channel - The channel to resolve a label for. * @returns The provider display label. */ export declare function getChannelProviderLabel(channel: Channel): string; export declare const VALID_SORT_FIELDS: Set; /** * Extracts a sortable string value from a channel for the specified sort field. Channel numbers are zero-padded to 6 digits for correct numeric ordering within a * string comparison. Provider values use the display label for human-meaningful sort order. This is the single source of truth for channel sort key extraction, * shared by both the server-side table renderer and the M3U playlist generator. * @param channel - Fallback channel definition, used only when the selected provider variant cannot be resolved (e.g., key not in the merged channel map). * @param key - The canonical channel key. Used for key-based sorting and to resolve the selected provider variant internally. * @param field - The sort field to extract. * @returns A lowercase string suitable for comparison-based sorting. */ export declare function getChannelSortKey(channel: Channel, key: string, field: ChannelSortField): string; /** * Compares two channels for sorting by the specified field and direction with a built-in channel name tiebreaker. The tiebreaker is always ascending so that rows * within each group maintain a consistent alphabetical order regardless of the primary sort direction. This is the single comparator for all sort sites — server HTML * render, client re-sort, and M3U playlist — to prevent ordering divergence. * @param channelA - First channel definition. * @param keyA - First channel key. * @param channelB - Second channel definition. * @param keyB - Second channel key. * @param field - The sort field to compare. * @param direction - Sort direction for the primary field. * @returns A negative, zero, or positive number for sort ordering. */ export declare function compareChannelSort(channelA: Channel, keyA: string, channelB: Channel, keyB: string, field: ChannelSortField, direction: SortDirection): number; /** * Gets the provider group for a channel key. Works with both canonical and variant keys. * @param key - Any channel key in the group. * @returns The provider group if the channel is part of a multi-provider group, undefined otherwise. */ export declare function getProviderGroup(key: string): ProviderGroup | undefined; /** * Checks if a channel key is a non-canonical provider variant. Used to filter variants from channel listings. * @param key - The channel key to check. * @returns True if the key is a variant (not canonical) in a provider group. */ export declare function isProviderVariant(key: string): boolean; /** * Checks if a channel has multiple provider options. Used to determine whether to show a provider dropdown in the UI. * @param key - The channel key to check. * @returns True if the channel has more than one provider variant. */ export declare function hasMultipleProviders(key: string): boolean; /** * Gets the canonical key for any channel key. For variant keys, returns the canonical key. For non-grouped or canonical keys, returns the input unchanged. * Handles the PREDEFINED_SUFFIX used when a user has overridden a predefined channel. * @param key - Any channel key. * @returns The canonical key for the channel's provider group, or the input key if not part of a group. */ export declare function getCanonicalKey(key: string): string; /** * Sets the user's provider selections. Called when loading from channels.json. * @param selections - Provider selections keyed by canonical channel key. */ export declare function setProviderSelections(selections: Record): void; /** * Gets all provider selections. * @returns Copy of the provider selections object. */ export declare function getProviderSelections(): Record; /** * Gets the provider selection for a specific channel. * @param canonicalKey - The canonical channel key. * @returns The selected provider key, or undefined if using the default. */ export declare function getProviderSelection(canonicalKey: string): string | undefined; /** * Sets the provider selection for a channel. * @param canonicalKey - The canonical channel key. * @param providerKey - The selected provider key. */ export declare function setProviderSelection(canonicalKey: string, providerKey: string): void; /** * Resolves a canonical channel key to the actual channel key based on user selection. If the user has selected a specific provider for this channel, returns that * provider's key. Otherwise returns the canonical key (default provider). When the provider filter is active, falls back to the first enabled variant if the stored * selection's provider is filtered out. * @param canonicalKey - The canonical channel key. * @returns The resolved provider key to use for streaming. */ export declare function resolveProviderKey(canonicalKey: string): string; /** * Gets a channel with inheritance applied. For provider variants, this merges the variant's properties with inherited properties from the canonical entry * using the live channel data (which includes user overrides). Use `resolvePredefinedVariant()` when you need resolution against pure predefined data. * @param key - The channel key (canonical or variant). * @returns The complete channel with inheritance applied, or undefined if the channel doesn't exist. */ export declare function getResolvedChannel(key: string): Channel | undefined; /** * Resolves a variant channel key against pure predefined data (ignoring user overrides). This is used for revert detection — when the user's edits match a * variant's predefined definition, the custom override can be removed and the provider selection switched to that variant. For canonical keys, returns the raw * predefined channel. For variant keys, applies the same inheritance rules as `getResolvedChannel()` but against `PREDEFINED_CHANNELS` instead of `channelsRef`. * @param key - The channel key (canonical or variant). * @returns The channel with inheritance applied against predefined data, or undefined if the key has no predefined definition. */ export declare function resolvePredefinedVariant(key: string): Channel | undefined;