<?php

namespace Bricks;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Fluxtore_Element_Checkout_Block extends Element {
    public $category = 'fluxtore';
    public $name     = 'fluxtore-checkout-block';
    public $icon     = 'ti-shopping-cart';

    public function get_label() {
        return esc_html__( 'Fluxtore Checkout Block', 'fluxtore' );
    }

    public function set_controls() {
        // No custom controls required for the checkout block yet.
    }

    public function render() {
        global $post;

        $has_product = false;

        if ( $post instanceof \WP_Post ) {
            $product_meta = get_post_meta( $post->ID, '__fluxtore__product', true );
            $has_product  = ! empty( $product_meta );
        }

        echo '<div ' . $this->render_attributes( '_root' ) . '>';

        if ( $has_product ) {
            echo do_shortcode( '[fluxtore-checkout-block]' );
        } else {
            echo '<p style="text-align:center">' . esc_html__( 'Product is empty or not set.', 'fluxtore' ) . '</p>';
        }

        echo '</div>';
        ?>
        <style>
        @layer fluxtore-checkout {
            div#customer_details {
                display: flex !important;
                grid-template-columns: repeat(2, 1fr) !important;
                gap: 20px !important;
                width: 100% !important;
            }

            .woocommerce-billing-fields,
            .woocommerce-shipping-fields {
                flex: 1 !important;
                border: 1px solid var(--bricks-border-color, #ddd) !important;
                padding: 20px !important;
                border-radius: var(--bricks-border-radius, 4px) !important;
                background-color: var(--bricks-background-color, #fff) !important;
            }
        }
        </style>
        <?php
    }
}
