<?php

class PZY_Select_Slide extends \Elementor\Base_Data_Control
{
    public function get_type()
    {
        return 'pzy_select_slide';
    }

    protected function get_default_settings()
    {
        return [

        ];
    }

    public function get_default_value()
    {
        return 0;
    }

    public function content_template()
    {
        $control_uid = $this->get_control_uid();
        $recent_slides = wp_get_recent_posts(array('post_type' => 'pzy_slide'));
        ?>
        <div class="elementor-control-field">

            <# if ( data.label ) {#>
            <label for="<?php echo $control_uid; ?>" class="elementor-control-title">{{{ data.label }}}</label>
            <# } #>

            <div class="elementor-control-input-wrapper">
                <select id="<?php echo $control_uid; ?>" data-setting="{{ data.name }}">
                    <option value=""><?php echo esc_html__('Select slide', 'pezeshkyar'); ?></option>
                    <?php foreach ($recent_slides as $slide) { ?>
                        <option value="<?php echo $slide['ID'] ?>"><?php echo $slide["post_title"] ?></option>
                    <?php } ?>
                </select>
            </div>

        </div>

        <# if ( data.description ) { #>
        <div class="elementor-control-field-description">{{{ data.description }}}</div>
        <# } #>
        <?php
    }
}