4801}48024803/**4804* Монтирует quantity widget.4805* Учитывает настройки показа, наличие кнопки заказа и остаток товара.4806*4807* @param {Element | null} productEl - Корневой DOM-элемент товара (карточка или попап).4808* @param {object} product - Данные товара или выбранной edition (в т.ч. quantity/editions).4809* @param {CatalogOptions | null} [opt] - Настройки показа количества.4810*/4811function t_catalog_addProductQuantity(productEl, product, opt) {4812
if (!productEl) return; const options = opt || {}; const popupButton = productEl.querySelector( '.t-catalog__prod-popup__btn-wrapper a[href="#order"]:not(.t-catalog__prod-popup__btn_disabled)' ); const cardButton = productEl.querySelector( '.t-catalog__card__btns-wrapper a[href="#order"]:not([style*="display: none"])' ); // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 let quantity = parseInt(product.quantity, 10); // @ts-expect-error ST-2949_1 if (isNaN(quantity) && product.editions && product.editions.length) { // @ts-expect-error ST-2949_1 const firstAvailableEdition = t_catalog_product_getFirstAvailableEditionData(product.editions); quantity = parseInt(firstAvailableEdition.quantity, 10); } if ( (!cardButton && !popupButton) || quantity === 0 || quantity === 1 || options.showStoreBtnQuantity === '' || !options.showStoreBtnQuantity ) { t_catalog_removeProductQuantity(productEl); return; } if ( !( (options.showStoreBtnQuantity === 'list' && productEl.classList.contains('t-catalog__card')) || (options.showStoreBtnQuantity === 'popup' && productEl.classList.contains('t-catalog__product-snippet')) || (options.showStoreBtnQuantity === 'popup' && productEl.classList.contains('t-catalog__product-popup')) || options.showStoreBtnQuantity === 'both' ) ) { t_catalog_removeProductQuantity(productEl); return; } const mountTarget = popupButton || cardButton; if (!mountTarget) { t_catalog_removeProductQuantity(productEl); return; } if (cardButton) { // TODO ST-2949_5: assignability, arguments, calls, return types (TS2345, TS2322, TS2554, TS2769, TS2740, TS2739, TS2353, TS2349, TS2355, TS2366, TS2774, TS18046) // @ts-expect-error ST-2949_5 t_catalog__prepareCardQuantityWrapper(cardButton); } let quantityContainer = productEl.querySelector('.js-product-quantity-widget'); if (!quantityContainer) { quantityContainer = document.createElement('div'); // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 quantityContainer.style.display = 'contents'; quantityContainer.classList.add('js-product-quantity-widget'); mountTarget.insertAdjacentElement('beforebegin', quantityContainer); } // eslint-disable-next-line no-nested-ternary const max = isNaN(quantity) ? 99999 : quantity > 0 ? quantity : 1; /** @type {import('../src/tilda-catalog/components/quantity/index.ts').QuantityWidgetSize | undefined} */ let size; let borderRadius; if (productEl.classList.contains('t-catalog__card')) { // Степпер встает перед кнопкой покупки: размер берем у нее, btnSize — размер первой кнопки size = t_catalog__resolveCardButtonSize(cardButton, options.btnSize); } // TODO ST-2949_1: missing properties on Window/DOM/data objects (TS2339, TS2551) // @ts-expect-error ST-2949_1 if (options.buttonRadius) { // @ts-expect-error ST-2949_1 borderRadius = options.buttonRadius; } else if (typeof options.btn1_style === 'string') { const match = options.btn1_style.match(/border-radius\s*:\s*([^;]+)/); if (match && typeof match[1] === 'string' && match[1].trim()) { borderRadius = match[1].trim(); } } if (!(quantityContainer instanceof HTMLElement)) return; const quantityState = t_catalog_createQuantityState({