<?php
if (!defined('ABSPATH')) exit;

class SS_Glossary_Setup {

    public static function init() {
        register_activation_hook(SEARCHSHIFTER_PLUGIN_FILE, [self::class, 'create_page']);
    }

    public static function create_page() {

        $existing = get_page_by_path('glossary');

        if ($existing) {
            update_option('ss_glossary_page_id', $existing->ID);
            return;
        }

        $page_id = wp_insert_post([
            'post_title'   => 'Glossary',
            'post_name'    => 'glossary',
            'post_type'    => 'page',
            'post_status'  => 'publish',
            'post_content' => '[searchshifter_glossary]'
        ]);

        if ($page_id && !is_wp_error($page_id)) {
            update_option('ss_glossary_page_id', $page_id);
        }
    }
}