<?php

namespace App\Livewire\Products;

use App\Models\Products\Product;
use Livewire\Component;

class Show extends Component
{
    public Product $product;

    public function mount(Product $product)
    {
        $this->product = $product->load([
            'tokens.client',
            'tokens.environments.client'
        ]);
    }

    public function getSetupsProperty()
    {
        return \App\Models\Setups\Setup::where('product_id', $this->product->id)
            ->with('creator')
            ->orderByDesc('version')
            ->get();
    }

    public function getScssVersionsProperty()
    {
        return \App\Models\Scss\ScssVersion::where('product_id', $this->product->id)
            ->with(['creator', 'files'])
            ->withCount('files')
            ->orderByDesc('version')
            ->get();
    }

    public function getJsVersionsProperty()
    {
        return \App\Models\Js\JsVersion::where('product_id', $this->product->id)
            ->with(['creator', 'files'])
            ->withCount('files')
            ->orderByDesc('version')
            ->get();
    }

    public function getScssCdnBundlesProperty()
    {
        return \App\Models\ScssCdn\ScssCdnBundle::where('product_id', $this->product->id)
            ->with(['creator', 'files'])
            ->withCount('files')
            ->orderByDesc('version')
            ->get();
    }

    public function getFeatureVersionsProperty()
    {
        return \App\Models\Features\FeatureVersion::where('product_id', $this->product->id)
            ->with(['creator', 'features'])
            ->withCount('features')
            ->orderByDesc('version')
            ->limit(10)
            ->get();
    }

    public function getTutorialVersionsProperty()
    {
        return \App\Models\Tutorials\TutorialVersion::where('product_id', $this->product->id)
            ->with(['creator', 'tutorials'])
            ->withCount('tutorials')
            ->orderByDesc('version')
            ->limit(10)
            ->get();
    }

    public function getResourceVersionsProperty()
    {
        return \App\Models\Resources\ResourceVersion::where('product_id', $this->product->id)
            ->with(['creator', 'resources'])
            ->withCount('resources')
            ->orderByDesc('version')
            ->limit(10)
            ->get();
    }

    public function render()
    {
        return view('livewire.products.show')->layout('layouts.app');
    }
}

