<?php

/* ==========================================================================
 *  General
 * ========================================================================== */

function realizer_after_setup_theme() {
	add_theme_support( 'woocommerce' );
	add_theme_support( 'title-tag' );
	add_post_type_support( 'page', 'excerpt' );
}
add_action( 'after_setup_theme', 'realizer_after_setup_theme' );

function realizer_wp_enqueue_scripts() {
	wp_enqueue_style( 'realizer-style', get_stylesheet_uri() );

	// If you write the following in customizer.php, an error will occur.
	if ( get_theme_mod ( 'realizer_fontawesome_setting', true ) == "is-on" ) {
		wp_enqueue_style( 'fontawesome-free-6.7.2-web', get_theme_file_uri( '/assets/fontawesome-free-6.7.2-web/css/all.min.css' ) );
	}

	if ( get_theme_mod ( 'realizer_pagetop_button_setting', true ) == "is-on" ) {
		wp_enqueue_style( 'realizer-pagetop', esc_url( get_template_directory_uri() ) . '/assets/css/realizer-pagetop.css' );
		wp_enqueue_script( 'realizer-pagetop', esc_url( get_template_directory_uri() ) . '/assets/js/realizer-pagetop.js', array( 'jquery' ) , false, true );
	}
}
add_action( 'wp_enqueue_scripts', 'realizer_wp_enqueue_scripts' );

/* ==========================================================================
 *  Template part areas
 * ========================================================================== */

function realizer_template_part_areas( array $areas ) {
	$areas[] = array(
		'area'			=> 'query',
		'area_tag'		=> 'div',
		'label'			=> __( 'Query', 'realizer' ),
		'description'	=> __( 'The Query template defines a page area that typically contains a list of posts.', 'realizer' ),
		'icon'			=> 'layout'
	);
	return $areas;
}
add_filter( 'default_wp_template_part_areas', 'realizer_template_part_areas' );

/* ==========================================================================
 *  Block Pattern categories
 * ========================================================================== */

function realizer_pattern_categories() {
	register_block_pattern_category( 'realizer', array(
		'label' => __( 'REALIZER', 'realizer' )
	) );
}
add_action( 'init', 'realizer_pattern_categories' );

/* ==========================================================================
 *  Block Style Variations
 * ========================================================================== */

