module ExcelReports
  module VideoReports
    module DiscoveryProductionElementsLogs
      class AppearanceSheet < ::ExcelReports::Worksheet
        def title
          "Appearance"
        end

        def fill_content(sheet)
          sheet.add_row ["APPEARANCE LOG  (for all episodes/programs)", "", "", "", "", ""]
          sheet.add_row [instructions]
          sheet.add_row
          sheet.add_row ["EPISODE NUMBER(S) or LIST \"ALL\"", "EPISODE TITLE(S) or LIST \"ALL\"", "TIMECODE IN", "SOURCE TAPE / HARD DRIVE NUMBER", "NAME", "BRIEF VIDEO DESCRIPTION"]

          data.each do |confirmation|
            sheet.add_row [
              confirmation.episode_number,
              confirmation.episode_title,
              confirmation.timecode_in,
              confirmation.source_file_and_clip_names,
              confirmation.name,
              confirmation.description
            ]
          end

          sheet.add_row
          sheet.add_row ["*On co-productions, releases & logs retained by Producer.  Deliver upon request."]
        end

        def format(sheet)
          sheet.column_widths *column_widths
          cells_to_merge.each { |cell| sheet.merge_cells cell }
        end

        def style(sheet)
          sheet.add_style "A1", Styles::BOLD, { sz: 14 }
          sheet.add_style "A2", sz: 9
          sheet.add_style "A4:F4", Styles::TABLE_HEADER

          if data.any?
            sheet.add_style "A#{data_start_index}:F#{data_end_index}", Styles::TABLE_DATA
          end
        end

        private

        def instructions
          <<~INSTRUCTIONS
          All licenses must conform to the DCI contractual requirements and must be fully executed.

          Releases, licenses and agreements should only be logged once, based on the order of their appearance in the program.

          If an image does not appear in the final Program, log that release after those in the final Program; indicate on the Log sheet “NOT IN FINAL PROGRAM” and list the camera tape only.

          Please note that if it is not possible to deliver an English language agreement, an English language translation must accompany any agreement delivered in a foreign language (if applicable)."
          INSTRUCTIONS
        end

        def data_start_index
          5
        end

        def data_end_index
          (data_start_index + data.size) - 1
        end

        def column_widths
          [20, 25, 20, 20, 25, 30]
        end

        def cells_to_merge
          %w[ A2:F2 ]
        end
      end
    end
  end
end
