"use client"
import CtBoardDetail from '@/components/CtBoardDetail';
import Button from '@/components/ui/button/Button2';
import React from "react";
import { useEffect, useState } from 'react';
import api, { convertDateTime3, getUrlParam } from '@/lib/_AG';



let g_resource_board_id : string = "";

export default function ResourceBoardDetail() {
  const [title, setTitle] = useState("");
  const [content, setContent] = useState("");

  // function part
  function reqResourceBoardDetail() {
    alert(g_resource_board_id);

    const params = {
      id: g_resource_board_id
    }
    
    api.post('/api/get-resource-board-detail.do', params).then((resp) => {
      console.log(resp);
      
      if (resp.data.errCode == 0) {
          setTitle(resp.data.result.title);
          setContent(resp.data.result.content);
      }
      else {
          alert("일시적으로 사용할 수 없습니다 : " + resp.data.errCode);
      }
    })
    .catch((err) => console.error(err))
  }


  useEffect(() => {
    g_resource_board_id = getUrlParam("bid")!;
    reqResourceBoardDetail();
  }, []);


  return (
    <CtBoardDetail title={title} desc={"작성자 닉네임"} regDate={"resp.data.values.reg_date useState"}>
      <div>
        <p>{content}</p>
        <Button>수정</Button>
        <Button>삭제 </Button>
      </div>
    </CtBoardDetail>
  );
}
