<?php

/**
 * Font setting
 */

function neatnote_font_choices()
{
	$font_family_arr     = array();
	$font_family_arr[''] = esc_html__('Select Font', 'neatnote');

	// Make the request.
	$request = wp_remote_get(get_theme_file_uri('assets/fonts/neatnote-webfonts.json'));

	if (is_wp_error($request)) {
		return false;
	}
	// Retrieve the data.
	$body = wp_remote_retrieve_body($request);
	$data = json_decode($body);
	if (! empty($data)) {
		foreach ($data->items as $items => $fonts) {
			$family_str_arr                   = explode(' ', $fonts->family);
			$family_value                     = implode('+', $family_str_arr);
			$font_family_arr[$family_value] = $fonts->family;
		}
	}
	return $font_family_arr;
}

$wp_customize->add_setting(
	'neatnote_body_fonts',
	array(
		'default'           => '',
		'sanitize_callback' => 'neatnote_sanitize_google_fonts',
	)
);

$wp_customize->add_control(
	'neatnote_body_fonts',
	array(
		'label'    => esc_html__('Neatnote Body Font Family', 'neatnote'),
		'section'  => 'neatnote_theme_general_settings',
		'settings' => 'neatnote_body_fonts',
		'type'     => 'select',
		'choices'  => neatnote_font_choices(),
	)
);
