/**
 * DevExtreme (esm/__internal/ui/collection/m_collection_widget.edit.strategy.plain.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import EditStrategy from "./m_collection_widget.edit.strategy";
var PlainEditStrategy = EditStrategy.inherit({
    _getPlainItems() {
        return this._collectionWidget.option("items") || []
    },
    getIndexByItemData(itemData) {
        var keyOf = this._collectionWidget.keyOf.bind(this._collectionWidget);
        if (keyOf) {
            return this.getIndexByKey(keyOf(itemData))
        }
        return this._getPlainItems().indexOf(itemData)
    },
    getItemDataByIndex(index) {
        return this._getPlainItems()[index]
    },
    deleteItemAtIndex(index) {
        this._getPlainItems().splice(index, 1)
    },
    itemsGetter() {
        return this._getPlainItems()
    },
    getKeysByItems(items) {
        var keyOf = this._collectionWidget.keyOf.bind(this._collectionWidget);
        var result = items;
        if (keyOf) {
            result = [];
            for (var i = 0; i < items.length; i++) {
                result.push(keyOf(items[i]))
            }
        }
        return result
    },
    getIndexByKey(key) {
        var cache = this._cache;
        var keys = cache && cache.keys || this.getKeysByItems(this._getPlainItems());
        if (cache && !cache.keys) {
            cache.keys = keys
        }
        if ("object" === typeof key) {
            for (var i = 0, {
                    length: length
                } = keys; i < length; i++) {
                if (this._equalKeys(key, keys[i])) {
                    return i
                }
            }
        } else {
            return keys.indexOf(key)
        }
        return -1
    },
    getItemsByKeys: (keys, items) => (items || keys).slice(),
    moveItemAtIndexToIndex(movingIndex, destinationIndex) {
        var items = this._getPlainItems();
        var movedItemData = items[movingIndex];
        items.splice(movingIndex, 1);
        items.splice(destinationIndex, 0, movedItemData)
    },
    _isItemIndex: index => "number" === typeof index && Math.round(index) === index,
    _getNormalizedItemIndex(itemElement) {
        return this._collectionWidget._itemElements().index(itemElement)
    },
    _normalizeItemIndex: index => index,
    _denormalizeItemIndex: index => index,
    _getItemByNormalizedIndex(index) {
        return index > -1 ? this._collectionWidget._itemElements().eq(index) : null
    },
    _itemsFromSameParent: () => true
});
export default PlainEditStrategy;
