import { BlockTextSize, BlockTextStyle, BlockTextWeight } from '@devvit/protos';
import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
import { nothing } from 'lit';
import { defaultClasses, defaultStyles, onClickAction, setTextOutline, textAlignClass, textColorClass, textColorStyle, textOverflowClass, textSelectClass, textSizeClass, textWeightClass, } from '../attributes.js';
import { resolveStyleColor } from './color.js';
import { classMap } from './util.js';
export function renderTextBlock(block, ctx) {
    const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
    if (!block.config?.textConfig) {
        console.error('Invalid block: Text missing TextConfig');
        return nothing;
    }
    const { text, color, colors, size, alignment, weight, style, outline, selectable } = block.config.textConfig;
    let textColor;
    let textSize;
    let textWeight;
    switch (style) {
        case BlockTextStyle.TEXT_STYLE_METADATA:
            textColor = 'neutral-content-weak';
            textSize = BlockTextSize.TEXT_SIZE_SMALL;
            textWeight = BlockTextWeight.TEXT_WEIGHT_REGULAR;
            break;
        case BlockTextStyle.TEXT_STYLE_HEADING:
            textColor = 'neutral-content-strong';
            textSize = BlockTextSize.TEXT_SIZE_LARGE;
            textWeight = BlockTextWeight.TEXT_WEIGHT_BOLD;
            break;
        case BlockTextStyle.TEXT_STYLE_BODY:
        case undefined:
        default:
            textColor = 'neutral-content';
            textSize = BlockTextSize.TEXT_SIZE_MEDIUM;
            textWeight = BlockTextWeight.TEXT_WEIGHT_REGULAR;
            break;
    }
    textSize = size ?? textSize;
    textWeight = weight ?? textWeight;
    const classes = {
        ...defaultClasses(block, ctx),
        ...textColorClass(),
        ...textSizeClass(textSize),
        ...textAlignClass(alignment),
        ...textWeightClass(textWeight),
        ...textSelectClass(selectable),
        ...textOverflowClass(block.config.textConfig),
    };
    const styles = {
        ...defaultStyles(block, ctx),
        ...textColorStyle(colors, color ?? textColor),
    };
    const onClick = onClickAction(block, ctx);
    return html `<span
    class="${classMap(classes)}"
    style="${styleMap(styles)}"
    @click="${ifDefined(onClick)}"
    data-debug-block-type="text"
    ${resolveStyleColor(styles, 'color')}
    ${setTextOutline(outline)}
    >${text}</span
  >`;
}
//# sourceMappingURL=renderTextBlock.js.map