module Workstation
  class EditFilmChapters < Workstation::BasePage
    include Workstation::ReleaseStatusBar
    button(:save_chapters, id: "save_chapters")
    button(:cancel, id: "back-to-overview")
    div(:please_wait_bar, id: "loadingbarid")

    indexed_property(
      :chapters,
      [
        [:text_field, :chapter_title, { id: "chapter_title_%s" }],
        [:text_field, :chapter_time, { id: "chapter_time_%s" }],
        [:button, :chapter_trash_can, { id: "chapter_trash_cans_%s" }]
      ]
    )

    def edit_chapter_time(chapter_number, time_value)
      chapter = chapters[chapter_number]
      chapter.chapter_time_element.when_present.click
      chapter.chapter_time = time_value
    end

    def edit_chapter_title(chapter_number, title_name)
      chapter = chapters[chapter_number]
      chapter.chapter_title_element.when_present.click
      chapter.chapter_title = title_name
    end

    def remove_chapter(chapter_number)
      chapter = chapters[chapter_number]
      chapter.chapter_trash_can_element.when_present.click
    end
  end
end
