refactor: rename shop to storefront for consistency
Rename all "shop" directories and references to "storefront" to match the API and route naming convention already in use. Renamed directories: - app/templates/shop/ → app/templates/storefront/ - static/shop/ → static/storefront/ - app/templates/shared/macros/shop/ → .../macros/storefront/ - docs/frontend/shop/ → docs/frontend/storefront/ Renamed files: - shop.css → storefront.css - shop-layout.js → storefront-layout.js Updated references in: - app/routes/storefront_pages.py (21 template references) - app/modules/cms/routes/pages/vendor.py - app/templates/storefront/base.html (static paths) - All storefront templates (extends/includes) - docs/architecture/frontend-structure.md This aligns the template/static naming with: - Route file: storefront_pages.py - API directory: app/api/v1/storefront/ - Module routes: */routes/api/storefront.py - URL paths: /storefront/* Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
283
static/storefront/css/storefront.css
Normal file
@@ -0,0 +1,283 @@
|
||||
/* Shop Frontend Styles */
|
||||
/* Uses CSS variables injected by theme system */
|
||||
|
||||
/* Base Utilities */
|
||||
.hover\:text-primary:hover {
|
||||
color: var(--color-primary) !important;
|
||||
}
|
||||
|
||||
.text-primary {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.bg-primary {
|
||||
background-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.bg-accent {
|
||||
background-color: var(--color-accent);
|
||||
}
|
||||
|
||||
.border-primary {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Button Styles */
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--color-secondary);
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn-outline {
|
||||
border: 2px solid var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
background-color: transparent;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 0.375rem;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-outline:hover {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Product Card Styles */
|
||||
.product-card {
|
||||
background: white;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s;
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.product-card:hover {
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-4px);
|
||||
}
|
||||
|
||||
.product-card.dark {
|
||||
background: #1f2937;
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.product-card-image {
|
||||
width: 100%;
|
||||
height: 250px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-card-title {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.product-card-price {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Category Badge */
|
||||
.category-badge {
|
||||
display: inline-block;
|
||||
padding: 0.25rem 0.75rem;
|
||||
background-color: var(--color-secondary);
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
/* Toast Notifications */
|
||||
.toast {
|
||||
animation: slideInRight 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideInRight {
|
||||
from {
|
||||
transform: translateX(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateX(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loading Spinner */
|
||||
.spinner {
|
||||
border: 3px solid rgba(0, 0, 0, 0.1);
|
||||
border-left-color: var(--color-primary);
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Search Overlay */
|
||||
.search-overlay {
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
/* Mobile Menu Slide */
|
||||
.mobile-menu {
|
||||
transform: translateX(-100%);
|
||||
transition: transform 0.3s ease-out;
|
||||
}
|
||||
|
||||
.mobile-menu.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
/* Cart Badge */
|
||||
.cart-badge {
|
||||
min-width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
/* Smooth Transitions */
|
||||
* {
|
||||
transition-property: background-color, border-color, color, fill, stroke;
|
||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
transition-duration: 150ms;
|
||||
}
|
||||
|
||||
/* Typography with Theme Fonts */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-family: var(--font-heading);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-body);
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-background);
|
||||
}
|
||||
|
||||
/* Dark Mode Adjustments */
|
||||
.dark body {
|
||||
background-color: #111827;
|
||||
color: #f9fafb;
|
||||
}
|
||||
|
||||
.dark .product-card {
|
||||
background-color: #1f2937;
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.dark .product-card-title {
|
||||
color: #f9fafb;
|
||||
}
|
||||
|
||||
/* Hero Section */
|
||||
.hero-section {
|
||||
background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
|
||||
color: white;
|
||||
padding: 4rem 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Feature Cards */
|
||||
.feature-card {
|
||||
padding: 2rem;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid var(--color-border);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.feature-card:hover {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Breadcrumbs */
|
||||
.breadcrumb {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
font-size: 0.875rem;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.breadcrumb a:hover {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Price Display */
|
||||
.price-old {
|
||||
text-decoration: line-through;
|
||||
color: #9ca3af;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.price-new {
|
||||
color: var(--color-accent);
|
||||
font-weight: 700;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.price-discount {
|
||||
background-color: var(--color-accent);
|
||||
color: white;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 0.25rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Rating Stars */
|
||||
.rating-stars {
|
||||
display: flex;
|
||||
gap: 0.125rem;
|
||||
color: #fbbf24;
|
||||
}
|
||||
|
||||
/* Responsive Grid */
|
||||
.product-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.product-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
285
static/storefront/css/tailwind.css
Normal file
@@ -0,0 +1,285 @@
|
||||
/* Tailwind CSS v4 - Shop Frontend Styles */
|
||||
/* Configuration is CSS-first in v4 */
|
||||
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Source paths for content scanning */
|
||||
@source "../../js/**/*.js";
|
||||
@source "../../../app/templates/shop/**/*.html";
|
||||
@source "../../../app/templates/shared/**/*.html";
|
||||
|
||||
/* Custom theme configuration */
|
||||
@theme {
|
||||
/* Custom gray palette (Windmill Dashboard) */
|
||||
--color-gray-50: #f9fafb;
|
||||
--color-gray-100: #f4f5f7;
|
||||
--color-gray-200: #e5e7eb;
|
||||
--color-gray-300: #d5d6d7;
|
||||
--color-gray-400: #9e9e9e;
|
||||
--color-gray-500: #707275;
|
||||
--color-gray-600: #4c4f52;
|
||||
--color-gray-700: #24262d;
|
||||
--color-gray-800: #1a1c23;
|
||||
--color-gray-900: #121317;
|
||||
|
||||
/* Custom purple palette (Windmill Dashboard) */
|
||||
--color-purple-50: #f6f5ff;
|
||||
--color-purple-100: #edebfe;
|
||||
--color-purple-200: #dcd7fe;
|
||||
--color-purple-300: #cabffd;
|
||||
--color-purple-400: #ac94fa;
|
||||
--color-purple-500: #9061f9;
|
||||
--color-purple-600: #7e3af2;
|
||||
--color-purple-700: #6c2bd9;
|
||||
--color-purple-800: #5521b5;
|
||||
--color-purple-900: #4a1d96;
|
||||
|
||||
/* Custom orange palette */
|
||||
--color-orange-50: #fff8f1;
|
||||
--color-orange-100: #feecdc;
|
||||
--color-orange-200: #fcd9bd;
|
||||
--color-orange-300: #fdba8c;
|
||||
--color-orange-400: #ff8a4c;
|
||||
--color-orange-500: #ff5a1f;
|
||||
--color-orange-600: #d03801;
|
||||
--color-orange-700: #b43403;
|
||||
--color-orange-800: #8a2c0d;
|
||||
--color-orange-900: #771d1d;
|
||||
|
||||
/* Custom green palette */
|
||||
--color-green-50: #f3faf7;
|
||||
--color-green-100: #def7ec;
|
||||
--color-green-200: #bcf0da;
|
||||
--color-green-300: #84e1bc;
|
||||
--color-green-400: #31c48d;
|
||||
--color-green-500: #0e9f6e;
|
||||
--color-green-600: #057a55;
|
||||
--color-green-700: #046c4e;
|
||||
--color-green-800: #03543f;
|
||||
--color-green-900: #014737;
|
||||
|
||||
/* Custom red palette */
|
||||
--color-red-50: #fdf2f2;
|
||||
--color-red-100: #fde8e8;
|
||||
--color-red-200: #fbd5d5;
|
||||
--color-red-300: #f8b4b4;
|
||||
--color-red-400: #f98080;
|
||||
--color-red-500: #f05252;
|
||||
--color-red-600: #e02424;
|
||||
--color-red-700: #c81e1e;
|
||||
--color-red-800: #9b1c1c;
|
||||
--color-red-900: #771d1d;
|
||||
|
||||
/* Custom yellow palette */
|
||||
--color-yellow-50: #fdfdea;
|
||||
--color-yellow-100: #fdf6b2;
|
||||
--color-yellow-200: #fce96a;
|
||||
--color-yellow-300: #faca15;
|
||||
--color-yellow-400: #e3a008;
|
||||
--color-yellow-500: #c27803;
|
||||
--color-yellow-600: #9f580a;
|
||||
--color-yellow-700: #8e4b10;
|
||||
--color-yellow-800: #723b13;
|
||||
--color-yellow-900: #633112;
|
||||
|
||||
/* Custom teal palette */
|
||||
--color-teal-50: #edfafa;
|
||||
--color-teal-100: #d5f5f6;
|
||||
--color-teal-200: #afecef;
|
||||
--color-teal-300: #7edce2;
|
||||
--color-teal-400: #16bdca;
|
||||
--color-teal-500: #0694a2;
|
||||
--color-teal-600: #047481;
|
||||
--color-teal-700: #036672;
|
||||
--color-teal-800: #05505c;
|
||||
--color-teal-900: #014451;
|
||||
|
||||
/* Custom blue palette */
|
||||
--color-blue-50: #ebf5ff;
|
||||
--color-blue-100: #e1effe;
|
||||
--color-blue-200: #c3ddfd;
|
||||
--color-blue-300: #a4cafe;
|
||||
--color-blue-400: #76a9fa;
|
||||
--color-blue-500: #3f83f8;
|
||||
--color-blue-600: #1c64f2;
|
||||
--color-blue-700: #1a56db;
|
||||
--color-blue-800: #1e429f;
|
||||
--color-blue-900: #233876;
|
||||
|
||||
/* Custom indigo palette */
|
||||
--color-indigo-50: #f0f5ff;
|
||||
--color-indigo-100: #e5edff;
|
||||
--color-indigo-200: #cddbfe;
|
||||
--color-indigo-300: #b4c6fc;
|
||||
--color-indigo-400: #8da2fb;
|
||||
--color-indigo-500: #6875f5;
|
||||
--color-indigo-600: #5850ec;
|
||||
--color-indigo-700: #5145cd;
|
||||
--color-indigo-800: #42389d;
|
||||
--color-indigo-900: #362f78;
|
||||
|
||||
/* Custom pink palette */
|
||||
--color-pink-50: #fdf2f8;
|
||||
--color-pink-100: #fce8f3;
|
||||
--color-pink-200: #fad1e8;
|
||||
--color-pink-300: #f8b4d9;
|
||||
--color-pink-400: #f17eb8;
|
||||
--color-pink-500: #e74694;
|
||||
--color-pink-600: #d61f69;
|
||||
--color-pink-700: #bf125d;
|
||||
--color-pink-800: #99154b;
|
||||
--color-pink-900: #751a3d;
|
||||
|
||||
/* Cool gray palette */
|
||||
--color-cool-gray-50: #fbfdfe;
|
||||
--color-cool-gray-100: #f1f5f9;
|
||||
--color-cool-gray-200: #e2e8f0;
|
||||
--color-cool-gray-300: #cfd8e3;
|
||||
--color-cool-gray-400: #97a6ba;
|
||||
--color-cool-gray-500: #64748b;
|
||||
--color-cool-gray-600: #475569;
|
||||
--color-cool-gray-700: #364152;
|
||||
--color-cool-gray-800: #27303f;
|
||||
--color-cool-gray-900: #1a202e;
|
||||
|
||||
/* Font family */
|
||||
--font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
|
||||
|
||||
/* Custom max-height */
|
||||
--spacing-xl: 36rem;
|
||||
}
|
||||
|
||||
/* Dark mode variant - uses class on html element */
|
||||
@variant dark (&:where(.dark, .dark *));
|
||||
|
||||
/* Custom utilities layer */
|
||||
@layer utilities {
|
||||
/* Hide number input spinners */
|
||||
.no-spinner::-webkit-outer-spin-button,
|
||||
.no-spinner::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
.no-spinner {
|
||||
-moz-appearance: textfield;
|
||||
appearance: textfield;
|
||||
}
|
||||
|
||||
/* Shadow outline utilities for focus states */
|
||||
.shadow-outline-gray {
|
||||
box-shadow: 0 0 0 3px hsla(220, 9%, 83%, 0.45);
|
||||
}
|
||||
.shadow-outline-purple {
|
||||
box-shadow: 0 0 0 3px hsla(262, 97%, 81%, 0.45);
|
||||
}
|
||||
.shadow-outline-red {
|
||||
box-shadow: 0 0 0 3px hsla(0, 91%, 85%, 0.45);
|
||||
}
|
||||
.shadow-outline-orange {
|
||||
box-shadow: 0 0 0 3px hsla(22, 97%, 77%, 0.45);
|
||||
}
|
||||
.shadow-outline-green {
|
||||
box-shadow: 0 0 0 3px hsla(152, 68%, 70%, 0.45);
|
||||
}
|
||||
.shadow-outline-blue {
|
||||
box-shadow: 0 0 0 3px hsla(215, 96%, 81%, 0.45);
|
||||
}
|
||||
.shadow-outline-yellow {
|
||||
box-shadow: 0 0 0 3px hsla(46, 97%, 65%, 0.45);
|
||||
}
|
||||
.shadow-outline-teal {
|
||||
box-shadow: 0 0 0 3px hsla(182, 68%, 69%, 0.45);
|
||||
}
|
||||
.shadow-outline-indigo {
|
||||
box-shadow: 0 0 0 3px hsla(226, 95%, 85%, 0.45);
|
||||
}
|
||||
.shadow-outline-pink {
|
||||
box-shadow: 0 0 0 3px hsla(330, 89%, 83%, 0.45);
|
||||
}
|
||||
}
|
||||
|
||||
/* Shop-specific component styles */
|
||||
@layer components {
|
||||
/* Form input styles */
|
||||
.form-input,
|
||||
.form-textarea,
|
||||
.form-select,
|
||||
.form-multiselect {
|
||||
@apply block w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm shadow-sm transition-colors;
|
||||
@apply focus:border-purple-500 focus:outline-none focus:ring-1 focus:ring-purple-500;
|
||||
@apply placeholder:text-gray-400;
|
||||
}
|
||||
|
||||
/* Dark mode form inputs */
|
||||
.dark .form-input,
|
||||
.dark .form-textarea,
|
||||
.dark .form-select,
|
||||
.dark .form-multiselect {
|
||||
@apply border-gray-600 bg-gray-700 text-gray-200;
|
||||
@apply focus:border-purple-400 focus:ring-purple-400;
|
||||
@apply placeholder:text-gray-500;
|
||||
}
|
||||
|
||||
/* Checkbox styles */
|
||||
.form-checkbox {
|
||||
@apply h-4 w-4 rounded border-gray-300 text-purple-600 transition-colors;
|
||||
@apply focus:ring-2 focus:ring-purple-500 focus:ring-offset-2;
|
||||
}
|
||||
|
||||
.dark .form-checkbox {
|
||||
@apply border-gray-600 bg-gray-700;
|
||||
@apply focus:ring-purple-400 focus:ring-offset-gray-800;
|
||||
}
|
||||
|
||||
/* Radio styles */
|
||||
.form-radio {
|
||||
@apply h-4 w-4 border-gray-300 text-purple-600 transition-colors;
|
||||
@apply focus:ring-2 focus:ring-purple-500 focus:ring-offset-2;
|
||||
}
|
||||
|
||||
.dark .form-radio {
|
||||
@apply border-gray-600 bg-gray-700;
|
||||
@apply focus:ring-purple-400 focus:ring-offset-gray-800;
|
||||
}
|
||||
|
||||
/* Shop-specific button using CSS variable for vendor theming */
|
||||
.btn-shop-primary {
|
||||
background-color: var(--color-primary, #7e3af2);
|
||||
@apply text-white px-4 py-2 rounded-lg font-medium transition-all;
|
||||
}
|
||||
|
||||
.btn-shop-primary:hover {
|
||||
filter: brightness(0.9);
|
||||
}
|
||||
|
||||
/* Product card hover effect */
|
||||
.product-card {
|
||||
@apply bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden transition-all duration-300;
|
||||
}
|
||||
|
||||
.product-card:hover {
|
||||
@apply shadow-xl -translate-y-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Base layer for default styles */
|
||||
@layer base {
|
||||
/* Default body styles */
|
||||
body {
|
||||
@apply bg-gray-50 text-gray-900 antialiased;
|
||||
}
|
||||
|
||||
/* Dark mode body */
|
||||
.dark body {
|
||||
@apply bg-gray-900 text-gray-200;
|
||||
}
|
||||
|
||||
/* Focus visible for accessibility */
|
||||
:focus-visible {
|
||||
@apply outline-2 outline-offset-2 outline-purple-500;
|
||||
}
|
||||
|
||||
.dark :focus-visible {
|
||||
@apply outline-purple-400;
|
||||
}
|
||||
}
|
||||
2
static/storefront/css/tailwind.output.css
Normal file
BIN
static/storefront/img/create-account-office-dark.jpeg
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
static/storefront/img/create-account-office.jpeg
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
static/storefront/img/forgot-password-office-dark.jpeg
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
static/storefront/img/forgot-password-office.jpeg
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
static/storefront/img/login-office-dark.jpeg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
static/storefront/img/login-office.jpeg
Normal file
|
After Width: | Height: | Size: 37 KiB |
6
static/storefront/img/placeholder.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="400" height="400" fill="#f3f4f6"/>
|
||||
<text x="50%" y="50%" font-family="Arial, sans-serif" font-size="20" fill="#9ca3af" text-anchor="middle" dominant-baseline="middle">
|
||||
No Image Available
|
||||
</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 291 B |
295
static/storefront/js/storefront-layout.js
Normal file
@@ -0,0 +1,295 @@
|
||||
// static/storefront/js/storefront-layout.js
|
||||
/**
|
||||
* Shop Layout Component
|
||||
* Provides base functionality for vendor shop pages
|
||||
* Works with vendor-specific themes
|
||||
*/
|
||||
|
||||
const shopLog = {
|
||||
info: (...args) => console.info('🛒 [SHOP]', ...args),
|
||||
warn: (...args) => console.warn('⚠️ [SHOP]', ...args),
|
||||
error: (...args) => console.error('❌ [SHOP]', ...args),
|
||||
debug: (...args) => console.log('🔍 [SHOP]', ...args)
|
||||
};
|
||||
|
||||
/**
|
||||
* Shop Layout Data
|
||||
* Base Alpine.js component for shop pages
|
||||
*/
|
||||
function shopLayoutData() {
|
||||
return {
|
||||
// Theme state
|
||||
dark: localStorage.getItem('shop-theme') === 'dark',
|
||||
|
||||
// UI state
|
||||
mobileMenuOpen: false,
|
||||
searchOpen: false,
|
||||
loading: false,
|
||||
cartCount: 0,
|
||||
|
||||
// Cart state
|
||||
cart: [],
|
||||
sessionId: null,
|
||||
|
||||
// Initialize
|
||||
init() {
|
||||
shopLog.info('Shop layout initializing...');
|
||||
|
||||
// Get or create session ID
|
||||
this.sessionId = this.getOrCreateSessionId();
|
||||
shopLog.debug('Session ID:', this.sessionId);
|
||||
|
||||
// Load cart from localStorage
|
||||
this.loadCart();
|
||||
|
||||
// Listen for cart updates
|
||||
window.addEventListener('cart-updated', () => {
|
||||
this.loadCart();
|
||||
});
|
||||
|
||||
shopLog.info('Shop layout initialized');
|
||||
},
|
||||
|
||||
// Get or create session ID
|
||||
getOrCreateSessionId() {
|
||||
let sessionId = localStorage.getItem('cart_session_id');
|
||||
if (!sessionId) {
|
||||
sessionId = 'session_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
|
||||
localStorage.setItem('cart_session_id', sessionId);
|
||||
shopLog.info('Created new session ID:', sessionId);
|
||||
}
|
||||
return sessionId;
|
||||
},
|
||||
|
||||
// Theme management
|
||||
toggleTheme() {
|
||||
this.dark = !this.dark;
|
||||
localStorage.setItem('shop-theme', this.dark ? 'dark' : 'light');
|
||||
shopLog.debug('Theme toggled:', this.dark ? 'dark' : 'light');
|
||||
},
|
||||
|
||||
// Mobile menu
|
||||
toggleMobileMenu() {
|
||||
this.mobileMenuOpen = !this.mobileMenuOpen;
|
||||
if (this.mobileMenuOpen) {
|
||||
document.body.style.overflow = 'hidden';
|
||||
} else {
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
},
|
||||
|
||||
closeMobileMenu() {
|
||||
this.mobileMenuOpen = false;
|
||||
document.body.style.overflow = '';
|
||||
},
|
||||
|
||||
// Search
|
||||
openSearch() {
|
||||
this.searchOpen = true;
|
||||
shopLog.debug('Search opened');
|
||||
// Focus search input after a short delay
|
||||
setTimeout(() => {
|
||||
const input = document.querySelector('#search-input');
|
||||
if (input) input.focus();
|
||||
}, 100);
|
||||
},
|
||||
|
||||
closeSearch() {
|
||||
this.searchOpen = false;
|
||||
},
|
||||
|
||||
// Cart management
|
||||
loadCart() {
|
||||
try {
|
||||
const cartData = localStorage.getItem('shop-cart');
|
||||
if (cartData) {
|
||||
this.cart = JSON.parse(cartData);
|
||||
this.cartCount = this.cart.reduce((sum, item) => sum + item.quantity, 0);
|
||||
}
|
||||
} catch (error) {
|
||||
shopLog.error('Failed to load cart:', error);
|
||||
this.cart = [];
|
||||
this.cartCount = 0;
|
||||
}
|
||||
},
|
||||
|
||||
addToCart(product, quantity = 1) {
|
||||
shopLog.info('Adding to cart:', product.name, 'x', quantity);
|
||||
|
||||
// Find existing item
|
||||
const existingIndex = this.cart.findIndex(item => item.id === product.id);
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
// Update quantity
|
||||
this.cart[existingIndex].quantity += quantity;
|
||||
} else {
|
||||
// Add new item
|
||||
this.cart.push({
|
||||
id: product.id,
|
||||
name: product.name,
|
||||
price: product.price,
|
||||
image: product.image,
|
||||
quantity: quantity
|
||||
});
|
||||
}
|
||||
|
||||
// Save and update
|
||||
this.saveCart();
|
||||
this.showToast(`${product.name} added to cart`, 'success');
|
||||
},
|
||||
|
||||
updateCartItem(productId, quantity) {
|
||||
const index = this.cart.findIndex(item => item.id === productId);
|
||||
if (index !== -1) {
|
||||
if (quantity <= 0) {
|
||||
this.cart.splice(index, 1);
|
||||
} else {
|
||||
this.cart[index].quantity = quantity;
|
||||
}
|
||||
this.saveCart();
|
||||
}
|
||||
},
|
||||
|
||||
removeFromCart(productId) {
|
||||
this.cart = this.cart.filter(item => item.id !== productId);
|
||||
this.saveCart();
|
||||
this.showToast('Item removed from cart', 'info');
|
||||
},
|
||||
|
||||
clearCart() {
|
||||
this.cart = [];
|
||||
this.saveCart();
|
||||
this.showToast('Cart cleared', 'info');
|
||||
},
|
||||
|
||||
saveCart() {
|
||||
try {
|
||||
localStorage.setItem('shop-cart', JSON.stringify(this.cart));
|
||||
this.cartCount = this.cart.reduce((sum, item) => sum + item.quantity, 0);
|
||||
|
||||
// Dispatch custom event
|
||||
window.dispatchEvent(new CustomEvent('cart-updated'));
|
||||
|
||||
shopLog.debug('Cart saved:', this.cart.length, 'items');
|
||||
} catch (error) {
|
||||
shopLog.error('Failed to save cart:', error);
|
||||
}
|
||||
},
|
||||
|
||||
// Get cart total
|
||||
get cartTotal() {
|
||||
return this.cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
|
||||
},
|
||||
|
||||
// Toast notifications
|
||||
showToast(message, type = 'info') {
|
||||
const container = document.getElementById('toast-container');
|
||||
if (!container) return;
|
||||
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type} transform transition-all duration-300 mb-2`;
|
||||
|
||||
// Color based on type
|
||||
const colors = {
|
||||
success: 'bg-green-500',
|
||||
error: 'bg-red-500',
|
||||
warning: 'bg-yellow-500',
|
||||
info: 'bg-blue-500'
|
||||
};
|
||||
|
||||
// noqa: SEC-015 - message is application-controlled
|
||||
toast.innerHTML = `
|
||||
<div class="${colors[type]} text-white px-6 py-3 rounded-lg shadow-lg flex items-center space-x-3">
|
||||
<span>${message}</span>
|
||||
<button onclick="this.parentElement.parentElement.remove()"
|
||||
class="ml-4 hover:opacity-75">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
container.appendChild(toast);
|
||||
|
||||
// Auto-remove after 3 seconds
|
||||
setTimeout(() => {
|
||||
toast.style.opacity = '0';
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
},
|
||||
|
||||
// Format currency using configured locale
|
||||
formatPrice(amount) {
|
||||
if (!amount && amount !== 0) return '';
|
||||
const locale = window.SHOP_CONFIG?.locale || 'fr-LU';
|
||||
const currency = window.SHOP_CONFIG?.currency || 'EUR';
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency: currency
|
||||
}).format(amount);
|
||||
},
|
||||
|
||||
// Format date
|
||||
formatDate(dateString) {
|
||||
if (!dateString) return '-';
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Make available globally
|
||||
window.shopLayoutData = shopLayoutData;
|
||||
|
||||
/**
|
||||
* Language Selector Component
|
||||
* Alpine.js component for language switching
|
||||
*/
|
||||
function languageSelector(currentLang, enabledLanguages) {
|
||||
return {
|
||||
isLangOpen: false,
|
||||
currentLang: currentLang || 'fr',
|
||||
languages: enabledLanguages || ['fr', 'de', 'en'],
|
||||
languageNames: {
|
||||
'en': 'English',
|
||||
'fr': 'Français',
|
||||
'de': 'Deutsch',
|
||||
'lb': 'Lëtzebuergesch'
|
||||
},
|
||||
languageFlags: {
|
||||
'en': 'gb',
|
||||
'fr': 'fr',
|
||||
'de': 'de',
|
||||
'lb': 'lu'
|
||||
},
|
||||
async setLanguage(lang) {
|
||||
if (lang === this.currentLang) {
|
||||
this.isLangOpen = false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/v1/language/set', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ language: lang })
|
||||
});
|
||||
if (response.ok) {
|
||||
this.currentLang = lang;
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to set language:', error);
|
||||
}
|
||||
this.isLangOpen = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.languageSelector = languageSelector;
|
||||
|
||||
shopLog.info('Shop layout module loaded');
|
||||