import React from 'react';

import LinkManager from 'modularity-front';
import Modularity from 'modularity-front';
import {Row, Pagination} from 'react-materialize';
import './pagination.css';


let Module = Modularity.Module;

class PaginationModule extends Modularity.Module {
	constructor(props) {
		super(props);
		this.state = {
        }
        this.selected.onUpdate(() => this.forceUpdate());
        this.page.set(this.selected.value);
		//this.object.onUpdate((e)=> this.forceUpdate());
		//this.lastPage.onUpdate(() => this.forceUpdate());
    }


    componentWillReceiveProps(props) {
        super.componentWillReceiveProps(props);
    }

    go(page) {
		this.page.set(page);
		if(this.props.onPage) {
			this.props.onPage(page);
		}
    }
    
    render() {
        return(
            <Row>
            {this.lastPage.value === 0 ? '' : 
                <Pagination className={this.props.className || 'pagination_layout'}onSelect= {(e) => this.go(e)} items={this.lastPage.value} activePage={this.selected.value} maxButtons={5}/>
            }
                {super.render()}
            </Row>
        )
    }


}


PaginationModule.EditPosition = 'top-right';
PaginationModule.Category = "sxoinas";

PaginationModule.Inputs = {
	selected: {
		type: Module.Types.Number,
		defaultValue: 1
	},
	lastPage: {
		type: Module.Types.Number,
		defaultValue: 0
	} 
}


PaginationModule.Outputs = {
	page: {
	}
}

export default PaginationModule;