<?php

namespace BWDK\Core;

use BWDK\Admin\Assets as AdminAssets;
use BWDK\Admin\SettingsPage;
use BWDK\API\AjaxHandler;
use BWDK\Front\Assets as FrontAssets;
use BWDK\Integrations\Digify\Routes\CallbackRoute;
use BWDK\Support\Constant;
use BWDK\Woo\Order\OrderListColumns;
use BWDK\Woo\Order\OrderMetabox;
use BWDK\Woo\SingleBuyEndpoint;
use BWDK\Woo\WooHooks;

class ServiceProvider
{
    public function register(): void
    {
        // غیرفعال‌سازی ایمیل خوشامد برای کاربران خودکار
        add_filter('woocommerce_email_enabled_customer_new_account', function ($enabled, $email) {
            if (!isset($email->object) || !($email->object instanceof \WP_User)) {
                return $enabled;
            }
            $user_id = $email->object->ID ?? 0;
            if ($user_id && get_user_meta($user_id, Constant::META_AUTO_CREATED, true)) {
                return false;
            }
            return $enabled;
        }, 10, 2);

        App::bind(AjaxHandler::class, new AjaxHandler());
        App::get(AjaxHandler::class)->register();

        App::bind(CallbackRoute::class, new CallbackRoute());
        App::get(CallbackRoute::class)->register();

        App::bind(SingleBuyEndpoint::class, new SingleBuyEndpoint());
        App::get(SingleBuyEndpoint::class)->register();

        if (is_admin()) {

            App::bind(SettingsPage::class, new SettingsPage());
            App::bind(AdminAssets::class, new AdminAssets());

            App::get(SettingsPage::class)->register();
            App::get(AdminAssets::class)->register();


            App::bind(OrderListColumns::class, new OrderListColumns());
            App::get(OrderListColumns::class)->register();

            App::bind(OrderMetabox::class, new OrderMetabox());
            App::get(OrderMetabox::class)->register();





        } else {


            App::bind(FrontAssets::class, new FrontAssets());
            App::get(FrontAssets::class)->register();



            App::bind(WooHooks::class, new WooHooks());
            App::get(WooHooks::class)->register();





        }

    }
}
