module ExcelReports
  module GraphicReports
    module DiscoveryGfxCueLists
      class TextedElementsSheet < ::ExcelReports::Worksheet
        def title
          "Texted Elements List"
        end

        def fill_content(sheet)
          sheet.add_row ["Texted Element / CG List"]
          sheet.add_row
          sheet.add_row ["Program Title", header_data.program_title]
          sheet.add_row ["Episode", header_data.episode]
          sheet.add_row ["Network", header_data.network]
          sheet.add_row ["Executive Producer", ""]
          sheet.add_row ["Production Company", header_data.company]
          sheet.add_row
          sheet.add_row ["Title/Subtitle/Graphics", "T/C IN", "T/C OUT", "TRT"]

          data.each do |graphics_data|
            sheet.add_row [graphics_data.text, graphics_data.timecode_in, graphics_data.timecode_out, graphics_data.duration]
          end
        end

        def format(sheet)
          sheet.column_widths *column_widths
        end

        def style(sheet)
          sheet.add_style "A1", Styles::BOLD, { sz: 12 }
          sheet.add_style "A9:D9", Styles::TABLE_HEADER
          sheet.add_style "A3:A7", Styles::PROGRAM_HEADER
          sheet.add_style "B3:B7", Styles::HEADER_DATA

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

        private

        def column_widths
          [60, 20, 20]
        end

        def data_start_index
          10
        end

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