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 shared from './shared/index.js';
import * as plugins from '../plugins.js';
import * as appstate from '../appstate.js';
import { DeesElement, customElement, html, state, css, cssManager, } from '@design.estate/dees-element';
let ObViewDomains = (() => {
    let _classDecorators = [customElement('ob-view-domains')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _networkState_decorators;
    let _networkState_initializers = [];
    let _networkState_extraInitializers = [];
    var ObViewDomains = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _networkState_decorators = [state()];
            __esDecorate(this, null, _networkState_decorators, { kind: "accessor", name: "networkState", static: false, private: false, access: { has: obj => "networkState" in obj, get: obj => obj.networkState, set: (obj, value) => { obj.networkState = value; } }, metadata: _metadata }, _networkState_initializers, _networkState_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            ObViewDomains = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #networkState_accessor_storage = __runInitializers(this, _networkState_initializers, {
            targets: [],
            stats: null,
            statsResource: { phase: 'idle', error: null, lastSuccessAt: null },
            trafficStats: null,
            dnsRecords: [],
            domains: [],
            gatewayDomains: [],
            gatewayDnsRecords: [],
            certificates: [],
        });
        get networkState() { return this.#networkState_accessor_storage; }
        set networkState(value) { this.#networkState_accessor_storage = value; }
        constructor() {
            super();
            __runInitializers(this, _networkState_extraInitializers);
            const networkSub = appstate.networkStatePart.select((s) => s).subscribe((newState) => {
                this.networkState = newState;
            });
            this.rxSubscriptions.push(networkSub);
        }
        static styles = [
            cssManager.defaultStyles,
            shared.viewHostCss,
            css `
      .domain { font-weight: 600; }
      .muted { color: var(--ci-shade-5, #71717a); font-size: 13px; }
      .badge { border-radius: 999px; padding: 3px 8px; background: var(--ci-shade-1, #f4f4f5); font-size: 12px; }
      .empty { padding: 32px; text-align: center; color: var(--ci-shade-5, #71717a); }
    `,
        ];
        async connectedCallback() {
            super.connectedCallback();
            await appstate.dispatchProtectedAction(appstate.fetchGatewayDomainsAction, null);
        }
        render() {
            const domains = this.networkState.gatewayDomains;
            return html `
      <ob-sectionheading>Domains</ob-sectionheading>
      <div class="muted" style="margin-bottom: 16px;">
        Domains are managed in dcrouter. Onebox shows gateway visibility for deployed services.
      </div>
      ${domains.length
                ? html `
            <dees-table
              .heading1=${'Gateway Domains'}
              .heading2=${'Domains imported from dcrouter gateway visibility'}
              .data=${domains}
              .showColumnFilters=${true}
              .displayFunction=${(domain) => ({
                    Domain: html `
                  <div>
                    <div class="domain">${domain.name}</div>
                    ${domain.providerId ? html `<div class="muted">Provider: ${domain.providerId}</div>` : ''}
                  </div>
                `,
                    Source: html `<span class="badge">${domain.source || 'dcrouter'}</span>`,
                    Authoritative: domain.authoritative ? 'Yes' : 'No',
                    Services: domain.serviceCount || 0,
                })}
              .dataActions=${[
                    {
                        name: 'Refresh',
                        iconName: 'lucide:rotateCw',
                        type: ['header'],
                        actionFunc: async () => {
                            await appstate.dispatchProtectedAction(appstate.fetchGatewayDomainsAction, null);
                        },
                    },
                    {
                        name: 'Manage in dcrouter',
                        iconName: 'lucide:externalLink',
                        type: ['inRow', 'contextmenu'],
                        actionRelevancyCheckFunc: (domain) => !!domain.manageUrl,
                        actionFunc: async (actionData) => {
                            if (actionData.item.manageUrl) {
                                globalThis.open(actionData.item.manageUrl, '_blank', 'noopener');
                            }
                        },
                    },
                ]}
            ></dees-table>
          `
                : html `<div class="empty">No gateway domains found. Configure a dcrouter gateway in Settings.</div>`}
    `;
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return ObViewDomains = _classThis;
})();
export { ObViewDomains };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2Itdmlldy1kb21haW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vdHNfd2ViL2VsZW1lbnRzL29iLXZpZXctZG9tYWlucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsT0FBTyxLQUFLLE1BQU0sTUFBTSxt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