import {Button} from 'antd'
import { useState } from "react"
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
import DocumentsTemplate from './DocumentsTemplate'
import LoaderPortal from '../../components/LoaderPortal'

const idFileCategoryDrillingProgramItems = 13;

export default function DrillingProgram({idWell}) {
  const [showLoader, setShowLoader] = useState(false)
  
  const urlDownloadProgram =`api/well/${idWell}/drillingProgram`

  const downloadProgram = () => invokeWebApiWrapperAsync(async()=>{
    await download(urlDownloadProgram)
  }, 
  setShowLoader,
  "Не удалось загрузить программу бурения")

  return(<LoaderPortal show={showLoader}>
      <Button onClick={downloadProgram}>Сформировать программу бурения</Button>
      <DocumentsTemplate
        idWell={idWell}
        idCategory={idFileCategoryDrillingProgramItems}/>
    </LoaderPortal>)
}