<?php

namespace Modules\Invoice\Components;

use App\Module\Module;
use Illuminate\Validation\Rule;
use Livewire\Component;
use Modules\Invoice\InvoiceSettings;
use Modules\Module\ModuleSettings;

class SettingView extends Component
{

    public $settingClass = InvoiceSettings::class;
    public InvoiceSettings $settings;

    public function mount(): void
    {
        $this->settings = app(InvoiceSettings::class);
    }

    public function save(): void
    {
        $this->settings->save();
        $this->dispatch('success', 'Einstellungen gespeichert.');
    }

    public function render()
    {
        return <<<'HTML'
            <x-page::setting-layout :active="$settingClass">
                <x-slot:right>
                    <x-form::save-button form="billsettingform"></x-form::save-button>
                </x-slot:right>
                <form id="billsettingform" class="grow p-6 grid grid-cols-2 gap-3 items-start content-start" wire:submit.prevent="save">
                    <x-form::text name="from" wire:model="settings.from" label="Absender" hint="Absender-Name in Kurzform, i.d.R. der kurze Stammesname"></x-form::text>
                    <x-form::text name="from_long" wire:model="settings.from_long" label="Absender (lang)" hint="Absender-Name in Langform, i.d.R. der Stammesname"></x-form::text>
                    <h2 class="text-lg font-semibold text-gray-300 col-span-2 mt-5">Kontaktdaten</h2>
                    <div class="col-span-2 text-gray-300 text-sm">Diese Kontaktdaten stehen im Absender-Bereich auf der Rechnung.</div>
                    <x-form::text name="address" wire:model="settings.address" label="Straße"></x-form::text>
                    <x-form::text name="zip" wire:model="settings.zip" label="PLZ"></x-form::text>
                    <x-form::text name="place" wire:model="settings.place" label="Ort"></x-form::text>
                    <x-form::text name="email" wire:model="settings.email" label="E-Mail-Adresse"></x-form::text>
                    <x-form::text name="mobile" wire:model="settings.mobile" label="Telefonnummer"></x-form::text>
                    <x-form::text name="website" wire:model="settings.website" label="Webseite"></x-form::text>
                    <x-form::text name="iban" wire:model="settings.iban" label="IBAN"></x-form::text>
                    <x-form::text name="bic" wire:model="settings.bic" label="BIC"></x-form::text>
                    <x-form::text name="remember_weeks" wire:model="settings.rememberWeeks" type="number" label="Erinnerung alle X Wochen versenden"></x-form::text>
                </form>
            </x-page::setting-layout>
        HTML;
    }
}