import '../components/devvit-blocks-web-view.js';
import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
import { nothing } from 'lit';
import { defaultClasses, defaultStyles, onWebViewAction } from '../attributes.js';
import { blockTypeToString } from '../block-type.js';
import { classMap } from './util.js';
export function renderWebViewBlock(block, ctx) {
    const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
    if (!block.config?.webviewConfig) {
        console.error('Invalid block: WebView missing WebViewConfig');
        return nothing;
    }
    const { id } = block;
    const { url, state } = block.config.webviewConfig;
    const classes = {
        ...defaultClasses(block, ctx),
    };
    const styles = {
        ...defaultStyles(block, ctx),
    };
    const onWebView = onWebViewAction(block, ctx);
    const resolvedURL = ctx.resolveWebViewUrl?.(url);
    return html `<devvit-blocks-web-view
    id="${ifDefined(id)}"
    src="${resolvedURL}"
    class="${classMap(classes)}"
    style="${styleMap(styles)}"
    ?dev-mode="${ctx.disableAssetSandbox}"
    .state="${state}"
    data-block-type="${blockTypeToString(block.type)}"
    @devvit-web-view-message="${onWebView}"
  ></devvit-blocks-web-view>`;
}
//# sourceMappingURL=renderWebViewBlock.js.map