package com.axis.innovators.box.register;

import com.axis.innovators.box.AxisInnovatorsBox;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 注册主题
 * @author tzdwindows 7
 */
public class RegistrationTopic {
    private final Logger logger = LogManager.getLogger(RegistrationTopic.class);
    private final List<String> topicsClasses =  new ArrayList<>();
    private final List<LookAndFeel> topicsClassesLookAndFeel =  new ArrayList<>();
    private final List<String> topicsName =  new ArrayList<>();
    private final List<String> registeredNameList = new ArrayList<>();
    private final List<Icon> iconList = new ArrayList<>();
    private final List<String> tipList = new ArrayList<>();
    private final AxisInnovatorsBox axisInnovatorsBox;
    private String loadTopics = "";

    public RegistrationTopic(AxisInnovatorsBox axisInnovatorsBox) {
        this.axisInnovatorsBox = axisInnovatorsBox;
    }

    /**
     * 注册主题
     * @param topicClass 主题类
     * @param topicName 主题名
     * @param icon 显示图标
     * @param registeredName 注册名
     */
    public void addTopic(String topicClass, String topicName, String tip ,Icon icon, String registeredName) {
        if (!axisInnovatorsBox.isWindow()) {
            if (registeredNameList.contains(registeredName)) {
                throw new RegistrationError(registeredName + " duplicate registered names");
            }
            topicsClasses.add(topicClass);
            topicsClassesLookAndFeel.add(null);
            topicsName.add(topicName);
            tipList.add(tip);
            iconList.add(icon);
            registeredNameList.add(registeredName);
        } else {
            logger.warn("Wrong time to add topics");
        }
    }

    /**
     * 注册主题
     * @param topicClass 主题类
     * @param topicName 主题名
     * @param icon 显示图标
     * @param registeredName 注册名
     */
    public void addTopic(LookAndFeel topicClass, String topicName, String tip ,Icon icon, String registeredName) {
        if (!axisInnovatorsBox.isWindow()) {
            if (registeredNameList.contains(registeredName)) {
                throw new RegistrationError(registeredName + " duplicate registered names");
            }
            topicsClasses.add(null);
            topicsClassesLookAndFeel.add(topicClass);
            topicsName.add(topicName);
            tipList.add(tip);
            iconList.add(icon);
            registeredNameList.add(registeredName);
        } else {
            logger.warn("Wrong time to add topics");
        }
    }

    /**
     * 判断是否已经加载
     * @return 是否已经加载
     */
    public boolean isLoading(String loading) {
        if (loadTopics.isEmpty()) {
            return false;
        }
        return Objects.equals(loading, loadTopics);
    }

    /**
     * 设置是否加载
     * @param loading 是否加载
     */
    public void setLoading(String loading) {
        loadTopics = loading;
    }

    /**
     * 判断是否为空
     * @return 是否为空
     */
    public boolean isEmpty() {
        return registeredNameList.isEmpty();
    }

    /**
     * 获取主题类
     * @return 主题类
     */
    public List<String> getTopicsClasses() {
        return topicsClasses;
    }

    public AxisInnovatorsBox getAxisInnovatorsBox() {
        return axisInnovatorsBox;
    }

    public List<LookAndFeel> getTopicsClassesLookAndFeel() {
        return topicsClassesLookAndFeel;
    }

    public List<Icon> getIconList() {
        return iconList;
    }

    public List<String> getRegisteredNameList() {
        return registeredNameList;
    }

    public List<String> getTipList() {
        return tipList;
    }

    public List<String> getTopicsName() {
        return topicsName;
    }
}
