<?php
namespace EPWF\Includes;
use EPWF\Admin\Admin;
use EPWF\PublicFacing\Frontend;
defined('ABSPATH')||exit;
class Init {
    public function run(){
        $l=new Loader();$s=new Settings();$ai=new AI_Client($s);
        $m=new FAQ_Manager($s,$ai);$fe=new Frontend($s,$m);
        $hk=new Hooks($s,$fe);$ad=new Admin($s,$m);
        if(is_admin()){
            $l->add_action('admin_menu',$ad,'menu');
            $l->add_action('admin_init',$ad,'register_settings');
            $l->add_action('admin_enqueue_scripts',$ad,'assets',10,1);
            $l->add_action('add_meta_boxes',$ad,'meta_box');
            $l->add_action('save_post_product',$ad,'save_meta',10,2);
            $l->add_action('wp_ajax_epwf_regenerate',$ad,'ajax_regenerate');
        }
        $l->add_action('save_post_product',$m,'maybe_auto_generate',20,2);
        $l->add_action('wp_enqueue_scripts',$fe,'assets');
        $l->add_action('init',$hk,'attach',20);
        // Register [woofaq_ai] shortcode
        add_shortcode( 'productfaq_ai', [ $fe, 'render_shortcode' ] );
        $l->add_filter('update_option_'.EPWF_OPTION_KEY,$hk,'reattach',10,2);
        $l->run();
    }
}
