<?php

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound -- APD is the established namespace shared with the Pro add-on and retained for backward compatibility.
namespace APD\Admin;

defined('ABSPATH') || exit;

final class AdminDesignerWorkspace
{
    public const ID = 'builtin-admin-workspace';

    public function config() : array
    {
        return [
            'configured' => true,
            'builtin' => true,
            'layout' => [
                'left' => [
                    'type' => 'default',
                    'collapsed' => false,
                    'collapsible' => true,
                    'items' => $this->items([
                        ['views', 'Views', 'views'],
                        ['designs', 'Designs', 'brush'],
                        ['text', 'Text', 'text'],
                        ['image', 'Images', 'images'],
                        ['shapes', 'Shapes', 'customize'],
                        ['layers', 'Layers', 'layers'],
                        ['elements', 'Elements', 'puzzle'],
                        ['product-parameters', 'Parameters', 'product-parameters'],
                        ['assembly', 'Assembly', 'magnet'],
                        ['drawingAreas', 'Drawing areas', 'drawing-areas'],
                        ['marker', 'Markers', 'pin'],
                        ['pricingRules', 'Pricing rules', 'pricing-rules'],
                    ], 'left'),
                ],
                'top' => [
                    'type' => 'default',
                    'collapsed' => false,
                    'collapsible' => true,
                    'items' => $this->items([
                        ['history', 'History', 'history'],
                        ['zoom', 'Zoom', 'zoom'],
                        ['magnifier', 'Magnifier', 'magnifying-glass'],
                        ['ruler', 'Ruler', 'ruler'],
                        ['camera', 'Camera', 'camera'],
                        ['download', 'Download', 'download'],
                        ['pricing', 'Pricing', 'pricing'],
                        ['modelOptimizer', 'GLB optimizer', 'model-optimizer', 'modal'],
                        ['state', 'State', 'state'],
                    ], 'top'),
                ],
                'right' => [
                    'type' => 'default',
                    'collapsed' => false,
                    'collapsible' => true,
                    'items' => [],
                ],
                'bottom' => [
                    'type' => 'default',
                    'collapsed' => true,
                    'collapsible' => true,
                    'items' => [],
                ],
                'selectionMenu' => [
                    'type' => 'popover',
                    'open' => false,
                    'items' => [
                        'transform',
                        'colors',
                        'font-family',
                        'text-formatting',
                        'text-curve',
                        'studio',
                    ],
                ],
            ],
            'moduleConfig' => [],
            'selectionMenu' => [
                'type' => 'popover',
                'open' => false,
                'items' => [
                    'transform',
                    'colors',
                    'font-family',
                    'text-formatting',
                    'text-curve',
                    'studio',
                ],
            ],
            'ui' => [],
        ];
    }

    private function items(array $definitions, string $zone) : array
    {
        return array_map(static function (array $definition) use ($zone) : array {
            return [
                'id' => (string) $definition[0],
                'kind' => (string) $definition[0],
                'label' => (string) $definition[1],
                'icon' => (string) $definition[2],
                'zone' => $zone,
                'type' => (string) ($definition[3] ?? 'floating'),
            ];
        }, $definitions);
    }
}
