<?php

namespace App\Livewire;

use Livewire\Component;
use App\Models\Work as WorkModel;

class Work extends Component
{
    public $activeFilter = 'recommended';

    public function setFilter($filter)
    {
        if (in_array($filter, ['recommended', 'latest'])) {
            $this->activeFilter = $filter;
        }
    }

    // Recommended → editorial order (position based)
    public function getRecommendedProperty()
    {
        return WorkModel::where('status', 1)
            ->orderBy('position')
            ->get();
    }

    
   // Latest → newest works (collection)
// public function getLatestProperty()
// {
//     return WorkModel::where('status', 1)
//         ->orderByDesc('created_at')
//         ->take(2)  
//         ->get();
// }

public function getLatestProperty()
{
    $latestClients = [
        'Bank of Maharashtra',
        'Madhavbaug',
        'Manipal Cigna',
        'Vasant Masala',
        'REID & TAYLOR',
        'Hari Darshan',
        'Fino Payments Bank',
        'Siemens',
        'Dehaat Starter',
        'Icon Steel',
        'BAYER',
        'VIM'
    ];

    return WorkModel::where('status', 1)
        ->whereIn('client_name', $latestClients)
        ->orderByRaw("FIELD(client_name, '" . implode("','", $latestClients) . "')")
        ->get();
}


    public function render()
    {
        return view('livewire.work', [
            'recommended' => $this->recommended,
            'latest'      => $this->latest,
            'activeFilter'=> $this->activeFilter,
        ])->layout('components.layout');
    }
}