import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { RunView } from '@memberjunction/core';
import { BaseAngularComponent } from '@memberjunction/ng-base-types';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-ui-components";
import * as i2 from "@memberjunction/ng-shared-generic";
const _forTrack0 = ($index, $item) => $item.Name;
function ActionCardComponent_Conditional_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 8);
    i0.ɵɵelement(1, "i", 21);
    i0.ɵɵtext(2, " AI ");
    i0.ɵɵelementEnd();
} }
function ActionCardComponent_Conditional_19_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 13);
    i0.ɵɵelement(1, "i", 22);
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r0.formatDate(ctx_r0.Action.__mj_UpdatedAt));
} }
function ActionCardComponent_Conditional_20_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 13);
    i0.ɵɵelement(1, "i");
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵattribute("data-status", ctx_r0.Action.CodeApprovalStatus);
    i0.ɵɵadvance();
    i0.ɵɵclassMap(ctx_r0.getApprovalStatusIcon());
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r0.Action.CodeApprovalStatus);
} }
function ActionCardComponent_Conditional_28_Conditional_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 23);
    i0.ɵɵelement(1, "mj-loading", 24);
    i0.ɵɵelementStart(2, "span");
    i0.ɵɵtext(3, "Loading execution stats...");
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    i0.ɵɵadvance();
    i0.ɵɵproperty("showText", false);
} }
function ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_For_6_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 37);
    i0.ɵɵtext(1, "*");
    i0.ɵɵelementEnd();
} }
function ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_For_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 36);
    i0.ɵɵtext(1);
    i0.ɵɵconditionalCreate(2, ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_For_6_Conditional_2_Template, 2, 0, "span", 37);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const param_r2 = ctx.$implicit;
    i0.ɵɵclassProp("required", param_r2.IsRequired);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", param_r2.Name, " ");
    i0.ɵɵadvance();
    i0.ɵɵconditional(param_r2.IsRequired ? 2 : -1);
} }
function ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_Conditional_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 35);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(4);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1("+", ctx_r0.Action.Params.length - 4, " more");
} }
function ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 30)(1, "div", 31);
    i0.ɵɵelement(2, "i", 32);
    i0.ɵɵtext(3, " Parameters ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "div", 33);
    i0.ɵɵrepeaterCreate(5, ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_For_6_Template, 3, 4, "span", 34, _forTrack0);
    i0.ɵɵconditionalCreate(7, ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_Conditional_7_Template, 2, 1, "span", 35);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(5);
    i0.ɵɵrepeater(ctx_r0.Action.Params.slice(0, 4));
    i0.ɵɵadvance(2);
    i0.ɵɵconditional(ctx_r0.Action.Params.length > 4 ? 7 : -1);
} }
function ActionCardComponent_Conditional_28_Conditional_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 25)(1, "div", 26)(2, "div", 27);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "div", 28);
    i0.ɵɵtext(5, "Total Runs");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(6, "div", 26)(7, "div", 27);
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "div", 28);
    i0.ɵɵtext(10, "Success Rate");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(11, "div", 26)(12, "div", 27);
    i0.ɵɵtext(13);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(14, "div", 28);
    i0.ɵɵtext(15, "Last Run");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(16, "div", 29)(17, "div", 27);
    i0.ɵɵtext(18);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(19, "div", 28);
    i0.ɵɵtext(20, "Parameters");
    i0.ɵɵelementEnd()()();
    i0.ɵɵconditionalCreate(21, ActionCardComponent_Conditional_28_Conditional_2_Conditional_21_Template, 8, 1, "div", 30);
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r0.ExecutionStats.totalExecutions);
    i0.ɵɵadvance(4);
    i0.ɵɵclassProp("success", ctx_r0.ExecutionStats.successRate >= 90)("warning", ctx_r0.ExecutionStats.successRate >= 50 && ctx_r0.ExecutionStats.successRate < 90)("error", ctx_r0.ExecutionStats.successRate < 50);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate1(" ", ctx_r0.ExecutionStats.successRate, "% ");
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(ctx_r0.formatDate(ctx_r0.ExecutionStats.lastExecuted));
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(ctx_r0.Action.Params.length || 0);
    i0.ɵɵadvance(3);
    i0.ɵɵconditional(ctx_r0.Action.Params && ctx_r0.Action.Params.length > 0 ? 21 : -1);
} }
function ActionCardComponent_Conditional_28_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 20);
    i0.ɵɵconditionalCreate(1, ActionCardComponent_Conditional_28_Conditional_1_Template, 4, 1, "div", 23)(2, ActionCardComponent_Conditional_28_Conditional_2_Template, 22, 11);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵconditional(ctx_r0.ExecutionStats.isLoading ? 1 : 2);
} }
export class ActionCardComponent extends BaseAngularComponent {
    cdr;
    Action;
    Categories = new Map();
    ActionClick = new EventEmitter();
    EditClick = new EventEmitter();
    RunClick = new EventEmitter();
    CategoryClick = new EventEmitter();
    IsExpanded = false;
    ExecutionStats = {
        totalExecutions: 0,
        successRate: 0,
        lastExecuted: null,
        isLoading: false,
        isLoaded: false
    };
    constructor(cdr) {
        super();
        this.cdr = cdr;
    }
    onCardClick() {
        this.ActionClick.emit(this.Action);
    }
    onEditClick(event) {
        event.stopPropagation();
        this.EditClick.emit(this.Action);
    }
    onRunClick(event) {
        event.stopPropagation();
        this.RunClick.emit(this.Action);
    }
    onCategoryClick(event) {
        event.stopPropagation();
        if (this.Action.CategoryID) {
            this.CategoryClick.emit(this.Action.CategoryID);
        }
    }
    toggleExpanded(event) {
        event.stopPropagation();
        this.IsExpanded = !this.IsExpanded;
        if (this.IsExpanded && !this.ExecutionStats.isLoaded && !this.ExecutionStats.isLoading) {
            this.loadExecutionStats();
        }
    }
    async loadExecutionStats() {
        this.ExecutionStats.isLoading = true;
        this.cdr.markForCheck();
        try {
            const rv = RunView.FromMetadataProvider(this.ProviderToUse);
            // Load both executions and result codes in parallel
            const [executionsResult, resultCodesResult] = await rv.RunViews([
                {
                    EntityName: 'MJ: Action Execution Logs',
                    ExtraFilter: `ActionID='${this.Action.ID}'`,
                    OrderBy: 'StartedAt DESC',
                    MaxRows: 100,
                    ResultType: 'simple',
                    Fields: ['ID', 'ResultCode', 'StartedAt']
                },
                {
                    EntityName: 'MJ: Action Result Codes',
                    ExtraFilter: `ActionID='${this.Action.ID}'`,
                    ResultType: 'simple',
                    Fields: ['ResultCode', 'IsSuccess']
                }
            ]);
            if (executionsResult.Success && executionsResult.Results) {
                const executions = executionsResult.Results;
                // Build a map of result codes to IsSuccess
                const successMap = new Map();
                if (resultCodesResult.Success && resultCodesResult.Results) {
                    const resultCodes = resultCodesResult.Results;
                    resultCodes.forEach(rc => {
                        successMap.set(rc.ResultCode, rc.IsSuccess);
                    });
                }
                // Count successful executions using result code lookup
                const successful = executions.filter(e => {
                    if (!e.ResultCode)
                        return false;
                    // Look up the result code in the map
                    const isSuccess = successMap.get(e.ResultCode);
                    // If result code is defined in the map, use it; otherwise fall back to heuristic
                    if (isSuccess !== undefined) {
                        return isSuccess;
                    }
                    // Fallback heuristic for unknown result codes
                    const code = e.ResultCode.toLowerCase();
                    return code === 'success' || code === 'ok' || code === 'completed';
                }).length;
                this.ExecutionStats = {
                    totalExecutions: executions.length,
                    successRate: executions.length > 0 ? Math.round((successful / executions.length) * 100) : 0,
                    lastExecuted: executions.length > 0 ? new Date(executions[0].StartedAt) : null,
                    isLoading: false,
                    isLoaded: true
                };
            }
            else {
                this.ExecutionStats.isLoading = false;
                this.ExecutionStats.isLoaded = true;
            }
        }
        catch (error) {
            console.error('Failed to load execution stats:', error);
            this.ExecutionStats.isLoading = false;
            this.ExecutionStats.isLoaded = true;
        }
        this.cdr.markForCheck();
    }
    getCategoryName() {
        if (!this.Action.CategoryID)
            return 'Uncategorized';
        return this.Categories.get(this.Action.CategoryID)?.Name || 'Unknown Category';
    }
    getStatusColor() {
        switch (this.Action.Status) {
            case 'Active': return 'success';
            case 'Pending': return 'warning';
            case 'Disabled': return 'error';
            default: return 'info';
        }
    }
    getActionIcon() {
        // Use custom icon if set, otherwise derive from type
        if (this.Action.IconClass) {
            return this.Action.IconClass;
        }
        switch (this.Action.Type) {
            case 'Generated': return 'fa-solid fa-robot';
            case 'Custom': return 'fa-solid fa-code';
            default: return 'fa-solid fa-bolt';
        }
    }
    getTypeLabel() {
        return this.Action.Type === 'Generated' ? 'AI Generated' : 'Custom';
    }
    getApprovalStatusIcon() {
        switch (this.Action.CodeApprovalStatus) {
            case 'Approved': return 'fa-solid fa-check-circle';
            case 'Pending': return 'fa-solid fa-clock';
            case 'Rejected': return 'fa-solid fa-times-circle';
            default: return 'fa-solid fa-question-circle';
        }
    }
    getApprovalStatusColor() {
        switch (this.Action.CodeApprovalStatus) {
            case 'Approved': return 'success';
            case 'Pending': return 'warning';
            case 'Rejected': return 'error';
            default: return 'info';
        }
    }
    formatDate(date) {
        if (!date)
            return 'Never';
        const now = new Date();
        const diff = now.getTime() - date.getTime();
        const minutes = Math.floor(diff / 60000);
        const hours = Math.floor(diff / 3600000);
        const days = Math.floor(diff / 86400000);
        if (minutes < 1)
            return 'Just now';
        if (minutes < 60)
            return `${minutes}m ago`;
        if (hours < 24)
            return `${hours}h ago`;
        if (days < 7)
            return `${days}d ago`;
        return date.toLocaleDateString();
    }
    static ɵfac = function ActionCardComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ActionCardComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ActionCardComponent, selectors: [["mj-action-card"]], inputs: { Action: "Action", Categories: "Categories" }, outputs: { ActionClick: "ActionClick", EditClick: "EditClick", RunClick: "RunClick", CategoryClick: "CategoryClick" }, standalone: false, features: [i0.ɵɵInheritDefinitionFeature], decls: 29, vars: 21, consts: [[1, "action-card", 3, "click"], [1, "card-main"], [1, "action-icon"], [1, "action-content"], [1, "action-header"], [1, "action-name", 3, "title"], [1, "action-badges"], [1, "status-chip"], ["data-color", "info", 1, "status-chip"], [1, "action-description", 3, "title"], [1, "action-meta"], [1, "meta-item", "category", 3, "click", "title"], [1, "fa-solid", "fa-folder"], [1, "meta-item"], [1, "action-buttons"], ["mjButton", "", "variant", "flat", "size", "sm", "title", "View Stats", 3, "click"], ["mjButton", "", "variant", "primary", "size", "sm", "title", "Run Action", 3, "click", "disabled"], [1, "fa-solid", "fa-play"], ["mjButton", "", "variant", "flat", "size", "sm", "title", "Edit Action", 3, "click"], [1, "fa-solid", "fa-pen"], [1, "card-expanded"], [1, "fa-solid", "fa-robot"], [1, "fa-solid", "fa-clock"], [1, "stats-loading"], ["size", "small", 3, "showText"], [1, "stats-grid"], [1, "stat-item"], [1, "stat-value"], [1, "stat-label"], [1, "stat-item", "params"], [1, "params-preview"], [1, "params-header"], [1, "fa-solid", "fa-sliders"], [1, "params-list"], [1, "param-tag", 3, "required"], [1, "param-more"], [1, "param-tag"], [1, "required-marker"]], template: function ActionCardComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵlistener("click", function ActionCardComponent_Template_div_click_0_listener() { return ctx.onCardClick(); });
            i0.ɵɵelementStart(1, "div", 1)(2, "div", 2);
            i0.ɵɵelement(3, "i");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(4, "div", 3)(5, "div", 4)(6, "h3", 5);
            i0.ɵɵtext(7);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(8, "div", 6)(9, "span", 7);
            i0.ɵɵtext(10);
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(11, ActionCardComponent_Conditional_11_Template, 3, 0, "span", 8);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(12, "p", 9);
            i0.ɵɵtext(13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(14, "div", 10)(15, "button", 11);
            i0.ɵɵlistener("click", function ActionCardComponent_Template_button_click_15_listener($event) { return ctx.onCategoryClick($event); });
            i0.ɵɵelement(16, "i", 12);
            i0.ɵɵelementStart(17, "span");
            i0.ɵɵtext(18);
            i0.ɵɵelementEnd()();
            i0.ɵɵconditionalCreate(19, ActionCardComponent_Conditional_19_Template, 4, 1, "span", 13);
            i0.ɵɵconditionalCreate(20, ActionCardComponent_Conditional_20_Template, 4, 4, "span", 13);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(21, "div", 14)(22, "button", 15);
            i0.ɵɵlistener("click", function ActionCardComponent_Template_button_click_22_listener($event) { return ctx.toggleExpanded($event); });
            i0.ɵɵelement(23, "i");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(24, "button", 16);
            i0.ɵɵlistener("click", function ActionCardComponent_Template_button_click_24_listener($event) { return ctx.onRunClick($event); });
            i0.ɵɵelement(25, "i", 17);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(26, "button", 18);
            i0.ɵɵlistener("click", function ActionCardComponent_Template_button_click_26_listener($event) { return ctx.onEditClick($event); });
            i0.ɵɵelement(27, "i", 19);
            i0.ɵɵelementEnd()()();
            i0.ɵɵconditionalCreate(28, ActionCardComponent_Conditional_28_Template, 3, 1, "div", 20);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵclassProp("expanded", ctx.IsExpanded);
            i0.ɵɵadvance(2);
            i0.ɵɵclassProp("ai-generated", ctx.Action.Type === "Generated");
            i0.ɵɵadvance();
            i0.ɵɵclassMap(ctx.getActionIcon());
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("title", ctx.Action.Name);
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate(ctx.Action.Name);
            i0.ɵɵadvance(2);
            i0.ɵɵattribute("data-color", ctx.getStatusColor());
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate1(" ", ctx.Action.Status, " ");
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Action.Type === "Generated" ? 11 : -1);
            i0.ɵɵadvance();
            i0.ɵɵproperty("title", ctx.Action.Description || "No description");
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate1(" ", ctx.Action.Description || "No description available", " ");
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("title", "View category: " + ctx.getCategoryName());
            i0.ɵɵadvance(3);
            i0.ɵɵtextInterpolate(ctx.getCategoryName());
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Action.__mj_UpdatedAt ? 19 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Action.Type === "Generated" && ctx.Action.CodeApprovalStatus ? 20 : -1);
            i0.ɵɵadvance(3);
            i0.ɵɵclassMap(ctx.IsExpanded ? "fa-solid fa-chevron-up" : "fa-solid fa-chart-line");
            i0.ɵɵadvance();
            i0.ɵɵproperty("disabled", ctx.Action.Status !== "Active");
            i0.ɵɵadvance(4);
            i0.ɵɵconditional(ctx.IsExpanded ? 28 : -1);
        } }, dependencies: [i1.MJButtonDirective, i2.LoadingComponent], styles: [".action-card[_ngcontent-%COMP%] {\n  background: var(--mj-bg-surface-card);\n  border: 1px solid var(--mj-border-default);\n  border-radius: 12px;\n  overflow: hidden;\n  cursor: pointer;\n  transition: all 0.2s ease;\n}\n\n.action-card[_ngcontent-%COMP%]:hover {\n  border-color: var(--mj-brand-primary);\n  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n  transform: translateY(-2px);\n}\n\n.action-card.expanded[_ngcontent-%COMP%] {\n  border-color: var(--mj-brand-primary);\n}\n\n.card-main[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: flex-start;\n  gap: 16px;\n  padding: 20px;\n}\n\n\n\n.action-icon[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 48px;\n  height: 48px;\n  border-radius: 12px;\n  background: color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface));\n  flex-shrink: 0;\n}\n\n.action-icon[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 20px;\n  color: var(--mj-brand-primary);\n}\n\n.action-icon.ai-generated[_ngcontent-%COMP%] {\n  background: linear-gradient(135deg, color-mix(in srgb, var(--mj-status-info) 10%, var(--mj-bg-surface)), color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface)));\n}\n\n.action-icon.ai-generated[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  background: linear-gradient(135deg, var(--mj-status-info), var(--mj-brand-primary));\n  -webkit-background-clip: text;\n  -webkit-text-fill-color: transparent;\n  background-clip: text;\n}\n\n\n\n.action-content[_ngcontent-%COMP%] {\n  flex: 1;\n  min-width: 0;\n}\n\n.action-header[_ngcontent-%COMP%] {\n  display: flex;\n  justify-content: space-between;\n  align-items: flex-start;\n  gap: 12px;\n  margin-bottom: 8px;\n}\n\n.action-name[_ngcontent-%COMP%] {\n  margin: 0;\n  font-size: 16px;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n\n.action-badges[_ngcontent-%COMP%] {\n  display: flex;\n  gap: 6px;\n  flex-shrink: 0;\n}\n\n.action-description[_ngcontent-%COMP%] {\n  margin: 0 0 12px 0;\n  font-size: 13px;\n  color: var(--mj-text-muted);\n  line-height: 1.5;\n  display: -webkit-box;\n  -webkit-line-clamp: 2;\n  -webkit-box-orient: vertical;\n  overflow: hidden;\n}\n\n.action-meta[_ngcontent-%COMP%] {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 12px;\n}\n\n.meta-item[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  font-size: 12px;\n  color: var(--mj-text-muted);\n  background: none;\n  border: none;\n  padding: 0;\n  cursor: default;\n}\n\n.meta-item.category[_ngcontent-%COMP%] {\n  cursor: pointer;\n  padding: 2px 6px;\n  border-radius: 4px;\n  transition: background 0.15s ease;\n}\n\n.meta-item.category[_ngcontent-%COMP%]:hover {\n  background: var(--mj-bg-surface-hover);\n  color: var(--mj-brand-primary);\n}\n\n.meta-item[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 11px;\n  color: var(--mj-brand-primary);\n}\n\n.meta-item[data-status=\"Approved\"][_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-success);\n}\n\n.meta-item[data-status=\"Pending\"][_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-warning);\n}\n\n.meta-item[data-status=\"Rejected\"][_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  color: var(--mj-status-error);\n}\n\n\n\n.action-buttons[_ngcontent-%COMP%] {\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  opacity: 0;\n  transition: opacity 0.2s ease;\n}\n\n.action-card[_ngcontent-%COMP%]:hover   .action-buttons[_ngcontent-%COMP%] {\n  opacity: 1;\n}\n\n.action-buttons[_ngcontent-%COMP%]   button[_ngcontent-%COMP%] {\n  padding: 6px;\n}\n\n\n\n.card-expanded[_ngcontent-%COMP%] {\n  padding: 0 20px 20px 20px;\n  border-top: 1px solid var(--mj-border-default);\n  margin-top: -1px;\n  padding-top: 16px;\n  background: var(--mj-bg-page);\n}\n\n.stats-loading[_ngcontent-%COMP%] {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 12px;\n  padding: 20px;\n  color: var(--mj-text-muted);\n  font-size: 13px;\n}\n\n.stats-grid[_ngcontent-%COMP%] {\n  display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  gap: 16px;\n  margin-bottom: 16px;\n}\n\n.stat-item[_ngcontent-%COMP%] {\n  text-align: center;\n  padding: 12px 8px;\n  background: var(--mj-bg-surface-card);\n  border-radius: 8px;\n}\n\n.stat-value[_ngcontent-%COMP%] {\n  font-size: 20px;\n  font-weight: 700;\n  color: var(--mj-text-primary);\n  margin-bottom: 4px;\n}\n\n.stat-value.success[_ngcontent-%COMP%] {\n  color: var(--mj-status-success);\n}\n\n.stat-value.warning[_ngcontent-%COMP%] {\n  color: var(--mj-status-warning);\n}\n\n.stat-value.error[_ngcontent-%COMP%] {\n  color: var(--mj-status-error);\n}\n\n.stat-label[_ngcontent-%COMP%] {\n  font-size: 11px;\n  color: var(--mj-text-muted);\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n}\n\n\n\n.params-preview[_ngcontent-%COMP%] {\n  padding: 12px;\n  background: var(--mj-bg-surface-card);\n  border-radius: 8px;\n}\n\n.params-header[_ngcontent-%COMP%] {\n  font-size: 11px;\n  font-weight: 600;\n  color: var(--mj-text-muted);\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  margin-bottom: 8px;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n\n.params-header[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n  font-size: 12px;\n}\n\n.params-list[_ngcontent-%COMP%] {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 6px;\n}\n\n.param-tag[_ngcontent-%COMP%] {\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  padding: 4px 10px;\n  background: var(--mj-bg-surface-sunken);\n  border-radius: 14px;\n  font-size: 12px;\n  color: var(--mj-text-primary);\n}\n\n.param-tag.required[_ngcontent-%COMP%] {\n  background: color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface));\n  color: var(--mj-brand-primary);\n}\n\n.required-marker[_ngcontent-%COMP%] {\n  color: var(--mj-status-error);\n  font-weight: 600;\n}\n\n.param-more[_ngcontent-%COMP%] {\n  padding: 4px 10px;\n  font-size: 12px;\n  color: var(--mj-text-muted);\n}\n\n\n\n@media (max-width: 640px) {\n  .card-main[_ngcontent-%COMP%] {\n    flex-wrap: wrap;\n  }\n\n  .action-icon[_ngcontent-%COMP%] {\n    width: 40px;\n    height: 40px;\n  }\n\n  .action-icon[_ngcontent-%COMP%]   i[_ngcontent-%COMP%] {\n    font-size: 16px;\n  }\n\n  .action-header[_ngcontent-%COMP%] {\n    flex-direction: column;\n    align-items: flex-start;\n  }\n\n  .action-buttons[_ngcontent-%COMP%] {\n    flex-direction: row;\n    opacity: 1;\n    width: 100%;\n    justify-content: flex-end;\n  }\n\n  .stats-grid[_ngcontent-%COMP%] {\n    grid-template-columns: repeat(2, 1fr);\n  }\n}"], changeDetection: 0 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ActionCardComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-action-card', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"action-card\" [class.expanded]=\"IsExpanded\" (click)=\"onCardClick()\">\n  <div class=\"card-main\">\n    <!-- Icon -->\n    <div class=\"action-icon\" [class.ai-generated]=\"Action.Type === 'Generated'\">\n      <i [class]=\"getActionIcon()\"></i>\n    </div>\n\n    <!-- Content -->\n    <div class=\"action-content\">\n      <div class=\"action-header\">\n        <h3 class=\"action-name\" [title]=\"Action.Name\">{{ Action.Name }}</h3>\n        <div class=\"action-badges\">\n          <span class=\"status-chip\" [attr.data-color]=\"getStatusColor()\">\n            {{ Action.Status }}\n          </span>\n          @if (Action.Type === 'Generated') {\n            <span class=\"status-chip\" data-color=\"info\">\n              <i class=\"fa-solid fa-robot\"></i> AI\n            </span>\n          }\n        </div>\n      </div>\n\n      <p class=\"action-description\" [title]=\"Action.Description || 'No description'\">\n        {{ Action.Description || 'No description available' }}\n      </p>\n\n      <div class=\"action-meta\">\n        <button class=\"meta-item category\" (click)=\"onCategoryClick($event)\" [title]=\"'View category: ' + getCategoryName()\">\n          <i class=\"fa-solid fa-folder\"></i>\n          <span>{{ getCategoryName() }}</span>\n        </button>\n\n        @if (Action.__mj_UpdatedAt) {\n          <span class=\"meta-item\">\n            <i class=\"fa-solid fa-clock\"></i>\n            <span>{{ formatDate(Action.__mj_UpdatedAt) }}</span>\n          </span>\n        }\n\n        @if (Action.Type === 'Generated' && Action.CodeApprovalStatus) {\n          <span class=\"meta-item\" [attr.data-status]=\"Action.CodeApprovalStatus\">\n            <i [class]=\"getApprovalStatusIcon()\"></i>\n            <span>{{ Action.CodeApprovalStatus }}</span>\n          </span>\n        }\n      </div>\n    </div>\n\n    <!-- Actions -->\n    <div class=\"action-buttons\">\n      <button mjButton\n        variant=\"flat\"\n        size=\"sm\"\n        title=\"View Stats\"\n        (click)=\"toggleExpanded($event)\">\n        <i [class]=\"IsExpanded ? 'fa-solid fa-chevron-up' : 'fa-solid fa-chart-line'\"></i>\n      </button>\n      <button mjButton\n        variant=\"primary\"\n        size=\"sm\"\n        title=\"Run Action\"\n        [disabled]=\"Action.Status !== 'Active'\"\n        (click)=\"onRunClick($event)\">\n        <i class=\"fa-solid fa-play\"></i>\n      </button>\n      <button mjButton\n        variant=\"flat\"\n        size=\"sm\"\n        title=\"Edit Action\"\n        (click)=\"onEditClick($event)\">\n        <i class=\"fa-solid fa-pen\"></i>\n      </button>\n    </div>\n  </div>\n\n  <!-- Expanded Stats Section -->\n  @if (IsExpanded) {\n    <div class=\"card-expanded\">\n      @if (ExecutionStats.isLoading) {\n        <div class=\"stats-loading\">\n          <mj-loading [showText]=\"false\" size=\"small\"></mj-loading>\n          <span>Loading execution stats...</span>\n        </div>\n      } @else {\n        <div class=\"stats-grid\">\n          <div class=\"stat-item\">\n            <div class=\"stat-value\">{{ ExecutionStats.totalExecutions }}</div>\n            <div class=\"stat-label\">Total Runs</div>\n          </div>\n          <div class=\"stat-item\">\n            <div class=\"stat-value\" [class.success]=\"ExecutionStats.successRate >= 90\" [class.warning]=\"ExecutionStats.successRate >= 50 && ExecutionStats.successRate < 90\" [class.error]=\"ExecutionStats.successRate < 50\">\n              {{ ExecutionStats.successRate }}%\n            </div>\n            <div class=\"stat-label\">Success Rate</div>\n          </div>\n          <div class=\"stat-item\">\n            <div class=\"stat-value\">{{ formatDate(ExecutionStats.lastExecuted) }}</div>\n            <div class=\"stat-label\">Last Run</div>\n          </div>\n          <div class=\"stat-item params\">\n            <div class=\"stat-value\">{{ Action.Params.length || 0 }}</div>\n            <div class=\"stat-label\">Parameters</div>\n          </div>\n        </div>\n\n        @if (Action.Params && Action.Params.length > 0) {\n          <div class=\"params-preview\">\n            <div class=\"params-header\">\n              <i class=\"fa-solid fa-sliders\"></i>\n              Parameters\n            </div>\n            <div class=\"params-list\">\n              @for (param of Action.Params.slice(0, 4); track param.Name) {\n                <span class=\"param-tag\" [class.required]=\"param.IsRequired\">\n                  {{ param.Name }}\n                  @if (param.IsRequired) {\n                    <span class=\"required-marker\">*</span>\n                  }\n                </span>\n              }\n              @if (Action.Params.length > 4) {\n                <span class=\"param-more\">+{{ Action.Params.length - 4 }} more</span>\n              }\n            </div>\n          </div>\n        }\n      }\n    </div>\n  }\n</div>\n", styles: [".action-card {\n  background: var(--mj-bg-surface-card);\n  border: 1px solid var(--mj-border-default);\n  border-radius: 12px;\n  overflow: hidden;\n  cursor: pointer;\n  transition: all 0.2s ease;\n}\n\n.action-card:hover {\n  border-color: var(--mj-brand-primary);\n  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n  transform: translateY(-2px);\n}\n\n.action-card.expanded {\n  border-color: var(--mj-brand-primary);\n}\n\n.card-main {\n  display: flex;\n  align-items: flex-start;\n  gap: 16px;\n  padding: 20px;\n}\n\n/* Icon */\n.action-icon {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 48px;\n  height: 48px;\n  border-radius: 12px;\n  background: color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface));\n  flex-shrink: 0;\n}\n\n.action-icon i {\n  font-size: 20px;\n  color: var(--mj-brand-primary);\n}\n\n.action-icon.ai-generated {\n  background: linear-gradient(135deg, color-mix(in srgb, var(--mj-status-info) 10%, var(--mj-bg-surface)), color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface)));\n}\n\n.action-icon.ai-generated i {\n  background: linear-gradient(135deg, var(--mj-status-info), var(--mj-brand-primary));\n  -webkit-background-clip: text;\n  -webkit-text-fill-color: transparent;\n  background-clip: text;\n}\n\n/* Content */\n.action-content {\n  flex: 1;\n  min-width: 0;\n}\n\n.action-header {\n  display: flex;\n  justify-content: space-between;\n  align-items: flex-start;\n  gap: 12px;\n  margin-bottom: 8px;\n}\n\n.action-name {\n  margin: 0;\n  font-size: 16px;\n  font-weight: 600;\n  color: var(--mj-text-primary);\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n\n.action-badges {\n  display: flex;\n  gap: 6px;\n  flex-shrink: 0;\n}\n\n.action-description {\n  margin: 0 0 12px 0;\n  font-size: 13px;\n  color: var(--mj-text-muted);\n  line-height: 1.5;\n  display: -webkit-box;\n  -webkit-line-clamp: 2;\n  -webkit-box-orient: vertical;\n  overflow: hidden;\n}\n\n.action-meta {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 12px;\n}\n\n.meta-item {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  font-size: 12px;\n  color: var(--mj-text-muted);\n  background: none;\n  border: none;\n  padding: 0;\n  cursor: default;\n}\n\n.meta-item.category {\n  cursor: pointer;\n  padding: 2px 6px;\n  border-radius: 4px;\n  transition: background 0.15s ease;\n}\n\n.meta-item.category:hover {\n  background: var(--mj-bg-surface-hover);\n  color: var(--mj-brand-primary);\n}\n\n.meta-item i {\n  font-size: 11px;\n  color: var(--mj-brand-primary);\n}\n\n.meta-item[data-status=\"Approved\"] i {\n  color: var(--mj-status-success);\n}\n\n.meta-item[data-status=\"Pending\"] i {\n  color: var(--mj-status-warning);\n}\n\n.meta-item[data-status=\"Rejected\"] i {\n  color: var(--mj-status-error);\n}\n\n/* Action Buttons */\n.action-buttons {\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  opacity: 0;\n  transition: opacity 0.2s ease;\n}\n\n.action-card:hover .action-buttons {\n  opacity: 1;\n}\n\n.action-buttons button {\n  padding: 6px;\n}\n\n/* Expanded Section */\n.card-expanded {\n  padding: 0 20px 20px 20px;\n  border-top: 1px solid var(--mj-border-default);\n  margin-top: -1px;\n  padding-top: 16px;\n  background: var(--mj-bg-page);\n}\n\n.stats-loading {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 12px;\n  padding: 20px;\n  color: var(--mj-text-muted);\n  font-size: 13px;\n}\n\n.stats-grid {\n  display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  gap: 16px;\n  margin-bottom: 16px;\n}\n\n.stat-item {\n  text-align: center;\n  padding: 12px 8px;\n  background: var(--mj-bg-surface-card);\n  border-radius: 8px;\n}\n\n.stat-value {\n  font-size: 20px;\n  font-weight: 700;\n  color: var(--mj-text-primary);\n  margin-bottom: 4px;\n}\n\n.stat-value.success {\n  color: var(--mj-status-success);\n}\n\n.stat-value.warning {\n  color: var(--mj-status-warning);\n}\n\n.stat-value.error {\n  color: var(--mj-status-error);\n}\n\n.stat-label {\n  font-size: 11px;\n  color: var(--mj-text-muted);\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n}\n\n/* Params Preview */\n.params-preview {\n  padding: 12px;\n  background: var(--mj-bg-surface-card);\n  border-radius: 8px;\n}\n\n.params-header {\n  font-size: 11px;\n  font-weight: 600;\n  color: var(--mj-text-muted);\n  text-transform: uppercase;\n  letter-spacing: 0.5px;\n  margin-bottom: 8px;\n  display: flex;\n  align-items: center;\n  gap: 6px;\n}\n\n.params-header i {\n  font-size: 12px;\n}\n\n.params-list {\n  display: flex;\n  flex-wrap: wrap;\n  gap: 6px;\n}\n\n.param-tag {\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  padding: 4px 10px;\n  background: var(--mj-bg-surface-sunken);\n  border-radius: 14px;\n  font-size: 12px;\n  color: var(--mj-text-primary);\n}\n\n.param-tag.required {\n  background: color-mix(in srgb, var(--mj-brand-primary) 10%, var(--mj-bg-surface));\n  color: var(--mj-brand-primary);\n}\n\n.required-marker {\n  color: var(--mj-status-error);\n  font-weight: 600;\n}\n\n.param-more {\n  padding: 4px 10px;\n  font-size: 12px;\n  color: var(--mj-text-muted);\n}\n\n/* Responsive */\n@media (max-width: 640px) {\n  .card-main {\n    flex-wrap: wrap;\n  }\n\n  .action-icon {\n    width: 40px;\n    height: 40px;\n  }\n\n  .action-icon i {\n    font-size: 16px;\n  }\n\n  .action-header {\n    flex-direction: column;\n    align-items: flex-start;\n  }\n\n  .action-buttons {\n    flex-direction: row;\n    opacity: 1;\n    width: 100%;\n    justify-content: flex-end;\n  }\n\n  .stats-grid {\n    grid-template-columns: repeat(2, 1fr);\n  }\n}\n"] }]
    }], () => [{ type: i0.ChangeDetectorRef }], { Action: [{
            type: Input
        }], Categories: [{
            type: Input
        }], ActionClick: [{
            type: Output
        }], EditClick: [{
            type: Output
        }], RunClick: [{
            type: Output
        }], CategoryClick: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ActionCardComponent, { className: "ActionCardComponent", filePath: "src/Actions/components/explorer/action-card.component.ts", lineNumber: 29 }); })();
//# sourceMappingURL=action-card.component.js.map