<?php

namespace App\Http\Controllers\Vendor;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class VendorProfileController extends Controller
{
    public function edit()
    {
        $vendor = Auth::user()->vendor;
        return view('vendor.profile.edit', compact('vendor'));
    }

    public function update(Request $request)
    {

    dd([
        'controller' => 'VendorProfileController',
        'request_url' => $request->url(),
        'request_method' => $request->method(),
        'request_data' => $request->except(['_token', '_method']),
    ]);
        $vendor = Auth::user()->vendor;

        $data = $request->validate([
            'shop_name' => 'required|string|max:255',
            'description' => 'nullable|string',
            'phone' => 'nullable|string|max:20',
            'address' => 'nullable|string',
            'city' => 'nullable|string|max:100',
            'state' => 'nullable|string|max:100',
            'country' => 'nullable|string|max:100',
            'zip_code' => 'nullable|string|max:20',
            'logo' => 'nullable|image|max:2048',
            'banner' => 'nullable|image|max:4096',
        ]);

        if ($request->hasFile('logo')) {
            $data['logo'] = $request->file('logo')->store('vendors/logos', 'public');
        }

        if ($request->hasFile('banner')) {
            $data['banner'] = $request->file('banner')->store('vendors/banners', 'public');
        }

        $vendor->update($data);

        return redirect()->route('vendor.profile.edit')
            ->with('success', 'Profile updated successfully.');
    }
}
