/**
 * DevExtreme (esm/renovation/ui/pager/page_size/large.js)
 * Version: 21.2.0 (build 21200-0321)
 * Build date: Mon Jul 19 2021
 *
 * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["defaultPageSize", "pageSize", "pageSizeChange", "pageSizes"];
import {
    createFragment,
    createComponentVNode
} from "inferno";
import {
    Fragment
} from "inferno";
import {
    BaseInfernoComponent
} from "@devextreme/vdom";
import {
    LightButton
} from "../common/light_button";
import {
    PagerProps
} from "../common/pager_props";
import {
    PAGER_SELECTED_PAGE_SIZE_CLASS,
    PAGER_PAGE_SIZE_CLASS
} from "../common/consts";
export var viewFunction = _ref => {
    var {
        pageSizesText: pageSizesText
    } = _ref;
    return createFragment(pageSizesText.map(_ref2 => {
        var {
            className: className,
            click: click,
            label: label,
            text: text
        } = _ref2;
        return createComponentVNode(2, LightButton, {
            className: className,
            label: label,
            onClick: click,
            children: text
        }, text)
    }), 0)
};
export var PageSizeLargeProps = {};
var PageSizeLargePropsType = {
    defaultPageSize: PagerProps.pageSize
};
export class PageSizeLarge extends BaseInfernoComponent {
    constructor(props) {
        super(props);
        this.state = {
            pageSize: void 0 !== this.props.pageSize ? this.props.pageSize : this.props.defaultPageSize
        };
        this.onPageSizeChange = this.onPageSizeChange.bind(this)
    }
    get pageSizesText() {
        var {
            pageSizes: pageSizes
        } = this.props;
        return pageSizes.map(_ref3 => {
            var {
                text: text,
                value: processedPageSize
            } = _ref3;
            var selected = processedPageSize === (void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize);
            var className = selected ? PAGER_SELECTED_PAGE_SIZE_CLASS : PAGER_PAGE_SIZE_CLASS;
            return {
                className: className,
                click: this.onPageSizeChange(processedPageSize),
                label: "Display ".concat(processedPageSize, " items on page"),
                text: text
            }
        })
    }
    onPageSizeChange(processedPageSize) {
        return () => {
            var __newValue;
            this.setState(state => {
                __newValue = processedPageSize;
                return {
                    pageSize: __newValue
                }
            });
            this.props.pageSizeChange(__newValue)
        }
    }
    get restAttributes() {
        var _this$props$pageSize = _extends({}, this.props, {
                pageSize: void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize
            }),
            restProps = _objectWithoutPropertiesLoose(_this$props$pageSize, _excluded);
        return restProps
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props, {
                pageSize: void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize
            }),
            pageSizesText: this.pageSizesText,
            restAttributes: this.restAttributes
        })
    }
}
PageSizeLarge.defaultProps = _extends({}, PageSizeLargePropsType);
