<?php

namespace Tests\Feature;

use App\Enums\UserRole;
use App\Models\Business;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PricingToggleUiTest extends TestCase
{
    use RefreshDatabase;

    public function test_landing_pricing_has_working_monthly_yearly_toggle_markup(): void
    {
        $this->seed();

        $this->get('/')
            ->assertOk()
            ->assertSee('data-pricing-scope', false)
            ->assertSee('data-billing-cycle="yearly"', false)
            ->assertSee('data-yearly="$390"', false)
            ->assertSee('booklio-ui.js', false)
            ->assertDontSee('Monthly -', false);
    }

    public function test_auth_choose_plan_uses_shared_billing_toggle(): void
    {
        $user = User::factory()->create(['role' => UserRole::BusinessOwner->value]);

        $this->actingAs($user)
            ->get('/choose-plan')
            ->assertOk()
            ->assertSee('data-pricing-scope', false)
            ->assertSee('data-billing-cycle="yearly"', false)
            ->assertSee('data-yearly="$390"', false)
            ->assertSee('booklio-ui.js', false)
            ->assertDontSee('Yearly price switching', false);
    }

    public function test_business_upgrade_page_updates_hidden_billing_inputs(): void
    {
        $this->seed();
        $owner = User::query()->where('email', 'owner@booklio.test')->firstOrFail();
        $business = Business::query()->where('slug', 'glow-beauty-salon')->firstOrFail();

        $this->actingAs($owner)
            ->withSession(['current_business_id' => $business->id])
            ->get('/subscription/upgrade')
            ->assertOk()
            ->assertSee('data-plan-billing-input', false)
            ->assertSee('data-yearly="$390.00"', false)
            ->assertDontSee('Monthly -', false);
    }

    public function test_super_admin_plans_do_not_show_yearly_price_in_monthly_caption(): void
    {
        $this->seed();
        $admin = User::query()->where('email', 'admin@booklio.test')->firstOrFail();

        $this->actingAs($admin)
            ->get('/super-admin/plans')
            ->assertOk()
            ->assertSee('data-pricing-scope', false)
            ->assertSee('data-billing-cycle="yearly"', false)
            ->assertSee('data-yearly="$390.00"', false)
            ->assertSee('Billed monthly')
            ->assertDontSee('Monthly -', false);
    }
}
