<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

// phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
/**
 * SMS Template for Canceled Bookings
 * 
 * This template is used to send SMS notifications when a booking is canceled.
 * The same message is sent to both admin and customer (differentiated by phone number).
 * 
 * @var SLN_Plugin          $plugin
 * @var SLN_Wrapper_Booking $booking
 */

$default_template = SLN_Admin_SettingTabs_GeneralTab::getDefaultSmsNotificationMessageCanceled();
$template = $plugin->getSettings()->get('sms_notification_message_canceled') 
            ? $plugin->getSettings()->get('sms_notification_message_canceled') 
            : $default_template;

$bookingDateTime = $plugin->getSettings()->isDisplaySlotsCustomerTimezone() && $booking->getCustomerTimezone() 
    ? (new SLN_DateTime($booking->getDate()->format('Y-m-d') . ' ' . $booking->getTime()->format('H:i')))->setTimezone(new DateTimeZone($booking->getCustomerTimezone())) 
    : new SLN_DateTime($booking->getDate()->format('Y-m-d') . ' ' . $booking->getTime()->format('H:i'));

$message = str_replace(
    array(
        '[NAME]',
        '[SALON NAME]',
        '[DATE]',
        '[TIME]',
        '[PRICE]',
        '[BOOKING ID]',
    ),
    array(
        $booking->getDisplayName(),
        $plugin->getSettings()->getSalonName($booking),
        $plugin->format()->date($bookingDateTime),
        $plugin->format()->time($bookingDateTime),
        $booking->getAmount(),
        $booking->getId(),
    ),
    $template
);

if (strlen($message) > 160) {
    $more_string = __('...more details in the email confirmation', 'salon-booking-system');
    $message = substr($message, 0, (159 - strlen($more_string))) . $more_string;
}

echo $plugin->getSettings()->get('sms_ascii_mode') ? remove_accents($message) : $message;

