<?php
/**
 * Custom Base Class
 *
 * @package errigal
 * @since 1.1.0
 */

namespace Errigal\Customiser;

defined( 'ABSPATH' ) || exit;

use Errigal\Shared\Errigal_Validator as Validator;

/**
 * This class is in charge of providing shared custom option functions.
 *
 * @since 1.1.0
 */
abstract class Errigal_Custom_Base {
	/**
	 * Gets theme mod: bool.
	 *
	 * @since 1.2.0
	 *
	 * @param bool $name          Theme modification name.
	 * @param bool $default_value Theme modification default value.
	 * @return bool
	 */
	protected static function get_theme_mod_bool( $name, $default_value ) {
		if (
			! Validator::is_non_empty_string( $name ) &&
			! is_bool( $default_value )
		) {
			return false;
		}

		$theme_mod = get_theme_mod( $name, $default_value );

		return is_bool( $theme_mod )
			? $theme_mod
			: $default_value;
	}

	/**
	 * Gets theme mod: int.
	 *
	 * @since 1.2.0
	 *
	 * @param int $name          Theme modification name.
	 * @param int $default_value Theme modification default value.
	 * @return int
	 */
	protected static function get_theme_mod_int( $name, $default_value ) {
		if (
			! Validator::is_non_empty_string( $name ) &&
			! is_int( $default_value )
		) {
			return 0;
		}

		$theme_mod = get_theme_mod( $name, $default_value );

		return is_numeric( $theme_mod )
			? (int) $theme_mod
			: $default_value;
	}

	/**
	 * Gets theme mod: string.
	 *
	 * @since 1.2.0
	 *
	 * @param string $name          Theme modification name.
	 * @param string $default_value Theme modification default value.
	 * @return string
	 */
	protected static function get_theme_mod_string( $name, $default_value ) {
		if (
			! Validator::is_non_empty_string( $name ) &&
			! is_string( $default_value )
		) {
			return '';
		}

		$theme_mod = get_theme_mod( $name, $default_value );

		return is_string( $theme_mod )
			? $theme_mod
			: $default_value;
	}
}
