<?php
defined("ABSPATH") || exit;
/**
 * Shared Field Definitions — reusable across multiple widgets
 *
 * Ye file individual field definitions provide karti hai jo 50%+ widgets mein use hoti hain.
 * _common_fields.php se fark ye hai ke _common_fields AUTOMATICALLY har widget mein merge hota hai,
 * jabke _shared_fields se manually pick karte hain jo chahiye.
 *
 * Usage:
 *   $vunelix_shared = require __DIR__ . '/_shared_fields.php';
 *
 *   // Puri links group use karo with defaults
 *   'settings' => [
 *       'links' => $vunelix_shared['groups']['links'],
 *   ]
 *
 *   // Individual field pick karo
 *   'link_target' => $vunelix_shared['fields']['link_target'],
 *
 *   // Field override karo (tooltip change, pkg change, etc)
 *   'link_url' => array_merge($vunelix_shared['fields']['link_url'], [
 *       'description' => 'Custom tooltip for this widget. Placeholders: {{from}}, {{to}}',
 *   ]),
 *
 *   // Defaults pick karo
 *   'defaults' => array_merge($myDefaults, $vunelix_shared['defaults']['links']),
 *
 *   // Config map pick karo
 *   'config_map' => array_merge($myMap, $vunelix_shared['config_map']['links']),
 */

// ================================================================
// INDIVIDUAL FIELD DEFINITIONS — with tooltips
// ================================================================

$vunelix_fields = [

    // ── Click Behavior ──────────────────────────────────────────
    'link_target' => [
        'type'        => 'select',
        'label'       => 'Open In',
        'description' => 'Choose whether clicking an item opens in the same tab or a new tab.',
        'default'     => '_blank',
        'key'         => 'link_target',
        'pkg'         => 1,
        'options'     => ['_blank' => 'New Tab', '_self' => 'Same Tab'],
    ],
    'link_url' => [
        'type'        => 'text',
        'label'       => 'Custom URL',
        'description' => 'Replace the default link with your own page URL. Click the buttons below to insert placeholders. Example: yoursite.com/stocks/{{symbol}} becomes yoursite.com/stocks/AAPL when clicked.',
        'default'     => '',
        'placeholder' => 'https://example.com/{{symbol}}',
        'key'         => 'link_url',
        'pkg'         => 1,
        'tokens'      => ['symbol', 'name', 'exchange'],
    ],
    'enable_links' => [
        'type'        => 'toggle',
        'label'       => 'Enable Links',
        'description' => 'Make each item clickable. Links to its detail page by default, or your custom URL if set.',
        'default'     => true,
        'key'         => 'enable_links',
        'pkg'         => 1,
    ],

    // ── Storage ────────────────────────────────────────────────
    'enable_storage' => [
        'type'        => 'toggle',
        'label'       => 'Remember Selection',
        'description' => 'Save visitor choices (selected tab, time period, and other settings) so they stay the same when the page reloads.',
        'default'     => false,
        'key'         => 'enable_storage',
        'pkg'         => 1,
    ],

    // ── Live Data / Animation ──────────────────────────────────
    'animation_mode' => [
        'type'        => 'select',
        'label'       => 'Animation Style',
        'description' => 'How live price changes are highlighted when prices update in real time.',
        'default'     => 'digits',
        'key'         => 'animation_mode',
        'pkg'         => 1,
        'options'     => [
            'digits' => 'Changed digits only',
            'full'   => 'Full price',
            'flash'  => 'Background flash',
            'none'   => 'No animation',
        ],
    ],
    'animation_duration' => [
        'type'        => 'number',
        'label'       => 'Animation Duration (ms)',
        'description' => 'How long the color highlight stays visible after a price change (e.g. 1500 = 1.5 seconds).',
        'default'     => 1500,
        'key'         => 'animation_duration',
        'pkg'         => 1,
    ],
];


// ================================================================
// FIELD GROUPS — ready-made setting groups, use directly in 'settings'
// ================================================================

$vunelix_groups = [
    'links' => [
        'label'  => 'Click Behavior',
        'pkg'    => 1,
        'fields' => [
            'link_target'  => $vunelix_fields['link_target'],
            'link_url'     => $vunelix_fields['link_url'],
            'enable_links' => $vunelix_fields['enable_links'],
        ],
    ],
    'storage' => [
        'label'  => 'Remember Settings',
        'pkg'    => 1,
        'fields' => [
            'enable_storage' => $vunelix_fields['enable_storage'],
        ],
    ],
    'live_data' => [
        'label'  => 'Live Data Animation',
        'pkg'    => 1,
        'fields' => [
            'animation_mode'     => $vunelix_fields['animation_mode'],
            'animation_duration' => $vunelix_fields['animation_duration'],
        ],
    ],
];


// ================================================================
// DEFAULTS — merge into widget 'defaults' array
// ================================================================

$vunelix_defaults = [
    'links' => [
        'enable_links' => true,
        'link_target'  => '_blank',
        'link_url'     => '',
    ],
    'storage' => [
        'enable_storage' => false,
    ],
    'live_data' => [
        'animation_mode'     => 'digits',
        'animation_duration' => 1500,
    ],
];


// ================================================================
// CONFIG MAPS — merge into widget 'config_map' array
// ================================================================

$vunelix_config_map = [
    'links' => [
        'enable_links' => 'enableLinks',
        'link_target'  => 'linkTarget',
        'link_url'     => 'linkUrl',
    ],
    'storage' => [
        'enable_storage' => 'enableStorage',
    ],
    'live_data' => [
        'animation_mode'     => 'animationMode',
        'animation_duration' => 'animationDuration',
    ],
];


return [
    'fields'     => $vunelix_fields,
    'groups'     => $vunelix_groups,
    'defaults'   => $vunelix_defaults,
    'config_map' => $vunelix_config_map,
];
