<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class Reactify_Select extends Reactify_Field {
    public $values;
    public $selected;

    public function setValues( $values ) {
        $this->values = $values;
        return $this;
    }

    public function setDefault( $selected ) {
        $this->selected = $selected;
        return $this;
    }

    public function build() {
        $is_disabled = $this->disabled ? 'disabled' : '';

        echo "<div class='" . esc_attr( $this->classes ) . "'>";

        // Label with HTML allowed
        if ( $this->label != '' ) {
            echo "<label for='" . esc_attr( $this->id ) . "'>" . wp_kses_post( $this->label ) . "</label>";
        }

        echo "<select name='" . esc_attr( $this->id ) . "' id='" . esc_attr( $this->id ) . "' class='reactify-custom-select form-control' {$is_disabled}>";

        foreach ( $this->values as $key => $value ) {
            $is_selected = ( $this->selected == $key ) ? 'selected' : '';
            echo "<option value='" . esc_attr( $key ) . "' " . esc_attr( $is_selected ) . ">" . wp_kses_post( $value ) . "</option>";
        }

        echo "</select></div>";
    }

}