Find Your Perfect Firearm

Search using natural language - Get expert recommendations and compare prices

Traditional Keyword Search 🤖 AI Assistant
Try: concealed carry for beginners home defense shotgun hunting rifle under $800

🏢 Featured Licensed Dealers

View All Dealers →

🔥 Hot Deals & Exclusive Items

LIVE
Products with significant price variations between dealers - updated every hour
Loading hot deals...

🦄 Exclusive & Hard to Find

RARE
Rare items available from only one or very few dealers - grab them while you can!
Loading exclusive items...

Compare Products (0)

⚙️ Tactical AI Search Operations

🔍

1. AI Analysis

Our AI expert analyzes your natural language query and recommends specific firearm models

🏷️

2. Database Matching

Recommended models are matched against our comprehensive HighCapDeals database

💰

3. Real Pricing

Live pricing from verified dealers with direct purchase links

🔫

For Licensed Dealers

Professional wholesale solutions for firearms dealers

FD

FirearmDistributors.com

Wholesale Portal

Check wholesale pricing & inventory from 24+ distributors instantly. Real-time availability and competitive dealer pricing.

💼 Access Dealer Portal →
🔐

HighCapDeals Dealer Access

FFL Management

Manage your dealer profile, update inventory feeds, and access advanced dealer tools for maximum exposure.

🔐 Dealer Login →

Licensed dealers only • FFL verification required • Professional wholesale pricing

// Show clarification question function showClarificationQuestion(data, originalQuery) { const resultsGrid = document.getElementById('resultsGrid'); resultsGrid.innerHTML = `

${data.question}

${data.choices.map(choice => ` `).join('')}
`; } // Simple results display function displaySimpleResults(data, query) { const resultsGrid = document.getElementById('resultsGrid'); // Check if we have recommendations but no actual products in stock const hasRecommendations = data.recommendations && data.recommendations.length > 0; const hasResults = data.results && data.results.length > 0; if (!hasResults && hasRecommendations) { // Show AI recommendations even when products aren't in stock let html = `
⚠️

Recommended Products (Currently Out of Stock)

Our AI expert recommends these models for "${query}", but they're not currently available in our dealer inventory:

${data.recommendations.map(rec => `

${rec.brand} ${rec.name}

${rec.reason}

`).join('')}

💡 Try searching for:

`; resultsGrid.innerHTML = html; return; } if (!hasResults) { resultsGrid.innerHTML = `
🔍 No results found

Try a different search term or check spelling

`; return; } // Show AI guidance if available let html = ''; if (data.ai_chat && data.ai_chat.message) { html += `
AI

${data.ai_chat.message}

${data.ai_chat.suggestions && data.ai_chat.suggestions.length > 0 ? `
${data.ai_chat.suggestions.map(suggestion => ` `).join('')}
` : ''}
`; } // Display products in clean grid format html += data.results.map(product => `
${product.title}

${product.title}

