import { ChangeDetectorRef, OnDestroy } from '@angular/core';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import { ResourceData, MJListEntity, MJUserViewEntity } from '@memberjunction/core-entities';
import { Subject } from 'rxjs';
import { ListSetOperationsService, VennData, VennIntersection, SetOperation, SetOperationResult } from '../services/list-set-operations.service';
import { VennRegionClickEvent } from './venn-diagram/venn-diagram.component';
import { MJNotificationService } from '@memberjunction/ng-notifications';
import { ExportService } from '@memberjunction/ng-export-service';
import type { ListDelta } from '@memberjunction/lists-base';
import * as i0 from "@angular/core";
interface ListSelection {
    list: MJListEntity;
    entityName: string;
    color: string;
}
/**
 * Parallel structure for view operands. Views resolve to record IDs the
 * same way lists do (via the operations service's cache), but are tracked
 * separately in component state so existing list-only flows keep working.
 */
interface ViewSelection {
    view: MJUserViewEntity;
    entityName: string;
    entityID: string;
    color: string;
}
/**
 * Preview record with meaningful display fields
 */
interface PreviewRecord {
    id: string;
    displayName: string;
    secondaryInfo?: string;
    entityName: string;
}
/**
 * Entity option for filtering
 */
interface EntityOption {
    id: string;
    name: string;
    listCount: number;
}
export declare class ListsOperationsResource extends BaseResourceComponent implements OnDestroy {
    private cdr;
    private setOperationsService;
    private notificationService;
    private exportService;
    protected destroy$: Subject<void>;
    maxLists: number;
    selectedLists: ListSelection[];
    availableLists: MJListEntity[];
    filteredAvailableLists: MJListEntity[];
    listSearchTerm: string;
    showListDropdown: boolean;
    selectedViews: ViewSelection[];
    availableViews: MJUserViewEntity[];
    filteredAvailableViews: MJUserViewEntity[];
    viewSearchTerm: string;
    showViewDropdown: boolean;
    entityOptions: EntityOption[];
    selectedEntityId: string;
    vennData: VennData | null;
    selectedRegion: VennIntersection | null;
    lastOperationResult: SetOperationResult | null;
    previewRecords: string[];
    previewRecordsDisplay: PreviewRecord[];
    loadingPreview: boolean;
    isCalculating: boolean;
    isSaving: boolean;
    showCreateDialog: boolean;
    newListName: string;
    newListDescription: string;
    recordsToAdd: string[];
    showAddToListDialog: boolean;
    addToListSearchTerm: string;
    filteredAddToListOptions: MJListEntity[];
    selectedTargetListId: string | null;
    composeOp: SetOperation;
    composeTarget: 'new' | 'existing';
    composeNewListName: string;
    composeTargetListId: string | null;
    composeTargetSearch: string;
    showComposeTargetDropdown: boolean;
    isComposing: boolean;
    composeDelta: ListDelta | null;
    composeConfirmVisible: boolean;
    showExportDialog: boolean;
    exportFormat: 'excel' | 'csv' | 'json';
    exportFields: Array<{
        Name: string;
        DisplayName: string;
        Selected: boolean;
    }>;
    exportRecordCount: number;
    isExporting: boolean;
    private entityIdFromSelectedLists;
    private currentEntityInfo;
    private readonly USER_SETTING_KEY;
    private saveSettingsTimeout;
    private isLoadingSettings;
    constructor(cdr: ChangeDetectorRef, setOperationsService: ListSetOperationsService, notificationService: MJNotificationService, exportService: ExportService);
    get hasMultipleEntities(): boolean;
    ngOnInit(): Promise<void>;
    ngOnDestroy(): void;
    loadAvailableLists(): Promise<void>;
    /**
     * Build entity options for the filter dropdown
     */
    private buildEntityOptions;
    /**
     * Handle entity filter change
     */
    onEntityFilterChange(): void;
    filterAvailableLists(): void;
    /**
     * Same logic as `filterAvailableLists` for the view picker. Views are
     * locked to the same entity as any already-selected list or view.
     */
    filterAvailableViews(): void;
    /**
     * Returns the entity ID that operands are currently locked to, or null
     * if no operands are selected. Lists win over views purely because they
     * come first in the operand list; either source is authoritative.
     */
    private get lockedEntityID();
    /**
     * Display name of the entity currently locking the picker — drives the
     * "Comparing operands of type: …" hint in the UI. Falls back to the
     * first available denormalized name we have.
     */
    get lockedEntityName(): string | null;
    addList(list: MJListEntity): void;
    removeList(index: number): void;
    addView(view: MJUserViewEntity): void;
    removeView(index: number): void;
    private reassignOperandColors;
    recalculateVenn(): Promise<void>;
    /**
     * Combined operand count — drives "≥ 2 operands" checks for showing
     * operation buttons + the Venn diagram empty-state.
     */
    get totalOperandCount(): number;
    /**
     * Build the unified `SetOperand[]` for the service. Lists come first
     * (preserving the existing color order); views follow. Each view's
     * color is picked sequentially from the same palette.
     */
    private buildAllOperands;
    onRegionClick(event: VennRegionClickEvent): void;
    /**
     * Load preview records with meaningful display fields
     */
    private loadPreviewRecords;
    /**
     * Get the best display fields for an entity based on metadata
     */
    private getDisplayFields;
    /**
     * Get a display value from a record
     */
    private getDisplayValue;
    /**
     * Open a record in the entity viewer
     */
    openRecord(record: PreviewRecord): void;
    performOperation(operation: SetOperation): Promise<void>;
    /**
     * Server-side compose preview — builds inputs from the currently selected
     * operands (lists + views) and calls `ComposeLists`. Returns the signed
     * delta so `composeAndSave` can route through `ApplyListDelta` when the
     * target is an existing list.
     */
    private buildComposeInputs;
    get canCompose(): boolean;
    /**
     * "Preview Result" — re-runs the Quick-Operation path with the compose
     * panel's chosen op so the user can see the expected output count
     * before committing. We use the local set-op service rather than the
     * server here because preview is a read-only operation that doesn't
     * need a delta token (target is null) — staying local keeps it fast.
     */
    previewCompose(): Promise<void>;
    /**
     * Commit the compose: either materialize a new list (client-side using
     * the previewed record IDs) or merge into an existing list via the
     * server's ComposeLists + ApplyListDelta flow.
     */
    composeAndSave(): Promise<void>;
    /**
     * New-list path: ensure preview is fresh, then route through the
     * existing "create list from selection" machinery using the result's
     * record IDs. This keeps materialization + naming in one place.
     */
    private composeToNewList;
    /**
     * Existing-list path: compose server-side to get a signed delta, then
     * surface the delta-confirm dialog. Sync semantics (replace contents)
     * apply implicitly — the server returns ToRemove for any records that
     * are in the target but not in the compose result.
     */
    private composeToExistingList;
    onComposeConfirmCancel(): void;
    onComposeConfirmCommit(deltaToken: string): Promise<void>;
    /**
     * Filtered list of existing lists eligible as compose targets. We
     * exclude lists already in the selected operands (committing to a
     * source list would be a self-referential compose) and lists from
     * other entities (the entity invariant still applies).
     */
    get filteredComposeTargets(): MJListEntity[];
    selectComposeTarget(list: MJListEntity): void;
    composeTargetDisplayName(): string;
    getOperationLabel(operation: SetOperation): string;
    createListFromSelection(): void;
    createListFromResult(): void;
    cancelCreateDialog(): void;
    confirmCreateList(): Promise<void>;
    addToExistingList(): void;
    addResultToExistingList(): void;
    /**
     * Open the Add to Existing List dialog
     */
    private openAddToListDialog;
    /**
     * Filter available lists for add-to-list dialog
     */
    filterAddToListOptions(): void;
    /**
     * Select a target list for adding records
     */
    IsTargetListSelected(list: MJListEntity): boolean;
    selectTargetList(listId: string): void;
    /**
     * Cancel the add to list dialog
     */
    cancelAddToListDialog(): void;
    /**
     * Confirm adding records to selected list
     */
    confirmAddToList(): Promise<void>;
    /**
     * Open the export-format-and-columns picker (mockup 26). Resolves the
     * candidate field list from EntityInfo on the loaded metadata — no
     * extra RunView. Default selection mirrors what the previous
     * "export all" behavior produced.
     */
    openExportDialog(): void;
    closeExportDialog(): void;
    selectAllExportFields(): void;
    selectNoneExportFields(): void;
    get selectedExportFieldCount(): number;
    /**
     * Run the export with the user's selected format + columns. Bulk-load
     * via RunView restricted to the chosen Fields so we don't shuttle
     * data we'll then throw away.
     */
    executeExport(): Promise<void>;
    GetResourceDisplayName(_data: ResourceData): Promise<string>;
    GetResourceIconClass(_data: ResourceData): Promise<string>;
    /**
     * Clear all selections and reset state
     */
    clearAllSelections(): void;
    /**
     * Save state to User Settings (debounced to avoid excessive writes)
     */
    private saveState;
    /**
     * Save state to User Settings entity on server
     */
    private saveStateToServer;
    /**
     * Load saved state from User Settings
     */
    private loadSavedState;
    static ɵfac: i0.ɵɵFactoryDeclaration<ListsOperationsResource, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<ListsOperationsResource, "mj-lists-operations-resource", never, {}, {}, never, never, false, never>;
}
export {};
//# sourceMappingURL=lists-operations-resource.component.d.ts.map