<?php

namespace App\Web\Components\Meeting;

use App\Exceptions\ApiException;
use App\Web\Facades\MeetingFacade;
use App\Web\Facades\WebFacade;
use App\Web\Services\WebService;
use Illuminate\View\Component;

class MeetingInfo extends Component
{
    protected $viewFile; //视图地址
    protected $router_path;
    protected $meeting_id;


    public function __construct($viewFile = "", $params = [], $id = 0, $routerPath = '')
    {

        if (empty($viewFile)) {
            throw new ApiException("common.page_none", '您访问的地址不存在~');
        }
        $this->meeting_id = $params['id'] ?? $id;
        $this->router_path = $params['router_path'] ?? $routerPath;
        $this->viewFile = $viewFile;
    }


    /**
     *
     */
    public function render()
    {
        $params = [
            "id" => $this->meeting_id,
        ];
        $meetingInfo = MeetingFacade::getMeetingRenderData($params);
        if (!empty($meetingInfo['expand_content'])) {
            $meetingInfo['expand_content'] = mapByKey($meetingInfo['expand_content'], 'key');
            if (!empty($meetingInfo['speech_schedule'])) {
                foreach ($meetingInfo['speech_schedule'] as $speech_schedule_key => $speech_schedule_item) {
                    if (!empty($speech_schedule_item['expand_content'])) {
                        $meetingInfo['speech_schedule'][$speech_schedule_key]['expand_content'] = mapByKey($speech_schedule_item['expand_content'], 'key');
                    } else {
                        $meetingInfo['speech_schedule'][$speech_schedule_key]['expand_content'] = [];
                    }
                }
            }
        }
        $retData['event_detail']=$meetingInfo;
        if (!empty($this->router_path)) {
            $pageContent = WebFacade::getStaticPageInfo(['route_path' => $this->router_path]);
            $retData['page_content'] = $pageContent['page_content'];
        }

        $retData['menu_data'] = WebFacade::getWebMenu();
        //dd($retData);
        return view($this->viewFile, $retData);
    }

}
