import EventListenerApplication from "./application/EventListenerApplication";
import RuleService from "./domain/rules/RuleService";
import StyleApplication from "./application/StyleApplication";
import ChromeBackgroundMessageService from "./_infra/ChromeBackgroundMessageService";
import ChromeMessageListener from "./_infra/ChromeMessageListener";

console.log("AIFEX script is running.")

const ruleService = new RuleService();
const backgroundMessageService = new ChromeBackgroundMessageService();

backgroundMessageService.getState().then(state => {
    ruleService.loadRules(state.webSite);
    const styleApplication = new StyleApplication(state, ruleService, backgroundMessageService);
    styleApplication.init();
    
    const eventListener = new EventListenerApplication(ruleService, backgroundMessageService);
    eventListener.listen();

    const backgroundMessageListener = new ChromeMessageListener(styleApplication, eventListener);
    backgroundMessageListener.listenBackground();
    
    
    eventListener.addNewActionCallback(() => styleApplication.onActionPushed);
});
