import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots' import type { ReconcilerTask } from '../core/reconciler-core.ts' import { NS } from '../i18n/locales.ts' import { getFrame } from '../platform/frame.ts' export function createPreviewFullscreenTask(t: TranslateNS): ReconcilerTask { let button: HTMLButtonElement | null = null const syncLabel = (target: HTMLButtonElement): void => { const full = getFrame()?.hasAttribute('data-mobile-preview-full') ?? false const label = t(full ? 'previewExitFullscreen' : 'previewFullscreen') if (target.getAttribute('aria-label') === label) return target.setAttribute('aria-label', label) target.title = label } const onClick = (): void => { getFrame()?.toggleAttribute('data-mobile-preview-full') if (button !== null) syncLabel(button) } return { name: 'preview-fullscreen-toggle', scopes: ['data-aionui-preview-open', 'data-mobile-preview-full'], ensure: () => { const col = document.querySelector('[data-aionui-preview-col]') if (col === null) return if (button === null) { button = document.createElement('button') button.type = 'button' button.dataset.mobileNav = 'preview-full-toggle' button.innerHTML = [ '', '', ].join('') button.addEventListener('click', onClick) } syncLabel(button) if (button.parentElement !== col) col.appendChild(button) }, dispose: () => { button?.remove() button = null }, } }