<?php
/**
 * Block menu builder settings schema.
 *
 * See the wording note in the mobile menu schema: labels are written for
 * someone describing what they want, not for someone who already knows the
 * CSS term for it. `ui.advanced` collapses a property into "Fine tuning".
 *
 * @package MenuVerse
 */

defined( 'ABSPATH' ) || exit;

return array(
	'type'       => 'object',
	'properties' => array(
		'menu'               => array(
			'type'    => 'string',
			'default' => '',
			'pattern' => '^$|^[a-z][a-z0-9_]*:\d+$',
			'ui'      => array(
				'control' => 'menu-picker',
				'group'   => 'general',
				'label'   => __( 'Which menu to fall back to', 'menuverse' ),
				'help'    => __( 'Used by the shortcode and by automatic insertion. When you use the block instead, you build the items right there in the editor, so this is ignored.', 'menuverse' ),
			),
		),
		'auto_insert'        => array(
			'type'    => 'boolean',
			'default' => false,
			'ui'      => array(
				'control' => 'toggle',
				'group'   => 'general',
				'label'   => __( 'Show it on every page automatically', 'menuverse' ),
			),
		),
		'breakpoint'         => array(
			'type'    => 'integer',
			'default' => 782,
			'minimum' => 320,
			'maximum' => 1600,
			'ui'      => array(
				'control' => 'range',
				'group'   => 'general',
				'unit'    => 'px',
				'label'   => __( 'Stack the items on screens narrower than', 'menuverse' ),
				'help'    => __( 'A row of links does not fit across a phone, so below this width they stack into a list.', 'menuverse' ),
			),
		),
		'layout'             => array(
			'type'    => 'string',
			'default' => 'horizontal',
			'enum'    => array( 'horizontal', 'vertical' ),
			'ui'      => array(
				'control' => 'segmented',
				'group'   => 'layout',
				'label'   => __( 'Lay the items out', 'menuverse' ),
				'options' => array(
					'horizontal' => __( 'In a row', 'menuverse' ),
					'vertical'   => __( 'In a list', 'menuverse' ),
				),
			),
		),
		'align'              => array(
			'type'    => 'string',
			'default' => 'start',
			'enum'    => array( 'start', 'center', 'end' ),
			'ui'      => array(
				'control' => 'segmented',
				'group'   => 'layout',
				'label'   => __( 'Line them up', 'menuverse' ),
				'options' => array(
					'start'  => __( 'To the start', 'menuverse' ),
					'center' => __( 'In the middle', 'menuverse' ),
					'end'    => __( 'To the end', 'menuverse' ),
				),
			),
		),
		'gap'                => array(
			'type'    => 'string',
			'format'  => 'css-size',
			'default' => '20px',
			'ui'      => array(
				'control'  => 'unit',
				'group'    => 'layout',
				'advanced' => true,
				'label'    => __( 'Space between items', 'menuverse' ),
				'token'    => '--menuverse-nav-gap',
			),
		),
		'submenu_trigger'    => array(
			'type'    => 'string',
			'default' => 'hover',
			'enum'    => array( 'hover', 'click' ),
			'ui'      => array(
				'control' => 'segmented',
				'group'   => 'submenus',
				'label'   => __( 'Nested items appear when someone', 'menuverse' ),
				'help'    => __( 'Either way, clicking and keyboard navigation keep working.', 'menuverse' ),
				'options' => array(
					'hover' => __( 'Points at the item', 'menuverse' ),
					'click' => __( 'Clicks the item', 'menuverse' ),
				),
			),
		),
		'submenu_background' => array(
			'type'    => 'string',
			'format'  => 'color',
			'default' => '',
			'ui'      => array(
				'control' => 'color',
				'group'   => 'submenus',
				'label'   => __( 'Background behind nested items', 'menuverse' ),
				'help'    => __( 'Leave empty to inherit your theme’s colours.', 'menuverse' ),
				'token'   => '--menuverse-nav-submenu-background',
			),
		),
		'link_color'         => array(
			'type'    => 'string',
			'format'  => 'color',
			'default' => '',
			'ui'      => array(
				'control' => 'color',
				'group'   => 'style',
				'label'   => __( 'Link colour', 'menuverse' ),
				'token'   => '--menuverse-nav-color',
			),
		),
		'active_color'       => array(
			'type'    => 'string',
			'format'  => 'color',
			'default' => '',
			'ui'      => array(
				'control' => 'color',
				'group'   => 'style',
				'label'   => __( 'Colour for the current page', 'menuverse' ),
				'token'   => '--menuverse-nav-active-color',
			),
		),
	),
	'ui'         => array(
		'preview' => array(
			'viewport' => 1280,
		),
		'presets' => array(
			array(
				'id'          => 'header',
				'label'       => __( 'Header row', 'menuverse' ),
				'description' => __( 'A row of links across the top, the usual site header arrangement.', 'menuverse' ),
				'values'      => array(
					'layout'          => 'horizontal',
					'align'           => 'start',
					'gap'             => '20px',
					'submenu_trigger' => 'hover',
				),
			),
			array(
				'id'          => 'centred',
				'label'       => __( 'Centred', 'menuverse' ),
				'description' => __( 'Links centred with generous spacing. Suits a logo above the menu.', 'menuverse' ),
				'values'      => array(
					'layout'          => 'horizontal',
					'align'           => 'center',
					'gap'             => '32px',
					'submenu_trigger' => 'hover',
				),
			),
			array(
				'id'          => 'stacked',
				'label'       => __( 'Stacked list', 'menuverse' ),
				'description' => __( 'Links down the page instead of across it. For sidebars and footers.', 'menuverse' ),
				'values'      => array(
					'layout'          => 'vertical',
					'align'           => 'start',
					'gap'             => '10px',
					'submenu_trigger' => 'click',
				),
			),
		),
		'groups'  => array(
			'general'  => array(
				'label'       => __( 'The basics', 'menuverse' ),
				'description' => __( 'This module is built around a block: add it to a page or template and you assemble the items there. These settings cover the other ways of placing it.', 'menuverse' ),
				'order'       => 10,
			),
			'layout'   => array(
				'label' => __( 'Arrangement', 'menuverse' ),
				'order' => 20,
			),
			'submenus' => array(
				'label'       => __( 'Nested items', 'menuverse' ),
				'description' => __( 'Only relevant if your menu has items nested under other items.', 'menuverse' ),
				'order'       => 30,
			),
			'style'    => array(
				'label' => __( 'Colours', 'menuverse' ),
				'order' => 40,
			),
		),
	),
);
