import BaseComponent from "../BaseComponent";
import AppData from "../../Common/AppData";
import EventBus, { Events, Event } from "../../Events/EventBus";


class GeneralInfo {
    init() {
        if (!jQuery('.info-ui')[0]) {
            return;
        }
        if (jQuery('.info-ui').data('initializied') !== 'true') {
            new GeneralInfoHandler(jQuery('.info-ui'));
        }
    }
}

class GeneralInfoHandler extends BaseComponent {

    constructor(component_base_ui) {
        super(component_base_ui);
        this._handleEvents();
    }

    _handleEvents() {
        const _this = this;

        const soundRequiredPopup = new Event(
            Events.SOUND_LOGIN_REQUIRED_POPUP,
            (payload) => {
                this._showLoginRequired();
            }
        );
        EventBus.getInstance().registerEvent(soundRequiredPopup);

        const soundRequiredProPopup = new Event(
            Events.SOUND_PRO_REQUIRED_POPUP,
            (payload) => {
                this._showProRequired();
            }
        );
        EventBus.getInstance().registerEvent(soundRequiredProPopup);

        const bckRequiredPopup = new Event(
            Events.BCK_LOGIN_REQUIRED_POPUP,
            (payload) => {
                this._showBckLoginRequired();
            }
        );
        EventBus.getInstance().registerEvent(bckRequiredPopup);

        const bkgRequiredProPopup = new Event(
            Events.BCK_PRO_REQUIRED_POPUP,
            (payload) => {
                this._showBckProRequired();
            }
        );
        EventBus.getInstance().registerEvent(bkgRequiredProPopup);

        this._component_base_ui.find('.close-btn').on('click', function(event) {
            event.preventDefault();
            _this._hidePopup();
        });
        this._component_base_ui.find('.pupup-background-ui').on('click', function(event) {
            event.preventDefault();
            _this._hidePopup();
        });
    }

    _showLoginRequired() {
        const sound_signup_popup_title = AppData.getInstance().getLabel('sound_signup_popup_title');
        const sound_requires_login_info = AppData.getInstance().getLabel('sound_requires_login_info');

        this._component_base_ui.find('.popup-title').html(sound_signup_popup_title);
        this._component_base_ui.find('.popup-content-text').html(sound_requires_login_info);
        this._showPopup();
    }

    _showProRequired() {
        const upgrade_to_pro_popup_title = AppData.getInstance().getLabel('upgrade_to_pro_popup_title');
        const sound_requires_pro_info = AppData.getInstance().getLabel('sound_requires_pro_info');

        this._component_base_ui.find('.popup-title').html(upgrade_to_pro_popup_title);
        this._component_base_ui.find('.popup-content-text').html(sound_requires_pro_info);
        this._showPopup();
    }

    _showBckLoginRequired() {
        const bkg_signup_popup_title = AppData.getInstance().getLabel('bkg_signup_popup_title');
        const bkg_requires_login_info = AppData.getInstance().getLabel('bkg_requires_login_info');

        this._component_base_ui.find('.popup-title').html(bkg_signup_popup_title);
        this._component_base_ui.find('.popup-content-text').html(bkg_requires_login_info);
        this._showPopup();
    }

    _showBckProRequired() {
        const bkg_upgrade_to_pro_popup_title = AppData.getInstance().getLabel('bkg_upgrade_to_pro_popup_title');
        const bkg_requires_pro_info = AppData.getInstance().getLabel('bkg_requires_pro_info');

        this._component_base_ui.find('.popup-title').html(bkg_upgrade_to_pro_popup_title);
        this._component_base_ui.find('.popup-content-text').html(bkg_requires_pro_info);
        this._showPopup();
    }

    _showPopup() {
        this.checkRecaptcha();
        this.show();
        this.fadeIn();
    }

    _hidePopup() {
        this.hide();
        this.fadeOut();
    }

}

export default GeneralInfo;
