import React from 'react'; import { cn } from '@/lib/utils'; import { __ } from '@/lib/i18n'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from '@/components/ui/accordion'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Slider } from '@/components/ui/slider'; import { Settings, PanelRightClose, PanelRight, Trash2, ExternalLink, Palette, Type, Home } from 'lucide-react'; import { InspectorField, SectionProp } from './InspectorField'; import { InspectorRepeater } from './InspectorRepeater'; import { MediaUploader } from '@/components/MediaUploader'; import { SectionStyles, ElementStyle, PageItem } from '../store/usePageEditorStore'; interface Section { id: string; type: string; layoutVariant?: string; colorScheme?: string; styles?: SectionStyles; elementStyles?: Record; props: Record; } interface InspectorPanelProps { page: PageItem | null; selectedSection: Section | null; isCollapsed: boolean; isTemplate: boolean; availableSources: { value: string; label: string }[]; onToggleCollapse: () => void; onSectionPropChange: (propName: string, value: SectionProp) => void; onLayoutChange: (layout: string) => void; onColorSchemeChange: (scheme: string) => void; onSectionStylesChange: (styles: Partial) => void; onElementStylesChange: (fieldName: string, styles: Partial) => void; onDeleteSection: () => void; onSetAsSpaLanding?: () => void; onUnsetSpaLanding?: () => void; onDeletePage?: () => void; onContainerWidthChange?: (width: 'boxed' | 'fullwidth') => void; } // Section field configurations const SECTION_FIELDS: Record = { hero: [ { name: 'title', label: 'Title', type: 'text', dynamic: true }, { name: 'subtitle', label: 'Subtitle', type: 'text', dynamic: true }, { name: 'image', label: 'Image URL', type: 'url', dynamic: true }, { name: 'cta_text', label: 'Button Text', type: 'text' }, { name: 'cta_url', label: 'Button URL', type: 'url' }, ], content: [ { name: 'content', label: 'Content', type: 'rte', dynamic: true }, { name: 'cta_text', label: 'Button Text', type: 'text' }, { name: 'cta_url', label: 'Button URL', type: 'url' }, ], 'image-text': [ { name: 'title', label: 'Title', type: 'text', dynamic: true }, { name: 'text', label: 'Text', type: 'textarea', dynamic: true }, { name: 'image', label: 'Image URL', type: 'url', dynamic: true }, { name: 'cta_text', label: 'Button Text', type: 'text' }, { name: 'cta_url', label: 'Button URL', type: 'url' }, ], 'feature-grid': [ { name: 'heading', label: 'Heading', type: 'text' }, ], 'cta-banner': [ { name: 'title', label: 'Title', type: 'text' }, { name: 'text', label: 'Description', type: 'text' }, { name: 'button_text', label: 'Button Text', type: 'text' }, { name: 'button_url', label: 'Button URL', type: 'url' }, ], 'contact-form': [ { name: 'title', label: 'Title', type: 'text' }, { name: 'webhook_url', label: 'Webhook URL', type: 'url' }, { name: 'redirect_url', label: 'Redirect URL', type: 'url' }, ], }; const LAYOUT_OPTIONS: Record = { hero: [ { value: 'default', label: 'Centered' }, { value: 'hero-left-image', label: 'Image Left' }, { value: 'hero-right-image', label: 'Image Right' }, ], 'image-text': [ { value: 'image-left', label: 'Image Left' }, { value: 'image-right', label: 'Image Right' }, ], 'feature-grid': [ { value: 'grid-2', label: '2 Columns' }, { value: 'grid-3', label: '3 Columns' }, { value: 'grid-4', label: '4 Columns' }, ], content: [ { value: 'default', label: 'Full Width' }, { value: 'narrow', label: 'Narrow' }, { value: 'medium', label: 'Medium' }, ], }; const COLOR_SCHEMES = [ { value: 'default', label: 'Default' }, { value: 'primary', label: 'Primary' }, { value: 'secondary', label: 'Secondary' }, { value: 'muted', label: 'Muted' }, { value: 'gradient', label: 'Gradient' }, ]; const STYLABLE_ELEMENTS: Record = { hero: [ { name: 'title', label: 'Title', type: 'text' }, { name: 'subtitle', label: 'Subtitle', type: 'text' }, { name: 'image', label: 'Image', type: 'image' }, { name: 'cta_text', label: 'Button', type: 'text' }, ], content: [ { name: 'heading', label: 'Headings', type: 'text' }, { name: 'text', label: 'Body Text', type: 'text' }, { name: 'link', label: 'Links', type: 'text' }, { name: 'image', label: 'Images', type: 'image' }, { name: 'button', label: 'Button', type: 'text' }, { name: 'content', label: 'Container', type: 'text' }, // Keep for backward compat or wrapper style ], 'image-text': [ { name: 'title', label: 'Title', type: 'text' }, { name: 'text', label: 'Text', type: 'text' }, { name: 'image', label: 'Image', type: 'image' }, { name: 'button', label: 'Button', type: 'text' }, ], 'feature-grid': [ { name: 'heading', label: 'Heading', type: 'text' }, { name: 'feature_item', label: 'Feature Item (Card)', type: 'text' }, ], 'cta-banner': [ { name: 'title', label: 'Title', type: 'text' }, { name: 'text', label: 'Description', type: 'text' }, { name: 'button_text', label: 'Button', type: 'text' }, ], 'contact-form': [ { name: 'title', label: 'Title', type: 'text' }, { name: 'button', label: 'Button', type: 'text' }, { name: 'fields', label: 'Input Fields', type: 'text' }, ], }; export function InspectorPanel({ page, selectedSection, isCollapsed, isTemplate, availableSources, onToggleCollapse, onSectionPropChange, onLayoutChange, onColorSchemeChange, onSectionStylesChange, onElementStylesChange, onDeleteSection, onSetAsSpaLanding, onUnsetSpaLanding, onDeletePage, onContainerWidthChange, }: InspectorPanelProps) { if (isCollapsed) { return (
); } if (!selectedSection) { return (

{__('Page Settings')}

{isTemplate ? __('Template Info') : __('Page Info')}

{isTemplate ? __('Template (Dynamic)') : __('Page (Structural)')}

{page?.title && (

{page.title}

)} {page?.url && ( )} {/* SPA Landing Settings - Only for Pages */} {!isTemplate && page && (
{page.isSpaLanding ? (
{__('This is your SPA Landing')}
) : ( )}
)} {/* Container Width */} {!isTemplate && page && onContainerWidthChange && (
onContainerWidthChange(val)} className="gap-2" >
)} {/* Danger Zone */} {!isTemplate && page && onDeletePage && (
)}
{__('Select any section on the canvas to edit its content and design.')}
); } return (
{/* Header */}
{SECTION_FIELDS[selectedSection.type] ? (selectedSection.type.charAt(0).toUpperCase() + selectedSection.type.slice(1)).replace('-', ' ') : 'Settings'}
{/* Content Tabs (Content vs Design) */}
{__('Content')} {__('Design')}
{/* Content Tab */} {/* Structure & Presets */}

{__('Structure')}

{LAYOUT_OPTIONS[selectedSection.type] && (
)}
{/* Fields */}

{__('Fields')}

{SECTION_FIELDS[selectedSection.type]?.map((field) => ( onSectionPropChange(field.name, val)} supportsDynamic={field.dynamic && isTemplate} availableSources={availableSources} /> {selectedSection.type === 'contact-form' && field.name === 'redirect_url' && (

Available shortcodes: {'{name}'}, {'{email}'}, {'{date}'}

)} {selectedSection.type === 'contact-form' && field.name === 'webhook_url' && ( View Payload Example
                                                        {JSON.stringify({
                                                            "form_id": "contact_form_123",
                                                            "fields": {
                                                                "name": "John Doe",
                                                                "email": "john@example.com",
                                                                "message": "Hello world"
                                                            },
                                                            "meta": {
                                                                "url": "https://site.com/contact",
                                                                "timestamp": 1710000000
                                                            }
                                                        }, null, 2)}
                                                    
)}
))}
{/* Feature Grid Repeater */} {selectedSection.type === 'feature-grid' && (
onSectionPropChange('features', { type: 'static', value: items })} fields={[ { name: 'title', label: 'Title', type: 'text' }, { name: 'description', label: 'Description', type: 'textarea' }, { name: 'icon', label: 'Icon', type: 'icon' }, ]} itemLabelKey="title" />
)} {/* Design Tab */} {/* Background */}

