<?php

if (!class_exists('SEPSectionSeparator')) {

    class SEPSectionSeparator
    {
        public function __construct()
        {
            add_action('init', [$this, 'onInit']);
            add_action('enqueue_block_assets', [$this, 'enqueueBlockAssets']);
        }

        public function onInit()
        {
            register_block_type(__DIR__ . '/build');
        }

        public function enqueueBlockAssets()
        {
            wp_register_script('paperJS', SEP_DIR_URL . 'public/js/paper-full.min.js', [], '0.12.15', true);
            $handle = 'sep-inline-premium';
            wp_register_script($handle, false, [], SEP_VERSION, true);
            $data = [
                'isPremium' => function_exists('sepIsPremium') ? sepIsPremium() : false,
                'hasPro' => defined('SEP_HAS_PRO') ? SEP_HAS_PRO : false,
                'version' => defined('SEP_VERSION') ? SEP_VERSION : '',
            ];
            $inline = 'window.sepSeparator = Object.assign(window.sepSeparator || {}, ' . wp_json_encode($data) . ');';
            wp_add_inline_script($handle, $inline, 'before');
            wp_enqueue_script($handle);
        }
    }

    new SEPSectionSeparator();
}
