import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { CompositeKey, Metadata } from '@memberjunction/core';
import { SharedService } from '@memberjunction/ng-shared';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
function EntityLinkPillComponent_Conditional_0_Template(rf, ctx) { if (rf & 1) {
    const _r1 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "span", 1);
    i0.ɵɵlistener("click", function EntityLinkPillComponent_Conditional_0_Template_span_click_0_listener() { i0.ɵɵrestoreView(_r1); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.openRecord()); });
    i0.ɵɵelement(1, "i", 2);
    i0.ɵɵelementStart(2, "span", 3);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelement(4, "i", 4);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("title", ctx_r1.tooltipText);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngClass", ctx_r1.iconClass);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.displayLabel);
} }
/**
 * A clickable pill component that displays a link to a related entity record.
 * Shows the entity icon (from metadata) and either the record name or entity name.
 * Clicking opens the entity record in a new tab.
 *
 * Usage:
 * ```html
 * <mj-entity-link-pill
 *   [entityName]="'MJ: AI Agent Runs'"
 *   [recordId]="run.TargetLogID"
 *   [recordName]="run.AgentRunName">
 * </mj-entity-link-pill>
 * ```
 */
export class EntityLinkPillComponent {
    constructor(cdr) {
        this.cdr = cdr;
        /**
         * The entity name to link to (e.g., 'MJ: AI Agent Runs')
         */
        this.entityName = null;
        /**
         * The record ID to link to
         */
        this.recordId = null;
        /**
         * Optional display name for the record. If not provided, uses entity name.
         */
        this.recordName = null;
        this.entityInfo = null;
        this.metadata = new Metadata();
    }
    ngOnChanges(changes) {
        if (changes['entityName'] && this.entityName) {
            this.entityInfo = this.metadata.EntityByName(this.entityName);
            this.cdr.markForCheck();
        }
    }
    get iconClass() {
        if (this.entityInfo?.Icon) {
            // Entity icon is typically a Font Awesome class like 'fa-robot'
            // Ensure it has the proper prefix
            const icon = this.entityInfo.Icon;
            if (icon.startsWith('fa-')) {
                return `fas ${icon}`;
            }
            return icon;
        }
        // Default icon if none specified
        return 'fas fa-link';
    }
    get displayLabel() {
        if (this.recordName) {
            return this.recordName;
        }
        if (this.entityInfo) {
            return this.entityInfo.Name;
        }
        return 'View Record';
    }
    get tooltipText() {
        const entityLabel = this.entityInfo?.Name || 'Record';
        if (this.recordName) {
            return `Open ${entityLabel}: ${this.recordName}`;
        }
        return `Open ${entityLabel}`;
    }
    openRecord() {
        if (this.entityName && this.recordId) {
            SharedService.Instance.OpenEntityRecord(this.entityName, CompositeKey.FromID(this.recordId));
        }
    }
    static { this.ɵfac = function EntityLinkPillComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || EntityLinkPillComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: EntityLinkPillComponent, selectors: [["mj-entity-link-pill"]], inputs: { entityName: "entityName", recordId: "recordId", recordName: "recordName" }, standalone: false, features: [i0.ɵɵNgOnChangesFeature], decls: 1, vars: 1, consts: [[1, "entity-link-pill", 3, "title"], [1, "entity-link-pill", 3, "click", "title"], [1, "entity-icon", 3, "ngClass"], [1, "entity-label"], [1, "fas", "fa-external-link-alt", "pill-action"]], template: function EntityLinkPillComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵconditionalCreate(0, EntityLinkPillComponent_Conditional_0_Template, 5, 3, "span", 0);
        } if (rf & 2) {
            i0.ɵɵconditional(ctx.entityInfo && ctx.recordId ? 0 : -1);
        } }, dependencies: [i1.NgClass], styles: [".entity-link-pill[_ngcontent-%COMP%] {\n      display: inline-flex;\n      align-items: center;\n      gap: 6px;\n      padding: 4px 10px;\n      background: color-mix(in srgb, var(--mj-brand-primary) 8%, transparent);\n      border: 1px solid color-mix(in srgb, var(--mj-brand-primary) 20%, transparent);\n      border-radius: 16px;\n      font-size: 12px;\n      font-weight: 500;\n      color: var(--mj-brand-primary);\n      cursor: pointer;\n      transition: all 0.2s ease;\n      white-space: nowrap;\n      max-width: 200px;\n    }\n\n    .entity-link-pill[_ngcontent-%COMP%]:hover {\n      background: color-mix(in srgb, var(--mj-brand-primary) 15%, transparent);\n      border-color: color-mix(in srgb, var(--mj-brand-primary) 40%, transparent);\n      transform: translateY(-1px);\n      box-shadow: var(--mj-shadow-sm);\n    }\n\n    .entity-icon[_ngcontent-%COMP%] {\n      font-size: 11px;\n      opacity: 0.9;\n    }\n\n    .entity-label[_ngcontent-%COMP%] {\n      overflow: hidden;\n      text-overflow: ellipsis;\n      max-width: 150px;\n    }\n\n    .pill-action[_ngcontent-%COMP%] {\n      font-size: 9px;\n      opacity: 0.6;\n      transition: opacity 0.2s ease;\n    }\n\n    .entity-link-pill[_ngcontent-%COMP%]:hover   .pill-action[_ngcontent-%COMP%] {\n      opacity: 1;\n    }"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EntityLinkPillComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'mj-entity-link-pill', template: `
    @if (entityInfo && recordId) {
      <span class="entity-link-pill" (click)="openRecord()" [title]="tooltipText">
        <i class="entity-icon" [ngClass]="iconClass"></i>
        <span class="entity-label">{{ displayLabel }}</span>
        <i class="fas fa-external-link-alt pill-action"></i>
      </span>
    }
    `, changeDetection: ChangeDetectionStrategy.OnPush, styles: ["\n    .entity-link-pill {\n      display: inline-flex;\n      align-items: center;\n      gap: 6px;\n      padding: 4px 10px;\n      background: color-mix(in srgb, var(--mj-brand-primary) 8%, transparent);\n      border: 1px solid color-mix(in srgb, var(--mj-brand-primary) 20%, transparent);\n      border-radius: 16px;\n      font-size: 12px;\n      font-weight: 500;\n      color: var(--mj-brand-primary);\n      cursor: pointer;\n      transition: all 0.2s ease;\n      white-space: nowrap;\n      max-width: 200px;\n    }\n\n    .entity-link-pill:hover {\n      background: color-mix(in srgb, var(--mj-brand-primary) 15%, transparent);\n      border-color: color-mix(in srgb, var(--mj-brand-primary) 40%, transparent);\n      transform: translateY(-1px);\n      box-shadow: var(--mj-shadow-sm);\n    }\n\n    .entity-icon {\n      font-size: 11px;\n      opacity: 0.9;\n    }\n\n    .entity-label {\n      overflow: hidden;\n      text-overflow: ellipsis;\n      max-width: 150px;\n    }\n\n    .pill-action {\n      font-size: 9px;\n      opacity: 0.6;\n      transition: opacity 0.2s ease;\n    }\n\n    .entity-link-pill:hover .pill-action {\n      opacity: 1;\n    }\n  "] }]
    }], () => [{ type: i0.ChangeDetectorRef }], { entityName: [{
            type: Input
        }], recordId: [{
            type: Input
        }], recordName: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(EntityLinkPillComponent, { className: "EntityLinkPillComponent", filePath: "src/lib/custom/Tests/entity-link-pill.component.ts", lineNumber: 79 }); })();
//# sourceMappingURL=entity-link-pill.component.js.map