package com.atlassian.stash.internal.plugin;

import com.atlassian.bitbucket.i18n.I18nService;
import com.atlassian.plugin.hostcontainer.HostContainer;
import com.atlassian.plugin.module.ModuleFactory;
import com.atlassian.plugin.web.WebInterfaceManager;
import com.atlassian.plugin.web.descriptors.DefaultWebPanelModuleDescriptor;

/**
 * A subclass which ensures labels and tooltips use the label element text as the fallback message
 */
public class StashWebPanelModuleDescriptor extends DefaultWebPanelModuleDescriptor {
    private final I18nService i18nService;

    public StashWebPanelModuleDescriptor(HostContainer hostContainer, ModuleFactory moduleClassFactory, WebInterfaceManager webInterfaceManager, I18nService i18nService) {
        super(hostContainer, moduleClassFactory, webInterfaceManager);
        this.i18nService = i18nService;
    }

    @Override
    public void enabled() {
        super.enabled();

        if (element.element("label") != null) {
            label = new StashWebLabel(element.element("label"), webInterfaceManager.getWebFragmentHelper(), contextProvider, this, i18nService);
        }

        if (element.element("tooltip") != null) {
            tooltip = new StashWebLabel(element.element("tooltip"), webInterfaceManager.getWebFragmentHelper(), contextProvider, this, i18nService);
        }

        webInterfaceManager.refresh();
    }
}
