/*
 * Decompiled with CFR 0.152.
 */
package com.hst.framework.common;

import com.hst.framework.constants.WebConstants;
import java.io.Serializable;
import java.util.List;

public class PaginationSupport
implements Serializable {
    public static final int PAGESIZE = 30;
    private int pageSize = 30;
    private List items;
    private int totalCount;
    private int[] indexes = new int[0];
    private int startIndex = 0;
    private int totalPage = 0;
    private int currentPage = 0;
    private List heads;
    private String[] fieldNames;
    private String expFileName;
    private String goToPageStr = new String("");
    private String goToPageWithSubmitStr = new String("");

    public PaginationSupport(List items, int totalCount) {
        this.setPageSize(30);
        this.setTotalCount(totalCount);
        this.setItems(items);
        this.setStartIndex(0);
        this.calcPage();
        this.genGoToPagewithSubmit(String.valueOf(this.currentPage));
    }

    public PaginationSupport(List items, int totalCount, int startIndex) {
        this.setPageSize(30);
        this.setTotalCount(totalCount);
        this.setItems(items);
        this.setStartIndex(startIndex);
        this.calcPage();
        this.genGoToPagewithSubmit(String.valueOf(this.currentPage));
    }

    public PaginationSupport(List items, int totalCount, int pageSize, int startIndex) {
        this.setPageSize(pageSize);
        this.setTotalCount(totalCount);
        this.setItems(items);
        this.setStartIndex(startIndex);
        this.calcPage();
        this.genGoToPagewithSubmit(String.valueOf(this.currentPage));
    }

    private void calcPage() {
        this.currentPage = this.startIndex / this.pageSize + 1;
        if (this.totalCount != 0) {
            this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
            if (this.currentPage > this.totalPage) {
                this.currentPage = this.totalPage;
            }
            if (this.currentPage < 1) {
                this.currentPage = 1;
            }
        } else {
            this.currentPage = 0;
        }
    }

    public List getItems() {
        return this.items;
    }

    public void setItems(List items) {
        this.items = items;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return this.totalCount;
    }

    public void setTotalCount(int totalCount) {
        if (totalCount > 0) {
            this.totalCount = totalCount;
            int count = totalCount / this.pageSize;
            if (totalCount % this.pageSize > 0) {
                ++count;
            }
            this.indexes = new int[count];
            int i = 0;
            while (i < count) {
                this.indexes[i] = this.pageSize * i;
                ++i;
            }
        } else {
            this.totalCount = 0;
        }
    }

    public int[] getIndexes() {
        return this.indexes;
    }

    public void setIndexes(int[] indexes) {
        this.indexes = indexes;
    }

    public int getStartIndex() {
        return this.startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = this.totalCount <= 0 ? 0 : (startIndex >= this.totalCount ? this.indexes[this.indexes.length - 1] : (startIndex < 0 ? 0 : this.indexes[startIndex / this.pageSize]));
    }

    public int getNextIndex() {
        int nextIndex = this.getStartIndex() + this.pageSize;
        if (nextIndex >= this.totalCount) {
            return this.getStartIndex();
        }
        return nextIndex;
    }

    public int getPreviousIndex() {
        int previousIndex = this.getStartIndex() - this.pageSize;
        if (previousIndex < 0) {
            return 0;
        }
        return previousIndex;
    }

    public String getGoToPageStr() {
        return this.goToPageStr;
    }

    public void genGoToPage(String PageURL) {
        String previouspageURL = new String("");
        String nextpageURL = new String("");
        String firstpageURL = new String("");
        String lastpageURL = new String("");
        StringBuffer turnpagelist = new StringBuffer();
        int first = PageURL.indexOf("?");
        PageURL = first == -1 ? String.valueOf(PageURL) + "?page=PageNum" : String.valueOf(PageURL) + "&page=PageNum";
        turnpagelist.append("\u5f53\u524d\u7b2c<font color=#FF9900>" + this.currentPage + "</font>\u9875,\u5171<font color=#FF9900>" + this.totalPage + "</font>\u9875<font color=#FF9900>" + this.getTotalCount() + "</font>\u6761\u8bb0\u5f55");
        if (this.currentPage <= 1) {
            turnpagelist.append("&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/firstpage_2.gif'>" + "&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/prepage_2.gif'>");
        } else {
            firstpageURL = PageURL.replaceAll("PageNum", "1");
            previouspageURL = PageURL.replaceAll("PageNum", String.valueOf(this.currentPage - 1));
            turnpagelist.append("&nbsp&nbsp&nbsp;<a href='" + firstpageURL + "'><img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/firstpage.gif'></a>" + "&nbsp&nbsp&nbsp;<a href='" + previouspageURL + "'><img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/prepage.gif'></a>");
        }
        if (this.currentPage >= this.totalPage) {
            turnpagelist.append("&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/nextpage_2.gif'>" + "&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/lastpage_2.gif'>");
        } else {
            nextpageURL = PageURL.replaceAll("PageNum", String.valueOf(this.currentPage + 1));
            lastpageURL = PageURL.replaceAll("PageNum", String.valueOf(this.totalPage));
            turnpagelist.append("&nbsp&nbsp&nbsp;<a href='" + nextpageURL + "'><img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/nextpage.gif'></a>" + "&nbsp&nbsp&nbsp;<a href='" + lastpageURL + "'><img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/lastpage.gif'></a>");
        }
        this.goToPageStr = turnpagelist.toString();
    }

    public void genGoToPagewithSubmit(String cPage) {
        StringBuffer turnpagelist = new StringBuffer();
        int currentPage = (cPage = cPage.trim()) == "firstpage" ? Integer.MIN_VALUE : (cPage == "lastpage" ? Integer.MAX_VALUE : Integer.parseInt(cPage));
        turnpagelist.append("\u5f53\u524d\u7b2c<font color=#FF9900>" + currentPage + "</font>\u9875,\u5171<font color=#FF9900>" + this.totalPage + "</font>\u9875<font color=#FF9900>" + this.getTotalCount() + "</font>\u6761\u8bb0\u5f55");
        if (currentPage <= 1 || currentPage == Integer.MIN_VALUE) {
            turnpagelist.append("&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/firstpage_2.gif'>" + "&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/prepage_2.gif'>");
        } else {
            turnpagelist.append("&nbsp&nbsp&nbsp;<INPUT type='image' style='width:10px;height:12px;border:0' src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/firstpage.gif' onclick=\"jump('firstpage'," + "this.form" + "," + 1 + ")\"/>" + "&nbsp&nbsp&nbsp;<INPUT type='image' style='width:7px;height:12px;border:0' src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/prepage.gif' onclick=\"jump('prepage'," + "this.form" + "," + cPage + ")\"/>");
        }
        if (currentPage >= this.totalPage || currentPage == Integer.MAX_VALUE) {
            turnpagelist.append("&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/nextpage_2.gif'>" + "&nbsp&nbsp&nbsp;<img border=0 src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/lastpage_2.gif'>");
        } else {
            turnpagelist.append("&nbsp&nbsp&nbsp;<INPUT type='image' style='width:7px;height:12px;border:0' src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/nextpage.gif' onclick=\"jump('nextpage'," + "this.form" + "," + cPage + ")\"/>" + "&nbsp&nbsp&nbsp;<INPUT type='image' style='width:10px;height:12px;border:0' src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/lastpage.gif' onclick=\"jump('lastpage'," + "this.form" + "," + this.totalPage + ")\"/>");
        }
        turnpagelist.append("&nbsp&nbsp&nbsp;\u8f6c\u5230\u7b2c<INPUT type='text' name='pageToGen' value='" + cPage + "' size='" + String.valueOf(this.totalPage).length() + "' onkeydown=\"if(event.keyCode==13) return false;\"/>\u9875&nbsp;").append("<INPUT type='image' style='width:25px;height:20px;border:0' src='" + WebConstants.GLOBAL_WEB_ROOT + "/resource/pageframe/images/cp/go.gif' onclick=\"if(validatePage(this.form.pageToGen.value,1," + this.totalPage + ")){jump('gopage'," + "this.form" + ",this.form.pageToGen.value);}else{return false;}\"/>");
        this.goToPageWithSubmitStr = turnpagelist.toString();
    }

    public String getGoToPageWithSubmitStr() {
        return this.goToPageWithSubmitStr;
    }

    public void setGoToPageWithSubmitStr(String goToPageWithSubmitStr) {
        this.goToPageWithSubmitStr = goToPageWithSubmitStr;
    }

    public int getCurrentPage() {
        return this.currentPage;
    }

    public String getExpFileName() {
        return this.expFileName;
    }

    public void setExpFileName(String expFileName) {
        this.expFileName = expFileName;
    }

    public String[] getFieldNames() {
        return this.fieldNames;
    }

    public void setFieldNames(String[] fieldNames) {
        this.fieldNames = fieldNames;
    }

    public List getHeads() {
        return this.heads;
    }

    public void setHeads(List heads) {
        this.heads = heads;
    }

    public int getTotalPage() {
        return this.totalPage;
    }
}
