class DroneCustomizer extends HTMLElement { constructor() { super(); this.selectedParts = { frame: null, motor: null, controller: null, camera: null, battery: null, propeller: null }; this.totalPrice = 0; } connectedCallback() { this.attachShadow({ mode: 'open' }); this.render(); this.addEventListeners(); } render() { this.shadowRoot.innerHTML = `

Frame

${this.renderComponentCards('frame', [ { id: 'frame-1', name: 'X-Light Carbon', price: 299, specs: ['5" size', 'Carbon fiber', '120g', '3K weave'], img: 'http://static.photos/technology/320x240/501' }, { id: 'frame-2', name: 'Titan Armor', price: 459, specs: ['6" size', 'Armored', '210g', 'Crash resistant'], img: 'http://static.photos/technology/320x240/502' }, { id: 'frame-3', name: 'Stealth Pro', price: 699, specs: ['7" size', 'Military grade', '180g', 'Low radar profile'], img: 'http://static.photos/technology/320x240/503' } ])}

Motores

${this.renderComponentCards('motor', [ { id: 'motor-1', name: 'Vortex 2207', price: 189, specs: ['2450KV', '4S-6S', '35A max', 'Neodymium'], img: 'http://static.photos/industry/320x240/511' }, { id: 'motor-2', name: 'Titan 2806', price: 289, specs: ['1750KV', '6S-8S', '45A max', 'Industrial'], img: 'http://static.photos/industry/320x240/512' }, { id: 'motor-3', name: 'Cyclone 2306', price: 239, specs: ['1950KV', '4S-6S', '40A max', 'High torque'], img: 'http://static.photos/industry/320x240/513' } ])}

Controlador de Vuelo

${this.renderComponentCards('controller', [ { id: 'fc-1', name: 'Betaflight F7', price: 129, specs: ['F7 processor', '8 PWM', 'Blackbox', 'OSD'], img: 'http://static.photos/technology/320x240/521' }, { id: 'fc-2', name: 'iNAV Pro', price: 199, specs: ['Triple IMU', 'GPS ready', 'Autonomous', 'Return home'], img: 'http://static.photos/technology/320x240/522' }, { id: 'fc-3', name: 'Ardupilot Military', price: 599, specs: ['Encrypted', 'Waypoints', 'Thermal cam', 'Secure comms'], img: 'http://static.photos/technology/320x240/523' } ])}

Cámara

${this.renderComponentCards('camera', [ { id: 'cam-1', name: 'Foxeer 4K', price: 159, specs: ['4K 60fps', 'Superview', 'Gyro flow', 'Low light'], img: 'http://static.photos/technology/320x240/531' }, { id: 'cam-2', name: 'DJI O3 Air', price: 239, specs: ['4K 120fps', '10-bit', '50km range', 'HD low latency'], img: 'http://static.photos/technology/320x240/532' }, { id: 'cam-3', name: 'Thermal FLIR', price: 1299, specs: ['Thermal 640x512', 'Zoom 30x', 'Night vision', 'Military spec'], img: 'http://static.photos/technology/320x240/533' } ])}

Batería

${this.renderComponentCards('battery', [ { id: 'bat-1', name: 'CNHL 6S 1300mAh', price: 89, specs: ['1300mAh', '6S 100C', 'XT60', 'Lightweight'], img: 'http://static.photos/technology/320x240/541' }, { id: 'bat-2', name: 'Tattu 6S 1800mAh', price: 129, specs: ['1800mAh', '6S 120C', 'XT90', 'Long flight'], img: 'http://static.photos/technology/320x240/542' }, { id: 'bat-3', name: 'Military 8S 2500mAh', price: 299, specs: ['2500mAh', '8S 150C', 'Anti-EMP', 'Wide temp'], img: 'http://static.photos/technology/320x240/543' } ])}

Hélices

${this.renderComponentCards('propeller', [ { id: 'prop-1', name: 'Gemfan 51466', price: 29, specs: ['3-blade', '5.1" pitch', '66mm', 'Durable'], img: 'http://static.photos/abstract/320x240/551' }, { id: 'prop-2', name: 'HQProp 6040', price: 39, specs: ['4-blade', '6" pitch', '40mm', 'Efficient'], img: 'http://static.photos/abstract/320x240/552' }, { id: 'prop-3', name: 'Stealth Whisper', price: 59, specs: ['5-blade', 'Silent', 'Carbon', 'Military'], img: 'http://static.photos/abstract/320x240/553' } ])}

Tu Configuración

${Object.entries(this.selectedParts).map(([category, part]) => `
${category} ${part ? part.name : 'No seleccionado'} ${part ? `$${part.price}` : ''}
`).join('')}
Subtotal: $0
Envío: $99
Total: $0

2 años de garantía incluida

`; if (typeof feather !== 'undefined') { feather.replace(); } this.updateSummary(); } renderComponentCards(category, components) { return components.map(component => `
${component.name}

${component.name}

$${component.price}
`).join(''); } addEventListeners() { this.shadowRoot.addEventListener('click', (e) => { const card = e.target.closest('.component-card'); if (card) { const category = card.dataset.category; const id = card.dataset.id; const name = card.dataset.name; const price = parseInt(card.dataset.price); this.selectComponent(category, { id, name, price }); this.updateSummary(); } if (e.target.id === 'add-custom-to-cart' || e.target.closest('#add-custom-to-cart')) { this.addCustomBuildToCart(); } }); } selectComponent(category, component) { this.selectedParts[category] = component; // Update UI const cards = this.shadowRoot.querySelectorAll(`[data-category="${category}"]`); cards.forEach(card => { card.classList.remove('selected'); if (card.dataset.id === component.id) { card.classList.add('selected'); } }); } updateSummary() { // Calculate subtotal this.totalPrice = Object.values(this.selectedParts) .filter(part => part !== null) .reduce((total, part) => total + part.price, 0); const subtotalEl = this.shadowRoot.getElementById('subtotal'); const totalEl = this.shadowRoot.getElementById('total-price'); const cartBtn = this.shadowRoot.getElementById('add-custom-to-cart'); if (subtotalEl) subtotalEl.textContent = `$${this.totalPrice}`; if (totalEl) totalEl.textContent = `$${this.totalPrice + 99}`; // Enable/disable cart button const allSelected = Object.values(this.selectedParts).every(part => part !== null); if (cartBtn) { cartBtn.disabled = !allSelected; } } addCustomBuildToCart() { if (!Object.values(this.selectedParts).every(part => part !== null)) { alert('Por favor selecciona todos los componentes antes de agregar al carro.'); return; } // Generate a unique build name const buildName = `Drone Personalizado: ${this.selectedParts.frame.name} + ${this.selectedParts.motor.name}`; const totalPrice = this.totalPrice + 99; // Add to cart const event = new CustomEvent('add-custom-build', { detail: { id: `custom-${Date.now()}`, name: buildName, price: totalPrice, parts: this.selectedParts } }); document.dispatchEvent(event); // Show success message alert(`✓ ${buildName} agregado al carro por $${totalPrice}`); } } customElements.define('drone-customizer', DroneCustomizer);