<?php
/**
 * Kvarken functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Kvarken
 */

/* width     bredd */
if ( ! isset( $content_width ) ) {
	$content_width = 560;
}

if ( ! function_exists( 'kvarken_setup' ) ) {
	/**
	 * Theme setup
	 */
	function kvarken_setup() {
		$kvarken_ch = array( // Custom header settings.
			'default-image'      => get_template_directory_uri() . '/images/headers/seagull.png',
			'random-default'     => false,
			'width'              => 960,
			'height'             => 300,
			'flex-height'        => true,
			'flex-width'         => true,
			'uploads'            => true,
			'header-text'        => true,
			'default-text-color' => '222',
			'wp-head-callback'   => 'kvarken_header_textcolor',
		);

		add_theme_support( 'custom-header', $kvarken_ch );
		add_theme_support( 'custom-background' );
		add_theme_support( 'custom-logo' );

		/**
		 * Replace the previous logo option with the WordPress custom logo.
		 * We want users to upgrade to the latest WordPress version, that is why no fallback is included.
		 * Check if the new logo option is already set and if there is a logo saved in the old option.
		 */
		if ( ! has_custom_logo() && get_theme_mod( 'kvarken_logo' ) ) {
			set_theme_mod( 'custom_logo', attachment_url_to_postid( get_theme_mod( 'kvarken_logo' ) ) );
			remove_theme_mod( 'kvarken_logo' );
		}

		add_theme_support( 'post-thumbnails' );
		set_post_thumbnail_size( 190, 190 );
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'title-tag' );
		add_editor_style();

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		/* translate */
		load_theme_textdomain( 'kvarken', get_template_directory() . '/languages' );

		/* add menu */
		register_nav_menus( array( 'header' => __( 'Header Navigation', 'kvarken' ) ) );

		register_default_headers(
			array(
			'sunset' => array(
				'url' => '%s/images/headers/sunset.png',
				'thumbnail_url' => '%s/images/headers/sunset-thumb.png',
				/* translators: header image description */
				'description' => __( 'Sunset', 'kvarken' ),
			),
			'stones' => array(
				'url' => '%s/images/headers/stones.png',
				'thumbnail_url' => '%s/images/headers/stones-thumb.png',
				/* translators: header image description */
				'description' => __( 'Stones', 'kvarken' ),
			),
			'flower' => array(
				'url' => '%s/images/headers/flora.png',
				'thumbnail_url' => '%s/images/headers/flora-thumb.png',
				/* translators: header image description */
				'description' => __( 'Flower', 'kvarken' ),
			),
			'cloudy' => array(
				'url' => '%s/images/headers/acloudyday.png',
				'thumbnail_url' => '%s/images/headers/acloudyday-thumb.png',
				/* translators: header image description */
				'description' => __( 'A cloudy day', 'kvarken' ),
			),
			'seagull' => array(
				'url' => '%s/images/headers/seagull.png',
				'thumbnail_url' => '%s/images/headers/seagull-thumb.png',
				/* translators: header image description */
				'description' => __( 'Seagull', 'kvarken' ),
			),
			'birdsonrock' => array(
				'url' => '%s/images/headers/birdsonrock.png',
				'thumbnail_url' => '%s/images/headers/birdsonrock-thumb.png',
				/* translators: header image description */
				'description' => __( 'Birds On Rock', 'kvarken' ),
			),
			'sunset2' => array(
				'url' => '%s/images/headers/sunset2.png',
				'thumbnail_url' => '%s/images/headers/sunset2-thumb.png',
				/* translators: header image description */
				'description' => __( 'Sunset', 'kvarken' ),
			),
			'sunset2' => array(
				'url' => '%s/images/headers/sunset3.png',
				'thumbnail_url' => '%s/images/headers/sunset3-thumb.png',
				/* translators: header image description */
				'description' => __( 'Sunset', 'kvarken' ),
			),
			)
		);
	}
}
add_action( 'after_setup_theme', 'kvarken_setup' );

/* Enqueue fonts */
function kvarken_fonts_styles() {
	wp_enqueue_style( 'kvarken_style', get_stylesheet_uri() );
	wp_enqueue_style( 'kvarken_font2', '//fonts.googleapis.com/css?family=Oswald&subset=latin,latin-ext' );

	if ( get_theme_mod( 'kvarken_hide_shadows' ) == '' ) {
		wp_enqueue_style( 'kvarken_shadow', get_template_directory_uri() . '/css/shadow.css' );
	}

	if ( get_theme_mod( 'kvarken_genericons' ) ) {
		wp_enqueue_style( 'kvarken_genericons', get_template_directory_uri() . '/css/icons.css' );
	}

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	wp_enqueue_script( 'kvarken-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20190509', true );
	wp_enqueue_script( 'kvarken-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20190509', true );
}
add_action( 'wp_enqueue_scripts', 'kvarken_fonts_styles' );

/**
 * Register widget areas (Sidebars)        Skapa sidebars
 */
function kvarken_widgets_init() {
	register_sidebar(
		array(
			'id'          => 'sidebar-1',
			'name'        => __( 'Right Hand Sidebar', 'kvarken' ),
			'description' => __( 'Widgets in this area will be shown on the right-hand side.', 'kvarken' ),
		)
	);

	register_sidebar(
		array(
			'id'          => 'sidebar-2',
			'name'        => __( 'Footer Sidebar', 'kvarken' ),
			'description' => __( 'Widgets in this area will be shown in the footer.', 'kvarken' ),
		)
	);
}
add_action( 'widgets_init', 'kvarken_widgets_init' );

// Customizer.
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/class-customize.php';

require get_template_directory() . '/inc/extras.php';
