<?php
    /*
    Plugin Name: <<productname>>
    Plugin URI:
    Description: simple description
    Version: 1.0.0.0
    */

    require_once "<<baseclassname>>.php";

	class <<productname_without_space>> {
        public $plugin_file=__FILE__;
        public $responseObj;
        public $licenseMessage;
        public $showMessage=false;
        public $slug="<<productbase>>";
        function __construct() {
    	    add_action( 'admin_print_styles', [ $this, 'SetAdminStyle' ] );
    	    $licenseKey=get_option("<<productname_without_space>>_lic_Key","");
    	    if(<<baseclassname>>::CheckWPPlugin($licenseKey,$this->licenseMessage,$this->responseObj,__FILE__)){
    		    add_action( 'admin_menu', [$this,'ActiveAdminMenu']);
    		    add_action( 'admin_post_<<productname_without_space>>_el_deactivate_license', [ $this, 'action_deactivate_license' ] );
    		    //$this->licenselMessage=$this->mess;
    	    }else{
    	        if(!empty($licenseKey) && !empty($this->licenseMessage)){
    	           $this->showMessage=true;
                }
    		    update_option("<<productname_without_space>>_lic_Key","") || add_option("<<productname_without_space>>_lic_Key","");
    		    add_action( 'admin_post_<<productname_without_space>>_el_activate_license', [ $this, 'action_activate_license' ] );
    		    add_action( 'admin_menu', [$this,'InactiveMenu']);
    	    }
        }
    	function SetAdminStyle() {
    		wp_register_style( "<<productname_without_space>>Lic", plugins_url("style.css",$this->plugin_file),10);
    		wp_enqueue_style( "<<productname_without_space>>Lic" );
    	}
        function ActiveAdminMenu(){
    	    add_menu_page (  "<<productname_without_space>>", "<<productname>>", 'activate_plugins', $this->slug, [$this,"Activated"], " dashicons-star-filled ");

        }
        function InactiveMenu() {
    	    add_menu_page( "<<productname_without_space>>", "<<productname>>", 'activate_plugins', $this->slug,  [$this,"LicenseForm"], " dashicons-star-filled " );

        }
        function action_activate_license(){
    	    check_admin_referer( 'el-license' );
    	    $licenseKey=!empty($_POST['el_license_key'])?$_POST['el_license_key']:"";
    	    update_option("<<productname_without_space>>_lic_Key",$licenseKey) || add_option("<<productname_without_space>>_lic_Key",$licenseKey);
    	    wp_safe_redirect(admin_url( 'admin.php?page='.$this->slug));
        }
        function action_deactivate_license() {
    	    check_admin_referer( 'el-license' );
    	    if(<<baseclassname>>::RemoveLicenseKey(__FILE__,$message)){
    		    update_option("<<productname_without_space>>_lic_Key","") || add_option("<<productname_without_space>>_lic_Key","");
    	    }
    	    wp_safe_redirect(admin_url( 'admin.php?page='.$this->slug));
        }
        function Activated(){
            ?>
            <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
                <input type="hidden" name="action" value="<<productname_without_space>>_el_deactivate_license"/>
                <div class="el-license-container">
                    <h3 class="el-license-title"><i class="dashicons-before dashicons-star-filled"></i> <<productname>> License Info</h3>
                    <hr>
                    <ul class="el-license-info">
                    <li>
                        <div>
                            <span class="el-license-info-title"><?php _e( 'Status', 'bdthemes-element-pack' ); ?></span>

    			            <?php if ( $this->responseObj->is_valid ) : ?>
                                <span class="el-license-valid">Valid</span>
    			            <?php else : ?>
                                <span class="el-license-valid">Invalid</span>
    			            <?php endif; ?>
                        </div>
                    </li>

                    <li>
                        <div>
                            <span class="el-license-info-title"><?php _e( 'License Type', 'bdthemes-element-pack' ); ?></span>
    			            <?php echo $this->responseObj->license_title; ?>
                        </div>
                    </li>

                    <li>
                        <div>
                            <span class="el-license-info-title"><?php _e( 'License Expired on', 'bdthemes-element-pack' ); ?></span>
    			            <?php echo $this->responseObj->expire_date; ?>
                        </div>
                    </li>

                    <li>
                        <div>
                            <span class="el-license-info-title"><?php _e( 'Support Expired on', 'bdthemes-element-pack' ); ?></span>
    			            <?php echo $this->responseObj->support_end; ?>
                        </div>
                    </li>
                        <li>
                            <div>
                                <span class="el-license-info-title"><?php _e( 'Your License Key', 'bdthemes-element-pack' ); ?></span>
                                <span class="el-license-key"><?php echo esc_attr( substr($this->responseObj->license_key,0,9)."XXXXXXXX-XXXXXXXX".substr($this->responseObj->license_key,-9) ); ?></span>
                            </div>
                        </li>
                    </ul>
                    <div class="el-license-active-btn">
    				    <?php wp_nonce_field( 'el-license' ); ?>
    				    <?php submit_button('Deactivate'); ?>
                    </div>
                </div>
            </form>
    	<?php
        }

        function LicenseForm() {
    	    ?>
        <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
    	    <input type="hidden" name="action" value="<<productname_without_space>>_el_activate_license"/>
    	    <div class="el-license-container">
    		    <h3 class="el-license-title"><i class="dashicons-before dashicons-star-filled"></i> <<productname>> Licensing</h3>
    		    <hr>
                <?php
                if(!empty($this->showMessage) && !empty($this->licenseMessage)){
                    ?>
                    <div class="notice notice-error is-dismissible">
                        <p><?php echo $this->licenseMessage; ?></p>
                    </div>
                    <?php
                }
                ?>
    		    <p>Enter your license key here, to activate the product, and get full feature updates and premium support.</p>
    		    <ol>
    			    <li>Write your licnese key details</li>
    			    <li>How buyer will get this license key?</li>
    			    <li>Describe other info about licensing if rquired</li>
                    <li>. ...</li>
    		    </ol>
    		    <div class="el-license-field">
    			    <label for="el_license_key">License code</label>
    			    <input type="text" class="regular-text code" name="el_license_key" size="50" placeholder="xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx" required="required">
    		    </div>

    		    <div class="el-license-active-btn">
    			    <?php wp_nonce_field( 'el-license' ); ?>
    			    <?php submit_button('Activate'); ?>
    		    </div>
    	    </div>
        </form>
    	    <?php
        }
    }

    new <<productname_without_space>>();