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 plugins from '../plugins.js';
import * as shared from './shared/index.js';
import * as appstate from '../appstate.js';
import { DeesElement, customElement, html, state, css, cssManager, } from '@design.estate/dees-element';
let ObViewTokens = (() => {
    let _classDecorators = [customElement('ob-view-tokens')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _registriesState_decorators;
    let _registriesState_initializers = [];
    let _registriesState_extraInitializers = [];
    var ObViewTokens = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _registriesState_decorators = [state()];
            __esDecorate(this, null, _registriesState_decorators, { kind: "accessor", name: "registriesState", static: false, private: false, access: { has: obj => "registriesState" in obj, get: obj => obj.registriesState, set: (obj, value) => { obj.registriesState = value; } }, metadata: _metadata }, _registriesState_initializers, _registriesState_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            ObViewTokens = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #registriesState_accessor_storage = __runInitializers(this, _registriesState_initializers, {
            tokens: [],
            registryStatus: null,
        });
        get registriesState() { return this.#registriesState_accessor_storage; }
        set registriesState(value) { this.#registriesState_accessor_storage = value; }
        constructor() {
            super();
            __runInitializers(this, _registriesState_extraInitializers);
            const registriesSub = appstate.registriesStatePart
                .select((s) => s)
                .subscribe((newState) => {
                this.registriesState = newState;
            });
            this.rxSubscriptions.push(registriesSub);
        }
        static styles = [
            cssManager.defaultStyles,
            shared.viewHostCss,
            css ``,
        ];
        async connectedCallback() {
            super.connectedCallback();
            await appstate.dispatchProtectedAction(appstate.fetchRegistryTokensAction, null);
        }
        render() {
            const globalTokens = this.registriesState.tokens.filter((t) => t.type === 'global');
            const ciTokens = this.registriesState.tokens.filter((t) => t.type === 'ci');
            return html `
      <ob-sectionheading>Tokens</ob-sectionheading>
      <sz-tokens-view
        .globalTokens=${globalTokens.map((t) => ({
                id: String(t.id),
                name: t.name,
                type: 'global',
                createdAt: new Date(t.createdAt).toISOString(),
                lastUsed: t.lastUsedAt ? new Date(t.lastUsedAt).toISOString() : undefined,
            }))}
        .ciTokens=${ciTokens.map((t) => ({
                id: String(t.id),
                name: t.name,
                type: 'ci',
                service: Array.isArray(t.scope) ? t.scope.join(', ') : undefined,
                createdAt: new Date(t.createdAt).toISOString(),
                lastUsed: t.lastUsedAt ? new Date(t.lastUsedAt).toISOString() : undefined,
            }))}
        @create=${(e) => {
                appstate.dispatchProtectedAction(appstate.createRegistryTokenAction, {
                    token: {
                        name: `new-${e.detail.type}-token`,
                        type: e.detail.type,
                        scope: 'all',
                        expiresIn: 'never',
                    },
                });
            }}
        @delete=${(e) => {
                appstate.dispatchProtectedAction(appstate.deleteRegistryTokenAction, {
                    tokenId: Number(e.detail.id || e.detail.tokenId),
                });
            }}
      ></sz-tokens-view>
    `;
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return ObViewTokens = _classThis;
})();
export { ObViewTokens };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2Itdmlldy10b2tlbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90c193ZWIvZWxlbWVudHMvb2Itdmlldy10b2tlbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sZUFBZSxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxNQUFNLE1BQU0sbUJBQW1CLENBQUM7QUFDNUMsT0FBTyxLQUFLLFFBQVEsTUFBTSxnQkFBZ0IsQ0FBQztBQUMzQyxPQUFPLEVBQ0wsV0FBVyxFQUNYLGFBQWEsRUFDYixJQUFJLEVBQ0osS0FBSyxFQUNMLEdBQUcsRUFDSCxVQUFVLEdBRVgsTUFBTSw2QkFBNkIsQ0FBQztJQUd4QixZQUFZOzRCQUR4QixhQUFhLENBQUMsZ0JBQWdCLENBQUM7Ozs7c0JBQ0UsV0FBVzs7Ozs0QkFBbkIsU0FBUSxXQUFXOzs7OzJDQUMxQyxL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