/**
 * DevExtreme (esm/renovation/ui/grids/data_grid_next/paging/paging.js)
 * Version: 22.1.3 (build 22180-0310)
 * Build date: Wed Jun 29 2022
 *
 * Copyright (c) 2012 - 2022 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 = ["defaultPageIndex", "defaultPageSize", "enabled", "pageIndex", "pageIndexChange", "pageSize", "pageSizeChange"];
import {
    createFragment,
    createComponentVNode
} from "inferno";
import {
    Fragment
} from "inferno";
import {
    BaseInfernoComponent
} from "@devextreme/runtime/inferno";
import {
    ValueSetter
} from "../../../../utils/plugin/value_setter";
import {
    GetterExtender
} from "../../../../utils/plugin/getter_extender";
import {
    LoadOptionsValue,
    LocalVisibleItems,
    LocalDataState
} from "../plugins";
import {
    PageIndex,
    PageSize,
    SetPageIndex,
    SetPageSize,
    PagingEnabled,
    ApplyPagingToVisibleItems,
    AddPagingToLoadOptions,
    LoadPageCount,
    SetLoadPageCount,
    AddPagingToLocalDataState
} from "./plugins";
export var viewFunction = viewModel => createFragment([createComponentVNode(2, ValueSetter, {
    type: PageIndex,
    value: viewModel.props.pageIndex
}), createComponentVNode(2, ValueSetter, {
    type: PageSize,
    value: viewModel.pageSize
}), createComponentVNode(2, ValueSetter, {
    type: PagingEnabled,
    value: viewModel.props.enabled
}), createComponentVNode(2, ValueSetter, {
    type: SetPageIndex,
    value: viewModel.setPageIndex
}), createComponentVNode(2, ValueSetter, {
    type: SetPageSize,
    value: viewModel.setPageSize
}), createComponentVNode(2, ValueSetter, {
    type: LoadPageCount,
    value: viewModel.loadPageCount
}), createComponentVNode(2, ValueSetter, {
    type: SetLoadPageCount,
    value: viewModel.setLoadPageCount
}), createComponentVNode(2, GetterExtender, {
    type: LocalVisibleItems,
    order: 1,
    value: ApplyPagingToVisibleItems
}), createComponentVNode(2, GetterExtender, {
    type: LoadOptionsValue,
    order: 1,
    value: AddPagingToLoadOptions
}), createComponentVNode(2, GetterExtender, {
    type: LocalDataState,
    order: 1,
    value: AddPagingToLocalDataState
})], 4);
export var DataGridNextPagingProps = {
    enabled: true,
    defaultPageSize: 20,
    pageSizeChange: () => {},
    defaultPageIndex: 0,
    pageIndexChange: () => {}
};
export class DataGridNextPaging extends BaseInfernoComponent {
    constructor(props) {
        super(props);
        this.state = {
            loadPageCount: 1,
            pageSize: void 0 !== this.props.pageSize ? this.props.pageSize : this.props.defaultPageSize,
            pageIndex: void 0 !== this.props.pageIndex ? this.props.pageIndex : this.props.defaultPageIndex
        };
        this.setPageIndex = this.setPageIndex.bind(this);
        this.setPageSize = this.setPageSize.bind(this);
        this.setLoadPageCount = this.setLoadPageCount.bind(this)
    }
    get pageSize() {
        if (0 === (void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize)) {
            return "all"
        }
        return void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize
    }
    setPageIndex(pageIndex) {
        var __newValue;
        this.setState(__state_argument => {
            __newValue = pageIndex;
            return {
                pageIndex: __newValue
            }
        });
        this.props.pageIndexChange(__newValue)
    }
    setPageSize(pageSize) {
        var __newValue;
        this.setState(__state_argument => {
            __newValue = pageSize;
            return {
                pageSize: __newValue
            }
        });
        this.props.pageSizeChange(__newValue)
    }
    setLoadPageCount(loadPageCount) {
        this.setState(__state_argument => ({
            loadPageCount: loadPageCount
        }))
    }
    get restAttributes() {
        var _this$props$pageSize$ = _extends({}, this.props, {
                pageSize: void 0 !== this.props.pageSize ? this.props.pageSize : this.state.pageSize,
                pageIndex: void 0 !== this.props.pageIndex ? this.props.pageIndex : this.state.pageIndex
            }),
            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,
                pageIndex: void 0 !== this.props.pageIndex ? this.props.pageIndex : this.state.pageIndex
            }),
            loadPageCount: this.state.loadPageCount,
            pageSize: this.pageSize,
            setPageIndex: this.setPageIndex,
            setPageSize: this.setPageSize,
            setLoadPageCount: this.setLoadPageCount,
            restAttributes: this.restAttributes
        })
    }
}
DataGridNextPaging.defaultProps = DataGridNextPagingProps;
