<?php 
require('../conexion.php');


if(isset($_POST['clave_receta'])){
    $clave_receta= $_POST['clave_receta'];
    $query=query("SELECT A.id 'ID', A.rec_nombre 'REC_NOMBRE', A.rec_clave 'REC_CLAVE', A.rec_estatus 'REC_ESTATUS', A.rec_costo 'REC_COSTO' FROM receta A WHERE id='$clave_receta'"); // Busqueda por id antes lo hacia por la clave
    $datos=mysqli_fetch_assoc($query);
}else{
    $datos="";
}

$salida = "";
if($datos != ""){ 
    if($query->num_rows > 0){
        $salida.="<table class='table'>
        <thead style='background: #052659; color:#D5D8DC;'>
            <tr>
                <th class='align-middle text-center' scope='col'>Clave de Receta</th>
                <th class='align-middle text-center' scope='col'>Nombre de Receta</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th>
                    <div class='input-group input-group-outline'>
                        <!--<label class='form-label'>Clave</label>-->
                        <input type='text' class='form-control' name='rec_clave' id='rec_clave' value='".$datos['REC_CLAVE']."'>
                    </div>
                </th>
                <th>
                    <div class='input-group input-group-outline'>
                        <!--<label class='form-label'>Nombre</label>-->
                        <input type='text' class='form-control' name='rec_nombre' id='rec_nombre' value='".$datos['REC_NOMBRE']."'>
                    </div>
                </th>
                <th>
                    <input type='hidden' class='form-control' name='rec_id' id='rec_id' value='".$datos['ID']."'>
                </th>
                <th>
                    <input type='hidden' class='form-control' name='rec_costo' id='rec_costo' value='".$datos['REC_COSTO']."'>
                </th>
            </tr>
        </tbody>
    </table>";
    }
}
    else{
        $salida.="
        <table class='table'>
        <thead style='background: #052659; color:#D5D8DC;'>
            <tr>
                <th class='align-middle text-center' scope='col'>Clave de Receta</th>
                <th class='align-middle text-center' scope='col'>Nombre de Receta</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th>
                    <div class='input-group input-group-outline'>
                        <label class='form-label'>Clave</label>
                        <input type='text' class='form-control' name='rec_clave'>
                    </div>
                </th>
                <th>
                    <div class='input-group input-group-outline'>
                        <label class='form-label'>Nombre</label>
                        <input type='text' class='form-control' name='rec_nombre'>
                    </div>
                </th>
                <th>
                    <input type='hidden' class='form-control' name='rec_id' value=''>
                </th>
                <th>
                    <input type='hidden' class='form-control' name='rec_costo' value=''>
                </th>
            </tr>
        </tbody>
    </table>";
    }
echo $salida;
?>