var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
 * @fileoverview Agent Requests Resource Component
 *
 * Dashboard resource for the AI application's "Requests" tab.
 * Displays all agent feedback requests with filtering by status, priority,
 * request type, and agent. Opens the generic agent-request-panel for
 * viewing details and responding.
 */
import { Component } from '@angular/core';
import { Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { RunView } from '@memberjunction/core';
import { UserInfoEngine } from '@memberjunction/core-entities';
import { RegisterClass, UUIDsEqual } from '@memberjunction/global';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-shared-generic";
import * as i2 from "@memberjunction/ng-agent-requests";
import * as i3 from "@memberjunction/ng-ui-components";
import * as i4 from "@angular/common";
const _forTrack0 = ($index, $item) => $item.ID;
function AgentRequestsResourceComponent_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "mj-stat-badge", 1);
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Count", ctx_r0.PendingCount);
} }
function AgentRequestsResourceComponent_Conditional_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 6);
    i0.ɵɵelement(1, "mj-loading", 10);
    i0.ɵɵelementEnd();
} }
function AgentRequestsResourceComponent_Conditional_9_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "p", 12);
    i0.ɵɵtext(1, "No agent requests yet");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(2, "p", 13);
    i0.ɵɵtext(3, "When agents need human input, their requests will appear here.");
    i0.ɵɵelementEnd();
} }
function AgentRequestsResourceComponent_Conditional_9_Conditional_3_Template(rf, ctx) { if (rf & 1) {
    const _r2 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "p", 12);
    i0.ɵɵtext(1, "No requests match your filters");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(2, "button", 14);
    i0.ɵɵlistener("click", function AgentRequestsResourceComponent_Conditional_9_Conditional_3_Template_button_click_2_listener() { i0.ɵɵrestoreView(_r2); const ctx_r0 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r0.ClearFilters()); });
    i0.ɵɵtext(3, "Clear Filters");
    i0.ɵɵelementEnd();
} }
function AgentRequestsResourceComponent_Conditional_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 7);
    i0.ɵɵelement(1, "i", 11);
    i0.ɵɵconditionalCreate(2, AgentRequestsResourceComponent_Conditional_9_Conditional_2_Template, 4, 0)(3, AgentRequestsResourceComponent_Conditional_9_Conditional_3_Template, 4, 0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r0.Requests.length === 0 ? 2 : 3);
} }
function AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 21);
    i0.ɵɵtext(1, "Expired");
    i0.ɵɵelementEnd();
} }
function AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_15_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 24);
    i0.ɵɵelement(1, "i", 28);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const request_r4 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", request_r4.Agent, " ");
} }
function AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_16_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 24);
    i0.ɵɵelement(1, "i", 29);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "date");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const request_r4 = i0.ɵɵnextContext().$implicit;
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind2(3, 1, request_r4.__mj_CreatedAt, "short"), " ");
} }
function AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_17_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 24);
    i0.ɵɵelement(1, "i", 30);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "date");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const request_r4 = i0.ɵɵnextContext().$implicit;
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵclassProp("expired", ctx_r0.IsExpired(request_r4));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" Expires ", i0.ɵɵpipeBind2(3, 3, request_r4.ExpiresAt, "short"), " ");
} }
function AgentRequestsResourceComponent_Conditional_10_For_2_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 16);
    i0.ɵɵlistener("click", function AgentRequestsResourceComponent_Conditional_10_For_2_Template_div_click_0_listener() { const request_r4 = i0.ɵɵrestoreView(_r3).$implicit; const ctx_r0 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r0.OnRequestClick(request_r4)); });
    i0.ɵɵelementStart(1, "div", 17);
    i0.ɵɵelement(2, "i");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "div", 18)(4, "div", 19)(5, "span", 20);
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "span");
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "span");
    i0.ɵɵtext(10);
    i0.ɵɵelementEnd();
    i0.ɵɵconditionalCreate(11, AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_11_Template, 2, 0, "span", 21);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(12, "p", 22);
    i0.ɵɵtext(13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(14, "div", 23);
    i0.ɵɵconditionalCreate(15, AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_15_Template, 3, 1, "span", 24);
    i0.ɵɵconditionalCreate(16, AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_16_Template, 4, 4, "span", 24);
    i0.ɵɵconditionalCreate(17, AgentRequestsResourceComponent_Conditional_10_For_2_Conditional_17_Template, 4, 6, "span", 25);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(18, "div", 26);
    i0.ɵɵelement(19, "i", 27);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const request_r4 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵclassProp("actionable", request_r4.Status === "Requested")("expired", ctx_r0.IsExpired(request_r4));
    i0.ɵɵadvance(2);
    i0.ɵɵclassMap(i0.ɵɵinterpolate1("", ctx_r0.GetRequestTypeIcon(request_r4.RequestTypeID), " type-icon"));
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(ctx_r0.GetRequestTypeName(request_r4.RequestTypeID));
    i0.ɵɵadvance();
    i0.ɵɵclassMap(i0.ɵɵinterpolate1("priority-badge ", ctx_r0.GetPriorityClass(request_r4.Priority)));
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", ctx_r0.GetPriorityLabel(request_r4.Priority), " ");
    i0.ɵɵadvance();
    i0.ɵɵclassMap(i0.ɵɵinterpolate1("status-badge status-", request_r4.Status.toLowerCase()));
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", request_r4.Status, " ");
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r0.IsExpired(request_r4) && request_r4.Status === "Requested" ? 11 : -1);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(request_r4.Request);
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(request_r4.Agent ? 15 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(request_r4.__mj_CreatedAt ? 16 : -1);
    i0.ɵɵadvance();
    i0.ɵɵconditional(request_r4.ExpiresAt ? 17 : -1);
} }
function AgentRequestsResourceComponent_Conditional_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 8);
    i0.ɵɵrepeaterCreate(1, AgentRequestsResourceComponent_Conditional_10_For_2_Template, 20, 21, "div", 15, _forTrack0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵrepeater(ctx_r0.FilteredRequests);
} }
function AgentRequestsResourceComponent_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "mj-agent-request-dialog", 31);
    i0.ɵɵlistener("Close", function AgentRequestsResourceComponent_Conditional_11_Template_mj_agent_request_dialog_Close_0_listener($event) { i0.ɵɵrestoreView(_r5); const ctx_r0 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r0.OnPanelClose($event)); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("Visible", ctx_r0.ShowRequestPanel)("Request", ctx_r0.SelectedRequest);
} }
let AgentRequestsResourceComponent = class AgentRequestsResourceComponent extends BaseResourceComponent {
    cdr;
    USER_SETTINGS_KEY = 'AI.AgentRequests.UserPreferences';
    settingsPersistSubject = new Subject();
    destroy$ = new Subject();
    settingsLoaded = false;
    IsLoading = false;
    Requests = [];
    FilteredRequests = [];
    RequestTypes = [];
    // Panel state
    SelectedRequest = null;
    ShowRequestPanel = false;
    // Filter state
    Filters = {
        SearchTerm: '',
        Status: '',
        RequestType: '',
        Priority: ''
    };
    // Available filter options
    StatusOptions = ['Requested', 'Approved', 'Rejected', 'Responded', 'Canceled', 'Expired'];
    PriorityOptions = [
        { Label: 'Critical (76-100)', Value: 'critical' },
        { Label: 'High (51-75)', Value: 'high' },
        { Label: 'Normal (26-50)', Value: 'normal' },
        { Label: 'Low (1-25)', Value: 'low' }
    ];
    searchSubject = new Subject();
    constructor(cdr) {
        super();
        this.cdr = cdr;
    }
    async ngAfterViewInit() {
        this.setupSearchDebounce();
        await this.loadUserSettings();
        await this.loadData();
        this.autoOpenRequestFromQueryParams();
        this.NotifyLoadComplete();
    }
    ngOnDestroy() {
        super.ngOnDestroy();
        this.destroy$.next();
        this.destroy$.complete();
    }
    async GetResourceDisplayName(data) {
        return 'Agent Requests';
    }
    async GetResourceIconClass(data) {
        return 'fa-solid fa-inbox';
    }
    /** Count of pending (Requested) items */
    get PendingCount() {
        return this.Requests.filter(r => r.Status === 'Requested').length;
    }
    /** Open the detail panel for a request */
    OnRequestClick(request) {
        this.SelectedRequest = request;
        this.ShowRequestPanel = true;
        this.cdr.detectChanges();
    }
    /** Handle panel close */
    OnPanelClose(result) {
        this.ShowRequestPanel = false;
        this.SelectedRequest = null;
        if (result.Success) {
            // Refresh the list to reflect the status change
            this.loadData();
        }
        this.cdr.detectChanges();
    }
    /** Handle search input */
    OnSearchChange(term) {
        this.searchSubject.next(term);
    }
    /** Handle filter changes */
    OnFilterChange() {
        this.applyFilters();
        this.saveUserSettings();
    }
    /** Clear all filters */
    ClearFilters() {
        this.Filters = { SearchTerm: '', Status: '', RequestType: '', Priority: '' };
        this.applyFilters();
        this.saveUserSettings();
    }
    /** Reset only the popover filters (Status/Type/Priority) — leave SearchTerm alone. */
    resetPopoverFilters() {
        this.Filters = { ...this.Filters, Status: '', RequestType: '', Priority: '' };
        this.applyFilters();
        this.saveUserSettings();
    }
    /** Number of currently-applied filter criteria inside the popover (excludes SearchTerm — surfaced separately). */
    get ActiveFilterCount() {
        let n = 0;
        if (this.Filters.Status)
            n++;
        if (this.Filters.RequestType)
            n++;
        if (this.Filters.Priority)
            n++;
        return n;
    }
    /** Values record consumed by the centralized <mj-filter-panel>. */
    get requestFilterValues() {
        return {
            Status: this.Filters.Status,
            RequestType: this.Filters.RequestType,
            Priority: this.Filters.Priority,
        };
    }
    /** Field config consumed by the centralized <mj-filter-panel>. */
    get requestFilterFields() {
        return [
            {
                key: 'Status',
                type: 'dropdown',
                label: 'Status',
                icon: 'fa-solid fa-toggle-on',
                options: [
                    { text: 'All Statuses', value: '' },
                    ...this.StatusOptions.map(s => ({ text: s, value: s })),
                ],
            },
            {
                key: 'RequestType',
                type: 'dropdown',
                label: 'Type',
                icon: 'fa-solid fa-tag',
                filterable: this.RequestTypes.length > 10,
                options: [
                    { text: 'All Types', value: '' },
                    ...this.RequestTypes.map(t => ({ text: t.Name, value: t.ID })),
                ],
            },
            {
                key: 'Priority',
                type: 'dropdown',
                label: 'Priority',
                icon: 'fa-solid fa-flag',
                options: [
                    { text: 'All Priorities', value: '' },
                    ...this.PriorityOptions.map(p => ({ text: p.Label, value: p.Value })),
                ],
            },
        ];
    }
    /** Receive the updated values record from <mj-filter-panel> and apply it. */
    onFilterValuesChange(values) {
        this.Filters = {
            ...this.Filters,
            Status: values['Status'] ?? '',
            RequestType: values['RequestType'] ?? '',
            Priority: values['Priority'] ?? '',
        };
        this.applyFilters();
        this.saveUserSettings();
    }
    /** Get the request type name by ID */
    GetRequestTypeName(typeId) {
        if (!typeId)
            return '';
        const type = this.RequestTypes.find(t => UUIDsEqual(t.ID, typeId));
        return type?.Name ?? '';
    }
    /** Get the request type icon by ID */
    GetRequestTypeIcon(typeId) {
        if (!typeId)
            return 'fa-solid fa-question-circle';
        const type = this.RequestTypes.find(t => UUIDsEqual(t.ID, typeId));
        return type?.Icon ?? 'fa-solid fa-question-circle';
    }
    /** Get priority label from numeric value */
    GetPriorityLabel(priority) {
        if (priority <= 25)
            return 'Low';
        if (priority <= 50)
            return 'Normal';
        if (priority <= 75)
            return 'High';
        return 'Critical';
    }
    /** Get priority CSS class from numeric value */
    GetPriorityClass(priority) {
        if (priority <= 25)
            return 'priority-low';
        if (priority <= 50)
            return 'priority-normal';
        if (priority <= 75)
            return 'priority-high';
        return 'priority-critical';
    }
    /** Whether a request is expired */
    IsExpired(request) {
        if (!request.ExpiresAt)
            return false;
        return new Date(request.ExpiresAt) < new Date();
    }
    // ---- Private Methods ----
    /**
     * If a requestId was passed via configuration (e.g. from a notification click),
     * auto-open that request in the detail panel.
     */
    autoOpenRequestFromQueryParams() {
        const requestId = this.Data?.Configuration?.requestId
            || this.Data?.Configuration?.queryParams?.requestId;
        if (!requestId)
            return;
        const match = this.Requests.find(r => UUIDsEqual(r.ID, requestId));
        if (match) {
            this.OnRequestClick(match);
        }
    }
    async loadData() {
        this.IsLoading = true;
        this.cdr.detectChanges();
        try {
            const rv = RunView.FromMetadataProvider(this.ProviderToUse);
            const [requestsResult, typesResult] = await rv.RunViews([
                {
                    EntityName: 'MJ: AI Agent Requests',
                    OrderBy: 'Priority DESC, __mj_CreatedAt DESC',
                    ResultType: 'entity_object'
                },
                {
                    EntityName: 'MJ: AI Agent Request Types',
                    OrderBy: 'Name',
                    ResultType: 'entity_object'
                }
            ]);
            if (requestsResult.Success) {
                this.Requests = requestsResult.Results;
            }
            if (typesResult.Success) {
                this.RequestTypes = typesResult.Results;
            }
            this.applyFilters();
        }
        catch (error) {
            console.error('Error loading agent requests:', error);
        }
        finally {
            this.IsLoading = false;
            this.cdr.detectChanges();
        }
    }
    applyFilters() {
        let filtered = [...this.Requests];
        // Status filter
        if (this.Filters.Status) {
            filtered = filtered.filter(r => r.Status === this.Filters.Status);
        }
        // Request type filter
        if (this.Filters.RequestType) {
            filtered = filtered.filter(r => r.RequestTypeID && UUIDsEqual(r.RequestTypeID, this.Filters.RequestType));
        }
        // Priority filter
        if (this.Filters.Priority) {
            filtered = filtered.filter(r => {
                const p = r.Priority;
                switch (this.Filters.Priority) {
                    case 'low': return p <= 25;
                    case 'normal': return p > 25 && p <= 50;
                    case 'high': return p > 50 && p <= 75;
                    case 'critical': return p > 75;
                    default: return true;
                }
            });
        }
        // Search term filter
        if (this.Filters.SearchTerm) {
            const term = this.Filters.SearchTerm.toLowerCase();
            filtered = filtered.filter(r => (r.Request && r.Request.toLowerCase().includes(term)) ||
                (r.Agent && r.Agent.toLowerCase().includes(term)) ||
                (r.Response && r.Response.toLowerCase().includes(term)));
        }
        this.FilteredRequests = filtered;
        this.cdr.detectChanges();
    }
    setupSearchDebounce() {
        this.searchSubject.pipe(debounceTime(300), takeUntil(this.destroy$)).subscribe(term => {
            this.Filters.SearchTerm = term;
            this.applyFilters();
            this.saveUserSettings();
        });
        this.settingsPersistSubject.pipe(debounceTime(500), takeUntil(this.destroy$)).subscribe(() => this.persistUserSettings());
    }
    async loadUserSettings() {
        try {
            const prefs = UserInfoEngine.Instance.GetSetting(this.USER_SETTINGS_KEY);
            if (prefs) {
                const parsed = JSON.parse(prefs);
                if (parsed.Filters) {
                    this.Filters = { ...this.Filters, ...parsed.Filters };
                }
            }
        }
        catch {
            // Use defaults
        }
        this.settingsLoaded = true;
    }
    saveUserSettings() {
        if (this.settingsLoaded) {
            this.settingsPersistSubject.next();
        }
    }
    async persistUserSettings() {
        try {
            const prefs = {
                Filters: this.Filters,
                SortColumn: 'Priority',
                SortDirection: 'desc'
            };
            await UserInfoEngine.Instance.SetSetting(this.USER_SETTINGS_KEY, JSON.stringify(prefs));
        }
        catch {
            // Silent failure for settings persistence
        }
    }
    static ɵfac = function AgentRequestsResourceComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || AgentRequestsResourceComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AgentRequestsResourceComponent, selectors: [["app-agent-requests-resource"]], standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 12, vars: 8, consts: [["Title", "Agent Requests", "Icon", "fa-solid fa-inbox"], ["meta", "", "Icon", "fa-solid fa-hourglass-half", "Label", "pending", "Variant", "warning", 3, "Count"], ["toolbar", ""], ["Placeholder", "Search requests...", 3, "ValueChange", "Value"], [3, "ClearAllRequested", "ActiveCount", "ShowClearAll"], [3, "ValuesChange", "Reset", "Fields", "Values"], [1, "loading-container"], [1, "empty-state"], [1, "requests-list"], [3, "Visible", "Request"], ["text", "Loading agent requests..."], [1, "fa-solid", "fa-inbox", "empty-icon"], [1, "empty-text"], [1, "empty-subtext"], [1, "clear-filters-btn", 3, "click"], [1, "request-card", 3, "actionable", "expired"], [1, "request-card", 3, "click"], [1, "card-left"], [1, "card-content"], [1, "card-top-row"], [1, "request-type-name"], [1, "expired-tag"], [1, "request-text"], [1, "card-meta"], [1, "meta-item"], [1, "meta-item", 3, "expired"], [1, "card-right"], [1, "fa-solid", "fa-chevron-right"], [1, "fa-solid", "fa-robot"], [1, "fa-regular", "fa-clock"], [1, "fa-solid", "fa-hourglass-end"], [3, "Close", "Visible", "Request"]], template: function AgentRequestsResourceComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "mj-page-layout")(1, "mj-page-header", 0);
            i0.ɵɵconditionalCreate(2, AgentRequestsResourceComponent_Conditional_2_Template, 1, 1, "mj-stat-badge", 1);
            i0.ɵɵelementStart(3, "div", 2)(4, "mj-page-search", 3);
            i0.ɵɵlistener("ValueChange", function AgentRequestsResourceComponent_Template_mj_page_search_ValueChange_4_listener($event) { return ctx.OnSearchChange($event); });
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "mj-filter-popover", 4);
            i0.ɵɵlistener("ClearAllRequested", function AgentRequestsResourceComponent_Template_mj_filter_popover_ClearAllRequested_5_listener() { return ctx.resetPopoverFilters(); });
            i0.ɵɵelementStart(6, "mj-filter-panel", 5);
            i0.ɵɵlistener("ValuesChange", function AgentRequestsResourceComponent_Template_mj_filter_panel_ValuesChange_6_listener($event) { return ctx.onFilterValuesChange($event); })("Reset", function AgentRequestsResourceComponent_Template_mj_filter_panel_Reset_6_listener() { return ctx.resetPopoverFilters(); });
            i0.ɵɵelementEnd()()()();
            i0.ɵɵelementStart(7, "mj-page-body");
            i0.ɵɵconditionalCreate(8, AgentRequestsResourceComponent_Conditional_8_Template, 2, 0, "div", 6)(9, AgentRequestsResourceComponent_Conditional_9_Template, 4, 1, "div", 7)(10, AgentRequestsResourceComponent_Conditional_10_Template, 3, 0, "div", 8);
            i0.ɵɵelementEnd()();
            i0.ɵɵconditionalCreate(11, AgentRequestsResourceComponent_Conditional_11_Template, 1, 2, "mj-agent-request-dialog", 9);
        } if (rf & 2) {
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.PendingCount > 0 ? 2 : -1);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("Value", ctx.Filters.SearchTerm);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ActiveCount", ctx.ActiveFilterCount)("ShowClearAll", ctx.ActiveFilterCount > 0);
            i0.ɵɵadvance();
            i0.ɵɵproperty("Fields", ctx.requestFilterFields)("Values", ctx.requestFilterValues);
            i0.ɵɵadvance(2);
            i0.ɵɵconditional(ctx.IsLoading ? 8 : ctx.FilteredRequests.length === 0 ? 9 : 10);
            i0.ɵɵadvance(3);
            i0.ɵɵconditional(ctx.ShowRequestPanel && ctx.SelectedRequest ? 11 : -1);
        } }, dependencies: [i1.LoadingComponent, i2.AgentRequestDialogComponent, i3.MJPageHeaderComponent, i3.MJPageLayoutComponent, i3.MJPageBodyComponent, i3.MJFilterPopoverComponent, i3.MJPageSearchComponent, i3.MJFilterPanelComponent, i3.MJStatBadgeComponent, i4.DatePipe], styles: ["\n\n\n\n\n\n.clear-filters-btn[_ngcontent-%COMP%] {\n    padding: 6px 12px;\n    border: none;\n    border-radius: 6px;\n    font-size: 12px;\n    background: var(--mj-bg-surface-hover);\n    color: var(--mj-text-secondary);\n    cursor: pointer;\n    display: flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.clear-filters-btn[_ngcontent-%COMP%]:hover {\n    background: var(--mj-bg-surface-active);\n    color: var(--mj-text-primary);\n}\n\n\n\n.loading-container[_ngcontent-%COMP%] {\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    padding: 60px 20px;\n}\n\n\n\n.empty-state[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    justify-content: center;\n    padding: 80px 20px;\n    text-align: center;\n}\n\n.empty-icon[_ngcontent-%COMP%] {\n    font-size: 48px;\n    color: var(--mj-text-disabled);\n    margin-bottom: 16px;\n}\n\n.empty-text[_ngcontent-%COMP%] {\n    margin: 0 0 8px 0;\n    font-size: 16px;\n    color: var(--mj-text-secondary);\n}\n\n.empty-subtext[_ngcontent-%COMP%] {\n    margin: 0;\n    font-size: 13px;\n    color: var(--mj-text-muted);\n}\n\n\n\n.requests-list[_ngcontent-%COMP%] {\n    display: flex;\n    flex-direction: column;\n    gap: 8px;\n    flex: 1;\n    padding: 0 20px 20px;\n    overflow-y: auto;\n}\n\n.request-card[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: flex-start;\n    gap: 14px;\n    padding: 14px 16px;\n    background: var(--mj-bg-surface);\n    border: 1px solid var(--mj-border-default);\n    border-radius: 8px;\n    cursor: pointer;\n    transition: border-color 0.15s, box-shadow 0.15s;\n}\n\n.request-card[_ngcontent-%COMP%]:hover {\n    border-color: var(--mj-brand-primary);\n    box-shadow: 0 2px 8px color-mix(in srgb, var(--mj-brand-primary) 10%, transparent);\n}\n\n.request-card.actionable[_ngcontent-%COMP%] {\n    border-left: 3px solid var(--mj-status-warning);\n}\n\n.request-card.expired[_ngcontent-%COMP%] {\n    opacity: 0.7;\n}\n\n.card-left[_ngcontent-%COMP%] {\n    flex-shrink: 0;\n    padding-top: 2px;\n}\n\n.type-icon[_ngcontent-%COMP%] {\n    font-size: 18px;\n    color: var(--mj-brand-primary);\n}\n\n.card-content[_ngcontent-%COMP%] {\n    flex: 1;\n    min-width: 0;\n}\n\n.card-top-row[_ngcontent-%COMP%] {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    flex-wrap: wrap;\n    margin-bottom: 6px;\n}\n\n.request-type-name[_ngcontent-%COMP%] {\n    font-size: 13px;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.request-text[_ngcontent-%COMP%] {\n    margin: 0 0 8px 0;\n    font-size: 13px;\n    color: var(--mj-text-secondary);\n    line-height: 1.5;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    display: -webkit-box;\n    -webkit-line-clamp: 2;\n    -webkit-box-orient: vertical;\n}\n\n.card-meta[_ngcontent-%COMP%] {\n    display: flex;\n    gap: 14px;\n    flex-wrap: wrap;\n}\n\n.meta-item[_ngcontent-%COMP%] {\n    font-size: 11px;\n    color: var(--mj-text-muted);\n    display: flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.meta-item.expired[_ngcontent-%COMP%] {\n    color: var(--mj-status-error-text);\n}\n\n.card-right[_ngcontent-%COMP%] {\n    flex-shrink: 0;\n    color: var(--mj-text-disabled);\n    font-size: 12px;\n    padding-top: 4px;\n}\n\n\n\n.status-badge[_ngcontent-%COMP%] {\n    display: inline-block;\n    padding: 2px 8px;\n    border-radius: 12px;\n    font-size: 10px;\n    font-weight: 600;\n    text-transform: uppercase;\n    letter-spacing: 0.5px;\n}\n\n.status-requested[_ngcontent-%COMP%] {\n    background: var(--mj-status-info-bg);\n    color: var(--mj-status-info-text);\n    border: 1px solid var(--mj-status-info-border);\n}\n\n.status-approved[_ngcontent-%COMP%], \n.status-responded[_ngcontent-%COMP%] {\n    background: var(--mj-status-success-bg);\n    color: var(--mj-status-success-text);\n    border: 1px solid var(--mj-status-success-border);\n}\n\n.status-rejected[_ngcontent-%COMP%], \n.status-canceled[_ngcontent-%COMP%] {\n    background: var(--mj-status-error-bg);\n    color: var(--mj-status-error-text);\n    border: 1px solid var(--mj-status-error-border);\n}\n\n.status-expired[_ngcontent-%COMP%] {\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n    border: 1px solid var(--mj-status-warning-border);\n}\n\n.priority-badge[_ngcontent-%COMP%] {\n    display: inline-block;\n    padding: 2px 8px;\n    border-radius: 12px;\n    font-size: 10px;\n    font-weight: 600;\n}\n\n.priority-low[_ngcontent-%COMP%] {\n    background: var(--mj-bg-surface-sunken);\n    color: var(--mj-text-muted);\n}\n\n.priority-normal[_ngcontent-%COMP%] {\n    background: var(--mj-status-info-bg);\n    color: var(--mj-status-info-text);\n}\n\n.priority-high[_ngcontent-%COMP%] {\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n}\n\n.priority-critical[_ngcontent-%COMP%] {\n    background: var(--mj-status-error-bg);\n    color: var(--mj-status-error-text);\n}\n\n.expired-tag[_ngcontent-%COMP%] {\n    display: inline-block;\n    padding: 2px 6px;\n    border-radius: 8px;\n    font-size: 10px;\n    font-weight: 600;\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n}"] });
};
AgentRequestsResourceComponent = __decorate([
    RegisterClass(BaseResourceComponent, 'AIAgentRequestsResource')
], AgentRequestsResourceComponent);
export { AgentRequestsResourceComponent };
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AgentRequestsResourceComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'app-agent-requests-resource', template: "<mj-page-layout>\n    <!-- Header -->\n    <mj-page-header\n        Title=\"Agent Requests\"\n        Icon=\"fa-solid fa-inbox\">\n        @if (PendingCount > 0) {\n            <mj-stat-badge meta\n                Icon=\"fa-solid fa-hourglass-half\"\n                [Count]=\"PendingCount\"\n                Label=\"pending\"\n                Variant=\"warning\">\n            </mj-stat-badge>\n        }\n        <div toolbar>\n            <mj-page-search\n                Placeholder=\"Search requests...\"\n                [Value]=\"Filters.SearchTerm\"\n                (ValueChange)=\"OnSearchChange($event)\">\n            </mj-page-search>\n            <mj-filter-popover\n                [ActiveCount]=\"ActiveFilterCount\"\n                [ShowClearAll]=\"ActiveFilterCount > 0\"\n                (ClearAllRequested)=\"resetPopoverFilters()\">\n                <mj-filter-panel\n                    [Fields]=\"requestFilterFields\"\n                    [Values]=\"requestFilterValues\"\n                    (ValuesChange)=\"onFilterValuesChange($event)\"\n                    (Reset)=\"resetPopoverFilters()\">\n                </mj-filter-panel>\n            </mj-filter-popover>\n        </div>\n    </mj-page-header>\n\n    <mj-page-body>\n    <!-- Content -->\n    @if (IsLoading) {\n        <div class=\"loading-container\">\n            <mj-loading text=\"Loading agent requests...\"></mj-loading>\n        </div>\n    } @else if (FilteredRequests.length === 0) {\n        <div class=\"empty-state\">\n            <i class=\"fa-solid fa-inbox empty-icon\"></i>\n            @if (Requests.length === 0) {\n                <p class=\"empty-text\">No agent requests yet</p>\n                <p class=\"empty-subtext\">When agents need human input, their requests will appear here.</p>\n            } @else {\n                <p class=\"empty-text\">No requests match your filters</p>\n                <button class=\"clear-filters-btn\" (click)=\"ClearFilters()\">Clear Filters</button>\n            }\n        </div>\n    } @else {\n        <div class=\"requests-list\">\n            @for (request of FilteredRequests; track request.ID) {\n                <div\n                    class=\"request-card\"\n                    [class.actionable]=\"request.Status === 'Requested'\"\n                    [class.expired]=\"IsExpired(request)\"\n                    (click)=\"OnRequestClick(request)\">\n                    <div class=\"card-left\">\n                        <i class=\"{{ GetRequestTypeIcon(request.RequestTypeID) }} type-icon\"></i>\n                    </div>\n                    <div class=\"card-content\">\n                        <div class=\"card-top-row\">\n                            <span class=\"request-type-name\">{{ GetRequestTypeName(request.RequestTypeID) }}</span>\n                            <span class=\"priority-badge {{ GetPriorityClass(request.Priority) }}\">\n                                {{ GetPriorityLabel(request.Priority) }}\n                            </span>\n                            <span class=\"status-badge status-{{ request.Status.toLowerCase() }}\">\n                                {{ request.Status }}\n                            </span>\n                            @if (IsExpired(request) && request.Status === 'Requested') {\n                                <span class=\"expired-tag\">Expired</span>\n                            }\n                        </div>\n                        <p class=\"request-text\">{{ request.Request }}</p>\n                        <div class=\"card-meta\">\n                            @if (request.Agent) {\n                                <span class=\"meta-item\">\n                                    <i class=\"fa-solid fa-robot\"></i> {{ request.Agent }}\n                                </span>\n                            }\n                            @if (request.__mj_CreatedAt) {\n                                <span class=\"meta-item\">\n                                    <i class=\"fa-regular fa-clock\"></i> {{ request.__mj_CreatedAt | date:'short' }}\n                                </span>\n                            }\n                            @if (request.ExpiresAt) {\n                                <span class=\"meta-item\" [class.expired]=\"IsExpired(request)\">\n                                    <i class=\"fa-solid fa-hourglass-end\"></i> Expires {{ request.ExpiresAt | date:'short' }}\n                                </span>\n                            }\n                        </div>\n                    </div>\n                    <div class=\"card-right\">\n                        <i class=\"fa-solid fa-chevron-right\"></i>\n                    </div>\n                </div>\n            }\n        </div>\n    }\n    </mj-page-body>\n</mj-page-layout>\n\n<!-- Agent Request Detail Panel -->\n@if (ShowRequestPanel && SelectedRequest) {\n    <mj-agent-request-dialog\n        [Visible]=\"ShowRequestPanel\"\n        [Request]=\"SelectedRequest\"\n        (Close)=\"OnPanelClose($event)\">\n    </mj-agent-request-dialog>\n}\n", styles: ["/* Container is now provided by <mj-page-layout>; body padding moved to .filter-bar / list sections below */\n\n/* Search & filters now live in <mj-page-header>'s toolbar/actions via shared components. */\n\n.clear-filters-btn {\n    padding: 6px 12px;\n    border: none;\n    border-radius: 6px;\n    font-size: 12px;\n    background: var(--mj-bg-surface-hover);\n    color: var(--mj-text-secondary);\n    cursor: pointer;\n    display: flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.clear-filters-btn:hover {\n    background: var(--mj-bg-surface-active);\n    color: var(--mj-text-primary);\n}\n\n/* Loading */\n.loading-container {\n    display: flex;\n    justify-content: center;\n    align-items: center;\n    padding: 60px 20px;\n}\n\n/* Empty State */\n.empty-state {\n    display: flex;\n    flex-direction: column;\n    align-items: center;\n    justify-content: center;\n    padding: 80px 20px;\n    text-align: center;\n}\n\n.empty-icon {\n    font-size: 48px;\n    color: var(--mj-text-disabled);\n    margin-bottom: 16px;\n}\n\n.empty-text {\n    margin: 0 0 8px 0;\n    font-size: 16px;\n    color: var(--mj-text-secondary);\n}\n\n.empty-subtext {\n    margin: 0;\n    font-size: 13px;\n    color: var(--mj-text-muted);\n}\n\n/* Request Cards */\n.requests-list {\n    display: flex;\n    flex-direction: column;\n    gap: 8px;\n    flex: 1;\n    padding: 0 20px 20px;\n    overflow-y: auto;\n}\n\n.request-card {\n    display: flex;\n    align-items: flex-start;\n    gap: 14px;\n    padding: 14px 16px;\n    background: var(--mj-bg-surface);\n    border: 1px solid var(--mj-border-default);\n    border-radius: 8px;\n    cursor: pointer;\n    transition: border-color 0.15s, box-shadow 0.15s;\n}\n\n.request-card:hover {\n    border-color: var(--mj-brand-primary);\n    box-shadow: 0 2px 8px color-mix(in srgb, var(--mj-brand-primary) 10%, transparent);\n}\n\n.request-card.actionable {\n    border-left: 3px solid var(--mj-status-warning);\n}\n\n.request-card.expired {\n    opacity: 0.7;\n}\n\n.card-left {\n    flex-shrink: 0;\n    padding-top: 2px;\n}\n\n.type-icon {\n    font-size: 18px;\n    color: var(--mj-brand-primary);\n}\n\n.card-content {\n    flex: 1;\n    min-width: 0;\n}\n\n.card-top-row {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    flex-wrap: wrap;\n    margin-bottom: 6px;\n}\n\n.request-type-name {\n    font-size: 13px;\n    font-weight: 600;\n    color: var(--mj-text-primary);\n}\n\n.request-text {\n    margin: 0 0 8px 0;\n    font-size: 13px;\n    color: var(--mj-text-secondary);\n    line-height: 1.5;\n    overflow: hidden;\n    text-overflow: ellipsis;\n    display: -webkit-box;\n    -webkit-line-clamp: 2;\n    -webkit-box-orient: vertical;\n}\n\n.card-meta {\n    display: flex;\n    gap: 14px;\n    flex-wrap: wrap;\n}\n\n.meta-item {\n    font-size: 11px;\n    color: var(--mj-text-muted);\n    display: flex;\n    align-items: center;\n    gap: 4px;\n}\n\n.meta-item.expired {\n    color: var(--mj-status-error-text);\n}\n\n.card-right {\n    flex-shrink: 0;\n    color: var(--mj-text-disabled);\n    font-size: 12px;\n    padding-top: 4px;\n}\n\n/* Badges */\n.status-badge {\n    display: inline-block;\n    padding: 2px 8px;\n    border-radius: 12px;\n    font-size: 10px;\n    font-weight: 600;\n    text-transform: uppercase;\n    letter-spacing: 0.5px;\n}\n\n.status-requested {\n    background: var(--mj-status-info-bg);\n    color: var(--mj-status-info-text);\n    border: 1px solid var(--mj-status-info-border);\n}\n\n.status-approved,\n.status-responded {\n    background: var(--mj-status-success-bg);\n    color: var(--mj-status-success-text);\n    border: 1px solid var(--mj-status-success-border);\n}\n\n.status-rejected,\n.status-canceled {\n    background: var(--mj-status-error-bg);\n    color: var(--mj-status-error-text);\n    border: 1px solid var(--mj-status-error-border);\n}\n\n.status-expired {\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n    border: 1px solid var(--mj-status-warning-border);\n}\n\n.priority-badge {\n    display: inline-block;\n    padding: 2px 8px;\n    border-radius: 12px;\n    font-size: 10px;\n    font-weight: 600;\n}\n\n.priority-low {\n    background: var(--mj-bg-surface-sunken);\n    color: var(--mj-text-muted);\n}\n\n.priority-normal {\n    background: var(--mj-status-info-bg);\n    color: var(--mj-status-info-text);\n}\n\n.priority-high {\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n}\n\n.priority-critical {\n    background: var(--mj-status-error-bg);\n    color: var(--mj-status-error-text);\n}\n\n.expired-tag {\n    display: inline-block;\n    padding: 2px 6px;\n    border-radius: 8px;\n    font-size: 10px;\n    font-weight: 600;\n    background: var(--mj-status-warning-bg);\n    color: var(--mj-status-warning-text);\n}\n"] }]
    }], () => [{ type: i0.ChangeDetectorRef }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(AgentRequestsResourceComponent, { className: "AgentRequestsResourceComponent", filePath: "src/AI/components/requests/agent-requests-resource.component.ts", lineNumber: 44 }); })();
export function LoadAgentRequestsResource() {
    // Prevents tree-shaking
}
//# sourceMappingURL=agent-requests-resource.component.js.map