<?php

namespace WPT\Cf7Divi\WP;

/**
 * Bootstrap.
 */
class Bootstrap
{
    protected $container;

    /**
     * Constructor.
     */
    public function __construct($container)
    {
        $this->container = $container;
    }

    /**
     * Register activation hook
     */
    public function register_activation_hook()
    {
        flush_rewrite_rules(true);
    }

    public function admin_menu()
    {
        add_submenu_page(
            'wpcf7',
            'Contact Form 7 For Divi',
            'Contact Form 7 For Divi',
            'manage_options',
            'cf7-grid-and-styler-for-divi',
            [$this, 'admin_submenu_page']
        );
    }

    public function admin_submenu_page()
    {
        ob_start();
        require $this->container['plugin_dir'] . '/resources/views/admin_menu/sub_menu.php';
        //phpcs:ignore
        echo ob_get_clean();
    }

    public function after_license_change($status, $plan)
    {
        $expected_plans = ['downgraded', 'cancelled', 'expired', 'trial_expired'];
        if (in_array($status, $expected_plans)) {
            if (class_exists('\ET_Core_PageResource')) {
                \ET_Core_PageResource::remove_static_resources('all', 'all');
            }
        }
    }
}
