import React, { useState } from 'react';
import { X, Printer, Calendar, FileText, AlertCircle } from 'lucide-react';

export default function AutoReprintModal({ isOpen, onClose, store, onConfirm }) {
    const [formData, setFormData] = useState({
        documentType: 'FV',
        date: '',
        documentNumber: ''
    });

    if (!isOpen) return null;

    const handleSubmit = (e) => {
        e.preventDefault();
        onConfirm(formData);
    };

    return (
        <div className="ar-modal-overlay">
            <div className="ar-modal-content">
                {/* Header */}
                <div className="ar-modal-header">
                    <div className="flex items-center gap-2">
                        <Printer size={20} style={{ color: 'var(--text-accent)' }} />
                        <h2 style={{ margin: 0, fontSize: '1rem', color: '#fff', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.05em' }}>
                            Reimpresión Automática
                        </h2>
                    </div>
                    <button onClick={onClose} className="ar-close-btn">
                        <X size={20} />
                    </button>
                </div>

                {/* Content */}
                <form onSubmit={handleSubmit} className="ar-modal-body">
                    <div className="ar-info-banner">
                        <AlertCircle size={18} style={{ color: 'var(--info)', flexShrink: 0 }} />
                        <div style={{ fontSize: '0.75rem', color: 'var(--text-secondary)', lineHeight: '1.5' }}>
                            Se solicitará la reimpresión automática de documentos en <b style={{ color: '#fff' }}>{store?.name}</b>.
                            Configure los parámetros de búsqueda.
                        </div>
                    </div>

                    <div className="ar-form-grid">
                        {/* Document Type */}
                        <div className="ar-input-group">
                            <label><FileText size={12} /> Tipo de Documento</label>
                            <select
                                required
                                value={formData.documentType}
                                onChange={(e) => setFormData(prev => ({ ...prev, documentType: e.target.value }))}
                            >
                                <option value="FV">Factura (FV)</option>
                                <option value="BL">Boleta (BL)</option>
                                <option value="NC">Nota de Crédito (NC)</option>
                            </select>
                        </div>

                        {/* Date */}
                        <div className="ar-input-group">
                            <label><Calendar size={12} /> Fecha</label>
                            <input
                                type="date"
                                required
                                value={formData.date}
                                onChange={(e) => setFormData(prev => ({ ...prev, date: e.target.value }))}
                            />
                        </div>

                        {/* Document Number */}
                        <div className="ar-input-group full-width">
                            <label><FileText size={12} /> Número de Documento</label>
                            <input
                                type="text"
                                required
                                value={formData.documentNumber}
                                onChange={(e) => setFormData(prev => ({ ...prev, documentNumber: e.target.value }))}
                                placeholder="Ej: 12345"
                            />
                        </div>
                    </div>

                    <div className="ar-modal-footer">
                        <button type="button" onClick={onClose} className="ar-btn-secondary">
                            Cancelar
                        </button>
                        <button type="submit" className="ar-btn-primary">
                            <Printer size={18} /> Iniciar Reimpresión
                        </button>
                    </div>
                </form>
            </div>

            <style>{`
                .ar-modal-overlay {
                    position: fixed;
                    top: 0;
                    left: 0;
                    right: 0;
                    bottom: 0;
                    background-color: rgba(0, 0, 0, 0.7);
                    backdrop-filter: blur(4px);
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    z-index: 1000;
                    padding: 1rem;
                }

                .ar-modal-content {
                    background-color: var(--bg-panel);
                    width: 100%;
                    max-width: 500px;
                    border-radius: 0.75rem;
                    border: 1px solid var(--border);
                    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
                    overflow: hidden;
                    animation: modalEntry 0.3s ease-out;
                }

                @keyframes modalEntry {
                    from { opacity: 0; transform: translateY(20px); }
                    to { opacity: 1; transform: translateY(0); }
                }

                .ar-modal-header {
                    background-color: var(--bg-input);
                    padding: 1rem 1.25rem;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    border-bottom: 1px solid var(--border);
                }

                .ar-close-btn {
                    background: transparent;
                    border: none;
                    color: var(--text-muted);
                    cursor: pointer;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    padding: 4px;
                    border-radius: 4px;
                }

                .ar-close-btn:hover {
                    color: #fff;
                    background-color: rgba(255,255,255,0.1);
                }

                .ar-modal-body {
                    padding: 1.5rem;
                    display: flex;
                    flex-direction: column;
                    gap: 1.25rem;
                }

                .ar-info-banner {
                    background-color: rgba(59, 130, 246, 0.1);
                    border: 1px solid rgba(59, 130, 246, 0.2);
                    padding: 0.75rem;
                    border-radius: 0.5rem;
                    display: flex;
                    gap: 0.75rem;
                    align-items: center;
                }

                .ar-form-grid {
                    display: grid;
                    grid-template-columns: 1fr 1fr;
                    gap: 1rem;
                }

                .ar-input-group {
                    display: flex;
                    flex-direction: column;
                    gap: 0.375rem;
                }

                .ar-input-group.full-width {
                    grid-column: span 2;
                }

                .ar-input-group label {
                    font-size: 0.7rem;
                    font-weight: 700;
                    color: var(--text-muted);
                    text-transform: uppercase;
                    letter-spacing: 0.05em;
                    display: flex;
                    align-items: center;
                    gap: 0.5rem;
                }

                .ar-input-group input,
                .ar-input-group select {
                    background-color: var(--bg-input);
                    border: 1px solid var(--border);
                    color: #fff;
                    padding: 0.625rem 0.875rem;
                    border-radius: 0.5rem;
                    font-size: 0.875rem;
                    outline: none;
                    transition: border-color 0.2s;
                }

                .ar-input-group input:focus,
                .ar-input-group select:focus {
                    border-color: var(--accent);
                }

                .ar-input-group select {
                    cursor: pointer;
                }

                .ar-modal-footer {
                    display: flex;
                    gap: 1rem;
                    margin-top: 0.5rem;
                }

                .ar-btn-secondary {
                    flex: 1;
                    padding: 0.75rem;
                    background: transparent;
                    border: 1px solid var(--border);
                    color: #fff;
                    border-radius: 0.5rem;
                    font-weight: 600;
                    cursor: pointer;
                    transition: all 0.2s;
                }

                .ar-btn-secondary:hover {
                    background-color: var(--bg-hover);
                }

                .ar-btn-primary {
                    flex: 1;
                    padding: 0.75rem;
                    background-color: var(--accent);
                    border: none;
                    color: #fff;
                    border-radius: 0.5rem;
                    font-weight: 600;
                    cursor: pointer;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    gap: 0.5rem;
                    transition: all 0.2s;
                    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
                }

                .ar-btn-primary:hover {
                    background-color: var(--accent-hover);
                    transform: translateY(-1px);
                }
            `}</style>
        </div>
    );
}
