<?php

    class PuzzleHTML
    {
        public static function TitleSection ($icon, $titulo, $volver = FALSE, $volver_texto = FALSE) 
        {
            $html = '<div class="col-12 mt-4 d-flex justify-content-between border-bottom">';
                $html .= '<h4>';
                    $html .= '<i class="fas fa-' . $icon . ' mb-3 mr-2"></i>' . $titulo;
                $html .= '</h4>';

            if($volver)
            {

                $html .= '<div class="text-secondary d-block float-right">';
                    $html .= '<a href="javascript:window.location.href=\'' . $volver . '\'" class="btn btn-outline-info mr-2">';
                        $html .= '<i class="fas fa-chevron-left"></i><span class="ml-2">' . $volver_texto . '</span>';
                    $html .= '</a>';
                $html .= '</div>';
            }

            $html .= '</div>';
            return $html;
        }


        public static function MainTitle($titulo, $icon = FALSE, $subtitulo = FALSE)
        {

            
            $iconTAG = $icon ? '<i class="fas fa-' . $icon . ' fa-lg mb-3 mr-2"></i>' : '';
            

            $html = '<h4>';
                $html .= $iconTAG . $titulo;
            $html .= '</h4>';

            if($subtitulo)
            {
                $html .= '<div>' . $subtitulo . '</div>';
            }

            return $html;
        }


        public static function Back($volver, $volver_texto)
        {

            //window.location.href=
            //history.back()
            $html = '<div class="text-secondary d-block float-right">';
                $html .= '<a href="' . $volver . '" class="btn btn-outline-info mr-2">';
                    $html .= '<i class="fas fa-chevron-left"></i><span class="ml-2">' . $volver_texto . '</span>';
                $html .= '</a>';
            $html .= '</div>';

            return $html;
        }


        public static function buscarContacto($placeholder, $control_input , $cliente = NULL, $titulo)
        {

            $html = '<div class="mb-3">';
                $html .= '<div class="input-group">';
                    $html .= '<input onkeyup="yelling(this)" type="text" name="buscador" class="form-control" id="buscador" placeholder="' . $placeholder . '..." aria-describedby="buscar">';
                    $html .= '<input type="hidden" name="control_input" id="control_input" value="' . $control_input . '">';
                    $html .= '<div class="input-group-append">';
                        $html .= '<button class="btn btn-outline-secondary rounded-right mr-2" type="button" id="buscar" data-toggle="modal" data-target=".buscador-modal"><i class="fas fa-search"></i></button>';
                        $html .= $cliente;
                    $html .= '</div>';
                $html .= '</div>';
            $html .= '</div>';


            $html .= '<div class="modal fade buscador-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">';
                $html .= '<div class="modal-dialog modal-lg">';
                    $html .= '<div class="modal-content">';
                        $html .= '<div class="modal-header">';
                            $html .= '<h5 class="modal-title">' . $titulo .'</h5>';
                            $html .= '<button type="button" class="close" data-dismiss="modal" aria-label="Close">';
                                $html .= '<span aria-hidden="true">&times;</span>';
                            $html .= '</button>';
                        $html .= '</div>';
                        $html .= '<div class="modal-body">';
                            $html .= '<div id="resultadosBusqueda"></div>';
                        $html .= '</div>';
                    $html .= '</div>';
                $html .= '</div>';
            $html .= '</div>';


            echo $html;
 
        }



        public static function inputsClientes($id, $label, $type, $value = NULL, $required = NULL, $required_text = NULL)
        {
            
          $html = '<div class="col-md-4 mb-4">';
                $html .= '<label for="' . $id . '">' . $label . '</label>';
                $html .= '<input onkeyup="yelling(this)" type="' . $type . '" class="form-control" id="' . $id . '" placeholder="' . $label .'..." ' . $required . '  name="' . $id . '"
                value="' . $value .'">';

                if($required)
                {
                    $html .= '<div class="invalid-tooltip">';
                        $html .= $required_text;
                    $html .= '</div>';
                }
            $html .= '</div>';

            echo $html;
        }



        //$id = label for, id input, name input
        //$label = titulo de input
        //$tipo_input = el tipo de input (number, text, date, hidden)
        //$otras = cualquier campo necesario del input como value, acciones js, placeholder
        //required = si es necesario el campo, y el mensaje
        public static function inputSinIcono($id, $label, $tipo_input, $otras = FALSE, $required = FALSE, $mensaje_invalid = FALSE)
        {
            
            $html = '<label for="' . $id . '">' . $label . '</label>';
            $html .= '<input onkeyup="yelling(this)"  type="' . $tipo_input . '" class="form-control" id="' .  $id . '" name="' . $id . '" ' . $otras . ' ' . $required . ' >';

            if($required)
            {
                $html .= '<div class="invalid-tooltip">' . $mensaje_invalid . '</div>';
            }


            return $html;
        }


        public static function inputConIcono ($id, $icon, $tipo_input, $otras = FALSE, $required = FALSE, $label = FALSE) {

            global $campo_obligatorio_lg;
            $required = $required ? 'required' : '';
            $invalid_tooltip = '';
            $d_none = 'd-none';

            if($required)
            {
                $required = 'required';
                $invalid_tooltip = '<div class="invalid-tooltip">' . $campo_obligatorio_lg . '</div>';
            }

            if($label)
            {
                $d_none = 'd-block';
            }

            
            $html = '<label class="' . $d_none . '" for="' . $id . '">' . $label . '</label>';
            $html .= '<div class="input-group">';
                $html .= '<div class="input-group-prepend">';
                    $html .= '<span class="input-group-text">' . $icon . '</span>';
                $html .= '</div>';
                $html .= '<input type="' . $tipo_input . '" name="' . $id . '" class="form-control" id="' . $id . '" ' . $otras . '  ' . $required . '>';
                $html .= $invalid_tooltip;
            $html .= '</div>';
            

            return $html;

        }



        
        public static function TextArea($id, $placeholder)
        {
            $html = '<div class="input-group col-12 mb-4">';
                $html .= '<div class="input-group-prepend">';
                    $html .= '<span class="input-group-text"><i class="fas fa-sticky-note text-muted"></i></span>';
                $html .= '</div>';
                $html .= '<textarea class="form-control" name="' . $id . '" id="' . $id . '" aria-label="With textarea" style="resize:none;" placeholder="' .  $placeholder . '"></textarea>';
            $html .= '</div>';

            echo $html;
        }





        public static function ButtonModal($title, $target, $icon)
        {

            $html = '<span data-toggle="tooltip" data-placement="top" title="' . $title .'">';
                $html .= '<a style="cursor:pointer;" data-toggle="modal" data-target="#' . $target . '" >';
                    $html .= '<i class="' . $icon . ' fa-lg mr-3"></i>';
                $html .= '</a>';
            $html .= '</span>';

            echo $html;
        }




        //Observaciones Tasaciones
        public static function observaciones($con, $observaciones_lg, $codigo_tas = FALSE, $tas_value, $vehiculo, $guardar_lg, $seccion_vacia_lg)
        {
            $schema = new Schema($con);
            $html = '<form class="mt-4 mb-4" novalidate="" enctype="multipart/form-data" method="post">';
                $html .= '<div class="input-group mb-2">';
                    $html .= '<div class="input-group-prepend">';
                        $html .= '<span class="input-group-text"><i class="fas fa-sticky-note"></i></span>';
                    $html .= '</div>';
                    $html .= '<textarea class="form-control" name="obsDocumentos" id="obsDocumentos" aria-label="With textarea" placeholder="' . $observaciones_lg .'"></textarea>';
                    $html .= '<input type="hidden" name="codigoTas" id="codigoTas" value="' . $codigo_tas . '">';
                    $html .= '<input type="hidden" name="variableTas" id="variableTas" value="' . $tas_value . '">';
                    $html .= '<input type="hidden" name="vehiculo" id="vehiculo" value="' . $vehiculo . '">';
                $html .= '</div>';

                $html .= '<div class="d-flex justify-content-end">';
                    $html .= '<button type="button" onclick="uploadOBS()" id="btn-txt" class="btn btn-primary">' . $guardar_lg . '</button>';
                $html .= '</div>';
            $html .= '</form>';


            $html .= '<ul class="list-group" id="obsSection">';
                $html .= '<li class="list-group-item d-flex justify-content-between bg-light">';
                    $html .= '<div class="text-dark">';  
                        $html .= '<h6 class="my-0">' . $observaciones_lg .'</h6>';
                    $html .= '</div>';
                    $html .= '</li>';
                    $sql = "SELECT * FROM VEHICULOS_NOTAS WHERE VARIABLE_TAS = ? AND CLAVE = ? ORDER BY FECHA DESC";
                    $res = $schema->executeQuery($sql, 'si', [$tas_value, $vehiculo]);
                    if($res->num_rows)
                    {
                        while($row = $res->fetch_array())
                        {
                            $html .= '<li class="list-group-item">';
                            $html .= '<span class="d-block mb-3 mt-1">&bull; ' . nl2br($row['NOTA']) . '</span>';
                            $html .= '<small class="text-muted d-block float-right text-muted"> ' . ucfirst($row['USUARIO']) . " - " . date('H:i:s d/m/Y', strtotime($row['FECHA'])) .'</small>';
                            $html .= '</li>';
                        }
                    }
                    else
                    {
                        $html .= '<li class="list-group-item text-center">';
                            $html .= '<small class="text-muted text-muted"> ' . $seccion_vacia_lg .'</small>';
                        $html .= '</li>';
                    }
            $html .= '</ul>';

            echo $html;

        }


        

        public static function ListadoIVA($con, $id, $impuestos_lg, $sin_asignar_2_lg, $select = FALSE)
        {
            $html = '<label for="' . $id . '">' . $impuestos_lg .'</label>';
            $html .= '<select name="' . $id . '" id="' . $id . '" class="form-control">';
            $sql = "SELECT * FROM EXPEDIENTES_IMPUESTOS WHERE GRUPO = 'IVA'";
            $res = $con->query($sql);
            $html .= '<option value="">' . $sin_asignar_2_lg . '</option>';
            while($row = $res->fetch_array())
            {
                $selected = $row['CODIGO'] == $select ? 'selected' : '';
                $html .= '<option value="' . $row['CODIGO'] . '" data-porcentaje="' . $row['PORCENTAJE'] . '" ' . $selected . '>' . $row['DESCRIPCION'] . '</option>';
            }
            $html .= '</select>';

            return $html;
        }



        public static function select_precio ($input_name = FALSE, $style = FALSE, $top = FALSE, $min = FALSE) {
            global $precio_hasta_lg;
            $input_name = !$input_name ? 'precio_hasta' : $input_name;
            $style = !$style ? 'col-md-2 col-12 mb-3' : $style;
            $top = !$top ? 1000000 : $top;
            $min = !$min ? 1000: $min;

            $html = '<div class="' . $style . '">';
                $html .= '<select name="' . $input_name . '" class="form-control">';
                $html .= "<option value=''>$precio_hasta_lg</option>";
                for($i = $min; $i <= $top; $i = $i + 1000)
                {
                    if(!empty($i))
                    {
                        if($i > 10000 AND $i < 10000)
                        {
                            $i = $i + 9000;
                        }
                        if($i > 10000 AND $i < 100000)
                        {      
                            $i = $i + 9000;
                        }
                        if($i > 100000 AND $i < 1000000)
                        {      
                            $i = $i + 49000;
                        }
                        if($i > 1000000 AND $i < $top)
                        {      
                            $i = $i + 499000;
                        }

                        $html .= "<option value='$i'>" . number_format($i,2,',','.') . "</option>";
                    }
                    
                }
                $html .= '</select>';
            $html .= '</div>';

            return $html;
        }
    }

?>