import React from "react";
import { Movie } from "./movie-wall";
import tmdb from "./tmdb";
import { WatchProviders, WhereToWatch } from "./whereToWatch";
import CrossfadeImage from 'react-crossfade-image'
import { Config } from "../App";

export interface SidebarProps extends React.ComponentPropsWithRef<"div"> {
  movie: Movie;
  similarMoviesAvailable: boolean;
  watchProviders: WatchProviders;
  config: Config;
  className: string
}
export function Sidebar({ movie, similarMoviesAvailable, watchProviders, config, className }: SidebarProps) {
  const apology = config.language == "es" ?
    "Resumen no disponible" :
    config.language == "en" ?
      "Summary unavailable." :
      ""
  return <div id="sidebar" className={className}>
    <h1 className="font-bold text-base sm:text-lg text-nowrap sm:text-wrap my-1 sm:my-4 sm:h-14 overflow-hidden">{movie?.title ?? "loading"}</h1>
    <div className="flex flex-row sm:flex-col gap-2 justify-center sm:items-center">
      <a href={tmdb.makeMovieLink(movie)} target="_blank" rel="noopener noreferrer" className="h-32 sm:h-96 aspect-poster flex justify-center">
        <CrossfadeImage src={tmdb.makeImgUrl(movie.poster_path ?? "")} style={{
          objectFit: "clip",
          height: "100%"
        }} />
      </a>
      {similarMoviesAvailable ? "" : "No hay data suficiente para darte pelílculas relacionadas."}
      <div className="h-32 sm:h-56 w-64 sm:w-full overflow-scroll sm:mt-4 p-2 sm:p-4 text-sm sm:text-base flex justify-center items-center border-2 border-slate-800 rounded-lg ">
        {/* TODO: make the apology vertically centered */}
        <p id="summary" className="self-start">{movie.overview === null ? "Loading"
          : movie.overview === "" ? apology
            : movie.overview}
        </p>
      </div>
    </div>
    <WhereToWatch watchProviders={watchProviders} config={config} className="w-full h-16 sm:h-32 flex flex-col justify-center mb-1 sm:mb-4 text-xs sm:text-base" />
  </div >


}
