/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pw.yumc.Residence.text.help;

import java.util.Arrays;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

import pw.yumc.Residence.ResidenceMain;

/**
 *
 * @author Administrator
 */
public class InformationPager {

    public static int linesPerPage = 7;

    public static int getLinesPerPage() {
        return linesPerPage;
    }

    public static void printInfo(final ResidenceMain plugin, final CommandSender sender, final String title, final List<String> lines, final int page) {
        final int perPage = 6;
        final int start = (page - 1) * perPage;
        final int end = start + perPage;
        int pagecount = (int) Math.ceil((double) lines.size() / (double) perPage);
        if (pagecount == 0) {
            pagecount = 1;
        }
        if (page > pagecount) {
            sender.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidPage"));
            return;
        }
        sender.sendMessage(ChatColor.YELLOW + "---<" + ChatColor.GREEN + title + ChatColor.YELLOW + ">---");
        sender.sendMessage(ChatColor.YELLOW + "---<"
                + plugin.getLanguage().getPhrase("GenericPage", ChatColor.GREEN + String.format("%d", page) + ChatColor.YELLOW + "." + ChatColor.GREEN + pagecount + ChatColor.YELLOW) + ">---");
        for (int i = start; i < end; i++) {
            if (lines.size() > i) {
                sender.sendMessage(ChatColor.GREEN + lines.get(i));
            }
        }
        if (pagecount > page) {
            sender.sendMessage(ChatColor.GRAY + "---<" + plugin.getLanguage().getPhrase("NextPage") + ">---");
        } else {
            sender.sendMessage(ChatColor.GRAY + "-----------------------");
        }
    }

    public static void printInfo(final ResidenceMain plugin, final CommandSender sender, final String title, final String[] lines, final int page) {
        InformationPager.printInfo(plugin, sender, title, Arrays.asList(lines), page);
    }

    public static void setLinesPerPage(final int lines) {
        linesPerPage = lines;
    }
}
