import { html } from "lit";
import { Directive, PartType, directive } from "lit/directive.js";
class LocalizedStringDirective extends Directive {
    render(props) {
        const { i18n, key, params, count } = props;
        const getPlaceholderForParamKey = (paramKey)=>`${this.delimitingCharacter}${this.placeholderPrefixCharacter}${paramKey}${this.delimitingCharacter}`;
        const getParamFromPlaceholder = (placeholder)=>params[placeholder.slice(1)];
        const placeholdersMap = Object.fromEntries(Object.keys(params).map((paramKey)=>[
                paramKey,
                getPlaceholderForParamKey(paramKey)
            ]));
        const localizedStringWithPlaceholders = i18n.t(key, {
            interpolation: {
                escapeValue: false
            },
            count: count,
            ...placeholdersMap
        });
        return html`${localizedStringWithPlaceholders.split(this.delimitingCharacter).map((text)=>text.startsWith(this.placeholderPrefixCharacter) ? getParamFromPlaceholder(text) : text)}`;
    }
    constructor(partInfo){
        super(partInfo), this.delimitingCharacter = '\u001d', this.placeholderPrefixCharacter = '\u001a';
        if (partInfo.type !== PartType.CHILD) throw new Error('localizedString can only be used in child bindings');
    }
}
const localizedString = directive(LocalizedStringDirective);
export { localizedString };
