defmodule ErlefWeb.StipendView do
  use ErlefWeb, :view

  # Currently values chosen for select simply go into an html doc so we map name to name as to avoid
  # stipend reviewers having to look up the country name for agiven code.

  @country_data [
    {"Select your country", ""},
    {"Afghanistan", "Afghanistan"},
    {"Albania", "Albania"},
    {"Algeria", "Algeria"},
    {"American Samoa", "American Samoa"},
    {"Andorra", "Andorra"},
    {"Angola", "Angola"},
    {"Anguilla", "Anguilla"},
    {"Antarctica", "Antarctica"},
    {"Antigua And Barbuda", "Antigua And Barbuda"},
    {"Argentina", "Argentina"},
    {"Armenia", "Armenia"},
    {"Aruba", "Aruba"},
    {"Australia", "Australia"},
    {"Austria", "Austria"},
    {"Azerbaijan", "Azerbaijan"},
    {"Bahamas", "Bahamas"},
    {"Bahrain", "Bahrain"},
    {"Bangladesh", "Bangladesh"},
    {"Barbados", "Barbados"},
    {"Belarus", "Belarus"},
    {"Belgium", "Belgium"},
    {"Belize", "Belize"},
    {"Benin", "Benin"},
    {"Bermuda", "Bermuda"},
    {"Bhutan", "Bhutan"},
    {"Bolivia", "Bolivia"},
    {"Bosnia And Herzegovina", "Bosnia And Herzegovina"},
    {"Botswana", "Botswana"},
    {"Bouvet Island", "Bouvet Island"},
    {"Brazil", "Brazil"},
    {"British Indian Ocean Territory", "British Indian Ocean Territory"},
    {"Brunei Darussalam", "Brunei Darussalam"},
    {"Bulgaria", "Bulgaria"},
    {"Burkina Faso", "Burkina Faso"},
    {"Burundi", "Burundi"},
    {"Cambodia", "Cambodia"},
    {"Cameroon", "Cameroon"},
    {"Canada", "Canada"},
    {"Cape Verde", "Cape Verde"},
    {"Cayman Islands", "Cayman Islands"},
    {"Central African Republic", "Central African Republic"},
    {"Chad", "Chad"},
    {"Chile", "Chile"},
    {"China", "China"},
    {"Christmas Island", "Christmas Island"},
    {"Cocos (keeling) Islands", "Cocos (keeling) Islands"},
    {"Colombia", "Colombia"},
    {"Comoros", "Comoros"},
    {"Congo", "Congo"},
    {"Congo, The Democratic Republic Of The", "Congo, The Democratic Republic Of The"},
    {"Cook Islands", "Cook Islands"},
    {"Costa Rica", "Costa Rica"},
    {"Cote D'ivoire", "Cote D'ivoire"},
    {"Croatia", "Croatia"},
    {"Cuba", "Cuba"},
    {"Cyprus", "Cyprus"},
    {"Czech Republic", "Czech Republic"},
    {"Denmark", "Denmark"},
    {"Djibouti", "Djibouti"},
    {"Dominica", "Dominica"},
    {"Dominican Republic", "Dominican Republic"},
    {"East Timor", "East Timor"},
    {"Ecuador", "Ecuador"},
    {"Egypt", "Egypt"},
    {"El Salvador", "El Salvador"},
    {"Equatorial Guinea", "Equatorial Guinea"},
    {"Eritrea", "Eritrea"},
    {"Estonia", "Estonia"},
    {"Ethiopia", "Ethiopia"},
    {"Falkland Islands (malvinas)", "Falkland Islands (malvinas)"},
    {"Faroe Islands", "Faroe Islands"},
    {"Fiji", "Fiji"},
    {"Finland", "Finland"},
    {"France", "France"},
    {"French Guiana", "French Guiana"},
    {"French Polynesia", "French Polynesia"},
    {"French Southern Territories", "French Southern Territories"},
    {"Gabon", "Gabon"},
    {"Gambia", "Gambia"},
    {"Georgia", "Georgia"},
    {"Germany", "Germany"},
    {"Ghana", "Ghana"},
    {"Gibraltar", "Gibraltar"},
    {"Greece", "Greece"},
    {"Greenland", "Greenland"},
    {"Grenada", "Grenada"},
    {"Guadeloupe", "Guadeloupe"},
    {"Guam", "Guam"},
    {"Guatemala", "Guatemala"},
    {"Guinea", "Guinea"},
    {"Guinea-bissau", "Guinea-bissau"},
    {"Guyana", "Guyana"},
    {"Haiti", "Haiti"},
    {"Heard Island And Mcdonald Islands", "Heard Island And Mcdonald Islands"},
    {"Holy See (vatican City State)", "Holy See (vatican City State)"},
    {"Honduras", "Honduras"},
    {"Hong Kong", "Hong Kong"},
    {"Hungary", "Hungary"},
    {"Iceland", "Iceland"},
    {"India", "India"},
    {"Indonesia", "Indonesia"},
    {"Iran, Islamic Republic Of", "Iran, Islamic Republic Of"},
    {"Iraq", "Iraq"},
    {"Ireland", "Ireland"},
    {"Israel", "Israel"},
    {"Italy", "Italy"},
    {"Jamaica", "Jamaica"},
    {"Japan", "Japan"},
    {"Jordan", "Jordan"},
    {"Kazakhstan", "Kazakhstan"},
    {"Kenya", "Kenya"},
    {"Kiribati", "Kiribati"},
    {"Korea, Democratic People's Republic Of", "Korea, Democratic People's Republic Of"},
    {"Korea, Republic Of", "Korea, Republic Of"},
    {"Kosovo", "Kosovo"},
    {"Kuwait", "Kuwait"},
    {"Kyrgyzstan", "Kyrgyzstan"},
    {"Lao People's Democratic Republic", "Lao People's Democratic Republic"},
    {"Latvia", "Latvia"},
    {"Lebanon", "Lebanon"},
    {"Lesotho", "Lesotho"},
    {"Liberia", "Liberia"},
    {"Libyan Arab Jamahiriya", "Libyan Arab Jamahiriya"},
    {"Liechtenstein", "Liechtenstein"},
    {"Lithuania", "Lithuania"},
    {"Luxembourg", "Luxembourg"},
    {"Macau", "Macau"},
    {"Macedonia, The Former Yugoslav Republic Of", "Macedonia, The Former Yugoslav Republic Of"},
    {"Madagascar", "Madagascar"},
    {"Malawi", "Malawi"},
    {"Malaysia", "Malaysia"},
    {"Maldives", "Maldives"},
    {"Mali", "Mali"},
    {"Malta", "Malta"},
    {"Marshall Islands", "Marshall Islands"},
    {"Martinique", "Martinique"},
    {"Mauritania", "Mauritania"},
    {"Mauritius", "Mauritius"},
    {"Mayotte", "Mayotte"},
    {"Mexico", "Mexico"},
    {"Micronesia, Federated States Of", "Micronesia, Federated States Of"},
    {"Moldova, Republic Of", "Moldova, Republic Of"},
    {"Monaco", "Monaco"},
    {"Mongolia", "Mongolia"},
    {"Montenegro", "Montenegro"},
    {"Montserrat", "Montserrat"},
    {"Morocco", "Morocco"},
    {"Mozambique", "Mozambique"},
    {"Myanmar", "Myanmar"},
    {"Namibia", "Namibia"},
    {"Nauru", "Nauru"},
    {"Nepal", "Nepal"},
    {"Netherlands", "Netherlands"},
    {"Netherlands Antilles", "Netherlands Antilles"},
    {"New Caledonia", "New Caledonia"},
    {"New Zealand", "New Zealand"},
    {"Nicaragua", "Nicaragua"},
    {"Niger", "Niger"},
    {"Nigeria", "Nigeria"},
    {"Niue", "Niue"},
    {"Norfolk Island", "Norfolk Island"},
    {"Northern Mariana Islands", "Northern Mariana Islands"},
    {"Norway", "Norway"},
    {"Oman", "Oman"},
    {"Pakistan", "Pakistan"},
    {"Palau", "Palau"},
    {"Palestinian Territory, Occupied", "Palestinian Territory, Occupied"},
    {"Panama", "Panama"},
    {"Papua New Guinea", "Papua New Guinea"},
    {"Paraguay", "Paraguay"},
    {"Peru", "Peru"},
    {"Philippines", "Philippines"},
    {"Pitcairn", "Pitcairn"},
    {"Poland", "Poland"},
    {"Portugal", "Portugal"},
    {"Puerto Rico", "Puerto Rico"},
    {"Qatar", "Qatar"},
    {"Reunion", "Reunion"},
    {"Romania", "Romania"},
    {"Russian Federation", "Russian Federation"},
    {"Rwanda", "Rwanda"},
    {"Saint Helena", "Saint Helena"},
    {"Saint Kitts And Nevis", "Saint Kitts And Nevis"},
    {"Saint Lucia", "Saint Lucia"},
    {"Saint Pierre And Miquelon", "Saint Pierre And Miquelon"},
    {"Saint Vincent And The Grenadines", "Saint Vincent And The Grenadines"},
    {"Samoa", "Samoa"},
    {"San Marino", "San Marino"},
    {"Sao Tome And Principe", "Sao Tome And Principe"},
    {"Saudi Arabia", "Saudi Arabia"},
    {"Senegal", "Senegal"},
    {"Serbia", "Serbia"},
    {"Seychelles", "Seychelles"},
    {"Sierra Leone", "Sierra Leone"},
    {"Singapore", "Singapore"},
    {"Slovakia", "Slovakia"},
    {"Slovenia", "Slovenia"},
    {"Solomon Islands", "Solomon Islands"},
    {"Somalia", "Somalia"},
    {"South Africa", "South Africa"},
    {"South Georgia And The South Sandwich Islands",
     "South Georgia And The South Sandwich Islands"},
    {"Spain", "Spain"},
    {"Sri Lanka", "Sri Lanka"},
    {"Sudan", "Sudan"},
    {"Suriname", "Suriname"},
    {"Svalbard And Jan Mayen", "Svalbard And Jan Mayen"},
    {"Swaziland", "Swaziland"},
    {"Sweden", "Sweden"},
    {"Switzerland", "Switzerland"},
    {"Syrian Arab Republic", "Syrian Arab Republic"},
    {"Taiwan, Province Of China", "Taiwan, Province Of China"},
    {"Tajikistan", "Tajikistan"},
    {"Tanzania, United Republic Of", "Tanzania, United Republic Of"},
    {"Thailand", "Thailand"},
    {"Togo", "Togo"},
    {"Tokelau", "Tokelau"},
    {"Tonga", "Tonga"},
    {"Trinidad And Tobago", "Trinidad And Tobago"},
    {"Tunisia", "Tunisia"},
    {"Turkey", "Turkey"},
    {"Turkmenistan", "Turkmenistan"},
    {"Turks And Caicos Islands", "Turks And Caicos Islands"},
    {"Tuvalu", "Tuvalu"},
    {"Uganda", "Uganda"},
    {"Ukraine", "Ukraine"},
    {"United Arab Emirates", "United Arab Emirates"},
    {"United Kingdom", "United Kingdom"},
    {"United States", "United States"},
    {"United States Minor Outlying Islands", "United States Minor Outlying Islands"},
    {"Uruguay", "Uruguay"},
    {"Uzbekistan", "Uzbekistan"},
    {"Vanuatu", "Vanuatu"},
    {"Venezuela", "Venezuela"},
    {"Viet Nam", "Viet Nam"},
    {"Virgin Islands, British", "Virgin Islands, British"},
    {"Virgin Islands, U.s.", "Virgin Islands, U.s."},
    {"Wallis And Futuna", "Wallis And Futuna"},
    {"Western Sahara", "Western Sahara"},
    {"Yemen", "Yemen"},
    {"Zambia", "Zambia"},
    {"Zimbabwe", "Zimbabwe"}
  ]

  @types [
    [
      key: "Development Work",
      value: "Development Work",
      type: "devel_work",
      "data-type": "devel_work",
      "data-requires-coc": "false"
    ],
    [
      key: "Conference",
      value: "conference",
      type: "conference",
      "data-type": "conference",
      "data-requires-coc": "true"
    ],
    [
      key: "Event Site Subscription",
      value: "Event Site Subscription",
      type: "event_site_sub",
      "data-type": "event_site_sub",
      "data-requires-coc": "false"
    ],
    [
      key: "Kids Coding Camp",
      value: "Kids Coding Camp",
      type: "kids_camp",
      "data-type": "kids_camp",
      "data-requires-coc": "false"
    ],
    [
      key: "Sprint",
      type: "sprint",
      value: "Sprint",
      "data-type": "sprint",
      "data-requires-coc": "false"
    ],
    [
      key: "Training Program",
      value: "Training Program",
      type: "training",
      "data-type": "training",
      "data-requires-coc": "false"
    ],
    [
      key: "Workshop-Education",
      value: "Workshop-Education",
      type: "workshop-edu",
      "data-type": "workshop-edu",
      "data-requires-coc": "true"
    ],
    [
      key: "Workshop-Women",
      value: "Workshop-Women",
      type: "workshop-women",
      "data-type": "workshop-women",
      "data-requires-coc": "true"
    ],
    [
      key: "Elixir Outreach",
      value: "Elixir Outreach",
      type: "elixir-outreach",
      "data-type": "elixir-outreach",
      "data-requires-coc": "false"
    ],
    [
      key: "Other",
      value: "Other",
      type: "other",
      "data-type": "other",
      "data-requires-coc": "false"
    ]
  ]

  def stipend_type_select(form, type) do
    select(
      form,
      :stipend_type,
      @types,
      selected: selected(type),
      id: "stipend_type",
      class: "form-control"
    )
  end

  defp selected(type) do
    case Enum.find(@types, fn t -> Keyword.get(t, :type) == type end) do
      nil -> 0
      v -> Keyword.get(v, :value)
    end
  end

  def payment_method_select(form) do
    select(
      form,
      :payment_method,
      [[key: "--", value: ""], "Paypal", "Zelle", "Check", "Wire"],
      class: "form-control",
      required: "true"
    )
  end

  def country_select(form) do
    select(form, :country, @country_data,
      class: "form-control",
      "data-live-search": "true"
    )
  end
end
