import React, {useEffect, useState} from "react";
import Form from "react-bootstrap/Form";
import * as EgovNet from "api/egovFetch";

function SelectOption({name, grpCd, selectedValue}){

    const [options, setOptions] = useState();

    useEffect(() => {
        getCodeItemList()
    }, []);

    function getCodeItemList(){
        EgovNet.requestFetch(
            '/commonCode/code-item?grpCd='+grpCd,
            {
                method: "GET"
            },
            (resp) => {
                let optionTag = [];
                // 리스트 항목 구성
                resp.result.codeList.forEach(function (item, index) {
                    optionTag.push(
                        <option value={item.itemCd} key={`${grpCd}option${index}`}>{item.itemNm}</option>
                    );
                });
                setOptions(optionTag);
            },
            function (resp) {
                console.log("err response : ", resp);
            }
        );
    }

    return (
        <Form.Select name={name} value={selectedValue} onChange={()=>{}}>
            {options}
        </Form.Select>
    )
}

export default SelectOption;