2025-06-29 07:12:20 -04:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
|
import React from 'react';
|
2025-06-29 07:43:18 -04:00
|
|
|
|
import SearchInput from '@/components/SearchInput';
|
2025-06-29 15:58:03 -04:00
|
|
|
|
import RestrictionAlert from '@/components/RestrictionAlert';
|
|
|
|
|
|
import { useBuildStore } from '@/store/useBuildStore';
|
|
|
|
|
|
import { mockProducts } from '@/mock/product';
|
|
|
|
|
|
import { Dialog } from '@headlessui/react';
|
2025-06-29 07:12:20 -04:00
|
|
|
|
|
|
|
|
|
|
// AR-15 Build Requirements grouped by main categories
|
|
|
|
|
|
const buildGroups = [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'Upper Parts',
|
|
|
|
|
|
description: 'Components that make up the upper receiver assembly',
|
|
|
|
|
|
components: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'upper-receiver',
|
|
|
|
|
|
name: 'Upper Receiver',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'The upper receiver houses the barrel, bolt carrier group, and charging handle',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 150,
|
|
|
|
|
|
notes: 'Can be purchased as complete upper or stripped'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'barrel',
|
|
|
|
|
|
name: 'Barrel',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'The barrel determines accuracy and caliber compatibility',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 200,
|
|
|
|
|
|
notes: 'Common lengths: 16", 18", 20"'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'bolt-carrier-group',
|
|
|
|
|
|
name: 'Bolt Carrier Group (BCG)',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Handles the firing, extraction, and ejection of rounds',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 150,
|
|
|
|
|
|
notes: 'Mil-spec or enhanced options available'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'charging-handle',
|
|
|
|
|
|
name: 'Charging Handle',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Allows manual operation of the bolt carrier group',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 50,
|
|
|
|
|
|
notes: 'Standard or ambidextrous options'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'gas-block',
|
|
|
|
|
|
name: 'Gas Block',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Controls gas flow from barrel to BCG',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 30,
|
|
|
|
|
|
notes: 'Low-profile for free-float handguards'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'gas-tube',
|
|
|
|
|
|
name: 'Gas Tube',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Transfers gas from barrel to BCG',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 15,
|
|
|
|
|
|
notes: 'Carbine, mid-length, or rifle length'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'handguard',
|
|
|
|
|
|
name: 'Handguard',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Provides grip and mounting points for accessories',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 100,
|
|
|
|
|
|
notes: 'Free-float or drop-in options'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'muzzle-device',
|
|
|
|
|
|
name: 'Muzzle Device',
|
|
|
|
|
|
category: 'Upper',
|
|
|
|
|
|
description: 'Flash hider, compensator, or suppressor mount',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 80,
|
|
|
|
|
|
notes: 'A2 flash hider is standard'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'Lower Parts',
|
|
|
|
|
|
description: 'Components that make up the lower receiver assembly',
|
|
|
|
|
|
components: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'lower-receiver',
|
|
|
|
|
|
name: 'Lower Receiver',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'The lower receiver contains the trigger group and magazine well',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 100,
|
|
|
|
|
|
notes: 'Must be purchased through FFL dealer'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'trigger',
|
|
|
|
|
|
name: 'Trigger',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Controls firing mechanism',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 60,
|
|
|
|
|
|
notes: 'Mil-spec or enhanced triggers available'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'trigger-guard',
|
|
|
|
|
|
name: 'Trigger Guard',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Protects trigger from accidental discharge',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 10,
|
|
|
|
|
|
notes: 'Often included with lower receiver'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'pistol-grip',
|
|
|
|
|
|
name: 'Pistol Grip',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Provides grip for firing hand',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 25,
|
|
|
|
|
|
notes: 'Various ergonomic options available'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'buffer-tube',
|
|
|
|
|
|
name: 'Buffer Tube',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Houses buffer and spring for recoil management',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 40,
|
|
|
|
|
|
notes: 'Carbine, A5, or rifle length'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'buffer',
|
|
|
|
|
|
name: 'Buffer',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Absorbs recoil energy',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 20,
|
|
|
|
|
|
notes: 'H1, H2, H3 weights available'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'buffer-spring',
|
|
|
|
|
|
name: 'Buffer Spring',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Returns BCG to battery position',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 15,
|
|
|
|
|
|
notes: 'Standard or enhanced springs'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'stock',
|
|
|
|
|
|
name: 'Stock',
|
|
|
|
|
|
category: 'Lower',
|
|
|
|
|
|
description: 'Provides shoulder support and cheek weld',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 60,
|
|
|
|
|
|
notes: 'Fixed or adjustable options'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'Accessories',
|
|
|
|
|
|
description: 'Additional components needed for a complete build',
|
|
|
|
|
|
components: [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'magazine',
|
|
|
|
|
|
name: 'Magazine',
|
|
|
|
|
|
category: 'Accessory',
|
|
|
|
|
|
description: 'Holds and feeds ammunition',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 15,
|
|
|
|
|
|
notes: '30-round capacity is standard'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 'sights',
|
|
|
|
|
|
name: 'Sights',
|
|
|
|
|
|
category: 'Accessory',
|
|
|
|
|
|
description: 'Iron sights or optic for aiming',
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
status: 'pending',
|
|
|
|
|
|
estimatedPrice: 100,
|
|
|
|
|
|
notes: 'Backup iron sights recommended'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
// Flatten all components for filtering and sorting
|
|
|
|
|
|
const allComponents = buildGroups.flatMap(group => group.components);
|
|
|
|
|
|
|
|
|
|
|
|
const categories = ["All", "Upper", "Lower", "Accessory"];
|
|
|
|
|
|
|
|
|
|
|
|
type SortField = 'name' | 'category' | 'estimatedPrice' | 'status';
|
|
|
|
|
|
type SortDirection = 'asc' | 'desc';
|
|
|
|
|
|
|
2025-06-29 15:58:03 -04:00
|
|
|
|
// Map checklist component categories to product categories for filtering
|
|
|
|
|
|
const getProductCategory = (componentCategory: string): string => {
|
|
|
|
|
|
const categoryMap: Record<string, string> = {
|
|
|
|
|
|
'Upper': 'Upper Receiver', // Default to Upper Receiver for Upper category
|
|
|
|
|
|
'Lower': 'Lower Receiver', // Default to Lower Receiver for Lower category
|
|
|
|
|
|
'Accessory': 'Magazine', // Default to Magazine for Accessory category
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return categoryMap[componentCategory] || 'Magazine';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Map specific checklist components to product categories
|
|
|
|
|
|
const getProductCategoryForComponent = (componentName: string): string => {
|
|
|
|
|
|
const componentMap: Record<string, string> = {
|
|
|
|
|
|
// Upper components
|
|
|
|
|
|
'Upper Receiver': 'Upper Receiver',
|
|
|
|
|
|
'Barrel': 'Barrel',
|
|
|
|
|
|
'Bolt Carrier Group (BCG)': 'BCG',
|
|
|
|
|
|
'Charging Handle': 'Charging Handle',
|
|
|
|
|
|
'Gas Block': 'Gas Block',
|
|
|
|
|
|
'Gas Tube': 'Gas Tube',
|
|
|
|
|
|
'Handguard': 'Handguard',
|
|
|
|
|
|
'Muzzle Device': 'Muzzle Device',
|
|
|
|
|
|
|
|
|
|
|
|
// Lower components
|
|
|
|
|
|
'Lower Receiver': 'Lower Receiver',
|
|
|
|
|
|
'Trigger': 'Trigger',
|
|
|
|
|
|
'Trigger Guard': 'Lower Receiver',
|
|
|
|
|
|
'Pistol Grip': 'Lower Receiver',
|
|
|
|
|
|
'Buffer Tube': 'Lower Receiver',
|
|
|
|
|
|
'Buffer': 'Lower Receiver',
|
|
|
|
|
|
'Buffer Spring': 'Lower Receiver',
|
|
|
|
|
|
'Stock': 'Stock',
|
|
|
|
|
|
|
|
|
|
|
|
// Accessories
|
|
|
|
|
|
'Magazine': 'Magazine',
|
|
|
|
|
|
'Sights': 'Magazine',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return componentMap[componentName] || 'Lower Receiver';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export { buildGroups };
|
2025-06-29 07:12:20 -04:00
|
|
|
|
export default function BuildPage() {
|
|
|
|
|
|
const [sortField, setSortField] = useState<SortField>('name');
|
|
|
|
|
|
const [sortDirection, setSortDirection] = useState<SortDirection>('asc');
|
|
|
|
|
|
const [selectedCategory, setSelectedCategory] = useState('All');
|
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState('');
|
|
|
|
|
|
|
2025-06-29 15:58:03 -04:00
|
|
|
|
const selectedParts = useBuildStore((state) => state.selectedParts);
|
|
|
|
|
|
const removePartForComponent = useBuildStore((state) => state.removePartForComponent);
|
|
|
|
|
|
const clearBuild = useBuildStore((state) => state.clearBuild);
|
|
|
|
|
|
const [showClearModal, setShowClearModal] = useState(false);
|
|
|
|
|
|
|
2025-06-29 07:12:20 -04:00
|
|
|
|
// Filter components
|
|
|
|
|
|
const filteredComponents = allComponents.filter(component => {
|
|
|
|
|
|
if (selectedCategory !== 'All' && component.category !== selectedCategory) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (searchTerm && !component.name.toLowerCase().includes(searchTerm.toLowerCase()) &&
|
|
|
|
|
|
!component.description.toLowerCase().includes(searchTerm.toLowerCase())) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Sort components
|
|
|
|
|
|
const sortedComponents = [...filteredComponents].sort((a, b) => {
|
|
|
|
|
|
let aValue: any, bValue: any;
|
|
|
|
|
|
|
|
|
|
|
|
if (sortField === 'estimatedPrice') {
|
|
|
|
|
|
aValue = a.estimatedPrice;
|
|
|
|
|
|
bValue = b.estimatedPrice;
|
|
|
|
|
|
} else if (sortField === 'category') {
|
|
|
|
|
|
aValue = a.category.toLowerCase();
|
|
|
|
|
|
bValue = b.category.toLowerCase();
|
|
|
|
|
|
} else if (sortField === 'status') {
|
|
|
|
|
|
aValue = a.status.toLowerCase();
|
|
|
|
|
|
bValue = b.status.toLowerCase();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
aValue = a.name.toLowerCase();
|
|
|
|
|
|
bValue = b.name.toLowerCase();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sortDirection === 'asc') {
|
|
|
|
|
|
return aValue > bValue ? 1 : -1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return aValue < bValue ? 1 : -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const handleSort = (field: SortField) => {
|
|
|
|
|
|
if (sortField === field) {
|
|
|
|
|
|
setSortDirection(sortDirection === 'asc' ? 'desc' : 'asc');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setSortField(field);
|
|
|
|
|
|
setSortDirection('asc');
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getSortIcon = (field: SortField) => {
|
|
|
|
|
|
if (sortField !== field) {
|
|
|
|
|
|
return '↕️';
|
|
|
|
|
|
}
|
|
|
|
|
|
return sortDirection === 'asc' ? '↑' : '↓';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const getStatusColor = (status: string) => {
|
|
|
|
|
|
switch (status) {
|
2025-06-29 15:58:03 -04:00
|
|
|
|
case 'completed': return 'bg-green-100 text-green-800';
|
|
|
|
|
|
case 'in-progress': return 'bg-yellow-100 text-yellow-800';
|
|
|
|
|
|
case 'pending': return 'bg-gray-100 text-gray-800';
|
|
|
|
|
|
default: return 'bg-gray-100 text-gray-800';
|
2025-06-29 07:12:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const totalEstimatedCost = sortedComponents.reduce((sum, component) => sum + component.estimatedPrice, 0);
|
2025-06-29 15:58:03 -04:00
|
|
|
|
const completedCount = sortedComponents.filter(component => selectedParts[component.id]).length;
|
|
|
|
|
|
const actualTotalCost = sortedComponents.reduce((sum, component) => {
|
|
|
|
|
|
const selected = selectedParts[component.id];
|
|
|
|
|
|
if (selected && selected.offers) {
|
|
|
|
|
|
return sum + Math.min(...selected.offers.map(offer => offer.price));
|
|
|
|
|
|
}
|
|
|
|
|
|
return sum;
|
|
|
|
|
|
}, 0);
|
2025-06-29 07:12:20 -04:00
|
|
|
|
|
|
|
|
|
|
const hasActiveFilters = selectedCategory !== 'All' || searchTerm;
|
|
|
|
|
|
|
2025-06-29 15:58:03 -04:00
|
|
|
|
// Check for restricted parts in the build
|
|
|
|
|
|
const getRestrictedParts = () => {
|
|
|
|
|
|
const restrictedParts: Array<{ part: any; restriction: string }> = [];
|
|
|
|
|
|
|
|
|
|
|
|
Object.values(selectedParts).forEach(selectedPart => {
|
|
|
|
|
|
if (selectedPart) {
|
|
|
|
|
|
const product = mockProducts.find(p => p.id === selectedPart.id);
|
|
|
|
|
|
if (product?.restrictions) {
|
|
|
|
|
|
const restrictions = product.restrictions;
|
|
|
|
|
|
if (restrictions.nfa) restrictedParts.push({ part: product, restriction: 'NFA' });
|
|
|
|
|
|
if (restrictions.sbr) restrictedParts.push({ part: product, restriction: 'SBR' });
|
|
|
|
|
|
if (restrictions.suppressor) restrictedParts.push({ part: product, restriction: 'Suppressor' });
|
|
|
|
|
|
if (restrictions.stateRestrictions && restrictions.stateRestrictions.length > 0) {
|
|
|
|
|
|
restrictedParts.push({ part: product, restriction: 'State Restrictions' });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return restrictedParts;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const restrictedParts = getRestrictedParts();
|
|
|
|
|
|
const hasNFAItems = restrictedParts.some(rp => rp.restriction === 'NFA');
|
|
|
|
|
|
const hasSuppressors = restrictedParts.some(rp => rp.restriction === 'Suppressor');
|
|
|
|
|
|
const hasStateRestrictions = restrictedParts.some(rp => rp.restriction === 'State Restrictions');
|
|
|
|
|
|
const [showRestrictionAlerts, setShowRestrictionAlerts] = useState(true);
|
|
|
|
|
|
|
2025-06-29 07:12:20 -04:00
|
|
|
|
return (
|
|
|
|
|
|
<main className="min-h-screen bg-gray-50">
|
|
|
|
|
|
{/* Page Title */}
|
|
|
|
|
|
<div className="bg-white border-b">
|
|
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<h1 className="text-3xl font-bold text-gray-900">Plan Your Build</h1>
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Build Summary */}
|
|
|
|
|
|
<div className="bg-white border-b">
|
|
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 items-center">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<div className="text-center">
|
|
|
|
|
|
<div className="text-2xl font-bold text-gray-900">{allComponents.length}</div>
|
|
|
|
|
|
<div className="text-sm text-gray-500">Total Components</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
|
<div className="text-2xl font-bold text-green-600">{completedCount}</div>
|
|
|
|
|
|
<div className="text-sm text-gray-500">Completed</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-center">
|
|
|
|
|
|
<div className="text-2xl font-bold text-yellow-600">{allComponents.length - completedCount}</div>
|
|
|
|
|
|
<div className="text-sm text-gray-500">Remaining</div>
|
|
|
|
|
|
</div>
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="text-center flex flex-col items-center md:flex-row md:justify-center md:items-center gap-2">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div className="text-2xl font-bold text-blue-600">${actualTotalCost.toFixed(2)}</div>
|
|
|
|
|
|
<div className="text-sm text-gray-500">Total Cost</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn btn-outline btn-error ml-0 md:ml-4"
|
|
|
|
|
|
onClick={() => setShowClearModal(true)}
|
|
|
|
|
|
>
|
|
|
|
|
|
Clear Build
|
|
|
|
|
|
</button>
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-06-29 15:58:03 -04:00
|
|
|
|
{/* Clear Build Modal */}
|
|
|
|
|
|
<Dialog open={showClearModal} onClose={() => setShowClearModal(false)} className="fixed z-50 inset-0 overflow-y-auto">
|
|
|
|
|
|
<div className="flex items-center justify-center min-h-screen px-4">
|
|
|
|
|
|
<div className="fixed inset-0 bg-black opacity-30" aria-hidden="true" />
|
|
|
|
|
|
<div className="relative bg-white rounded-lg max-w-sm w-full mx-auto p-6 z-10 shadow-xl">
|
|
|
|
|
|
<Dialog.Title className="text-lg font-bold mb-2">Clear Entire Build?</Dialog.Title>
|
|
|
|
|
|
<Dialog.Description className="mb-4 text-gray-600">
|
|
|
|
|
|
Are you sure you want to clear your entire build? This action cannot be undone.
|
|
|
|
|
|
</Dialog.Description>
|
|
|
|
|
|
<div className="flex justify-end gap-2">
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn btn-sm btn-ghost"
|
|
|
|
|
|
onClick={() => setShowClearModal(false)}
|
|
|
|
|
|
>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn btn-sm btn-error"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
clearBuild();
|
|
|
|
|
|
setShowClearModal(false);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Yes, Clear Build
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Restriction Alerts */}
|
|
|
|
|
|
{restrictedParts.length > 0 && (
|
|
|
|
|
|
<div className="bg-white border-b">
|
|
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
|
|
|
|
|
|
<div className="flex items-center justify-between mb-3">
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<div className="w-2 h-2 bg-yellow-500 rounded-full"></div>
|
|
|
|
|
|
<span className="text-sm font-medium text-gray-700">
|
|
|
|
|
|
{restrictedParts.length} restriction{restrictedParts.length > 1 ? 's' : ''} detected
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setShowRestrictionAlerts(!showRestrictionAlerts)}
|
|
|
|
|
|
className="text-sm text-gray-500 hover:text-gray-700 flex items-center gap-1"
|
|
|
|
|
|
>
|
|
|
|
|
|
{showRestrictionAlerts ? 'Hide' : 'Show'} details
|
|
|
|
|
|
<svg
|
|
|
|
|
|
className={`w-4 h-4 transition-transform ${showRestrictionAlerts ? 'rotate-180' : ''}`}
|
|
|
|
|
|
fill="none"
|
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{showRestrictionAlerts && (
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
{hasNFAItems && (
|
|
|
|
|
|
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-3">
|
|
|
|
|
|
<div className="flex items-start gap-2">
|
|
|
|
|
|
<span className="text-yellow-600 text-sm">🔒</span>
|
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
|
<div className="text-sm font-medium text-yellow-800">NFA Items in Your Build</div>
|
|
|
|
|
|
<div className="text-xs text-yellow-700 mt-1">
|
|
|
|
|
|
Your build contains items that require National Firearms Act registration.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{hasSuppressors && (
|
|
|
|
|
|
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-3">
|
|
|
|
|
|
<div className="flex items-start gap-2">
|
|
|
|
|
|
<span className="text-yellow-600 text-sm">🔇</span>
|
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
|
<div className="text-sm font-medium text-yellow-800">Suppressor in Your Build</div>
|
|
|
|
|
|
<div className="text-xs text-yellow-700 mt-1">
|
|
|
|
|
|
Sound suppressor requires NFA registration. Processing times: 6-12 months.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{hasStateRestrictions && (
|
|
|
|
|
|
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-3">
|
|
|
|
|
|
<div className="flex items-start gap-2">
|
|
|
|
|
|
<span className="text-yellow-600 text-sm">🗺️</span>
|
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
|
<div className="text-sm font-medium text-yellow-800">State Restrictions Apply</div>
|
|
|
|
|
|
<div className="text-xs text-yellow-700 mt-1">
|
|
|
|
|
|
Some items may be restricted in certain states. Verify local laws.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-06-29 07:12:20 -04:00
|
|
|
|
{/* Search and Filters */}
|
|
|
|
|
|
<div className="bg-white border-b">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
{/* Filters Row */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
{/* Category Dropdown */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="col-span-1">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Category</label>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={selectedCategory}
|
|
|
|
|
|
onChange={(e) => setSelectedCategory(e.target.value)}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
className="w-full px-3 py-1.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-white text-gray-900 text-sm"
|
2025-06-29 07:12:20 -04:00
|
|
|
|
>
|
|
|
|
|
|
{categories.map((category) => (
|
|
|
|
|
|
<option key={category} value={category}>
|
|
|
|
|
|
{category}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Status Filter */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="col-span-1">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Status</label>
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<select className="w-full px-3 py-1.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-white text-gray-900 text-sm">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<option value="all">All Status</option>
|
|
|
|
|
|
<option value="pending">Pending</option>
|
|
|
|
|
|
<option value="in-progress">In Progress</option>
|
|
|
|
|
|
<option value="completed">Completed</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Sort by */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="col-span-1">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">Sort By</label>
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={sortField}
|
|
|
|
|
|
onChange={(e) => handleSort(e.target.value as SortField)}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
className="w-full px-3 py-1.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 bg-white text-gray-900 text-sm"
|
2025-06-29 07:12:20 -04:00
|
|
|
|
>
|
|
|
|
|
|
<option value="name">Name</option>
|
|
|
|
|
|
<option value="category">Category</option>
|
|
|
|
|
|
<option value="estimatedPrice">Price</option>
|
|
|
|
|
|
<option value="status">Status</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Clear Filters */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="col-span-1 flex items-end">
|
|
|
|
|
|
<button className="w-full px-3 py-1.5 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors text-sm">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
Clear Filters
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Build Components Table */}
|
|
|
|
|
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="bg-white shadow-sm rounded-lg overflow-hidden border border-gray-200">
|
|
|
|
|
|
<div className="overflow-x-auto max-h-screen overflow-y-auto">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<table className="min-w-full divide-y divide-gray-200">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<thead className="bg-gray-50 sticky top-0 z-10 shadow-sm">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<tr>
|
|
|
|
|
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
|
|
|
|
Status
|
|
|
|
|
|
</th>
|
|
|
|
|
|
<th
|
|
|
|
|
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer hover:bg-gray-100"
|
|
|
|
|
|
onClick={() => handleSort('name')}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center space-x-1">
|
|
|
|
|
|
<span>Component</span>
|
|
|
|
|
|
<span className="text-sm">{getSortIcon('name')}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</th>
|
|
|
|
|
|
<th
|
|
|
|
|
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer hover:bg-gray-100"
|
|
|
|
|
|
onClick={() => handleSort('category')}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center space-x-1">
|
|
|
|
|
|
<span>Category</span>
|
|
|
|
|
|
<span className="text-sm">{getSortIcon('category')}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</th>
|
|
|
|
|
|
<th
|
|
|
|
|
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer hover:bg-gray-100"
|
|
|
|
|
|
onClick={() => handleSort('estimatedPrice')}
|
|
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center space-x-1">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<span>Price</span>
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<span className="text-sm">{getSortIcon('estimatedPrice')}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</th>
|
|
|
|
|
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
|
|
|
|
Notes
|
|
|
|
|
|
</th>
|
|
|
|
|
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
Selected Product
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody className="bg-white divide-y divide-gray-200">
|
|
|
|
|
|
{sortedComponents.length > 0 ? (
|
|
|
|
|
|
buildGroups.map((group) => {
|
|
|
|
|
|
// Filter components in this group that match current filters
|
|
|
|
|
|
const groupComponents = group.components.filter(component =>
|
|
|
|
|
|
sortedComponents.some(sorted => sorted.id === component.id)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (groupComponents.length === 0) return null;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<React.Fragment key={group.name}>
|
|
|
|
|
|
{/* Group Header */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<tr className="bg-gray-100">
|
|
|
|
|
|
<td colSpan={7} className="px-6 py-2">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
<div className="flex items-center">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div>
|
|
|
|
|
|
<h3 className="text-sm font-semibold text-gray-700">{group.name}</h3>
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="ml-auto text-right">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
<div className="text-xs text-gray-500 font-medium">
|
2025-06-29 07:12:20 -04:00
|
|
|
|
{groupComponents.length} components
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/* Group Components */}
|
2025-06-29 15:58:03 -04:00
|
|
|
|
{groupComponents.map((component) => {
|
|
|
|
|
|
const selected = selectedParts[component.id];
|
|
|
|
|
|
return (
|
|
|
|
|
|
<tr key={component.id} className="hover:bg-gray-50">
|
|
|
|
|
|
<td className="px-6 py-4 whitespace-nowrap">
|
|
|
|
|
|
{selected ? (
|
|
|
|
|
|
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
|
|
|
|
|
|
Selected
|
|
|
|
|
|
</span>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${getStatusColor(component.status)}`}>
|
|
|
|
|
|
{component.status}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="px-6 py-4 whitespace-nowrap">
|
|
|
|
|
|
{selected ? (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
|
<Link
|
|
|
|
|
|
href={`/products/${selected.id}`}
|
|
|
|
|
|
className="text-blue-600 hover:text-blue-800 hover:underline"
|
|
|
|
|
|
>
|
|
|
|
|
|
{selected.name}
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-xs text-gray-500">
|
|
|
|
|
|
{selected.brand.name} · {component.required ? 'Required' : 'Optional'}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
|
{component.name}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-xs text-gray-500">
|
|
|
|
|
|
{component.required ? 'Required' : 'Optional'}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="px-6 py-4 whitespace-nowrap">
|
|
|
|
|
|
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
|
|
|
|
|
{getProductCategoryForComponent(component.name)}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="px-6 py-4">
|
|
|
|
|
|
{selected ? (
|
|
|
|
|
|
<div className="text-sm font-semibold text-gray-900">
|
|
|
|
|
|
${Math.min(...selected.offers?.map(offer => offer.price) || [0]).toFixed(2)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="text-sm text-gray-400">
|
|
|
|
|
|
—
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="px-6 py-4">
|
|
|
|
|
|
<div className="text-sm text-gray-500 max-w-xs">
|
|
|
|
|
|
{component.notes}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium">
|
|
|
|
|
|
{selected ? (
|
|
|
|
|
|
<button
|
|
|
|
|
|
className="btn btn-outline btn-sm"
|
|
|
|
|
|
onClick={() => removePartForComponent(component.id)}
|
|
|
|
|
|
>
|
|
|
|
|
|
Remove
|
|
|
|
|
|
</button>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Link
|
|
|
|
|
|
href={`/parts?category=${encodeURIComponent(getProductCategoryForComponent(component.name))}`}
|
2025-06-30 20:47:49 -04:00
|
|
|
|
className="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md text-sm font-medium transition-colors"
|
2025-06-29 15:58:03 -04:00
|
|
|
|
>
|
|
|
|
|
|
Find Parts
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</React.Fragment>
|
|
|
|
|
|
);
|
|
|
|
|
|
})
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td colSpan={7} className="px-6 py-12 text-center">
|
|
|
|
|
|
<div className="text-gray-500">
|
|
|
|
|
|
<div className="text-lg font-medium mb-2">No components found</div>
|
|
|
|
|
|
<div className="text-sm">Try adjusting your filters or search terms</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Table Footer */}
|
|
|
|
|
|
<div className="bg-gray-50 px-6 py-3 border-t border-gray-200">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div className="text-sm text-gray-700">
|
|
|
|
|
|
Showing {sortedComponents.length} of {allComponents.length} components
|
|
|
|
|
|
{hasActiveFilters && (
|
|
|
|
|
|
<span className="ml-2 text-blue-600">
|
|
|
|
|
|
(filtered)
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="text-sm text-gray-500">
|
2025-06-29 15:58:03 -04:00
|
|
|
|
Total Value: ${actualTotalCost.toFixed(2)}
|
2025-06-29 07:12:20 -04:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</main>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|