<?php
/**
 * Theme functions and definitions
 *
 * @package Cargo Transport
 */ 

if ( ! function_exists( 'cargo_transport_enqueue_styles' ) ) :
	/**
	 * Load assets.
	 *
	 * @since 1.0.0
	 */
	function cargo_transport_enqueue_styles() {
		wp_enqueue_style( 'cargo-transport-block-patterns-style-frontend', get_theme_file_uri('/css/block-frontend.css') );
		wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
		wp_enqueue_style( 'cargo-transport-style-parent', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'cargo-transport-style', get_stylesheet_directory_uri() . '/style.css', array( 'cargo-transport-style-parent' ), '1.0.0' );
	}
endif;
add_action( 'wp_enqueue_scripts', 'cargo_transport_enqueue_styles');

/**
 * Enqueue block editor style
 */
function cargo_transport_block_editor_styles() {
	wp_enqueue_style( 'logistic-transport-font', logistic_transport_font_url(), array() );
	wp_enqueue_style( 'cargo-transport-block-patterns-style-editor', get_theme_file_uri( '/css/block-editor.css' ), false, '1.0', 'all' );
    wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/css/bootstrap.css' );
    wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/css/fontawesome-all.css' );
}
add_action( 'enqueue_block_editor_assets', 'cargo_transport_block_editor_styles' );

function cargo_transport_customize_register() {
	global $wp_customize;
	$wp_customize->remove_setting( 'logistic_transport_theme_color_first' );
	$wp_customize->remove_control( 'logistic_transport_theme_color_first' );
	$wp_customize->remove_setting( 'logistic_transport_theme_color_second' );
	$wp_customize->remove_control( 'logistic_transport_theme_color_second' );
}
add_action( 'customize_register', 'cargo_transport_customize_register', 11 );

/* Theme Setup */
if ( ! function_exists( 'cargo_transport_setup' ) ) :

function cargo_transport_setup() {

	$GLOBALS['content_width'] = apply_filters( 'cargo_transport_content_width', 640 );

	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );
	add_image_size('cargo-transport-homepage-thumb',240,145,true);

	add_theme_support( 'custom-background', array(
		'default-color' => 'f1f1f1'
	) );

	add_theme_support ('html5', array (
        'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    ) );

	add_theme_support('responsive-embeds');

	add_theme_support( 'post-formats', array('image','video','gallery','audio',) );

	add_editor_style( array( 'css/editor-style.css' ) );
}

endif;
add_action( 'after_setup_theme', 'cargo_transport_setup' );

function cargo_transport_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'cargo-transport' ),
		'description'   => __( 'Appears on blog page sidebar', 'cargo-transport' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s mb-4 p-2">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title pt-0">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'cargo_transport_widgets_init' );

function cargo_transport_enqueue_comments_reply() {
    if( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1) ) {
        wp_enqueue_script( 'comment-reply', '/wp-includes/js/comment-reply.min.js', array(), false, true );
    }
}
add_action( 'wp_enqueue_scripts', 'cargo_transport_enqueue_comments_reply' );

add_action( 'init', 'cargo_transport_remove_action');
function cargo_transport_remove_action() {
    remove_action( 'admin_menu','logistic_transport_gettingstarted' );
    remove_action( 'admin_notices','logistic_transport_activation_notice' );
}

// URL DEFINES
define('CARGO_TRANSPORT_SUPPORT',__('https://wordpress.org/support/theme/cargo-transport/','cargo-transport'));
define('CARGO_TRANSPORT_REVIEW',__('https://wordpress.org/support/theme/cargo-transport/reviews/','cargo-transport'));
define('CARGO_TRANSPORT_BUY_NOW',__('https://www.themescaliber.com/themes/cargo-wordpress-theme','cargo-transport'));
define('CARGO_TRANSPORT_LIVE_DEMO',__('https://www.themescaliber.com/cargo-transport-pro/','cargo-transport'));
define('CARGO_TRANSPORT_PRO_DOC',__('https://themescaliber.com/demo/doc/cargo-transport-pro/','cargo-transport'));
define('CARGO_TRANSPORT_CHILD_THEME',__('https://developer.wordpress.org/themes/advanced-topics/child-themes/','cargo-transport'));
define('CARGO_TRANSPORT_THEME_URL',__('https://www.themescaliber.com/themes/free-cargo-wordpress-theme/', 'cargo-transport'));

if ( ! defined( 'LOGISTIC_TRANSPORT_PRO_NAME' ) ) {
	define( 'LOGISTIC_TRANSPORT_PRO_NAME', esc_html__( 'Cargo Pro Theme', 'cargo-transport' ));
}
if ( ! defined( 'LOGISTIC_TRANSPORT_PRO_URL' ) ) {
	define( 'LOGISTIC_TRANSPORT_PRO_URL', esc_url('https://www.themescaliber.com/themes/cargo-wordpress-theme/'));
}

function cargo_transport_credit_link() {
    echo "<a href=".esc_url(CARGO_TRANSPORT_THEME_URL)." target='_blank'>".esc_html__('Cargo WordPress Theme','cargo-transport')."</a>";
}

/* Implement the get started page */
require get_theme_file_path() . '/inc/dashboard/getstart.php';

/* Block Pattern */
require get_theme_file_path() . '/block-patterns.php';