import { Skeleton } from "antd";
import { NFTCard } from "components/NFTCard";
import { useVerifyMetadata } from "pages/store/useVerifyMetadata";
import React from "react";
import { useMoralis } from "react-moralis";
import { useStoreNFTs } from "./useStoreNFTs";

const styles = {
  container: {
    width: "100%",
    padding: "0 100px",
  },
  NFTs: {
    display: "flex",
    flexWrap: "wrap",
    WebkitBoxPack: "start",
    justifyContent: "flex-start",
    gap: "10px",
  },
};

/*
 * Display storefront based on the subdomain, for example
 * mpj.hoji.xyz will have a subdomain as mpj
 * then we need to render all the listed nft of the username mpj.
 * Additionally, it should follow the following logic:
 * 1. If the subdomain is exists, render the NFT for that store
 * 2. If the subdomain doesn't exist, redirect to the dashboard
 */
function StoreFront() {
  const { verifyMetadata } = useVerifyMetadata();
  const { user } = useMoralis();
  const { storeNFTs } = useStoreNFTs();

  return (
    <div style={styles.container}>
      <div style={styles.NFTs}>
        <Skeleton style={{}} loading={!storeNFTs}>
          {storeNFTs &&
            storeNFTs.map((nft) => {
              const verifiedNFT = verifyMetadata(nft);

              return (
                <NFTCard
                  key={nft.token_id}
                  hasOrder={!!nft.order}
                  caller={user?.attributes?.ethAddress}
                  order={nft.order}
                  nft={verifiedNFT}
                />
              );
            })}
        </Skeleton>
      </div>
    </div>
  );
}

export default React.memo(StoreFront);
