<?php
/**
 * Tarantula functions and definitions
 */

if ( ! function_exists( 'tarantula_support' ) ) {

	// Sets up theme defaults and registers support for various WordPress features.
	function tarantula_support() {

		// Add support for block styles.
		add_theme_support( 'wp-block-styles' );

		// Enqueue editor styles.
		add_editor_style( 'style.css' );

	}
}
add_action( 'after_setup_theme', 'tarantula_support' );

if ( ! function_exists( 'tarantula_styles' ) ) {
	// Enqueue styles.
	function tarantula_styles() {

		// Register theme stylesheet.
		wp_register_style(
			'tarantula-style',
			get_template_directory_uri() . '/assets/css/theme.min.css',
			array(),
			wp_get_theme()->get( 'Version' )
		);

		// Add styles inline.
		wp_add_inline_style( 'tarantula-style', tarantula_get_font_face_styles() );

		// Enqueue theme stylesheet.
		wp_enqueue_style( 'tarantula-style' );

	}
}
add_action( 'wp_enqueue_scripts', 'tarantula_styles' );

if ( ! function_exists( 'tarantula_editor_styles' ) ) {
	// Enqueue editor styles.
	function tarantula_editor_styles() {
		// Add styles inline.
		wp_add_inline_style( 'wp-block-library', tarantula_get_font_face_styles() );

		add_editor_style(
			get_template_directory_uri() . '/assets/css/theme.min.css'
		);
	}
}
add_action( 'admin_init', 'tarantula_editor_styles' );

// Get font face styles.
if ( ! function_exists( 'tarantula_get_font_face_styles' ) ) {
	function tarantula_get_font_face_styles() {
		return "
		@font-face{
			font-family: 'Merriweather';
			font-weight: 100;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Light.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 100;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-LightItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 200;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Light.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 200;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-LightItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 300;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Light.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 300;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-LightItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 400;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Regular.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 400;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Italic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 500;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Regular.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 500;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Italic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 600;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Bold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 600;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-BoldItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 700;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Bold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 700;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-BoldItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 800;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Bold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 800;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-BoldItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 900;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-Black.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Merriweather';
			font-weight: 900;
			font-style: italic;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Merriweather-BlackItalic.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 100;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-ExtraLight.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 200;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-ExtraLight.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 300;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Light.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 400;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Regular.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 500;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Medium.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 600;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-SemiBold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 700;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Bold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 800;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Bold.woff2' ) . "') format('woff2');
		}
		@font-face{
			font-family: 'Oswald';
			font-weight: 900;
			font-style: normal;
			font-stretch: normal;
			font-display: swap;
			src: url('" . get_theme_file_uri( 'assets/fonts/Oswald-Bold.woff2' ) . "') format('woff2');
		}
		";
	}
}

// Add script to Editor
if ( ! function_exists( 'tarantula_admin_add_scripts' ) ) {
	function tarantula_admin_add_scripts( $hook ){
		if ( 'appearance_page_tarantula' != $hook ) {
			return;
		}
		
		wp_register_style( 'tarantula-settings-css',  get_template_directory_uri() . '/assets/css/admin.min.css' , '1.0.0' );
		wp_enqueue_style( 'tarantula-settings-css');
	
	}
}
add_action( 'admin_enqueue_scripts', 'tarantula_admin_add_scripts');

// Add admin page content
get_template_part( 'inc/theme' );

// Add admin page
if ( ! function_exists( 'tarantula_create_menu' ) ) {
	add_action( 'admin_menu', 'tarantula_create_menu' );
	// Adds our dashboard menu item
	function tarantula_create_menu() {
		add_theme_page( 'Tarantula WordPress Theme', 'Tarantula', 'edit_theme_options', 'tarantula', 'tarantula_admin_theme_page' );
	}
}