@extends('layouts.app')

@section('title', __('vrc::lang.settings'))

@section('content')
<section class="content-header">
    <h1>@lang('vrc::lang.settings')</h1>
    <p>@lang('vrc::lang.settings_tagline')</p>
</section>

<section class="content">
    {!! Form::open(['route' => 'vrc.settings.update', 'method' => 'PUT', 'id' => 'vrc_settings_form']) !!}

    @component('components.widget', ['class' => 'box-primary', 'title' => __('vrc::lang.general')])
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::label('default_labor_rate', __('vrc::lang.default_labor_rate') . ':') !!}
                    {!! Form::number('default_labor_rate', $settings['default_labor_rate'] ?? 0, ['class' => 'form-control', 'min' => '0', 'step' => '0.01']) !!}
                    <p class="help-block">@lang('vrc::lang.default_labor_rate_help')</p>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::label('estimate_validity_days', __('vrc::lang.estimate_validity_days') . ':') !!}
                    {!! Form::number('estimate_validity_days', $settings['estimate_validity_days'] ?? 14, ['class' => 'form-control', 'min' => '0']) !!}
                </div>
            </div>
        </div>
    @endcomponent

    @component('components.widget', ['class' => 'box-primary', 'title' => __('vrc::lang.source_strategy')])
        <p class="help-block">@lang('vrc::lang.source_strategy_help')</p>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::label('estimate_source', __('vrc::lang.estimate_source') . ':') !!}
                    {!! Form::select('estimate_source', [
                        'native' => __('vrc::lang.source_native_estimates'),
                        'erp'    => __('vrc::lang.source_erp_quotation'),
                    ], $settings['estimate_source'] ?? 'native', ['class' => 'form-control']) !!}
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::label('service_catalog_source', __('vrc::lang.service_catalog_source') . ':') !!}
                    {!! Form::select('service_catalog_source', [
                        'native' => __('vrc::lang.source_native_catalog'),
                        'erp'    => __('vrc::lang.source_erp_products'),
                    ], $settings['service_catalog_source'] ?? 'native', ['class' => 'form-control']) !!}
                </div>
            </div>
        </div>
    @endcomponent

    @component('components.widget', ['class' => 'box-primary', 'title' => __('vrc::lang.comms_matrix')])
        <p class="help-block">@lang('vrc::lang.comms_matrix_help')</p>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::label('comms_channel', __('vrc::lang.comms_channel') . ':') !!}
                    {!! Form::select('comms_channel', ['sms' => 'SMS', 'whatsapp' => 'WhatsApp'], $settings['comms_channel'] ?? 'sms', ['class' => 'form-control']) !!}
                </div>
            </div>
        </div>
        @php $matrix = (array) ($settings['comms_matrix'] ?? []); @endphp
        <div class="row">
            @foreach (['estimate_sent','ready_for_pickup','invoice_issued','payment_received','appointment_confirmed'] as $event)
                <div class="col-md-4">
                    <div class="checkbox">
                        <label>
                            {!! Form::checkbox("comms_matrix[$event]", 1, (bool) ($matrix[$event] ?? false)) !!}
                            @lang('vrc::lang.comms_' . $event)
                        </label>
                    </div>
                </div>
            @endforeach
        </div>
    @endcomponent

    <div class="form-group">
        <button type="submit" class="btn btn-primary">@lang('messages.update')</button>
    </div>

    {!! Form::close() !!}
</section>
@endsection
