import { Component, Input, Output, EventEmitter } from '@angular/core';
import { ResolveIntegrationIcon } from '../../services/integration-data.service';
import * as i0 from "@angular/core";
import * as i1 from "@memberjunction/ng-ui-components";
import * as i2 from "@angular/common";
const _forTrack0 = ($index, $item) => $item.ID;
function IntegrationCardComponent_Conditional_19_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10)(1, "span", 11);
    i0.ɵɵtext(2, "Records Synced");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "span", 12);
    i0.ɵɵtext(4);
    i0.ɵɵpipe(5, "number");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(6, "div", 10)(7, "span", 11);
    i0.ɵɵtext(8, "Duration");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(9, "span", 12);
    i0.ɵɵtext(10);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(5, 2, ctx_r0.Summary.LatestRun.TotalRecords));
    i0.ɵɵadvance(6);
    i0.ɵɵtextInterpolate(ctx_r0.FormattedDuration);
} }
function IntegrationCardComponent_Conditional_20_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10)(1, "span", 11);
    i0.ɵɵtext(2, "Errors");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "span", 19)(4, "span", 20);
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(ctx_r0.Summary.TotalErrors);
} }
function IntegrationCardComponent_Conditional_21_For_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 24);
} if (rf & 2) {
    const run_r2 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵstyleProp("height", ctx_r0.SparkBarHeight(run_r2.TotalRecords), "%");
    i0.ɵɵclassProp("spark-success", run_r2.Status === "Success")("spark-failed", run_r2.Status === "Failed")("spark-pending", run_r2.Status !== "Success" && run_r2.Status !== "Failed");
    i0.ɵɵproperty("title", run_r2.TotalRecords + " records - " + run_r2.Status);
} }
function IntegrationCardComponent_Conditional_21_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 13)(1, "span", 21);
    i0.ɵɵtext(2, "Recent syncs");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "div", 22);
    i0.ɵɵrepeaterCreate(4, IntegrationCardComponent_Conditional_21_For_5_Template, 1, 9, "div", 23, _forTrack0);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(4);
    i0.ɵɵrepeater(ctx_r0.Summary.RecentRuns);
} }
export class IntegrationCardComponent {
    Summary;
    Expanded = false;
    ViewProvider = null;
    RunNowClick = new EventEmitter();
    ExpandToggle = new EventEmitter();
    get SourceIconClass() {
        if (this.Summary.SourceType?.IconClass) {
            return this.Summary.SourceType.IconClass;
        }
        return ResolveIntegrationIcon(this.Summary.Integration.Integration ?? this.Summary.Integration.Name, this.Summary.Icon);
    }
    get StatusLabel() {
        const color = this.Summary.StatusColor;
        if (color === 'green')
            return 'Healthy';
        if (color === 'amber')
            return 'Warning';
        if (color === 'red')
            return 'Failed';
        return 'Inactive';
    }
    get IsActivelySyncing() {
        return this.Summary.LatestRun?.Status === 'In Progress'
            || this.Summary.LatestRun?.Status === 'Pending';
    }
    get FormattedDuration() {
        const ms = this.Summary.DurationMs;
        if (ms == null)
            return '--';
        const totalSeconds = Math.floor(ms / 1000);
        if (totalSeconds < 60)
            return `${totalSeconds}s`;
        const minutes = Math.floor(totalSeconds / 60);
        const seconds = totalSeconds % 60;
        return `${minutes}m ${seconds}s`;
    }
    get MaxSparkRecords() {
        const maxVal = Math.max(...this.Summary.RecentRuns.map(r => r.TotalRecords));
        return maxVal > 0 ? maxVal : 1;
    }
    SparkBarHeight(records) {
        return Math.max((records / this.MaxSparkRecords) * 100, 8);
    }
    OnRunNowClick() {
        this.RunNowClick.emit(this.Summary.Integration.ID);
    }
    OnExpandToggle() {
        this.ExpandToggle.emit(this.Summary.Integration.ID);
    }
    static ɵfac = function IntegrationCardComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || IntegrationCardComponent)(); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: IntegrationCardComponent, selectors: [["app-integration-card"]], inputs: { Summary: "Summary", Expanded: "Expanded", ViewProvider: "ViewProvider" }, outputs: { RunNowClick: "RunNowClick", ExpandToggle: "ExpandToggle" }, standalone: false, decls: 29, vars: 22, consts: [[1, "integration-card"], [1, "card-header"], [1, "source-icon"], [1, "card-title-area"], [1, "card-title"], [1, "source-type-label"], [1, "status-area"], [1, "status-indicator"], [1, "status-chip"], [1, "card-body"], [1, "stat-row"], [1, "stat-label"], [1, "stat-value"], [1, "sparkline-row"], [1, "card-footer"], ["mjButton", "", "variant", "primary", "size", "sm", 3, "click", "disabled"], [1, "fa-solid", "fa-play"], ["mjButton", "", "variant", "flat", "size", "sm", 3, "click"], [1, "fa-solid"], [1, "stat-value", "error-value"], [1, "error-badge"], [1, "sparkline-label"], [1, "sparkline"], [1, "spark-bar", 3, "height", "spark-success", "spark-failed", "spark-pending", "title"], [1, "spark-bar", 3, "title"]], template: function IntegrationCardComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "div", 2);
            i0.ɵɵelement(3, "i");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(4, "div", 3)(5, "h3", 4);
            i0.ɵɵtext(6);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(7, "span", 5);
            i0.ɵɵtext(8);
            i0.ɵɵelementEnd()();
            i0.ɵɵelementStart(9, "div", 6);
            i0.ɵɵelement(10, "span", 7);
            i0.ɵɵelementStart(11, "span", 8);
            i0.ɵɵtext(12);
            i0.ɵɵelementEnd()()();
            i0.ɵɵelementStart(13, "div", 9)(14, "div", 10)(15, "span", 11);
            i0.ɵɵtext(16, "Last Run");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(17, "span", 12);
            i0.ɵɵtext(18);
            i0.ɵɵelementEnd()();
            i0.ɵɵconditionalCreate(19, IntegrationCardComponent_Conditional_19_Template, 11, 4);
            i0.ɵɵconditionalCreate(20, IntegrationCardComponent_Conditional_20_Template, 6, 1, "div", 10);
            i0.ɵɵelementEnd();
            i0.ɵɵconditionalCreate(21, IntegrationCardComponent_Conditional_21_Template, 6, 0, "div", 13);
            i0.ɵɵelementStart(22, "div", 14)(23, "button", 15);
            i0.ɵɵlistener("click", function IntegrationCardComponent_Template_button_click_23_listener() { return ctx.OnRunNowClick(); });
            i0.ɵɵelement(24, "i", 16);
            i0.ɵɵtext(25, " Run Now ");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(26, "button", 17);
            i0.ɵɵlistener("click", function IntegrationCardComponent_Template_button_click_26_listener() { return ctx.OnExpandToggle(); });
            i0.ɵɵelement(27, "i", 18);
            i0.ɵɵtext(28, " History ");
            i0.ɵɵelementEnd()()();
        } if (rf & 2) {
            i0.ɵɵclassProp("inactive", !ctx.Summary.Integration.IsActive);
            i0.ɵɵadvance(3);
            i0.ɵɵclassMap(ctx.SourceIconClass);
            i0.ɵɵadvance(3);
            i0.ɵɵtextInterpolate(ctx.Summary.Integration.Name);
            i0.ɵɵadvance(2);
            i0.ɵɵtextInterpolate((ctx.Summary.SourceType == null ? null : ctx.Summary.SourceType.Name) ?? "Unknown");
            i0.ɵɵadvance(2);
            i0.ɵɵclassMap("indicator-" + ctx.Summary.StatusColor);
            i0.ɵɵclassProp("pulsing", ctx.IsActivelySyncing);
            i0.ɵɵadvance();
            i0.ɵɵclassMap("status-" + ctx.Summary.StatusColor);
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate1(" ", ctx.StatusLabel, " ");
            i0.ɵɵadvance(6);
            i0.ɵɵtextInterpolate(ctx.Summary.RelativeTime);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Summary.LatestRun ? 19 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Summary.TotalErrors > 0 ? 20 : -1);
            i0.ɵɵadvance();
            i0.ɵɵconditional(ctx.Summary.RecentRuns.length > 1 ? 21 : -1);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("disabled", !ctx.Summary.Integration.IsActive);
            i0.ɵɵadvance(4);
            i0.ɵɵclassProp("fa-chevron-down", !ctx.Expanded)("fa-chevron-up", ctx.Expanded);
        } }, dependencies: [i1.MJButtonDirective, i2.DecimalPipe], styles: [".integration-card[_ngcontent-%COMP%] {\n      background: var(--card-bg, #fff);\n      border: 1px solid var(--border-color, #e0e0e0);\n      border-radius: 8px;\n      padding: 16px;\n      transition: box-shadow 0.2s;\n    }\n    .integration-card[_ngcontent-%COMP%]:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }\n    .integration-card.inactive[_ngcontent-%COMP%] { opacity: 0.6; }\n\n    .card-header[_ngcontent-%COMP%] {\n      display: flex;\n      align-items: center;\n      gap: 12px;\n      margin-bottom: 12px;\n    }\n    .source-icon[_ngcontent-%COMP%] {\n      width: 40px; height: 40px;\n      border-radius: 8px;\n      background: var(--icon-bg, #f0f4ff);\n      display: flex; align-items: center; justify-content: center;\n      font-size: 18px; color: var(--primary-color, #4a6cf7);\n    }\n    .card-title-area[_ngcontent-%COMP%] { flex: 1; min-width: 0; }\n    .card-title[_ngcontent-%COMP%] {\n      margin: 0; font-size: 14px; font-weight: 600;\n      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n    }\n    .source-type-label[_ngcontent-%COMP%] { font-size: 12px; color: #888; }\n\n    .status-area[_ngcontent-%COMP%] {\n      display: flex;\n      align-items: center;\n      gap: 6px;\n      flex-shrink: 0;\n    }\n\n    .status-indicator[_ngcontent-%COMP%] {\n      width: 8px;\n      height: 8px;\n      border-radius: 50%;\n      display: inline-block;\n    }\n    .indicator-green[_ngcontent-%COMP%] { background: #1b7a3d; }\n    .indicator-amber[_ngcontent-%COMP%] { background: #b5850a; }\n    .indicator-red[_ngcontent-%COMP%] { background: #c62828; }\n    .indicator-gray[_ngcontent-%COMP%] { background: #999; }\n\n    .status-indicator.pulsing[_ngcontent-%COMP%] {\n      animation: _ngcontent-%COMP%_pulse 1.5s ease-in-out infinite;\n    }\n    @keyframes _ngcontent-%COMP%_pulse {\n      0%, 100% { opacity: 1; transform: scale(1); }\n      50% { opacity: 0.5; transform: scale(1.3); }\n    }\n\n    .status-chip[_ngcontent-%COMP%] {\n      font-size: 11px; font-weight: 600; padding: 3px 8px;\n      border-radius: 12px; text-transform: uppercase; white-space: nowrap;\n    }\n    .status-green[_ngcontent-%COMP%] { background: #e6f9ed; color: #1b7a3d; }\n    .status-amber[_ngcontent-%COMP%] { background: #fff7e0; color: #b5850a; }\n    .status-red[_ngcontent-%COMP%]   { background: #fde8e8; color: #c62828; }\n    .status-gray[_ngcontent-%COMP%]  { background: #f0f0f0; color: #757575; }\n\n    .card-body[_ngcontent-%COMP%] { margin-bottom: 12px; }\n    .stat-row[_ngcontent-%COMP%] {\n      display: flex; justify-content: space-between;\n      padding: 4px 0; font-size: 13px;\n    }\n    .stat-label[_ngcontent-%COMP%] { color: #666; }\n    .stat-value[_ngcontent-%COMP%] { font-weight: 500; }\n    .error-value[_ngcontent-%COMP%] { color: #c62828; }\n    .error-badge[_ngcontent-%COMP%] {\n      background: #fde8e8;\n      color: #c62828;\n      padding: 1px 8px;\n      border-radius: 10px;\n      font-size: 12px;\n      font-weight: 700;\n    }\n\n    \n\n    .sparkline-row[_ngcontent-%COMP%] {\n      display: flex;\n      align-items: flex-end;\n      gap: 8px;\n      padding: 8px 0;\n      border-top: 1px solid #f0f0f0;\n      margin-bottom: 4px;\n    }\n    .sparkline-label[_ngcontent-%COMP%] {\n      font-size: 11px;\n      color: #999;\n      white-space: nowrap;\n    }\n    .sparkline[_ngcontent-%COMP%] {\n      display: flex;\n      align-items: flex-end;\n      gap: 3px;\n      height: 24px;\n      flex: 1;\n    }\n    .spark-bar[_ngcontent-%COMP%] {\n      flex: 1;\n      min-height: 2px;\n      border-radius: 2px 2px 0 0;\n      transition: height 0.3s ease;\n    }\n    .spark-success[_ngcontent-%COMP%] { background: #4a6cf7; }\n    .spark-failed[_ngcontent-%COMP%] { background: #c62828; }\n    .spark-pending[_ngcontent-%COMP%] { background: #b5850a; }\n\n    .card-footer[_ngcontent-%COMP%] {\n      display: flex; justify-content: space-between;\n      border-top: 1px solid #eee; padding-top: 8px;\n    }"] });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(IntegrationCardComponent, [{
        type: Component,
        args: [{ standalone: false, selector: 'app-integration-card', template: `
    <div class="integration-card" [class.inactive]="!Summary.Integration.IsActive">
      <div class="card-header">
        <div class="source-icon">
          <i [class]="SourceIconClass"></i>
        </div>
        <div class="card-title-area">
          <h3 class="card-title">{{ Summary.Integration.Name }}</h3>
          <span class="source-type-label">{{ Summary.SourceType?.Name ?? 'Unknown' }}</span>
        </div>
        <div class="status-area">
          <span class="status-indicator" [class]="'indicator-' + Summary.StatusColor"
                [class.pulsing]="IsActivelySyncing"></span>
          <span class="status-chip" [class]="'status-' + Summary.StatusColor">
            {{ StatusLabel }}
          </span>
        </div>
      </div>

      <div class="card-body">
        <div class="stat-row">
          <span class="stat-label">Last Run</span>
          <span class="stat-value">{{ Summary.RelativeTime }}</span>
        </div>
        @if (Summary.LatestRun) {
          <div class="stat-row">
            <span class="stat-label">Records Synced</span>
            <span class="stat-value">{{ Summary.LatestRun.TotalRecords | number }}</span>
          </div>
          <div class="stat-row">
            <span class="stat-label">Duration</span>
            <span class="stat-value">{{ FormattedDuration }}</span>
          </div>
        }
        @if (Summary.TotalErrors > 0) {
          <div class="stat-row">
            <span class="stat-label">Errors</span>
            <span class="stat-value error-value">
              <span class="error-badge">{{ Summary.TotalErrors }}</span>
            </span>
          </div>
        }
      </div>

      <!-- Sparkline: records synced for last 5 runs -->
      @if (Summary.RecentRuns.length > 1) {
        <div class="sparkline-row">
          <span class="sparkline-label">Recent syncs</span>
          <div class="sparkline">
            @for (run of Summary.RecentRuns; track run.ID) {
              <div class="spark-bar"
                   [style.height.%]="SparkBarHeight(run.TotalRecords)"
                   [class.spark-success]="run.Status === 'Success'"
                   [class.spark-failed]="run.Status === 'Failed'"
                   [class.spark-pending]="run.Status !== 'Success' && run.Status !== 'Failed'"
                   [title]="run.TotalRecords + ' records - ' + run.Status">
              </div>
            }
          </div>
        </div>
      }

      <div class="card-footer">
        <button mjButton variant="primary" size="sm"
                (click)="OnRunNowClick()" [disabled]="!Summary.Integration.IsActive">
          <i class="fa-solid fa-play"></i> Run Now
        </button>
        <button mjButton variant="flat" size="sm" (click)="OnExpandToggle()">
          <i class="fa-solid" [class.fa-chevron-down]="!Expanded" [class.fa-chevron-up]="Expanded"></i>
          History
        </button>
      </div>
    </div>
  `, styles: ["\n    .integration-card {\n      background: var(--card-bg, #fff);\n      border: 1px solid var(--border-color, #e0e0e0);\n      border-radius: 8px;\n      padding: 16px;\n      transition: box-shadow 0.2s;\n    }\n    .integration-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }\n    .integration-card.inactive { opacity: 0.6; }\n\n    .card-header {\n      display: flex;\n      align-items: center;\n      gap: 12px;\n      margin-bottom: 12px;\n    }\n    .source-icon {\n      width: 40px; height: 40px;\n      border-radius: 8px;\n      background: var(--icon-bg, #f0f4ff);\n      display: flex; align-items: center; justify-content: center;\n      font-size: 18px; color: var(--primary-color, #4a6cf7);\n    }\n    .card-title-area { flex: 1; min-width: 0; }\n    .card-title {\n      margin: 0; font-size: 14px; font-weight: 600;\n      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n    }\n    .source-type-label { font-size: 12px; color: #888; }\n\n    .status-area {\n      display: flex;\n      align-items: center;\n      gap: 6px;\n      flex-shrink: 0;\n    }\n\n    .status-indicator {\n      width: 8px;\n      height: 8px;\n      border-radius: 50%;\n      display: inline-block;\n    }\n    .indicator-green { background: #1b7a3d; }\n    .indicator-amber { background: #b5850a; }\n    .indicator-red { background: #c62828; }\n    .indicator-gray { background: #999; }\n\n    .status-indicator.pulsing {\n      animation: pulse 1.5s ease-in-out infinite;\n    }\n    @keyframes pulse {\n      0%, 100% { opacity: 1; transform: scale(1); }\n      50% { opacity: 0.5; transform: scale(1.3); }\n    }\n\n    .status-chip {\n      font-size: 11px; font-weight: 600; padding: 3px 8px;\n      border-radius: 12px; text-transform: uppercase; white-space: nowrap;\n    }\n    .status-green { background: #e6f9ed; color: #1b7a3d; }\n    .status-amber { background: #fff7e0; color: #b5850a; }\n    .status-red   { background: #fde8e8; color: #c62828; }\n    .status-gray  { background: #f0f0f0; color: #757575; }\n\n    .card-body { margin-bottom: 12px; }\n    .stat-row {\n      display: flex; justify-content: space-between;\n      padding: 4px 0; font-size: 13px;\n    }\n    .stat-label { color: #666; }\n    .stat-value { font-weight: 500; }\n    .error-value { color: #c62828; }\n    .error-badge {\n      background: #fde8e8;\n      color: #c62828;\n      padding: 1px 8px;\n      border-radius: 10px;\n      font-size: 12px;\n      font-weight: 700;\n    }\n\n    /* Sparkline */\n    .sparkline-row {\n      display: flex;\n      align-items: flex-end;\n      gap: 8px;\n      padding: 8px 0;\n      border-top: 1px solid #f0f0f0;\n      margin-bottom: 4px;\n    }\n    .sparkline-label {\n      font-size: 11px;\n      color: #999;\n      white-space: nowrap;\n    }\n    .sparkline {\n      display: flex;\n      align-items: flex-end;\n      gap: 3px;\n      height: 24px;\n      flex: 1;\n    }\n    .spark-bar {\n      flex: 1;\n      min-height: 2px;\n      border-radius: 2px 2px 0 0;\n      transition: height 0.3s ease;\n    }\n    .spark-success { background: #4a6cf7; }\n    .spark-failed { background: #c62828; }\n    .spark-pending { background: #b5850a; }\n\n    .card-footer {\n      display: flex; justify-content: space-between;\n      border-top: 1px solid #eee; padding-top: 8px;\n    }\n  "] }]
    }], null, { Summary: [{
            type: Input
        }], Expanded: [{
            type: Input
        }], ViewProvider: [{
            type: Input
        }], RunNowClick: [{
            type: Output
        }], ExpandToggle: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(IntegrationCardComponent, { className: "IntegrationCardComponent", filePath: "src/Integration/components/widgets/integration-card.component.ts", lineNumber: 202 }); })();
//# sourceMappingURL=integration-card.component.js.map