<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/* https://gorigoricode.com/css-slideshow/ */
function haup_header_slider_content_sc_init(){
$post_title = get_the_title();
$site_title = get_bloginfo( 'name' );

if(is_front_page() || is_home()){
	$simage_alt = $site_title;
}else{
	$simage_alt = $post_title.'|'.$site_title;
}

return '
<div class="slide">
	<div class="slide-image" decoding="async" loading="eager" alt="'.$simage_alt.'"></div>
	<div class="slide-image" decoding="async" loading="lazy" alt="'.$simage_alt.'"></div>
	<div class="slide-image" decoding="async" loading="lazy" alt="'.$simage_alt.'"></div>
</div>
';
}
add_shortcode('ha-slide-image','haup_header_slider_content_sc_init');

function haup_slider_shortcode_style_init(){
	if(isset( GetOP07_addcontent()['header-slide-image-upload-01'] )){
		$fimage_url = esc_url(GetOP07_addcontent()['header-slide-image-upload-01']);
	}else{
		$fimage_url = '';
	}
	
	if(isset( GetOP07_addcontent()['header-slide-image-upload-02'] )){
		$simage_url = esc_url(GetOP07_addcontent()['header-slide-image-upload-02']);
	}else{
		$simage_url = '';
	}

	if(isset( GetOP07_addcontent()['header-slide-image-upload-03'] )){
		$timage_url = esc_url(GetOP07_addcontent()['header-slide-image-upload-03']);
	}else{
		$timage_url = '';
	}

	/* スライダーの高さ */
	if(isset( GetOP07_addcontent()['header-slide-image-height'] )){
		$slider_h = absint(GetOP07_addcontent()['header-slide-image-height']);
	}else{
		$slider_h = '';
	}

	if(empty( $slider_h )){
		$i_height = '500';
	}else{
		$i_height = absint($slider_h);
	}
	
	/* 全幅表示 */
	if(isset( GetOP07_addcontent()['header-slide-image-full-width'] )){
		$slider_w = absint(GetOP07_addcontent()['header-slide-image-full-width']);
	}else{
		$slider_w = '';
	}

	if(empty( $slider_w )){
		$full_width = 'width: 100%;';
	}else{
		$full_width = 'width: 100vw;  margin-left: calc(-50vw + 50%);';
	}


$custom_css_pre = hau_sanitize_css('
/* HAUP Slide Shortcode */
.slide {
	position: relative;
	'.$full_width.'
	height: '.$i_height.'px;
	min-height: '.$i_height.'px;
	overflow: hidden;
}

.slide-image{
	background-position: center;
	background-repeat: no-repeat;
	background-size: cover;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	animation: slider-1 24s linear infinite;
}

.slide-image:nth-child(1){
	background-image: url('.$fimage_url.');
	animation-delay: -2s;
}

.slide-image:nth-child(2){
	background-image: url('.$simage_url.');
	animation-delay: 6s;
}

.slide-image:nth-child(3){
	background-image: url('.$timage_url.');
	animation-delay: 14s;
}

@keyframes slider-1 {
	0% {
		opacity: 0;
		transform: scale(1);
	}
	4.16% {
		opacity: 1;
	}
	33.33% {
		opacity: 1;
	}
	41.66% {
		opacity: 0;
		transform: scale(1.2);
	}
	100% {
		opacity: 0;
	}
}
');

//タブを除去
$custom_css_deltab = preg_replace('/\t+/', '', $custom_css_pre);
//改行を除去
$custom_css = str_replace(PHP_EOL, '', $custom_css_deltab);

wp_add_inline_style( 'haup-front-and-blocks-style', $custom_css );//インラインでCSS出力

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