/**
 * DevExtreme (esm/__internal/ui/collection/m_collection_widget.async.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import {
    noop
} from "../../../core/utils/common";
import {
    Deferred,
    when
} from "../../../core/utils/deferred";
import CollectionWidgetEdit from "./m_collection_widget.edit";
const AsyncCollectionWidget = CollectionWidgetEdit.inherit({
    _initMarkup() {
        this._deferredItems = [];
        this.callBase()
    },
    _renderItemContent(args) {
        const renderContentDeferred = Deferred();
        const itemDeferred = Deferred();
        this._deferredItems[args.index] = itemDeferred;
        const $itemContent = this.callBase.call(this, args);
        itemDeferred.done((() => {
            renderContentDeferred.resolve($itemContent)
        }));
        return renderContentDeferred.promise()
    },
    _onItemTemplateRendered(itemTemplate, renderArgs) {
        return () => {
            this._deferredItems[renderArgs.index].resolve()
        }
    },
    _postProcessRenderItems: noop,
    _renderItemsAsync() {
        const d = Deferred();
        when.apply(this, this._deferredItems).done((() => {
            this._postProcessRenderItems();
            d.resolve()
        }));
        return d.promise()
    },
    _clean() {
        this.callBase();
        this._deferredItems = []
    }
});
export default AsyncCollectionWidget;
