import { useRef, useState, useEffect } from 'react' import cinemaApi from "../apis/cinema.api.js" import theaterApi from "../apis/theater.api.js" import catchErrors from "../utils/catchErrors" const { kakao } = window; const options = { center: new kakao.maps.LatLng(37.365264512305174, 127.10676860117488), level: 3 }; const TheaterInfo = () => { const container = useRef(null) const [cinemaInfo, setCinemaInfo] = useState() const [currentInfo, setCurrentInfo] = useState({ name: "init", title: "init", information: "init" }) const [error, setError] = useState() const [tabContent, setTabContent] = useState([]) useEffect(() => { getTheaterInfo() }, []) useEffect(() => { if (currentInfo.title === "address") { const container = document.getElementById("map"); const options = { center: new kakao.maps.LatLng(33.450701, 126.570667), level: 3, }; const map = new kakao.maps.Map(container, options); const geocoder = new kakao.maps.services.Geocoder(); geocoder.addressSearch(`${cinemaInfo.address}`, function (result, status) { if (status === kakao.maps.services.Status.OK) { const coords = new kakao.maps.LatLng(result[0].y, result[0].x); const marker = new kakao.maps.Marker({ map: map, position: coords }); const infowindow = new kakao.maps.InfoWindow({ content: '
Butter Studio
' }); infowindow.open(map, marker); map.setCenter(coords); } }); } }, [currentInfo]); async function getTheaterInfo() { try { const response = await cinemaApi.getCinemaInfo() const response2 = await theaterApi.getAll() setCinemaInfo({ ...response.data, theaterNum: response2.data.length }) setCurrentInfo({ name: "대중교통 안내", title: "transportation", information: response.data.transportation }) } catch (error) { catchErrors(error, setError) } } function handleClick(e) { setCurrentInfo({ name: e.target.name, title: e.target.id, information: e.target.value }) } return ( <> {cinemaInfo ?

{cinemaInfo.cinemaName}

총 상영관 수: {cinemaInfo.theaterNum}개
{cinemaInfo.address}
{currentInfo.information}
{currentInfo.information}
:
극장정보를 불러올 수 없습니다.
} ) } export default TheaterInfo