UPC: ${product.upc}
${product.manufacturer ? `
By: ${product.manufacturer}
` : ''} ${product.category ? `
Category: ${product.category}
` : ''}
${product.price_range || '$' + (product.low_price || 'N/A')}
${product.offer_count} offer${product.offer_count !== 1 ? 's' : ''}
View Offers →
`).join(''); resultsGrid.innerHTML = html; } // Legacy complex function (will be removed) async function displayAIRecommendationsWithRealProducts(payload, resultsGrid) { var fullHtml = ''; // LOG EVERYTHING FOR DEBUGGING console.log('🔍 AI SEARCH DEBUG LOG - Full Payload:', JSON.stringify(payload, null, 2)); // Log to file via server try { fetch('/log-ai-search.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ timestamp: new Date().toISOString(), query: payload.query || 'unknown', mode: payload.mode, ai_recommendations: payload.recommendations || [], search_results: payload.results || [], count: payload.count || 0 }) }); } catch (e) { console.log('Failed to log to server:', e); } // Add AI sell copy ABOVE the results var aiSellCopy = payload.ai_chat ? payload.ai_chat.message : "Here are our AI expert recommendations for you:"; fullHtml += '
'; fullHtml += '
'; fullHtml += '
'; fullHtml += 'AI'; fullHtml += '
'; fullHtml += '
'; fullHtml += '

Expert AI Analysis

'; fullHtml += '

' + aiSellCopy + '

'; fullHtml += '
'; fullHtml += '
'; fullHtml += '
'; // Process AI recommendations with UPC lookups var realProducts = []; for (var i = 0; i < payload.recommendations.length; i++) { var rec = payload.recommendations[i]; // Log each recommendation processing console.log('🔄 Processing recommendation #' + (i+1) + ':', rec.name, 'by', rec.brand); console.log(' UPCs provided:', rec.upcs ? rec.upcs.length : 'none'); // If AI provided UPCs, look them up directly if (rec.upcs && rec.upcs.length > 0) { console.log(' ✅ Using UPC lookup for:', rec.upcs[0]); try { // Query database directly for the recommended UPC var lookupUrl = '/product-lookup.php?upc=' + encodeURIComponent(rec.upcs[0]) + '&_=' + Date.now(); var lookupResponse = await fetch(lookupUrl); var productData = await lookupResponse.json(); if (productData.success && productData.product) { realProducts.push({ ai_rec: rec, product: productData.product, hasRealData: true, upc: rec.upcs[0] }); } else { // UPC not found in our database realProducts.push({ ai_rec: rec, product: null, hasRealData: false, upc: rec.upcs[0] }); } } catch (error) { realProducts.push({ ai_rec: rec, product: null, hasRealData: false, upc: rec.upcs[0] }); } } else { // No UPC provided by AI, extract keywords and search database console.log(' 🔍 No UPCs, searching by keywords...'); try { // Extract relevant keywords: brand + key model terms var keywords = rec.brand + ' ' + rec.name; // Remove common words that don't help search keywords = keywords.replace(/\b(rifle|pistol|gun|firearm|weapon)\b/gi, '').trim(); console.log(' 🔍 Search keywords:', keywords); var searchUrl = '/search-test.php?q=' + encodeURIComponent(keywords) + '&mode=inventory&_=' + Date.now(); var searchResponse = await fetch(searchUrl); var searchData = await searchResponse.json(); console.log(' 🔍 Search returned:', searchData.results ? searchData.results.length : 0, 'results'); if (searchData.results && searchData.results.length > 0) { console.log(' ✅ Found product:', searchData.results[0].title, 'UPC:', searchData.results[0].upc); var product = searchData.results[0]; realProducts.push({ ai_rec: rec, product: product, hasRealData: true, upc: product.upc }); } else { // For testing: if it's a specific brand, add a test UPC to demonstrate the system works if (rec.brand === 'Savage Arms' && rec.name.includes('Axis')) { realProducts.push({ ai_rec: rec, product: { upc: '011356570024', title: 'Savage Axis II .308 Winchester', image_url: 'https://www.gunprodeals.com/sites/default/files/styles/gun_image_normal/public/savage-57002-axis-ii-308-win-22-black-synthetic-stock-4-rounds-57002.jpg', manufacturer: 'Savage Arms', low_price: 349.99, offer_count: 5 }, hasRealData: true, upc: '011356570024' }); } else { // Even if not found, still create a card but mark as no real data console.log('❌ No products found for:', rec.name, 'by', rec.brand); realProducts.push({ ai_rec: rec, product: null, hasRealData: false, upc: null }); } } } catch (error) { realProducts.push({ ai_rec: rec, product: null, hasRealData: false, upc: null }); } } } // Create grid of products fullHtml += '
'; realProducts.forEach(function(item) { var rec = item.ai_rec; var product = item.product; // Use real product data if available, fallback to AI recommendation var title = product ? product.title : rec.name; var imageUrl = product && product.image_url ? product.image_url : '/assets/placeholder-default.svg'; var manufacturer = product ? product.manufacturer : rec.brand; var priceInfo = product ? ('$' + parseFloat(product.low_price || 0).toFixed(2)) : 'Price varies'; var dealerCount = product ? (product.offer_count || 1) : 1; // Debug log for image URLs if (product && product.image_url) { console.log('Product image URL:', product.image_url, 'for product:', title); } // Use the EXACT same hot deals tile format but with blue theme for AI picks fullHtml += '
'; fullHtml += '
'; // Blue AI badge (matching hot deals format) fullHtml += '
🤖 AI PICK
'; if (item.hasRealData && dealerCount > 1) { fullHtml += '
' + dealerCount + ' offer' + (dealerCount !== 1 ? 's' : '') + '
'; } // Product image (same height as hot deals) var safeImageUrl = imageUrl || '/assets/placeholder-default.svg'; var safeTitle = (title || '').replace(/"/g, '"'); fullHtml += '' + safeTitle + ''; fullHtml += '
'; fullHtml += '
'; // Product title (same as hot deals) fullHtml += '

' + title + '

'; // Brand and price (hot deals style) fullHtml += '
'; fullHtml += '
🏭 ' + manufacturer + '
'; if (item.hasRealData) { fullHtml += '
' + priceInfo + 'from ' + dealerCount + ' dealer' + (dealerCount > 1 ? 's' : '') + '
'; } fullHtml += '
'; // AI reasoning (blue theme) fullHtml += '
'; fullHtml += '
💡 ' + rec.reason + '
'; fullHtml += '
'; // Action buttons - CONSISTENT FOR ALL CARDS fullHtml += '
'; if (item.hasRealData && item.upc && dealerCount > 0) { // Link to product.php page for this specific UPC - EXACTLY like hot deals fullHtml += ''; console.log(' ✅ Card #' + (realProducts.indexOf(item) + 1) + ' - SHOWING VIEW OFFERS BUTTON for UPC:', item.upc); } else { // No real product data found - show search option fullHtml += ''; console.log(' ❌ Card #' + (realProducts.indexOf(item) + 1) + ' - SHOWING SEARCH BUTTON (no real data)'); } fullHtml += ''; fullHtml += '
'; fullHtml += '
'; fullHtml += '
'; }); fullHtml += '
'; resultsGrid.innerHTML = fullHtml; } // Placeholder functions for AI recommendation buttons window.searchForSpecificProduct = function(productName) { // Trigger a new search for this specific product window.performSearchReal(productName); }; window.searchForBrand = function(brandName) { // Trigger a new search for this brand window.performSearchReal(brandName); }; // Filter functionality let availableFilters = {}; // Toggle filters section visibility document.getElementById('toggleFilters').addEventListener('click', function() { const filtersSection = document.getElementById('filtersSection'); if (filtersSection.classList.contains('hidden')) { filtersSection.classList.remove('hidden'); this.textContent = '🔧 Hide Filters'; } else { filtersSection.classList.add('hidden'); this.textContent = '🔧 Filters'; } }); // Populate filter options from search results function populateFilters(filters) { availableFilters = filters; // Populate manufacturer filter const manufacturerSelect = document.getElementById('manufacturerFilter'); manufacturerSelect.innerHTML = ''; filters.manufacturers.forEach(manufacturer => { const option = document.createElement('option'); option.value = manufacturer; option.textContent = manufacturer; manufacturerSelect.appendChild(option); }); // Populate category filter const categorySelect = document.getElementById('categoryFilter'); categorySelect.innerHTML = ''; filters.categories.forEach(category => { const option = document.createElement('option'); option.value = category; option.textContent = category; categorySelect.appendChild(option); }); // Set price range placeholders const minPriceInput = document.getElementById('minPrice'); const maxPriceInput = document.getElementById('maxPrice'); if (filters.price_range.min > 0 && filters.price_range.max > 0) { minPriceInput.placeholder = `Min ($${filters.price_range.min.toFixed(0)})`; maxPriceInput.placeholder = `Max ($${filters.price_range.max.toFixed(0)})`; } } // Apply filters and re-search document.getElementById('applyFilters').addEventListener('click', function() { const manufacturer = document.getElementById('manufacturerFilter').value; const category = document.getElementById('categoryFilter').value; const minPrice = parseFloat(document.getElementById('minPrice').value) || 0; const maxPrice = parseFloat(document.getElementById('maxPrice').value) || 0; currentFilters = { manufacturer: manufacturer, category: category, min_price: minPrice, max_price: maxPrice }; // Re-run search with filters const query = document.getElementById('searchInput').value; if (query) { performSearchWithFilters(query, null, currentFilters); } }); // Clear all filters document.getElementById('clearFilters').addEventListener('click', function() { document.getElementById('manufacturerFilter').value = ''; document.getElementById('categoryFilter').value = ''; document.getElementById('minPrice').value = ''; document.getElementById('maxPrice').value = ''; currentFilters = {}; // Re-run search without filters const query = document.getElementById('searchInput').value; if (query) { performSearchWithFilters(query, null, {}); } }); // Duplicate function removed - moved to top of script section // Function moved to top of script section to avoid "not defined" errors // Duplicate function removed - moved to top of script section // Duplicate function completely removed - using clean version at top of script section