function realizer_block_style_variations() {
	// core/paragraph
	register_block_style( 'core/paragraph', array(
		'name'			=> 'text-shadow',
		'label'			=> __( 'Text shadow', 'realizer' ),
		'inline_style'	=> '
			p.is-style-text-shadow {
				text-shadow: 1px 1px 2px var(--wp--preset--color--realizer-contrast);
			}'
	) );

	// core/heading
	register_block_style( 'core/heading', array(
		'name'			=> 'border-dashed',
		'label'			=> __( 'Border dashed', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-dashed {
				border: dashed;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-dotted',
		'label'			=> __( 'Border dotted', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-dotted {
				border: dotted;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-double',
		'label'			=> __( 'Border double', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-double {
				border: double;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-groove',
		'label'			=> __( 'Border groove', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-groove {
				border: groove;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-ridge',
		'label'			=> __( 'Border ridge', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-ridge {
				border: ridge;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-inset',
		'label'			=> __( 'Border inset', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-inset {
				border: inset;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'border-outset',
		'label'			=> __( 'Border outset', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-border-outset {
				border: outset;
			}'
	) );
	register_block_style( 'core/heading', array(
		'name'			=> 'text-shadow',
		'label'			=> __( 'Text shadow', 'realizer' ),
		'inline_style'	=> '
			.wp-block-heading.is-style-text-shadow {
				text-shadow: 1px 1px 2px var(--wp--preset--color--realizer-contrast);
			}'
	) );

	// core/table
	register_block_style( 'core/table', array(
		'name'			=> 'horizontal-scroll',
		'label'			=> __( 'Horizontal scroll', 'realizer' ),
		'inline_style'	=> '
			@media screen and (max-width: 599px) {
				.wp-block-table.is-style-horizontal-scroll {
					overflow-x: scroll;
				}
				.wp-block-table.is-style-horizontal-scroll table th,
				.wp-block-table.is-style-horizontal-scroll table td {
					white-space: nowrap;
				}
				.wp-block-table.is-style-horizontal-scroll .wp-element-caption {
					white-space: nowrap;
				}
			}'
	) );
	register_block_style( 'core/table', array(
		'name'			=> 'responsive-from-horizontal-to-vertical',
		'label'			=> __( 'Responsive from horizontal to vertical', 'realizer' ),
		'inline_style'	=> '
			@media screen and (max-width: 599px) {
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table {
					overflow-x: scroll;
					width: max-content;
				}
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table thead,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tbody,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tfoot,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tr,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table th,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table td {
					display: block;
				}
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table thead,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tbody,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tfoot,
				.wp-block-table.is-style-responsive-from-horizontal-to-vertical table tr {
					float: left;
				}
			}'
	) );
	register_block_style( 'core/table', array(
		'name'			=> 'responsive-to-vertical-stacking',
		'label'			=> __( 'Responsive to vertical stacking', 'realizer' ),
		'inline_style'	=> '
			@media screen and (max-width: 599px) {
				.wp-block-table.is-style-responsive-to-vertical-stacking table {
					width: 100%;
				}
				.wp-block-table.is-style-responsive-to-vertical-stacking table thead tr th,
				.wp-block-table.is-style-responsive-to-vertical-stacking table tbody tr td,
				.wp-block-table.is-style-responsive-to-vertical-stacking table tfoot tr td {
					display: block;
					width: 100%;
				}
			}'
	) );

	// core/gallery
	register_block_style( 'core/gallery', array(
		'name'			=> 'loop-slide-right-to-left',
		'label'			=> __( 'Loop slide right to left', 'realizer' ),
		'inline_style'	=> '
			.is-root-container .wp-block-group:has(.wp-block-gallery.is-style-loop-slide-right-to-left),
			.entry-content .wp-block-group:has(.wp-block-gallery.is-style-loop-slide-right-to-left) {
				overflow: hidden;
			}
			.wp-block-gallery.is-style-loop-slide-right-to-left {
				animation: loop-slide-right-to-left;
				animation-delay: 0.64s;
				animation-duration: 64s;
				animation-fill-mode: both;
				animation-iteration-count: infinite;
				animation-timing-function: linear;
				flex-wrap: nowrap;
			}
			.is-root-container .wp-block-group:has(.is-style-loop-slide-right-to-left):hover > .wp-block-gallery.is-style-loop-slide-right-to-left,
			.entry-content .wp-block-group:has(.is-style-loop-slide-right-to-left):hover > .wp-block-gallery.is-style-loop-slide-right-to-left {
				animation-play-state: paused;
			}
			.wp-block-gallery.is-style-loop-slide-right-to-left .wp-block-image {
				width: 256px !important;
			}
			@keyframes loop-slide-right-to-left {
				from {
					transform: translateX(0%);
				}
				to {
					transform: translateX(-100%);
				}
			}'
	) );
	register_block_style( 'core/gallery', array(
		'name'			=> 'loop-slide-left-to-right',
		'label'			=> __( 'Loop slide left to right', 'realizer' ),
		'inline_style'	=> '
			.is-root-container .wp-block-group:has(.wp-block-gallery.is-style-loop-slide-left-to-right),
			.entry-content .wp-block-group:has(.wp-block-gallery.is-style-loop-slide-left-to-right) {
				overflow: hidden;
			}
			.wp-block-gallery.is-style-loop-slide-left-to-right {
				animation: loop-slide-left-to-right;
				animation-delay: 0.64s;
				animation-duration: 64s;
				animation-fill-mode: both;
				animation-iteration-count: infinite;
				animation-timing-function: linear;
				flex-wrap: nowrap;
			}
			.is-root-container .wp-block-group:has(.is-style-loop-slide-left-to-right):hover > .wp-block-gallery.is-style-loop-slide-left-to-right,
			.entry-content .wp-block-group:has(.is-style-loop-slide-left-to-right):hover > .wp-block-gallery.is-style-loop-slide-left-to-right {
				animation-play-state: paused;
			}
			.wp-block-gallery.is-style-loop-slide-left-to-right .wp-block-image {
				width: 256px !important;
			}
			@keyframes loop-slide-left-to-right {
				from {
					transform: translateX(-100%);
				}
				to {
					transform: translateX(0%);
				}
			}'
	) );

	// core/group
	register_block_style( 'core/group', array(
		'name'			=> 'fade-in',
		'label'			=> __( 'Fade in', 'realizer' ),
		'inline_style'	=> '
			.wp-block-group.is-style-fade-in {
				animation-name: fade-in;
				animation-timeline: view();
				animation-timing-function: ease;
				opacity: 1;
				transform: none;
			}
			@keyframes fade-in {
				0% {
					opacity: 0;
					}
				25% {
					opacity: 0.25;
				}
				50% {
					opacity: 1;
				}
			}'
	) );
	register_block_style( 'core/group', array(
		'name'			=> 'fade-in-from-bottom-to-top',
		'label'			=> __( 'Fade in from bottom to top', 'realizer' ),
		'inline_style'	=> '
			.wp-block-group.is-style-fade-in-from-bottom-to-top {
				animation-name: fade-in-from-bottom-to-top;
				animation-timeline: view();
				animation-timing-function: ease;
				opacity: 1;
				transform: none;
			}
			@keyframes fade-in-from-bottom-to-top {
				0% {
					opacity: 0;
					transform: translateY(10rem);
					}
				25% {
					opacity: 0.25;
				}
				50% {
					opacity: 1;
					transform: translateY(0);
				}
			}'
	) );
	register_block_style( 'core/group', array(
		'name'			=> 'fade-in-from-left-to-right',
		'label'			=> __( 'Fade in from left to right', 'realizer' ),
		'inline_style'	=> '
			.wp-block-group.is-style-fade-in-from-left-to-right {
				animation-name: fade-in-from-left-to-right;
				animation-timeline: view();
				animation-timing-function: ease;
				opacity: 1;
				transform: none;
			}
			@keyframes fade-in-from-left-to-right {
				0% {
					opacity: 0;
					transform: translateX(-10rem);
					}
				25% {
					opacity: 0.25;
				}
				50% {
					opacity: 1;
					transform: translateX(0);
				}
			}'
	) );
	register_block_style( 'core/group', array(
		'name'			=> 'fade-in-from-top-to-bottom',
		'label'			=> __( 'Fade in from top to bottom', 'realizer' ),
		'inline_style'	=> '
			.wp-block-group.is-style-fade-in-from-top-to-bottom {
				animation-name: fade-in-from-top-to-bottom;
				animation-timeline: view();
				animation-timing-function: ease;
				opacity: 1;
				transform: none;
			}
			@keyframes fade-in-from-top-to-bottom {
				0% {
					opacity: 0;
					transform: translateY(-10rem);
					}
				25% {
					opacity: 0.25;
				}
				50% {
					opacity: 1;
					transform: translateY(0);
				}
			}'
	) );
	register_block_style( 'core/group', array(
		'name'			=> 'fade-in-from-right-to-left',
		'label'			=> __( 'Fade in from right to left', 'realizer' ),
		'inline_style'	=> '
			.wp-block-group.is-style-fade-in-from-right-to-left {
				animation-name: fade-in-from-right-to-left;
				animation-timeline: view();
				animation-timing-function: ease;
				opacity: 1;
				transform: none;
			}
			@keyframes fade-in-from-right-to-left {
				0% {
					opacity: 0;
					transform: translateX(10rem);
					}
				25% {
					opacity: 0.25;
				}
				50% {
					opacity: 1;
					transform: translateX(0);
				}
			}'
	) );

	// core/post-title
	register_block_style( 'core/post-title', array(
		'name'			=> 'text-shadow',
		'label'			=> __( 'Text shadow', 'realizer' ),
		'inline_style'	=> '
			.wp-block-post-title.is-style-text-shadow {
				text-shadow: 1px 1px 2px var(--wp--preset--color--realizer-contrast);
			}'
	) );

	// core/query-title
	register_block_style( 'core/query-title', array(
		'name'			=> 'text-shadow',
		'label'			=> __( 'Text shadow', 'realizer' ),
		'inline_style'	=> '
			.wp-block-query-title.is-style-text-shadow {
				text-shadow: 1px 1px 2px var(--wp--preset--color--realizer-contrast);
			}'
	) );
}
add_action( 'init', 'realizer_block_style_variations' );

/* ==========================================================================
 *  Block Stylesheets
 * ========================================================================== */

function realizer_block_stylesheets() {
	wp_enqueue_block_style( 'core/buttons', array(
		'handle'	=> 'realizer-wp-block-buttons',
		'src'		=> get_theme_file_uri( "assets/blocks/core-buttons.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-buttons.css" )
	) );
	wp_enqueue_block_style( 'core/categories', array(
		'handle'	=> 'realizer-wp-block-categories',
		'src'		=> get_theme_file_uri( "assets/blocks/core-categories.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-categories.css" )
	) );
	wp_enqueue_block_style( 'core/comments-pagination', array(
		'handle'	=> 'realizer-wp-block-comments-pagination',
		'src'		=> get_theme_file_uri( "assets/blocks/core-comments-pagination.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-comments-pagination.css" )
	) );
	wp_enqueue_block_style( 'core/comment-template', array(
		'handle'	=> 'realizer-wp-block-comment-template',
		'src'		=> get_theme_file_uri( "assets/blocks/core-comment-template.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-comment-template.css" )
	) );
	wp_enqueue_block_style( 'core/cover', array(
		'handle'	=> 'realizer-wp-block-cover',
		'src'		=> get_theme_file_uri( "assets/blocks/core-cover.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-cover.css" )
	) );
	wp_enqueue_block_style( 'core/heading', array(
		'handle'	=> 'realizer-wp-block-heading',
		'src'		=> get_theme_file_uri( "assets/blocks/core-heading.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-heading.css" )
	) );
	wp_enqueue_block_style( 'core/image', array(
		'handle'	=> 'realizer-wp-block-image',
		'src'		=> get_theme_file_uri( "assets/blocks/core-image.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-image.css" )
	) );
	wp_enqueue_block_style( 'core/latest-posts', array(
		'handle'	=> 'realizer-wp-block-latest-posts',
		'src'		=> get_theme_file_uri( "assets/blocks/core-latest-posts.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-latest-posts.css" )
	) );
	wp_enqueue_block_style( 'core/media-text', array(
		'handle'	=> 'realizer-wp-block-media-text',
		'src'		=> get_theme_file_uri( "assets/blocks/core-media-text.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-media-text.css" )
	) );
	wp_enqueue_block_style( 'core/navigation', array(
		'handle'	=> 'realizer-wp-block-navigation',
		'src'		=> get_theme_file_uri( "assets/blocks/core-navigation.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-navigation.css" )
	) );
	wp_enqueue_block_style( 'core/post-author-name', array(
		'handle'	=> 'realizer-wp-block-post-author-name',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-author-name.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-author-name.css" )
	) );
	wp_enqueue_block_style( 'core/post-date', array(
		'handle'	=> 'realizer-wp-block-post-date',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-date.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-date.css" )
	) );
	wp_enqueue_block_style( 'core/post-featured-image', array(
		'handle'	=> 'realizer-wp-block-post-featured-image',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-featured-image.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-featured-image.css" )
	) );
	wp_enqueue_block_style( 'core/post-terms', array(
		'handle'	=> 'realizer-wp-block-post-terms',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-terms.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-terms.css" )
	) );
	wp_enqueue_block_style( 'core/post-template', array(
		'handle'	=> 'realizer-wp-block-post-template',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-template.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-template.css" )
	) );
	wp_enqueue_block_style( 'core/post-navigation-link', array(
		'handle'	=> 'realizer-wp-block-post-navigation-link',
		'src'		=> get_theme_file_uri( "assets/blocks/core-post-navigation-link.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-post-navigation-link.css" )
	) );
	wp_enqueue_block_style( 'core/query-pagination', array(
		'handle'	=> 'realizer-wp-block-query-pagination',
		'src'		=> get_theme_file_uri( "assets/blocks/core-query-pagination.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-query-pagination.css" )
	) );
	wp_enqueue_block_style( 'core/rss', array(
		'handle'	=> 'realizer-wp-block-rss',
		'src'		=> get_theme_file_uri( "assets/blocks/core-rss.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-rss.css" )
	) );
	wp_enqueue_block_style( 'core/search', array(
		'handle'	=> 'realizer-wp-block-search',
		'src'		=> get_theme_file_uri( "assets/blocks/core-search.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-search.css" )
	) );
	wp_enqueue_block_style( 'core/table', array(
		'handle'	=> 'realizer-wp-block-table',
		'src'		=> get_theme_file_uri( "assets/blocks/core-table.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-table.css" )
	) );
	wp_enqueue_block_style( 'core/template-part', array(
		'handle'	=> 'realizer-wp-block-template-part',
		'src'		=> get_theme_file_uri( "assets/blocks/core-template-part.css" ),
		'path'		=> get_theme_file_path( "assets/blocks/core-template-part.css" )
	) );
}
add_action( 'init', 'realizer_block_stylesheets' );

/* ==========================================================================
 *  Admin
 * ========================================================================== */

include get_theme_file_path( 'inc/admin.php' );

/* ==========================================================================
 *  Customizer
 * ========================================================================== */

include get_theme_file_path( 'inc/customizer.php' );