{"size": 3559, "ext": "js", "max_stars_repo_path": "pages/showtimes.js", "max_stars_repo_name": "gureuso/Movie", "max_stars_repo_stars_event_min_datetime": "2019-05-01T15:09:07.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-01T15:09:07.000Z", "max_issues_repo_path": "pages/showtimes.js", "max_issues_repo_name": "gureuso/Movie", "max_issues_repo_issues_event_min_datetime": "2021-03-09T03:11:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-13T02:15:22.000Z", "max_forks_repo_path": "pages/showtimes.js", "max_forks_repo_name": "gureuso/movie", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 30.947826087, "max_line_length": 179, "alphanum_fraction": 0.57544254}
import React from 'react'
import Link from 'next/link'
import fetch from 'isomorphic-unfetch'
import moment from 'moment'

import Error from './_error'
import Header from '../components/layout/Header'
import Nav from '../components/layout/Nav'

class ShowtimesPage extends React.Component {
  static async getInitialProps(req) {
    let fetch_uri = 'http://apis.movie.gureuso.me/v1/showtimes?'
    if(req.query.date) {
      fetch_uri += 'date='+req.query.date+'&'
    }
    if(req.query.cinema_id) {
      fetch_uri += 'cinema_id='+req.query.cinema_id+'&'
    }
    if (req.query.movie_id) {
      fetch_uri += 'movie_id='+req.query.movie_id+'&'
    }

    const res = await fetch(fetch_uri)
    const data = await res.json()

    return {
      status_code: data.code / 100,
      error_message: data.message,
      data: data.data
    };
  }

  create_week() {
    const week = this.props.data.week
    const selected = this.props.data.selected

    let week_list = []
    for(let w of week) {
      let active = ''
      if(w.date == selected.date) {
        active='active'
      }
      let url = "/showtimes?date=" + w.date
      if(selected.movie_id) {
        url += '&movie_id='+selected.movie_id
      }
      if(selected.cinema_id) {
        url += '&cinema_id='+selected.cinema_id
      }
      week_list.push(
        <li className="nav-item" key={w.date}>
          <Link href={url}><a className={"nav-link "+active}>{w.weekday}</a></Link>
        </li>
      )
    }
    return week_list
  }

  create_movies() {
    const movies = this.props.data.movies

    let movie_list = []
    for(let movie of movies) {
      let showtime_list = []
      for(let showtime of movie.showtimes) {
        if(showtime.start_time < moment().format('YYYYMMDDHHmm')) {
          showtime_list.push(
            <Link key={showtime.id} href={"/theaters?theater_id="+showtime.theater.id+"&showtime_id="+showtime.id} as={"/theaters/"+showtime.theater.id+"/showtimes/"+showtime.id}>
              <a className="list-group-item list-group-item-action disabled">
                {moment(showtime.start_time, 'YYYYMMDDHHmm').format('HH:mm')} ~ {moment(showtime.end_time, 'YYYYMMDDHHmm').format('HH:mm')}
                &nbsp;/&nbsp;
                {showtime.theater.title} 매진
              </a>
            </Link>
          )
        } else {
          showtime_list.push(
            <Link key={showtime.id} href={"/theaters?theater_id="+showtime.theater.id+"&showtime_id="+showtime.id} as={"/theaters/"+showtime.theater.id+"/showtimes/"+showtime.id}>
              <a className="list-group-item list-group-item-action">
                {moment(showtime.start_time, 'YYYYMMDDHHmm').format('HH:mm')} ~ {moment(showtime.end_time, 'YYYYMMDDHHmm').format('HH:mm')}
                &nbsp;/&nbsp;
                {showtime.theater.title} {showtime.theater.seat}석
              </a>
            </Link>
          )
        }
      }
      movie_list.push(
        <div className="list-group" key={movie.id}>
          <Link href={"/movie?id="+movie.id} as={"/movies/"+movie.id}><a className="list-group-item list-group-item-action">
            {movie.title} / {movie.director} / {movie.age_rating}세 이상 관람가
          </a></Link>
          {showtime_list}
        </div>
      )
    }
    return movie_list
  }

  render() {
    return (
      <div>
        <Header title="showtimes"/>
        <Nav/>
        <ul className="nav nav-tabs">
          {this.create_week()}
        </ul>
        {this.create_movies()}
      </div>
    )
  }
}

export default ShowtimesPage
