import axios from "axios";
import { baseUrl } from "../../constants/urls";
import { brands } from "../../mockData/brandsList";
import { idDefaultAddress } from "./address";
export const fetchSellerDetails = async (sellerId: any) => {
  const url = `${baseUrl}/api/seller/profile/${sellerId}`;

  const seller_details = await axios.get(url);
  return seller_details;
};

export const fetchSellerFeaturedProducts = async (id: any) => {
  const url = `${baseUrl}/api/products?category_id=1&page=1&limit=30&vendor_id=${id}&featured=1&product_type=2`;

  const featuredProducts = await axios.get(url);
  return featuredProducts;
};

export const fetchSellerProductsByBrand = async (brandId: any) => {
  const url = `${baseUrl}/api/products?category_id=1&page=1&limit=30&vendor_id=4&brand=${brandId}`;

  const featuredProducts = await axios.get(url);
  return featuredProducts;
};

export const fetchSellerProductsList = `${baseUrl}/api/products`;

export const fetchCategories = async (id: any) => {
  const urlSeller = `${baseUrl}/api/seller/seller_categories/${id}`;
  const response = await axios.get(urlSeller);

  const url = `${baseUrl}/api/categories?limit=1000`;
  const category_res = await axios.get(url);

  let categories;

  if (response.data.categories) {
    const res = JSON.parse(response.data.categories);
    categories = category_res.data.data.map((item: any) => ({
      ...item,
      isSeller: res.find((g: any) => g == item.id) >= 0,
    }));
  }

  return categories;
};

export const fetchSellerBrands = async (Id: any) => {
  const url = `${baseUrl}/api/productsCategories?category_id=1&page=1&limit=30&vendor_id=${Id}`;

  const featuredBrand = await axios.get(url);
  let brands: any;
  let brandsList;
  return featuredBrand.data.brand;
  if (featuredBrand) {
    brands = featuredBrand.data.brand;
    // return  brands;
  }

  if (brands) {
    const brandurl = `${baseUrl}/api/brands-list`;
    const brandList = await axios.get(brandurl);



    if (brandList && brands) {
      brandsList = brandList.data.filter((brand: any) =>
        brands.find((id: any) => brand.id == id.id)
      );
    }
  }

  return brandsList;

  // const brandListData = brands.data.filter((id: any) => id.vendor_Id == Id);

  // let brandsList;
  // if (brandListData.length) brandsList = brandListData[0].brand;
  // else brandsList = brandListData;

  // return brandsList;
};
