class IdmSearchHotspotTab {
constructor({ name, productsId }) {
console.log(`IDMSEARCH HOTSPOT1 ${productsId}`);
this.productsId = productsId;
this.name = name;
this.html = `
`;
}
// async initProducts(){
// const data = await idmGetClientStats();
// console.log(data);
// const allProductIds = data.lastOrders.flatMap(order => order.orderProducts.map(product => product.productId));
// const uniqueProductIds = [...new Set(allProductIds)];
// const testProductIds = [200665, 200664, 200686, 200684, 200669, 200596];
// this.productsId = testProductIds;
// }
// zapytrac Pawla o to zebvy uruchomic to asynmcrhonicznie
initHotspot() {
const classes = Array.from(this.container.classList).join(".");
const tabId = this.container.dataset.tabId;
const selector = `.${classes}[data-tab-id="${tabId}"] .idm-search-hotspot-tab__content`;
const id = `idm-search-hotspot-tab__hotspot-${tabId}`;
idmInsertHotspotObject({
id,
classes: "idm-search-hotspot-tab__hotspot",
title: "",
placement: {
selector,
insert: "beforeend",
},
query: {
string: `
searchInput: {productsId : [${this.productsId}]}
settingsInput: { limit: 100, page: 0 }
`,
graphFn: IDM_PRODUCTS_GQL,
},
options: {
swiper: false,
},
onLoad: () => {
setTimeout(() => {
app_shop.fn.idmSetHeight({
selectors: [
`#${id} .product__name`,
`#${id} .product__price`,
`#${id} .btn-idm`,
`#${id} .product__price-omnibus`,
],
container: `#${id} .products`,
});
}, 50);
},
});
// new IdmHotspot({
// id: `idm-search-hotspot-tab__hotspot-${tabId}`,
// classes: "idm-search-hotspot-tab__hotspot",
// title: "",
// placement: {
// selector,
// insert: "beforeend",
// },
// source: {
// productsId: this.productsId,
// },
// options: {
// swiper: false,
// showOpinions: true
// }
// });
}
initSearchInputEvents() {
const input = this.container.querySelector(
".idm-search-hotspot-tab__search",
);
const filterProducts = () => {
const products = this.container.querySelectorAll(".product");
const value = input.value.toLowerCase().trim();
products.forEach((product) => {
const nameEl = product.querySelector(".product__name");
if (!nameEl) return;
const name = nameEl.textContent.toLowerCase();
product.classList.toggle("product--hidden", !name.includes(value));
});
};
const DEBOUCE_DELAY = 200;
input.addEventListener(
"input",
app_shop.fn.idmDebounce(filterProducts, DEBOUCE_DELAY),
);
}
initEvents() {
this.initSearchInputEvents();
}
async onInit(tab, modalInstance) {
this.container = tab;
if (this.productsId.length === 0) {
console.error("IdmSearchHotspotTab: no products");
return;
}
await this.initHotspot();
this.initEvents();
}
}