<?php
    require_once(__DIR__.'/../.hta_config/conf.php');
    require_once(__DIR__.'/../.hta_slug/_header.php');
    require_once(__DIR__.'/../.hta_slug/_nav.php');
?>

<section class="diZContainer diZmxAuto diZmb20">
    <h1 class="diZBorderBottom">SiliconPin - Tools</h1>
    <div class="diZFlexRow diZmy8 diZFlexRow">
        <a href="/tools" class="diZButtonDefault diZmr2"><span>All</span></a>
        <a href="/tools/image" class="diZButtonDefault diZmr2"><span>Image</span></a>
        <a href="/tools/text" class="diZButtonDefault diZmr2"><span>Text</span></a>
        <a href="/tools/html" class="diZButtonDefault diZmr2"><span>HTML</span></a>
        <a href="/tools/color" class="diZButtonDefault diZmr2"><span>Color</span></a>
        <a href="/tools/info" class="diZButtonDefault diZmr2"><span>Info</span></a>
        <a href="/tools/encrypt-decrypt" class="diZButtonDefault diZmr2"><span>Encrypt / Decrypt</span></a>
    </div>
    <div class="diZGridCols1-3">
        <?php
        $requestUri = $_SERVER['REQUEST_URI'];
        $requestUri = explode('/', $requestUri)[2];
        $requestUri = ($requestUri <= 1) ? "%%" : $requestUri;
        if(isset($requestUri) && strlen($requestUri > 1)){
            try {
                $conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
                $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $stmt = $conn->prepare("SELECT * FROM api_tools WHERE `type` = :type");
                $stmt->bindParam(':type', $requestUri);
                $stmt->execute();
                $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
                // var_dump($rows);
                foreach($rows as $row){
                    // echo $row['name'].'<br>';
                    if($row['status']==1){
                        $link_button = '<a class="diZButtonDefault" href="/tools/'.$row['slug'].'" ><span class="">'.$row['name'].'</span></a>';
                    } else{
                        $link_button = '<a class="diZButtonDefault"><span>'.$row['name'].'</span></a>';
                    }
                    echo '
                        <div class="diZblogStyle diZPadding10px">
                            <p class="diZLineClamp1">'.$row['description'].'</p>
                            '.$link_button.'
                        </div>';
                }
            } catch (PDOException $e) {
                $in_page_message = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
            }
        }else{
            echo 'Page Not Found!';
        }
        ?>
    </div>
</section>
<style>
    .diZContainer {
        max-width: 1200px;
        margin: auto;
        padding: 20px;
    }

    .diZBorderBottom {
        border-bottom: 2px solid #87ab63;
        padding-bottom: 10px;
    }

    .diZFlexRow {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    .diZButtonDefault {
        background: #87ab63;
        color: #121212;
        padding: 10px 15px;
        border-radius: 5px;
        text-decoration: none;
        font-weight: bold;
        transition: 0.3s;
    }

    .diZButtonDefault:hover {
        background: #6f8f52;
        color: #fff;
    }

    .diZGridCols1-3 {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 15px;
        margin-top: 20px;
    }

    .diZblogStyle {
        background: #1e1e1e;
        border-radius: 8px;
        padding: 15px;
        box-shadow: 0px 0px 10px rgba(135, 171, 99, 0.3);
        transition: transform 0.3s ease-in-out;
    }

    .diZblogStyle:hover {
        transform: translateY(-5px);
        box-shadow: 0px 0px 15px rgba(135, 171, 99, 0.5);
    }

    .diZToolsContentHeight {
        min-height: 60px;
    }
</style>