import {tpl, noDataRendererTpl, loadingRendererTpl} from './pageListTpl';
import PageBase from '../pageTable/PageBase';
import "./pageList.scss";
const PageList = (($) => {
    const DefaultConfig = {
        nodataRenderer:noDataRendererTpl,
        loadingRenderer:loadingRendererTpl,
        defaultClassName:"cd-common-list"
    };
    class PageList extends PageBase{
        constructor(config) {
            super(config);
            this.__name = "PageList";
        }
        renderContent(){
            const {itemRenderer, nodataRenderer, loadingRenderer, loadingText, nodataText} = this._config;
            if(itemRenderer == null){
                throw Error("PageTable error: itemRenderer 不能为空");
            }
            if(this.state.loading){
                return template.render(loadingRenderer, {text:loadingText});
            }
            else{
                let pageData = this.state.pageData;
                if (pageData && pageData.length > 0) {
                    let _renderList = pageData.map((item, index) => {
                        return template.render(itemRenderer, item);
                    })
                    return _renderList.join("");
                }
                else{
                    return template.render(nodataRenderer, {text:nodataText});
                }
            }
        }
        
        _getConfig(config){
            config = $.extend(true, {}, DefaultConfig, config);
            return super._getConfig(config);
        }
        
        dispose() {
          super.dispose();
        }
    }
    return PageList;
})($);
export default PageList;