import CodeSnippet from '../CodeSnippet.js';
export default class AxiosSnippet extends CodeSnippet {
    lang = 'javascript';
    computeCommand(url, method, headers, payload) {
        if (!url || !method) {
            return '';
        }
        const parts = [];
        parts.push('import axios from "axios";');
        parts.push('');
        let hasHeaders = false;
        if (headers) {
            const map = {};
            for (const [name, value] of headers) {
                hasHeaders = true;
                map[name] = value;
            }
            if (hasHeaders) {
                parts.push(`const headers = ${JSON.stringify(map, null, 2)}`);
                parts.push('');
            }
        }
        if (payload) {
            parts.push(`const data = \`${payload}\`;`);
            parts.push('');
        }
        parts.push(`const options = {`);
        parts.push(`  url: '${url}',`);
        parts.push(`  method: '${method}',`);
        if (hasHeaders) {
            parts.push(`  headers,`);
        }
        if (payload) {
            parts.push(`  data,`);
        }
        parts.push(`}`);
        parts.push(``);
        parts.push(`const response = await axios.request(options);`);
        parts.push(`console.log(response.data);`);
        return parts.join('\n');
    }
}
//# sourceMappingURL=AxiosSnippet.js.map