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 { appRouter } from '../router.js';
import { DeesElement, customElement, html, state, css, cssManager, } from '@design.estate/dees-element';
let ObViewDnsRecords = (() => {
    let _classDecorators = [customElement('ob-view-dns-records')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _networkState_decorators;
    let _networkState_initializers = [];
    let _networkState_extraInitializers = [];
    var ObViewDnsRecords = 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);
            ObViewDnsRecords = _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 `
      .name { font-weight: 600; }
      .value { font-family: monospace; color: var(--ci-shade-5, #71717a); overflow-wrap: anywhere; }
      .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; }
      .missing { color: #dc2626; }
      .empty { padding: 32px; text-align: center; color: var(--ci-shade-5, #71717a); }
    `,
        ];
        async connectedCallback() {
            super.connectedCallback();
            await appstate.dispatchProtectedAction(appstate.fetchGatewayDnsRecordsAction, null);
        }
        render() {
            const records = this.networkState.gatewayDnsRecords;
            return html `
      <ob-sectionheading>DNS Records</ob-sectionheading>
      ${records.length
                ? html `
            <dees-table
              .heading1=${'Gateway DNS Records'}
              .heading2=${'DNS records published through dcrouter for Onebox services'}
              .data=${records}
              .showColumnFilters=${true}
              .displayFunction=${(record) => ({
                    Name: html `
                  <div>
                    <div class="name">${record.name}</div>
                    ${record.domainName ? html `<div class="muted">${record.domainName}</div>` : ''}
                  </div>
                `,
                    Type: html `<span class="badge">${record.type}</span>`,
                    Value: html `<span class="value">${record.value || '-'}</span>`,
                    Status: html `<span class=${record.status === 'missing' ? 'missing' : ''}>${record.status}</span>`,
                    Service: record.serviceName || record.appId || '-',
                })}
              .dataActions=${[
                    {
                        name: 'Refresh',
                        iconName: 'lucide:rotateCw',
                        type: ['header'],
                        actionFunc: async () => {
                            await appstate.dispatchProtectedAction(appstate.fetchGatewayDnsRecordsAction, null);
                        },
                    },
                    {
                        name: 'View service',
                        iconName: 'lucide:boxes',
                        type: ['inRow', 'contextmenu'],
                        actionFunc: async () => {
                            appRouter.navigateToView('services');
                        },
                    },
                    {
                        name: 'Manage in dcrouter',
                        iconName: 'lucide:externalLink',
                        type: ['inRow', 'contextmenu'],
                        actionRelevancyCheckFunc: (record) => !!record.manageUrl,
                        actionFunc: async (actionData) => {
                            if (actionData.item.manageUrl) {
                                globalThis.open(actionData.item.manageUrl, '_blank', 'noopener');
                            }
                        },
                    },
                ]}
            ></dees-table>
          `
                : html `<div class="empty">No gateway DNS records found. Configure a dcrouter gateway in Settings.</div>`}
    `;
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return ObViewDnsRecords = _classThis;
})();
export { ObViewDnsRecords };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2Itdmlldy1kbnMtcmVjb3Jkcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3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