using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Transversal.Interfaces;

namespace phronCare.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PdfTestController : ControllerBase
    {
        private readonly IPdfGeneratorService _pdfGeneratorService;

        public PdfTestController(IPdfGeneratorService pdfGeneratorService)
        {
            _pdfGeneratorService = pdfGeneratorService;
        }

        [HttpGet("test")]
        public async Task<IActionResult> GetTestPdf()
        {
            // HTML de ejemplo
            string html = @"
<html>
<head>
    <style>
        body { font-family: Arial, sans-serif; font-size: 12px; margin: 20px; }
        .header { text-align: center; border-bottom: 3px solid #4CAF50; padding-bottom: 10px; margin-bottom: 30px; }
        .header h1 { color: #4CAF50; margin: 0; }
        .info-table, .details-table, .totals-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
        .info-table td { padding: 5px; }
        .details-table th, .details-table td { border: 1px solid #ddd; padding: 8px; text-align: center; }
        .details-table th { background-color: #4CAF50; color: white; }
        .totals-table th, .totals-table td { border: 1px solid #ddd; padding: 8px; text-align: right; }
        .totals-table th { background-color: #4CAF50; color: white; }
        .footer { position: fixed; bottom: 15px; left: 0; right: 0; text-align: center; font-size: 10px; color: gray; border-top: 1px solid #ddd; padding-top: 5px; }
    </style>
</head>
<body>
    <div class='header'>
        <h1>PhronCare Ortopedia</h1>
        <p>Presupuesto médico de prueba</p>
    </div>

    <table class='info-table'>
        <tr>
            <td><strong>Cliente:</strong> Juan Pérez</td>
            <td><strong>Presupuesto N°:</strong> 000123</td>
        </tr>
        <tr>
            <td><strong>Fecha:</strong> 13/05/2025</td>
            <td><strong>Profesional:</strong> Dr. Carlos López</td>
        </tr>
    </table>

    <table class='details-table'>
        <tr>
            <th>Cantidad</th>
            <th>Producto</th>
            <th>Precio Unitario</th>
            <th>Subtotal</th>
        </tr>
        <tr>
            <td>2</td>
            <td>Rodillera ortopédica</td>
            <td>$5.000</td>
            <td>$10.000</td>
        </tr>
        <tr>
            <td>1</td>
            <td>Férula de inmovilización</td>
            <td>$8.000</td>
            <td>$8.000</td>
        </tr>
    </table>

    <table class='totals-table'>
        <tr>
            <th>Subtotal</th>
            <td>$18.000</td>
        </tr>
        <tr>
            <th>IVA (21%)</th>
            <td>$3.780</td>
        </tr>
        <tr>
            <th>Total</th>
            <td><strong>$21.780</strong></td>
        </tr>
    </table>

    <div class='footer'>
        Documento generado automáticamente por PhronCare - Solo para fines demostrativos. No válido como factura.
    </div>
</body>
</html>";

            byte[] pdfBytes = await _pdfGeneratorService.GeneratePdfFromHtmlAsync(html);

            return File(pdfBytes, "application/pdf", "Presupuesto.pdf");
        }

    }
}
