STATUS_KEYS = ['pending_payment', 'confirmed', 'picking', 'in_transit', 'delivered', 'cancelled']
TRACKER_STEP_KEYS = ['confirmed', 'picking', 'in_transit', 'delivered']
ACTION_KEYS = {
    'confirmed': 'action_start_picking',
    'picking': 'action_start_delivery_navigate',
    'in_transit': 'action_mark_delivered',
}

_STEP_KEYS = TRACKER_STEP_KEYS


def current_step_index(status):
    """Index into TRACKER_STEP_KEYS for the given order status, or -1 if the
    order hasn't reached the tracker yet (still pending payment/cancelled)."""
    try:
        return _STEP_KEYS.index(status)
    except ValueError:
        return -1


def get_status_labels(t):
    """Every order status, translated — {key: label} using the current
    request's language (see market.translations.get_t)."""
    return {key: t[f'status_{key}'] for key in STATUS_KEYS}


def get_status_label(t, status):
    return t.get(f'status_{status}', status)


def get_tracker_steps(t):
    return [{'key': key, 'label': t[f'status_{key}']} for key in TRACKER_STEP_KEYS]


def get_action_label(t, status):
    action_key = ACTION_KEYS.get(status)
    return t.get(action_key) if action_key else None
