/*!
 * Built by Revolist OU ❤️
 */
/**
 * Plugin which recalculates realSize on changes of sizes, originItemSize and count
 */
export const recalculateRealSizePlugin = (storeService) => {
    /**
     * Recalculates realSize if size, origin size or count changes
     */
    return {
        /**
         * Reacts on changes of count, sizes and originItemSize
         */
        set(k) {
            var _a;
            switch (k) {
                case 'count':
                case 'sizes':
                case 'originItemSize': {
                    // recalculate realSize
                    let realSize = 0;
                    const count = storeService.store.get('count');
                    const sizes = storeService.store.get('sizes');
                    const originItemSize = storeService.store.get('originItemSize');
                    for (let i = 0; i < count; i++) {
                        realSize += (_a = sizes[i]) !== null && _a !== void 0 ? _a : originItemSize;
                    }
                    storeService.setStore({ realSize });
                    break;
                }
            }
        },
    };
};
