import { e as createComponent, k as renderComponent, r as renderTemplate, h as createAstro, m as maybeRenderHead, ak as defineScriptVars } from '../chunks/astro/server_DePCulMI.mjs';
import 'piccolore';
import { $ as $$Layout } from '../chunks/Layout_DxAv3UTa.mjs';
import { $ as $$ProductCard } from '../chunks/ProductCard_7e_PI4fu.mjs';
import { S as SearchBar } from '../chunks/SearchBar_DC-3eI-y.mjs';
import { q as query } from '../chunks/db_Du3AmLCY.mjs';
export { renderers } from '../renderers.mjs';

var __freeze = Object.freeze;
var __defProp = Object.defineProperty;
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(cooked.slice()) }));
var _a;
const $$Astro = createAstro();
const $$Zoeken = createComponent(async ($$result, $$props, $$slots) => {
  const Astro2 = $$result.createAstro($$Astro, $$props, $$slots);
  Astro2.self = $$Zoeken;
  const q = Astro2.url.searchParams.get("q")?.trim() || "";
  let products = [];
  if (q.length >= 2) {
    const pattern = `%${q}%`;
    const result = await query(`
    SELECT p.id, p.name, p.slug, p.brand, p.colorway, p.gender, p.image_url, p.original_price,
           MIN(po.price) as lowest_price,
           MAX(po.original_price) as original_price_offer,
           COUNT(DISTINCT po.id) as offer_count,
           COUNT(DISTINCT COALESCE(f.merchant_name, f.name)) as shop_count
    FROM products p
    JOIN product_offers po ON po.product_id = p.id AND po.in_stock = true
    JOIN feeds f ON f.id = po.feed_id
    WHERE (p.name ILIKE $1 OR p.brand ILIKE $1 OR CONCAT(p.brand, ' ', p.name) ILIKE $1)
      AND p.is_sneaker = true AND p.image_url IS NOT NULL AND p.image_url != ''
    GROUP BY p.id
    HAVING MIN(po.price) > 0
    ORDER BY COUNT(po.id) DESC
    LIMIT 60
  `, [pattern]);
    products = result.rows.map((r) => {
      const lowestPrice = Number(r.lowest_price);
      const originalPrice = Number(r.original_price) || Number(r.original_price_offer) || lowestPrice;
      const shopCount = Number(r.shop_count);
      const offers = Array.from({ length: shopCount }, () => ({ shop: "", price: lowestPrice, url: "", inStock: true, sizes: [] }));
      return {
        id: String(r.id),
        slug: r.slug,
        name: r.name,
        brand: r.brand || "Unknown",
        brandSlug: (r.brand || "unknown").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, ""),
        colorway: r.colorway || "",
        image: r.image_url || "",
        lowestPrice,
        originalPrice: originalPrice > lowestPrice ? originalPrice : lowestPrice,
        offers,
        sizes: [],
        gender: r.gender || "unisex",
        releaseDate: "",
        trending: false,
        priceDrop: originalPrice > lowestPrice,
        priceHistory: []
      };
    });
  }
  const title = q ? `"${q}" \u2014 Zoekresultaten | SneakerPicks` : "Zoeken | SneakerPicks";
  const analyticsItems = products.map((s, i) => ({
    item_id: s.id,
    item_name: `${s.brand} ${s.name}`,
    item_brand: s.brand,
    price: s.lowestPrice,
    index: i
  }));
  const searchQuery = q;
  const resultsCount = products.length;
  return renderTemplate`${renderComponent($$result, "Layout", $$Layout, { "title": title }, { "default": async ($$result2) => renderTemplate` ${maybeRenderHead()}<section class="mx-auto max-w-7xl px-4 py-8 sm:px-6"> <div class="mb-8 max-w-2xl"> ${renderComponent($$result2, "SearchBar", SearchBar, { "large": true, "client:load": true, "client:component-hydration": "load", "client:component-path": "C:/Users/Roel/clawd/sneakerpicks/src/components/SearchBar.tsx", "client:component-export": "default" })} </div> ${q ? renderTemplate`<div> <h1 class="mb-6 text-2xl font-black"> ${products.length > 0 ? renderTemplate`<span>${products.length} resultaten voor <span class="text-accent">"${q}"</span></span>` : renderTemplate`<span>Geen resultaten voor <span class="text-accent">"${q}"</span></span>`} </h1> ${products.length > 0 ? renderTemplate`<div class="grid grid-cols-2 gap-4 sm:gap-6 md:grid-cols-3 lg:grid-cols-4"> ${products.map((sneaker, i) => renderTemplate`${renderComponent($$result2, "ProductCard", $$ProductCard, { "sneaker": sneaker, "index": i })}`)} </div>` : renderTemplate`<div class="py-16 text-center"> <p class="text-lg text-text-secondary">Probeer een andere zoekterm, bijvoorbeeld een merk of model.</p> </div>`} </div>` : renderTemplate`<div class="py-16 text-center"> <h1 class="mb-4 text-2xl font-black">Zoek sneakers</h1> <p class="text-text-secondary">Typ een merk, model of naam om te zoeken.</p> </div>`} </section> ${searchQuery && renderTemplate(_a || (_a = __template(["<script>(function(){", "\n      window.dataLayer = window.dataLayer || [];\n      window.dataLayer.push({ event: 'view_search_results', search_term: searchQuery, results_count: resultsCount });\n      if (analyticsItems.length > 0) {\n        window.dataLayer.push({ ecommerce: null });\n        window.dataLayer.push({\n          event: 'view_item_list',\n          ecommerce: {\n            item_list_id: 'search_results',\n            item_list_name: 'Zoekresultaten: ' + searchQuery,\n            items: analyticsItems.map(function(item) {\n              return Object.assign({}, item, { item_list_id: 'search_results', item_list_name: 'Zoekresultaten: ' + searchQuery });\n            })\n          }\n        });\n      }\n    })();<\/script>"])), defineScriptVars({ searchQuery, resultsCount, analyticsItems }))}` })}`;
}, "C:/Users/Roel/clawd/sneakerpicks/src/pages/zoeken.astro", void 0);

const $$file = "C:/Users/Roel/clawd/sneakerpicks/src/pages/zoeken.astro";
const $$url = "/zoeken";

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  default: $$Zoeken,
  file: $$file,
  url: $$url
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
