<?php

use Livewire\Component;
use App\Models\Setting;

return new class extends Component
{
    public $settings = [];

    public function render()
    {
        return $this->view()->layout('layouts::auth');
    }

    public function mount()
    {
        $this->settings = Setting::pluck('setting_value', 'setting_key')->toArray();
        
        $defaults = [
            'site_name' => '',
            'site_slogan' => '',
            'contact_email' => '',
            'contact_phone' => '',
            'contact_address' => '',
            'social_youtube' => '',
            'social_instagram' => '',
            'social_facebook' => '',
            'seo_description' => '',
            'google_analytics_id' => '',
        ];

        foreach ($defaults as $key => $value) {
            if (!isset($this->settings[$key])) {
                $this->settings[$key] = $value;
            }
        }
    }

    public function save()
    {
        foreach ($this->settings as $key => $value) {
            Setting::updateOrCreate(
                ['setting_key' => $key],
                ['setting_value' => $value]
            );
        }

        session()->flash('message', 'Settings updated successfully.');
    }

    protected function view($data = [])
    {
        return app('view')->file('D:\02-my freelance\00-DR_Padhi\DR_PADHI\storage\framework/views/livewire/views/3b3ad4ec.blade.php', $data);
    }
};
