<?php

namespace App\Http\Controllers\Web;

use App\Doctor;
use App\Http\Controllers\Controller;
use App\Page;
use App\Partner;
use App\Service;
use Illuminate\View\View;


class ServiceController extends Controller
{
    private $view = 'web.services.';

    /**
     * Show the application dashboard.
     * @return View
     */
    public function index(): View
    {
       $services = Service::withDescription();
       $page = Page::withDescription([16, 25]);
       $title = __('services.head');
       $pageTitle = explode(' ', $page[0]->title);
       $pageTitle2 = array_pop($pageTitle);
       $pageTitle1 = implode(' ', $pageTitle);

        $insurancePartnerPage = $page[1];
        $insurancePartnerPageTitle = explode(' ', $insurancePartnerPage->title);
        $insurancePartnerTitle2 = array_pop($insurancePartnerPageTitle);
        $insurancePartnerTitle1 = implode(' ', $insurancePartnerPageTitle);

        $insurancePartners = Partner::withDescription('insurance');

       return view($this->view.'index', get_defined_vars());
    }

    public function show(Service $service)
    {
        $service = Service::withDescription($service->id);
        $title = $service->name;
        $ids = $service->doctor_ids;
        if(count($ids) == 0)
        {
            $ids = ['0'];
        }
        $doctors = Doctor::withDescription($ids ?? []);
        return view($this->view.'show', get_defined_vars());

    }

}
