<?php

namespace App\Http\Controllers\Admin\Account;

use App\Http\Controllers\Concerns\FlashesEntityMessage;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Account\UpdateAppearanceRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Symfony\Component\HttpFoundation\Cookie;

class AppearanceController extends Controller
{
    use FlashesEntityMessage;

    public function edit(Request $request): Response
    {
        return Inertia::render('admin/account/Appearance', [
            'appearance' => $request->cookie('appearance', 'system'),
        ]);
    }

    public function update(UpdateAppearanceRequest $request): RedirectResponse
    {
        $appearance = $request->string('appearance')->toString();

        $this->flashUpdated('Tampilan');

        return redirect()
            ->route('admin.account.appearance')
            ->withCookie(Cookie::create('appearance')
                ->withValue($appearance)
                ->withExpires(now()->addYear())
                ->withPath('/')
                ->withHttpOnly(false)
                ->withSameSite('lax'));
    }
}
