/** * Header templates modal — pick a predefined layout for the current device. * * Applying a template overwrites the active device's rows, so it routes through * an inline confirm step first. Built on the WordPress core Modal primitive * (same as the Add Font modal); no new dependency. * * The confirm step is rendered inline (swapping the grid for a confirmation * panel) rather than as a second stacked Modal: nesting two `@wordpress/ * components` Modals dismisses the parent before the confirm can run, which * silently swallowed the apply. */ import { useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Modal, Button } from '@wordpress/components'; import { AlertTriangle } from 'lucide-react'; import { HEADER_TEMPLATES, type HeaderTemplate } from './header-templates'; import type { HeaderRow } from './canvas-model'; interface TemplateModalProps { deviceLabel: string; /** Preset list to offer — defaults to the header presets. */ presets?: HeaderTemplate[]; /** Intro sentence above the preset grid — defaults to the header copy. */ intro?: string; onApply: ( rows: HeaderRow[] ) => void; onClose: () => void; } export default function TemplateModal( { deviceLabel, presets = HEADER_TEMPLATES, intro, onApply, onClose, }: TemplateModalProps ) { const [ pending, setPending ] = useState< HeaderTemplate | null >( null ); return ( { pending ? (

{ sprintf( /* translators: %s: layout preset name. */ __( 'Apply the “%s” layout?', 'aureon' ), pending.label ) }

{ sprintf( /* translators: %s: device name (Desktop or Tablet). */ __( 'This replaces the current %s layout. Elements you have placed will be removed.', 'aureon' ), deviceLabel ) }

) : ( <>

{ intro ?? sprintf( /* translators: %s: device name (Desktop or Tablet). */ __( 'Choose a starting layout for the %s header.', 'aureon' ), deviceLabel ) }

) }
); }