import e1 from "./g/n";
import m from "./g/h";
import x3 from "./q";
export default class AnalyticsManager {
    static t() {
        if (!AnalyticsManager.m2) {
            AnalyticsManager.m2 = new AnalyticsManager();
        }
        return AnalyticsManager.m2;
    }
    constructor() {
        this.mainInstance = null;
        this.n2 = new Map();
        this.mainInstance = null;
        this.j1 = new e1();
    }
    initialize(config, context) {
        let instance = this.n2.get(config.identifier);
        if (instance) {
            if (instance.app_id !== config.app_id || instance.sub_app_id !== config.sub_app_id) {
                m.e('You have already initialized an instance with a different app id and sub app id.');
            }
            if (config.setMainInstance) {
                this.mainInstance = instance;
            }
            return instance;
        }
        m.i(`initialize with identifier:${config.identifier}, app_id:${config.app_id}, sub_app_id:${config.sub_app_id}`);
        instance = new x3(config, context);
        this.j1.write(() => {
            this.n2.set(config.identifier, instance);
            if (config.setMainInstance) {
                this.mainInstance = instance;
            }
        });
        return instance;
    }
    getInstance(identifier) {
        let instance;
        this.j1.read(() => {
            instance = this.n2.get(identifier);
        });
        if (!instance) {
            m.e(`No such instance: ${identifier}`);
            return null;
        }
        return instance;
    }
    getAllInstance() {
        let a4 = [];
        this.j1.read(() => {
            a4 = Array.from(this.n2.values());
        });
        return a4;
    }
    removeInstance(identifier) {
        this.j1.write(() => {
            if (this.n2.get(identifier) === this.mainInstance) {
                this.mainInstance = null;
            }
            this.n2.delete(identifier);
        });
    }
    setMainInstance(identifier) {
        let instance;
        this.j1.read(() => {
            instance = this.n2.get(identifier);
        });
        if (instance) {
            this.mainInstance = instance;
        }
    }
    u() {
        return this.mainInstance;
    }
}
AnalyticsManager.m2 = null;
