module ExcelReports
  module VideoReports
    module NatGeoLegalBinderLogs
      class AcquiredFootageLogSheet < Worksheet
        def title
          "Acquired Footage-Stills Log"
        end

        def fill_content(sheet)
          sheet.add_row
          sheet.add_row
          sheet.add_row(["", "", "", "", "", "RIGHTS OBTAINED", "", "", ""]) 
          sheet.add_row(table_headers)

          data.each_with_index do |confirmation, index|
            sheet.add_row [
              index + 1,
              confirmation.description,
              confirmation.timecode_in,
              confirmation.timecode_out,
              [confirmation.name, confirmation.contact_address].join("\n"),
              confirmation.applicable_media,
              confirmation.territory,
              confirmation.term,
              confirmation.restrictions,
            ]
          end
        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 "F3", Styles::BOLD, Styles::FULLY_CENTERED, Styles::BG_GRAY, Styles::THIN_BLACK_BORDER
          sheet.add_style "A4:I4", Styles::BOLD, Styles::FULLY_CENTERED, Styles::THIN_BLACK_BORDER, Styles::WRAP_TEXT

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

        private

        def table_headers
          [
            "Contract Number", 
            "Brief description of footage or stills",
            "Program Master Timecode IN",
            "Program Master Timecode OUT",
            "Vendor Name and Contact Information",
            "Media", 
            "Territory", 
            "Term", 
            "Restrictions",
          ]
        end

        def data_start_index
          5
        end

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

        def column_widths
          [12, 25, 22, 22, 28, 18, 22, 22, 25]
        end

        def cells_to_merge
          %w(F3:I3)
        end
      end
    end
  end
end
