<?php
namespace WPEventGenius\Common\Registration\Field;
use WPEventGenius\Common\Registration\Submission\Validator;

if ( ! defined( 'ABSPATH' ) ) {
	exit; 
}

class SingleCheckboxType extends BaseFieldType {
	public function get_type() {
		return 'single-checkbox';
	}

	public function hidden_label() {
		return true;
	}

	public function get_value( $registration_data = array() ) {
		$slug = $this->get_slug();
		if ( ! array_key_exists( $slug, $registration_data ) ) {
			return '';
		}
		$stored = $registration_data[ $slug ];
		if ( Validator::is_absent_submission_value( $stored ) ) {
			return '';
		}
		return 'true';
	}

	public function is_valid( Validator $validator, $value ) {
		return $validator->single_checkbox( $value );
	}
}