<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class UserInfoController extends Controller
{
    public function show()
    {
        $user_id = session('user_id');
        if (!$user_id) {
            return redirect('/login');
        }
        $user = DB::table('user')->where('user_id', $user_id)->first();

        // 利用者区分をusertypeテーブルから取得
        $user_category = '';
        if (isset($user->user_categoryid)) {
            $usertype = DB::table('usertype')
                ->where('user_categoryid', $user->user_categoryid)
                ->first();
            if ($usertype && isset($usertype->usertype_subject1)) {
                $user_category = $usertype->usertype_subject1;
            }
        }

        \Log::info('ユーザー情報確認画面にアクセス', [
            'user_id' => $user_id,
        ]);

        return view('user.info', [
            'user' => $user,
            'user_category' => $user_category,
            'active_menu' => 'SWC-1-1', // マイページメニューの選択状態用
            'user_name' => $user ? $user->user_name : '', // ユーザー名（ヘッダー用）
        ]);
    }
}
