<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\CategoryDescription;
use App\PageDescription;
use App\Models;
use App\Http\Resources\CountryResource;
use App\Http\Resources\AttributeResource;

class BranchResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
     
    public function toArray($request)
    {
        
        $vowels = array("&nbsp;", "&ndash;", "&bull;","\r\n","&ldquo;","&rdquo;");
        $arr = explode(',',$this->latlng);
        $lat = $arr[0];
        $lng = substr($arr[1], 1);
       
        $data =  [
            'id' => $this->id,
            'lat'=> $lat,
            'lng'=> $lng,
            'phone' => $this->phone,
            'name'=> str_replace($vowels, ' ', strip_tags($this->descriptions(currentLanguage()->id)['name'])),
            'address'=> str_replace($vowels, ' ', strip_tags($this->descriptions(currentLanguage()->id)['address'])),
            'city'=>new CityResource($this->whenLoaded('city')),
            'area'=>new AreaResource($this->whenLoaded('area')),
            'store'=>new StoreResource($this->whenLoaded('store')),
            
            
            
            
            
      ];
      
      if(\Auth::user()){
          
      }
      else{
          
      }
      return $data;
    }
}
