<?php

namespace App\Livewire;

use App\Models\WelcomePageContent;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Schema;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;

class EditWelcomePageContent extends Component
{
    use LivewireAlert;

    public WelcomePageContent $content;

    public $columns;

    protected $rules = [
        'content.welcome_heading' => 'nullable|string',
        'content.welcome_heading' => 'nullable|string',
        'content.welcome_sub_heading' => 'nullable|string',
        'content.features_section_heading' => 'nullable|string',
        'content.features_section_sub_heading' => 'nullable|string',
        'content.crypto_card_heading' => 'nullable|string',
        'content.crypto_card_text' => 'nullable|string',
        'content.holdings_card_heading' => 'nullable|string',
        'content.holdings_card_text' => 'nullable|string',
        'content.international_transfer_card_heading' => 'nullable|string',
        'content.international_transfer_card_text' => 'nullable|string',
        'content.bills_card_heading' => 'nullable|string',
        'content.gift_cards_card_heading' => 'nullable|string',
        'content.gift_cards_card_text' => 'nullable|string',
        'content.about_us_section_heading' => 'nullable|string',
        'content.about_us_section_sub_heading' => 'nullable|string',
        'content.mission_statement' => 'nullable|string',
        'content.vision_statement' => 'nullable|string',
        'content.testimonial_section_heading' => 'nullable|string',
        'content.contact_us_section_heading' => 'nullable|string',
        'content.contact_us_section_sub_heading' => 'nullable|string',
        'content.faq_section_sub_heading' => 'nullable|string',
        'content.call_to_action_section_heading' => 'nullable|string',
        'content.call_to_action_section_sub_heading' => 'nullable|string',
        'content.bills_card_text' => 'nullable|string'
    ];

    public function mount()
    {
        $this->content =  WelcomePageContent::first();

        $this->columns = Schema::getColumnListing('welcome_page_contents');

        // sort columns

        $this->columns = Arr::sort($this->columns);

        // dd($this->content, $this->columns);
    }

    public function update()
    {

        $this->validate();

        $this->content->save();

        $this->alert('success', 'Content Updated Successfully');
    }

    public function render()
    {
        return view('livewire.edit-welcome-page-content');
    }
}