{__('Background')}

onSectionStylesChange({ backgroundColor: e.target.value })} />
onSectionStylesChange({ backgroundColor: e.target.value })} />
onSectionStylesChange({ backgroundImage: url })}> {selectedSection.styles?.backgroundImage ? (
Background
{__('Change')}
) : ( )}
{selectedSection.styles?.backgroundOverlay ?? 0}%
onSectionStylesChange({ backgroundOverlay: vals[0] })} />
{/* Element Styles */}

{__('Element Styles')}

{(STYLABLE_ELEMENTS[selectedSection.type] || []).map((field) => { const styles = selectedSection.elementStyles?.[field.name] || {}; const isImage = field.type === 'image'; return ( {field.label} {/* Common: Background Wrapper */}
onElementStylesChange(field.name, { backgroundColor: e.target.value })} />
onElementStylesChange(field.name, { backgroundColor: e.target.value })} />
{!isImage ? ( <> {/* Text Color */}
onElementStylesChange(field.name, { color: e.target.value })} />
onElementStylesChange(field.name, { color: e.target.value })} />
{/* Typography Group */}
{/* Link Specific Styles */} {field.name === 'link' && (
onElementStylesChange(field.name, { hoverColor: e.target.value })} />
onElementStylesChange(field.name, { hoverColor: e.target.value })} />
)} {/* Button/Box Specific Styles */} {field.name === 'button' && (
onElementStylesChange(field.name, { borderColor: e.target.value })} />
onElementStylesChange(field.name, { borderWidth: e.target.value })} />
onElementStylesChange(field.name, { borderRadius: e.target.value })} />
onElementStylesChange(field.name, { padding: e.target.value })} />
)} ) : ( <> {/* Image Settings */}
onElementStylesChange(field.name, { width: e.target.value })} />
onElementStylesChange(field.name, { height: e.target.value })} />
)} ); })}
{/* Footer - Delete Button */} { selectedSection && (
) }
); }