// @ts-nocheck
import test from "node:test";
import assert from "node:assert/strict";
import { extractIdealoGalleryPictureUrls } from "../src/services/catalog-products.ts";

test("idealo gallery parser prefers large splide images over thumbnails", () => {
  const html = `
    <div class="splide__track container">
      <ul class="splide__list">
        <li class="splide__slide">
          <img
            src="//img.idealo.com/folder/Product/200123/4/200123456/s1_product_thumb.jpg"
            srcset="//img.idealo.com/folder/Product/200123/4/200123456/s1_product_150x150.jpg 150w,
                    //img.idealo.com/folder/Product/200123/4/200123456/s1_product_1000x1000.jpg 1000w">
        </li>
        <li class="splide__slide">
          <picture>
            <source srcset="//img.idealo.com/folder/Product/200123/4/200123456/s2_product_400x400.jpg 400w,
                            //img.idealo.com/folder/Product/200123/4/200123456/s2_product_1200x1200.jpg 1200w">
            <img src="//img.idealo.com/folder/Product/200123/4/200123456/s2_product_80x80.jpg">
          </picture>
        </li>
      </ul>
    </div>`;

  const urls = extractIdealoGalleryPictureUrls(html, "https://www.idealo.de/product.html");

  assert.deepEqual(urls, [
    "https://img.idealo.com/folder/Product/200123/4/200123456/s1_product_1000x1000.jpg",
    "https://img.idealo.com/folder/Product/200123/4/200123456/s2_product_1200x1200.jpg",
  ]);
});

test("idealo gallery parser does not fall back to search thumbnails", () => {
  const html = `
    <main>
      <article class="search-result">
        <img src="//img.idealo.com/folder/Product/200123/4/200123456/result_thumb_150x150.jpg">
      </article>
    </main>`;

  const urls = extractIdealoGalleryPictureUrls(html, "https://www.idealo.de/preisvergleich/MainSearchProductCategory.html?q=123");

  assert.deepEqual(urls, []);
});
