use super::*;

#[derive(Boilerplate)]
pub struct ItemHtml {
  pub gallery_id: InscriptionId,
  pub gallery_number: i32,
  pub i: usize,
  pub item: Item,
}

impl PageContent for ItemHtml {
  fn title(&self) -> String {
    format!("Gallery {} Item {}", self.gallery_number, self.i)
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn body() {
    assert_regex_match!(
      ItemHtml {
        gallery_id: inscription_id(2),
        gallery_number: 1,
        i: 2,
        item: Item {
          id: Some(inscription_id(1)),
          attributes: Attributes {
            title: Some("foo".into()),
            traits: Traits::default(),
          },
          index: None,
        }
      },
      "
        <h1>Gallery 1 Item 2</h1>
        <p class=subtitle>foo</p>
        <div class=inscription>
        <iframe .* src=/preview/1{64}i1></iframe>
        </div>
        <dl>
          <dt>inscription</dt>
          <dd><a href=/inscription/1{64}i1>1{64}i1</a></dd>
          <dt>gallery</dt>
          <dd><a href=/inscription/2{64}i2>2{64}i2</a></dd>
          <dt>title</dt>
        <dd>foo</dd>

        </dl>
      "
      .unindent()
    );
  }

  #[test]
  fn title() {
    assert_eq!(
      ItemHtml {
        gallery_id: inscription_id(2),
        gallery_number: 1,
        i: 2,
        item: Item {
          id: Some(inscription_id(1)),
          attributes: Attributes {
            title: Some("foo".into()),
            traits: Traits::default(),
          },
          index: None,
        }
      }
      .title(),
      "Gallery 1 Item 2",
    );
  }
}
