/** * SSA Booking Module - Divi 5 Visual Builder Component * * @package Simply_Schedule_Appointments * @since 5.9.0 */ const React = window.React; const { Component } = React; const { ModuleContainer } = window?.divi?.module || {}; /** * Internal class component for managing state */ class SSABookingRenderer extends Component { constructor(props) { super(props); this.state = { bookingHTML: null, isLoading: true, }; } componentDidMount() { this.fetchBookingForm(); } componentDidUpdate(prevProps) { const prevType = prevProps?.appointmentType || ''; const currentType = this.props?.appointmentType || ''; if (prevType !== currentType) { this.fetchBookingForm(); } } async fetchBookingForm() { this.setState({ isLoading: true }); const appointmentType = this.props.appointmentType || ''; const shortcodeAttr = appointmentType ? `type="${appointmentType}"` : ''; const shortcode = `[ssa_booking ${shortcodeAttr}]`; try { const response = await fetch(`${window.wpApiSettings?.root || '/wp-json/'}ssa/v1/render-shortcode`, { method: 'POST', headers: { 'X-WP-Nonce': window.wpApiSettings?.nonce || '', 'Content-Type': 'application/json', }, body: JSON.stringify({ shortcode }), }); const data = await response.json(); this.setState({ bookingHTML: data.html || data, isLoading: false }); } catch (err) { this.setState({ bookingHTML: '