import { r as registerInstance, h, g as getElement } from './chunk-82a2445c.js';
import './chunk-d7ac2f15.js';
import { T as TranslateService } from './chunk-18ca1c85.js';

class TranslateComponent {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.paramsJson = '{}';
        this.transform = 'none';
        this.translate = TranslateService.instance;
    }
    componentDidLoad() {
        this.postRender();
    }
    componentDidUpdate() {
        this.postRender();
    }
    async postRender() {
        let str = this.el.querySelector('span').innerText.trim();
        // beware: string property overrides slot content
        if (this.string && this.string !== '') {
            str = this.string;
        }
        if (this.language && this.language !== this.translate.language) {
            if (this.translationsLocation) {
                this.translate.translationsLocation = this.translationsLocation;
            }
            await this.translate.use(this.language);
        }
        this.translation = this.translate.get(str);
        if (this.params) {
            this.translation = this.translate.get(str, this.params);
        }
        if (this.paramsJson !== '{}') {
            let args = [str];
            let params = JSON.parse(this.paramsJson);
            params.forEach((v) => {
                args.push(v);
            });
            this.translation = this.translate.get.apply(this.translate, args);
        }
        if (this.transform) {
            this.transformTranslation(this.transform);
        }
        this.el.querySelector('span').innerText = this.translation;
    }
    async get(string) {
        return this.translate.get(string);
    }
    async set(string, language, transform) {
        this.translation = await this.translate.get(string);
        this.postRender();
    }
    async setTranslateService(instance) {
        this.translate = instance;
        this.postRender();
    }
    async update() {
        this.postRender();
    }
    transformTranslation(type) {
        if (type === 'lowercase') {
            this.translation = this.translation.toLowerCase();
        }
        if (type === 'lowercaseFirst') {
            this.translation = this.translation.charAt(0).toLowerCase() + this.translation.slice(1);
        }
        if (type === 'uppercase') {
            this.translation = this.translation.toUpperCase();
        }
        if (type === 'uppercaseFirst') {
            this.translation = this.translation.charAt(0).toUpperCase() + this.translation.slice(1);
        }
    }
    render() {
        return (h("span", null, h("slot", null)));
    }
    get el() { return getElement(this); }
}

export { TranslateComponent as ema_translate };
