/**
 * Map a Pencil node's properties to a CSS string.
 * Each property becomes one CSS declaration (property: value).
 */
export function mapNodeToCSS(node) {
    const lines = [];
    // Fill → background or color
    if (node.fill !== undefined) {
        if (node.type === 'text') {
            lines.push(`color: ${node.fill}`);
        }
        else {
            lines.push(`background: ${node.fill}`);
        }
    }
    // Font properties (text nodes)
    if (node.fontSize !== undefined)
        lines.push(`font-size: ${node.fontSize}px`);
    if (node.fontWeight !== undefined)
        lines.push(`font-weight: ${node.fontWeight}`);
    if (node.fontFamily !== undefined)
        lines.push(`font-family: ${node.fontFamily}`);
    if (node.lineHeight !== undefined)
        lines.push(`line-height: ${node.lineHeight}`);
    if (node.letterSpacing !== undefined)
        lines.push(`letter-spacing: ${node.letterSpacing}px`);
    // Padding
    if (node.padding !== undefined) {
        if (typeof node.padding === 'number') {
            lines.push(`padding: ${node.padding}px`);
        }
        else {
            lines.push(`padding: ${node.padding.map(v => `${v}px`).join(' ')}`);
        }
    }
    // Layout
    if (node.layout === 'vertical') {
        lines.push('display: flex');
        lines.push('flex-direction: column');
    }
    else if (node.layout === 'horizontal') {
        lines.push('display: flex');
        lines.push('flex-direction: row');
    }
    if (node.justifyContent !== undefined)
        lines.push(`justify-content: ${node.justifyContent}`);
    if (node.alignItems !== undefined)
        lines.push(`align-items: ${node.alignItems}`);
    if (node.gap !== undefined)
        lines.push(`gap: ${node.gap}px`);
    // Dimensions
    if (node.width !== undefined) {
        if (node.width === 'fill_container') {
            lines.push('width: 100%');
        }
        else if (node.width === 'fit_content') {
            lines.push('width: fit-content');
        }
        else if (typeof node.width === 'number') {
            lines.push(`width: ${node.width}px`);
        }
    }
    if (node.height !== undefined) {
        if (node.height === 'fill_container') {
            lines.push('flex-grow: 1');
        }
        else if (node.height === 'fit_content') {
            lines.push('height: fit-content');
        }
        else if (typeof node.height === 'number') {
            lines.push(`height: ${node.height}px`);
        }
    }
    // Corner radius
    if (node.cornerRadius !== undefined) {
        if (typeof node.cornerRadius === 'number') {
            lines.push(`border-radius: ${node.cornerRadius}px`);
        }
        else {
            lines.push(`border-radius: ${node.cornerRadius.map(v => `${v}px`).join(' ')}`);
        }
    }
    // Clip
    if (node.clip === true)
        lines.push('overflow: hidden');
    // Opacity
    if (node.opacity !== undefined)
        lines.push(`opacity: ${node.opacity}`);
    // Stroke → border
    if (node.stroke) {
        lines.push(`border: ${node.stroke.thickness}px solid ${node.stroke.fill}`);
    }
    // Effects
    if (node.effect?.shadow) {
        const s = node.effect.shadow;
        const spread = s.spread ?? 0;
        lines.push(`box-shadow: ${s.offsetX}px ${s.offsetY}px ${s.blur}px ${spread}px ${s.color}`);
    }
    if (node.effect?.blur !== undefined) {
        lines.push(`filter: blur(${node.effect.blur}px)`);
    }
    if (node.effect?.background_blur !== undefined) {
        lines.push(`backdrop-filter: blur(${node.effect.background_blur}px)`);
    }
    return lines.join(';\n');
}
