import React, { useState } from "react";
import axios from "axios";

const API_URL = "http://localhost:5000/mastersdata";


const DeleteMaster = ({ master,onClose}) => {
  const [loader, setLoader] = useState(false);


  const handleDelete =  () => {
   const index = mastersdata[master?.masterType]?.findIndex(item => String(item?.id) === String(master?.item?.id));
           console.log(index)
    if (index !== -1) {
        mastersdata[master?.masterType].splice(index, 1);
    }
    onClose()
  };

  return (
    <div className="row g-2">
      <p className="h5">Are your sure , you want delete</p>
      <div className="col-12 d-flex justify-content-between width-md-6 width-sm-12">
        <button
          type="submit"
          className="btn btn-primary me-3"
          onClick={handleDelete}
        >
          {loader ? (
            <div class="spinner-border text-primary" role="status">
              <span class="sr-only">Loading...</span>
            </div>
          ) : (
            "Delete"
          )}
        </button>
        <button
          type="reset"
          className="btn btn-label-secondary"
          data-bs-dismiss="modal"
          aria-label="Close"
        >
          Cancel
        </button>
      </div>
    </div>
  );
};

export default DeleteMaster;
