<?php

namespace BWDK\Support;

class Activate
{
    public function register()
    {
        register_activation_hook(BWDK_PLUGIN_FILE, [$this, "bwdk_activate"]);
    }

    public function bwdk_activate()
    {
        $slug = 'bwdk-thankyou';
        $bwdk_thankyou_page_id=get_page_by_path($slug)->ID??0;
        if ( !$bwdk_thankyou_page_id ) {
            $bwdk_thankyou_page_id=wp_insert_post([
                'post_title'   => 'پرداخت امن دیجیکالا',
                'post_name'    => $slug,
                'post_status'  => 'publish',
                'post_type'    => 'page',
                'post_content' => '[bwdk_thankyou]',
            ]);
        }
       
       
       if(!get_option(Constant::BWDK_OPTION_NAME)){
           $arg = [
            "api" => [
                'endpoint' => 'https://bwdk-backend.digify.shop/',
                'api-key' => ''
            ],
            "thankyou-page" => [
                "id"=>$bwdk_thankyou_page_id,
            ],
            "force-login" => [
                "status"=>'0'
            ],
            "top-banner"=>[
                "status"=>'1'
            ],
            "product-card"=>[
                "status"=>'1',
                'position' => 'woocommerce_after_shop_loop_item_title'
            ],
            "product-single"=>[
                "status"=>'1',
                'position' => 'woocommerce_after_add_to_cart_button'
            ],
            "product-single-badge"=>[
                "status"=>'1',
                'position' => 'woocommerce_before_single_product_summary'
            ],
            "cart"=>[
                "status"=>'1',
                'position' => 'woocommerce_before_cart_table'
            ],
            "checkout"=>[
                "status"=>'1',
                'position' => 'woocommerce_checkout_billing'
            ],
            "minicart"=>[
                "status"=>'1',
            ],
            "single-buy-button"=>[
                "status"=>'0',
            ],
            "custom"=>[
                "css"=>"",
                "js"=>""
            ]
        ];

        update_option(Constant::BWDK_OPTION_NAME, $arg);
       }

       // Flush rewrite rules
       flush_rewrite_rules();
    
    }
}