module ExcelReports
  module AudioReports
    class BrayInnovationGroupMusicCueSheet < ::ExcelReports::Worksheet
      def title
        "BiG Music Cue Sheet"
      end

      def fill_content(sheet)
        sheet.add_row ["TITLE", header_data.title]
        sheet.add_row ["COMPANY NAME", header_data.company_name]
        sheet.add_row ["ADDRESS", header_data.company_address]
        sheet.add_row ["LENGTH", ""]
        sheet.add_row ["TYPE", ""]
        sheet.add_row
        sheet.add_row table_headers
        sheet.add_row table_subheaders

        data.each do |datum|
          sheet.add_row [
            datum.cue_number,
            datum.title_and_source_file_name,
            datum.composers,
            datum.composers_split,
            datum.publishers,
            datum.publishers_split,
            datum.music_type,
            datum.music_category,
            datum.timecode_in,
            datum.timecode_out,
            datum.duration,
          ]
        end
      end

      def format(sheet)
        sheet.merge_cells "G7:H7"
        sheet.column_widths *column_widths
      end

      def style(sheet)
        sheet.add_style "A1:A5", Styles::PROGRAM_HEADER
        sheet.add_style "B1:B5", Styles::HEADER_DATA
        sheet.add_style "A7:K7", Styles::TABLE_HEADER

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

      private

      def table_headers
        [
          "Cue #",
          "Cue Title",
          "Composer(s)/Affiliation",
          "%",
          "Publisher(s)/Affiliation",
          "%",
          "Use",
          "",
          "In Time",
          "Out Time",
          "Duration",
        ]
      end

      def table_subheaders
        [
          "",
          "",
          "",
          "",
          "",
          "",
          "I = Instr.\nV = Vocal",
          "B = Bckgrnd\nF = Feature\nT = Theme",
          "",
          "",
          "",
        ]
      end

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

      def data_start_index
        9
      end

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