<?php

/**
 * Sets up theme defaults and registers support for various WordPress features.
 * Note that this function is hooked into the after_setup_theme hook, which  runs before the init hook. 
 * The init hook is too late for some features, such as indicating support for post thumbnails.
 * 
 * @package Glaciers
 * @since 1.0.0
 */

function glaciers_setup()
{
	/*
	* Make theme available for translation.
	* Translations can be filed in the /languages/ directory.
	* If you're building a theme based on Glaciers, use a find and replace to change 'glaciers' to the name of your theme in all the template files.
	*/
	load_theme_textdomain('glaciers', get_template_directory() . '/languages');

	// Additional support
	add_theme_support('automatic-feed-links');
	add_theme_support('title-tag');
	add_theme_support('customize-selective-refresh-widgets');
	add_theme_support('responsive-embeds');
	add_theme_support('custom-line-height');
	add_theme_support('experimental-link-color');
	add_theme_support('custom-spacing');
	add_theme_support('custom-units');
	add_theme_support('post-thumbnails');
	add_post_type_support('page', 'excerpt');
	add_theme_support('wp-block-styles');
	add_theme_support('align-wide');

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus(
		array(
			'primary' => esc_html__('Primary', 'glaciers'),
			'footer' => esc_html__('Footer', 'glaciers'),
			'social' => esc_html__('Social', 'glaciers'),
		)
	);

	// Switch default core markup for search form, comment form, and comments to output valid HTML5.
	add_theme_support(
		'html5',
		array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
			'style',
			'script',
		)
	);

	// Set up the WordPress core custom background feature.
	add_theme_support(
		'custom-background',
		apply_filters(
			'glaciers_custom_background_args',
			array(
				'default-color' => 'e9e9e9',
				'default-image' => '',
			)
		)
	);

	// Add support for core custom logo.
	add_theme_support(
		'custom-logo',
		array(
			'flex-width'  => true,
			'flex-height' => true,
		)
	);

	// Add editor styles to the block editor.
	add_theme_support('editor-styles');
	$editor_styles = apply_filters(
		'glaciers_editor_styles',
		array(
			'assets/css/editor-style.css',
		)
	);
	add_editor_style($editor_styles);

	// Block Editor color palette.
	$primary = get_theme_mod('glaciers_custom_primary_colour', '#35a0a7');
	$secondary    = get_theme_mod('glaciers_custom_secondary_colour', '#a66335');
	$tertiary    = get_theme_mod('glaciers_custom_tertiary_colour', '#145559');
	$black      = get_theme_mod('#000');
	$white     = get_theme_mod('#fff');

	add_theme_support(
		'editor-color-palette',
		array(
			array(
				'name'  => esc_html__('Black', 'glaciers'),
				'slug'  => 'black',
				'color' => esc_attr($black),
			),

			array(
				'name'  => esc_html__('White', 'glaciers'),
				'slug'  => 'white',
				'color' => esc_attr($white),
			),

			// Custom primary, secondary, and tertiary colours
			array(
				'name'  => esc_html__('Primary', 'glaciers'),
				'slug'  => 'primary',
				'color' => esc_attr($primary),
			),
			array(
				'name'  => esc_html__('Secondary', 'glaciers'),
				'slug'  => 'secondary',
				'color' => esc_attr($secondary),
			),
			array(
				'name'  => esc_html__('Tertiary', 'glaciers'),
				'slug'  => 'tertiary',
				'color' => esc_attr($tertiary),
			),
		)
	);

	// Add custom editor font sizes.
	add_theme_support(
		'editor-font-sizes',
		array(
			array(
				'name'      => esc_html__('Extra small', 'glaciers'),
				'shortName' => esc_html_x('XS', 'Font size', 'glaciers'),
				'size'      => 14,
				'slug'      => 'extra-small',
			),
			array(
				'name'      => esc_html__('Small', 'glaciers'),
				'shortName' => esc_html_x('S', 'Font size', 'glaciers'),
				'size'      => 16,
				'slug'      => 'small',
			),
			array(
				'name'      => esc_html__('Medium', 'glaciers'),
				'shortName' => esc_html_x('M', 'Font size', 'glaciers'),
				'size'      => 18,
				'slug'      => 'medium',
			),
			array(
				'name'      => esc_html__('Large', 'glaciers'),
				'shortName' => esc_html_x('L', 'Font size', 'glaciers'),
				'size'      => 20,
				'slug'      => 'large',
			),
			array(
				'name'      => esc_html__('Extra large', 'glaciers'),
				'shortName' => esc_html_x('XL', 'Font size', 'glaciers'),
				'size'      => 22,
				'slug'      => 'extra-large',
			),
			array(
				'name'      => esc_html__('Huge', 'glaciers'),
				'shortName' => esc_html_x('XXL', 'Font size', 'glaciers'),
				'size'      => 26,
				'slug'      => 'huge',
			),
			array(
				'name'      => esc_html__('Gigantic', 'glaciers'),
				'shortName' => esc_html_x('XXXL', 'Font size', 'glaciers'),
				'size'      => 32,
				'slug'      => 'gigantic',
			),
		)
	);
}
add_action('after_setup_theme', 'glaciers_setup');
