var request = require('request').defaults({ encoding: null });
module.exports.apartment = function($) {
    var result = {      
      images: $('.aspectRatioImage').map(function(){
        return {  src : $(this).find('img').attr("src") };        
        }).get(),
      name: $('#propertyName').text(),
      description: $('#descriptionSection>p').html(),
      rentInfo : $('#priceBedBathAreaInfoWrapper .rentInfoDetail').html(),
      review: $('.propertyReviewContainer .reviewRating').html(),
      lastUpdate  : $('.freshnessUserActionsContainer .lastUpdated>span').text(),
      address: {
        street: $('.propertyAddressContainer h2>span:nth-child(1)').text(),
        city: $('.propertyAddressContainer h2>span:nth-child(2)').text(),
        zip: {
          state: $('.propertyAddressContainer .stateZipContainer>span:nth-child(1)').text(),
          code: $('.propertyAddressContainer .stateZipContainer>span:nth-child(2)').text(),
        }
      },
      contact: {
        phone: $('.contactInfo .phoneNumber span').html(),
        language: $('.contactInfo .languages span').html(),
        url: $('.contactInfo .mortar-wrapper a').attr('href'),
        officeHours: $('.daysHoursContainer').map(function () {
          return {
            days: $(this).find('.days').text(),
            hours: $(this).find('.hours').text(),
          };
        }).get()
      },
      // features: $('#uniqueFeatures .uniqueAmenity').map(function () {
      //   return $(this).find('span').text();
      // }).get(),
      features: $('.amenitiesSection .amenityCard').map(function () {
          return $(this).find('.amenityLabel').text();
        }).get(),
      prices: $('[data-tab-content-id=all]>.pricingGridItem').add('[data-tab-content-id=all]>.jsAvailableModels').map(function () {
        return {
          name: $(this).find('.modelName').text(),
          available: $(this).hasClass('pricingGridItem'),
          rent: $(this).find('.rentLabel').text(),
          details: {
            rooms: $(this).find('.detailsTextWrapper>span:nth-child(1)').text(),
            baths: $(this).find('.detailsTextWrapper>span:nth-child(2)').text(),
            area: $(this).find('.detailsTextWrapper>span:nth-child(3)').html(),
            available: $(this).find('.availabilityInfo').html(),
          },
          url: $(this).find('.floorPlanButtonImage').attr('data-background-image'),
          plan: $(this).find('.allAmenities>li').map(function () {
            return {              
              title: $(this).find('.topAmenity').html(),
              amenities: $(this).find('.amenity').map(function () {
                return $(this).text();
              }).get(),
            };
          }).get(),
        };
      }).get()
    };
    var data = JSON.parse(JSON.stringify(result)
      .split('                ').join('')
      .split('        ').join('')
      .split('    ').join('')
      .split('            ').join('')
      .split('\\n').join(''));
    return data;
  } 