/* eslint-disable @typescript-eslint/no-explicit-any */
import { useState } from "react";
import classNames from "classnames";
import { toast } from "react-toastify";
import SpaceIcon from "@/assets/space.svg";
import Loading from "../loading/loading";
import Login from "../login/login";
import { Auth } from "./../../../utils/types";
const MsgToast = ({ url }: { url: string }) => (
  
    Your space is live!
     {
        window.open(url, "_blank");
      }}
    >
      See Space
     
  
);
function DeployButton({
  html,
  error = false,
  auth,
}: {
  html: string;
  error: boolean;
  auth?: Auth;
}) {
  const [open, setOpen] = useState(false);
  const [loading, setLoading] = useState(false);
  const [path, setPath] = useState(undefined);
  const [config, setConfig] = useState({
    title: "",
  });
  const createSpace = async () => {
    setLoading(true);
    try {
      const request = await fetch("/api/deploy", {
        method: "POST",
        body: JSON.stringify({
          title: config.title,
          path,
          html,
        }),
        headers: {
          "Content-Type": "application/json",
        },
      });
      const response = await request.json();
      if (response.ok) {
        toast.success(
          
      {auth && (
        
          Connected as{" "}
          
            {auth.preferred_username}
           
        
      )}
      
 setOpen(!open)}
      >
        {path ? "Update Space" : "Deploy to Space"}
       
       setOpen(false)}
      >
      
        {!auth ? (
          
            
              Host this project for free and share it with your friends.
            
           
        ) : (
          <>
            
              
                 
              Configure Deployment
             
            
              
                {path ? (
                  
                    Your space is live at{" "}
                    
                      huggingface.co/{path}
                     
                    . You can update it by deploying again.
                   
                ) : (
                  "Deploy your project to a space on the Hub. Spaces are a way to share your project with the world."
                )}
              
              {!path && (
                
                  
                    Space Title
                  
                   
              )}
              {error && (
                
                  Your code has errors. Fix them before deploying.
                
              )}
              
                
                  {path ? "Update Space" : "Create Space"}
                  {loading &&  
              
             
          >
        )}