import BaseView from '../../core/BaseView';
import ApiClient from '../../core/ApiClient';

export default class SmartFlowTestView extends BaseView {
    render() {
        return `
            <div style="padding:2rem;">
                <h2>SmartFlow Graph Test</h2>
                <input type="number" id="smartflow-voucher-id" value="1" style="width:100px;">
                <button class="button" id="smartflow-load-btn">Load Graph</button>
                <pre id="smartflow-output" style="background:#111;color:#0f0;padding:1rem;height:300px;overflow:auto;"></pre>
            </div>
        `;
    }
   afterRender() {
    const btn = this.$('#smartflow-load-btn');

    btn.addEventListener('click', async () => {
        const id = this.$('#smartflow-voucher-id').value;

        const data = await ApiClient.get(`smartflow/voucher/${id}/graph`);

        this.$('#smartflow-output').textContent =
            JSON.stringify(data, null, 2);
    });
}

}
