<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_Business_Mode
{
    public const LAYOUT_ARCHIVE = 'woo-product-archive';

    public const LAYOUT_SINGLE = 'woo-product-single';

    public static function init(): void
    {
        add_action('after_setup_theme', array(__CLASS__, 'maybe_add_woocommerce_theme_support'));
        add_action('wp_enqueue_scripts', array(__CLASS__, 'maybe_register_gallery_script'), 5);
        add_filter('loop_shop_per_page', array(__CLASS__, 'maybe_set_archive_per_page'), 20);
    }

    public static function maybe_set_archive_per_page($per_page)
    {
        return self::takeover_archive() ? 12 : $per_page;
    }

    public static function maybe_register_gallery_script(): void
    {
        if (! self::is_woo_active()) {
            return;
        }

if (wp_script_is('puffergo-product-gallery', 'registered')) {
            return;
        } wp_register_script('puffergo-product-gallery', plugins_url('assets/js/puffergo-product-gallery.js', PUFFERGO_PLUGIN_FILE), array(), PUFFERGO_CORE_VERSION, true);
    }

    public static function is_woo_active(): bool
    {
        return class_exists('WooCommerce');
    }

    public static function woo_takeover_enabled(): bool
    {
        return self::is_woo_active();
    }

    public static function takeover_archive(): bool
    {
        return self::woo_takeover_enabled() && class_exists('PufferGo_Template_Loader') && PufferGo_Template_Loader::layout_uses_puffergo_template(self::LAYOUT_ARCHIVE);
    }

    public static function takeover_single(): bool
    {
        return self::woo_takeover_enabled() && class_exists('PufferGo_Template_Loader') && PufferGo_Template_Loader::layout_uses_puffergo_template(self::LAYOUT_SINGLE);
    }

    public static function maybe_add_woocommerce_theme_support(): void
    {
        if (! self::is_woo_active()) {
            return;
        } add_theme_support('woocommerce');
    }
}
