<?php

namespace App\View\Components\Front;

use App\Models\Setting;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Head extends Component
{
    public $title;
    public $meta;
    public $logo;

    public function __construct($page = null, $meta = [])
    {
        $setting = Setting::first();
        $defaultMeta = $setting->meta_tags ?? [];

        $pageMeta = $page?->meta_tags ?? [];

        // Merge page meta over setting meta
        $this->meta = array_merge($defaultMeta, $pageMeta);

        $this->meta = array_merge($this->meta, $meta);

        $this->logo = $setting->logo ? asset('storage/'.$setting->logo) : asset('front/images/logo.png');


        $this->title = $page?->title ?? $setting->title ?? config('app.name');
    }

    /**
     * Get the view / contents that represent the component.
     */
    public function render(): View|Closure|string
    {
        return view('components.front.head');
    }
}
