text: require('./bootstrap');
  window.Jquery = require('jquery')
  require('alpinejs');
  $(document).ready(function () {
  if(top.location.pathname === "/getFilms") {
      $.ajax({
          url : 'index',
          type: 'GET',
          success: function (data) {
              let personID = data[0].swapi;
              let url = 'https://swapi.dev/api/people/'+personID + '/';
              $.getJSON(url,function (personData) {
                  let filmsURL =  personData.films;
                  filmsURL.forEach(function (f) {
                      $.getJSON(f,function(filmData) {
                          $(".films").append("<div class='border-4 border-light-blue-500 border-opacity-100 m-5 '>");
                          $(".films").append("<h1  class='inline-block rounded-min text-white bg-blue-500 px-2 py-1 text-xs font-bold m-3'>Title:&nbsp;" + filmData.title + "</h1>");
                          $(".films").append("<p><span class='inline-block rounded-min text-white bg-blue-500 px-2 py-1 text-xs font-bold m-3'>Crawl:</span>&nbsp;" + filmData.opening_crawl + "</p>");
                          $(".films").append("<p><span class='inline-block rounded-min text-white bg-blue-500 px-2 py-1 text-xs font-bold m-3'>Producer/s</span>" + filmData.producer + "</p>");
                          $(".films").append("<p><span class='inline-block rounded-min text-white bg-blue-500 px-2 py-1 text-xs font-bold m-3'>Release date</span>" + filmData.release_date + "</p>");
  
                          $(".films").append("</div>");
                      })
                  });
              })
          }
      })
  
  }
  if(top.location.pathname === '/getPlanets') {
          $.ajax({
              url: 'index',
              type: 'GET',
              success: function (data) {
                  let personID = data[0].swapi;
                  let url = 'https://swapi.dev/api/people/'+personID + '/';
                  $.getJSON(url,function (personData) {
                      let planetsUrl = personData.homeworld;
                      console.log(planetsUrl);
                      $.getJSON(planetsUrl,function (p) {
                          $(".planet-name").append(p.name);
                          $(".rotation_period").append(p.rotation_period);
                          $(".orbital-period").append(p.orbital_period);
                          $(".diameter").append(p.diameter);
                          $(".climate").append(p.climate);
                          $(".gravity").append(p.gravity);
                          $(".terrain").append( p.terrain);
                          $(".surface_water").append(p.surface_water);
                          let liczba = p.population;
                          function separator(num) {
                              let num_parts = num.toString().split(".");
                              num_parts[0] = num_parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                              return num_parts.join(".");
  
                          }
                          $(".population").append(separator(liczba));
                      })
  
                  })
              }
          })
  }
  
  })
  