Spaces:
Running
Running
File size: 17,889 Bytes
6fd26a4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | 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 = `
<style>
:host {
display: block;
width: 100%;
font-family: 'Inter', sans-serif;
}
.customizer-container {
background: white;
border-radius: 1.5rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.component-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1.5rem;
}
.component-card {
border: 2px solid #e5e7eb;
border-radius: 1rem;
padding: 1.5rem;
cursor: pointer;
transition: all 0.3s ease;
background: white;
}
.component-card:hover {
transform: translateY(-4px);
box-shadow: 0 10px 30px rgba(59, 130, 246, 0.15);
}
.component-card.selected {
border-color: #3b82f6;
background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}
.component-image {
height: 160px;
border-radius: 0.75rem;
overflow: hidden;
margin-bottom: 1rem;
background: #f8fafc;
}
.price-tag {
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
color: white;
padding: 0.25rem 0.75rem;
border-radius: 9999px;
font-weight: 600;
font-size: 0.875rem;
}
.specs-list {
list-style: none;
padding: 0;
}
.specs-list li {
display: flex;
justify-content: space-between;
padding: 0.25rem 0;
border-bottom: 1px solid #f1f5f9;
}
.summary-card {
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
border-radius: 1rem;
padding: 2rem;
position: sticky;
top: 2rem;
}
.total-price {
font-size: 2.5rem;
font-weight: 800;
background: linear-gradient(135deg, #3b82f6 0%, #0ea5e9 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.add-to-cart-btn {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
padding: 1rem 2rem;
border-radius: 0.75rem;
font-weight: 600;
transition: all 0.3s ease;
border: none;
width: 100%;
cursor: pointer;
}
.add-to-cart-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3);
}
.add-to-cart-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
.component-category {
font-size: 1.5rem;
font-weight: 700;
color: #1e293b;
margin-bottom: 1.5rem;
padding-bottom: 0.5rem;
border-bottom: 3px solid #3b82f6;
display: inline-block;
}
@media (max-width: 768px) {
.component-grid {
grid-template-columns: 1fr;
}
}
</style>
<div class="customizer-container">
<div class="grid lg:grid-cols-3 gap-8 p-8">
<!-- Component Selector -->
<div class="lg:col-span-2 space-y-12">
<!-- Frame -->
<div>
<h3 class="component-category">
<i data-feather="box" class="inline mr-2"></i> Frame
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
<!-- Motors -->
<div>
<h3 class="component-category">
<i data-feather="zap" class="inline mr-2"></i> Motores
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
<!-- Flight Controller -->
<div>
<h3 class="component-category">
<i data-feather="cpu" class="inline mr-2"></i> Controlador de Vuelo
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
<!-- Camera -->
<div>
<h3 class="component-category">
<i data-feather="video" class="inline mr-2"></i> Cámara
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
<!-- Battery -->
<div>
<h3 class="component-category">
<i data-feather="battery" class="inline mr-2"></i> Batería
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
<!-- Propellers -->
<div>
<h3 class="component-category">
<i data-feather="wind" class="inline mr-2"></i> Hélices
</h3>
<div class="component-grid">
${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' }
])}
</div>
</div>
</div>
<!-- Summary Sidebar -->
<div class="summary-card h-fit">
<h3 class="text-2xl font-bold mb-6">Tu Configuración</h3>
<div class="space-y-4 mb-8">
${Object.entries(this.selectedParts).map(([category, part]) => `
<div class="flex justify-between items-center p-3 bg-white rounded-lg">
<span class="font-medium capitalize">${category}</span>
<span class="font-semibold">${part ? part.name : 'No seleccionado'}</span>
${part ? `<span class="font-bold text-primary">$${part.price}</span>` : ''}
</div>
`).join('')}
</div>
<div class="border-t pt-6">
<div class="flex justify-between items-center mb-2">
<span class="text-lg font-semibold">Subtotal:</span>
<span class="text-xl font-bold" id="subtotal">$0</span>
</div>
<div class="flex justify-between items-center mb-2">
<span class="text-lg font-semibold">Envío:</span>
<span class="text-xl font-bold">$99</span>
</div>
<div class="flex justify-between items-center mb-6 border-t pt-4">
<span class="text-2xl font-extrabold">Total:</span>
<span class="total-price" id="total-price">$0</span>
</div>
<button id="add-custom-to-cart" class="add-to-cart-btn" disabled>
<i data-feather="shopping-cart" class="inline mr-2"></i>
Agregar al Carro
</button>
<p class="text-sm text-gray-500 mt-4 text-center">
<i data-feather="shield" class="inline w-4 h-4 mr-1"></i>
2 años de garantía incluida
</p>
</div>
</div>
</div>
</div>
`;
if (typeof feather !== 'undefined') {
feather.replace();
}
this.updateSummary();
}
renderComponentCards(category, components) {
return components.map(component => `
<div class="component-card ${this.selectedParts[category]?.id === component.id ? 'selected' : ''}"
data-category="${category}"
data-id="${component.id}"
data-name="${component.name}"
data-price="${component.price}">
<div class="component-image">
<img src="${component.img}" alt="${component.name}" class="w-full h-full object-cover">
</div>
<div class="flex justify-between items-start mb-3">
<h4 class="font-bold text-lg">${component.name}</h4>
<span class="price-tag">$${component.price}</span>
</div>
<ul class="specs-list text-sm text-gray-600">
${component.specs.map(spec => `<li><span>${spec}</span></li>`).join('')}
</ul>
</div>
`).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); |