<?php

namespace WeDevs\DokanVendorDashboard;

use WC_Product;

/**
 * Initiates necessary hooks.
 *
 * @since 1.0.0
 *
 * @return void
 */
class Hooks {
    public function __construct() {
        add_filter( 'dokan_get_edit_product_url', [ $this, 'update_edit_product_url' ], 10, 2 );
        add_action( 'rest_api_init', [ $this, 'rest_api_class_map' ] );
    }

    /**
     * Changes product edit url for vendor dashboard.
     *
     * @param string     $url
     * @param WC_Product $product
     *
     * @return string $url
     */
    public function update_edit_product_url( $url, $product ) {
        $url = dokan_get_navigation_url( 'products' ) . 'update/' . $product->get_id();

        return $url;
    }

    /**
     * Rest api class map
     *
     * @param array $classes
     *
     * @since DOKAN_SINCE
     *
     * @return array
     */
    public function rest_api_class_map() {
        dokan_vendor_dashboard()->dashboard_settings_api->register_routes();
    }
}
