import { BlockRadius, BlockStackDirection, BlockType } from '@devvit/protos';
import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
import { nothing } from 'lit';
import { growWrapperSizingStyle } from '../attributes.js';
import { renderAvatarBlock } from './renderAvatarBlock.js';
import { renderButtonBlock } from './renderButtonBlock.js';
import { renderIconBlock } from './renderIconBlock.js';
import { renderImageBlock } from './renderImageBlock.js';
import { renderSpacerBlock } from './renderSpacerBlock.js';
import { renderStackBlock } from './renderStackBlock.js';
import { renderTextBlock } from './renderTextBlock.js';
import { renderWebViewBlock } from './renderWebViewBlock.js';
export const DEFAULT_ROOT_HEIGHT = 320;
export function renderBlocks(block, context = {}) {
    if (block.type !== BlockType.BLOCK_ROOT) {
        console.error('Invalid root block');
        return nothing;
    }
    const height = `${block.config?.rootConfig?.height || DEFAULT_ROOT_HEIGHT}px`;
    return renderStackBlock({
        type: BlockType.BLOCK_STACK,
        config: {
            stackConfig: {
                direction: BlockStackDirection.STACK_VERTICAL,
                children: block.config?.rootConfig?.children ?? [],
                cornerRadius: BlockRadius.RADIUS_SMALL,
            },
        },
        actions: [],
    }, {
        ...context,
        stackDirection: BlockStackDirection.UNRECOGNIZED,
    }, renderBlock, {
        styles: {
            height,
            minHeight: height,
            maxHeight: height,
            overflow: 'hidden',
        },
    });
}
export function renderBlock(block, ctx) {
    const { html, styleMap } = getTemplateRenderingStrategy();
    let render = nothing;
    switch (block.type) {
        case BlockType.BLOCK_STACK:
            render = renderStackBlock(block, ctx, renderBlock);
            break;
        case BlockType.BLOCK_SPACER:
            render = renderSpacerBlock(block, ctx);
            break;
        case BlockType.BLOCK_TEXT:
            render = renderTextBlock(block, ctx);
            break;
        case BlockType.BLOCK_IMAGE:
            render = renderImageBlock(block, ctx);
            break;
        case BlockType.BLOCK_ICON:
            render = renderIconBlock(block, ctx);
            break;
        case BlockType.BLOCK_BUTTON:
            render = renderButtonBlock(block, ctx);
            break;
        case BlockType.BLOCK_WEBVIEW:
            render = renderWebViewBlock(block, ctx);
            break;
        case BlockType.UNRECOGNIZED:
            return nothing;
    }
    if (ctx.experimental) {
        // eslint-disable-next-line sonarjs/no-small-switch
        switch (block.type) {
            case BlockType.BLOCK_AVATAR:
                render = renderAvatarBlock(block, ctx);
                break;
        }
    }
    /* eslint-disable lit/attribute-value-entities */
    if (block.size?.grow === true || block.sizes?.grow === true) {
        const styles = growWrapperSizingStyle(block);
        return html `<div
      class="grid grid-cols-1 grow shrink pointer-events-none [&>:not(.pointer-events-none)]:pointer-events-auto"
      style="${styleMap(styles)}"
    >
      ${render === nothing ? '' : render}
    </div>`;
    }
    else {
        return render;
    }
    /* eslint-enable lit/attribute-value-entities */
}
//# sourceMappingURL=renderBlock.js.map