<?php

/**
 * transsocial-theme's functions and definitions
 *
 * @package transsocial-theme
 * @since transsocial-theme 1.0
 */

/**
 * First, let's set the maximum content width based on the theme's
 * design and stylesheet.
 * This will limit the width of all uploaded images and embeds.
 */
if (!isset($content_width)) {
  $content_width = 800; /* pixels */
}


if (!function_exists('transsocialtheme_setup')) :

  /**
   * Sets up theme defaults and registers support for various
   * WordPress features.
   *
   * Note that this function is hooked into the after_setup_theme
   * hook, which runs before the init hook. The init hook is too late
   * for some features, such as indicating support post thumbnails.
   */
  function transsocialtheme_setup()
  {

    // /**
    //  * Make theme available for translation.
    //  * Translations can be placed in the /languages/ directory.
    //  */
    // load_theme_textdomain( 'transsocial-theme', get_template_directory() . '/languages' );

    // /**
    //  * Add default posts and comments RSS feed links to <head>.
    //  */
    // add_theme_support( 'automatic-feed-links' );

    // /**
    //  * Enable support for post thumbnails and featured images.
    //  */
    // add_theme_support( 'post-thumbnails' );

    // /**
    //  * Add support for two custom navigation menus.
    //  */
    // register_nav_menus( array(
    // 	'primary'   => __( 'Primary Menu', 'transsocial-theme' ),
    // 	'secondary' => __( 'Secondary Menu', 'transsocial-theme' ),
    // ) );

    // /**
    //  * Enable support for the following post formats:
    //  * aside, gallery, quote, image, and video
    //  */
    // add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );

    $styled_blocks = ['post-title'];
    foreach ($styled_blocks as $block_name) {
      $args = array(
        'handle' => "myfirsttheme-$block_name",
        'src'    => get_theme_file_uri("assets/css/blocks/$block_name.css"),
        $args['path'] = get_theme_file_path("assets/css/blocks/$block_name.css"),
      );
      wp_enqueue_block_style("core/$block_name", $args);
    }

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

    // add_filter('render_block', function ($blockContent, $block) {

    //   if ($block['blockName'] !== 'core/post-title') {
    //     return $blockContent;
    //   }

    //   $pattern = '/(<h[^>]*>)(.*)(<\/h[1-7]{1}>)/i';
    //   $replacement = '$1<span>$2</span>$3';
    //   return preg_replace($pattern, $replacement, $blockContent);
    // }, 10, 2);
  }
endif; // transsocialtheme_setup
add_action('after_setup_theme', 'transsocialtheme_setup');

if (!function_exists('transsocialtheme_enqueue')) :
  function transsocialtheme_enqueue()
  {
    wp_enqueue_style('style', get_stylesheet_uri());
  }
endif;
add_action('wp_enqueue_scripts', 'transsocialtheme_enqueue');
