@extends('layouts.frontend')

@section('title', 'Холбоо барих — NSMA')

@section('content')

<section class="py-16 lg:py-20">
    <div class="max-w-6xl mx-auto px-4 lg:px-8 grid lg:grid-cols-2 gap-12">
        <div>
            <h1 class="text-3xl lg:text-4xl font-black mb-4">Бидэнтэй <span class="text-nsma-red">холбогдоорой</span></h1>
            <p class="text-gray-600 mb-8 max-w-md">Танай төсөл болон бизнесийн талаар зөвлөгөө авахыг хүсвэл зурвас үлдээгээрэй. Бид 24 цагийн дотор холбогдох болно.</p>

            <div class="space-y-5">
                <div class="flex items-center gap-4">
                    <span class="w-12 h-12 rounded-full bg-nsma-red/10 flex items-center justify-center text-nsma-red">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/></svg>
                    </span>
                    <div><div class="text-xs text-gray-500">Утас</div><a href="tel:{{ $siteSettings['contact_phone'] }}" class="font-semibold">{{ $siteSettings['contact_phone'] }}</a></div>
                </div>
                <div class="flex items-center gap-4">
                    <span class="w-12 h-12 rounded-full bg-nsma-red/10 flex items-center justify-center text-nsma-red">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
                    </span>
                    <div><div class="text-xs text-gray-500">И-мэйл</div><a href="mailto:{{ $siteSettings['contact_email'] }}" class="font-semibold">{{ $siteSettings['contact_email'] }}</a></div>
                </div>
                <div class="flex items-center gap-4">
                    <span class="w-12 h-12 rounded-full bg-nsma-red/10 flex items-center justify-center text-nsma-red">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a2 2 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"/></svg>
                    </span>
                    <div><div class="text-xs text-gray-500">Хаяг</div><div class="font-semibold">{{ $siteSettings['contact_address'] }}</div></div>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-2xl shadow-xl p-6 lg:p-8 border border-gray-100">
            <h3 class="text-xl font-bold mb-6">Зурвас илгээх</h3>
            <form id="contact-form" action="{{ route('contact.store') }}" method="POST" class="space-y-4">
                @csrf
                <div class="grid md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold mb-1">Нэр <span class="text-nsma-red">*</span></label>
                        <input type="text" name="name" required class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:border-nsma-red focus:ring-2 focus:ring-nsma-red/20 outline-none">
                    </div>
                    <div>
                        <label class="block text-sm font-semibold mb-1">И-мэйл <span class="text-nsma-red">*</span></label>
                        <input type="email" name="email" required class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:border-nsma-red focus:ring-2 focus:ring-nsma-red/20 outline-none">
                    </div>
                </div>
                <div class="grid md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-semibold mb-1">Утас</label>
                        <input type="tel" name="phone" class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:border-nsma-red focus:ring-2 focus:ring-nsma-red/20 outline-none">
                    </div>
                    <div>
                        <label class="block text-sm font-semibold mb-1">Сэдэв</label>
                        <input type="text" name="subject" class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:border-nsma-red focus:ring-2 focus:ring-nsma-red/20 outline-none">
                    </div>
                </div>
                <div>
                    <label class="block text-sm font-semibold mb-1">Зурвас <span class="text-nsma-red">*</span></label>
                    <textarea name="message" rows="4" required class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:border-nsma-red focus:ring-2 focus:ring-nsma-red/20 outline-none"></textarea>
                </div>
                <button type="submit" class="w-full bg-nsma-red text-white font-semibold px-6 py-3 rounded-lg hover:bg-red-600 transition flex items-center justify-center gap-2">
                    <span class="btn-text">Зурвас илгээх</span>
                    <svg class="btn-loading hidden w-5 h-5 animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8H4z"></path></svg>
                </button>
                <div id="contact-errors" class="hidden text-sm text-red-600"></div>
            </form>
        </div>
    </div>
</section>

@push('scripts')
<script>
    document.getElementById('contact-form').addEventListener('submit', async (e) => {
        e.preventDefault();
        const form = e.target;
        const btn = form.querySelector('button[type=submit]');
        const errorBox = document.getElementById('contact-errors');

        btn.disabled = true;
        form.querySelector('.btn-text').textContent = 'Илгээж байна...';
        form.querySelector('.btn-loading').classList.remove('hidden');
        errorBox.classList.add('hidden');

        const result = await window.ajaxSubmit(form);

        btn.disabled = false;
        form.querySelector('.btn-text').textContent = 'Зурвас илгээх';
        form.querySelector('.btn-loading').classList.add('hidden');

        if (result.ok && result.data.success) {
            window.showToast(result.data.message, 'success');
            form.reset();
        } else if (result.data.errors) {
            const messages = Object.values(result.data.errors).flat().join(', ');
            errorBox.textContent = messages;
            errorBox.classList.remove('hidden');
        } else {
            window.showToast(result.data.message || 'Алдаа гарлаа.', 'error');
        }
    });
</script>
@endpush

@endsection
