<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Models\Market;
use Illuminate\Http\Request;

class MarketController extends Controller
{
    public function index(Request $request)
    {
        $tab = $request->get('tab', 'coins');

        $tab = in_array($tab, ['coins', 'commodities', 'metals'], true) ? $tab : 'coins';

        $typeMap = [
            'coins' => 'crypto',
            'commodities' => 'commodity',
            'metals' => 'metal',
        ];

        $markets = Market::query()
            ->where('type', $typeMap[$tab])
            ->orderBy('sort_order')
            ->orderBy('name')
            ->get();

        return view('client.markets.index', compact('markets', 'tab'));
    }
}
