@model OnlyOneAccessTemplate.Models.ConversionConfig

<section id="conversion-form" class="conversion-section py-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="conversion-form-wrapper">
                    <div class="row g-0 shadow-lg rounded-3 overflow-hidden">
                        <!-- Form Side -->
                        <div class="col-md-7 bg-white p-5">
                            <div class="form-header text-center mb-4">
                                <h3 class="fw-bold mb-3">@ViewBag.FormTitle</h3>
                                <p class="text-muted">@ViewBag.FormSubtitle</p>
                            </div>

                            <form id="conversionForm" action="@(Model?.FormAction ?? "/conversion/submit")" method="post" class="needs-validation" novalidate>
                                <input type="hidden" name="language" value="@ViewBag.Language" />
                                <input type="hidden" name="pageName" value="@ViewBag.CurrentPage" />
                                <input type="hidden" name="source" id="source" />
                                <input type="hidden" name="medium" id="medium" />
                                <input type="hidden" name="campaign" id="campaign" />

                                @if (Model?.FormFields?.Any() == true)
                                {
                                    foreach (var field in Model.FormFields.OrderBy(f => f.Order))
                                    {
                                        <div class="mb-3">
                                            <label for="@field.Name" class="form-label">
                                                @field.Label
                                                @if (field.Required)
                                                {
                                                    <span class="text-danger">*</span>
                                                }
                                            </label>

                                            @{
                                                var fieldType = field.Type.ToLowerInvariant();
                                                var requiredAttr = field.Required ? "required" : "";
                                                var patternAttr = !string.IsNullOrEmpty(field.ValidationRegex) ? $"pattern=\"{field.ValidationRegex}\"" : "";
                                            }

                                            @if (fieldType == "email")
                                            {
                                                <input type="email"
                                                       class="form-control form-control-lg"
                                                       id="@field.Name"
                                                       name="@field.Name"
                                                       placeholder="@field.Placeholder"
                                                @Html.Raw(requiredAttr) />
                                                <div class="invalid-feedback">
                                                    @ViewBag.EmailValidationMessage
                                                </div>
                                            }
                                            else if (fieldType == "tel" || fieldType == "phone")
                                            {
                                                <input type="tel"
                                                       class="form-control form-control-lg"
                                                       id="@field.Name"
                                                       name="@field.Name"
                                                       placeholder="@field.Placeholder"
                                                @Html.Raw(requiredAttr) />
                                                <div class="invalid-feedback">
                                                    @ViewBag.PhoneValidationMessage
                                                </div>
                                            }
                                            else if (fieldType == "textarea")
                                            {
                                                <textarea class="form-control form-control-lg"
                                                          id="@field.Name"
                                                          name="@field.Name"
                                                          rows="4"
                                                          placeholder="@field.Placeholder"
                                                @Html.Raw(requiredAttr)></textarea>
                                                <div class="invalid-feedback">
                                                    @ViewBag.RequiredFieldMessage
                                                </div>
                                            }
                                            else if (fieldType == "select")
                                            {
                                                <select class="form-select form-select-lg"
                                                        id="@field.Name"
                                                        name="@field.Name"
                                                @Html.Raw(requiredAttr)>
                                                    <option value="">@field.Placeholder</option>
                                                    @if (field.Properties.ContainsKey("options") && field.Properties["options"] is IEnumerable<string> options)
                                                    {
                                                        foreach (var option in options)
                                                        {
                                                            <option value="@option">@option</option>
                                                        }
                                                    }
                                                </select>
                                                <div class="invalid-feedback">
                                                    @ViewBag.RequiredFieldMessage
                                                </div>
                                            }
                                            else
                                            {
                                                <input type="@field.Type"
                                                       class="form-control form-control-lg"
                                                       id="@field.Name"
                                                       name="@field.Name"
                                                       placeholder="@field.Placeholder"
                                                @Html.Raw(requiredAttr)
                                                @Html.Raw(patternAttr) />
                                                <div class="invalid-feedback">
                                                    @ViewBag.RequiredFieldMessage
                                                </div>
                                            }
                                        </div>
                                    }
                                }
                                else
                                {
                                    <!-- Campos padrão -->
                                    <div class="mb-3">
                                        <label for="name" class="form-label">@ViewBag.NameLabel <span class="text-danger">*</span></label>
                                        <input type="text" class="form-control form-control-lg" id="name" name="name" placeholder="@ViewBag.NamePlaceholder" required />
                                        <div class="invalid-feedback">@ViewBag.RequiredFieldMessage</div>
                                    </div>

                                    <div class="mb-3">
                                        <label for="email" class="form-label">@ViewBag.EmailLabel <span class="text-danger">*</span></label>
                                        <input type="email" class="form-control form-control-lg" id="email" name="email" placeholder="@ViewBag.EmailPlaceholder" required />
                                        <div class="invalid-feedback">@ViewBag.EmailValidationMessage</div>
                                    </div>

                                    <div class="mb-3">
                                        <label for="phone" class="form-label">@ViewBag.PhoneLabel</label>
                                        <input type="tel" class="form-control form-control-lg" id="phone" name="phone" placeholder="@ViewBag.PhonePlaceholder" />
                                        <div class="invalid-feedback">@ViewBag.PhoneValidationMessage</div>
                                    </div>
                                }

                                <!-- Checkbox de consentimento -->
                                <div class="mb-4">
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" id="consent" name="consent" required />
                                        <label class="form-check-label small" for="consent">
                                            @Html.Raw(ViewBag.ConsentText)
                                        </label>
                                        <div class="invalid-feedback">@ViewBag.ConsentValidationMessage</div>
                                    </div>
                                </div>

                                <!-- Submit Button -->
                                <div class="d-grid">
                                    <button type="submit" class="btn btn-primary btn-lg fw-bold" id="submitBtn">
                                        <span class="btn-text">@ViewBag.SubmitButtonText</span>
                                        <span class="btn-loading d-none">
                                            <span class="spinner-border spinner-border-sm me-2" role="status"></span>
                                            @ViewBag.LoadingText
                                        </span>
                                    </button>
                                </div>

                                <!-- Security badges -->
                                <div class="security-badges text-center mt-3">
                                    <small class="text-muted d-flex align-items-center justify-content-center">
                                        <i class="fas fa-lock me-1"></i>
                                        @ViewBag.SecurityText
                                    </small>
                                </div>
                            </form>
                        </div>

                        <!-- Benefits Side -->
                        <div class="col-md-5 bg-primary text-white p-5 d-flex flex-column justify-content-center">
                            <div class="benefits-content">
                                <h4 class="fw-bold mb-4">@ViewBag.BenefitsTitle</h4>

                                <div class="benefit-list">
                                    @if (ViewBag.BenefitsList is string[] benefits)
                                    {
                                        foreach (var benefit in benefits)
                                        {
                                            <div class="d-flex align-items-start mb-3">
                                                <i class="fas fa-check-circle text-success me-3 mt-1"></i>
                                                <span>@benefit</span>
                                            </div>
                                        }
                                    }
                                    else
                                    {
                                        <div class="d-flex align-items-start mb-3">
                                            <i class="fas fa-check-circle text-success me-3 mt-1"></i>
                                            <span>@ViewBag.DefaultBenefit1</span>
                                        </div>
                                        <div class="d-flex align-items-start mb-3">
                                            <i class="fas fa-check-circle text-success me-3 mt-1"></i>
                                            <span>@ViewBag.DefaultBenefit2</span>
                                        </div>
                                        <div class="d-flex align-items-start mb-3">
                                            <i class="fas fa-check-circle text-success me-3 mt-1"></i>
                                            <span>@ViewBag.DefaultBenefit3</span>
                                        </div>
                                    }
                                </div>

                                @if (!string.IsNullOrEmpty(ViewBag.TestimonialsCount as string))
                                {
                                    <div class="testimonial-count mt-4 pt-4 border-top border-light border-opacity-25">
                                        <div class="d-flex align-items-center">
                                            <div class="stars text-warning me-2">
                                                <i class="fas fa-star"></i>
                                                <i class="fas fa-star"></i>
                                                <i class="fas fa-star"></i>
                                                <i class="fas fa-star"></i>
                                                <i class="fas fa-star"></i>
                                            </div>
                                            <small>@ViewBag.TestimonialsCount</small>
                                        </div>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Success Modal -->
<div class="modal fade" id="successModal" tabindex="-1" aria-labelledby="successModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-body text-center p-5">
                <div class="success-icon mb-4">
                    <i class="fas fa-check-circle fa-4x text-success"></i>
                </div>
                <h4 class="fw-bold mb-3">@ViewBag.SuccessTitle</h4>
                <p class="text-muted mb-4">@ViewBag.SuccessMessage</p>
                <button type="button" class="btn btn-primary" data-bs-dismiss="modal">@ViewBag.CloseButtonText</button>
            </div>
        </div>
    </div>
</div>