@using Microsoft.Extensions.Localization
@inject IStringLocalizer<QRRapidoApp.Resources.SharedResource> Localizer
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
@model bool

@{
    var isPremiumUser = Model; // Receives isPremiumUser from _Layout
    var telegramUrl = Configuration["Support:TelegramUrl"] ?? "https://t.me/jobmakerbr";
    var formConfigured = !string.IsNullOrWhiteSpace(Configuration["Support:FormspreeUrl"]);
    var formLink = Url.Action("PremiumContact", "Support");
    var formEnabled = formConfigured && !string.IsNullOrEmpty(formLink);
}

<div class="support-fab-root" data-support-fab>
    <div id="supportFabMenu"
         class="support-fab-menu"
         data-support-fab-menu
         role="menu"
         aria-label="@Localizer["PremiumSupportMenuIntro"]"
         hidden>
        @if (isPremiumUser)
        {
            <p class="support-fab-text">@Localizer["PremiumSupportMenuIntro"]</p>
        }
        else
        {
            <p class="support-fab-text">@Localizer["RateOurService"]</p>
        }
        <div class="support-fab-actions">
            @if (isPremiumUser)
            {
                <a class="support-fab-link support-telegram"
                   href="@telegramUrl"
                   target="_blank"
                   rel="noopener"
                   role="menuitem">
                    <i class="fab fa-telegram-plane icon" aria-hidden="true"></i>
                    <span>@Localizer["PremiumSupportOptionTelegram"]</span>
                </a>
                @if (formEnabled)
                {
                    <a class="support-fab-link support-form"
                       href="@formLink"
                       target="_blank"
                       rel="noopener"
                       role="menuitem">
                        <i class="fas fa-envelope-open-text icon" aria-hidden="true"></i>
                        <span>@Localizer["PremiumSupportOptionForm"]</span>
                    </a>
                }
            }
            <button type="button"
                    class="support-fab-link support-rating"
                    data-rating-trigger
                    role="menuitem">
                <i class="fas fa-star icon" aria-hidden="true"></i>
                <span>@Localizer["RateOurService"]</span>
            </button>
        </div>
    </div>

    <button type="button"
            class="btn btn-primary fab-trigger"
            data-support-fab-toggle
            aria-controls="supportFabMenu"
            aria-expanded="false">
        <i class="fas fa-headset" aria-hidden="true"></i>
        <span class="fab-trigger-text">@Localizer["PremiumSupportFabButton"]</span>
    </button>
</div>

<!-- Rating Modal -->
<div class="modal fade" id="ratingModal" tabindex="-1" aria-labelledby="ratingModalLabel" aria-hidden="true" data-rating-modal>
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header border-0">
                <h5 class="modal-title w-100 text-center" id="ratingModalLabel">
                    <i class="fas fa-star text-warning me-2"></i>
                    @Localizer["RateOurService"]
                </h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="@Localizer["Close"]"></button>
            </div>
            <div class="modal-body">
                <form id="ratingForm">
                    <!-- Star Rating -->
                    <div class="text-center mb-4">
                        <p class="mb-3">@Localizer["RatingQuestion"]</p>
                        <div class="star-rating" data-star-rating>
                            <i class="far fa-star star" data-star="1"></i>
                            <i class="far fa-star star" data-star="2"></i>
                            <i class="far fa-star star" data-star="3"></i>
                            <i class="far fa-star star" data-star="4"></i>
                            <i class="far fa-star star" data-star="5"></i>
                        </div>
                        <input type="hidden" name="rating" id="ratingValue" required>
                    </div>

                    <!-- Name Field -->
                    <div class="mb-3">
                        <label for="ratingName" class="form-label">@Localizer["YourName"] <span class="text-muted">(@Localizer["Optional"])</span></label>
                        <input type="text" class="form-control" id="ratingName" name="name" placeholder="@Localizer["EnterYourName"]">
                    </div>

                    <!-- Email Field -->
                    <div class="mb-3">
                        <label for="ratingEmail" class="form-label">@Localizer["YourEmail"] <span class="text-muted">(@Localizer["Optional"])</span></label>
                        <input type="email" class="form-control" id="ratingEmail" name="email" placeholder="nome@exemplo.com">
                    </div>

                    <!-- Comment Field -->
                    <div class="mb-3">
                        <label for="ratingComment" class="form-label">@Localizer["YourComment"] <span class="text-muted">(@Localizer["Optional"])</span></label>
                        <textarea class="form-control" id="ratingComment" name="comment" rows="3" placeholder="@Localizer["TellUsMore"]"></textarea>
                    </div>

                    <!-- Submit Button -->
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary btn-lg" id="submitRating">
                            <i class="fas fa-paper-plane me-2"></i>
                            @Localizer["SendRating"]
                        </button>
                    </div>
                </form>

                <!-- Success Message -->
                <div class="alert alert-success mt-3 d-none" id="ratingSuccess">
                    <i class="fas fa-check-circle me-2"></i>
                    @Localizer["RatingThanks"]
                </div>
            </div>
        </div>
    </div>
</div>
