@extends('layouts.app')

@section('title', 'Nova proposta')
@section('page-title', 'Nova proposta')

@section('content')
    @include('partials.flash')

    <form method="post" action="{{ route('proposals.store') }}" class="mx-auto max-w-2xl space-y-5 rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
        @csrf
        <div>
            <label class="block text-sm font-medium">Pessoa</label>
            <select name="contact_id" required class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                <option value="">Selecione…</option>
                @foreach ($contacts as $c)
                    <option value="{{ $c->id }}">{{ $c->display_name ?: $c->phone }}</option>
                @endforeach
            </select>
        </div>
        <div>
            <label class="block text-sm font-medium">Negociação (opcional)</label>
            <select name="deal_id" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                <option value="">—</option>
                @foreach ($deals as $d)
                    <option value="{{ $d->id }}">{{ $d->title }}</option>
                @endforeach
            </select>
        </div>
        <div>
            <label class="block text-sm font-medium">Template</label>
            <select name="template_id" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                @foreach ($templates as $t)
                    <option value="{{ $t->id }}" @selected($t->is_default)>{{ $t->name }} ({{ $t->purpose->label() }})</option>
                @endforeach
            </select>
        </div>
        <div class="grid gap-4 sm:grid-cols-2">
            <div>
                <label class="block text-sm font-medium">Valor</label>
                <input type="number" step="0.01" name="amount" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
            </div>
            <div>
                <label class="block text-sm font-medium">Comissão %</label>
                <input type="number" step="0.01" name="commission_percent" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
            </div>
        </div>
        <div>
            <label class="block text-sm font-medium">Mensagem</label>
            <textarea name="intro_message" rows="3" class="mt-1 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">Segue nossa proposta comercial para sua análise.</textarea>
        </div>
        <label class="flex items-center gap-2 text-sm">
            <input type="checkbox" name="share_now" value="1" class="rounded border-slate-300 text-emerald-600" checked>
            Compartilhar no portal e enviar link pelo WhatsApp
        </label>
        <div class="flex justify-end gap-2">
            <a href="{{ route('proposals.index') }}" class="rounded-lg border border-slate-300 px-4 py-2 text-sm">Cancelar</a>
            <button class="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white">Gerar proposta</button>
        </div>
    </form>
@endsection
