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 { DeesElement, html, customElement, css, state, cssManager, } from '@design.estate/dees-element';
import {} from '@design.estate/dees-catalog';
import * as appstate from '../../appstate.js';
import * as interfaces from '../../../dist_ts_interfaces/index.js';
import { viewHostCss } from '../shared/css.js';
let OpsViewRedirects = (() => {
    let _classDecorators = [customElement('ops-view-redirects')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _routeState_decorators;
    let _routeState_initializers = [];
    let _routeState_extraInitializers = [];
    var OpsViewRedirects = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _routeState_decorators = [state()];
            __esDecorate(this, null, _routeState_decorators, { kind: "accessor", name: "routeState", static: false, private: false, access: { has: obj => "routeState" in obj, get: obj => obj.routeState, set: (obj, value) => { obj.routeState = value; } }, metadata: _metadata }, _routeState_initializers, _routeState_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            OpsViewRedirects = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #routeState_accessor_storage = __runInitializers(this, _routeState_initializers, appstate.routeManagementStatePart.getState());
        get routeState() { return this.#routeState_accessor_storage; }
        set routeState(value) { this.#routeState_accessor_storage = value; }
        constructor() {
            super();
            __runInitializers(this, _routeState_extraInitializers);
            const routeSub = appstate.routeManagementStatePart.select().subscribe((routeState) => {
                this.routeState = routeState;
            });
            this.rxSubscriptions.push(routeSub);
            const loginSub = appstate.loginStatePart
                .select((state) => state.isLoggedIn)
                .subscribe((isLoggedIn) => {
                if (isLoggedIn) {
                    void this.refreshData();
                }
            });
            this.rxSubscriptions.push(loginSub);
        }
        async connectedCallback() {
            await super.connectedCallback();
            await this.refreshData();
        }
        static styles = [
            cssManager.defaultStyles,
            viewHostCss,
            css `
      .redirectsContainer {
        display: flex;
        flex-direction: column;
        gap: 24px;
      }

      .empty-state {
        text-align: center;
        padding: 48px 24px;
        color: ${cssManager.bdTheme('#6b7280', '#9ca3af')};
      }

      .empty-state p {
        margin: 8px 0;
      }
    `,
        ];
        render() {
            const redirects = this.routeState.httpRedirects || [];
            const activeCount = redirects.filter((redirect) => redirect.status === 'active').length;
            const coveredCount = redirects.filter((redirect) => redirect.status === 'covered').length;
            const skippedCount = redirects.filter((redirect) => redirect.status === 'skipped').length;
            const remoteIngressCount = redirects.filter((redirect) => redirect.remoteIngress).length;
            const statsTiles = [
                {
                    id: 'totalRedirects',
                    title: 'Total Redirects',
                    type: 'number',
                    value: redirects.length,
                    icon: 'lucide:CornerDownRight',
                    description: 'Derived HTTP to HTTPS scopes',
                    color: '#3b82f6',
                },
                {
                    id: 'activeRedirects',
                    title: 'Active',
                    type: 'number',
                    value: activeCount,
                    icon: 'lucide:CircleCheck',
                    description: 'Generated at runtime',
                    color: '#22c55e',
                },
                {
                    id: 'coveredRedirects',
                    title: 'Covered',
                    type: 'number',
                    value: coveredCount,
                    icon: 'lucide:ShieldCheck',
                    description: 'Handled by explicit HTTP routes',
                    color: '#8b5cf6',
                },
                {
                    id: 'skippedRedirects',
                    title: 'Skipped',
                    type: 'number',
                    value: skippedCount,
                    icon: 'lucide:AlertTriangle',
                    description: 'Overlaps explicit HTTP routes',
                    color: skippedCount > 0 ? '#f59e0b' : '#6b7280',
                },
                {
                    id: 'remoteIngressRedirects',
                    title: 'Remote Ingress',
                    type: 'number',
                    value: remoteIngressCount,
                    icon: 'lucide:Globe',
                    description: 'Also exposed to edge nodes',
                    color: '#0ea5e9',
                },
            ];
            return html `
      <dees-heading level="3">Redirects</dees-heading>
      <div class="redirectsContainer">
        <dees-statsgrid .tiles=${statsTiles}></dees-statsgrid>

        ${redirects.length > 0
                ? html `
              <dees-table
                .heading1=${'HTTP to HTTPS Redirects'}
                .heading2=${'Runtime redirects derived from enabled HTTPS routes'}
                .data=${redirects}
                .showColumnFilters=${true}
                .displayFunction=${(redirect) => ({
                    Status: this.formatStatus(redirect.status),
                    'Domain Pattern': redirect.domainPattern,
                    Path: redirect.pathPattern || '*',
                    From: this.formatHttpTemplate(redirect, 'http'),
                    To: this.formatHttpTemplate(redirect, 'https'),
                    Code: redirect.statusCode,
                    Priority: redirect.priority,
                    'Source HTTPS Route': redirect.sourceRouteNames.join(', ') || '-',
                    'Covered By': redirect.coveredByRouteNames.join(', ') || '-',
                    Notes: this.formatNotes(redirect),
                })}
                .dataActions=${[
                    {
                        name: 'Refresh',
                        iconName: 'lucide:RefreshCw',
                        type: ['header'],
                        actionFunc: async () => this.refreshData(),
                    },
                ]}
              ></dees-table>
            `
                : html `
              <dees-table
                .heading1=${'HTTP to HTTPS Redirects'}
                .heading2=${'Runtime redirects derived from enabled HTTPS routes'}
                .data=${[]}
                .displayFunction=${() => ({})}
                .dataActions=${[
                    {
                        name: 'Refresh',
                        iconName: 'lucide:RefreshCw',
                        type: ['header'],
                        actionFunc: async () => this.refreshData(),
                    },
                ]}
              ></dees-table>
              <div class="empty-state">
                <p>No derived redirects</p>
                <p>Enable HTTPS routes with explicit domains to generate HTTP to HTTPS redirects.</p>
              </div>
            `}
      </div>
    `;
        }
        async refreshData() {
            await appstate.routeManagementStatePart.dispatchAction(appstate.fetchHttpRedirectsAction, null);
        }
        formatStatus(status) {
            return status.charAt(0).toUpperCase() + status.slice(1);
        }
        formatHttpTemplate(redirect, protocol) {
            return `${protocol}://${redirect.domainPattern}${redirect.pathPattern || '{path}'}`;
        }
        formatNotes(redirect) {
            const notes = redirect.notes ? [redirect.notes] : [];
            if (redirect.remoteIngress) {
                notes.push('Remote Ingress enabled');
            }
            return notes.join(' ') || 'Generated from HTTPS route';
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return OpsViewRedirects = _classThis;
})();
export { OpsViewRedirects };
//# sourceMappingURL=data:application/json;base64, 