module ExcelReports
  module VideoReports
    module DiscoveryProductionElementsLogs
      class LocationSheet < ::ExcelReports::Worksheet
        def title
          "Location"
        end

        def fill_content(sheet)
          sheet.add_row ["LOCATION LOG  (for all episodes/programs)"]
          sheet.add_row [instructions]
          sheet.add_row
          sheet.add_row table_headers

          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].join(" ")
            ]
          end
        end

        def format(sheet)
          sheet.column_widths *column_widths
        end

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

          if data.any?
            sheet.add_style "A#{data_start_index}:E#{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 table_headers
          ["EPISODE NUMBER(S) or LIST \"ALL\"", "EPISODE TITLE(S) or LIST \"ALL\"", "TIMECODE IN", "SOURCE TAPE / HARD DRIVE NUMBER", "LOCATION NAME and BRIEF VIDEO DESCRIPTION"]
        end

        def column_widths
          [20, 20, 15, 20, 40]
        end

        def data_start_index
          5
        end

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