<?php
/**
 * Custom header implementation
 *
 * @link https://codex.wordpress.org/Custom_Headers
 *
 * @package Preventive Maintenance
 * @subpackage preventive_maintenance
 */

function preventive_maintenance_custom_header_setup() {
    register_default_headers( array(
        'default-image' => array(
            'url'           => get_template_directory_uri() . '/assets/images/sliderimage.png',
            'thumbnail_url' => get_template_directory_uri() . '/assets/images/sliderimage.png',
            'description'   => __( 'Default Header Image', 'preventive-maintenance' ),
        ),
    ) );
}
add_action( 'after_setup_theme', 'preventive_maintenance_custom_header_setup' );

/**
 * Styles the header image based on Customizer settings.
 */
function preventive_maintenance_header_style() {
    $preventive_maintenance_header_image = get_header_image() ? get_header_image() : get_template_directory_uri() . '/assets/images/sliderimage.png';

    $preventive_maintenance_height     = get_theme_mod( 'preventive_maintenance_header_image_height', 350 );
    $preventive_maintenance_position   = get_theme_mod( 'preventive_maintenance_header_background_position', 'center' );
    $preventive_maintenance_attachment = get_theme_mod( 'preventive_maintenance_header_background_attachment', 1 ) ? 'fixed' : 'scroll';

    $preventive_maintenance_custom_css = "
        .header-img, .single-page-img, .external-div .box-image-page img, .external-div {
            background-image: url('" . esc_url( $preventive_maintenance_header_image ) . "');
            background-size: cover;
            height: " . esc_attr( $preventive_maintenance_height ) . "px;
            background-position: " . esc_attr( $preventive_maintenance_position ) . ";
            background-attachment: " . esc_attr( $preventive_maintenance_attachment ) . ";
        }

        @media (max-width: 1000px) {
            .header-img, .single-page-img, .external-div .box-image-page img,.external-div,.featured-image{
                height: 250px !important;
            }
            .box-text h2{
                font-size: 27px;
            }
        }
    ";

    wp_add_inline_style( 'preventive-maintenance-style', $preventive_maintenance_custom_css );
}
add_action( 'wp_enqueue_scripts', 'preventive_maintenance_header_style' );

/**
 * Enqueue the main theme stylesheet.
 */
function preventive_maintenance_enqueue_styles() {
    wp_enqueue_style( 'preventive-maintenance-style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'preventive_maintenance_enqueue_styles' );