<?php

/**
 * Custom Elementor control: searchable AJAX select.
 *
 * Extends Elementor's native Select2 control. The PHP side only declares the
 * control type; the searchable AJAX behaviour (querying the ArraySubs
 * select-options REST endpoint) is supplied by the matching JS control view
 * registered via elementor.addControlView( 'arraysubs_ajax_select', ... ).
 *
 * @package ArraySubs\Features\ElementorIntegration\Controls
 */

namespace ArraySubs\Features\ElementorIntegration\Controls;

defined('ABSPATH') || exit;

use Elementor\Control_Select2;

/**
 * Class AjaxSelect
 */
class AjaxSelect extends Control_Select2
{
    /**
     * Control type identifier (matches the registered JS control view).
     */
    const CONTROL_TYPE = 'arraysubs_ajax_select';

    /**
     * Get control type.
     *
     * @return string
     */
    public function get_type()
    {
        return self::CONTROL_TYPE;
    }

    /**
     * Default control settings.
     *
     * Defaults to a multi-select. `arraysubs_select` carries the endpoint
     * config consumed by the JS view (e.g. [ 'type' => 'products',
     * 'query' => [ 'product_type' => 'subscription' ] ]). `type` is the
     * dispatcher route; filters must ride on a separate key like `product_type`.
     *
     * @return array
     */
    protected function get_default_settings()
    {
        $settings = parent::get_default_settings();

        $settings['multiple']         = true;
        $settings['label_block']      = true;
        $settings['arraysubs_select'] = [];

        return $settings;
    }
}
