
require 'time'
require 'csv'


people = []
CSV.foreach('people.csv', headers: true) do |row|
  people << { name: row['名前'], resolution: row['抱負'] }
end


new_year = Time.new(2025, 1, 1, 0, 0, 0)


def display_ascii_art
  art = <<-'EOF'
 H     H       A       PPPPP  PPPPP Y       Y      N       N  EEEEEE W           W           W    Y     Y EEEEEE       A       RRRRRR
 H     H      A A      P   P  P   P  Y     Y       NN      N  E       W         W W         W      Y   Y  E           A A      R     R
 H     H     A   A     P   P  P   P   Y   Y        N  N    N  E        W       W   W       W        Y Y   E          A   A     R     R
 HHHHHHH    AAAAAAA    PPPPP  PPPPP     Y          N   N   N  EEEEEE    W     W     W     W          Y    EEEEEE    AAAAAAA    RRRRRR
 H     H   A       A   P      P         Y          N    N  N  E          W   W       W   W           Y    E        A       A   R R
 H     H  A         A  P      P         Y          N     N N  E           W W         W W            Y    E       A         A  R  R
 H     H A           A P      P         Y          N      NN  EEEEEE       W           W             Y    EEEEEE A           A R   R
EOF
      Happy New Year

  puts art
end


def display_random_resolutions(people)
  random_person = people.sample
  puts "\nこのかたが新年の抱負を発表します(45秒で): #{random_person[:name]}さん"
  sleep 45  # 名前を表示した後、少し待つ
  puts "パチパチパチ"
end

loop do
  now = Time.now
  if now >= new_year
    puts "🎉 明けましておめでとうございます！ 🎉"
    display_ascii_art
    display_random_resolutions(people)
    break
  else
    time_left = new_year - now
    hours = (time_left / 3600).to_i
    minutes = ((time_left % 3600) / 60).to_i
    seconds = (time_left % 60).to_i
    print "\rカウントダウン: #{hours}時間 #{minutes}分 #{seconds}秒"
    sleep 1
  end
end
