package reading.component.index import scalatags.JsDom.all._ import scalacss.Defaults._ import scalacss.ScalatagsCss._ import reading.component.index.style.{ BookDetail => BookStyle } import reading.models.{ Program, Book } object BookDetail { def apply(book: Book): HtmlTag = div( BookStyle.render, BookStyle.detail, img( BookStyle.cover, src := s"cover/${book.title}.jpg", alt := book.title ), div( if (book.programs.nonEmpty) { item("classe", book.programs.map(Program.grade(_).prettyPrint).distinct.sorted) }, if (book.programs.nonEmpty) { item("programme", book.programs.map(p => "« " ++ p.prettyPrint ++ " »").sorted) }, if (book.themes.nonEmpty) { item("thème", book.themes.sorted.map(_.prettyPrint)) }, if (book.genres.nonEmpty) { item("genre", book.genres.sorted.map(_.prettyPrint)) }, book.period.map { period => item("période", Seq(period.prettyPrint)) } ) ) private def item(key: String, values: Seq[String]): Frag = div( BookStyle.item, div(BookStyle.itemName, key), ul( BookStyle.itemValues, values.map(value => li(BookStyle.itemValue, value.capitalize)) ) ) }