<?php

namespace RistrettoApps\Spawnster\Helpers;

class HTMLTagFormatter
{
    public static function format($item, $id = '')
    {
        $pattern[0] = '/\<h1\>/is';
        $pattern[1] = '/\<h2\>/is';
        $pattern[2] = '/\<h3\>/is';
        $pattern[3] = '/\<h4\>/is';
        $pattern[4] = '/\<p\>/is';
        $pattern[5] = '/\<h1 class=\"(.*?)\"\>/is';
        $pattern[6] = '/\<h2 class=\"(.*?)\"\>/is';
        $pattern[7] = '/\<h3 class=\"(.*?)\"\>/is';
        $pattern[8] = '/\<h4 class=\"(.*?)\"\>/is';
        $pattern[9] = '/\<p class=\"(.*?)\"\>/is';
        $pattern[10] = '/\<\/p\>/is';
        $replace[0] = '<h1 class="text-2xl font-bold mb-6">';
        $replace[1] = '<h2 class="text-xl font-bold mb-6">';
        $replace[2] = '<h3 class="text-lg font-bold mb-6">';
        $replace[3] = '<h4 class="text-md font-bold mb-6">';
        $replace[4] = '<p class="para mb-3 text-base">';
        $replace[5] = '<h1 class="text-2xl font-bold mb-6">';
        $replace[6] = '<h2 class="text-xl font-bold mb-6">';
        $replace[7] = '<h3 class="text-lg font-bold mb-6">';
        $replace[8] = '<h4 class="text-md font-bold mb-6">';
        $replace[9] = '<p class="para mb-3 text-base" data-id="'.$id.'">';
        $replace[10] = '</p>';

        return preg_replace($pattern, $replace, $item);
    }

    private static function replyButton(): string
    {
        return '<div class="pt-6 justify-bottom align-bottom respond_block hidden"></div>';
    }

    private static function textBox(): string
    {
        $html = '<div class="pt-6 justify-bottom align-bottom">';
        $html .= '<hr>';
        $html .= '<div class="relative w-full pt-5">';
        $html .= '<textarea id="regen_content" class="max-h-48 py-3 ps-4 pe-20 block w-full border-gray-200 rounded-lg text-sm focus:border-blue-500 focus:ring-blue-500 disabled:opacity-50 disabled:pointer-events-none resize-none overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-track]:bg-gray-100 [&::-webkit-scrollbar-thumb]:bg-gray-300 "';
        $html .= 'rows="6" data-hs-textarea-auto-height=\'{"defaultHeight": 48}\'>';
        $html .= '</textarea>';
        $html .= '<div class="absolute top-28 end-3 pt-2">';
        $html .= '<button type="button" data-id="" class="regen py-1.5 px-3 inline-flex align-bottom shrink-0 justify-center items-center text-sm font-medium rounded-lg text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:bg-indigo-500">';
        $html .= 'Enhance';
        $html .= '</button>';
        $html .= \RistrettoApps\Spawnster\Helpers\ComponentView::render('components/small_loader', []);
        $html .= '</div></div></div>';

        return $html;
    }
}