<script lang="ts">
    import type { PatchPropiedad, setVenta } from "../types";

    let {onClose, onConfirm, title = "Publicar para venta", btntext = "Publicar a la venta"
    } : {
        onClose:()=>void, onConfirm:(data:setVenta)=>void, title:string, btntext:string
    } = $props();
    
    let data:setVenta = $state({iddivisa:0, idpropiedad:0, monto:0});
    let monto:number = $state(0);

    function handleSubmit(e: Event) {
        e.preventDefault();
        onConfirm(data);onClose();
    }
</script>

<div class="modal fade show" tabindex="-1" role="dialog" style="display: block; background-color: rgba(0, 0, 0, 0.5);">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">{title}</h5>
                <button type="button" class="btn-close" onclick={onClose} aria-label="Cerrar"></button>
            </div>
  
            <div class="modal-body">
                <form>
                    <div class="form-floating mb-3">
                        <input
                          type="number"
                          id="monto"
                          class="form-control"
                          bind:value={data.monto}
                          placeholder="0"
                          required
                        />
                        <label for="monto">Monto</label>
                    </div>
                    
                    <label for="divisa">divisa</label>
                    <select id="divisa" class="form-select" bind:value={data.iddivisa}>
                        <option value="0" selected>AR$</option>
                        <option value="1">US$</option>
                    </select>
                </form>
            </div>
            
            <div class="modal-footer">
                <button class="btn btn-primary" onclick={(e)=> handleSubmit(e)}>{btntext}</button>
                
                <button class="btn btn-secondary ms-auto" onclick={onClose}>Cerrar</button>
            </div>
        </div>
    </div>
</div>
