@php 
    $title = '';
    if (! isset($episode) && isset($hentai)) {
        $episode = $hentai->episodes[0];
        $gallery = $episode->gallery;
        $title = "{$episode->title} - Watch All Episodes English Subbed in 4K | hstream.moe";
        $canonical = url('/hentai/'.$hentai->slug);
    } else {
        $title = "{$episode->title} Episode {$episode->episode} - English Subbed 4K Stream | hstream.moe";
        $canonical = url('/hentai/'.$episode->slug);
    }

    $description = Str::limit(
        preg_replace('/\s+/', ' ', strip_tags($episode->description)),
        160
    );
@endphp

<!-- Site meta -->
<title>{{ $title }}</title>
<link rel="canonical" href="{{ $canonical }}">
<meta name="robots" content="index,follow,max-image-preview:large">
<meta name="description" content="{{ $description }}">

<!-- Open Graph -->
<meta property="og:title" content="{{ $title }}">
<meta property="og:description" content="{{ $description  }}">
<meta property="og:type" content="video.other">
<meta property="og:url" content="{{ $canonical }}">
<meta property="og:locale" content="en_US">
<meta property="og:site_name" content="hstream.moe">

@if(isset($gallery) && $episode->gallery->isNotEmpty())
<meta property="og:image" content="{{ url($gallery[0]->image_url) }}">
<meta property="og:image:secure_url" content="{{ url($gallery[0]->image_url) }}">
<meta property="og:image:alt" content="{{ $episode->title }} Episode {{ $episode->episode }}">
<meta property="og:image:width" content="1280">
<meta property="og:image:height" content="720">
<meta property="og:image:type" content="image/webp">
@endif

<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="{{ $title }}">
<meta name="twitter:description" content="{{ $description }}">
@if($episode->gallery->isNotEmpty())
<meta name="twitter:image" content="{{ url($episode->gallery[0]->image_url) }}">
<meta name="twitter:image:alt" content="{{ $episode->title }} Episode {{ $episode->episode }}">
@endif

<!-- JSON-LD -->
@if (!isset($hentai))
@php
    $data = [
        "@context" => "https://schema.org",
        "@type" => "VideoObject",
        "name" => "$episode->title Episode $episode->episode",
        "description" => $description,
        "url" => $canonical,
        "uploadDate" => $episode->created_at->toIso8601String()
    ];

    if ( $episode->gallery->isNotEmpty() ) {
        $data["thumbnailUrl"] = url($episode->gallery[0]->image_url);
    }

    $tags = [];
    foreach($episode->tags as $tag) {
        $tags[] = $tag->name;
    }
    $data["genre"] = $tags;

    $data["interactionStatistic"] = [
        "@type" => "InteractionCounter",
        "interactionType" => [
            "@type" => "WatchAction"
        ],
        "userInteractionCount" => $episode->view_count
    ];
@endphp
<script type="application/ld+json">
{!! json_encode($data, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE) !!}
</script>
@endif