(function () {
  try {
    if ( window.localStorage ) {
      window.localStorage.removeItem( 'foodord_order_mode' );
      window.localStorage.removeItem( 'foodord_delivery_time' );
      window.localStorage.removeItem( 'foodord_pickup_time' );
      window.localStorage.removeItem( 'foodord_delivery_date' );
      window.localStorage.removeItem( 'foodord_pickup_date' );
    }
  } catch ( error ) {
    void error;
  }

  try {
    document.dispatchEvent( new CustomEvent( 'wrc:deliveryModeChange', { detail: { mode: 'delivery' }, bubbles: true } ) );
  } catch ( error ) {
    void error;
  }

  const hiddenField = document.querySelector( 'input[name="foodord_order_mode"]' );
  if ( hiddenField ) {
    hiddenField.value = 'delivery';
  }
})();
