<?php
/**
    * The Block
    * https://theblocktheme.com
    *
    * @package The Block
    * @author  Luan Gjokaj <luan@thethemefoundry.com>
    * @link    https://thethemefoundry.com
 */

if (! function_exists('the_block_support')) :
  function the_block_support() {
    add_theme_support('wp-block-styles');
    add_editor_style('style.css');
    add_theme_support('align-wide');
    add_theme_support('woocommerce', [
      'thumbnail_image_width' => 512,
      'gallery_thumbnail_image_width' => 512,
      'single_image_width' => 512,
    ]);
  }
endif;
add_action('after_setup_theme', 'the_block_support');

if (! function_exists('the_block_styles')) :
  function the_block_styles() {
    $theme_version = wp_get_theme()->get('Version');
    $version_string = is_string($theme_version) ? $theme_version : false;
    wp_register_style(
      'the_block_style',
      get_template_directory_uri() . '/style.css',
      [],
      $version_string
    );
    wp_enqueue_style('the_block_style');
  }
endif;
add_action('wp_enqueue_scripts', 'the_block_styles');

function the_block_enqueue_scripts() {
  wp_enqueue_script('footer-script', get_template_directory_uri() . '/js/footer-bundle.js', [], true);
}
add_action('wp_enqueue_scripts', 'the_block_enqueue_scripts');

require_once dirname(__FILE__) . '/inc/class-tgm-plugin-activation.php';

add_action('tgmpa_register', 'the_block_register_required_plugins');

function the_block_register_required_plugins() {
  $plugins = [
    [
      'name' => 'HappyForms',
      'slug' => 'happyforms',
      'required' => false,
      'is_callable' => 'HappyForms',
    ],
  ];

  $config = [
    'id'           => 'tgmpa',                 // Unique ID for hashing notices for multiple instances of TGMPA.
    'default_path' => '',                      // Default absolute path to bundled plugins.
    'menu'         => 'tgmpa-install-plugins', // Menu slug.
    'parent_slug'  => 'themes.php',            // Parent menu slug.
    'capability'   => 'edit_theme_options',    // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
    'has_notices'  => true,                    // Show admin notices or not.
    'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
    'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
    'is_automatic' => false,                   // Automatically activate plugins after installation or not.
    'message'      => '',                      // Message to output right before the plugins table.
  ];

  tgmpa($plugins, $config);
}

require_once get_template_directory() . '/inc/class-modal.php';

function the_block_theme_activation() {
  $modal = The_Block_Modal::instance();
  $modal->activate();
}
add_action('after_switch_theme', 'the_block_theme_activation');
