<?php

namespace App\Http\Resources;

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

class PackageResource 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;");
       
        $data =  [
            'id' => $this->id,
            
            'cost_brfore' => $this->cost,
            'cost_after' => $this->cost_after,
            'image'=>asset('').$this->image,
            'name'=>$this->descriptions(currentLanguage()->id)['name'],
            'details'=> str_replace($vowels, ' ', strip_tags($this->descriptions(currentLanguage()->id)['details'])),
            'description'=> str_replace($vowels, ' ', strip_tags($this->descriptions(currentLanguage()->id)['description'])),
            'subscribed'=>subscribed($this->id),
      ];
      if(\Auth::user()){
          if(subscribed($this->id)){
               $data_merged =  [
                               'months'=>subscribtion($this->id)['months'],
                               'days'=>subscribtion($this->id)['days'],
                               'hours'=>subscribtion($this->id)['hours'],
                               'minutes'=>subscribtion($this->id)['minutes'],
                            ];
            $data= array_merge($data, $data_merged);
          }
      }
      return $data;
    }
}
