module ExcelReports
  module IssuesAndConcernsReports
    class IssuesAndConcernsWorksheet < ::ExcelReports::Worksheet
      def title
        "Issues and Concerns Report"
      end

      def fill_content(sheet)
        sheet.add_row ["ISSUES AND CONCERNS REPORT"]
        sheet.add_row ["Project Name", data.project_name]
        sheet.add_row ["Video Name", data.video_name]
        sheet.add_row ["Date of Report", data.date_of_report]

        sheet.add_row []
        sheet.add_row ["Track", "TC In", "TC Out", "Clip Name", "Source File Name", "Notes"]
        data.unreleased_appearances.each do |unreleased_appearance|
          sheet.add_row [
            unreleased_appearance.channel, 
            unreleased_appearance.timecode_in, 
            unreleased_appearance.timecode_out,
            unreleased_appearance.clip_name,
            unreleased_appearance.source_file_name,
            unreleased_appearance.note_text
          ]
        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:A4", Styles::PROGRAM_HEADER
        sheet.add_style "B2:B4", Styles::HEADER_DATA
        sheet.add_style "A6:F6", Styles::TABLE_HEADER

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

      private

      def data_start_index
        7
      end

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

      def column_widths
        [15, 15, 15, 15, 15, 50]
      end
    end
  end
end
