module ExcelReports
  module GraphicReports
    module NatGeoTextGraphicsLogs
      class InternalProgramGfxLogSheet < Worksheet
        def title
          "Internal Program GFX Log"
        end

        def fill_content(sheet)
          sheet.add_row ["NATIONAL GEOGRAPHIC", "", "", "", "", "", ""]
          sheet.add_row ["Text-Graphics Log", "", "", "", "", "", ""]
          sheet.add_row ["(Title Sequence, Maps, Lower Thirds, CGI, Subtitles, Captions, Text Identifiers, Chyrons, Credits etc. )", "", "", "", "", "", ""]
          sheet.add_row
          sheet.add_row ["", "Series Name:", "", "", "", "", ""]
          sheet.add_row ["", "Episode Title:", header_data.name, "", "", "", ""]
          sheet.add_row ["", "Episode Number:", header_data.number, "", "", "", ""]
          sheet.add_row ["", "Traffic Code(s):", "", "", "", "", ""]
          sheet.add_row ["", "Date:", BigMediaTime.time_zone_now.to_date.strftime("%D"), "", "", "", ""]
          sheet.add_row
          sheet.add_row table_headers

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

          sheet.add_row(["*Clean Graphics should appear at the end of the program master.  If all shots do not fit on the program master, a separate graphics master should be delivered."])
          sheet.add_row(["*If delivering textless masters & no clean graphics at the end, denote N/A in the clean scene timecode section."])
        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:A2", Styles::BOLD, Styles::FULLY_CENTERED, { sz: 12 }
          sheet.add_style "A3", Styles::FULLY_CENTERED, { sz: 12 }
          sheet.add_style "B5:B9", Styles::BOLD, Styles::HORIZONTAL_RIGHT
          sheet.add_style "A11:G11", Styles::BOLD, Styles::FULLY_CENTERED, Styles::THIN_BLACK_BORDER, Styles::WRAP_TEXT

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

        private

        def table_headers
          [
            "Element\n(Ex: Title, Lower Third, Subtitle, Graphic, Credits,  etc.)",
            "Description",
            "Program Timecode In",
            "Program Timecode Out",
            "Clean Scene Timecode In",
            "Clean Scene Timecode Out",
            "Font Information\n(Include Font Name, Style, Color, & Opacity)"
          ]
        end

        def column_widths
          [25, 36, 18, 18, 18, 18, 23]
        end

        def cells_to_merge
          %w(A1:G1 A2:G2 A3:G3 C5:E5 C6:E6 C7:E7 C8:E8 C9:E9)
        end

        def data_start_index
          12
        end

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