var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _DevvitBlocksRenderer_colorSchemeMediaQuery, _DevvitBlocksRenderer_onColorSchemeChange, _DevvitBlocksRenderer_baseRenderContext;
import { BlockStackDirection, BlockType } from '@devvit/protos';
import { localized, msg } from '@lit/localize';
import { emptyState } from '@reddit/faceplate-ui/templates/empty-state.js';
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { styles } from '../../styles.js';
import { renderBlocks } from '../templates/index.js';
let DevvitBlocksRenderer = class DevvitBlocksRenderer extends LitElement {
    constructor() {
        super(...arguments);
        _DevvitBlocksRenderer_colorSchemeMediaQuery.set(this, window.matchMedia('(prefers-color-scheme: dark)'));
        _DevvitBlocksRenderer_onColorSchemeChange.set(this, () => this.requestUpdate());
        _DevvitBlocksRenderer_baseRenderContext.set(this, () => ({
            stackDirection: BlockStackDirection.UNRECOGNIZED,
        }));
    }
    static get styles() {
        return [styles];
    }
    connectedCallback() {
        super.connectedCallback();
        __classPrivateFieldGet(this, _DevvitBlocksRenderer_colorSchemeMediaQuery, "f")?.addEventListener('change', __classPrivateFieldGet(this, _DevvitBlocksRenderer_onColorSchemeChange, "f"));
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        __classPrivateFieldGet(this, _DevvitBlocksRenderer_colorSchemeMediaQuery, "f")?.removeEventListener('change', __classPrivateFieldGet(this, _DevvitBlocksRenderer_onColorSchemeChange, "f"));
    }
    render() {
        if (this.block && this.block.type === BlockType.BLOCK_ROOT) {
            const context = { ...__classPrivateFieldGet(this, _DevvitBlocksRenderer_baseRenderContext, "f").call(this), ...(this.renderContext?.() ?? {}) };
            return html `<div class="${ifDefined(this.class)}">${renderBlocks(this.block, context)}</div>`;
        }
        return html `${emptyState({
            creative: html `<slot name="empty-state-image"></slot>`,
            title: msg('Whoops!', { desc: 'Header for message to display when rendering fails' }),
            description: msg('Something went wrong while attempting to display this content.', {
                desc: 'Message for users to display when rendering fails',
            }),
        })}`;
    }
};
_DevvitBlocksRenderer_colorSchemeMediaQuery = new WeakMap();
_DevvitBlocksRenderer_onColorSchemeChange = new WeakMap();
_DevvitBlocksRenderer_baseRenderContext = new WeakMap();
__decorate([
    property({ attribute: false }),
    __metadata("design:type", Object)
], DevvitBlocksRenderer.prototype, "block", void 0);
__decorate([
    property({ attribute: false }),
    __metadata("design:type", Object)
], DevvitBlocksRenderer.prototype, "renderContext", void 0);
__decorate([
    property(),
    __metadata("design:type", Object)
], DevvitBlocksRenderer.prototype, "class", void 0);
DevvitBlocksRenderer = __decorate([
    localized(),
    customElement('devvit-blocks-renderer')
], DevvitBlocksRenderer);
export { DevvitBlocksRenderer };
//# sourceMappingURL=devvit-blocks-renderer.js.map