<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_Pattern_Generator
{
    public function __construct()
    {
        add_action('wp_ajax_puffergo_b2b_create_pattern', array($this, 'handle_create_pattern'));
    }

    public function handle_create_pattern()
    {
        check_ajax_referer('puffergo_pattern_generator', '_ajax_nonce');
        $title = isset($_POST['title']) ? sanitize_text_field(wp_unslash($_POST['title'])) : '';
        $html_code = isset($_POST['html_code']) ? wp_kses_post(wp_unslash($_POST['html_code'])) : '';
        $css_code = isset($_POST['css_code']) ? sanitize_textarea_field(wp_unslash($_POST['css_code'])) : '';

        if (empty($title)) {
            wp_send_json_error(array('message' => __('Pattern title cannot be empty', 'puffergo')), 400);

            return;
        }

if (empty($html_code)) {
            wp_send_json_error(array('message' => __('HTML code cannot be empty', 'puffergo')), 400);

            return;
        } $response_data = array('title' => $title, 'html_code' => $html_code, 'css_code' => $css_code, 'timestamp' => current_time('mysql'), 'user_id' => get_current_user_id());
        wp_send_json_success($response_data);
    }
} new PufferGo_Pattern_Generator();
