import { SchedulerResource, SchedulerGroup } from '../types/scheduler-types'; import { CellData, ResourceNodeRef, ResourceTreeItem } from '../types/internal-interface'; /** * Represents a single resource in the hierarchy. * * @private */ export interface ResourceLevel { /** * The resource configuration. */ resource: SchedulerResource; /** * The associated resource data. */ resourceData: Record; /** * Hierarchical path as an array of IDs. */ groupOrder: string[]; /** * Available render dates for this resource. */ renderDates: Date[]; /** * Working days for this resource. */ workDays: number[]; /** * Child resources in the hierarchy. */ children: ResourceLevel[]; /** * CSS class for events in this resource. */ cssClass?: string; /** * Index for group identification. */ groupIndex?: number; } /** * Metadata for resource grouping configuration. * * @private */ export interface ResourceGroupingMetadata { /** * Grouping order of resource names. */ resourceNames: string[]; /** * Whether rendering is grouped by date first. */ byDate: boolean; /** * Whether to filter by group ID. */ byGroupID: boolean; /** * Enables creating and editing linked appointments assigned to multiple resources. */ groupEdit: boolean; /** * Depth of the resource hierarchy. */ depth: number; /** * Array of leaf-level resources. */ leafResources: ResourceLevel[]; /** * Whether the scheduler is rendering in compact view mode. * When `true`, the DOM contains only the visible leaf's cells and * cell-index arithmetic must collapse to the date index alone. */ enableCompactView: boolean; } /** * Metadata for a timeline resource row used in resource grouping views. * * @private */ export interface TimelineResourceRowMeta { /** * Resource data associated with this row. */ resourceData?: Record; /** * Resource configuration metadata. */ resource?: SchedulerResource; /** * Unique index of the resource group. */ groupIndex: number; /** * Parent resource group index. */ parentGroupIndex?: number; /** * Number of child resources. */ count?: number; /** * Display text of the resource row. */ resourceName?: string; /** * Hierarchy depth level of the resource. */ depth?: number; /** * Resource hierarchy path used to match timeline events. */ groupOrder?: string[]; } export declare class ResourceGroupingService { /** * Builds a hierarchical resource tree based on grouping configuration. * Adapts the recursive "group" function from EJ2 Scheduler. * * @param {SchedulerResource[]} resources - All available resources * @param {SchedulerGroup} groupConfig - Grouping configuration (resources, byGroupID) * @param {Date[]} allRenderDates - Global render dates (used as fallback) * @param {number[]} defaultWorkDays - Default work days (used as fallback) * @returns {ResourceLevel[]} Root-level resource array for rendering * * @private */ static buildResourceTree(resources: SchedulerResource[], groupConfig: SchedulerGroup, allRenderDates: Date[], defaultWorkDays: number[]): ResourceLevel[]; /** * Extracts all leaf-level resources from the tree (final resources with data). * * @param {ResourceLevel[]} resourceTree - Root resource tree * @returns {ResourceLevel[]} Array of all leaf resources * * @private */ static getLeafResources(resourceTree: ResourceLevel[]): ResourceLevel[]; /** * Collects resource grouping metadata. * * @param {ResourceLevel[]} resourceTree - Root resource tree * @param {SchedulerGroup} groupConfig - Grouping configuration * @returns {ResourceGroupingMetadata} Metadata about the resource grouping * * @private */ static getGroupingMetadata(resourceTree: ResourceLevel[], groupConfig: SchedulerGroup): ResourceGroupingMetadata; private static getResourcesAtLevel; private static buildResourceHeaderCell; private static buildHeaderLevel; /** * Generates column levels for rendering with unified slot handling. * This is a unified method supporting both date-based (Day/Week views) and weekday-based (Month view) layouts. * Slot format is auto-detected: slots with 'weekdayIndex' are treated as weekday headers, * Date objects or CellData with 'date' property are treated as date headers. * * @param {ResourceLevel[]} resourceTree - Root resource tree * @param {SchedulerGroup} groupConfig - Grouping configuration * @param {Date[] | CellData[]} slots - Generic slot data (Date objects OR weekday slots with CellData) * @param {ResourceLevel[]} [leafResources] - Pre-calculated leaf resources (avoids recalculation) * @returns {ColumnLevel[]} Hierarchical column level structure for rendering * * @private */ static generateColumnLevels(resourceTree: ResourceLevel[], groupConfig: SchedulerGroup, slots: Date[] | CellData[], leafResources?: ResourceLevel[]): CellData[][]; /** * Determines if a resource row should be hidden based on parent expansion state. * * Traverses the parent hierarchy of a resource row. If any ancestor parent is collapsed * (expandedState = false), the entire row and its descendants are hidden from view. * This ensures child resources of collapsed parents remain hidden from the UI. * * @param {TimelineResourceRowMeta} row - The resource row to evaluate for visibility * @param {Map} expandedState - Map of groupIndex to expansion state (true = expanded, false = collapsed) * @param {TimelineResourceRowMeta[]} allRows - Complete list of all timeline resource rows for hierarchy lookup * @returns {boolean} True if row should be hidden; false if row should be visible * * @private */ static shouldHideTimelineResourceRow(row: TimelineResourceRowMeta, expandedState: Map, allRows: TimelineResourceRowMeta[]): boolean; /** * Builds flat timeline resource headers from hierarchical tree with proper group indexing. * * @param {ResourceLevel[]} resourceTree - Root resource tree * @param {string} textField - Field name to use for resource name display * @returns {TimelineResourceRowMeta[]} Flat array of timeline resource rows with parent relationships * * @private */ static buildTimelineResourceHeaders(resourceTree: ResourceLevel[]): TimelineResourceRowMeta[]; /** * Resolves the leaf-resource index for a given initial resource identifier. * Used by compact view mode to honour `group.selectedResource`. * * @param {ResourceLevel[]} leafResources - All leaf resources, as returned by `getLeafResources`. * @param {string | number | undefined} id - Resource identifier (string or number). Matched against each leaf's value at `resource.idField` (default: `'id'`). * @returns {number} The zero-based index of the matching leaf resource. Returns `0` when no match is found or when `id` is `undefined`. * * @private */ static getResourceByInitialId(leafResources: ResourceLevel[], id: string | number | undefined): number; /** * Returns a stable, human-readable label for a leaf resource. The fallback * order mirrors the Blazor `RenderResourceHeaderText` resolution * (textField ? name ? id) so the breadcrumb renders correctly even when * `resourceData` is partially populated by upstream consumers. * * @param {ResourceLevel} leaf - The leaf resource whose label should be resolved. * @returns {string} The resolved label; an empty string when no label candidate is found. * * @private */ static getLeafLabel(leaf: ResourceLevel | null | undefined): string; /** * Builds a composite, stable id for a tree node as * `${resource.name}_${getNodeId(node)}`. Used by the compact-view * TreeView so the bound node id is unique across both the resource * type and the resource row, matching how the resource data is * identified elsewhere in the grouping pipeline. * * @param {ResourceNodeRef} node - The node whose composite id should be built. * @returns {string} The composite id; an empty string when the node, its * `resource` or its resolved id is missing. * * @private */ static getTreeNodeId(node: ResourceNodeRef | null | undefined): string; /** * Returns the stable identifier of a tree node. Looks up the configured * `idField`, falling back to `'id'`. Returns `null` when the node, its * data or the resolved id is missing — callers can treat `null` as a * non-match rather than crashing on `undefined`. * * @param {ResourceNodeRef | null | undefined} node - Node whose id should be resolved. * @returns {string | number | null} Stable id; `null` when the node, its data, or its id is missing. * * @private */ static getNodeId(node: ResourceNodeRef | null | undefined): string | number | null; /** * Maps `ResourceLevel` tree to compact-view `TreeView` items. * * @param {ResourceLevel[]} resourceTree - Root resource tree. * @returns {ResourceTreeItem[]} Tree items, or `[]` for empty input. * @private */ static buildResourceTreeItems(resourceTree: ResourceLevel[] | null | undefined): ResourceTreeItem[]; /** * Resolves `selectedIds` for the leaf at `selectedGroupIndex`. * * @param {ResourceLevel[]} leafResources - Leaves in current scope. * @param {number} selectedGroupIndex - Index into `leafResources`, or `-1`. * @returns {string[]} `[nodeId]` or `[]`. * @private */ static resolveTreeSelectionId(leafResources: ResourceLevel[] | null | undefined, selectedGroupIndex: number | null | undefined): string[]; /** * Resolves `defaultExpandedIds` — every parent row (`count > 0`) is expanded. * * @param {TimelineResourceRowMeta[]} rows - Timeline resource headers. * @returns {string[]} Composite node ids for parent rows. * @private */ static resolveDefaultExpandedTreeIds(rows: TimelineResourceRowMeta[] | null | undefined): string[]; /** * Resolves the labels for a leaf resource's hierarchy path. * * @param {ResourceLevel[] | null | undefined} tree - Resource hierarchy. * @param {ResourceLevel | null | undefined} leaf - Leaf resource. * @returns {string[]} Labels for the leaf's hierarchy path. * * @private */ static resolveLeafBreadcrumb(tree: ResourceLevel[] | null | undefined, leaf: ResourceLevel | null | undefined): string[]; }