<?php

namespace Booktics\Shortcode;

/**
 * Service View shortcode class
 */
class Service_Shortcode {
    /**
     * Constructor for service view shortcode
     *
     * @return  void
     */
    public function __construct() {
        add_shortcode(
            'booktics_service_view', array(
                $this,
                'render_service_view',
            )
        );
    }

    /**
     * Render service view
     *
     * @param array $attributes
     *
     * @return  string
     */
    public function render_service_view( $attributes ) {
        $id = isset( $attributes['id'] ) ? absint( $attributes['id'] ) : 0;

        wp_enqueue_style( 'booktics-vendor' );
        wp_enqueue_style( 'booktics-frontend' );

        wp_enqueue_script( 'booktics-packages' );
        wp_enqueue_script( 'booktics-frontend-scripts' );
        wp_enqueue_script( 'booktics-flatpickr-scripts' ); 

        do_action( 'booktics_before_rendering_service_view_shortcode' );

        $post = get_post( $id );
        if ( ! $post || ( isset( $post->post_status ) && $post->post_status === 'deactive' ) ) {
            return '<div class="booktics-shortcode-notice-wrapper">
                    <div>
                        <h3>' . esc_html__( 'Service Unavailable', 'booktics' ) . '</h3>
                    </div>
                </div>';
        }

        return "<div class='booktics-shortcode-wrapper'>
                        <div class='booktics-single-service-wrapper'
                             data-id='" . esc_attr( $id ) . "'>
                        </div>
                    </div>";
    }
}
