var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
import * as appstate from '../../appstate.js';
import { viewHostCss } from '../shared/css.js';
import { DeesElement, customElement, html, state, css, cssManager, } from '@design.estate/dees-element';
import {} from '@design.estate/dees-catalog';
let OpsViewSecurityAuthentication = (() => {
    let _classDecorators = [customElement('ops-view-security-authentication')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _statsState_decorators;
    let _statsState_initializers = [];
    let _statsState_extraInitializers = [];
    var OpsViewSecurityAuthentication = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _statsState_decorators = [state()];
            __esDecorate(this, null, _statsState_decorators, { kind: "accessor", name: "statsState", static: false, private: false, access: { has: obj => "statsState" in obj, get: obj => obj.statsState, set: (obj, value) => { obj.statsState = value; } }, metadata: _metadata }, _statsState_initializers, _statsState_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            OpsViewSecurityAuthentication = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #statsState_accessor_storage = __runInitializers(this, _statsState_initializers, appstate.statsStatePart.getState());
        get statsState() { return this.#statsState_accessor_storage; }
        set statsState(value) { this.#statsState_accessor_storage = value; }
        constructor() {
            super();
            __runInitializers(this, _statsState_extraInitializers);
            const sub = appstate.statsStatePart
                .select((s) => s)
                .subscribe((s) => {
                this.statsState = s;
            });
            this.rxSubscriptions.push(sub);
        }
        static styles = [
            cssManager.defaultStyles,
            viewHostCss,
            css `
      h2 {
        margin: 32px 0 16px 0;
        font-size: 24px;
        font-weight: 600;
        color: ${cssManager.bdTheme('#333', '#ccc')};
      }
      dees-statsgrid {
        margin-bottom: 32px;
      }
    `,
        ];
        render() {
            const metrics = this.statsState.securityMetrics;
            if (!metrics) {
                return html `
        <div class="loadingMessage">
          <p>Loading security metrics...</p>
        </div>
      `;
            }
            // Derive auth events from recentEvents
            const allEvents = metrics.recentEvents || [];
            const authEvents = allEvents.filter((evt) => evt.type === 'authentication');
            const successfulLogins = authEvents.filter((evt) => evt.success === true).length;
            const tiles = [
                {
                    id: 'authFailures',
                    title: 'Authentication Failures',
                    value: metrics.authenticationFailures,
                    type: 'number',
                    icon: 'lucide:LockOpen',
                    color: metrics.authenticationFailures > 10 ? '#ef4444' : '#f59e0b',
                    description: 'Failed authentication attempts today',
                },
                {
                    id: 'successfulLogins',
                    title: 'Successful Logins',
                    value: successfulLogins,
                    type: 'number',
                    icon: 'lucide:Lock',
                    color: '#22c55e',
                    description: 'Successful logins today',
                },
            ];
            // Map auth events to login history table data
            const loginHistory = authEvents.map((evt) => ({
                timestamp: evt.timestamp,
                username: evt.details?.username || 'unknown',
                ipAddress: evt.ipAddress || 'unknown',
                success: evt.success ?? false,
                reason: evt.success ? '' : evt.message || 'Authentication failed',
            }));
            return html `
      <dees-heading level="3">Authentication</dees-heading>

      <dees-statsgrid
        .tiles=${tiles}
        .minTileWidth=${200}
      ></dees-statsgrid>

      <h2>Recent Login Attempts</h2>
      <dees-table
        .heading1=${'Login History'}
        .heading2=${'Recent authentication attempts'}
        .data=${loginHistory}
        .displayFunction=${(item) => ({
                'Time': new Date(item.timestamp).toLocaleString(),
                'Username': item.username,
                'IP Address': item.ipAddress,
                'Status': item.success ? 'Success' : 'Failed',
                'Reason': item.reason || '-',
            })}
      ></dees-table>
    `;
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return OpsViewSecurityAuthentication = _classThis;
})();
export { OpsViewSecurityAuthentication };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3BzLXZpZXctc2VjdXJpdHktYXV0aGVudGljYXRpb24uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi90c193ZWIvZWxlbWVudHMvc2VjdXJpdHkvb3BzLXZpZXctc2VjdXJpdHktYXV0aGVudGljYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLE9BQU8sS0FBSyxRQUFRLE1BQU0sbUJBQW1CLENBQUM7QUFDOUMsT0FBTy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