"""Step definitions for BPM Clock feature."""
from behave import given, when, then
import requests


@given('the BPM clock is displayed')
def bpm_clock_displayed(context):
    resp = requests.get(context.base_url)
    context.page_html = resp.text


@then('a BPM input is shown in the header')
def bpm_input_in_header(context):
    html = context.page_html
    assert 'bpmInput' in html or 'bpm' in html.lower(), \
        "Page should have a BPM control"


@then('the default value is 120')
def bpm_default_120(context):
    html = context.page_html
    assert 'value="120"' in html or '120' in html, \
        "Default BPM should be 120"


@given('the BPM clock is running')
def bpm_clock_running(context):
    pass


@when('I change the BPM value to 140')
def change_bpm(context):
    pass


@when('I click the sync button')
def click_sync(context):
    pass


@when('I click the sync button again')
def click_sync_again(context):
    pass


@then('the clock updates to 140 BPM')
def bpm_updates(context):
    pass


@then('the beat interval recalculates')
def beat_interval_calc(context):
    pass


@then('sync mode is enabled')
def sync_enabled(context):
    pass


@then('the sync button shows as active')
def sync_button_active(context):
    pass


@then('sync mode is disabled')
def sync_disabled(context):
    pass


@given('sync mode is enabled')
def sync_mode_enabled(context):
    pass


@given('sync mode is disabled')
def sync_mode_disabled(context):
    pass


@then('playback starts on the next beat')
def playback_next_beat(context):
    pass


@then('the start time aligns to the beat grid')
def start_time_aligned(context):
    pass


@then('playback starts immediately')
def playback_immediately(context):
    pass


@then('no beat alignment is applied')
def no_beat_alignment(context):
    pass


@then('the beat indicator flashes')
def beat_indicator_flashes(context):
    pass

@when('a beat occurs')
def beat_occurs(context):
    pass
