// js/components/widgets/pagamentos/PagamentoFormModal.jsx
// [Wave 34 v224.15 NUCLEAR EXTRACT 2026-05-24] Modal form new/edit pagamento
// Extract LITERAL Pagamentos.jsx L240-270
//
// Props:
//   - open (bool) — modal === 'form'
//   - form (obj) — {recipient, type, value, date, reference, status, notes}
//   - setForm (fn) — controla form state
//   - editId (id|null) — pra título "Editar" vs "Novo"
//   - onSave (fn) — handler save RPC (preservado LITERAL no main)
//   - onClose (fn) — fecha modal
//   - isSaving (bool) — savingRef.current pra disabled botão
//
// Deps lazy: window.Modal, window.SmartSelect, window.PAGAMENTO_TYPES
(function(){
  'use strict';
  function PagamentoFormModal(props){
    const Modal = window.Modal;
    const SmartSelect = window.SmartSelect;
    const PAGAMENTO_TYPES = window.PAGAMENTO_TYPES || [];
    const { open, form, setForm, editId, onSave, onClose, isSaving } = props;
    if(!open || !Modal) return null;
    return (
      <Modal title={editId?'Editar Pagamento':'Novo Pagamento'} onClose={onClose}>
        <div className="form-grid">
          <div className="form-group full"><label>Destinatário <span style={{color:'#6B7280',fontWeight:400}}>(opcional)</span></label>
            <input value={form.recipient} onChange={function(e){setForm(function(f){return {...f, recipient:e.target.value};});}} placeholder="Ex: Lattafa Import, Rápido Log, Bradesco..."/>
          </div>
          <div className="form-group"><label>Tipo</label>
            <SmartSelect value={form.type} onChange={function(val){setForm(function(f){return {...f, type:val};});}} options={PAGAMENTO_TYPES.map(function(t){return {value:t, label:t};})}/>
          </div>
          <div className="form-group"><label>Valor (R$)</label>
            <input type="number" step="0.01" value={form.value} onChange={function(e){setForm(function(f){return {...f, value:e.target.value};});}}/>
          </div>
          <div className="form-group"><label>Data</label>
            <input type="date" value={form.date} onChange={function(e){setForm(function(f){return {...f, date:e.target.value};});}}/>
          </div>
          <div className="form-group"><label>Referência / NF</label>
            <input value={form.reference} onChange={function(e){setForm(function(f){return {...f, reference:e.target.value};});}} placeholder="Opcional"/>
          </div>
          <div className="form-group"><label>Status</label>
            <SmartSelect value={form.status} onChange={function(val){setForm(function(f){return {...f, status:val};});}} options={['Pendente','Pago','Cancelado'].map(function(x){return {value:x, label:x};})}/>
          </div>
          <div className="form-group full"><label>Observações</label>
            <input value={form.notes} onChange={function(e){setForm(function(f){return {...f, notes:e.target.value};});}} placeholder="Opcional"/>
          </div>
        </div>
        <div style={{display:'flex',gap:10,marginTop:20,justifyContent:'flex-end'}}>
          <button className="btn-outline" onClick={onClose}>Cancelar</button>
          <button className="btn-gold" disabled={isSaving} onClick={onSave}>{isSaving?'Salvando…':'Salvar'}</button>
        </div>
      </Modal>
    );
  }
  window.ZNX = window.ZNX || {};
  window.ZNX.widgets = window.ZNX.widgets || {};
  window.ZNX.widgets.pagamentos = window.ZNX.widgets.pagamentos || {};
  window.ZNX.widgets.pagamentos.PagamentoFormModal = PagamentoFormModal;
  // [Wave 34 marker v224.15] confirma PagamentoFormModal executado
  window.PagamentoFormModal_v224_15_wave34 = true;
})();
